dos.library: Correct the usage of the AROS_CALL4() macro
[AROS.git] / test / screentest.c
blobc9ef08e1e6052a86fae0bf113b881308649c87a1
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 struct myargs
24 LONG *left;
25 LONG *top;
26 LONG *width;
27 LONG *height;
28 LONG *depth;
29 STRPTR mode;
30 LONG *oscan;
31 LONG *scroll;
32 LONG *drag;
33 LONG *likewb;
36 struct IntuitionBase *IntuitionBase;
37 struct GfxBase *GfxBase;
38 struct DosLibrary *DOSBase;
40 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h);
42 ULONG handleevents(struct Window *win, struct Screen *screen, WORD x, WORD y);
44 #define W1_LEFT 100
45 #define W1_TOP 100
46 #define W1_WIDTH 350
47 #define W1_HEIGHT 220
49 WORD drawtext(struct Window *win, WORD x, WORD y, char *fmt, ...)
51 va_list args;
52 char buf[256];
53 struct IntuiText it = {
54 1, 0,
55 JAM2,
56 0, 0,
57 NULL,
58 buf,
59 NULL
62 va_start(args, fmt);
63 vsprintf(buf, fmt, args);
64 va_end(args);
65 PrintIText(win->RPort, &it, x, y);
66 return y + win->IFont->tf_YSize;
69 int __nocommandline = 1;
71 int main(int argc, char **argv)
73 struct myargs args = {NULL};
74 struct RDArgs *rda;
76 if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0)))
78 if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0)))
80 if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0)))
82 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);
83 if (rda) {
84 struct Screen *screen;
85 struct Window *w1;
86 ULONG oserr = 0;
87 struct TagItem tags[] = {
88 {SA_Width, 640 },
89 {SA_Height, 480 },
90 {SA_Depth, 4 },
91 {TAG_IGNORE, 0 },
92 {TAG_IGNORE, 0 },
93 {TAG_IGNORE, 0 },
94 {TAG_IGNORE, 0 },
95 {TAG_IGNORE, 0 },
96 {TAG_IGNORE, 0 },
97 {TAG_IGNORE, 0 },
98 {SA_Title, (IPTR)"Screen opening and movement test"},
99 {SA_ErrorCode, (IPTR)&oserr },
100 {TAG_DONE, 0 }
103 if (args.width)
104 tags[0].ti_Data = *args.width;
105 if (args.height)
106 tags[1].ti_Data = *args.height;
107 if (args.depth)
108 tags[2].ti_Data = *args.depth;
109 printf("Opening screen, size: %lux%lu, depth: %lu\n", tags[0].ti_Data, tags[1].ti_Data, tags[3].ti_Data);
110 if (args.mode) {
111 tags[3].ti_Tag = SA_DisplayID;
112 tags[3].ti_Data = strtoul(args.mode, NULL, 16);
113 printf("ModeID: 0x%08lX\n", tags[3].ti_Data);
115 if (args.scroll) {
116 tags[4].ti_Tag = SA_AutoScroll;
117 tags[4].ti_Data = *args.scroll;
118 printf("SA_Autoscroll: %ld\n", tags[4].ti_Data);
120 if (args.drag) {
121 tags[5].ti_Tag = SA_Draggable;
122 tags[5].ti_Data = *args.drag;
123 printf("SA_Draggable: %ld\n", tags[5].ti_Data);
125 if (args.likewb) {
126 tags[6].ti_Tag = SA_LikeWorkbench;
127 tags[6].ti_Data = *args.likewb;
128 printf("SA_LikeWorkbench: %ld\n", tags[6].ti_Data);
130 if (args.oscan) {
131 tags[7].ti_Tag = SA_Overscan;
132 tags[7].ti_Data = *args.oscan;
133 printf("SA_Overscan: %ld\n", tags[7].ti_Data);
135 if (args.left) {
136 tags[8].ti_Tag = SA_Left;
137 tags[8].ti_Data = *args.left;
138 printf("SA_Left: %ld\n", tags[8].ti_Data);
140 if (args.top) {
141 tags[9].ti_Tag = SA_Top;
142 tags[9].ti_Data = *args.top;
143 printf("SA_Left: %ld\n", tags[9].ti_Data);
146 screen = OpenScreenTagList(NULL, tags);
147 if (screen) {
148 w1 = openwindow(screen, "Screen data", W1_LEFT, W1_TOP, W1_WIDTH, W1_HEIGHT);
149 if (w1) {
150 WORD x = w1->BorderLeft;
151 WORD y = w1->BorderTop;
152 struct BitMap *bitmap = screen->RastPort.BitMap;
154 y = drawtext(w1, x, y, "Requested size: %lux%lu", tags[0].ti_Data, tags[1].ti_Data);
155 y = drawtext(w1, x, y, "Requested depth: %lu", tags[2].ti_Data);
156 if (args.mode)
157 y = drawtext(w1, x, y, "Requested ModeID: 0x%08lX", tags[3].ti_Data);
158 y = drawtext(w1, x, y, "Actual size: %ux%u", screen->Width, screen->Height);
159 y = drawtext(w1, x, y, "Actual ModeID: 0x%08X", screen->ViewPort.ColorMap->VPModeID);
160 y = drawtext(w1, x, y, "Flags: 0x%04lX", screen->Flags);
161 y = drawtext(w1, x, y, "BitMap size: %ux%u", GetBitMapAttr(bitmap, BMA_WIDTH), GetBitMapAttr(bitmap, BMA_HEIGHT));
162 y = drawtext(w1, x, y, "BitMap depth: %u", GetBitMapAttr(bitmap, BMA_DEPTH));
163 handleevents(w1, screen, x, y);
164 CloseWindow(w1);
166 CloseScreen(screen);
167 } else
168 printf("Failed to open screen, error: %d\n", (int)oserr);
169 FreeArgs(rda);
170 } else
171 printf("Error parsing arguments\n");
172 CloseLibrary((struct Library *)DOSBase);
174 CloseLibrary((struct Library *)GfxBase);
176 CloseLibrary((struct Library *) IntuitionBase);
178 return 0;
179 } /* main */
183 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h)
186 struct Window *window;
187 printf("Opening window, screen=0x%p\n", screen);
189 window = OpenWindowTags(NULL,
190 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_INTUITICKS,
191 WA_Left, x,
192 WA_Top, y,
193 WA_Width, w,
194 WA_Height, h,
195 WA_CustomScreen, screen,
196 WA_Activate, TRUE,
197 WA_DepthGadget, TRUE,
198 WA_DragBar, TRUE,
199 WA_CloseGadget, TRUE,
200 WA_NoCareRefresh, TRUE,
201 WA_NotifyDepth, TRUE,
202 WA_Title, title,
204 TAG_END);
206 printf("Window opened\n");
208 return window;
211 ULONG handleevents(struct Window *win, struct Screen *screen, WORD x, WORD y)
213 struct IntuiMessage *imsg;
214 WORD y1;
215 struct MsgPort *port = win->UserPort;
216 BOOL terminated = FALSE;
217 ULONG retidcmp = 0;
219 while (!terminated)
221 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
224 switch (imsg->Class)
226 case IDCMP_CLOSEWINDOW:
227 terminated = TRUE;
228 break;
229 case IDCMP_INTUITICKS:
230 y1 = drawtext(win, x, y, "Screen position: (%d, %d) ", screen->LeftEdge, screen->TopEdge);
231 y1 = drawtext(win, x, y1, "Mouse position: (%d, %d) ", screen->MouseX, screen->MouseY);
232 y1 = drawtext(win, x, y1, "ViewPort size: %dx%d ", screen->ViewPort.DWidth, screen->ViewPort.DHeight);
233 y1 = drawtext(win, x, y1, "ViewPort position: (%d, %d) ", screen->ViewPort.DxOffset, screen->ViewPort.DyOffset);
234 drawtext(win, x, y1, "RasInfo position: (%d, %d) ", screen->ViewPort.RasInfo->RxOffset, screen->ViewPort.RasInfo->RyOffset);
235 break;
237 } /* switch (imsg->Class) */
238 ReplyMsg((struct Message *)imsg);
241 } /* if ((imsg = GetMsg(port)) != NULL) */
242 else
244 Wait(1L << port->mp_SigBit);
246 } /* while (!terminated) */
248 return retidcmp;
250 } /* HandleEvents() */