Calling the Paint event

  1. 3 months ago

    Hey guys,
    I've got a project going on and i want to draw a border around multiple canvas from clicking on one. Also, how do i call the paint event? I've read it's canvas.refresh but it does not work.

  2. shao s

    May 8 Pre-Release Testers Sudbury, Ontario, Canada

    Move the code, from your .Paint event, to a method and then you can call that method from the .Paint event, as well as from other methods..

  3. Markus W

    May 8 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    It’s canvas1.refresh or whatevernamethecanvashas.refresh

    Canvas.refresh would call the class which obviously won’t work.

  4. Dave S

    May 8 San Diego, California USA

    Avoid using CANVAS1.REFRESH if at all possible... it can lead to over-use of the CPU if not done properly....

    use CANVAS1.INVALIDATE instead... this allows the OS to schedule the exact refresh.

    REFRESH does it "immediately" and without regard to other recent calls to REFRESH
    INVALIDATE does it at the next CPU cycle that it can....

    canvas1.refresh
    canvas1.refresh
    canvas1.refresh
    canvas1.refresh
    canvas1.refresh

    will call the PAINT event FIVE times

    while

    canvas1.Invalidate
    canvas1.Invalidate
    canvas1.Invalidate
    canvas1.Invalidate
    canvas1.Invalidate

    calls it ONCE

  5. Detect event in mouse-down or other mouse events and
    decide what to do with it.
    is x and y in the given rectangle Example Rect1 = true
    then draw in paint
    if Rect1 = true then g.drawrect (left, top, width, height)

    call canvas1.invalidate (false) in mouse-down

  6. Thanks i'll try it out!

  7. shao s

    May 8 Pre-Release Testers Sudbury, Ontario, Canada

    I thought we were supposed to use .Invalidate instead of .Refresh

    .Refresh does it right then and there
    .Invalidate waits until the next screen refresh (or something like that)

  8. Greg O

    May 9 Xojo Inc Somewhere near Raleigh, NC

    @shao s I thought we were supposed to use .Invalidate instead of .Refresh

    .Refresh does it right then and there
    .Invalidate waits until the next screen refresh (or something like that)

    Yup. That’s exactly what Dave said.

  9. shao s

    May 9 Pre-Release Testers Sudbury, Ontario, Canada

    oh.. I blocked Dave a while back, so don't see his posts..

  10. I just realized my 1st question wasn't answered. Though i checked the xojo dev center and other resources again and it seems it has to be done manually. There's no way to make a border appear around a canvas which I just clicked on with a premade function ? Is there a place on this forum or somewhere on the net that contains lots of functions made from people which everyone can use ? Like an online book containing encapsuled functions that can be used in whatever way we see fit for the project we make ? Finally, can i use g as graphics somewhere else than in the paint event ?

  11. Michel B

    May 10 Pre-Release Testers RubberViews.com
    Edited 3 months ago

    @LouisRobitaille Hey guys,
    I've got a project going on and i want to draw a border around multiple canvas from clicking on one. Also, how do i call the paint event? I've read it's canvas.refresh but it does not work.

    Just use Drawrect in the Paint event to draw the border in each canvas. Then when you do canvas.invalidate which will trigger the Paint event, and it will draw it.

    http://docs.xojo.com/index.php/Graphics.DrawRect

  12. Dave S

    May 10 San Diego, California USA

    @LouisRobitaille Finally, can i use g as graphics somewhere else than in the paint event ?

    the CANVAS control and the PICTURE object both have a graphics context

    The CANVAS context cannot be accessed outside of the PAINT event, although you could forward if to another method

    In some cases its best to draw into a picture and then have canvas display that picture... espeically if a large part of the display remains unchanged from cycle to cycle

  13. @Michel B Just use Drawrect in the Paint event to draw the border in each canvas. Then when you do canvas.invalidate which will trigger the Paint event, and it will draw it.

    http://docs.xojo.com/index.php/Graphics.DrawRect

    This doesn't seem to take the canvas having a backdrop into consideration. Is there a way to draw a transparent rectangle (borders only)?

  14. Dave S

    May 10 San Diego, California USA
    Edited 3 months ago

    confused... you can only draw within a graphics context

    g.penWidth=50
    g.drawrect 25,25,g.width-50,g.height-50

    that draws a 50px wide border around whatever in inthe graphics context

  15. @Dave S confused... you can only draw within a graphics context

    I'm new to coding so could you explain to me what a graphic context is ? I searched it on the net and I don't really get the definition most website are giving.

  16. Michel B

    May 10 Pre-Release Testers RubberViews.com
    Edited 3 months ago

    @LouisRobitaille This doesn't seem to take the canvas having a backdrop into consideration. Is there a way to draw a transparent rectangle (borders only)?

    This will draw only the border. The rest will remain transparent.

  17. Dave S

    May 10 San Diego, California USA

    @LouisRobitaille what a graphic context is

    in relation to a Canvas it is "g"

  18. Markus W

    May 10 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...
    Edited 3 months ago

    A canvas has more than just the drawing area. It has properties like left, right, name etc, it has events like open and paint, it has methods and all kinds of “stuff”. Now where the canvas can draw is the graphics context (or g for short) and also the backdrop (though try to avoid the backdrop).

    Part of the confusion is that we associate picture with a photo, and Graphics with a drawing. But if “graphics” is the drawing then what do you call the area where you do the drawing? Canvas is already taken for the class name, picture is already taken for another class name, so the graphics is drawn in the … graphics context.

  19. Thanks for all you answers! I now understand those concepts.

or Sign Up to reply!