Fix clipping when rendering a single icon so that it takes the objects dimensions...
[AROS.git] / test / screentest.c
blob463dd1eee397645b00e971da47aee3bde1014409
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Screen opening test
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <exec/types.h>
12 #include <graphics/rastport.h>
13 #include <graphics/gfxmacros.h>
14 #include <intuition/intuition.h>
15 #include <proto/dos.h>
16 #include <proto/exec.h>
17 #include <proto/graphics.h>
18 #include <proto/intuition.h>
20 #include <stdarg.h>
22 #ifndef IPTR
23 #define IPTR ULONG
24 #endif
26 struct myargs
28 LONG *left;
29 LONG *top;
30 LONG *width;
31 LONG *height;
32 LONG *depth;
33 STRPTR mode;
34 LONG *oscan;
35 LONG *scroll;
36 LONG *drag;
37 LONG *likewb;
40 struct IntuitionBase *IntuitionBase;
41 struct GfxBase *GfxBase;
42 struct DosLibrary *DOSBase;
44 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h);
46 ULONG handleevents(struct Window *win, struct Screen *screen, WORD x, WORD y);
48 #define W1_LEFT 100
49 #define W1_TOP 100
50 #define W1_WIDTH 350
51 #define W1_HEIGHT 220
53 WORD drawtext(struct Window *win, WORD x, WORD y, char *fmt, ...)
55 va_list args;
56 char buf[256];
57 struct IntuiText it = {
58 1, 0,
59 JAM2,
60 0, 0,
61 NULL,
62 buf,
63 NULL
66 va_start(args, fmt);
67 vsprintf(buf, fmt, args);
68 va_end(args);
69 PrintIText(win->RPort, &it, x, y);
70 return y + win->IFont->tf_YSize;
73 int __nocommandline = 1;
75 int main(int argc, char **argv)
77 struct myargs args = {NULL};
78 struct RDArgs *rda;
80 if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0)))
82 if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0)))
84 if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0)))
86 rda = ReadArgs("LEFT/K/N,TOP/K/N,WIDTH/N,HEIGHT/N,DEPTH/K/N,MODEID/K,OVERSCAN/K/N,SCROLL/K/N,DRAG/K/N,LIKEWB/K/N", (IPTR *)&args, NULL);
87 if (rda) {
88 struct Screen *screen;
89 struct Window *w1;
90 ULONG oserr = 0;
91 struct TagItem tags[] = {
92 {SA_Width, 640 },
93 {SA_Height, 480 },
94 {SA_Depth, 4 },
95 {TAG_IGNORE, 0 },
96 {TAG_IGNORE, 0 },
97 {TAG_IGNORE, 0 },
98 {TAG_IGNORE, 0 },
99 {TAG_IGNORE, 0 },
100 {TAG_IGNORE, 0 },
101 {TAG_IGNORE, 0 },
102 {SA_Title, "Screen opening and movement test"},
103 {SA_ErrorCode, &oserr },
104 {TAG_DONE, 0 }
107 if (args.width)
108 tags[0].ti_Data = *args.width;
109 if (args.height)
110 tags[1].ti_Data = *args.height;
111 if (args.depth)
112 tags[2].ti_Data = *args.depth;
113 printf("Opening screen, size: %lux%lu, depth: %lu\n", tags[0].ti_Data, tags[1].ti_Data, tags[3].ti_Data);
114 if (args.mode) {
115 tags[3].ti_Tag = SA_DisplayID;
116 tags[3].ti_Data = strtoul(args.mode, NULL, 16);
117 printf("ModeID: 0x%08lX\n", tags[3].ti_Data);
119 if (args.scroll) {
120 tags[4].ti_Tag = SA_AutoScroll;
121 tags[4].ti_Data = *args.scroll;
122 printf("SA_Autoscroll: %ld\n", tags[4].ti_Data);
124 if (args.drag) {
125 tags[5].ti_Tag = SA_Draggable;
126 tags[5].ti_Data = *args.drag;
127 printf("SA_Draggable: %ld\n", tags[5].ti_Data);
129 if (args.likewb) {
130 tags[6].ti_Tag = SA_LikeWorkbench;
131 tags[6].ti_Data = *args.likewb;
132 printf("SA_LikeWorkbench: %ld\n", tags[6].ti_Data);
134 if (args.oscan) {
135 tags[7].ti_Tag = SA_Overscan;
136 tags[7].ti_Data = *args.oscan;
137 printf("SA_Overscan: %ld\n", tags[7].ti_Data);
139 if (args.left) {
140 tags[8].ti_Tag = SA_Left;
141 tags[8].ti_Data = *args.left;
142 printf("SA_Left: %ld\n", tags[8].ti_Data);
144 if (args.top) {
145 tags[9].ti_Tag = SA_Top;
146 tags[9].ti_Data = *args.top;
147 printf("SA_Left: %ld\n", tags[9].ti_Data);
150 screen = OpenScreenTagList(NULL, tags);
151 if (screen) {
152 w1 = openwindow(screen, "Screen data", W1_LEFT, W1_TOP, W1_WIDTH, W1_HEIGHT);
153 if (w1) {
154 WORD x = w1->BorderLeft;
155 WORD y = w1->BorderTop;
156 struct BitMap *bitmap = screen->RastPort.BitMap;
158 y = drawtext(w1, x, y, "Requested size: %lux%lu", tags[0].ti_Data, tags[1].ti_Data);
159 y = drawtext(w1, x, y, "Requested depth: %lu", tags[2].ti_Data);
160 if (args.mode)
161 y = drawtext(w1, x, y, "Requested ModeID: 0x%08lX", tags[3].ti_Data);
162 y = drawtext(w1, x, y, "Actual size: %ux%u", screen->Width, screen->Height);
163 y = drawtext(w1, x, y, "Actual ModeID: 0x%08X", screen->ViewPort.ColorMap->VPModeID);
164 y = drawtext(w1, x, y, "Flags: 0x%04lX", screen->Flags);
165 y = drawtext(w1, x, y, "BitMap size: %ux%u", GetBitMapAttr(bitmap, BMA_WIDTH), GetBitMapAttr(bitmap, BMA_HEIGHT));
166 y = drawtext(w1, x, y, "BitMap depth: %u", GetBitMapAttr(bitmap, BMA_DEPTH));
167 handleevents(w1, screen, x, y);
168 CloseWindow(w1);
170 CloseScreen(screen);
171 } else
172 printf("Failed to open screen, error: %d\n", oserr);
173 FreeArgs(rda);
174 } else
175 printf("Error parsing arguments\n");
176 CloseLibrary((struct Library *)DOSBase);
178 CloseLibrary((struct Library *)GfxBase);
180 CloseLibrary((struct Library *) IntuitionBase);
182 return 0;
183 } /* main */
187 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h)
190 struct Window *window;
191 printf("Opening window, screen=0x%p\n", screen);
193 window = OpenWindowTags(NULL,
194 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_INTUITICKS,
195 WA_Left, x,
196 WA_Top, y,
197 WA_Width, w,
198 WA_Height, h,
199 WA_CustomScreen, screen,
200 WA_Activate, TRUE,
201 WA_DepthGadget, TRUE,
202 WA_DragBar, TRUE,
203 WA_CloseGadget, TRUE,
204 WA_NoCareRefresh, TRUE,
205 WA_NotifyDepth, TRUE,
206 WA_Title, title,
208 TAG_END);
210 printf("Window opened\n");
212 return window;
215 ULONG handleevents(struct Window *win, struct Screen *screen, WORD x, WORD y)
217 struct IntuiMessage *imsg;
218 WORD y1;
219 struct MsgPort *port = win->UserPort;
220 BOOL terminated = FALSE;
221 ULONG retidcmp = 0;
223 while (!terminated)
225 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
228 switch (imsg->Class)
230 case IDCMP_CLOSEWINDOW:
231 terminated = TRUE;
232 break;
233 case IDCMP_INTUITICKS:
234 y1 = drawtext(win, x, y, "Screen position: (%d, %d) ", screen->LeftEdge, screen->TopEdge);
235 y1 = drawtext(win, x, y1, "Mouse position: (%d, %d) ", screen->MouseX, screen->MouseY);
236 y1 = drawtext(win, x, y1, "ViewPort size: %dx%d ", screen->ViewPort.DWidth, screen->ViewPort.DHeight);
237 y1 = drawtext(win, x, y1, "ViewPort position: (%d, %d) ", screen->ViewPort.DxOffset, screen->ViewPort.DyOffset);
238 drawtext(win, x, y1, "RasInfo position: (%d, %d) ", screen->ViewPort.RasInfo->RxOffset, screen->ViewPort.RasInfo->RyOffset);
239 break;
241 } /* switch (imsg->Class) */
242 ReplyMsg((struct Message *)imsg);
245 } /* if ((imsg = GetMsg(port)) != NULL) */
246 else
248 Wait(1L << port->mp_SigBit);
250 } /* while (!terminated) */
252 return retidcmp;
254 } /* HandleEvents() */