Using canvas from a method

  1. 5 days ago

    Mario v

    Nov 8 Netherlands

    I have just converted my large project from Real Studio 2012 to Xojo 2019r2 and most of the code is executing fine after some tinkering.

    The one thing I can't seem to get working is my canvas related code...

    I have a (global) method that handles my canvas stuff and for that I use the canvas as a parameter:

    Globaal.ToonFoto Function ToonFoto(LokaalGrafics as graphics, Lok_Foto as string) As Picture

    I can't seem to get this to work. With the new Xojo approach to a canvas you need to put all code in the paint event?

    (I am not a daily coder, only for one large project I manage and I have just switched from RS 2012 to Xojo 2019)

  2. Mario v

    Nov 8 Netherlands

    ...and also calling a canvas from a method in the same window: I can't seem to get it to work. :-(

  3. Dave S

    Nov 8 San Diego, California USA
    Edited 5 days ago

    You don't. period.
    All actions on a canvas must be done via that canvas PAINT event

    this was changed sometime after 2012

  4. Christian M

    Nov 8 Pre-Release Testers, Xojo Pro Germany

    I hope I understand your question correctly...

    You can call a method (for example "DrawSomething") from the paint event of the canvas by passing the graphics object to the method like this:

    DrawSomething(g)

    Of course the method "DrawSomething" needs to have a parameter "g as Graphics".
    Then in the method "DrawSomething" you can do your drawing onto g (the graphics object of the canvas), for example like this:

    g.DrawRect(...)
    g.DrawPicture(ToonFoto, ...)

    Everytime you call Canvas.Invalidate (for example from a timers "Action" event) the canvas will do the (re)drawing.

    Also in this case, all drawing is done via the paint event, like Dave already said.

  5. 4 days ago

    Mario v

    Nov 9 Netherlands

    Strange thing is that I was able to run my RS2012 code in Xojo just about a year ago without too much changes. I was considering the switch then also, but the party I develop this project for was not ready for an investment yet. So this must have been removed in a recent Xojo update?

    BUT: I was able to make a start in solving this...
    I am now doing all my "old" stuff in a picture instead and draw that picture onto the canvas. This way I have my old code up and running in Xojo in a couple of days without having to do massive rewrites. I can see what I can improve from there on.

  6. Paul L

    Nov 9 Xojo Inc, Third Party Store Answer http://docs.xojo.com

    Also see:

    https://docs.xojo.com/UserGuide:Updating_Code_That_Used_the_Graphics_Property

  7. 3 days ago

    Mario v

    Nov 10 Netherlands

    Thanks!

  8. @Dave S You don't. period.
    All actions on a canvas must be done via that canvas PAINT event

    this was changed sometime after 2012

    Now with 19r2, this is a "Have To" way to do it.

    I feel the same as back then with threads updating GUI elements, but for me, these changes are fine.
    Needs to updating a lot of code, but I'm not angry about.

    Hint for programmers that want change graphics displayed in a Canvas:
    Set a global variable, then call Canvas.invalidate now, instead of manipulating from within code.

  9. Dave S

    Nov 10 San Diego, California USA

    this has been the "Have to" method for some years now... not new with R2

  10. Michel B

    Nov 10 Pre-Release Testers, Xojo Pro RubberViews.com

    A quick and convenient way to replace Canvas.graphic by creating a new picture and adding it as Canvas backdrop.

    You can then replace canvas.graphic by canvas.backdrop.graphic without changing anything else in your method.

  11. 2 days ago

    Mario v

    Nov 11 Netherlands

    @Dave S this has been the "Have to" method for some years now... not new with R2

    Actually only for a year or so. I tried Xojo 2018 and that still ran my old code. The helptext also confirms that this was removed somewhere in 2018.

    As I said: I'm coming from RB2012r1.2 so I have some catching up to do ;-)

  12. Emile S

    Nov 11 Europe (France, Strasbourg)

    As they already said: it was deprecated in the night of times.

    It ws removed within the previous year.

    Check within R2 IDE how many deprecated you have in your code (that “ran your old code” ;)

  13. 6 hours ago

    Mario v

    6 hours ago Netherlands

    There's a lot deprecated, but most of it is still working in the newest Xojo. The only thing that I needed to fix right away was this canvas stuff, because that was not working anymore. But that is solved now! I used a local picture instead and was able to make it work with minor changes.

    My project is running again and in the next few weeks I am going to replace old code with new.

    Thanks for all the help here!!
    :)

  14. 3 hours ago

    Dave S

    3 hours ago San Diego, California USA
    Edited 3 hours ago

    @Mario vGinneken Actually only for a year or so. I tried Xojo 2018

    Prior to 2018r3 Window and Canvas both had a Graphics property that you could access and draw to. This was deprecated in 2011 because it had significant performance issues on all platforms.

    Deprecate <> removed

  15. 2 hours ago

    Mario v

    2 hours ago Netherlands

    Ah oke, thanks. English is not my first language and I was under the assumption it meant "removed". But Google Translate explains that it means that it is still working, but is discouraged to use :)

or Sign Up to reply!