[Gambas-user] Scrollarea Graphics

Sean Sayandeep Khan seany at ...3224...
Mon Nov 17 14:50:15 CET 2014


Hello, I have the folloing setup (See attached image, 
UI1.png). The Canvas is a scrollarea. I want to add text 
commands, such as "ADDTILE 10,10 40,60 hello" in the 
textbox called Command. I expect as output (on clicking 
the button "exec") a tile of width 40 and height 60 to 
appear with top left being 10, 10 in the canvas. Here is 
my code :

' Gambas class file


Public func As String
Public cmds As String[]


Public Sub addtile()
   
   Dim dtls As String[]
   Dim coordinatestring As String
   Dim coords As String[]
   Dim tile_x As Integer
   Dim tile_y As Integer
   
   Dim sizestring As String
   Dim size As String[]
   Dim height As Integer
   Dim width As Integer
   
   Dim lbl As String
   
   dtls = Me.cmds
   
   Status.Text = "Adding tile"
   coordinatestring = dtls[1]
   coords = Split(coordinatestring, ",")
   tile_x = Eval(coords[0])
   tile_y = Eval(coords[1])
   
   sizestring = dtls[2]
   size = Split(sizestring, ",")
   height = size[0]
   width = size[1]
   
   lbl = dtls[3]
   

   Paint.Rectangle(tile_x, tile_y, width, height)
   Paint.Stroke()
   
   
   
End

Public Sub execute()
   Dim commands As String[]
   
   Status.Text = "Executing Command"
     commands = Split(Command.Text, " ", "\\", True, 
False)
     Select commands[0]
       Case "ADDTILE"

         Me.func = "addtile"
         Me.cmds = commands
       Case "REMOVETILE"

     End Select
   Command.Text = ""
   Status.Text = "Done"
   
End


Public Sub _new()

func = "_new"
Canvas.ResizeContents(400, 400)
Canvas.Refresh()
End

Public Sub Form_Open()

End

Public Sub Status_MouseDown()

   

End

Public Sub History_KeyPress()

   

End

Public Sub Button1_Click()

   execute()

End

Public Sub Command_KeyPress()

   

End

Public Sub Canvas_Draw()

   Dim a As Variant[]
   a = Canvas.Children
   Object.Call(Me, func)
   
   Canvas.Refresh()
End



You see, if I drop the canvas.refresh() in subroutine 
canvas_draw() , then only the first tille would be drawn, 
and all subsequent ADDTILE .... calls will be ignored, 
i.e. no new tile is drawn.
If I keep the refresh() then only the last tile is drawn, 
and the previous tiles are erased.

However, I want to keep on adding tiles, and keep the 
previously added tiles.

Also, how do I remove a particular tile added, say as the 
second one, in the sequence, of say, five tiles, and 
retain the other four?

Thank you.




More information about the User mailing list