chiark / gitweb /
Initial revision
[ssr] / StraySrc / SapphToys / !ColDemo / s / colSelect
1 ;
2 ; colSelect.s
3 ;
4 ; The Colour Selector kernel
5 ;
6 ; © 1994-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 ;----- External dependencies ------------------------------------------------
33
34                 GET     sapphire:alloc
35                 GET     sapphire:dbox
36                 GET     sapphire:errorBox
37                 GET     sapphire:menu
38                 GET     sapphire:menuDefs
39                 GET     sapphire:msgs
40                 GET     sapphire:pane
41
42                 GET     sapphire:dbx.dbx
43                 GET     sapphire:dbx.stringSet
44
45                 GET     sapphire:_cs.vars
46                 GET     sapphire:_cs.models
47
48 ;----- Main code ------------------------------------------------------------
49
50                 AREA    |Sapphire$$Code|,CODE,READONLY
51
52 ; --- colSelect ---
53 ;
54 ; On entry:     R0 == address of a colour block
55 ;               R1 == pointer to routine to call when done
56 ;               R2 == R10 to call routine with
57 ;               R3 == R12 to call routine with
58 ;
59 ; On exit:      May return error
60 ;
61 ; Use:          Displays a colour selector dialogue box.  It allows the user
62 ;               to edit a colour (understatement....)
63
64                 EXPORT  colSelect
65 colSelect       ROUT
66
67                 BIC     R14,R14,#V_flag         ;Clear the V flag
68                 STMFD   R13!,{R0-R4,R10,R14}    ;Save a load of registers
69
70                 ; --- Try to create a workspace block ---
71
72                 MOV     R0,#cs__dSize           ;Get my data size
73                 BL      alloc                   ;Try to allocate the memory
74                 BLCS    alloc_error             ;If it failed, get a message
75                 BCS     %99colSelect            ;And tidy up as we go
76                 MOV     R10,R0                  ;Look after this block
77
78                 ; --- Now create a dialogue box ---
79
80                 ADR     R0,cs__dbName           ;Point to the dialogue name
81                 BL      dbox_create             ;Create the dialogue
82                 BVS     %98colSelect            ;Tidy up if it failed
83                 STR     R0,cs__frameDb          ;Save the dialogue handle
84                 ADR     R1,cs__handler          ;The event handler
85                 MOV     R2,R10                  ;Pass this R10 value
86                 MOV     R3,R12                  ;And this R12 value
87                 BL      dbox_eventHandler       ;Set up the handler
88                 ADR     R1,cs__dbxBlock         ;Point to dbx information
89                 BL      dbx_declare             ;Declare the block
90
91                 ; --- Save the caller's information ---
92
93                 LDR     R0,[R13,#0]             ;Load his colour's address
94                 LDMIA   R0,{R1-R3}              ;Load the colour arguments
95                 ADR     R14,cs__address         ;Point into the data block
96                 STMIA   R14,{R0-R3}             ;And save all of that stuff
97
98                 ; --- Set up the workspace ---
99
100                 MOV     R14,#3                  ;Start on low resolution
101                 STR     R14,cs__resolution      ;Save it in the workspace
102
103                 ; --- Set up the initial model ---
104
105                 BL      cs__initModel           ;Get a model index
106                 BVS     %97colSelect            ;Clean up on an error
107                 MOV     R4,R2                   ;Keep the model number
108                 STR     R0,cs__modelDb          ;Save model's dialogue box
109                 BL      dbox_window             ;Get the window handle
110                 MOV     R3,R0                   ;Put model's db handle in R3
111                 LDR     R0,cs__frameDb          ;Get frame db handle
112                 MOV     R1,#dbOpen_persist+dbOpen_current
113                 BL      dbox_open               ;Open the dialogue box
114                 MOV     R1,#csIcon__rgb         ;The first model icon number
115                 ADD     R1,R1,R2                ;Get the correct icon number
116                 MOV     R2,#1                   ;Turn the icon on
117                 BL      dbox_select             ;Select the icon
118                 MOV     R2,R3                   ;Pane window handle
119                 BL      dbox_window             ;Get the window handle
120                 MOV     R1,#csIcon__models      ;The icon handle
121                 BL      pane_add                ;Add the pane
122                 BL      pane_open               ;Open the pane
123                 BL      cs__setCaret            ;And give it the focus
124 95colSelect     LDMFD   R13!,{R0-R4,R10,PC}^    ;Return to caller
125
126 97colSelect     MOV     R4,R0                   ;Preserve R0
127                 LDR     R0,cs__frameDb          ;Get the dialogue box handle
128                 BL      dbox_destroy            ;Destroy the dialogue box
129                 MOV     R0,R4                   ;Get R0 back
130 98colSelect     MOV     R4,R0                   ;Preserve R0
131                 MOV     R0,R10                  ;Point to allocated memory
132                 BL      free                    ;Free it nicely
133                 MOV     R0,R4                   ;Get R0 back
134 99colSelect     ADD     R13,R13,#4              ;Don't load R0
135                 LDMFD   R13!,{R1-R4,R10,R14}    ;Load registers
136                 ORRS    PC,R14,#V_flag          ;Return with error
137
138                 LTORG
139
140 cs__dbName      DCB     "colSelect",0
141
142 cs__dbxBlock    CONTROL csIcon__colour,colButton,R10,0,:INDEX: cs__colour
143                 ECTRL
144                 STRSET  csIcon__resDisp,R10,:INDEX: cs__resolution,                                     cs__resMenu,cs__resStrings,csIcon__resDisp
145                 STRSET  csIcon__resMenu,R10,:INDEX: cs__resolution,                                     cs__resMenu,cs__resStrings,csIcon__resDisp
146                 DBXEND
147
148 cs__resMenu     MENU    "csRESMT"
149                 ITEM    "csRESVH:Very high"
150                 RADIO   0,0
151                 ITEM    "csRESH:High"
152                 RADIO   0,1
153                 ITEM    "csRESM:Medium"
154                 RADIO   0,2
155                 ITEM    "csRESL:Low"
156                 RADIO   0,3
157                 MENUEND
158
159 cs__resStrings  DCB     "csRESVH:Very high",0
160                 DCB     "csRESH:High",0
161                 DCB     "csRESM:Medium",0
162                 DCB     "csRESL:Low",0
163
164 ; --- cs__initModel ---
165 ;
166 ; On entry:     R2 == colour model number, or 0
167 ;
168 ; On exit:      R0 == dialogue box created by colour model, or error
169 ;               R2 == preserved, or index of RGB model
170 ;
171 ; Use:          Initialises a colour model dialogue box.
172
173 cs__initModel   ROUT
174
175                 CMP     R2,#cs__noModels        ;Is the model in range?
176                 MOVHS   R2,#cMod_rgb            ;No -- use RGB then
177                 ADD     PC,PC,R2,LSL #2         ;Call the function
178                 DCB     "MDW!"
179
180 00cs__initModel B       rgb_open
181                 B       hsv_open
182 10cs__initModel
183
184 cs__noModels    EQU     (%10-%00)/4
185
186 ; --- cs__setCaret ---
187 ;
188 ; On entry:     --
189 ;
190 ; On exit:      --
191 ;
192 ; Use:          Sets the caret in the current colour select pane window.
193
194 cs__setCaret    ROUT
195
196                 STMFD   R13!,{R0-R5,R14}        ;Save some registers
197                 LDR     R0,cs__modelDb          ;Get the model dialogue
198                 BL      dbox_window             ;And find its window handle
199                 MOV     R1,#-1                  ;In no particular icon
200                 MOV     R2,#&ff000000           ;Quite a long way away
201                 ORR     R2,R2,#&00ff0000
202                 MOV     R3,#0                   ;Doesn't really matter
203                 MOV     R4,#&02000000           ;Hide caret, make it small
204                 MOV     R5,#-1                  ;No index into icon, please
205                 SWI     Wimp_SetCaretPosition   ;Set the caret's position
206                 LDMFD   R13!,{R0-R5,PC}^        ;Return to caller
207
208                 LTORG
209
210 ; --- cs__handler ---
211 ;
212 ; On entry:     R0 == dialogue box event code
213 ;               R1-R9 == depend on the event
214 ;               R10 == colour selector data
215 ;               R12 == nothing much, actually -- corrupted on exit
216 ;
217 ; On exit:      --
218 ;
219 ; Use:          Handles events for the main dialogue frame
220
221 cs__handler     ROUT
222
223                 CMP     R0,#stringSet_event     ;Is this a string set event?
224                 BEQ     cs__resMenuClk          ;Yes -- handle that
225
226                 CMP     R0,#dbEvent_OK          ;Is it an OK event?
227                 CMPNE   R0,#csIcon__ok          ;Or a click on OK?
228                 BEQ     cs__ok                  ;Yes -- handle it then
229
230                 CMP     R0,#dbEvent_help        ;Does someone want help?
231                 BEQ     cs__getHelp             ;Yes -- deal with that too
232
233                 SUB     R12,R0,#csIcon__rgb     ;Was it a model icon?
234                 CMP     R12,#cs__noModels
235                 BLO     cs__changeModel         ;Yes -- deal with it
236
237                 MOVS    PC,R14
238
239                 ; --- Handle an OK click/keypress ---
240
241 cs__ok          ROUT
242
243                 STMFD   R13!,{R0-R5,R14}        ;Save some registers
244                 MOV     R5,R1                   ;Remember mouse button state
245                 MOV     R0,R9                   ;Get my dialogue handle
246                 MOV     R1,#csIcon__ok          ;And the OK button
247                 BL      dbox_slab               ;Press it in nicely
248
249                 ; --- Find the actual colour he chose ---
250
251                 BL      dbox_unslab             ;Unslab the button
252                 LDMFD   R13!,{R0-R5,PC}^        ;And return to caller
253
254                 LTORG
255
256                 ; --- Give a help message if required ---
257
258 cs__getHelp     B       dbox_help               ;Just let dbox do it all!
259
260                 ; --- Handle the resolution menu button ---
261
262 cs__resMenuClk  ROUT
263
264                 CMP     R1,#csIcon__resDisp     ;Is this the resolution one?
265                 MOVNES  PC,R14                  ;No -- ignore it then
266
267                 STMFD   R13!,{R0,R10,R14}       ;Save some registers
268                 LDR     R10,cs__modelDb         ;Get the model's handle too
269                 MOV     R0,#csEvent__newRes     ;The resolution's changed
270                 BL      dbx_sendEvent           ;Send the event out
271                 LDMFD   R13!,{R0,R10,PC}^       ;And return to caller
272
273                 LTORG
274
275                 ; --- Handle a model selection ---
276
277 cs__changeModel ROUT
278
279                 STMFD   R13!,{R0-R3,R14}        ;Stack some registers
280                 LDR     R1,cs__colour+col_model ;Load the existing model
281                 CMP     R1,R12                  ;Is it the same?
282                 LDMEQFD R13!,{R0-R3,PC}^        ;Yes -- return
283
284                 ; --- Tell old model to update colour ---
285
286                 STMFD   R13!,{R10}              ;Save my instance pointer
287                 LDR     R10,cs__modelDb         ;Get the current panel dbox
288                 MOV     R0,#csEvent__read       ;Tell it to read its settings
289                 BL      dbx_sendEvent           ;Send it the event
290                 LDMFD   R13!,{R10}              ;Restore the instance pointer
291
292                 ; --- First try to get a new model dialogue ---
293
294                 MOV     R2,R12                  ;Get the new colour model
295                 BL      cs__initModel           ;Try to initialise it nicely
296                 BVS     %90cs__changeModel      ;If it failed, report error
297
298                 ; --- Now remove the old one ---
299
300                 STMFD   R13!,{R0,R10}           ;Save some important regs
301                 LDR     R10,cs__modelDb         ;Get the current panel dbox
302                 MOV     R0,R10                  ;Get it in R0
303                 BL      dbox_window             ;Find its window handle
304                 MOV     R3,R0                   ;Keep this value nicely
305                 SUB     R13,R13,#24             ;Space for a caret block
306                 MOV     R1,R13                  ;Point to the caret block
307                 SWI     Wimp_GetCaretPosition   ;Find the caret nicely
308                 LDR     R0,[R13,#0]             ;Load the focus window handle
309                 CMP     R0,R3                   ;Is it the panel?
310                 MOVNE   R3,#0                   ;No -- clear the value then
311                 ADD     R13,R13,#24             ;Restore the stack pointer
312                 MOV     R0,#csEvent__close      ;Send a close event
313                 BL      dbx_sendEvent           ;Send the event
314                 LDMFD   R13!,{R0,R10}           ;Restore the registers again
315
316                 ; --- Set up the new panel nicely ---
317
318                 STR     R0,cs__modelDb          ;Store the new db handle
319                 STR     R2,cs__colour+col_model ;And the new model type
320                 BL      dbox_window             ;Get the new window handle
321                 MOV     R2,R0                   ;This is the new pane
322                 LDR     R0,cs__frameDb          ;Get the main dialogue box
323                 BL      dbox_window             ;And get its window handle
324                 MOV     R1,#csIcon__models      ;The main icon thingy
325                 BL      pane_swap               ;Swap the pane over
326                 CMP     R3,#0                   ;Was the caret in the panel
327                 BLNE    cs__setCaret            ;Yes -- put it in the new one
328                 LDMFD   R13!,{R0-R3,PC}^        ;Return to caller
329
330 90              MOV     R1,#1                   ;Only an OK button please
331                 BL      errorBox                ;Call error box
332                 LDMFD   R13!,{R0-R3,R14}        ;Return to caller
333                 ORRS    PC,R14,#C_flag          ;Don't change the radio state
334
335                 LTORG
336
337 ; --- cs_passBack ---
338 ;
339 ; On entry:     R0-R7 == dialogue box event information
340 ;               R10 == pointer to colour selector instance
341 ;
342 ; On exit:      --
343 ;
344 ; Use:          Passes an event back to the main colour selector frame dbox.
345
346                 EXPORT  cs_passBack
347 cs_passBack     ROUT
348
349                 STMFD   R13!,{R10,R14}          ;Save some registers
350                 LDR     R10,cs__frameDb         ;Get the dialogue handle
351                 BL      dbx_sendEvent           ;Pass the event on
352                 LDMFD   R13!,{R10,PC}^          ;And return to caller
353
354                 LTORG
355
356 ; --- cs_colChange ---
357 ;
358 ; On entry:     R10 == currently selected dialogue box
359 ;
360 ; On exit:      --
361 ;
362 ; Use:          Updates the colour selector's colour display.
363
364                 EXPORT  cs_colChange
365 cs_colChange    ROUT
366
367                 STMFD   R13!,{R0,R1,R14}        ;Save some registers
368                 LDR     R0,cs__frameDb          ;Load the frame handle
369                 MOV     R1,#csIcon__colour      ;Get the colour button icon
370                 BL      dbx_update              ;Redraw it nicely
371                 LDMFD   R13!,{R0,R1,PC}^        ;And return to caller
372
373                 LTORG
374
375 ; --- cs_immediate ---
376 ;
377 ; On entry:     R10 == currently selected dialogue box
378 ;
379 ; On exit:      CS if immediate operations are enabled, or CC
380 ;
381 ; Use:          Informs the caller whether sliders and arrows should cause
382 ;               immediate update of the dialogue box, or wait until the
383 ;               operation has completed.
384
385                 EXPORT  cs_immediate
386 cs_immediate    ROUT
387
388                 STMFD   R13!,{R0,R1,R14}        ;Save some registers
389                 LDR     R0,cs__frameDb          ;Load the frame handle
390                 MOV     R1,#csIcon__instant     ;Get instant effect switch
391                 BL      dbox_isSelected         ;Is it selected?
392                 LDMFD   R13!,{R0,R1,PC}         ;Return this state
393
394                 LTORG
395
396 ; --- cs_resolution ---
397 ;
398 ; On entry:     R10 == currently selected dialogue box
399 ;
400 ; On exit:      R0 == quality value, from 0 (pixel) to 3 (grotty)
401 ;
402 ; Use:          Returns the current resolution value.  This is interpreted
403 ;               in a model-dependent manner.
404
405                 EXPORT  cs_resolution
406 cs_resolution   ROUT
407
408                 LDR     R0,cs__resolution       ;Load the value out
409                 MOVS    PC,R14                  ;Return to caller
410
411                 LTORG
412
413 ;----- Icon numbers ---------------------------------------------------------
414
415 csIcon__panel   EQU     0
416 csIcon__modDisp EQU     2
417 csIcon__modMenu EQU     3
418 csIcon__sample  EQU     4
419 csIcon__resDisp EQU     6
420 csIcon__resMenu EQU     7
421 csIcon__instant EQU     8
422 csIcon__cancel  EQU     9
423 csIcon__ok      EQU     10
424
425 ;----- dbx controls ---------------------------------------------------------
426
427                 EXPORT  colButton
428 colButton       DCD     0,0
429                 DCD     dbxMask_redraw
430
431                 STMFD   R13!,{R0-R4,R14}        ;Stack some registers
432                 LDR     R0,[R8,#0]              ;Get the RGB colour
433                 MOV     R3,#&180                ;ColourTrans flags
434                 MOV     R4,#0                   ;GCOL type
435                 SWI     XColourTrans_SetGCOL    ;Set the colour
436
437                 ; --- If error, try without dithering ---
438
439                 LDRVS   R0,[R8,#0]              ;Get the RGB colour
440                 MOVVS   R3,#&080                ;ColourTrans flags
441                 MOVVS   R4,#0                   ;GCOL type
442                 SWIVS   ColourTrans_SetGCOL     ;Set the colour
443
444                 ; --- Do a CLG... cunning! ---
445
446                 SWI     OS_WriteI+16            ;Plot the colour nicley
447
448                 LDMFD   R13!,{R0-R4,PC}^        ;Return nicley then
449
450 ;----- Workspace ------------------------------------------------------------
451
452                 AREA    |Sapphire$$LibData|,CODE,READONLY
453
454                 DCD     cs__wSize
455                 DCD     cs__wSpace
456                 DCD     0
457                 DCD     cs__init
458
459 ;----- That's all, folks ----------------------------------------------------
460
461                 END