2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
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>
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
)
58 printf("scrollerwin: %s\n",msg
);
66 for(i
= 0; i
< NUM_GADGETS
;i
++)
68 if (gad
[i
]) RemoveGadget(win
,gad
[i
]);
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
);
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
[] =
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
],
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,
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,
164 GA_Previous
,(IPTR
)gad
[GAD_UPARROW
],
168 gad
[GAD_VERTSCROLL
] = NewObject(0,PROPGCLASS
,
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
],
182 PGA_Freedom
,FREEVERT
,
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
],
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,
200 GA_BottomBorder
,TRUE
,
201 GA_Previous
,(IPTR
)gad
[GAD_RIGHTARROW
],
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
,
219 PGA_Freedom
,FREEHORIZ
,
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
,
235 WA_Title
,(IPTR
)"Scroller Window",
236 WA_SimpleRefresh
,TRUE
,
243 WA_Gadgets
,(IPTR
)firstgadget
,
246 WA_MaxWidth
,scr
->Width
,
247 WA_MaxHeight
,scr
->Height
,
248 WA_IDCMP
,IDCMP_CLOSEWINDOW
| IDCMP_REFRESHWINDOW
,
251 Cleanup("Can't open window!");
254 ScreenToFront(win
->WScreen
);
258 static void HandleAll(void)
260 struct IntuiMessage
*msg
;
266 WaitPort(win
->UserPort
);
267 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
271 case IDCMP_CLOSEWINDOW
:
275 case IDCMP_REFRESHWINDOW
:
277 EndRefresh(win
,TRUE
);
280 ReplyMsg((struct Message
*)msg
);