This demonstrates sliders with feedback.
You can set colors with the Red-Green-Blue sliders or the Hue-Luminance-Saturation sliders.
If you change the RGB sliders the HLS sliders will be adjusted and vice-versa
include "win64.inc"
sys wx=640,wy=480,fx=10,fy=20,fw=400
Window "Sliders in Moveable Dialog Box",wx,wy,2
Font fx,fy,fw,"arial"
sys sxMouse,syMouse
class Slider
'
sys px,py,sx,sy 'position and sensing-size
sys lx1,lx2,ly1,ly2 'limits of movement
string txt
sys spx,spy,slx1,slx2,sly1,sly2,act
single sc
'
method zone() as sys
if sxMouse>=lx1-sx and sxMouse<=lx2+sx then
if syMouse>=ly1-sy and syMouse<=ly2+sy then
return 1
end if
end if
end method
'
method pos() as sys
if MouseButton=1 then
if xMouse>=lx1-sx and xMouse<=lx2+sx then
if yMouse>=ly1-sy and yMouse<=ly2+sy then
px=spx+xMouse-sxMouse : py=spy+yMouse-syMouse
if px<lx1 then px=lx1
if px>lx2 then px=lx2
if py<ly1 then py=ly1
if py>ly2 then py=ly2
act=1
return 1
end if
end if
elseif MouseButton=0 then
spx=px : spy=py
slx1=lx1 : slx2=lx2
sly1=ly1 : sly2=ly2
end if
act=0
end method
'
method show() as sys
Line lx1,ly1,lx2,ly2,4,200,200,200
if act then
Oval px-sx, py-sy, sx*2, sy*2, 255,0,200
else
Oval px-sx, py-sy, sx*2, sy*2, 120,0,100
end if
if lx1<lx2 then
if sc=0 then sc=255
Text lx2+10,ly1-fy*.5,txt+" "+round(sc*(px-lx1)/(lx2-lx1)),255,255,255
end if
end method
'
method trans(sys tx,ty)
px=spx+tx : py=spy+ty
lx1=slx1+tx : lx2=slx2+tx
ly1=sly1+ty : ly2=sly2+ty
end method
'
method fvalue(single s) as single
sc=s
if lx1<lx2 then return s*(px-lx1)/(lx2-lx1)
if ly1<ly2 then return (py-ly1)/(ly2-ly1)
end method
'
method bvalue() as sys
if lx1<lx2 then return 255*(px-lx1)/(lx2-lx1)
if ly1<ly2 then return 255*(py-ly1)/(ly2-ly1)
end method
'
method ffeedback(single v,s) as sys
sc=s
if lx1<lx2 then px=lx1+(lx2-lx1)*v/s
if ly1<ly2 then py=ly1+(ly2-ly1)*v/s
end method
'
method bfeedback(sys v) as sys
if lx1<lx2 then px=lx1+(lx2-lx1)*v/255
if ly1<ly2 then py=ly1+(ly2-ly1)*v/255
end method
'
end class
'HORIZONTAL SLIDERS
Slider s1<=(100,100,10,15,50,150,100,100,"Red")
Slider s2<=(100,140,10,15,50,150,140,140,"Green")
Slider s3<=(100,180,10,15,50,150,180,180,"Blue")
Slider s4<=(100,220,10,15,50,150,220,220,"Hue")
Slider s5<=(100,260,10,15,50,150,260,260,"Luminance")
Slider s6<=(100,300,10,15,50,150,300,300,"Saturation")
'VERTICAL SLIDERS
'Slider s4<=(200,150,15,10,200,200,100,200)
'Slider s5<=(250,150,15,10,250,250,100,200)
'Slider s6<=(300,150,15,10,300,300,100,200)
class Knob
'
sys px,py,sx,sy 'position and sensing-size
single sens,ang
string txt
single sang
sys spx,spy,act
'
method zone() as sys
if sxMouse>=px-sx and sxMouse<=px+sx then
if syMouse>=py-sy and syMouse<=py+sy then
return 1
end if
end if
end method
'
method pos() as sys
if MouseButton=1 then
if sxMouse>=px-sx and sxMouse<=px+sx then
if syMouse>=py-sy and syMouse<=py+sy then
ang=sang+(xMouse-sxMouse+yMouse-syMouse)*sens
if ang>1 then ang=1
if ang<0 then ang=0
act=1
return 1
end if
end if
elseif MouseButton=0 then
sang=ang
spx=px
spy=py
end if
act=0
end method
'
method show() as sys
if act then
Oval px-sx, py-sy, sx*2, sy*2, 250,0,250
else
Oval px-sx, py-sy, sx*2, sy*2, 100,0,100
end if
Line px,py,px+sx*sin(ang*6),py-sy*cos(ang*6),2,200,200,200
'Text px+sx+10,py-sy+(fy>>2),txt+" "+str(ang,2),255,255,255
Text px+sx+10,py-sy+(fy>>2),txt+" "+str(ang*255,0),255,255,255
end method
'
method trans(sys tx,ty)
px=spx+tx : py=spy+ty
end method
'
method fvalue() as single
return ang
end method
'
method bvalue() as sys
return 255*ang
end method
'
end class
class DialogBox
sys px,py,sx,sy 'position and sensing-size
string txt
sys spx,spy,act
'
method zone() as sys
if xMouse>=px-sx and xMouse<=px+sx then
if yMouse>=py-sy and yMouse<=py+sy then
return 1
end if
end if
end method
'
method pos() as sys
if MouseButton=1 then
if xMouse>=px-sx and xMouse<=px+sx then
if yMouse>=py-sy and yMouse<=py+sy then
px=spx+xMouse-sxMouse
py=spy+yMouse-syMouse
if px+sx>wx then px=wx-sx
if py+sy>wy then py=wy-sy
if px<0 then px=0
if py<0 then py=0
act=1
return 1
end if
end if
elseif MouseButton=0 then
spx=px : spy=py
end if
act=0
end method
'
method show() as sys
FillBox px,py,sx,sy,160,160,160
Text px+5,py+5,txt,0,0,0 '255,255,255
end method
'
end class
DialogBox d1<=(40,50,280,300,"Background Colors")
'knob c1<=(100,110,25,15,.012,.5,"red")
'knob c2<=(100,160,25,15,.012,.3,"green")
'knob c3<=(100,210,25,15,.012,.5,"blue")
sys p,p1,p2,q,tx,ty,c,r,g,b,h,l,s
While AscKey=0 and WinExit=0
ClsColor s1.bvalue,s2.bvalue,s3.bvalue
if mouseButton=0 then
sxMouse=xMouse
syMouse=yMouse
q=0
end if
p=d1.zone() or q
if p then
if q then
p=0 : p1=0 : p2=0
else
p1=s1.zone()+s2.zone()+s3.zone()
p2=s4.zone()+s5.zone()+s6.zone()
p=p1 or p2
end if
if p>0 or MouseButton=0 then
s1.pos
s2.pos
s3.pos
s4.pos
s5.pos
s6.pos
if MouseButton then
if p1 then
c=s1.bvalue()+s2.bvalue()*0x100+s3.bvalue()*0x10000
ColorRGBToHLS c,h,l,s
s4.ffeedback h,240
s5.ffeedback l,240
s6.ffeedback s,240
'SetWindowText sys_hwnd, h " " l " " s
end if
if p2 then
h=s4.fvalue 240
l=s5.fvalue 240
s=s6.fvalue 240
c=ColorHLStoRGB h,l,s
r=c and 255
shr c,8
g=c and 255
shr c,8
b=c and 255
s1.bfeedback r
s2.bfeedback g
s3.bfeedback b
end if
else 'mousebutton=0
d1.pos
end if
else 'p=0 and mousebutton=1
q=1 'inhibit child control activity
d1.pos
tx=d1.px-d1.spx
ty=d1.py-d1.spy
s1.trans tx,ty
s2.trans tx,ty
s3.trans tx,ty
s4.trans tx,ty
s5.trans tx,ty
s6.trans tx,ty
end if
end if
d1.show
s1.show
s2.show
s3.show
s4.show
s5.show
s6.show
FlipBuffer
if MouseButton then sleep 10 else sleep 50
Wend
Charles