.Graphics

In the latest release you can no longer reference .graphics. I use to use code like the following in say Mouse down for example which I am assuming is bad practice. Should I now be moving this code to the paint event and passing the mouse down coordinates to a global?

MOUSEDOWN Event of Canvas
Dim c As Color = HighlightColor
c = HSV(c.Hue, .5, c.Value)
Canvas1.Graphics.ForeColor = c
///////
ME.Graphics.fillRect x,y,xbox,ybox
’ Box outline
ME.graphics.ForeColor = rgb(90, 90, 90)
ME.graphics.drawRect x,y,xbox+1,ybox+1

IF clnum(xspot,yspot) > 0 then
ME.graphics.ForeColor = RGB(0,0,0)
ME.graphics.TextFont = “Times”
ME.graphics.TextSize = 10
ME.graphics.Bold = False
ME.graphics.DrawString STR(clnum(xspot,yspot)),x+3,y+10
end if

yes

not to a global, but to a window property.

Canvas property ?

Canvas1.Graphics Property ?

:
I use Offscreen_Picture.Graphics. to make the drawings, then Canvas1.Backdrop = Offscreen_Picture to display it.

oups yes !

No, not if you ever want it to work on windows.

Ideally you should be drawing to a picture in your canvas.mousedown event, then drawing that picture in the canvas.paint using g.drawpicture. You can then invalidate the area of the canvas that you just painted in the picture and the system will only need to repaint that portion on the canvas that changed. This means that if your canvas needs to repaint, all it needs to do it look at the picture to see what should be on the canvas rather than going through that whole method, clearing the background, drawing the box and the text, even if it needs to repaint just a pixel.

From a quick test on the mac this is different and the canvas has an “internal memory” (off screen buffer) of what is on the canvas and will automatically repaint what is on there, this doesn’t happen in windows.

This is one for the key areas for speed differences between mac and windows.

You should only be doing the calculations for the canvas when something changes rather than calculating it on every paint otherwise if you compound this with lots of canvas controls you will end up with a really poor performing app when you do something like resizing a window and causes all those canvas’ to paint.

Again, all a mute point if you’re only developing for the mac because it handles all this for you, probably in the os, as I doubt this would have been an oversight on xojo’s part.

Here’s a quick example https://www.dropbox.com/s/rduxbjwkgp3yzzn/PaintBuffer.xojo_binary_project?dl=1

If you changed the buffer property to be called graphics you could use this without much code change, other than putting in some refreshrect’s

[quote=413586:@Martin Fitzgibbons]In the latest release you can no longer reference .graphics. I use to use code like the following in say Mouse down for example which I am assuming is bad practice. Should I now be moving this code to the paint event and passing the mouse down coordinates to a global?

MOUSEDOWN Event of Canvas
Dim c As Color = HighlightColor
c = HSV(c.Hue, .5, c.Value)
Canvas1.Graphics.ForeColor = c
///////
ME.Graphics.fillRect x,y,xbox,ybox
’ Box outline
ME.graphics.ForeColor = rgb(90, 90, 90)
ME.graphics.drawRect x,y,xbox+1,ybox+1

IF clnum(xspot,yspot) > 0 then
ME.graphics.ForeColor = RGB(0,0,0)
ME.graphics.TextFont = “Times”
ME.graphics.TextSize = 10
ME.graphics.Bold = False
ME.graphics.DrawString STR(clnum(xspot,yspot)),x+3,y+10
end if[/quote]

This is the programming of the past and has been for many years, all the Operating systems don’t want this any more and have not wanted it like that for long time.

In mouse down then all you need to do is to do something like this:

isDown = true // Variable that you would define on your class
Invalidate()

Then in your

Paint event then you check how to paint it

if isDown then
// Paint it in down state
else
// Paint it in normal state
end if

Thats all you need to learn to be in modern times.

Hello,

I am trying to upgrade my project which works well in Xojo 2018 Release 2, I am now building it in Xojo 2018 Release 4 and am having some issues…

In Xojo 2018 Release 2 Canvas1.MouseDown I have the following code
app.gMousedownXD = X
app.gMousedownyD = Y

In Canvas1.MouseUp, I have
app.gMousedownXU = X
app.gMousedownYU = Y

Canvas1.Graphics.ForeColor = &cFF0000
Canvas1.Graphics.DrawOval ( app.gMousedownXD-3, app.gMousedownYD-3, app.gMousedownXU-app.gMousedownXD+6, app.gMousedownYU-app.gMousedownYD+6 )
Canvas1.Graphics.DrawOval ( app.gMousedownXD, app.gMousedownYD, app.gMousedownXU-app.gMousedownXD, app.gMousedownYU-app.gMousedownYD )

and that works well… the marquee is displayed.

                 ***********************

in Xojo 2018 Release 4 Canvas1.MouseDown I have the following code
app.gMousedownXD = X
app.gMousedownyD = Y

In Canvas1.MouseUp, I have
app.gMousedownXU = X
app.gMousedownYU = Y

MouseUp = true // MouseUp is a property
Invalidate()

In Canvas1.Paint I have
if MouseUp = true Then
g.ForeColor = &cFF0000
g.DrawOval ( app.gMousedownXD-3, app.gMousedownYD-3, app.gMousedownXU-app.gMousedownXD+6, app.gMousedownYU-app.gMousedownYD+6 )
g.DrawOval ( app.gMousedownXD, app.gMousedownYD, app.gMousedownXU-app.gMousedownXD, app.gMousedownYU-app.gMousedownYD )

MouseUp = false

else
// Paint it in normal state
end if

When I do a Canvas1.MouseDown followed by a Canvas1.MouseUp at a different co-ordinate
I do not see any marquee but in Xojo 2018 Release 2 the marquee is displayed.

Any suggestions?

Thanks.

Lennox

@Lennox: Please create a different thread as it much easier to mark one solved if there is only one question included.
Besides, I am pretty sure you will have a spot appear, but only very shortly. You invalidate MouseUp during the paint event, and if you move the mouse over the Canvas, it gets invalidated automatically so it is redrawn with a state of MouseUp = False.

Thanks Ulrich, I will create a new post if your suggestion does not help.

Thanks again.

Lennox