Refresh canvas (defaultCanvas) in run-time.

  1. ‹ Older
  2. 3 months ago

    Markus W

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

    Does it really say vanvas in your code?

  3. Djamel A

    Jul 15 Oran (Algeria)

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

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

  4. Jeff T

    Jul 16 Midlands of England, Europe
    Edited 3 months 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
  5. 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.

  6. 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
  7. Jeff T

    Jul 16 Midlands of England, Europe
    Edited 3 months 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

  8. 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

  9. 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?

  10. 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.

  11. 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

  12. 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.

  13. 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.

  14. 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.

  15. 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 !

  16. Djamel A

    Jul 17 Oran (Algeria)

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

  17. Djamel A

    Jul 18 Oran (Algeria)

    Now it take account of time control change, it seems Ok, any suggestion or remark ?
    It will be helpful and welcome !
    example attached in this msg "moonphase(TimeChange)_2.rar"link text

  18. Kevin G

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

    Your project worked for me when I selected the Time Change option.

  19. Djamel A

    Jul 18 Oran (Algeria)

    Ah, sorry i forget that i bought Time ctrl and Date ctrl plugins, RB in this time have not .
    I tried with VB6 .ocx DateTimePicker does not run properly under xojo (windows).
    Any way, it is running for time change.
    I was using :

    Dim d as New Date

    extracting time by :
    hrs = d.Date.Hours
    mn = d.Date.Minutes
    ss = d.Date.Seconds

    Instead of :
    hrs = TimeCtrl.Hour
    mn= TimeCtrl.Minute
    ss = TimeCtrl.Second
    Thank you Kevin and others.

  20. Djamel A

    Jul 22 Oran (Algeria)

    @Djamel A;AMRANE Kevin,
    Unlike to textchange, timeCtrl change does not respond.
    an example is attached this msg.

    Hello,
    come back to refresh drawing on canvas.
    I discover that the problem is coming from the DateTime Picker (Einhugur plugin).
    When changing other input data (SkyMap) it means when changing the position
    (latitude and longitude) of observer the sky (stars) are moving well "textchange".
    using simple Textfield and textchange event for hours, minutes,
    and seconds instead of Date Time Picker (Einhugur plugin) the problem disappear.
    Any one has experience with Einhugur Date time picker ?
    I tried to use Microsoft DateTime Picker (ActiveX Component) with out succeed !

  21. Djamel A

    Jul 28 Oran (Algeria)

    @Eugene D 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 :)

    Eugene,
    I am sure now that the Canvas.Refresh problem is done by my DTPicker Time (plugin).
    Drawing is displayed properly when time or date are introduced via textfield.text and textfield textChange Event.

or Sign Up to reply!