2 Example for custom screen
4 This time we are setting the colors directly.
7 #include <proto/exec.h>
9 #include <proto/graphics.h>
10 #include <proto/intuition.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
32 {-1} // Array must be terminated with -1
38 screen
= OpenScreenTags(NULL
,
45 if (! screen
) clean_exit("Can't open screen\n");
47 window
= OpenWindowTags(NULL
,
51 WA_IDCMP
, IDCMP_VANILLAKEY
,
53 WA_NoCareRefresh
, TRUE
, // We don't want to listen to refresh messages
54 WA_CustomScreen
, screen
, // Link to screen
57 if (! window
) clean_exit("Can't open window\n");
70 static void draw_stuff(void)
74 Text(rp
, "Press any key to quit", 21);
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
100 static void handle_events(void)
102 struct IntuiMessage
*imsg
;
103 struct MsgPort
*port
= window
->UserPort
;
107 BOOL terminated
= FALSE
;
111 signals
= Wait(1L << port
->mp_SigBit
);
113 while ((imsg
= (struct IntuiMessage
*)GetMsg(port
)) != NULL
)
117 case IDCMP_VANILLAKEY
:
121 ReplyMsg((struct Message
*)imsg
);
127 static void clean_exit(CONST_STRPTR s
)
131 // Give back allocated resourses
132 if (window
) CloseWindow(window
);
133 if (screen
) CloseScreen(screen
);