New topic: Deprecated Canvas.graphics problem
<http://forums.realsoftware.com/viewtopic.php?t=46274> Page 1 of 1 [ 9 posts ] Previous topic | Next topic Author Message bernard Post subject: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 8:36 am Joined: Sat Oct 27, 2007 8:21 am Posts: 34 Using RB2012, upgraded from RB2009, in Windows XP: I have an app. on which a square at bottom right of the Canvas changes to always show the colour under the cursor. This is easily done by calling Canvas.graphics from the MouseMove event. With Canvas.graphics deprecated I have tried to do it as follows: In Canvas.MouseMove, Xpicked & Ypicked being global: Xpicked=x Ypicked=y Cv.Invalidate in Canvas.Paint: dim rr,gg,bb,n as integer 'just to paint the canvas.............. gg=130 for n=0 to me.width rr=255*n/me.Width bb=255-255*n/me.Width g.ForeColor=rgb(rr,gg,bb) g.DrawLine(n,0,n,me.Height) next 'right corner from MouseMove............. g.ForeColor=g.Pixel(Xpicked,Ypicked) g.fillrect(me.Width-50,me.Height-50,50,50) This runs very erratically in Windows as the Canvas is constantly renewed. Can anyone advise a better way? Oddly, I find that it runs perfectly smoothly in Ubuntu (when built for Linux) Top jakuno Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 9:09 am Joined: Fri Aug 31, 2012 3:56 pm Posts: 42 Your code works fine, on Windows try the following in the Open event of the Canvas. me.DoubleBuffer=True me.EraseBackground=False Top bernard Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 9:19 am Joined: Sat Oct 27, 2007 8:21 am Posts: 34 Perfect, thank you jakuno. Now I just have to work to understand it. As I understand this deprecation, it is no longer possible to address Canvas graphics directly from any other control. Is this correct? Top npalardy Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 10:11 am Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7606 Location: Canada, Alberta, Near Red Deer It should work just that on Cocoa it may be really slow _________________ My web site Great White Software RBLibrary.com REALbasic learning Top jakuno Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 10:37 am Joined: Fri Aug 31, 2012 3:56 pm Posts: 42 bernard wrote:Perfect, thank you jakuno. Now I just have to work to understand it. As I understand this deprecation, it is no longer possible to address Canvas graphics directly from any other control. Is this correct? Yes. Top jakuno Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 10:40 am Joined: Fri Aug 31, 2012 3:56 pm Posts: 42 npalardy wrote:It should work just that on Cocoa it may be really slow Changes for Real Studio 2012 R1 22054 MacCocoa: drawing to a Picture that has already been drawn somewhere itself is no longer excessively slow. Top bernard Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 1:35 pm Joined: Sat Oct 27, 2007 8:21 am Posts: 34 The code which fills the canvas in the app. for which I need this action is much more lengthy (mathematically) in operation than the simple example I gave at the start of this thread. In RB2009, as I explained, the code in Canvas.MouseMove which used Canvas.Graphics ran quickly and smoothly. While the Canvas.Open code explained by jakuno does prevent the flickering using the new code, it now takes 2.5 seconds for a move of the mouse to register through Paint. So it appears that this simple action can no longer be performed efficiently by RB. Every time I upgrade I find yet another retrograde step. Top jakuno Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 2:05 pm Joined: Fri Aug 31, 2012 3:56 pm Posts: 42 RB is fast enough, try: https://dl.dropbox.com/u/103694210/CanvasColor.rbp.zip Top bernard Post subject: Re: Deprecated Canvas.graphics problemPosted: Tue Dec 18, 2012 5:43 pm Joined: Sat Oct 27, 2007 8:21 am Posts: 34 Yes jakuno, my original runs like your sample (thanks for going to the trouble) but that was only a simple example. The picture that I want to apply this to is actually generated as follows, and it is now much, much slower than it was in RB2009. This paints a colour circle of which CentrX and CentrY are, of course, the centre. In fact I have several other much more complicated graphics apps which rely heavily on Canvas.Graphics directed from other controls and which will need complete rewriting, if I ever get round to it. I have elsewhere used the method that you have shown and will try it for this when I have time. But I really think that invalidating so much of their customers' work is very much like a Microsoft ploy, which is precisely what I was avoiding when I started using RB. dim x,y as integer dim rr,gg,bb,c As UInt8 dim dx,dy,angle,part as Double dx=X-CentrX dy=Y-CentrY angle=ATan(dx/dy)*180/Pi for x=0 to me.Width for y=0 to me.Height if ((sqrt((CentrX-x)^2 + (CentrY-y)^2))>Radius) then '.......................white background.................... g.Pixel(x,y)=&cffffff else '...............paint the circle....................... dx=x-CentrX dy=y-CentrY angle=ATan(dx/dy)*180/Pi dist=sqrt(dx*dx+dy*dy) if dy>0 then angle=180-angle elseif dx>0 then angle=-angle if y=250 then angle=90 elseif dx<0 then angle=360-angle end if if angle<=120 then if angle<=60 then rr=255 gg=255*angle/60 else rr=255*(120-angle)/60 gg=255 end if part=127*(Radius-Dist)/Radius rr=rr*Dist/Radius+part gg=gg*Dist/Radius+part bb=part elseif ((angle>120)and(angle<=240)) then angle=angle-120 if angle<=60 then gg=255 bb=255*angle/60 else gg=255*(120-angle)/60 bb=255 end if part=127*(Radius-Dist)/Radius gg=gg*Dist/Radius+part bb=bb*Dist/Radius+part rr=part elseif ((angle>240)and(angle<=360)) then angle=angle-240 if angle<=60 then bb=255 rr=255*angle/60 else bb=255*(120-angle)/60 rr=255 end if part=127*(Radius-Dist)/Radius bb=bb*Dist/Radius+part rr=rr*Dist/Radius+part gg=part end if g.Pixel(x,y)=rgb(rr,gg,bb) end if Next next g.ForeColor=g.Pixel(Xpicked,Ypicked) g.fillrect(me.Width-50,me.Height-50,50,50) Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 9 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
