
'#compact
$ filename "t.exe"
'uses RTL32
'uses RTL64
uses Controls


class ColorDialogBox
====================
  '
  indexbase 0
  '
  'FlatBox     im1
  'ShadeBox    im1
  NoiseBox    im1
  '
  DialogBox   d1
  Slider      s1,s2,s3,s4,s5,s6
  Slider      v1,v2,v3,v4,v5,v6,v7,v8
  sys         r,g,b,h,l,s,p,q
  sys         RgbZone,HcsZone
  '
  method constructor()
  int i
  '
  'images
  '
  im1<=0,0,320,160,0x7f7f7f,2
  im1.create
  '
  'controls
  '
  d1<=20,40,600,400,"Procedural Noise"
  '
  s1<=100,100,10,15,50,150,100,100,"Red"
  s2<=100,140,10,15,50,150,140,140,"Green"
  s3<=100,180,10,15,50,150,180,180,"Blue"
  s4<=100,220,10,15,50,150,220,220,"Hue"
  s5<=100,260,10,15,50,150,260,260,"Luminance"
  s6<=100,300,10,15,50,150,300,300,"Saturation"
  s4.sc=240 'show scale
  s5.sc=240 'show scale
  s6.sc=240 'show scale
  v1<=360,300,08,07,360,360,250,350,"A"
  v2<=380,300,08,07,380,380,250,350,"B"
  v3<=400,300,08,07,400,400,250,350,"C"
  v4<=420,300,08,07,420,420,250,350,"D"
  v5<=440,300,08,07,440,440,250,350,"E"
  v6<=460,300,08,07,460,460,250,350,"F"
  v7<=480,300,08,07,480,480,250,350,"G"
  v8<=500,300,08,07,500,500,250,350,"H"
  v1.bset 128
  v2.bset  64
  v3.bset  32
  v4.bset  16
  v5.bset   8
  v6.bset   4
  v7.bset   2
  v8.bset   1
  render
  MoveImages
  end method
  '
  method destructor()
  im1.destroy
  end method
  '
  method moveImages()
  im1.px=d1.px+d1.sx-im1.w-10
  im1.py=d1.py+10
  end method
  '
  method set()
  s1.set
  s2.set
  s3.set
  s4.set
  s5.set
  s6.set
  v1.set
  v2.set
  v3.set
  v4.set
  v5.set
  v6.set
  v7.set
  v8.set
  end method
  '
  method show()
  d1.show
  im1.show
  s1.show
  s2.show
  s3.show
  s4.show
  s5.show
  s6.show
  v1.show
  v2.show
  v3.show
  v4.show
  v5.show
  v6.show
  v7.show
  v8.show
  end method
  '
  method anchor()
  d1.anchor
  s1.anchor
  s2.anchor
  s3.anchor
  s4.anchor
  s5.anchor
  s6.anchor
  v1.anchor
  v2.anchor
  v3.anchor
  v4.anchor
  v5.anchor
  v6.anchor
  v7.anchor
  v8.anchor
  end method

  method move(sys tx,ty)
  sys x,y
  d1.move tx,ty
  x=d1.px-d1.spx 'with limits
  y=d1.py-d1.spy 'with limits
  s1.move x,y
  s2.move x,y
  s3.move x,y
  s4.move x,y
  s5.move x,y
  s6.move x,y
  v1.move x,y
  v2.move x,y
  v3.move x,y
  v4.move x,y
  v5.move x,y
  v6.move x,y
  v7.move x,y
  v8.move x,y
  MoveImages
  end method
  '
  method HcsSet(sys c)
  ColorRGBToHLS c,h,l,s
  s4.fset h,240
  s5.fset l,240
  s6.fset s,240
  end method
  '
  method RgbSet(sys c)
  r=c and 255
  shr c,8
  g=c and 255
  shr c,8
  b=c and 255
  s1.bset r
  s2.bset g
  s3.bset b
  end method
  '
  method GetHcsColor() as sys
  h=s4.fget 240
  l=s5.fget 240
  s=s6.fget 240
  return ColorHLStoRGB h,l,s
  end method
  '
  method GetRgbColor() as sys
  return s1.bget()+s2.bget()*0x100+s3.bget()*0x10000
  end method
  '
  method zone() as sys
  return d1.zone
  end method
  '
  method render()
  im1.nn=>
  v1.bget,v2.bget,v3.bget,v4.bget,
  v5.bget,v6.bget,v7.bget,v8.bget
  im1.rf=s1.fget 1
  im1.gf=s2.fget 1
  im1.bf=s3.fget 1
  im1.render
  end method
  '
  method zones(sys *RgbZone,*HcsZone)
  RgbZone=s1.zone()+s2.zone()+s3.zone()
  HcsZone=s4.zone()+s5.zone()+s6.zone()
  end method
  '
  method action()
  if mouseButton=0
    anchor
    q=0
  end if
  if q
    move xMouse-sxMouse, yMouse-syMouse
  elseif MouseButton
    set
    zones RgbZone,HcsZone
    if RgbZone then
      HcsSet GetRgbColor
      render
    elseif HcsZone
      RgbSet GetHcsColor
      render
    elseif v1.zone() or v2.zone() or v3.zone() or v4.zone() or
           v5.zone() or v6.zone() or v7.zone() or v8.zone()
      render
    elseif zone
      q=1
    end if
  end if
  end method
  '
end class

's=recordof ColorDialogBox
'putfile "t.txt", s

new ColorDialogBox cdb

AscKey=-1
do
  if EscKey then exit do
  if mouseButton=0
    sxMouse=xMouse
    syMouse=yMouse
  end if
  cdb.action
  if MouseButton or AscKey
    ClsColor 0x606060 'cdb.GetRgbColor
    cdb.show
    AscKey=0
    FlipBuffer
    sleep 5
  else
    events
    sleep 50
  end if
end do

del cdb
