- Go back to using IoErr() to retrieve error codes.
[AROS.git] / test / customscreen.c
blobabfa66281f2312eb8cfa4dda76bb44e723cbb5e6
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 Example for custom screen
9 This time we are setting the colors directly.
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/graphics.h>
15 #include <proto/intuition.h>
17 #include <stdlib.h>
19 static struct Window *window;
20 static struct Screen *screen;
21 static struct RastPort *rp;
23 static void clean_exit(CONST_STRPTR s);
24 static void draw_stuff(void);
25 static void handle_events(void);
28 Initial color values for the screen.
29 Must be an array with index, red, green, blue for each color.
30 The range for each color component is between 0 and 255.
32 static struct ColorSpec colors[] =
34 {0, 240, 100, 0}, // Color 0 is background
35 {1, 240, 0, 0},
36 {2, 0, 0, 240},
37 {-1} // Array must be terminated with -1
41 int main(void)
43 screen = OpenScreenTags(NULL,
44 SA_Width, 800,
45 SA_Height, 600,
46 SA_Depth, 16,
47 SA_Colors, colors,
48 TAG_END);
50 if (! screen) clean_exit("Can't open screen\n");
52 window = OpenWindowTags(NULL,
53 WA_Activate, TRUE,
54 WA_Borderless, TRUE,
55 WA_Backdrop, TRUE,
56 WA_IDCMP, IDCMP_VANILLAKEY,
57 WA_RMBTrap, TRUE,
58 WA_NoCareRefresh, TRUE, // We don't want to listen to refresh messages
59 WA_CustomScreen, screen, // Link to screen
60 TAG_END);
62 if (! window) clean_exit("Can't open window\n");
64 rp = window->RPort;
66 draw_stuff();
68 handle_events();
70 clean_exit(NULL);
72 return 0;
75 static void draw_stuff(void)
77 SetAPen(rp, 1);
78 Move(rp, 100, 50);
79 Text(rp, "Press any key to quit", 21);
81 Move(rp, 100, 100);
82 Draw(rp, 500, 100);
84 SetAPen(rp, 2);
85 Move(rp, 100, 200);
86 Draw(rp, 500, 200);
89 We can change single colors with SetRGB32() or a range of
90 colors with LoadRGB32(). In contrast to the color table above
91 we need 32 bit values for the color components.
93 SetRGB32(&screen->ViewPort, 2, 0, 0xFFFFFFFF, 0);
96 Even when we use the same pen number as before we have to
97 set it again.
99 SetAPen(rp, 2);
100 Move(rp, 100, 300);
101 Draw(rp, 500, 300);
105 static void handle_events(void)
107 struct IntuiMessage *imsg;
108 struct MsgPort *port = window->UserPort;
110 BOOL terminated = FALSE;
112 while (! terminated)
114 Wait(1L << port->mp_SigBit);
116 while ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
118 switch (imsg->Class)
120 case IDCMP_VANILLAKEY:
121 terminated = TRUE;
122 break;
124 ReplyMsg((struct Message *)imsg);
130 static void clean_exit(CONST_STRPTR s)
132 if (s) PutStr(s);
134 // Give back allocated resourses
135 if (window) CloseWindow(window);
136 if (screen) CloseScreen(screen);
138 exit(0);