2 #include <intuition/intuition.h>
3 #include <intuition/imageclass.h>
4 #include <intuition/gadgetclass.h>
5 #include <graphics/gfx.h>
6 #include <utility/hooks.h>
8 #include <proto/exec.h>
9 #include <proto/intuition.h>
10 #include <proto/graphics.h>
11 #include <proto/alib.h>
37 struct IntuitionBase
*IntuitionBase
;
38 struct GfxBase
*GfxBase
;
40 static struct Screen
*scr
;
41 static struct Window
*win
;
42 static struct DrawInfo
*dri
;
44 static struct Gadget
*gad
[NUM_GADGETS
], *firstgadget
;
45 static struct Image
*img
[NUM_GADGETS
];
47 static void Cleanup(char *msg
)
53 printf("scrollerwin: %s\n",msg
);
61 for(i
= 0; i
< NUM_GADGETS
;i
++)
63 if (gad
[i
]) RemoveGadget(win
,gad
[i
]);
69 for(i
= 0; i
< NUM_GADGETS
;i
++)
71 if (gad
[i
]) DisposeObject(gad
[i
]);
73 for(i
= 0; i
< NUM_IMAGES
;i
++)
75 if (img
[i
]) DisposeObject(img
[i
]);
78 if (dri
) FreeScreenDrawInfo(scr
,dri
);
79 if (scr
) UnlockPubScreen(0,scr
);
81 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
82 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
87 static void OpenLibs(void)
89 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",39)))
91 Cleanup("Can't open intuition.library V39!");
94 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",39)))
96 Cleanup("Can't open graphics.library V39!");
100 static void GetVisual(void)
102 if (!(scr
= LockPubScreen(0)))
104 Cleanup("Can't lock pub screen!");
107 if (!(dri
= GetScreenDrawInfo(scr
)))
109 Cleanup("Can't get drawinfo!");
113 static void MakeGadgets(void)
115 static WORD img2which
[] =
124 IPTR imagew
[NUM_IMAGES
],imageh
[NUM_IMAGES
];
125 WORD v_offset
,h_offset
, btop
, i
;
127 for(i
= 0;i
< NUM_IMAGES
;i
++)
129 img
[i
] = NewObject(0,SYSICLASS
,SYSIA_DrawInfo
,(IPTR
)dri
,
130 SYSIA_Which
,img2which
[i
],
133 if (!img
[i
]) Cleanup("Can't create SYSICLASS image!");
135 GetAttr(IA_Width
,(Object
*)img
[i
],&imagew
[i
]);
136 GetAttr(IA_Height
,(Object
*)img
[i
],&imageh
[i
]);
139 btop
= scr
->WBorTop
+ dri
->dri_Font
->tf_YSize
+ 1;
141 v_offset
= imagew
[IMG_DOWNARROW
] / 4;
142 h_offset
= imageh
[IMG_LEFTARROW
] / 4;
144 firstgadget
= gad
[GAD_UPARROW
] = NewObject(0,BUTTONGCLASS
,
145 GA_Image
,(IPTR
)img
[IMG_UPARROW
],
146 GA_RelRight
,-imagew
[IMG_UPARROW
] + 1,
147 GA_RelBottom
,-imageh
[IMG_DOWNARROW
] - imageh
[IMG_UPARROW
] - imageh
[IMG_SIZE
] + 1,
153 gad
[GAD_DOWNARROW
] = NewObject(0,BUTTONGCLASS
,
154 GA_Image
,(IPTR
)img
[IMG_DOWNARROW
],
155 GA_RelRight
,-imagew
[IMG_UPARROW
] + 1,
156 GA_RelBottom
,-imageh
[IMG_UPARROW
] - imageh
[IMG_SIZE
] + 1,
159 GA_Previous
,(IPTR
)gad
[GAD_UPARROW
],
163 gad
[GAD_VERTSCROLL
] = NewObject(0,PROPGCLASS
,
165 GA_RelRight
,-imagew
[IMG_DOWNARROW
] + v_offset
+ 1,
166 GA_Width
,imagew
[IMG_DOWNARROW
] - v_offset
* 2,
167 GA_RelHeight
,-imageh
[IMG_DOWNARROW
] - imageh
[IMG_UPARROW
] - imageh
[IMG_SIZE
] - btop
-2,
168 GA_ID
,GAD_VERTSCROLL
,
169 GA_Previous
,(IPTR
)gad
[GAD_DOWNARROW
],
177 PGA_Freedom
,FREEVERT
,
180 gad
[GAD_RIGHTARROW
] = NewObject(0,BUTTONGCLASS
,
181 GA_Image
,(IPTR
)img
[IMG_RIGHTARROW
],
182 GA_RelRight
,-imagew
[IMG_SIZE
] - imagew
[IMG_RIGHTARROW
] + 1,
183 GA_RelBottom
,-imageh
[IMG_RIGHTARROW
] + 1,
184 GA_ID
,GAD_RIGHTARROW
,
185 GA_BottomBorder
,TRUE
,
186 GA_Previous
,(IPTR
)gad
[GAD_VERTSCROLL
],
190 gad
[GAD_LEFTARROW
] = NewObject(0,BUTTONGCLASS
,
191 GA_Image
,(IPTR
)img
[IMG_LEFTARROW
],
192 GA_RelRight
,-imagew
[IMG_SIZE
] - imagew
[IMG_RIGHTARROW
] - imagew
[IMG_LEFTARROW
] + 1,
193 GA_RelBottom
,-imageh
[IMG_RIGHTARROW
] + 1,
195 GA_BottomBorder
,TRUE
,
196 GA_Previous
,(IPTR
)gad
[GAD_RIGHTARROW
],
200 gad
[GAD_HORIZSCROLL
] = NewObject(0,PROPGCLASS
,
201 GA_Left
,scr
->WBorLeft
,
202 GA_RelBottom
,-imageh
[IMG_LEFTARROW
] + h_offset
+ 1,
203 GA_RelWidth
,-imagew
[IMG_LEFTARROW
] - imagew
[IMG_RIGHTARROW
] - imagew
[IMG_SIZE
] - scr
->WBorRight
- 2,
204 GA_Height
,imageh
[IMG_LEFTARROW
] - (h_offset
* 2),
205 GA_ID
,GAD_HORIZSCROLL
,
206 GA_Previous
,(IPTR
)gad
[GAD_LEFTARROW
],
207 GA_BottomBorder
,TRUE
,
214 PGA_Freedom
,FREEHORIZ
,
217 for(i
= 0;i
< NUM_GADGETS
;i
++)
219 if (!gad
[i
]) Cleanup("Can't create gadget!");
223 static void MakeWin(void)
225 if (!(win
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
230 WA_Title
,(IPTR
)"Scroller Window",
231 WA_SimpleRefresh
,TRUE
,
238 WA_Gadgets
,(IPTR
)firstgadget
,
241 WA_MaxWidth
,scr
->Width
,
242 WA_MaxHeight
,scr
->Height
,
243 WA_IDCMP
,IDCMP_CLOSEWINDOW
| IDCMP_REFRESHWINDOW
,
246 Cleanup("Can't open window!");
249 ScreenToFront(win
->WScreen
);
253 static void HandleAll(void)
255 struct IntuiMessage
*msg
;
261 WaitPort(win
->UserPort
);
262 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
266 case IDCMP_CLOSEWINDOW
:
270 case IDCMP_REFRESHWINDOW
:
272 EndRefresh(win
,TRUE
);
275 ReplyMsg((struct Message
*)msg
);