Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Aug 19, 2018 2:58 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 4:49 am 
Offline

Joined: Thu Dec 27, 2012 12:46 am
Posts: 4
Location: Australia
I use RS to build simulators. Anything from simulating electronic devices such as Radars, Sonars, Radio Transceivers, Sound Mixers Chart Plotters to ship simulators. These are done for e-learning purposes in education market.

Many of these devices have Rotary Knobs and using the deprecated "Graphics" I have managed to make a very real life like simulation of Rotary Knobs that eliminates the jittery results of scroll-bar-in-disguise effects commonly found in most applications. This would be impossible without the now deprecated "Graphics".

This is the command that does the trick:

Window1.Graphics.DrawObject myPixmapShap, myX, myY


Now the Project Analyzer warns me that I should abandon "Graphics" and use the "Canvas.Paint" instead.

I have tried for nearly a month! to make this work but "Canvas.Paint" method is simply too slow causing screen flashes. I went through all postings on the subject, tried every suggestion and then some, explored many work-arounds and now have given up because the problem is simply systemic and architectural.

May I suggest that deprecated features should not be eliminated until RS can provide a substitute that achieves the same performance. Otherwise, many developers will spend many hours to find unachievable alternatives for irreplaceable features.

I am happy with RB but now I have to re-write some of my applications with other tools. Waste of time, money and loss of credibility as I have championed RB against considerable resistance.


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 7:54 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Quote:
I have tried for nearly a month! to make this work but "Canvas.Paint" method is simply too slow causing screen flashes. I went through all postings on the subject, tried every suggestion and then some, explored many work-arounds and now have given up because the problem is simply systemic and architectural.


I suggest you have not understood the postings.
The task is not difficult.

If you have a pixmapshape as you say:

Window1.Graphics.DrawObject myPixmapShap, myX, myY


Then the ONLY changes you need to make are these:

1) make myPixMapShape,myX, and myY into properties of the app, so that they are 'global'
2) Where you make the DrawObject call above, change it to Window1.invalidate (even this is incorrect, but Im keeping it simple)
3) In the Window1.Paint event , put this code:

DrawObject myPixmapShap, myX, myY




=============
You should draw things to the graphics, in the Paint event of the window or object.
The graphics of the object is passed as a parameter g
What you draw to it can be a set of instructions, or a ready-created bitmap that you made as a global or window property at some point.

The paint event is called for you when the window needs to be painted (maybe after another window has been moved in front)

You can force it to happen using the .refresh statement
You can SUGGEST that it happens, using .invalidate

Using several .invalidates in quick succession does not mean you get lots of repaints: the operating system 'eats' all outstanding invalidate requests when it fires.
Thats not the case with refresh: every call forces a full paint, so avoid that if you can.


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 8:25 am 
Offline
Real Software Engineer

Joined: Fri Jan 28, 2011 5:24 pm
Posts: 145
Siamack Yousofi wrote:
I use RS to build simulators. Anything from simulating electronic devices such as Radars, Sonars, Radio Transceivers, Sound Mixers Chart Plotters to ship simulators. These are done for e-learning purposes in education market.

Many of these devices have Rotary Knobs and using the deprecated "Graphics" I have managed to make a very real life like simulation of Rotary Knobs that eliminates the jittery results of scroll-bar-in-disguise effects commonly found in most applications. This would be impossible without the now deprecated "Graphics".

This is the command that does the trick:

Window1.Graphics.DrawObject myPixmapShap, myX, myY


Now the Project Analyzer warns me that I should abandon "Graphics" and use the "Canvas.Paint" instead.

I have tried for nearly a month! to make this work but "Canvas.Paint" method is simply too slow causing screen flashes. I went through all postings on the subject, tried every suggestion and then some, explored many work-arounds and now have given up because the problem is simply systemic and architectural.

May I suggest that deprecated features should not be eliminated until RS can provide a substitute that achieves the same performance. Otherwise, many developers will spend many hours to find unachievable alternatives for irreplaceable features.

I am happy with RB but now I have to re-write some of my applications with other tools. Waste of time, money and loss of credibility as I have championed RB against considerable resistance.


If you're finding that it's still too slow, you might want to list what you've tried and see if we can give any suggestions. Also, you should say what platforms you're targeting.

_________________
Joe Ranieri
Mac Frameworks & Compiler
REAL Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 9:11 am 
Offline

Joined: Thu Dec 27, 2012 12:46 am
Posts: 4
Location: Australia
Thank you Kermit.

I tried your suggestions. It made things worse. The code responds to Mouse Drag event which fires in rapid successions as the user turns (drags) the rotary knob. Therefore there are many "invalidations" and the repainting can not keep up causing flicker. With the deprecated method there is absolutely no flicker and it is as close to reality as one can get.

Joe

I am using Windows 7 and "Graphics" works very well. I can use my code with Canvas as well as Label controls. Prefer Label since it can be made transparent but Canvas works too. When I do the drawing in Canvas.Paint and invalidate to force refresh the knob behaves correctly but there is unacceptable flicker because there are hundreds of refreshes in rapid succession as mouse drags the knob around. Quite happy to make a RS project and email it to you if you wish.


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 9:42 am 
Offline
Real Software Engineer

Joined: Fri Jan 28, 2011 5:24 pm
Posts: 145
Siamack Yousofi wrote:
Joe

I am using Windows 7 and "Graphics" works very well. I can use my code with Canvas as well as Label controls. Prefer Label since it can be made transparent but Canvas works too. When I do the drawing in Canvas.Paint and invalidate to force refresh the knob behaves correctly but there is unacceptable flicker because there are hundreds of refreshes in rapid succession as mouse drags the knob around. Quite happy to make a RS project and email it to you if you wish.


Please do. I won't make any guarantees as to whether or not I can, though.

_________________
Joe Ranieri
Mac Frameworks & Compiler
REAL Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 11:34 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Quote:
Mouse Drag event


What are you dragging?
Surely you should just be using mouse move?


Out of curiosity, can you try this code, and see how it performs on your setup?
It should take you 5 minutes to type at most..

start a new project
Add 2 properties to the window:

Quote:
buttonimage as picture
myPixmap as Object2d


Add a canvas1 to the window.
Add a scrollbar1 to the window. (Set min and max to - 10 and plus 10 if you like)
Set livescroll to true

Window open event:

buttonimage = new picture(100,100,32)
buttonimage.Transparent = 1
buttonimage.Graphics.ForeColor = rgb(255,255,255)
buttonimage.Graphics.FillRect 0,0,100,100
buttonimage.Graphics.ForeColor = rgb(255,0,0)
buttonimage.Graphics.FillOval 0,0,100,100
buttonimage.Graphics.ForeColor = rgb(0,0,0)
buttonimage.Graphics.FillRect 48,0,4,50
mypixmap = new PixmapShape(buttonimage)



slider1 valuechanged event:

mypixmap.Rotation = me.Value
canvas1.Invalidate



canvas1 Paint event:
if mypixmap = Nil then

else
g.DrawObject mypixmap,50,50
end if



Now, drag the slider about.
How does it look?


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 1:16 pm 
Offline

Joined: Fri Sep 30, 2005 8:53 am
Posts: 1002
I am not sure what you were doing before, and I might not understand the issue, and do most of my coding on a Mac so I may be totally wrong...

When you call invalidate, do you set Erasebackground to false (canvas.invalidate(false)) and draw the whole graphic in the paint event to the canvas? I would think that should get rid of most if not all of the the flicker.

If recreating the whole control panel graphic from scratch is too slow, at the start of the drag you could create a picture of your control panel without that nob, then at each update (with EraseBackground = False) draw that picture to the canvas and then draw the knob on top of that.

- Karen


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 6:01 pm 
Offline

Joined: Thu Dec 27, 2012 12:46 am
Posts: 4
Location: Australia
Thank you Kermit

Mouse move has the same problem. Remember this is a simulation. I am dragging the knob image around just as you do in the real life device. Scroll bar is not true simulation. I have created a mini project with two knobs using the two approaches and will email it to Joe. If you like to see the code I can send the project to you too.

Karen

Thanks for the advice. I have tried your suggestions before. Same problem.


I do not think the issue is how I have coded the Canvas. My approach is the same as your suggestions and I have followed the documentation. The knob works and turns as expected in both cases. Only difference is the performance of the "Canvas.Paint" vs Graphics.DrawObject".

All I am saying is we should hold off eliminating "Graphics" until "Paint" can deliver identical results.

Regards

Siamack


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun Feb 03, 2013 8:30 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Here is a sample project that I used when I designed a set of custom scrollbars for a recent project

http://www.rdsisemore.com/myscrollbar.xml.zip

It was written under OSX, but should work equally as well under Windows (just make sure you check the GDI+ option)

ImageImage

The controls consist of NOTHING but CANVAS and code, using the exact techniques described above
and meet all the requirements of not drawing to the CANVAS.GRAPHICS object outside of its own paint event.



FYI... you are free to use this code anyway you wish... but if you include the two above graphics.. please credit me in you "About Box"

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Mon Feb 04, 2013 2:28 pm 
Offline
Site Admin
User avatar

Joined: Fri Sep 30, 2005 9:35 am
Posts: 987
Location: South Portland, Maine
You might also want to take a look at these two examples that ship with Real Studio to see how you can do your drawing entirely within the Paint event handler:

Example Projects/Graphics and Multimedia/CanvasDrawDrag

Example Projects/Graphics and Multimedia/ObjectsInCanvas

_________________
Paul Lefebvre
Developer Evangelist
Xojo, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Mon Feb 04, 2013 5:39 pm 
Offline

Joined: Thu Dec 27, 2012 12:46 am
Posts: 4
Location: Australia
Hi Paul

Thank you very much for your help. The examples you suggested were informative but did not directly relate to my problem. However, the Animation example project did! It is just a matter of switching ON the double buffer option. It solves the problem with the flicker but now I loose the transparency. I suppose I could find a workaround for the transparency issue.

So folks please consider the problem SOLVED :mrgreen:

Many thanks to those who took the time to contribute.

Joe,

Thank you for your time.

Siamack


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun May 12, 2013 11:45 am 
Offline

Joined: Sat Feb 05, 2011 10:52 am
Posts: 2
I've worked with RB since 1999, almost totally Mac for Mac programs. For the last two years, though, I've been working on a large project involving a Win32 touch Kiosk for mental health screening. Canvas buttons have been my bane. A few things I've learned:

1) Never place a control on top of another control.
2) If you hide a control that does overlap another, you will have trouble. Not only set visible to false, but also set its location on planet Mars when not in use.
3) Use invalidate only for specific items that absolutely require it. Don't routinely put invalidate in a loop that acts on rectControls that don't need refreshing.
4) Set a global method to (platform is a var set in app.open):


select case platform
case "mac"
gDblBuffer=false
gErase=true
gComposite=false
case "win"
gComposite=true
gDblBuffer=true
gErase=false
gTransparent=true
case "unix"
gDblBuffer=false
gErase=true
gComposite=false
end

exception
msgBox "Exception in set platform draws"


I've found the issue of invalidate vs refresh a real pain in some cases, and even after all these years I rely on trial-and-error mostly.


Top
 Profile  
Reply with quote  
 Post subject: Re: Deprecated Graphics
PostPosted: Sun May 12, 2013 12:47 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
drjuluka wrote:
I've worked with RB since 1999, almost totally Mac for Mac programs. For the last two years, though, I've been working on a large project involving a Win32 touch Kiosk for mental health screening. Canvas buttons have been my bane. A few things I've learned:

1) Never place a control on top of another control.
2) If you hide a control that does overlap another, you will have trouble. Not only set visible to false, but also set its location on planet Mars when not in use.
3) Use invalidate only for specific items that absolutely require it. Don't routinely put invalidate in a loop that acts on rectControls that don't need refreshing.
4) Set a global method to (platform is a var set in app.open):


select case platform
case "mac"
gDblBuffer=false
gErase=true
gComposite=false
case "win"
gComposite=true
gDblBuffer=true
gErase=false
gTransparent=true
case "unix"
gDblBuffer=false
gErase=true
gComposite=false
end

exception
msgBox "Exception in set platform draws"


I've found the issue of invalidate vs refresh a real pain in some cases, and even after all these years I rely on trial-and-error mostly.


All good suggestions. Instead of doing the select case you're using I use #if targetWin32, targetMacOS to let the compiler strip out unneeded code for each platform I build for. It might mean only few microseconds but there's no decision branches at runtime since the compiler is only putting the code it needs for that platform.

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group