My current redraw strategy is to iterate the linkedlist in the paint method and pass the getBounds method of each element into the hitClip method of the graphics object to determine if I need to draw it. By offscreen buffering do you mean am I using the default double buffering capability built into Java2D? I still have doublebuffering enabled at the moment but have considered turning it off to see what speed improvements might turn up.
Yep, there is a lot that can be done to speed up your app. Hopefully, I'll provide some starter info.
I am assuming that the user can only move one icon or a group of icons at a time on the screen. Simplest case is for one at a time.
Definitely take a look at the Volatile Image API; there is a significant speedup to be had here on Win32; my development platform presently.
The best way to speed up you app is to not redraw all of the shapes every single time you repaint. You should manually double buffer (with volatile images) your component. The first buffer should be your background with no items (you might want a texture here). The second buffer (shape buffer) consists of the background + all non moving items. Lastly your paintComponent method will draw the shape buffer + all the moving shape(s).
As Jim suggested find a way to eliminate the hitClip calls. You should be able to check for visible components in a loop.
Now to the basic idea:
Mouse is pressed 1. Check to see if shape(s) is selected; if not do nothing.
2. If shape(s) is selected then redraw your shape buffer with all visible
non selected shapes.
2a. add a mouse motion listener.
2b. set a flag indicating movable a shape(s)Mouse dragged (update mouse position and call repaint) In paintComponent: 1. Draw shape buffer 2. Draw movable shape(s)
Mouse is released 1. Draw the previously moving shape(s) into the shape buffer and remove the mouse motion listener and set the movable objects flag to false.
When there isn't a movable shape the shape buffer will contain all visible shapes
Interesting tips: You can keep a reference to the Graphics2D object of the shape buffer. This will allow you to set the rending hints once and start redrawing the buffer immediately without a call to createGraphics().
Use VM parameter: -Dsun.java2d.accthreshold=0 If using translucent images then add: -Dsun.java2d.translaccel=true
The drawShapeBuffer method will look like this. 1. draw the background buffer via drawImage 2. draw all visible non moving shapes.
If you don't want a background image you can eliminate the background buffer and use clearRect on the shape buffer.
---------
Conceivably in 1.5 if the user is allowed to select/move multiple shapes you could create a transparent movable shape buffer with all of the moving shapes drawn in it; IE just move/draw one image instead of redrawing many shapes.
---------
With the strategy above you should have a lightning fast app.
Best, --Mike
Egregious "Spiritual renewal through music for those outside the heard." http://www.egregious.net/
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
