Discussion:
Clear Canvas?
Jeff Ayling
2004-06-15 14:12:41 UTC
Permalink
Hi all,

Just wondering how to completely clear a canvas of graphic elements
which have been added.

I'm trying:

canvas2.graphics.clearrect 0,0,canvas2.width,canvas2.height

but it isn't clearing the canvas.

Any thoughts would be great,


thanks


Jeff

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Charles Yeomans
2004-06-15 14:21:54 UTC
Permalink
Post by Jeff Ayling
Hi all,
Just wondering how to completely clear a canvas of graphic elements
which have been added.
canvas2.graphics.clearrect 0,0,canvas2.width,canvas2.height
but it isn't clearing the canvas.
Any thoughts would be great,
Where did you add the graphic elements?

Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-15 14:45:36 UTC
Permalink
Post by Charles Yeomans
Post by Jeff Ayling
Hi all,
Just wondering how to completely clear a canvas of graphic elements
which have been added.
canvas2.graphics.clearrect 0,0,canvas2.width,canvas2.height
but it isn't clearing the canvas.
Any thoughts would be great,
Where did you add the graphic elements?
Perhaps I should be asking a different question here....

What would be the best way to display a few hundred thumbnail images -
as a single column which scrolls up and down - and these thumbnails
each have to be clickable.

So, I have a canvas - canvas2 - with an embedded canvas -canvas1(0)
- then as I parse my thumbnail directory I add each thumbnail as a new
canvas1 so that when I scroll canvas2 all the thumbnails scroll because
they are embedded.

The problem is that once the c.top value is >32000 strange things start
happening (overlapping images etc) so I may have to display only 100 at
a time....this is my problem - clearing canvas2 of all embedded canvas1
images so that I can start again and add a new 100 thumbnails.

Sorry it sounds confusing - It's late and I'm having trouble explaining
:-)


Here is my rough code.

Dim i,n,j,k,m,t,v,w,mc as Integer
Dim f,f2 as FolderItem
dim c as canvas
Dim p,p1 as picture
dim b as boolean
d=new dictionary
canvas1(0).top=-250
canvas2.height=10000
scrollBar1.maximum=10000
j=150
f=getfolderItem("thumbs")
n=f.count
k=550
t=0
m=1

scrollBar1.lineStep=j
scrollBar1.PageStep=j
If n>0 then
For i=1 to n

if left(f.item(i).name,1)<>"." and f.item(i).isReadable=true and
right(f.item(i).name,4)=".gif" then
p=f.item(i).openasPicture
c=new canvas1
c.top=t-scrollBar1.value
c.width=p.width
c.height=p.height
c.left=550
mc=mc+1
d.Value(mc)=f.item(i).absolutePath

p1=newpicture(j,j,screen(0).depth)
if p<>Nil then

p1=p
c.backdrop=p
canvas2.refresh
window1.refresh
k=k+j
m=m+1
if m=2 then
if t>1000 then
scrollBar1.maximum=t-j-j-j
end
t=t+j+50
k=0
m=1
end
end

end





Next
End if


_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Thomas Reed
2004-06-15 14:55:45 UTC
Permalink
Post by Jeff Ayling
So, I have a canvas - canvas2 - with an embedded canvas
-canvas1(0) - then as I parse my thumbnail directory I add each
thumbnail as a new canvas
Ahh, well, there's your problem. You're clearing canvas2, but not
all of the various canvas1s. They still have contents, and being on
top of canvas2, will draw them.

This sounds like a troublesome approach to a thumbnail list. If I
were you, I would write code to draw all the thumbnails in canvas2
and eliminate the canvas1 array altogether.
--
-Thomas

Personal web page: <http://homepage.mac.com/thomasareed/>
My shareware: <http://www.bitjuggler.com/>
Free REALbasic code: <http://www.bitjuggler.com/extra/>

There are 10 kinds of people in the world -- those who understand binary
numbers and those who don't.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-15 15:01:21 UTC
Permalink
So, I have a canvas - canvas2 - with an embedded canvas -canvas1(0)
- then as I parse my thumbnail directory I add each thumbnail as a
new canvas
Ahh, well, there's your problem. You're clearing canvas2, but not all
of the various canvas1s. They still have contents, and being on top
of canvas2, will draw them.
This sounds like a troublesome approach to a thumbnail list. If I
were you, I would write code to draw all the thumbnails in canvas2 and
eliminate the canvas1 array altogether.
--
-Thomas
Yep, that's the problem,

Now I just need to work out how to make each thumbnail on a single
canvas clickable...

Thanks Thomas ... and everyone else for the other ideas.

Cheers


Jeff

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Joseph J. Strout
2004-06-16 01:30:33 UTC
Permalink
Post by Jeff Ayling
Yep, that's the problem,
Now I just need to work out how to make each thumbnail on a single
canvas clickable...
Or go the easy route, and just use a listbox. :)

Best,
- Joe
--
,------------------------------------------------------------------.
| Joseph J. Strout REAL Software, Inc. |
| joe-***@public.gmane.org http://www.realsoftware.com |
`------------------------------------------------------------------'
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-16 03:31:23 UTC
Permalink
Post by Joseph J. Strout
Post by Jeff Ayling
Yep, that's the problem,
Now I just need to work out how to make each thumbnail on a single
canvas clickable...
Or go the easy route, and just use a listbox. :)
Best,
- Joe
I must be doing something very wrong...

After using a

listbox1.addrow ""

my CellTextPaint event always returns '0' when I have

msgbox str(row)

at the top of the CellTextPaint event.

I would have thought that the row would increase as each new
listbox1.addrow is called

Cheers


Jeff

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Will Leshner
2004-06-16 03:34:16 UTC
Permalink
Post by Jeff Ayling
I would have thought that the row would increase as each new
listbox1.addrow is called
Yes, but it is starting the refresh with the first row, which is row 0.
Then, when you dismiss the dialog, most likely it has to refresh again,
starting again with row 0.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-16 03:41:29 UTC
Permalink
Post by Will Leshner
Post by Jeff Ayling
I would have thought that the row would increase as each new
listbox1.addrow is called
Yes, but it is starting the refresh with the first row, which is row
0. Then, when you dismiss the dialog, most likely it has to refresh
again, starting again with row 0.
Hi Will,

thanks for your help.

I have the following in my CellTextPaint event:

g.DrawPicture thisthumb,0,0
return true

But the new picture is replacing every thumbnail in the listbox

In my thread I have:
//within f.count loop
P=f.item(i).openaspicture
thisthumb=P
listBox1.addrow ""


I see each new thumbnail appear in the listbox however each row
contains only the new image - then when the thread finishes I have a
few hundred rows all with the same thumbnail rather than a few hundred
rows each with a unique thumbnail


Any thoughts would be great,

Cheers

Jeff

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Will Leshner
2004-06-16 03:46:47 UTC
Permalink
Post by Jeff Ayling
g.DrawPicture thisthumb,0,0
return true
But the new picture is replacing every thumbnail in the listbox
//within f.count loop
P=f.item(i).openaspicture
thisthumb=P
listBox1.addrow ""
I see each new thumbnail appear in the listbox however each row
contains only the new image - then when the thread finishes I have a
few hundred rows all with the same thumbnail rather than a few hundred
rows each with a unique thumbnail
But it would make sense that every row would paint the same picture
since you are painting the same picture for every row. If you wanted to
paint a different picture for each row, you'd have to specify a
different picture depending on which row you were painting.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-16 03:51:56 UTC
Permalink
Post by Will Leshner
Post by Jeff Ayling
g.DrawPicture thisthumb,0,0
return true
But the new picture is replacing every thumbnail in the listbox
//within f.count loop
P=f.item(i).openaspicture
thisthumb=P
listBox1.addrow ""
I see each new thumbnail appear in the listbox however each row
contains only the new image - then when the thread finishes I have a
few hundred rows all with the same thumbnail rather than a few
hundred rows each with a unique thumbnail
But it would make sense that every row would paint the same picture
since you are painting the same picture for every row. If you wanted
to paint a different picture for each row, you'd have to specify a
different picture depending on which row you were painting.
Ok, I think I'm getting it now.

thanks again for your help

Cheers


Jeff

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Joseph J. Strout
2004-06-15 14:50:22 UTC
Permalink
Post by Jeff Ayling
What would be the best way to display a few hundred thumbnail images
- as a single column which scrolls up and down - and these
thumbnails each have to be clickable.
Use a Listbox, in which you draw the thumbnails in the CellTextPaint
event. (Remember to set the DefaultRowHeight to the height you want
for your thumbnails.)

Best,
- Joe
--
,------------------------------------------------------------------.
| Joseph J. Strout REAL Software, Inc. |
| joe-***@public.gmane.org http://www.realsoftware.com |
`------------------------------------------------------------------'
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-15 15:29:16 UTC
Permalink
Post by Joseph J. Strout
Post by Jeff Ayling
What would be the best way to display a few hundred thumbnail images
- as a single column which scrolls up and down - and these thumbnails
each have to be clickable.
Use a Listbox, in which you draw the thumbnails in the CellTextPaint
event. (Remember to set the DefaultRowHeight to the height you want
for your thumbnails.)
Best,
- Joe
--
Hi Joe,

Great idea, thanks.

I'm just having a little trouble getting it working though.

Could anyone show me a little example of how to trigger the
CellTextPaint event.

I need to cycle through my "thumbnails" folder and add each image found
as a background image for that row.

Cheers


Jeff

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-15 15:39:49 UTC
Permalink
Post by Jeff Ayling
Post by Joseph J. Strout
Post by Jeff Ayling
What would be the best way to display a few hundred thumbnail images
- as a single column which scrolls up and down - and these
thumbnails each have to be clickable.
Use a Listbox, in which you draw the thumbnails in the CellTextPaint
event. (Remember to set the DefaultRowHeight to the height you want
for your thumbnails.)
Best,
- Joe
--
Hi Joe,
Great idea, thanks.
I'm just having a little trouble getting it working though.
Could anyone show me a little example of how to trigger the
CellTextPaint event.
I need to cycle through my "thumbnails" folder and add each image
found as a background image for that row.
Cheers
Jeff
My thumbnails sit too far to the left and chopped when I use:

listBox1.RowPicture(listbox1.lastIndex)=p

Is there any way of moving the image to the right a bit?

Or shouldn't I be using RowPicture to add these thumbnails to a listbox

The thumbnails are approx 150 W by 200 H ... are they too big to use
RowPicture?

Cheers


Jeff




_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Joseph J. Strout
2004-06-15 17:01:28 UTC
Permalink
Post by Jeff Ayling
Post by Jeff Ayling
Could anyone show me a little example of how to trigger the
CellTextPaint event.
You don't trigger it; the listbox itself triggers it when a cell
needs to be redrawn. (You do need to add a row for each row you want
to draw, of course; lb.AddRow "" will suffice.)
Post by Jeff Ayling
listBox1.RowPicture(listbox1.lastIndex)=p
So don't use that. Draw your pictures in the CellTextPaint event instead.
Post by Jeff Ayling
Or shouldn't I be using RowPicture to add these thumbnails to a listbox
Correct, you shouldn't.
Post by Jeff Ayling
The thumbnails are approx 150 W by 200 H ... are they too big to use
RowPicture?
Yes.

Best,
- Joe
--
,------------------------------------------------------------------.
| Joseph J. Strout REAL Software, Inc. |
| joe-***@public.gmane.org http://www.realsoftware.com |
`------------------------------------------------------------------'
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-16 03:22:28 UTC
Permalink
Post by Jeff Ayling
Post by Jeff Ayling
Could anyone show me a little example of how to trigger the
CellTextPaint event.
You don't trigger it; the listbox itself triggers it when a cell needs
to be redrawn. (You do need to add a row for each row you want to
draw, of course; lb.AddRow "" will suffice.)
Post by Jeff Ayling
listBox1.RowPicture(listbox1.lastIndex)=p
So don't use that. Draw your pictures in the CellTextPaint event instead.
Post by Jeff Ayling
Or shouldn't I be using RowPicture to add these thumbnails to a listbox
Correct, you shouldn't.
Post by Jeff Ayling
The thumbnails are approx 150 W by 200 H ... are they too big to use
RowPicture?
Yes.
Best,
- Joe
Hi again,

I have the following in my CellTextPaint event:

g.DrawPicture thisthumb,0,0
return true

But the new picture is replacing every thumbnail in the listbox

In my thread I have:
//within f.count loop
P=f.item(i).openaspicture
thisthumb=P
listBox1.addrow ""


I see each new thumbnail appear in the listbox however each row
contains only the new image - then when the thread finishes I have a
few hundred rows all with the same thumbnail rather than a few hundred
rows each with a unique thumbnail


Any thoughts would be great,

Cheers

Jeff



_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Seth Willits
2004-06-16 04:06:37 UTC
Permalink
Post by Jeff Ayling
g.DrawPicture thisthumb,0,0
return true
But the new picture is replacing every thumbnail in the listbox
//within f.count loop
P=f.item(i).openaspicture
thisthumb=P
listBox1.addrow ""
You aren't supposed to count on when the event fires. As you've found
out, it doesn't fire after you add the row. Instead it fires when it
needs to, which it finds is later on when RB gets control again (after
your method/event ends). The second thing you're doing wrong is
thinking that the event only fires once. This is not true. That event,
as ALL paint events, will fire MANY times. If you scroll out and scroll
back in the event will fire again because it needs to redraw.

What you need to do is either keep an array of 100 thumbnails or open
the file in the event and draw it.



Seth Willits
------------------------------------------------------------------------
---
President and Lead Developer of Freak Software - http://www.freaksw.com
REALbasic Guru at ResExcellence - http://www.resexcellence.com/realbasic

"We call that person who has lost his father, an orphan; and a widower
that
man who has lost his wife. But that man who has known the immense
unhappiness of losing a friend, by what name do we call him? Here every
language is silent and holds its peace in impotence."
-- Joseph Roux
------------------------------------------------------------------------
---

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Jeff Ayling
2004-06-16 04:38:18 UTC
Permalink
Post by Seth Willits
Post by Jeff Ayling
g.DrawPicture thisthumb,0,0
return true
But the new picture is replacing every thumbnail in the listbox
//within f.count loop
P=f.item(i).openaspicture
thisthumb=P
listBox1.addrow ""
You aren't supposed to count on when the event fires. As you've found
out, it doesn't fire after you add the row. Instead it fires when it
needs to, which it finds is later on when RB gets control again (after
your method/event ends). The second thing you're doing wrong is
thinking that the event only fires once. This is not true. That event,
as ALL paint events, will fire MANY times. If you scroll out and
scroll back in the event will fire again because it needs to redraw.
What you need to do is either keep an array of 100 thumbnails or open
the file in the event and draw it.
Thanks folks,

All working perfectly now :-)

The images look like their not 32 bit - or high quality - or whatever
the correct terminology is.

They look a little washed out - the original thumbnails are high
quality but they're not once in the listbox.

Where in the CellTextPaint g.Drampicture p,0,0 can I adjust the image
resolution so that it appears at it's original quality?

Cheers


Jeff

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Joseph J. Strout
2004-06-16 13:33:22 UTC
Permalink
Post by Seth Willits
What you need to do is either keep an array of 100 thumbnails or
open the file in the event and draw it.
Or make use of CellTag. In your setup code, do something like this:

ListBox1.AddRow ""
ListBox1.CellTag( ListBox1.LastIndex, 0 ) = f.item(i).openaspicture

then in CellTextPaint, do:

Dim p as Picture
p = me.CellTag( row, 0 )
if p <> nil then g.DrawPicture p, 0, 0

Cheers,
- Joe
--
,------------------------------------------------------------------.
| Joseph J. Strout REAL Software, Inc. |
| joe-***@public.gmane.org http://www.realsoftware.com |
`------------------------------------------------------------------'
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
William Squires
2004-06-15 14:48:02 UTC
Permalink
In the Paint() event, put:

Sub Paint()
...
If (clearFlag = True) Then
// Use this if your canvas background is a solid color...
g.ForeColor = RGB(255, 255, 255) // or whatever your background
color is
g.FillRect 0, 0, Me.Width-1, Me.Height-1

// or this, if your canvas has a picture as a backdrop. Note that
for this to work, you must have
// the picture "myCustomCanvasBackdropPicture" in the project!
// g.DrawPicture myCustomCanvasBackdropPicture, 0, 0
Else
// Your regular drawing code goes here...
End If
...
End Sub

Define a "Protected clearFlag As Boolean" property for the subclass,
and make a method, Clear() (or Cls(), or whatever...):

Sub Clear()
clearFlag = True
Me.Refresh() // forces the Paint() event to occur
clearFlag = False
End Sub

Also, if you're trying to clear it from outside the canvas, try giving
it a call to Refresh() and see what happens... :)
Post by Jeff Ayling
Hi all,
Just wondering how to completely clear a canvas of graphic elements
which have been added.
canvas2.graphics.clearrect 0,0,canvas2.width,canvas2.height
but it isn't clearing the canvas.
Any thoughts would be great,
thanks
Jeff
_______________________________________________
<http://support.realsoftware.com/listmanager/>
<http://support.realsoftware.com/listarchives/lists.html>
William H Squires Jr
wsquires-uPW4AIIVxGbRZPF1ST97DpYMw5pvChx+@public.gmane.org <- remove the .nospam

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
CV
2004-06-15 14:44:06 UTC
Permalink
Perhaps you have some code in the canvas's Paint event. If so, it wil
execute whenever the canvas decides that it needs to refresh itself, thus
maintaining the image. If this is what you have, then incorporate a
conditional with a boolean into the aforementioned Paint event code
reflecting the case in which you want the image cleared along with the
current case in which you want the image drawn. Then set the boolean flag
and do a Canvas2.refresh from the location that you are now calling the
ClearRect line below.

HTH

Jack


----- Original Message -----
From: "Jeff Ayling" <jeff-***@public.gmane.org>
To: "REALbasic NUG" <realbasic-nug-Gjhu/N1EzaPthnj+***@public.gmane.org>
Sent: Tuesday, June 15, 2004 9:12 AM
Subject: Clear Canvas?
Post by Jeff Ayling
Hi all,
Just wondering how to completely clear a canvas of graphic elements
which have been added.
canvas2.graphics.clearrect 0,0,canvas2.width,canvas2.height
but it isn't clearing the canvas.
Any thoughts would be great,
thanks
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Loading...