chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / s / gallery
1 ;
2 ; gallery.s
3 ;
4 ; Background-drawing viewers
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
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)
16 ; any later version.
17 ;
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.
22 ;
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.
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:swis
31
32                 GET     libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36                 GET     sapphire:idle
37                 GET     sapphire:screen
38                 GET     sapphire:viewer
39
40                 IMPORT  vw__intSimple
41                 IMPORT  vw__enum
42                 IMPORT  vw__doUpdate
43                 IMPORT  vw__callShape
44
45 ;----- Main code ------------------------------------------------------------
46 ;
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.
50
51                 AREA    |Sapphire$$Code|,CODE,READONLY
52
53 ; --- gallery_eventHandler ---
54 ;
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
59 ;
60 ; On exit:      --
61 ;
62 ; Use:          Sets up an event handler for the viewer, and adds in
63 ;               gallery's own special processing for background drawing.
64
65                 EXPORT  gallery_eventHandler
66 gallery_eventHandler ROUT
67
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
75
76                 LTORG
77
78 ; --- gallery_drawBox ---
79 ;
80 ; On entry:     R0-R3 == window relative coords of box to plot
81 ;
82 ; On exit:      --
83 ;
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.
87
88                 EXPORT  gallery_drawBox
89 gallery_drawBox ROUT
90
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
101
102                 LTORG
103
104 ; --- gallery_removeBox ---
105 ;
106 ; On entry:     R0-R3 == window relative coords of box to remove
107 ;
108 ; On exit:      --
109 ;
110 ; Use:          Removes a previously draw temporary box.  It is assumed that
111 ;               the background colour of the viewere is 1.
112
113                 EXPORT  gallery_removeBox
114 gallery_removeBox ROUT
115
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
126
127                 LTORG
128
129 ; --- gl__events ---
130 ;
131 ; On entry:     R0 == event code
132 ;               R1-R7 == information from viewer
133 ;
134 ; On exit:      exits via user handler
135 ;
136 ; Use:          Intercepts viewer events to do background redraw.
137
138 gl__events      ROUT
139
140                 CMP     R0,#vwEvent_redraw      ;Is this a redraw request?
141                 LDRNE   PC,[R9,#gl__handler]    ;No -- pass it on then
142
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
148
149                 MOV     R0,#0                   ;This icon is not drawn yet
150                 BL      gl__drawn               ;So set the flag up nicely
151
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
155
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
163
164 10gl__events    LDMFD   R13!,{R0-R3,R10,R14}    ;And return to caller
165                 LDR     PC,[R9,#gl__handler]    ;Continue processing event
166
167                 LTORG
168
169 ; --- gallery_reset ---
170 ;
171 ; On entry:     R0 == viewer handle
172 ;
173 ; On exit:      --
174 ;
175 ; Use:          Resets all the icons in the gallery to their `undrawn' state.
176 ;               Use this before opening the window etc.
177
178                 EXPORT  gallery_reset
179 gallery_reset   ROUT
180
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
196
197                 LTORG
198
199 ; --- gl__idles ---
200 ;
201 ; On entry:     R10 == pointer to viewer block
202 ;
203 ; On exit:      --
204 ;
205 ; Use:          Redraws the first unredrawn item in the viewer.
206
207 gl__idles       ROUT
208
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
217
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
225
226                 ; --- Draw this item ---
227
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
237
238                 ; --- Remove this handler ---
239
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
250
251                 LTORG
252
253 ; --- gl__clipBlock ---
254 ;
255 ; On entry:     R1 == pointer to window-state block
256 ;               R3 == pointer to output block
257 ;
258 ; On exit:      --
259 ;
260 ; Use:          Replaces the window-state block with a block containing the
261 ;               window-relative coordinates of the visible part of the
262 ;               window.
263
264 gl__clipBlock   ROUT
265
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
275
276                 LTORG
277
278 ; --- gl__drawn ---
279 ;
280 ; On entry:     R0 == 0 to say `undrawn', 1 to say `drawn'
281 ;               R1 == item handle
282 ;
283 ; On exit:      --
284 ;
285 ; Use:          Sets or resets an icon's drawn flag.
286
287 gl__drawn       ROUT
288
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
297
298                 LTORG
299
300 ; --- gl__isDrawn ---
301 ;
302 ; On entry:     R1 == item handle
303 ;
304 ; On exit:      CC if item has been drawn, else CS
305 ;
306 ; Use:          Tells you quickly whether an item has been drawn.
307
308 gl__isDrawn     ROUT
309
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
321
322                 LTORG
323
324 ;----- List definition format -----------------------------------------------
325
326                 ^       0
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
331
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
336
337 vw__enumerate   #       4                       ;Enumeration function
338                                                 ;Entry: R0 == list pointer
339                                                 ;       R1 == item, or 0
340                                                 ;       R2 == BIC mask
341                                                 ;       R3 == test mask
342                                                 ;Exit:  CS if match, and
343                                                 ;       R1 == item ptr
344
345 vw__items       #       4                       ;Function to return items
346                                                 ;Entry: R0 == list pointer
347                                                 ;Exit:  R1 == number of items
348
349 vw__setFlags    #       4                       ;Function to set/read flags
350                                                 ;Entry: R1 == pointer to item
351                                                 ;       R2 == BIC mask
352                                                 ;       R3 == EOR mask
353                                                 ;Exit:  R2 == new flags
354
355 ;----- Viewer's icky bits which we poke around in ---------------------------
356
357                 ^       0
358
359                 ; --- Information about the window ---
360
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
371
372                 ; --- Icon sizing information ---
373
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
380
381                 ; --- Data for default selection model ---
382
383 vw__tempSel     #       4                       ;Temporary selected icon
384
385                 ; --- Big buffers at the end ---
386
387 vw__title       #       256                     ;Title bar buffer
388
389 vw__size        #       0                       ;Size of a viewer block
390
391                 ; --- Flags bits ---
392                 ;
393                 ; We only have the top-end bits.
394
395 glFlag__drawing EQU     (1<<31)                 ;We have idle handler running
396
397 ;----- That's all, folks ----------------------------------------------------
398
399                 END