Refresh canvas (defaultCanvas) in run-time.

  1. last week

    Djamel A

    Jul 11 Oran (Algeria)

    Hello,
    graphics drawn on canvas control move with time system, it means that TimeCtrl ChangeValue event : "Canvas.Refresh" is done.
    unfortunately with Class Canvas this way does not work (defaultCanvas1), graph does not move with time change.

    @Djamel A;AMRANE Init method is called to clear.

    The init method seems to be getting called once to create the picture.

    You need to clear the content every time you want to draw a new version PBuffer.Graphics.ClearRect(0, 0, PBuffer.Width, PBuffer.Height) otherwise you are just going to draw on top of what is already there.

  2. 6 days ago

    Eugene D

    Jul 14 Pre-Release Testers, Xojo Pro Canada scispec.ca

    HI Djamel,

    Usually Canvas.Invalidate is the correct call to try and refresh an image that is drawn on the canvas.

    I am going to guess that your drawing code is in the Canvas.Paint event, and looks something like this:

    Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
      'Draw the picture to the graphics layer
      If PBuffer <> Nil then
        g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
      End If
      'Draw a rectangle around the canvas
      g.DrawRect(0,0,me.Width, me.Height)
    End Sub

    This takes a picture called PBuffer and draws it to the canvas.

    If you want to update the picture based on time, then redraw the new PBuffer picture from the new time, and then call the Canvas1.Invalidate to update the picture in the canvas to the user.

    //Make changes to date/time
    //change variables to draw your new picture based on the time
    //Once the new picture has been drawn for your new time then
    //call Canvas1.invalidate to shown the new picture on the canvas:
    
    Canvas1.invalidate

    I hope this helps :)

  3. 5 days ago
  4. Djamel A

    Jul 15 Oran (Algeria)

    @Eugene D Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint 'Draw the picture to the graphics layer If PBuffer <> Nil then g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height) End If 'Draw a rectangle around the canvas g.DrawRect(0,0,me.Width, me.Height) End Sub

    Unfortunately it does not work (Buffer), unlike :

    Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
    g.DrawRect(0,0,Canvas1.Width,vanvas1.Height)
     
    End Sub

    Instead of Buffer, all controls runs properly, date and time change, CheckBox , ...., but graphic is not so better !

  5. Derk J

    Jul 15 Pre-Release Testers, Xojo Pro

    You may want to set a color g.ForeColor =

  6. Markus W

    Jul 15 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    Does it really say vanvas in your code?

  7. Djamel A

    Jul 15 Oran (Algeria)

    @Markus W Does it really say vanvas in your code?

    g.DrawRect(0,0,Canvas1.Width,canvas1.Height)

  8. 4 days ago

    Jeff T

    Jul 16 Midlands of England, Europe
    Edited 4 days ago

    pBuffer is a picture property of the Window.
    Initialise it when the window opens. Draw something on it , even if it is a line.

    Any time you have new data, draw it on the pBuffer.graphics
    And then invalidate Canvas1 with canvas1.invalidate

    Canvas1 will paint at the next opportunity.
    nb: Even if you have called invalidate 7 times, Canvas1 will paint itself once.

    The code supplied was correct to make this work.. I have added a few lines here

    'Canvas1 Paint event
    Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
      'Draw the picture to the graphics layer
      If PBuffer <> Nil then
        g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
      End If
      'Draw a rectangle around the canvas
      g.DrawRect(0,0,me.Width, me.Height)   
      //possibly me.width -1, me.height -1
    else
        pbuffer = new picture (canvas1.width,canvas1.height,32)
        pbuffer.graphics.drawrect  20,20,30,30  'do something
        me.invalidate   ' paint again at next opportunity so you can see the rectangle 
    End Sub
  9. Djamel A

    Jul 16 Oran (Algeria)
      'Draw the picture to the graphics layer
      If PBuffer <> Nil then
        g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
        //End If
        'Draw a rectangle around the canvas
        g.DrawRect(0,0,me.Width, me.Height)
        //possibly me.width -1, me.height -1
      else
        pbuffer = new picture (CnvSkyMap.width,CnvSkyMap.height,32)
        pbuffer.graphics.drawrect  0,0,700,700  'do something
        
      end if
      me.Invalidate

    I tried with this wrote, but nothing change.

  10. Kevin G

    Jul 16 Pre-Release Testers, Xojo Pro Gatesheed, England

    Would it not be something like:

    'Draw the picture to the graphics layer
      If PBuffer = Nil then
        pbuffer = new picture (CnvSkyMap.width,CnvSkyMap.height,32)
        pbuffer.graphics.drawrect  0,0,700,700  'do something
      end if
      
    g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
    
        'Draw a rectangle around the canvas
        g.DrawRect(0,0,me.Width, me.Height)
        //possibly me.width -1, me.height -1
  11. Jeff T

    Jul 16 Midlands of England, Europe
    Edited 4 days ago

    nothing change.

    I know this works, I use code like it all the time.
    Where /when do you draw on PBuffer?

    Can you decide what your canvas is called?

    does not work (defaultCanvas1),

    Unfortunately it does not work (Buffer), unlike :

    Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
    g.DrawRect(0,0,Canvas1.Width,vanvas1.Height)

    End Sub

    pbuffer = new picture (CnvSkyMap.width,CnvSkyMap.height,32)

    try this, and do not alter it, and make sure it is in the paint event of the actual canvas, whatever it happens to be called.

    Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
      'Draw the picture to the graphics layer
      If PBuffer <> Nil then
        g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
      End If
      'Draw a rectangle around the canvas
      g.DrawRect(0,0,me.Width, me.Height)   
      //possibly me.width -1, me.height -1
    else
    //pbuffer is nil, so draw anything
    g.forecolor = &cff0000
    g.drawrect   10,10,20,90   
    
    
    End Sub

    if you get a red rectangle, pBuffer is nil, and you need to have initialised it and drawn on it.
    If you get nothing, then pBuffer is blank (have you drawn on it yet?) or it is 1 x 1 pixel in size

  12. Djamel A

    Jul 16 Oran (Algeria)

    I think that it will be better to see this simple example (windows with out buffer) attached to this msg.

    link text

  13. Jeff T

    Jul 16 Midlands of England, Europe

    OK.
    It draws a moon. The moon is different when you type numbers.
    There is no timer, there is no animation, there is no TimeCtrl , but there is a moon.

    What is the problem?

  14. 3 days ago

    Djamel A

    Jul 17 Oran (Algeria)

    @Jeff T OK.
    It draws a moon. The moon is different when you type numbers.
    There is no timer, there is no animation, there is no TimeCtrl , but there is a moon.

    What is the problem?

    I gave a simple example with txtPhaseAngle textChange event , moon is just for test (change value).
    This drawing is done with out buffer (see Paint event), adding buffer nothing done.
    It seems that when i use buffer, the controls does not respond.

  15. Djamel A

    Jul 17 Oran (Algeria)

    This attached example is wrote with Buffer property it seems running by calling DrawMoon in the PhaseAngle textchange event.
    Is it a good way ?link text

  16. Kevin G

    Jul 17 Pre-Release Testers, Xojo Pro Gatesheed, England

    Try clearing PBuffer before you commence drawing otherwise you will be drawing over the top of the previous content.

  17. Djamel A

    Jul 17 Oran (Algeria)

    @Kevin G Try clearing PBuffer before you commence drawing otherwise you will be drawing over the top of the previous content.

    Init method is called to clear.

  18. Kevin G

    Jul 17 Pre-Release Testers, Xojo Pro Answer Gatesheed, England

    @Djamel A;AMRANE Init method is called to clear.

    The init method seems to be getting called once to create the picture.

    You need to clear the content every time you want to draw a new version PBuffer.Graphics.ClearRect(0, 0, PBuffer.Width, PBuffer.Height) otherwise you are just going to draw on top of what is already there.

  19. Djamel A

    Jul 17 Oran (Algeria)

    @Kevin G You need to clear the content every time you want to draw a new version PBuffer.Graphics.ClearRect(0, 0, PBuffer.Width, PBuffer.Height) otherwise you are just going to draw on top of what is already there.

    Perfect, going properly !

  20. Djamel A

    Jul 17 Oran (Algeria)

    Kevin,
    Unlike to textchange, timeCtrl change does not respond.
    an example is attached this msg.
    link text

  21. Newer ›

or Sign Up to reply!