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