Question about sliders

BlitzPlus Forums/BlitzPlus Programming/Question about sliders

CloseToPerfect(Posted 2008) [#1]
Ok, I admit I have had B+ for along time now but have yet to really do any GUI programming, but I'm hard and heavy into a program now and I keep having issues. The help section is very poor for the GUI and most commands don't have examples. I hope youcan help me along as I learn.

I was trying to implement sliders into my program and I came across a problem. I wrote this little code piece as simple as possible to show the problem.

win = CreateWindow("Test window",0,0,400,400)
can = CreateCanvas(0,0,400,400,win)
SetGadgetLayout can,1,0,1,0
hslider = CreateSlider(0,ClientHeight(win)-18,ClientWidth(win)-20,18,win)
vslider = CreateSlider(ClientWidth(win)-18,0,18,ClientHeight(win),win,2)

Repeat
Until KeyHit(1)

Now what I am having issues with is when the slider bar is over the canvas it wont operate, but resize the window so the bar is off the canvas and it does operate. You can see with 2 sliders you can have one on the canvas and one off the canvas.

Questions
1) Is this how sliders work, if not what am I missing.
2) If this is how sliders work, does it mean I have to resize the canvas so its area is inside of the sliders.

would it be something like this -

win = CreateWindow("Test window",0,0,400,400)
can = CreateCanvas(0,0,400,400,win)
SetGadgetLayout can,1,0,1,0
hslider = CreateSlider(0,ClientHeight(win)-18,ClientWidth(win)-20,18,win)
vslider = CreateSlider(ClientWidth(win)-18,0,18,ClientHeight(win),win,2)

Repeat
If WaitEvent() = $802 Then
SetGadgetShape can, 0,0,ClientWidth(win)-30,ClientHeight(win)-30
SetGadgetShape hslider, 0,ClientHeight(win)-18,ClientWidth(win)-20,18
SetGadgetShape vslider, ClientWidth(win)-18,0,18,ClientHeight(win)
EndIf

Until KeyHit(1)

Question here is, I was setting my canvas to the size of my image, does it hurt anything to have a image that overlaps the canvas?

Thanks, John.


CloseToPerfect(Posted 2008) [#2]
ok, I'm still trying and am making some progress. I've expanded the sample program to do some canvas drawing.

if I use SetGadgetShape to resize the canvas it then stretches all future drawing on the canvas

if I free the canvas and create it new each time it does work fine but has this terrible flickering going on when you resize the window.

I can only assume I am still doing something wrong. Please have a look.
at least I can now move forward on the program until I get help with the flickering. The flickering must be cause my freeing the can then having a canvas free window and then creating the new canvas. So I assume there must be a way to not update the window till this is complete?

win = CreateWindow("Test window",0,0,400,400)
can = CreateCanvas(0,0,ClientWidth(win)-30,ClientHeight(win)-30,win)
SetGadgetLayout can,1,0,1,0
hslider = CreateSlider(0,ClientHeight(win)-18,ClientWidth(win)-20,18,win)
vslider = CreateSlider(ClientWidth(win)-18,0,18,ClientHeight(win),win,2)

Repeat

If WaitEvent() = $802 Then

;swap these two line to see difference
;SetGadgetShape can, 0,0,ClientWidth(win)-30,ClientHeight(win)-30
FreeGadget can
can = CreateCanvas(0,0,ClientWidth(win)-30,ClientHeight(win)-30,win)

SetGadgetShape hslider, 0,ClientHeight(win)-18,ClientWidth(win)-20,18
SetGadgetShape vslider, ClientWidth(win)-18,0,18,ClientHeight(win)
EndIf


SetBuffer CanvasBuffer(can)
Cls
Color Rand(0,255),Rand(0,255),Rand(0,255)
Rect Rand(0,GadgetWidth(can)),Rand(0,GadgetHeight(can)),Rand(0,40),Rand(0,40),Rand(0,1)
Text 0,0,"canvas height :"+GadgetHeight(can)
Text 0,20,"canvas width :"+GadgetWidth(can)
FlipCanvas can



Until KeyHit(1)


CloseToPerfect(Posted 2008) [#3]
oh yes,
I did figure out that the canvas is in front of the sliders and as such the sliders wont work when the canvas area is in the same area as the sliders.

I figured this out by making a really big canvas and then trying to have to sliders on it and they would not even appear.

I guess I can assume all gadget objects are draw first then the canvas is drawn. Therefore you can't have gadgets on the canvas. Right?


blackgecko(Posted 2008) [#4]
To your last question: No
You can have gadgets on the canvas. It's really simple, you just have to enter the canvas handle for the gadget's group.
Try this:

Window = CreateWindow("Test",100,100,400,400)
Canvas = CreateCanvas(0,0,400,400,Window)
Button = CreateButton("finish",200,200,100,40,Canvas) ;enter canvas handle
Slider = CreateSlider(20,20,30,150,Canvas,2) ;here also
SetSliderRange Slider,0,100
TextField = CreateTextField(100,20,100,20,Canvas) ;and here

Repeat
Until WaitEvent() = $401 And EventSource() = Button

Notify "finish button selected"+Chr(13)+SliderValue(Slider)+Chr(13)+TextFieldText(TextField)
End