Can anyone help with the following - surely someone who's written a paint program knows the answer to this.
I'm updating a Blitz 2D program to Blitz+. The Blitz2D program allowed the user to pick a colour-tint for the grey-scale interface from a predefined list of colours. Now that I've got access to slider gadgets, I thought it would be nice to offer the user the ability to select their own tint by changing the red/green/blue percent with slider gadgets. Unfortunately, it doesn't work too well - I want the user to see the results as soon as they release the slider gadget - an interface example is reddrawn with the new rgb values.
Grabbing the slider bar and moving it works perfectly - but obviously I don't want to update the interface tint for every increment of the slider when they click and hold an arrow-button, or in the gap between the slider bar and the arrow-button. However, there doesn't seem to be a way to avoid it. Why doesn't clicking the arrow-buttons or gap thingy generate an event similar to the event generated when they grab the slider bar?
I've enclosed two versions of the code - the first one has a text gadget and is easier to follow. If you try the first, you will see that the text gadget is updated perfectly if you slide the slider-bar - but if you click and hold an arrow-button, or the gap, then the text gadget updates really slowly - but when you let go of the arrow-button - the text-gadget suddenly jumps to the correct value.
The second piece of code attempts to simulate what my program is doing, by CLSing a canvas with the current tint - where my program actually makes a call to tint_greyscale(), where writepixel is used to redraw the interface with the new tint.
Again, grabbing the slider-bar works perfectly - remember I don't want the tint to update until they let go of it - which makes redrawing easily fast enough. But if you hold the arrow-button down until the slider-bar reaches the end, from the middle - then 100 queued CLSes are performed - which is bad enough - but imagine watching 100 queued calls to tint_greyscale(), and seeing the example interface slowly changing colour :)
Anyone recommend a solution. If not, I'll have to give it up, and just put a bunch of predefined tints in a list box like those you can currently select from the menu.
Thanks.
Thanks for any help.
I'm updating a Blitz 2D program to Blitz+. The Blitz2D program allowed the user to pick a colour-tint for the grey-scale interface from a predefined list of colours. Now that I've got access to slider gadgets, I thought it would be nice to offer the user the ability to select their own tint by changing the red/green/blue percent with slider gadgets. Unfortunately, it doesn't work too well - I want the user to see the results as soon as they release the slider gadget - an interface example is reddrawn with the new rgb values.
Grabbing the slider bar and moving it works perfectly - but obviously I don't want to update the interface tint for every increment of the slider when they click and hold an arrow-button, or in the gap between the slider bar and the arrow-button. However, there doesn't seem to be a way to avoid it. Why doesn't clicking the arrow-buttons or gap thingy generate an event similar to the event generated when they grab the slider bar?
I've enclosed two versions of the code - the first one has a text gadget and is easier to follow. If you try the first, you will see that the text gadget is updated perfectly if you slide the slider-bar - but if you click and hold an arrow-button, or the gap, then the text gadget updates really slowly - but when you let go of the arrow-button - the text-gadget suddenly jumps to the correct value.
Global winx, winy, event, evsource, redpercent winx=(ClientWidth(Desktop()) Shr 1)-95 winy=(ClientHeight(Desktop()) Shr 1)-15 window=CreateWindow("Slider test",winx,winy,190,30,0,$31) SetMinWindowSize window red=CreateSlider(10,10,100,20,window,1) SetSliderRange red,5,205 SetSliderValue red,100 redfield=CreateTextField(130,10,40,20,window) SetGadgetText redfield,0 While WaitEvent()<>$803 FlushEvents $801 event=EventID() Select event Case $401 ;gadget event Select EventSource() Case red redpercent=EventData() SetGadgetText redfield,redpercent-100 End Select Case $201 ;mouse down Case $202 ;mouse up Case $204 ;wheel turned Case $801 ;win moved Case $2004 evsource=EventSource() If evsource=red DebugLog "Slider grabbed" While WaitEvent()<>$2005 ;slider released If EventID()=$401 ;slider moved redpercent=EventData() SetGadgetText redfield,redpercent-100 EndIf Wend DebugLog "Slider Released" Else DebugLog "Title-bar grabbed" EndIf Case $2005 DebugLog "Title-bar released" Default DebugLog Hex$(event) End Select Wend
The second piece of code attempts to simulate what my program is doing, by CLSing a canvas with the current tint - where my program actually makes a call to tint_greyscale(), where writepixel is used to redraw the interface with the new tint.
Again, grabbing the slider-bar works perfectly - remember I don't want the tint to update until they let go of it - which makes redrawing easily fast enough. But if you hold the arrow-button down until the slider-bar reaches the end, from the middle - then 100 queued CLSes are performed - which is bad enough - but imagine watching 100 queued calls to tint_greyscale(), and seeing the example interface slowly changing colour :)
Anyone recommend a solution. If not, I'll have to give it up, and just put a bunch of predefined tints in a list box like those you can currently select from the menu.
Thanks.
;Note that the sliders indicate a percentage from -100 to 100 ;and not RGB values - so full red would mean the top slider all the ;way right, and the bottom two sliders all the way left. ;events Const KEY_ACTION=$101 Const GADGET_ACTION=$401, MENU_ACTION=$1001 Const MOUSE_GRAB=$2004, MOUSE_RELEASE=$2005 Global redpercent#, greenpercent#, bluepercent# Global event, evsource, n, colourchanged ;NOTE WINDOW POSITIONING JUST TEMPORARY - SHORTER LINES - WILL CENTRE IN FINAL VERSION Global window=CreateWindow("Tint Interface",300,200,280,140,0,49) Global menu=CreateMenu("Predefined",0,WindowMenu(window)) CreateMenu "Greyscale",1,menu CreateMenu "Purple",2,menu CreateMenu "Chocolate",3,menu UpdateWindowMenu window SetMinWindowSize window Global canvas=CreateCanvas(180,20,84,93,window) rlabel=CreateLabel("Red %",10,33,50,20,window,0) Global red=CreateSlider(65,30,100,20,window,1) SetSliderRange red,5,205 SetSliderValue red,100 glabel=CreateLabel("Green %",10,63,50,20,window,0) Global green=CreateSlider(65,60,100,20,window,1) SetSliderRange green,5,205 SetSliderValue green,100 blabel=CreateLabel("Blue %",10,93,50,20,window,0) Global blue=CreateSlider(65,90,100,20,window,1) SetSliderRange blue,5,205 SetSliderValue blue,100 plusminus=CreateLabel("- 0 +",105,5,50,20,window,0) SetBuffer CanvasBuffer(canvas) ;tint_greyscale(veneerpointer) ClsColor 128,128,128 Cls FlipCanvas canvas,False While (WaitEvent()<>$803) And (Not(quitted)) event=EventID() Select event Case GADGET_ACTION ;gadget evsource=EventSource() n=EventData() colourchanged=True ; Delay 5 ;watch those queued CLSes performed Case MENU_ACTION ;menu n=EventData() If n ;don't know if it's possible for n to be zero Select n Case 1 ;greyscale redpercent=0: greenpercent=0: bluepercent=0 Case 2 ;default redpercent=0.1: greenpercent=-0.5: bluepercent=0.4 Case 3 ;chocolate redpercent=0.28: greenpercent=-0.09: bluepercent=-0.32 End Select SetSliderValue red,100+(redpercent*100) SetSliderValue green,100+(greenpercent*100) SetSliderValue blue,100+(bluepercent*100) colourchanged=True EndIf Case MOUSE_GRAB evsource=EventSource() ;could be title-bar If (evsource=red) Or (evsource=green) Or (evsource=blue) While WaitEvent()<>MOUSE_RELEASE event=EventID() If event=GADGET_ACTION n=EventData() EndIf Wend colourchanged=True EndIf Case KEY_ACTION If EventData()=1 Then quitted=True End Select If colourchanged Then tint_greyscale() Wend Function tint_greyscale() Select evsource Case red redpercent=(n-100) redpercent=redpercent/100 Case green greenpercent=(n-100) greenpercent=greenpercent/100 Case blue bluepercent=(n-100) bluepercent=bluepercent/100 End Select ;simulation rgb=128 ;peekbyte If rgb > 127 Then difference=255-rgb Else difference=rgb ClsColor rgb+(difference * redpercent),rgb+(difference * greenpercent),rgb+(difference * bluepercent) Cls FlipCanvas canvas,False colourchanged=False Return End Function
Thanks for any help.