Author Topic: Knob Controls  (Read 2910 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Knob Controls
« on: April 03, 2012, 09:29:55 AM »
Using the same technique as sliders.

Click and drag to turn them.

Code: [Select]
include "win64.inc"


Window "Knobs",400,300,2

sys sxMouse,syMouse

class Knob
  '
  sys px,py,sx,sy     'position and sensing-size
  single sang
  single ang
  '
  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)*.05
      if ang>6 then ang=6
      if ang<0 then ang=0
    end if
    end if
  elseif MouseButton=0 then
    sang=ang
  end if
  end method
  '
  method show() as sys
  Oval px-sx, py-sy, sx*2, sy*2, 255,0,200
  Line px,py,px+sx*sin(ang),py-sy*cos(ang),2,200,200,200
  end method
  '
  method fvalue() as single
  return ang*.166667
  end method
  '
  method bvalue() as sys
  return 255*ang*.166667
  end method
  '
end class


knob c1<=(100,100,25,15)
knob c2<=(100,150,25,15)
knob c3<=(100,200,25,15)


While AscKey=0 and WinExit=0
ClsColor c1.bvalue,c2.bvalue,c3.bvalue
if mouseButton=0 then
  sxMouse=xMouse
  syMouse=yMouse
end if
c1.pos : c1.show
c2.pos : c2.show
c3.pos : c3.show
Events
FlipBuffer
WaitFor 60
Wend
WinEnd

Charles