4 ; Background-drawing viewers
6 ; © 1995-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Standard header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
45 ;----- Main code ------------------------------------------------------------
47 ; Some of this makes deep assumptions about the way viewer works and which
48 ; registers we /can/ corrupt even though the docs say otherwise. That's OK
49 ; though. We don't care.
51 AREA |Sapphire$$Code|,CODE,READONLY
53 ; --- gallery_eventHandler ---
55 ; On entry: R0 == viewer handle
56 ; R1 == pointer to handler routine
57 ; R2 == R10 value to pass to handler
58 ; R3 == R12 value to pass to handler
62 ; Use: Sets up an event handler for the viewer, and adds in
63 ; gallery's own special processing for background drawing.
65 EXPORT gallery_eventHandler
66 gallery_eventHandler ROUT
68 STMFD R13!,{R4,R14} ;Save some registers
69 ADD R14,R0,#vw__handler+4 ;Find some spare space
70 MOV R4,R1 ;And get R10 value in R4
71 STMIA R14,{R2-R4} ;Store the new handler
72 ADR R4,gl__events ;Point to our handler
73 STR R4,[R0,#vw__handler] ;And store that away
74 LDMFD R13!,{R4,PC}^ ;And return to caller
78 ; --- gallery_drawBox ---
80 ; On entry: R0-R3 == window relative coords of box to plot
84 ; Use: Draws a box to indicate tht this item hasn't been
85 ; displayed yet. Use this routine to give a consistant
86 ; look to applications which use the gallery.
88 EXPORT gallery_drawBox
91 STMFD R13!,{R0,R1,R14} ;Stack some registers
92 SUB R13,R13,#32 ;Get room for an icon block
93 STMIA R13,{R0-R3} ;Store away the coordinates
94 MOV R0,#&00000024 ;The icon flags
95 ORR R0,R0,#&27000000 ;Compete them
96 STR R0,[R13,#16] ;Store the icon flags
97 MOV R1,R13 ;Point to the block
98 SWI Wimp_PlotIcon ;Plot the icon
99 ADD R13,R13,#32 ;Increment the stack again
100 LDMFD R13!,{R0,R1,PC}^ ;Return to caller
104 ; --- gallery_removeBox ---
106 ; On entry: R0-R3 == window relative coords of box to remove
110 ; Use: Removes a previously draw temporary box. It is assumed that
111 ; the background colour of the viewere is 1.
113 EXPORT gallery_removeBox
114 gallery_removeBox ROUT
116 STMFD R13!,{R0,R1,R14} ;Stack some registers
117 SUB R13,R13,#32 ;Get room for an icon block
118 STMIA R13,{R0-R3} ;Store away the coordinates
119 MOV R0,#&00000024 ;The icon flags
120 ORR R0,R0,#&11000000 ;Compete them
121 STR R0,[R13,#16] ;Store the icon flags
122 MOV R1,R13 ;Point to the block
123 SWI Wimp_PlotIcon ;Plot the icon
124 ADD R13,R13,#32 ;Increment the stack again
125 LDMFD R13!,{R0,R1,PC}^ ;Return to caller
131 ; On entry: R0 == event code
132 ; R1-R7 == information from viewer
134 ; On exit: exits via user handler
136 ; Use: Intercepts viewer events to do background redraw.
140 CMP R0,#vwEvent_redraw ;Is this a redraw request?
141 LDRNE PC,[R9,#gl__handler] ;No -- pass it on then
143 STMFD R13!,{R0-R3,R10,R14} ;Save some registers
144 MOV R10,R9 ;Point to viewer block
145 MOV R0,#vwShape_slowBit ;Is this intersecting?
146 BL vw__callShape ;Call the shape function
147 BCC %10gl__events ;No -- then skip round
149 MOV R0,#0 ;This icon is not drawn yet
150 BL gl__drawn ;So set the flag up nicely
152 LDR R14,[R10,#vw__flags] ;Load the flags word
153 TST R14,#glFlag__drawing ;Do we have the idle going?
154 BNE %10gl__events ;Yes -- then skip on
156 ORR R14,R14,#glFlag__drawing;No -- set the flag then
157 STR R14,[R10,#vw__flags] ;And store them back again
158 MOV R0,#0 ;Call me all the time
159 ADR R1,gl__idles ;No -- point to the handler
160 MOV R2,R10 ;Point to the viewer block
161 MOV R3,R12 ;Point to someone else's wsp
162 BL idle_handler ;Register the handler
164 10gl__events LDMFD R13!,{R0-R3,R10,R14} ;And return to caller
165 LDR PC,[R9,#gl__handler] ;Continue processing event
169 ; --- gallery_reset ---
171 ; On entry: R0 == viewer handle
175 ; Use: Resets all the icons in the gallery to their `undrawn' state.
176 ; Use this before opening the window etc.
181 STMFD R13!,{R0-R4,R10,R14} ;Save some registers
182 MOV R10,R0 ;Get the viewer handle
183 MOV R1,#0 ;Start at the beginning
184 LDR R4,[R10,#vw__listDef] ;Find the list definition
185 00 LDR R0,[R10,#vw__list] ;Find the list base address
186 MOV R2,#2 ;Match drawn icons
187 MOV R3,#2 ;And only the drawn ones
188 MOV R14,PC ;Set up the return address
189 ADD PC,R4,#vw__enumerate ;Find the next item
190 BCC %f00 ;When finished, skip out
191 MOV R3,#0 ;Clear the bit now
192 MOV R14,PC ;Set up return address
193 ADD PC,R4,#vw__setFlags ;Set up the flags nicely
194 B %b00 ;And loop back round again
195 00 LDMFD R13!,{R0-R4,R10,PC}^ ;And return to caller
201 ; On entry: R10 == pointer to viewer block
205 ; Use: Redraws the first unredrawn item in the viewer.
209 STMFD R13!,{R0-R4,R14} ;Save some registers
210 SUB R13,R13,#36 ;Make space for a window blk
211 LDR R14,[R10,#vw__window] ;Load the window handle
212 STR R14,[R13,#0] ;Store it in the block
213 MOV R1,R13 ;Point to the block
214 SWI Wimp_GetWindowState ;Get the window information
215 MOV R3,R13 ;And again please
216 BL gl__clipBlock ;Build the clipping info
218 MOV R1,#0 ;Start at the beginning
219 00 ADD R2,R13,#16 ;Point to a spare bit of blk
220 BL vw__enum ;Get another icon to do
221 BCC %50gl__idles ;No icons -- remove handler
222 BL vw__intSimple ;Do the boxes intersect?
223 BLCS gl__isDrawn ;Is the thing drawn yet?
224 BCC %b00 ;No -- then skip back
226 ; --- Draw this item ---
228 MOV R0,#1 ;It's now drawn (well, soon)
229 BL gl__drawn ;So remember this
230 MOV R0,R10 ;Point to the viewer block
231 MOV R2,#vwEvent_unDraw ;Undraw the temporary bit
232 BL vw__doUpdate ;Go and do the update
233 MOV R2,#vwEvent_draw ;Now draw it properly
234 BL vw__doUpdate ;And then draw it properly
235 ADD R13,R13,#36 ;Restore the stack pointer
236 LDMFD R13!,{R0-R4,PC}^ ;Return to caller
238 ; --- Remove this handler ---
240 50gl__idles MOV R0,#0 ;Call me all the time
241 ADR R1,gl__idles ;No -- point to the handler
242 MOV R2,R10 ;Point to the viewer block
243 MOV R3,R12 ;Point to someone else's wsp
244 BL idle_removeHandler ;Remove the handler thing
245 LDR R14,[R10,#vw__flags] ;Load the flags word
246 BIC R14,R14,#glFlag__drawing;Not drawing any more
247 STR R14,[R10,#vw__flags] ;Store the flags away
248 ADD R13,R13,#36 ;Restore the stack pointer
249 LDMFD R13!,{R0-R4,PC}^ ;And return to caller
253 ; --- gl__clipBlock ---
255 ; On entry: R1 == pointer to window-state block
256 ; R3 == pointer to output block
260 ; Use: Replaces the window-state block with a block containing the
261 ; window-relative coordinates of the visible part of the
266 STMFD R13!,{R0-R2,R4,R5,R14} ;Save some registers
267 LDMIB R1,{R0-R2,R4,R5,R14} ;Load window position/scroll
268 SUB R2,R2,R0 ;Find the window width
269 SUB R1,R4,R1 ;And the window height
270 MOV R0,R5 ;This is the x0 position
271 ADD R5,R5,R2 ;And this is the x1 position
272 SUB R1,R14,R1 ;This is y0
273 STMIA R3,{R0,R1,R5,R14} ;Save that lot away now
274 LDMFD R13!,{R0-R2,R4,R5,PC}^ ;And return to caller
280 ; On entry: R0 == 0 to say `undrawn', 1 to say `drawn'
285 ; Use: Sets or resets an icon's drawn flag.
289 STMFD R13!,{R0,R2-R4,R14} ;Save some registers
290 MOV R2,#2 ;Set the drawn flag
291 MOV R3,R0,LSL #1 ;Do with it what he said
292 LDR R0,[R10,#vw__list] ;Load the list pointer
293 LDR R4,[R10,#vw__listDef] ;And the list defintion
294 MOV R14,PC ;Set up the return address
295 ADD PC,R4,#vw__setFlags ;Read the item's flags
296 LDMFD R13!,{R0,R2-R4,PC}^ ;Restore registers
300 ; --- gl__isDrawn ---
302 ; On entry: R1 == item handle
304 ; On exit: CC if item has been drawn, else CS
306 ; Use: Tells you quickly whether an item has been drawn.
310 STMFD R13!,{R0,R2-R4,R14} ;Save some registers
311 LDR R0,[R10,#vw__list] ;Load the list pointer
312 LDR R4,[R10,#vw__listDef] ;And the list defintion
313 MOV R2,#0 ;Read the flags please
314 MOV R3,#0 ;Don't change them, no missus
315 MOV R14,PC ;Set up the return address
316 ADD PC,R4,#vw__setFlags ;Read the item's flags
317 TST R2,#2 ;Is the flag set?
318 LDMFD R13!,{R0,R2-R4,R14} ;Restore registers
319 ORREQS PC,R14,#C_flag ;If not set, return CS
320 BICNES PC,R14,#C_flag ;Else return CC
324 ;----- List definition format -----------------------------------------------
327 vw__itemToIndex # 4 ;Item to index routine
328 ;Entry: R0 == pointer to list
329 ; R1 == pointer to item
330 ;Exit: R1 == index, or -1
332 vw__indexToItem # 4 ;Index to item routine
333 ;Entry: R0 == pointer to list
334 ; R1 == index of item
335 ;Exit: R1 == item ptr, or 0
337 vw__enumerate # 4 ;Enumeration function
338 ;Entry: R0 == list pointer
342 ;Exit: CS if match, and
345 vw__items # 4 ;Function to return items
346 ;Entry: R0 == list pointer
347 ;Exit: R1 == number of items
349 vw__setFlags # 4 ;Function to set/read flags
350 ;Entry: R1 == pointer to item
353 ;Exit: R2 == new flags
355 ;----- Viewer's icky bits which we poke around in ---------------------------
359 ; --- Information about the window ---
361 vw__window # 4 ;Window handle
362 vw__extent # 16 ;Current window extent
363 vw__flags # 4 ;Any flags of interest
364 vw__list # 4 ;Pointer to list head
365 vw__listDef # 4 ;Pointer to list handler
366 vw__handler # 12 ;Viewer's event handler
367 gl__handler # 8 ;Gallery's event handler(YUK)
368 vw__shape # 4 ;Shape handler function
369 vw__banner # 4 ;Pointer to banner string
370 vw__fixedWidth # 4 ;Width of banner/title
372 ; --- Icon sizing information ---
374 vw__icons # 4 ;Cache number of icons
375 vw__stdDimens # 8 ;`Standard' width and height
376 vw__iconWidth # 4 ;Width of icons currently
377 vw__iconHeight # 4 ;Height of icons currently
378 vw__across # 4 ;Number of icons across
379 vw__down # 4 ;Number of icons down
381 ; --- Data for default selection model ---
383 vw__tempSel # 4 ;Temporary selected icon
385 ; --- Big buffers at the end ---
387 vw__title # 256 ;Title bar buffer
389 vw__size # 0 ;Size of a viewer block
393 ; We only have the top-end bits.
395 glFlag__drawing EQU (1<<31) ;We have idle handler running
397 ;----- That's all, folks ----------------------------------------------------