disable changefrequency code temporarily since it is leaving the controller in an...
[AROS.git] / test / customscreen.c
blob4a063316af745f1f290e1e8cc13ca394100e7213
1 /*
2 Example for custom screen
4 This time we are setting the colors directly.
5 */
7 #include <proto/exec.h>
8 #include <proto/dos.h>
9 #include <proto/graphics.h>
10 #include <proto/intuition.h>
12 #include <stdlib.h>
14 static struct Window *window;
15 static struct Screen *screen;
16 static struct RastPort *rp;
18 static void clean_exit(CONST_STRPTR s);
19 static void draw_stuff(void);
20 static void handle_events(void);
23 Initial color values for the screen.
24 Must be an array with index, red, green, blue for each color.
25 The range for each color component is between 0 and 255.
27 static struct ColorSpec colors[] =
29 {0, 240, 100, 0}, // Color 0 is background
30 {1, 240, 0, 0},
31 {2, 0, 0, 240},
32 {-1} // Array must be terminated with -1
36 int main(void)
38 screen = OpenScreenTags(NULL,
39 SA_Width, 800,
40 SA_Height, 600,
41 SA_Depth, 16,
42 SA_Colors, colors,
43 TAG_END);
45 if (! screen) clean_exit("Can't open screen\n");
47 window = OpenWindowTags(NULL,
48 WA_Activate, TRUE,
49 WA_Borderless, TRUE,
50 WA_Backdrop, TRUE,
51 WA_IDCMP, IDCMP_VANILLAKEY,
52 WA_RMBTrap, TRUE,
53 WA_NoCareRefresh, TRUE, // We don't want to listen to refresh messages
54 WA_CustomScreen, screen, // Link to screen
55 TAG_END);
57 if (! window) clean_exit("Can't open window\n");
59 rp = window->RPort;
61 draw_stuff();
63 handle_events();
65 clean_exit(NULL);
67 return 0;
70 static void draw_stuff(void)
72 SetAPen(rp, 1);
73 Move(rp, 100, 50);
74 Text(rp, "Press any key to quit", 21);
76 Move(rp, 100, 100);
77 Draw(rp, 500, 100);
79 SetAPen(rp, 2);
80 Move(rp, 100, 200);
81 Draw(rp, 500, 200);
84 We can change single colors with SetRGB32() or a range of
85 colors with LoadRGB32(). In contrast to the color table above
86 we need 32 bit values for the color components.
88 SetRGB32(&screen->ViewPort, 2, 0, 0xFFFFFFFF, 0);
91 Even when we use the same pen number as before we have to
92 set it again.
94 SetAPen(rp, 2);
95 Move(rp, 100, 300);
96 Draw(rp, 500, 300);
100 static void handle_events(void)
102 struct IntuiMessage *imsg;
103 struct MsgPort *port = window->UserPort;
105 BOOL terminated = FALSE;
107 while (! terminated)
109 Wait(1L << port->mp_SigBit);
111 while ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
113 switch (imsg->Class)
115 case IDCMP_VANILLAKEY:
116 terminated = TRUE;
117 break;
119 ReplyMsg((struct Message *)imsg);
125 static void clean_exit(CONST_STRPTR s)
127 if (s) PutStr(s);
129 // Give back allocated resourses
130 if (window) CloseWindow(window);
131 if (screen) CloseScreen(screen);
133 exit(0);