Author Topic: Knobs in a moveable box  (Read 3369 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Knobs in a moveable box
« on: April 03, 2012, 04:10:44 PM »

Code: [Select]

include "win64.inc"

sys wx=640,wy=480
Window "Knobs in Moveable Dialog Box",wx,wy,2

sys sxMouse,syMouse

class DialogBox
  sys px,py,sx,sy     'position and sensing-size
  sys spx,spy
  '
  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
      return 1
    end if
    end if
  elseif MouseButton=0 then
    spx=px : spy=py
  end if
  end method
  '
  method show() as sys
  FillBox px,py,sx,sy,160,160,160
  end method
  '
end class


class Knob
  '
  sys px,py,sx,sy     'position and sensing-size
  single sens,sang,ang
  sys spx,spy
  '
  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>6 then ang=6
      if ang<0 then ang=0
      return 1
    end if
    end if
  elseif MouseButton=0 then
    sang=ang
    spx=px
    spy=py
  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 trans(sys tx,ty)
  px=spx+tx : py=spy+ty
  end method

  method fvalue() as single
  return ang*.166667
  end method
  '
  method bvalue() as sys
  return 255*ang*.166667
  end method
  '
end class

DialogBox d1<=(50,50,200,200)

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

sys p,q,tx,ty

While AscKey=0 and WinExit=0
ClsColor c1.bvalue,c2.bvalue,c3.bvalue
if mouseButton=0 then
  sxMouse=xMouse
  syMouse=yMouse
  q=0
end if

p=d1.zone

if p then
  if q then
    p=0
  else
    p=c1.zone()+c2.zone()+c3.zone()
  end if
  if p=1 or MouseButton=0 then
    c1.pos
    c2.pos
    c3.pos
    if MouseButton=0 then d1.pos
  else 'p=0 and mousebutton=1
    q=1 'inhibit child control activation
    d1.pos
    tx=d1.px-d1.spx
    ty=d1.py-d1.spy
    c1.trans tx,ty
    c2.trans tx,ty
    c3.trans tx,ty
  end if
end if
d1.show
c1.show
c2.show
c3.show

FlipBuffer
WaitFor 60
Wend


Charles Pegge

  • Guest
Re: Knobs in a moveable box
« Reply #1 on: April 04, 2012, 08:35:51 AM »
An enhanced version with text and button highlighting

Code: [Select]


include "win64.inc"

sys wx=640,wy=480,fx=10,fy=20,fw=400
Window "Knobs in Moveable Dialog Box",wx,wy,2
Font fx,fy,fw,"arial"

sys sxMouse,syMouse

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
  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<=(50,50,200,200,"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,q,tx,ty

While AscKey=0 and WinExit=0
ClsColor c1.bvalue,c2.bvalue,c3.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
  else
    p=c1.zone()+c2.zone()+c3.zone()
  end if
  if p=1 or MouseButton=0 then
    c1.pos
    c2.pos
    c3.pos
    if MouseButton=0 then d1.pos
  else 'p=0 and mousebutton=1
    q=1 'inhibit child control activity
    d1.pos
    tx=d1.px-d1.spx
    ty=d1.py-d1.spy
    c1.trans tx,ty
    c2.trans tx,ty
    c3.trans tx,ty
  end if
end if
d1.show
c1.show
c2.show
c3.show

FlipBuffer
sleep 15
Wend


Charles
« Last Edit: April 04, 2012, 11:32:08 AM by Charles Pegge »

Peter

  • Guest
Re: Knobs in a moveable box
« Reply #2 on: April 04, 2012, 10:32:17 AM »
Hi Charles

Is now (create button) time?  :D
This work is not bad, but I prefer sliders.

The mouse pointer must be within the range of the knobs.

Charles Pegge

  • Guest
Re: Knobs in a moveable box
« Reply #3 on: April 04, 2012, 11:24:24 AM »
Hi Peter,

You can drag outside the knobs to turn them fully but not outside the box. I will fix this limitation, as it inhibits full turning off - dragging to the left.

Charles

the line:

p=d1.zone

change to

p=d1.zone() or q
« Last Edit: April 04, 2012, 11:31:14 AM by Charles Pegge »