  #compact
  $ FileName  "co.exe"
  'uses RTL64
  'uses console
  '
  % ExplicitMain
  % title        "Lower Popup Control"
  % fontA        "Arial",FW_SEMIBOLD
  '%ColorCodedPick

  'macro keydown
  'case 27 : 'no action
  'case 32 : 'no action
  'end macro


  uses OpenglSceneFrame
  uses glo2\shapes
  uses glo2\materials
  uses glo2\textures
  uses controls

'/*
  ===================
  class ControlPanelB
  ===================
  has AdjustableControl
  lightbuttons l[12]
  sliders      c[8]
  joysticks    j[1]
  knobs        k[3]

  method act(optional int n)
  static int t1,t2,t3,t4
  static int f1,f2,f3,f4
  int i,oi1,oi2,oi3,oi4
  string lbl
  if id=0
    f1=0
    if not f2 then f2=MakePolygon 0,32,2
    if not f3 then f3=MakePolygon 22.5,8,2
    if not f4 then f4=MakePolygon 90,3,2
    indexbase 1
    ---------------------------------------------------------------------------
    'ctrl    x    y   z     sc    shm shb tex id  lk, lb
    ---------------------------------------------------------------------------
    c[1] => .00,-.00, .00,  0.10, f1, 00, t1, 110, 1, "Slider A"
    c[2] => .10,-.00, .00 , 0.10, f1, 00, t1, 120, 1, "Slider B"
    c[3] => .20,-.00, .00 , 0.10, f1, 00, t1, 130, 1, "Slider C"
    c[4] => .30,-.00, .00 , 0.10, f1, 00, t1, 140, 1, "Slider D"
    ---------------------------------------------------------------------------
    c[5] => .40,-.00, .00,  0.10, f3, 00, t1, 150, 1, "x rotate"
    c[6] => .50,-.00, .00 , 0.10, f3, 00, t1, 160, 1, "y rotate"
    c[7] => .60,-.00, .00 , 0.10, f3, 00, t1, 170, 1, "z rotate"
    c[8] => .70,-.00, .00 , 0.10, f3, 00, t1, 180, 1, "Lift"
    ---------------------------------------------------------------------------
    l[1] => .00, .15, .00,  0.02, f3, 00, t1, 210, 1, "Light Button A"
    l[2] => .10, .15, .00 , 0.02, f1, 00, t1, 220, 1, "Light Button B"
    l[3] => .20, .15, .00 , 0.02, f4, 00, t1, 230, 1, "Light Button C"
    l[4] => .30, .15, .00 , 0.02, f3, 00, t1, 240, 1, "Light Button D"
    ---------------------------------------------------------------------------
    l[5] => .40, .15, .00,  0.02, f3, 00, t1, 250, 1, "Light Button E"
    l[6] => .50, .15, .00 , 0.02, f1, 00, t1, 260, 1, "Light Button F"
    l[7] => .60, .15, .00 , 0.02, f4, 00, t1, 270, 1, "Light Button G"
    l[8] => .70, .15, .00 , 0.02, f3, 00, t1, 280, 1, "Light Button H"
    ---------------------------------------------------------------------------
    j[1] => .90,-.00, .00,  0.10, f2, 00, t1, 310, 1, "xz Joystick"
    ---------------------------------------------------------------------------
    k[1] =>-.10, .10, .00,  0.15, f2, 00, t1, 410, 1, "Knob A"
    k[2] =>-.10,-.00, .00,  0.15, f2, 00, t1, 420, 1, "Knob B"
    k[3] =>-.10,-.10, .00,  0.15, f2, 00, t1, 430, 1, "Knob C"
    ---------------------------------------------------------------------------
    l[9] => .85,-.15, .00,  0.020,f4, 00, t1, 510, 1, "joystick reset x"
    l[10]=> .90,-.15, .00,  0.025,f4, 00, t1, 520, 1, "joystick reset xy"
    l[11]=> .95,-.15, .00,  0.020,f4, 00, t1, 530, 1, "joystick reset y"
    l[12]=> .70,-.15, .00,  0.020,f4, 00, t1, 540, 1, "Slider reset y"
    ---------------------------------------------------------------------------
    id=n+1000
    if sc=0.0 then sc=1.0
    this.label="ControlBoxB"
  end if 'init
  '
  glDisable GL_LIGHTING
  glDisable GL_TEXTURE_2D
  glpushmatrix
  gltranslatef  x,y,z-.0005
  glScalef      sc,sc,1.0
  if pick
    PickLabel     id
  else
    QuadShadow    .60,.20,.005,.5
    glcolor3f     .60,.50,.60 'fix alpha bug
    glcolor4f     .60,.50,.60,0.50 'box
  endif
  QuadTex       .60,.20,.0
  gltranslatef -.45,.0,-.0
  '
  if bleft
    if picked=id
      if not lock
        drag(dx,dy,1.2)
        x=xx+dx : y=yy+dy
      end if
    end if
    select picked
    'RESET JOYSICK X Y POSITIONS
    case 511 : l[09].lit={1,0} : j[1].vx=0.0
    case 521 : l[10].lit={1,0} : j[1].vx={0.0,0.0}
    case 531 : l[11].lit={1,0} : j[1].vy=0.0
    case 541 : l[12].lit={1,0} : c[8].vy=0.0
    end select
  else
    xx=x : yy=y : zz=z 'ANCHOR
  end if
  '
  'render
  '
  int i
  for i=1 to 8
    c[i].act(sc,i,oi1)
  next
  for i=1 to 12
    l[i].act(sc,i,oi2)
  next
  for i=1 to 1
    j[i].act(sc,i,oi3)
  next
  for i=1 to 3
    k[i].act(sc,i,oi4)
  next
  if picked=id then lbl=this.label
  if oi1 then lbl=c[oi1].label
  if oi2 then lbl=l[oi2].label
  if oi3 then lbl=j[oi3].label
  if oi4 then lbl=k[oi4].label
  '
  '
  'show data
  '
  glDisable GL_TEXTURE_2D
  glDisable GL_LIGHTING
  '
  if pick
    PickLabel    0
  endif
  if bleft
    gltranslatef -.1,0.-0.18,0.0004
    float w,h
    glscalef     .05,.05,.01
    GetWordArea  "Control:",w,h
    if pick
      PutBoxArea   w,h
    else
      glColor3f    .99,.99,.99
      'if picked then gprint    str(picked+id)
      if picked then gprint    lbl
      if oi1+oi2+oi3+oi4
        'float cm=100.0,cn=50.0
        if oi1 then gprint "   " str(c[oi1].vy,2)
        if oi2 then gprint "   " str(l[oi2].lit,2)
        if oi3 then gprint "   " str(j[oi3].vx, 2) "  " str(j[oi3].vy ,2)
        if oi4 then gprint "   " str(k[oi4].vy, 2)
      end if
    end if
  end if
  glPopMatrix
  end method
  '
  end class
'*/

  '
  indexbase 1
  float     ang1
  int       cube,pent



  sub initialize(sys hWnd)
  ========================
  '
  GDIplus 1
  BuildTextures 16,256
  'cube=CompileList : CubeForm  : glEndList
  BeginGlCompile cube : CubeForm : EndGlCompile
  end sub


  sub Release(sys hwnd)
  '====================
  DeleteAllGlCompiled
  DeleteTextures 16
  Gdiplus 0
  end sub

  sub RenderPlane(float su,sv, eu,ev)
  ===================================
  eu+=su : ev+=sv
  glBegin GL_TRIANGLE_STRIP
  glNormal3f 0.0,1.0,0.0
  glTexCoord2f su,sv : glVertex3f -1.0,0,-1.0
  glTexCoord2f eu,sv : glVertex3f  1.0,0,-1.0
  glTexCoord2f su,ev : glVertex3f -1.0,0, 1.0    
  glTexCoord2f eu,ev : glVertex3f  1.0,0, 1.0
  glend
  end sub


  ===================
  sub scene(sys hWnd)
  ===================
  '
  indexbase 1
  static single ra,ri,angi1=.5
  '
  DozyFrame
  'ActiveFrame
  glClearColor 0.5, 0.5, 0.7, 0
  Fog          .50, .50, .75, 0.030
  '
  PickSetup

  BeginPick
  '
  glColor4f 1,1,1,1
  StandardLighting li
  StandardMaterial ma
  '
  'MAIN SCENE
  '
  PickLabel 0
  'GREEN PLANE
  glPushMatrix
  glEnable      GL_TEXTURE_2D
  glTranslatef  0.0,-2.0,-15.0
  glScalef      16.,1.,16.
  int t1=texn[11]
  glBindTexture GL_TEXTURE_2D,t1
  RenderPlane   0.,0.,8.,8.
  glDisable     GL_TEXTURE_2D
  glPopMatrix
  '
  '
  '
  '
  '
  'CONTROL PANEL
  scope
    static ControlPanelB cb
    if cb.sc=0 then cb.sc=.75  : cb.lock=1 'initial
    static float my,mm
    if closing
      cb.destructor
      exit sub
    endif
    '
    'POSITION
    '
    if mposy>crect.bottom-15
      if my=0 then mm=.01 : actn=100 'MOVING UP
    elseif mposy<crect.bottom>>1
      if my>0 then mm=-.01 : actn=100 'MOVING DOWN
    end if
    '
    if mm
      my+=mm
      if my>.414 then
        my=.414 : mm=0 : actn=0 'STAY UP
      elseif my<0 then
        my=0 : mm=0 : actn=0 'STAY DOWN
      end if
    end if
    '
    'BUILD
    '
    if my>.1
      glpushmatrix
      gltranslatef .0,-.675+my,-1.0
      cb.act 0 'optional base id: 0000 1000 2000 3000 etc
      glpopmatrix
    end if
  end scope
  '
  EndPick
  '
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  end sub
  '
  MainWindow width,height,WS_OVERLAPPEDWINDOW 'WS_POPUP
