Change gfx.hidd API -:
[AROS.git] / test / intuition / scrollerwin.c
blobadeb21854bc47f63327d17c336b665d3a6ce04c5
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dos.h>
7 #include <intuition/intuition.h>
8 #include <intuition/imageclass.h>
9 #include <intuition/gadgetclass.h>
10 #include <graphics/gfx.h>
11 #include <utility/hooks.h>
13 #include <proto/exec.h>
14 #include <proto/intuition.h>
15 #include <proto/graphics.h>
16 #include <proto/alib.h>
18 #include <stdio.h>
19 #include <stdlib.h>
21 enum
23 GAD_UPARROW,
24 GAD_DOWNARROW,
25 GAD_LEFTARROW,
26 GAD_RIGHTARROW,
27 GAD_VERTSCROLL,
28 GAD_HORIZSCROLL,
29 NUM_GADGETS
32 enum
34 IMG_UPARROW,
35 IMG_DOWNARROW,
36 IMG_LEFTARROW,
37 IMG_RIGHTARROW,
38 IMG_SIZE,
39 NUM_IMAGES
42 struct IntuitionBase *IntuitionBase;
43 struct GfxBase *GfxBase;
45 static struct Screen *scr;
46 static struct Window *win;
47 static struct DrawInfo *dri;
49 static struct Gadget *gad[NUM_GADGETS], *firstgadget;
50 static struct Image *img[NUM_GADGETS];
52 static void Cleanup(char *msg)
54 WORD rc, i;
56 if (msg)
58 printf("scrollerwin: %s\n",msg);
59 rc = RETURN_WARN;
60 } else {
61 rc = RETURN_OK;
64 if (win)
66 for(i = 0; i < NUM_GADGETS;i++)
68 if (gad[i]) RemoveGadget(win,gad[i]);
71 CloseWindow(win);
74 for(i = 0; i < NUM_GADGETS;i++)
76 if (gad[i]) DisposeObject(gad[i]);
78 for(i = 0; i < NUM_IMAGES;i++)
80 if (img[i]) DisposeObject(img[i]);
83 if (dri) FreeScreenDrawInfo(scr,dri);
84 if (scr) UnlockPubScreen(0,scr);
86 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
87 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
89 exit(rc);
92 static void OpenLibs(void)
94 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
96 Cleanup("Can't open intuition.library V39!");
99 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
101 Cleanup("Can't open graphics.library V39!");
105 static void GetVisual(void)
107 if (!(scr = LockPubScreen(0)))
109 Cleanup("Can't lock pub screen!");
112 if (!(dri = GetScreenDrawInfo(scr)))
114 Cleanup("Can't get drawinfo!");
118 static void MakeGadgets(void)
120 static WORD img2which[] =
122 UPIMAGE,
123 DOWNIMAGE,
124 LEFTIMAGE,
125 RIGHTIMAGE,
126 SIZEIMAGE
129 IPTR imagew[NUM_IMAGES],imageh[NUM_IMAGES];
130 WORD v_offset,h_offset, btop, i;
132 for(i = 0;i < NUM_IMAGES;i++)
134 img[i] = NewObject(0,SYSICLASS,SYSIA_DrawInfo,(IPTR)dri,
135 SYSIA_Which,img2which[i],
136 TAG_DONE);
138 if (!img[i]) Cleanup("Can't create SYSICLASS image!");
140 GetAttr(IA_Width,(Object *)img[i],&imagew[i]);
141 GetAttr(IA_Height,(Object *)img[i],&imageh[i]);
144 btop = scr->WBorTop + dri->dri_Font->tf_YSize + 1;
146 v_offset = imagew[IMG_DOWNARROW] / 4;
147 h_offset = imageh[IMG_LEFTARROW] / 4;
149 firstgadget = gad[GAD_UPARROW] = NewObject(0,BUTTONGCLASS,
150 GA_Image,(IPTR)img[IMG_UPARROW],
151 GA_RelRight,-imagew[IMG_UPARROW] + 1,
152 GA_RelBottom,-imageh[IMG_DOWNARROW] - imageh[IMG_UPARROW] - imageh[IMG_SIZE] + 1,
153 GA_ID,GAD_UPARROW,
154 GA_RightBorder,TRUE,
155 GA_Immediate,TRUE,
156 TAG_DONE);
158 gad[GAD_DOWNARROW] = NewObject(0,BUTTONGCLASS,
159 GA_Image,(IPTR)img[IMG_DOWNARROW],
160 GA_RelRight,-imagew[IMG_UPARROW] + 1,
161 GA_RelBottom,-imageh[IMG_UPARROW] - imageh[IMG_SIZE] + 1,
162 GA_ID,GAD_DOWNARROW,
163 GA_RightBorder,TRUE,
164 GA_Previous,(IPTR)gad[GAD_UPARROW],
165 GA_Immediate,TRUE,
166 TAG_DONE);
168 gad[GAD_VERTSCROLL] = NewObject(0,PROPGCLASS,
169 GA_Top,btop + 1,
170 GA_RelRight,-imagew[IMG_DOWNARROW] + v_offset + 1,
171 GA_Width,imagew[IMG_DOWNARROW] - v_offset * 2,
172 GA_RelHeight,-imageh[IMG_DOWNARROW] - imageh[IMG_UPARROW] - imageh[IMG_SIZE] - btop -2,
173 GA_ID,GAD_VERTSCROLL,
174 GA_Previous,(IPTR)gad[GAD_DOWNARROW],
175 GA_RightBorder,TRUE,
176 GA_RelVerify,TRUE,
177 GA_Immediate,TRUE,
178 PGA_NewLook,TRUE,
179 PGA_Borderless,TRUE,
180 PGA_Total,100,
181 PGA_Visible,20,
182 PGA_Freedom,FREEVERT,
183 TAG_DONE);
185 gad[GAD_RIGHTARROW] = NewObject(0,BUTTONGCLASS,
186 GA_Image,(IPTR)img[IMG_RIGHTARROW],
187 GA_RelRight,-imagew[IMG_SIZE] - imagew[IMG_RIGHTARROW] + 1,
188 GA_RelBottom,-imageh[IMG_RIGHTARROW] + 1,
189 GA_ID,GAD_RIGHTARROW,
190 GA_BottomBorder,TRUE,
191 GA_Previous,(IPTR)gad[GAD_VERTSCROLL],
192 GA_Immediate,TRUE,
193 TAG_DONE);
195 gad[GAD_LEFTARROW] = NewObject(0,BUTTONGCLASS,
196 GA_Image,(IPTR)img[IMG_LEFTARROW],
197 GA_RelRight,-imagew[IMG_SIZE] - imagew[IMG_RIGHTARROW] - imagew[IMG_LEFTARROW] + 1,
198 GA_RelBottom,-imageh[IMG_RIGHTARROW] + 1,
199 GA_ID,GAD_LEFTARROW,
200 GA_BottomBorder,TRUE,
201 GA_Previous,(IPTR)gad[GAD_RIGHTARROW],
202 GA_Immediate,TRUE,
203 TAG_DONE);
205 gad[GAD_HORIZSCROLL] = NewObject(0,PROPGCLASS,
206 GA_Left,scr->WBorLeft,
207 GA_RelBottom,-imageh[IMG_LEFTARROW] + h_offset + 1,
208 GA_RelWidth,-imagew[IMG_LEFTARROW] - imagew[IMG_RIGHTARROW] - imagew[IMG_SIZE] - scr->WBorRight - 2,
209 GA_Height,imageh[IMG_LEFTARROW] - (h_offset * 2),
210 GA_ID,GAD_HORIZSCROLL,
211 GA_Previous,(IPTR)gad[GAD_LEFTARROW],
212 GA_BottomBorder,TRUE,
213 GA_RelVerify,TRUE,
214 GA_Immediate,TRUE,
215 PGA_NewLook,TRUE,
216 PGA_Borderless,TRUE,
217 PGA_Total,100,
218 PGA_Visible,20,
219 PGA_Freedom,FREEHORIZ,
220 TAG_DONE);
222 for(i = 0;i < NUM_GADGETS;i++)
224 if (!gad[i]) Cleanup("Can't create gadget!");
228 static void MakeWin(void)
230 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
231 WA_Left,10,
232 WA_Top,10,
233 WA_Width,300,
234 WA_Height,150,
235 WA_Title,(IPTR)"Scroller Window",
236 WA_SimpleRefresh,TRUE,
237 WA_CloseGadget,TRUE,
238 WA_DepthGadget,TRUE,
239 WA_DragBar,TRUE,
240 WA_SizeGadget,TRUE,
241 WA_SizeBBottom,TRUE,
242 WA_SizeBRight,TRUE,
243 WA_Gadgets,(IPTR)firstgadget,
244 WA_MinWidth,50,
245 WA_MinHeight,50,
246 WA_MaxWidth,scr->Width,
247 WA_MaxHeight,scr->Height,
248 WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
249 TAG_DONE)))
251 Cleanup("Can't open window!");
254 ScreenToFront(win->WScreen);
258 static void HandleAll(void)
260 struct IntuiMessage *msg;
262 BOOL quitme = FALSE;
264 while(!quitme)
266 WaitPort(win->UserPort);
267 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
269 switch(msg->Class)
271 case IDCMP_CLOSEWINDOW:
272 quitme = TRUE;
273 break;
275 case IDCMP_REFRESHWINDOW:
276 BeginRefresh(win);
277 EndRefresh(win,TRUE);
278 break;
280 ReplyMsg((struct Message *)msg);
285 int main(void)
287 OpenLibs();
288 GetVisual();
289 MakeGadgets();
290 MakeWin();
291 HandleAll();
292 Cleanup(0);
293 return 0;