
  % Title "Console Drag & Drrop Image Demo"
  uses consoleG
  uses filedialogs

  BeginScript

  procedure main()
  ================
  if opening
    static int res,wi[16],ht[16],imgn[16]
    static int imgne=4
    int i
    for i=1 to imgne
      texe++ 'texture slots
      imgn[i]=texe
    next
    static string wr
  end if

  'FILING
  if keystate(VK_CONTROL)
    int a=-1
    if lastkey=0x4f  'Open
      a=0
    elseif lastkey=0x53 'Save
      a=1
    endif
    if a>=0
      string ff
      scope
        char ch[256]
        GetCurrentDirectory 255,ch
        ff=GetFileName "t.txt",a
        if a=0
          filedrop=ff
          ff=""
        endif
        SetCurrentDirectory ch 'restore dir
      end scope
      'mbox filedrop
      lastkey=0
      lastchar=0
      key[VK_CONTROL]=0
    endif
  endif

  cls ' .3,.3,.5
  pushstate
  move 8.0,-4.0
  'UserMovement m1,100
  '
  'display image
  '
  static int pk
  flat
  int i
  float prp
  for i=1 to imgne
    if pick
      texture 0
      picklabel 100+i
    else
      if picked=100+i
        pk=100+i
        if filedrop
          wr=filedrop
          LoadTexture wr,imgn[i],res,wi[i],ht[i] 'slot in texture
          filedrop=""
        endif
      endif
      color 1,1,1,1
      texture imgn[i]
    endif
    pushstate
    scale 3
    '
    subroutine displaybox
      if wi[i]
        prp=Ht[i]/Wi[i]
      else
        prp=1.0
      endif
      quadnorm 1.0,prp 'apply image texture to a quad
    end subroutine
    '
    gosub displaybox
    '
    if picked=100+i
      texture 0
      color 0.9,0.9,0.0
      'box-around
      thickness 2
      scale 1.05
      move 0,0,0.001
      glBegin GL_LINE_STRIP
      glVertex2f -1,-prp
      glVertex2f  1,-prp
      glVertex2f  1, prp
      glVertex2f -1, prp
      glVertex2f -1,-prp
      glEnd
      move 0,0,-0.001
    endif
    '
    popstate
    move 8.0
  next
  picklabel 0
  if pk
    i=pk-100
    pushstate
    move -20,-15
    scale 10
    texture imgn[i]
    gosub displaybox
    popstate
  endif
  texture 0
  popstate
  '
  end procedure 'main

  EndScript