; ; colSelect.s ; ; The Colour Selector kernel ; ; © 1994 Straylight ; ;----- Standard header ------------------------------------------------------ GET libs:header GET libs:swis ;----- External dependencies ------------------------------------------------ GET sapphire:alloc GET sapphire:dbox GET sapphire:errorBox GET sapphire:menu GET sapphire:menuDefs GET sapphire:msgs GET sapphire:pane GET sapphire:dbx.dbx GET sapphire:dbx.stringSet GET sapphire:_cs.vars GET sapphire:_cs.models ;----- Main code ------------------------------------------------------------ AREA |Sapphire$$Code|,CODE,READONLY ; --- colSelect --- ; ; On entry: R0 == address of a colour block ; R1 == pointer to routine to call when done ; R2 == R10 to call routine with ; R3 == R12 to call routine with ; ; On exit: May return error ; ; Use: Displays a colour selector dialogue box. It allows the user ; to edit a colour (understatement....) EXPORT colSelect colSelect ROUT BIC R14,R14,#V_flag ;Clear the V flag STMFD R13!,{R0-R4,R10,R14} ;Save a load of registers ; --- Try to create a workspace block --- MOV R0,#cs__dSize ;Get my data size BL alloc ;Try to allocate the memory BLCS alloc_error ;If it failed, get a message BCS %99colSelect ;And tidy up as we go MOV R10,R0 ;Look after this block ; --- Now create a dialogue box --- ADR R0,cs__dbName ;Point to the dialogue name BL dbox_create ;Create the dialogue BVS %98colSelect ;Tidy up if it failed STR R0,cs__frameDb ;Save the dialogue handle ADR R1,cs__handler ;The event handler MOV R2,R10 ;Pass this R10 value MOV R3,R12 ;And this R12 value BL dbox_eventHandler ;Set up the handler ADR R1,cs__dbxBlock ;Point to dbx information BL dbx_declare ;Declare the block ; --- Save the caller's information --- LDR R0,[R13,#0] ;Load his colour's address LDMIA R0,{R1-R3} ;Load the colour arguments ADR R14,cs__address ;Point into the data block STMIA R14,{R0-R3} ;And save all of that stuff ; --- Set up the workspace --- MOV R14,#3 ;Start on low resolution STR R14,cs__resolution ;Save it in the workspace ; --- Set up the initial model --- BL cs__initModel ;Get a model index BVS %97colSelect ;Clean up on an error MOV R4,R2 ;Keep the model number STR R0,cs__modelDb ;Save model's dialogue box BL dbox_window ;Get the window handle MOV R3,R0 ;Put model's db handle in R3 LDR R0,cs__frameDb ;Get frame db handle MOV R1,#dbOpen_persist+dbOpen_current BL dbox_open ;Open the dialogue box MOV R1,#csIcon__rgb ;The first model icon number ADD R1,R1,R2 ;Get the correct icon number MOV R2,#1 ;Turn the icon on BL dbox_select ;Select the icon MOV R2,R3 ;Pane window handle BL dbox_window ;Get the window handle MOV R1,#csIcon__models ;The icon handle BL pane_add ;Add the pane BL pane_open ;Open the pane BL cs__setCaret ;And give it the focus 95colSelect LDMFD R13!,{R0-R4,R10,PC}^ ;Return to caller 97colSelect MOV R4,R0 ;Preserve R0 LDR R0,cs__frameDb ;Get the dialogue box handle BL dbox_destroy ;Destroy the dialogue box MOV R0,R4 ;Get R0 back 98colSelect MOV R4,R0 ;Preserve R0 MOV R0,R10 ;Point to allocated memory BL free ;Free it nicely MOV R0,R4 ;Get R0 back 99colSelect ADD R13,R13,#4 ;Don't load R0 LDMFD R13!,{R1-R4,R10,R14} ;Load registers ORRS PC,R14,#V_flag ;Return with error LTORG cs__dbName DCB "colSelect",0 cs__dbxBlock CONTROL csIcon__colour,colButton,R10,0,:INDEX: cs__colour ECTRL STRSET csIcon__resDisp,R10,:INDEX: cs__resolution, cs__resMenu,cs__resStrings,csIcon__resDisp STRSET csIcon__resMenu,R10,:INDEX: cs__resolution, cs__resMenu,cs__resStrings,csIcon__resDisp DBXEND cs__resMenu MENU "csRESMT" ITEM "csRESVH:Very high" RADIO 0,0 ITEM "csRESH:High" RADIO 0,1 ITEM "csRESM:Medium" RADIO 0,2 ITEM "csRESL:Low" RADIO 0,3 MENUEND cs__resStrings DCB "csRESVH:Very high",0 DCB "csRESH:High",0 DCB "csRESM:Medium",0 DCB "csRESL:Low",0 ; --- cs__initModel --- ; ; On entry: R2 == colour model number, or 0 ; ; On exit: R0 == dialogue box created by colour model, or error ; R2 == preserved, or index of RGB model ; ; Use: Initialises a colour model dialogue box. cs__initModel ROUT CMP R2,#cs__noModels ;Is the model in range? MOVHS R2,#cMod_rgb ;No -- use RGB then ADD PC,PC,R2,LSL #2 ;Call the function DCB "MDW!" 00cs__initModel B rgb_open B hsv_open 10cs__initModel cs__noModels EQU (%10-%00)/4 ; --- cs__setCaret --- ; ; On entry: -- ; ; On exit: -- ; ; Use: Sets the caret in the current colour select pane window. cs__setCaret ROUT STMFD R13!,{R0-R5,R14} ;Save some registers LDR R0,cs__modelDb ;Get the model dialogue BL dbox_window ;And find its window handle MOV R1,#-1 ;In no particular icon MOV R2,#&ff000000 ;Quite a long way away ORR R2,R2,#&00ff0000 MOV R3,#0 ;Doesn't really matter MOV R4,#&02000000 ;Hide caret, make it small MOV R5,#-1 ;No index into icon, please SWI Wimp_SetCaretPosition ;Set the caret's position LDMFD R13!,{R0-R5,PC}^ ;Return to caller LTORG ; --- cs__handler --- ; ; On entry: R0 == dialogue box event code ; R1-R9 == depend on the event ; R10 == colour selector data ; R12 == nothing much, actually -- corrupted on exit ; ; On exit: -- ; ; Use: Handles events for the main dialogue frame cs__handler ROUT CMP R0,#stringSet_event ;Is this a string set event? BEQ cs__resMenuClk ;Yes -- handle that CMP R0,#dbEvent_OK ;Is it an OK event? CMPNE R0,#csIcon__ok ;Or a click on OK? BEQ cs__ok ;Yes -- handle it then CMP R0,#dbEvent_help ;Does someone want help? BEQ cs__getHelp ;Yes -- deal with that too SUB R12,R0,#csIcon__rgb ;Was it a model icon? CMP R12,#cs__noModels BLO cs__changeModel ;Yes -- deal with it MOVS PC,R14 ; --- Handle an OK click/keypress --- cs__ok ROUT STMFD R13!,{R0-R5,R14} ;Save some registers MOV R5,R1 ;Remember mouse button state MOV R0,R9 ;Get my dialogue handle MOV R1,#csIcon__ok ;And the OK button BL dbox_slab ;Press it in nicely ; --- Find the actual colour he chose --- BL dbox_unslab ;Unslab the button LDMFD R13!,{R0-R5,PC}^ ;And return to caller LTORG ; --- Give a help message if required --- cs__getHelp B dbox_help ;Just let dbox do it all! ; --- Handle the resolution menu button --- cs__resMenuClk ROUT CMP R1,#csIcon__resDisp ;Is this the resolution one? MOVNES PC,R14 ;No -- ignore it then STMFD R13!,{R0,R10,R14} ;Save some registers LDR R10,cs__modelDb ;Get the model's handle too MOV R0,#csEvent__newRes ;The resolution's changed BL dbx_sendEvent ;Send the event out LDMFD R13!,{R0,R10,PC}^ ;And return to caller LTORG ; --- Handle a model selection --- cs__changeModel ROUT STMFD R13!,{R0-R3,R14} ;Stack some registers LDR R1,cs__colour+col_model ;Load the existing model CMP R1,R12 ;Is it the same? LDMEQFD R13!,{R0-R3,PC}^ ;Yes -- return ; --- Tell old model to update colour --- STMFD R13!,{R10} ;Save my instance pointer LDR R10,cs__modelDb ;Get the current panel dbox MOV R0,#csEvent__read ;Tell it to read its settings BL dbx_sendEvent ;Send it the event LDMFD R13!,{R10} ;Restore the instance pointer ; --- First try to get a new model dialogue --- MOV R2,R12 ;Get the new colour model BL cs__initModel ;Try to initialise it nicely BVS %90cs__changeModel ;If it failed, report error ; --- Now remove the old one --- STMFD R13!,{R0,R10} ;Save some important regs LDR R10,cs__modelDb ;Get the current panel dbox MOV R0,R10 ;Get it in R0 BL dbox_window ;Find its window handle MOV R3,R0 ;Keep this value nicely SUB R13,R13,#24 ;Space for a caret block MOV R1,R13 ;Point to the caret block SWI Wimp_GetCaretPosition ;Find the caret nicely LDR R0,[R13,#0] ;Load the focus window handle CMP R0,R3 ;Is it the panel? MOVNE R3,#0 ;No -- clear the value then ADD R13,R13,#24 ;Restore the stack pointer MOV R0,#csEvent__close ;Send a close event BL dbx_sendEvent ;Send the event LDMFD R13!,{R0,R10} ;Restore the registers again ; --- Set up the new panel nicely --- STR R0,cs__modelDb ;Store the new db handle STR R2,cs__colour+col_model ;And the new model type BL dbox_window ;Get the new window handle MOV R2,R0 ;This is the new pane LDR R0,cs__frameDb ;Get the main dialogue box BL dbox_window ;And get its window handle MOV R1,#csIcon__models ;The main icon thingy BL pane_swap ;Swap the pane over CMP R3,#0 ;Was the caret in the panel BLNE cs__setCaret ;Yes -- put it in the new one LDMFD R13!,{R0-R3,PC}^ ;Return to caller 90 MOV R1,#1 ;Only an OK button please BL errorBox ;Call error box LDMFD R13!,{R0-R3,R14} ;Return to caller ORRS PC,R14,#C_flag ;Don't change the radio state LTORG ; --- cs_passBack --- ; ; On entry: R0-R7 == dialogue box event information ; R10 == pointer to colour selector instance ; ; On exit: -- ; ; Use: Passes an event back to the main colour selector frame dbox. EXPORT cs_passBack cs_passBack ROUT STMFD R13!,{R10,R14} ;Save some registers LDR R10,cs__frameDb ;Get the dialogue handle BL dbx_sendEvent ;Pass the event on LDMFD R13!,{R10,PC}^ ;And return to caller LTORG ; --- cs_colChange --- ; ; On entry: R10 == currently selected dialogue box ; ; On exit: -- ; ; Use: Updates the colour selector's colour display. EXPORT cs_colChange cs_colChange ROUT STMFD R13!,{R0,R1,R14} ;Save some registers LDR R0,cs__frameDb ;Load the frame handle MOV R1,#csIcon__colour ;Get the colour button icon BL dbx_update ;Redraw it nicely LDMFD R13!,{R0,R1,PC}^ ;And return to caller LTORG ; --- cs_immediate --- ; ; On entry: R10 == currently selected dialogue box ; ; On exit: CS if immediate operations are enabled, or CC ; ; Use: Informs the caller whether sliders and arrows should cause ; immediate update of the dialogue box, or wait until the ; operation has completed. EXPORT cs_immediate cs_immediate ROUT STMFD R13!,{R0,R1,R14} ;Save some registers LDR R0,cs__frameDb ;Load the frame handle MOV R1,#csIcon__instant ;Get instant effect switch BL dbox_isSelected ;Is it selected? LDMFD R13!,{R0,R1,PC} ;Return this state LTORG ; --- cs_resolution --- ; ; On entry: R10 == currently selected dialogue box ; ; On exit: R0 == quality value, from 0 (pixel) to 3 (grotty) ; ; Use: Returns the current resolution value. This is interpreted ; in a model-dependent manner. EXPORT cs_resolution cs_resolution ROUT LDR R0,cs__resolution ;Load the value out MOVS PC,R14 ;Return to caller LTORG ;----- Icon numbers --------------------------------------------------------- csIcon__models EQU 0 csIcon__rgb EQU 2 csIcon__hsv EQU 3 csIcon__cmyk EQU 4 csIcon__help EQU 5 csIcon__cancel EQU 6 csIcon__ok EQU 10 csIcon__colour EQU 9 csIcon__trans EQU 7 csIcon__instant EQU 12 csIcon__resDisp EQU 14 csIcon__resMenu EQU 15 ;----- dbx controls --------------------------------------------------------- EXPORT colButton colButton DCD 0,0 DCD dbxMask_redraw STMFD R13!,{R0-R4,R14} ;Stack some registers LDR R0,[R8,#0] ;Get the RGB colour MOV R3,#&180 ;ColourTrans flags MOV R4,#0 ;GCOL type SWI XColourTrans_SetGCOL ;Set the colour ; --- If error, try without dithering --- LDRVS R0,[R8,#0] ;Get the RGB colour MOVVS R3,#&080 ;ColourTrans flags MOVVS R4,#0 ;GCOL type SWIVS ColourTrans_SetGCOL ;Set the colour ; --- Do a CLG... cunning! ---- SWI OS_WriteI+16 ;Plot the colour nicley LDMFD R13!,{R0-R4,PC}^ ;Return nicley then ;----- That's all, folks ---------------------------------------------------- END