' IDrawCanavas.bas
' see at /inc/iup_draw.bi

#include once "inc/iup.bi"
#include once "inc/iup_draw.bi"


sub _init_ constructor
  IupOpen(0,0)
end sub

sub _exit_ destructor
  IupClose()
end sub


' redraw canvas (create DrawCanvas on the fly)
function canvas_action_cb cdecl (self as IHandle ptr) as integer
  dim as IDrawCanvas ptr dc  = iupDrawCreateCanvas(self) 
  if dc then
    dim as integer w,h
    iupDrawGetSize(dc,@w,@h)
    iupDrawParentBackground(dc)
    for nLines as integer= 1 to 10
      iupDrawLine(dc, _
                  rnd*w,rnd*h,rnd*w,rnd*h, _
                  rnd*255,rnd*255,rnd*255, _
                    IUP_DRAW_STROKE)
    next

    for nLines as integer= 1 to 10
      iupDrawLine(dc, _
                  rnd*w,rnd*h,rnd*w,rnd*h, _
                  rnd*255,rnd*255,rnd*255, _
                  IUP_DRAW_STROKE_DASH)                    
    next
    iupDrawFlush(dc)
    iupDrawKillCanvas(dc)
  end if  
  return IUP_DEFAULT
end function


'
' main
'
dim as IHandle ptr canvas = IupCanvas(NULL)
IupSetCallback(canvas, "ACTION",@canvas_action_cb)


dim as IHandle ptr dialog=IupDialog(canvas)
IupSetAttribute(dialog, "RASTERSIZE", "320x240")
IupSetAttribute(dialog, "TITLE", "resize me ...")

IupShow(dialog)

IupMainLoop()











