2 canvas

Hello, I need to display many charts on a canvas. It works well.
Then I need to use some kind of vertical ruler (line) to show the values with mousemoove.
Again it works.
But line is depreciated. :frowning:
Therefore I inserted the vertical line into the graphic object. It works fine on a fast PC, but flickers on slower PCs because of the complex drawing code.
Therefore I use two canvases. One for the graphic and one for the line.
On Linux it works perfectly. It doesn’t work on Windows. It is only possible with one canvas.
It is always one canvas visible, but never transparent to the other canvas.
I have more than one chart planned on top of each other in the future.
Any ideas?

If you are drawing the chart in the canvas you can draw the line on the canvas as well. The great thing about using the canvas is that it can do a lot of things. The drawback to the canvas is that you have to do all the work.

Get the graphics object from the canvas (paint event) and then use the Graphics drawing classes to draw the chart and whatever else you need.

1 Like

:scream: Never draw everything on each Paint event!

If the only thing changing is a line, draw the charts to a PICTURE object stored in a property of the canvas. Then your “drawing code” is as complex as DrawPicture / DrawLine.

I have to display the charts, have to zoom and resize and if i click on “Start” the chart get continuously new values attached. To do that with a picture is very complex. Every value from under the line has to fit with the measured values.

@Bob_Keeney3
How can i draw on a canvas particular, without deleting parts of the chart? At the good old Realbasic 2013 it works.

I checked the graphtest from the examples. That is exactly my problem. But the graph and the grid is drawn always in the paint event. Thats not good if the graph is complex.

I found no difference between Canvas.refresh (true or false) (on Linux) ?

Unless every single pixel of the canvas is changed on every paint event, you are doing it wrong repainting all from scratch each time.

In the paint event of the canvas, draw your charts as you do now.

Then use g.drawline () to draw the line on top, instead of trying to use a line control or a second canvas.

If it flickers, try setting the canvas to erasebackground = false, and doublebuffer = true

Also note: you dont need a canvas at all… you can draw on the window itself in exactly the same way, and this avoids some of the problems you would see using one or more canvases

erasebackground ??? doublebuffer ??? Where is that documented?

I the future i have to compare multiple charts with each others by overlaying each other.
How should i do that? In one canvas / window in one paint event?
That will flicker about the complexity of redrawing everything in the paint event.
My idea is to draw the charts in one paint event and to move a line … in another paint event?

Seriously, I think you should take some time to explore the graphics class and how it draws. Then look at the Picture class and look at the alpha channel to figure out transparency.

Figure these out independently, first, and then combine them. I think you are trying to get to step D without first going through steps A, B, & C.

3 Likes

As described i have to pan, zoom, click and show the accurate values under the cursor and have to attach values at the charts. To realise that with pictures is really ugly!

I think i have to find my own solution to bring my App to Windows.
It works perfect on Linux.

I only need a transparent canvas without deleting the underneath canvas.

I can’t find documentation new/old for canvas erasebackground / doublebuffer.

Consider using Object2D objects… they will pan, zoom, and scale easily.

Also:
image

Both are deprecated. As I understood it, both properties stopped being useful when Xojo stopped trying for transparent controls on Windows.

Links:
https://docs.xojo.com/Canvas.DoubleBuffer
https://docs.xojo.com/Canvas.EraseBackground

Good call. I still use Xojo 2015 on Windows

and i thought it is good to search in the new documentation…
There is nothing to find.
I have other problems on Windows with transparent labels, used as buttons.
They are very slow at appstart.
But the main problem still exists: to display a line with mousemove

is not hard.
What code do you use to display the charts already, in the canvas paint event?

At Xojo 2022r1 there are no 2DObjects in the toolbar, but you can write a program to get 2DObjects. But also in in the paint event. That is no solution because everything is in the paint event.
Or am i wrong?

I get all the values for:
g.Drawline (x1, y1 , x2 , y2)
from different arrays with a length of 200-2000, depending of the zoom and pan up to 8 charts

The mouseposition is on the actual x1 pos and shows the values and other combined results on the screen.

am i wrong?

yes

In essence, you create a Group2D object
You add Object2d items to it.
Then in the canvas’ Paint event, you
g.drawobject theGroup2D…

Some example code for that is in the help under Group2D…

Var px As PixmapShape
Var t As TextShape
Var d As New Group2D

px = New PixmapShape(DSC_0343) // DSC_0343 is an image previously added to the project
d.Add(px)

t = New TextShape
t.Y=70
t.Value = “This is what I call a REAL car!”
t.FontName=“Helvetica”
t.Bold = True
d.AddObject(t)
g.DrawObject(d, 100, 100)

its really fast

I don’t understand:

You add Object2d items to it.
Then in the canvas’ Paint event, you
g.drawobject theGroup2D…

But it is always in the paint event. That will flicker.
To display all the charts in full length needs app 100ms to display and the line has to hoover over that and shows all the values.
And with a click the app starts and attaches values on some charts without flickering. It works perfect. IAfter stopping the DAQ al the charts can be displayed and compared by moving a line (with values) without the paintevent of the graphs.

It’s hard to explain but so easy.
I attached a picture

If the mouse moves, the line moves and shows the values on the right.
At the moment i use one canvas for the graph and one for the line. It works perfect.
But not on Windows.

It is easier and faster, obviously if you dont know how to work with the the Picture class and how to draw those pictures to the canvas… beter to follow Bob Keeney advice.

That does NOT exists in xojo

less than 1 ms to display a picture object, draw the line and values

But… good luck with that if you dont want to use pictures.