Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Sep 16, 2019 11:10 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Canvas resizing
PostPosted: Mon May 13, 2013 7:22 am 
Offline

Joined: Tue Aug 28, 2012 3:52 am
Posts: 28
I can't seem to find an answer for this issue: when resizing a canvas displaying a picture, the image disappears while resizing and appears when the mousebutton is released. Is it possible to keep the picture visible while the actual resizing occurs? Is there any 3rd party tool of library?

Alexander


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Mon May 13, 2013 9:10 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Mac or windows?
Isnt there a OS setting in windows that governs whether redrawing occurs during a resize?


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Mon May 13, 2013 9:13 am 
Offline

Joined: Tue Aug 28, 2012 3:52 am
Posts: 28
Mac. Never mind, I found the solution in http://www.scispec.ca/Realbasic/Realbasic.htm, posted in topic 'Canvas drag and drop'.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Tue May 14, 2013 4:44 am 
Offline

Joined: Tue Aug 28, 2012 3:52 am
Posts: 28
Mmm.. still got a minor problem:

I read a PNG file to use in the Canvas. In the Paint event in the canvas I have this code:

Dim scale As Double
scale = Min( g.Width / me.backdrop.Width, g.Height / me.backdrop.Height )
g.DrawPicture( me.backdrop , 0, 0, scale * me.backdrop.Width, scale * me.backdrop.Height, 0, 0, me.backdrop.Width, me.backdrop.Height )


The problem with this is that the Canvas shows 2 pictures: one unscaled version of the PNG and one scaled version. Upon resizing the Canvas the scaled version responds accordingly, but the original picture remains visible behind the scaled picture.

I use the Backdrop property because when I don't assign a backdrop file the compiler reports an error on the g.drawpicture function (NIL object).


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Tue May 14, 2013 5:20 am 
Offline

Joined: Thu Apr 10, 2008 6:03 am
Posts: 303
Location: Paris-La Défense, France
Using backdrop + drawing the same picture in the Canvas isn't the way to go.

You can create a new Class (myCanvas) derived from Canvas.
In the IDE, set the backdrop to the picture.

Add a "Pic As Picture" property to the myCanvas.

Then in the myCanvas.Open event add the following code:
If me.backdrop <> Nil then
me.Pic = New Picture(Backdrop.width, Backdrop.Height, 32)
me.pic.graphics.drawpicture(Backdrop, 0, 0)
If Backdrop.mask(false) <> Nil then
me.pic.graphics.mask.drawpicture(Backdrop.mask, 0, 0)
End If
End If

Backdrop=Nil


And finally in the myCanvas.Paint event:
If Pic <> Nil then
Dim scale As Double
scale = Min( g.Width / me.Pic.Width, g.Height / me.Pic.Height )
g.DrawPicture( me.Pic , 0, 0, scale * me.Pic.Width, scale * me.Pic.Height, 0, 0, me.Pic.Width, me.Pic.Height )
End If

_________________
Check my Website for high quality custom controls and classes (no plugins) for Windows, Mac OS and Linux
REALBasic 2012 R2 on Win 7 & Mac OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Tue May 14, 2013 7:36 am 
Offline

Joined: Tue Aug 28, 2012 3:52 am
Posts: 28
Hi jeremy,

thanks for your reply. Two things:

- there seems to be an error in the Open event:

If me.backdrop <> Nil then
me.Pic = New Picture(Backdrop.width, Backdrop.Height, 32)
me.pic.graphics.drawpicture(Backdrop, 0, 0)
If Backdrop.mask(false) <> Nil then
//me.pic.graphics.mask.drawpicture(Backdrop.mask, 0, 0)<-compiler error
me.pic.Graphics.DrawPicture(Backdrop.Mask,0,0)
End If
End If

Backdrop=Nil


- if I load a picture in the IDE as backdrop I can scale it no problems
- if I load a picture programmatically I cannot scale it [Edit: I was wrong; it must be bound to the Pic property. Works fine now. Thanks!!)

Alexander


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Tue May 14, 2013 8:47 am 
Offline

Joined: Thu Apr 10, 2008 6:03 am
Posts: 303
Location: Paris-La Défense, France
Hi Alexander,

If you add the backdrop programmatically it will certainly not work as the Open event of the Canvas has already been executed.
In that case, set the myCanvas.Pic property instead of backdrop.

_________________
Check my Website for high quality custom controls and classes (no plugins) for Windows, Mac OS and Linux
REALBasic 2012 R2 on Win 7 & Mac OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Wed May 15, 2013 1:47 pm 
Offline

Joined: Tue Aug 28, 2012 3:52 am
Posts: 28
Hi Jeremy,

I see you have quite some experience with the Canvas object. I have another question for you. In my application, there is one canvas visible. In this Canvas I show a picture. When the user enlarges the window, and there is room, I want to show a second picture/page. I have fiddled with this, but it is difficult to get the Canvasses scaled accordingly/synchrone.

To omit this, is it possible to create a Picture from 2 Pictures, that is, showing 2 Pictures next to each other in a Canvas?


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Thu May 16, 2013 6:44 am 
Offline

Joined: Thu Apr 10, 2008 6:03 am
Posts: 303
Location: Paris-La Défense, France
Hi,

Yes you can draw two pictures in a canvas using the "g As Graphics" property.

You will need a bit of math to position the pictures properly.

first test if the width of the canvas can accept to display two pictures.

_________________
Check my Website for high quality custom controls and classes (no plugins) for Windows, Mac OS and Linux
REALBasic 2012 R2 on Win 7 & Mac OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Thu May 16, 2013 8:59 am 
Offline

Joined: Tue Aug 28, 2012 3:52 am
Posts: 28
Thanks,

Ehmmmm... I thought like this (I gave the myCanvas object a 2nd property as Pic). In the Paint event:

If Pic1<> Nil then
Dim scale As Double
scale = Min( g.Width / me.Pic1.Width, g.Height / me.Pic1.Height )
g.DrawPicture( me.Pic1 , 0, 0, scale * me.Pic1.Width, scale * me.Pic1.Height, 0, 0, me.Pic1.Width, me.Pic1.Height )

End If
If Pic2 <> Nil then
Dim scale As Double
scale = Min( g.Width / me.Pic2.Width, g.Height / me.Pic2.Height )
g.DrawPicture( me.Pic2 , 0, me.Pic1.Width+20, scale * me.Pic2.Width, scale * me.Pic2.Height, 0, 0, me.Pic2.Width, me.Pic2.Height )
end if


But the picture doesn't show up. In the Resize event I check wether the Canvas.Width is enough to place 2 pictures.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Thu May 16, 2013 12:23 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
1) You need to take the width of BOTH pictures into account when you calculate the scale factor of either one.

2) You're using pic1.Width as the Y coordinate when you draw pic2.

3) You need to use the scaled pic1.Width (as the X coordinate) when you draw pic2.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas resizing
PostPosted: Sat May 18, 2013 10:41 am 
Offline

Joined: Tue Aug 28, 2012 3:52 am
Posts: 28
OK,

thanks, I will look into it...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group