Turned off debug and bumped revision and date.
[AROS.git] / workbench / demos / palettedemo.c
blob7509abc1fa3f807c1aca076ec505b75debf8de3c
1 /*
2 Copyright © 1995-97, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Demo/test for AROS boopsi objects
6 Lang: english
7 */
9 #include <aros/config.h>
11 #if !(AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
12 # define ENABLE_RT 1
13 #endif
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <proto/graphics.h>
18 #include <intuition/intuition.h>
19 #include <intuition/screens.h>
20 #include <gadgets/arospalette.h>
21 #include <gadgets/aroscheckbox.h>
22 #include <intuition/classes.h>
23 #include <utility/tagitem.h>
25 #include <aros/rt.h>
27 #define SDEBUG 1
28 #define DEBUG 1
29 #include <aros/debug.h>
31 #define GID_PALETTE 1
32 #define GID_PROP 2
34 STATIC VOID HandleEvents(struct Window *);
36 struct IntuitionBase *IntuitionBase;
37 struct Library *AROSPaletteBase;
39 Object *palette, *prop;
42 /*************
43 ** main() **
44 *************/
45 int main(int argc, char **argv)
47 struct Task*inputDevice;
49 EnterFunc(bug("main()\n"));
51 RT_Init();
53 /* Initialize the input.device's tc_UserData to 0 */
54 inputDevice = FindTask("input.device");
55 if (inputDevice)
57 D(bug("Initializing input device's indent count\n"));
58 inputDevice->tc_UserData = NULL;
62 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
63 if (IntuitionBase)
65 D(bug("Intuiton opened\n"));
67 AROSPaletteBase = OpenLibrary(AROSPALETTENAME, 0);
68 if (AROSPaletteBase)
70 struct Screen *scr;
72 D(bug("AROSPalette opened\n"));
74 scr = LockPubScreen(NULL);
75 if (scr)
77 struct Window *window;
79 D(bug("Got screen %p\n", scr));
81 window = OpenWindowTags(NULL,
82 WA_PubScreen, (IPTR) scr,
83 WA_Left, 0,
84 WA_Top, 0,
85 WA_Width, 600,
86 WA_Height, 300,
87 WA_MinWidth, 100,
88 WA_MinHeight, 100,
89 WA_MaxWidth, 10000,
90 WA_MaxHeight, 10000,
91 WA_Title, (IPTR) "Try resize to another aspect ratio",
92 WA_IDCMP,
93 IDCMP_GADGETUP
94 | IDCMP_MOUSEMOVE
95 | IDCMP_MOUSEBUTTONS
96 | IDCMP_REFRESHWINDOW
97 | IDCMP_CLOSEWINDOW
98 | IDCMP_NEWSIZE
99 | IDCMP_RAWKEY,
100 WA_SimpleRefresh, TRUE,
101 WA_DragBar, TRUE,
102 WA_CloseGadget, TRUE,
103 WA_SizeGadget, TRUE,
104 WA_DepthGadget, TRUE,
105 TAG_DONE);
108 if (window)
110 D(bug("Window opened\n"));
112 palette = NewObject(NULL, AROSPALETTECLASS,
113 GA_Left, window->BorderLeft + 5,
114 GA_Top, window->BorderTop * 2 + 5,
115 GA_RelWidth, -(window->BorderLeft + window->BorderRight + 10),
116 GA_RelHeight, -(window->BorderTop * 2 + window->BorderBottom + 30),
117 GA_RelVerify, TRUE,
118 GA_ID, GID_PALETTE,
119 AROSA_Palette_Depth, 3,
120 AROSA_Palette_IndicatorWidth, 40,
121 GA_Text, (IPTR) "Palette gadget",
122 GA_LabelPlace, GV_LabelPlace_Above,
123 TAG_DONE);
125 prop = NewObject(NULL, PROPGCLASS,
126 GA_RelVerify, TRUE,
127 GA_Left, 10,
128 GA_RelBottom, -(window->BorderBottom + 22),
129 GA_RelWidth, -(window->BorderLeft + window->BorderRight + 10),
130 GA_Height, 18,
131 GA_Previous, (IPTR) palette,
132 GA_ID, GID_PROP,
133 PGA_Total, 8,
134 PGA_Visible, 1,
135 PGA_Top, 2,
136 PGA_Freedom, FREEHORIZ,
137 TAG_DONE);
139 if (palette && prop)
141 D(bug("Palette created\n"));
143 D(bug("Adding Palette\n"));
144 AddGList(window, (struct Gadget *)palette, 0, 2, NULL);
146 D(bug("Refreshing Palette\n"));
147 RefreshGList((struct Gadget *)palette, window, NULL, 2);
149 HandleEvents(window);
153 CloseWindow(window);
155 if (prop)
156 DisposeObject(prop);
157 if (palette)
158 DisposeObject(palette);
160 } /* if (window opened) */
162 UnlockPubScreen(NULL, scr);
163 } /*if (screen locked) */
165 CloseLibrary(AROSPaletteBase);
166 } /* if (paletteclass opened) */
168 CloseLibrary((struct Library *)IntuitionBase);
169 } /* if (intuition opened) */
171 RT_Exit();
173 ReturnInt ("main", int, 0);
177 /*******************
178 ** HandleEvents **
179 *******************/
180 VOID HandleEvents(struct Window *win)
182 struct IntuiMessage *imsg;
183 struct MsgPort *port = win->UserPort;
184 BOOL terminated = FALSE;
186 EnterFunc(bug("HandleEvents(win=%p)\n", win));
188 while (!terminated)
190 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
193 switch (imsg->Class)
196 case IDCMP_GADGETUP: {
198 Object *gad;
200 D(bug("Recieved gadgetup"));
202 gad = (Object *)imsg->IAddress;
204 switch (((struct Gadget *)gad)->GadgetID)
206 case GID_PALETTE:
207 D(bug("Color selected: %d\n", imsg->Code));
208 break;
210 case GID_PROP:
211 D(bug("Changed to depth %d\n", imsg->Code));
212 /* Update the palette gadget accordingly */
213 SetGadgetAttrs((struct Gadget *)palette, win, NULL,
214 AROSA_Palette_Depth, imsg->Code + 1,
215 TAG_DONE);
216 RefreshGList((struct Gadget *)palette, win, NULL, 1);
217 break;
219 } break;
221 case IDCMP_REFRESHWINDOW:
222 BeginRefresh(win);
223 EndRefresh(win, TRUE);
224 break;
226 case IDCMP_RAWKEY:
227 case IDCMP_CLOSEWINDOW:
228 terminated = TRUE;
229 break;
231 } /* switch (imsg->Class) */
232 ReplyMsg((struct Message *)imsg);
235 } /* if ((imsg = GetMsg(port)) != NULL) */
236 else
238 Wait(1L << port->mp_SigBit);
240 } /* while (!terminated) */
242 ReturnVoid("HandleEvents");
243 } /* HandleEvents() */