Discussion:
canvas wrestling
Bart Pietercil
2007-01-07 17:33:00 UTC
Permalink
Hi List,

passing sunday breaking my head on this simple thing.

Why does this code not draw a string in the new canvas ?

Sub Action()
Dim aCanvas As Canvas

aCanvas = new Canvas1

aCanvas.Top = 120

aCanvas.Graphics.DrawString("allo,allo",0,0,50)
End Sub

I have put a graphic inside the template canvas and I see it is
created after performing the action. ( I see 2 images in the window)

But why the last line doesn't do a thing beats me....

Help REALLY appreciated

TIA

Bart
CV
2007-01-07 18:05:46 UTC
Permalink
Post by Bart Pietercil
Hi List,
passing sunday breaking my head on this simple thing.
Why does this code not draw a string in the new canvas ?
Sub Action()
Dim aCanvas As Canvas
aCanvas = new Canvas1
aCanvas.Top = 120
aCanvas.Graphics.DrawString("allo,allo",0,0,50)
End Sub
I have put a graphic inside the template canvas and I see it is
created after performing the action. ( I see 2 images in the window)
But why the last line doesn't do a thing beats me....
Help REALLY appreciated
Using a y-coordinate of 0 specifies the base(bottom) of the string at
0, thus the string text is off(above), the canvas. Try a larger y-
coordinate, at least aCanvas.Graphics.DrawString("allo, allo", 0,
aCanvas.Graphics.TextHeight, 50). Also, put code in the Paint event
to maintain your image.

Best,

Jack
Bart Pietercil
2007-01-07 18:31:02 UTC
Permalink
Post by CV
Post by Bart Pietercil
Hi List,
passing sunday breaking my head on this simple thing.
Why does this code not draw a string in the new canvas ?
Sub Action()
Dim aCanvas As Canvas
aCanvas = new Canvas1
aCanvas.Top = 120
aCanvas.Graphics.DrawString("allo,allo",0,0,50)
End Sub
I have put a graphic inside the template canvas and I see it is
created after performing the action. ( I see 2 images in the window)
But why the last line doesn't do a thing beats me....
Help REALLY appreciated
Using a y-coordinate of 0 specifies the base(bottom) of the string
at 0, thus the string text is off(above), the canvas. Try a larger
y-coordinate, at least aCanvas.Graphics.DrawString("allo, allo",
0, aCanvas.Graphics.TextHeight, 50).
Changing the coordinates didn't help...
Post by CV
Also, put code in the Paint event to maintain your image.
Could you elaborate on the what and why of putting code in the paint
event ?


Maybe if it is not too much trouble , I could ask to put the
actioncode in a button for

1) "cloning" an offscreen canvas named canvas 1 with nothing in it
2) putting a string inside the canvas
3) putting that cloned canvas at window coordinates 50,50 (example)

I must be doing something obvious completely wrong


TIA

Bart
Post by CV
Best,
Jack
_______________________________________________
<http://www.realsoftware.com/support/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
RBNUBE
2007-01-07 20:45:21 UTC
Permalink
Try something simple like removing the graphic and the wrap, then:

aCanvas.Graphics.DrawString("allo,allo",10,100)

The 10 and 100 should place the text well within an area that can be seen if
your canvas left and top settings are placing the clone in an area where it
will not be 'hiding' the text.

If you are then able to see it, you are on the right track. Go from here.

If you still cannot see it, let me know and I'll send you a simple example
off list.

HTH
Bart Pietercil
2007-01-07 20:56:24 UTC
Permalink
That's what i tried, should work, but doesn't (OSX RB2006/4)

Since I'm a newbie in RB I suppose the fault is some wire in my brain.
Post by RBNUBE
If you still cannot see it, let me know and I'll send you a simple example
off list.
Very much appreciated

TIA

Bart

***@gmail.com
Bart Pietercil
2007-01-07 21:12:17 UTC
Permalink
Nope, RB

nothing is happening, same issue as what I was having. As you said
nothing very special about the code, clicking the button gives
feedback, stepping through the code no exceptions, just... nothing

Do we need to look elsewhere ?

MacBook Pro OSX 10.4.8
Realbasic 2006/4
RBNUBE
2007-01-07 21:16:35 UTC
Permalink
Maybe instead you could send your project to me. I have to leave in about a
half hour...
Bart Pietercil
2007-01-07 21:25:16 UTC
Permalink
Uhm,

the real project is already far to complicated to send (it was the
last screen in the application where I need this functionality)

I was playing with the project you send me.

Out of the box(mail) , I just open it , hit run, click the button no joy
I looked at the code, maybe the left was a bit of so I changed that
to a value of 314
AND i added an image to the backdrop in order to have a visual feedback.

Hit run and I see the image duplicated when clicking the button but
no string appearing, so there must be something wrong with the
drawstring method

Does it run on your end (an does it draw the 'Joe....")?

Bart
Post by RBNUBE
Maybe instead you could send your project to me. I have to leave in about a
half hour...
_______________________________________________
<http://www.realsoftware.com/support/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
RBNUBE
2007-01-07 21:48:54 UTC
Permalink
(Sending complicated projects isn't an issue, I don't think. If you want to
attach it, you should be able to without problem. If you're worried about
other people seeing your code, that's understandable.)


Sure. It works fine on my end...on Windows.

I just tested it on my Mac where it does not appear to work. The clone is
created, but the string is not drawn.

Interestingly enough, placing a MsgBox statement in the code forces the
string to appear on the cloned canvas.


People are recommending that you place code in the Paint event of the
Canvas. This might lead to success, but it will more than likely cause
redraw issues (very annoying and obvious flicker) on Windows. So, if you
want to write for Windows, you may need to add a buffering system.



-----Original Message-----
From: gettingstarted-***@lists.realsoftware.com
[mailto:gettingstarted-***@lists.realsoftware.com] On Behalf Of Bart
Pietercil
Sent: Sunday, January 07, 2007 4:25 PM
To: Getting Started
Subject: Re: canvas wrestling


Uhm,

the real project is already far to complicated to send (it was the
last screen in the application where I need this functionality)

I was playing with the project you send me.

Out of the box(mail) , I just open it , hit run, click the button no joy I
looked at the code, maybe the left was a bit of so I changed that
to a value of 314
AND i added an image to the backdrop in order to have a visual feedback.

Hit run and I see the image duplicated when clicking the button but
no string appearing, so there must be something wrong with the
drawstring method

Does it run on your end (an does it draw the 'Joe....")?

Bart
Post by RBNUBE
Maybe instead you could send your project to me. I have to leave in about a
half hour...
_______________________________________________
<http://www.realsoftware.com/support/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Bart Pietercil
2007-01-07 22:13:01 UTC
Permalink
Hi List,

First special thanks to RBNUBE and CV for helping me out

These are my findings with the drawstring problem

This code on OSX does not work on my macbook pro with RB2006/4

Sub Action()

Dim aCanvas as Canvas

aCanvas = new Canvas1
'
aCanvas.Top = 7
aCanvas.Left = 314
aCanvas.Graphics.TextFont="Arial"
aCanvas.Graphics.TextSize=14
aCanvas.Graphics.ForeColor=RGB(255,0,0)
aCanvas.Graphics.DrawString("Joe Bob Gizzerdamp YEAH!!!",
10,10,aCanvas.Width-10)

End Sub

More precisely everything works but the last line
The code as stated above works on windows ( cfr RBNube)

Jack(CV) helped me by posting that the 3 last lines should be placed
within a select case construct in the paint event of the canvas
That works

However RBNube warns that this will lead to flickering on Windows
systems

So here I am needing something cross-platform AND maintainable (by
this I mean that I can see how I could place differing code for OSX
and Windows, but that can hardly be the way to go for a crossplatform
tool and what seems to me being a fairly common task)

RBNube told me that when placing a messagebox before drawing into the
canvas cured the problem on mac which lead me to this code that works

Sub Action()

Dim aCanvas as Canvas

aCanvas = new Canvas1
'
aCanvas.Top = 7
aCanvas.Left = 314
aCanvas.Graphics.TextFont="Arial"
aCanvas.Graphics.TextSize=14
aCanvas.Graphics.ForeColor=RGB(255,0,0)

self.Refresh(True)

aCanvas.Graphics.DrawString("Joe Bob Gizzerdamp YEAH!!!",
10,10,aCanvas.Width-10)

End Sub

Can somebody shed some light on the way to go ? And as to WHY the
first example does not work?

TIA

Bart Pietercil
RBNUBE
2007-01-08 00:26:43 UTC
Permalink
Something I overlooked (even though it was mentioned before in this thread)
is that if your code is not placed in the Paint event, it will disappear
under certain circumstances. For instance, if you move the window off
screen, then Back on screen.
CV
2007-01-08 00:25:32 UTC
Permalink
And as to WHY the first example does not work?
I don't know why, but apparently Rb refreshed the cloned canvas after
the string drawing from the button was performed. The canvas was
cleared and remained clear since there was no code in Paint to draw
the string again.

Best,

Jack
Bart Pietercil
2007-01-08 10:38:00 UTC
Permalink
And why would it behave differently on Windows?

Bart
Post by CV
And as to WHY the first example does not work?
I don't know why, but apparently Rb refreshed the cloned canvas
after the string drawing from the button was performed. The canvas
was cleared and remained clear since there was no code in Paint to
draw the string again.
Best,
Jack
_______________________________________________
<http://www.realsoftware.com/support/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
CV
2007-01-08 13:15:38 UTC
Permalink
With drawing code in the Paint event, where it should be, it works
the same on WindowsXP and OSX for me. Windows and OSX use different
graphics engines and their order of events can be slightly different
as well. Put your code in the Paint event and let Rb take care of
those differences for you, plus maintain your images during resizes
and so forth.

Best,

Jack
Post by Bart Pietercil
And why would it behave differently on Windows?
Bart
Post by CV
And as to WHY the first example does not work?
I don't know why, but apparently Rb refreshed the cloned canvas
after the string drawing from the button was performed. The canvas
was cleared and remained clear since there was no code in Paint to
draw the string again.
Best,
Jack
_______________________________________________
<http://www.realsoftware.com/support/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
<http://www.realsoftware.com/support/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
CV
2007-01-07 21:24:07 UTC
Permalink
Post by Bart Pietercil
Post by CV
Post by Bart Pietercil
Hi List,
passing sunday breaking my head on this simple thing.
Why does this code not draw a string in the new canvas ?
Sub Action()
Dim aCanvas As Canvas
aCanvas = new Canvas1
aCanvas.Top = 120
aCanvas.Graphics.DrawString("allo,allo",0,0,50)
End Sub
I have put a graphic inside the template canvas and I see it is
created after performing the action. ( I see 2 images in the window)
But why the last line doesn't do a thing beats me....
Help REALLY appreciated
Using a y-coordinate of 0 specifies the base(bottom) of the string
at 0, thus the string text is off(above), the canvas. Try a larger
y-coordinate, at least aCanvas.Graphics.DrawString("allo, allo",
0, aCanvas.Graphics.TextHeight, 50).
Changing the coordinates didn't help...
Post by CV
Also, put code in the Paint event to maintain your image.
Could you elaborate on the what and why of putting code in the
paint event ?
Maybe if it is not too much trouble , I could ask to put the
actioncode in a button for
1) "cloning" an offscreen canvas named canvas 1 with nothing in it
2) putting a string inside the canvas
3) putting that cloned canvas at window coordinates 50,50 (example)
I must be doing something obvious completely wrong
TIA
Bart
I'm sure that you've given your offscreen Canvas1 an index, say 0,
so that it can be cloned. In the button put:

Dim aCanvas as Canvas
aCanvas = new Canvas1
aCanvas.Top = 120

Then in the Paint event of Canvas1 put:

g.DrawString "Hello", 10, 10 // or whatever

Note that in your Paint event there is an index parameter, so if you
make additional clones with different strings you can put a Select
Case based on index.



Best,

Jack
Bart Pietercil
2007-01-07 21:52:29 UTC
Permalink
Thanks Jack,

this works and I can see how to use this, but that leaves the
Post by CV
Dim aCanvas as Canvas
aCanvas = new Canvas1
aCanvas.Top = 120
aCanvas.graphics.DrawString "Hello", 10, 10 // or whatever
As you can see I just added the line you put in the paint event to
the button. So why can I not talk to my new object from the button
code ?

TIA

Bart
Post by CV
I'm sure that you've given your offscreen Canvas1 an index, say 0,
Dim aCanvas as Canvas
aCanvas = new Canvas1
aCanvas.Top = 120
g.DrawString "Hello", 10, 10 // or whatever
Note that in your Paint event there is an index parameter, so if
you make additional clones with different strings you can put a
Select Case based on index.
Best,
Jack
_______________________________________________
<http://www.realsoftware.com/support/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
Phil Heycock
2007-01-07 18:11:55 UTC
Permalink
The 'y' coordinate in text drawing represents the BASELINE for the text...
not the TOP of the text. So, I would guess that your Canvas IS drawing the
text... except that you can't see it, because you are drawing it ABOVE the
'visible' area of the Canvas. Solution: Give the 'y' coordinate some
positive value GREATER THAN Graphics.TextHeight.

HTH

P.
Post by Bart Pietercil
Hi List,
passing sunday breaking my head on this simple thing.
Why does this code not draw a string in the new canvas ?
Sub Action()
Dim aCanvas As Canvas
aCanvas = new Canvas1
aCanvas.Top = 120
aCanvas.Graphics.DrawString("allo,allo",0,0,50)
End Sub
I have put a graphic inside the template canvas and I see it is
created after performing the action. ( I see 2 images in the window)
But why the last line doesn't do a thing beats me....
Help REALLY appreciated
TIA
Loading...