Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Resizing works, but scrolling "smears" image.(Issue with Resizing an image versus Scrolling it.)
Resizing works, but scrolling "smears" image. [message #1053444] Mon, 06 May 2013 01:53 Go to next message
Robert Adamson is currently offline Robert Adamson
Messages: 9
Registered: March 2013
Junior Member
I am writing an application which loads .jpg files as images and then allows users to place "marks" on the image. I'm using code similar to that of snipped #48. When I re-size the image the marks are retained. However, when I scroll the screen, the marks (small green circles) are "smeared across the image. Resizing again will restore the image and the marks to the "correct" state. I have attached screen shots to illustrate, the first one is what the file looks like with the green circles,
index.php/fa/14655/0/


the second one shows what happens when I scroll the screen.
index.php/fa/14656/0/

I looked at the javadoc for the Scroll event and one section of the description for scroll event stood out as the probable cause of the code not behaving as I want. Either that or I just don't understand the implication of what it says:
" ... In addition, all outstanding paint events are flushed before the source area is copied to ensure that the contents of the canvas are drawn correctly. "

The actual code which redraws the green circles is in the paint event handler.

So it seems like if the javadoc description was accurate it would finish scrolling before it reapplied my green circles. But obviously it's redrawing them at very small increments as the scrolling is taking place.

Any ideas would be appreciated.

And I'm using SWT 3.7.2 64 bit, on Windows 7 64 bit, in Indigo 3.7.2.
Re: Resizing works, but scrolling "smears" image. [message #1053685 is a reply to message #1053444] Tue, 07 May 2013 08:44 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
It depends on how you are painting those green circles...
could you please share a snippet to represent what you are doing there(paint code)..


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Resizing works, but scrolling "smears" image. [message #1057499 is a reply to message #1053685] Wed, 08 May 2013 12:33 Go to previous messageGo to next message
Robert Adamson is currently offline Robert Adamson
Messages: 9
Registered: March 2013
Junior Member
Thanks for Responding, here is the code for the Paint Event.

// Handle Paint event.s
canvas.addListener (SWT.Paint, new Listener () {
public void handleEvent (Event e) {
GC gc = e.gc;
gc.drawImage (image, origin.x, origin.y);
Rectangle rect = image.getBounds ();
Rectangle client = canvas.getClientArea ();
int marginWidth = client.width - rect.width;
if (marginWidth > 0) {
gc.fillRectangle (rect.width, 0, marginWidth, client.height);
}
int marginHeight = client.height - rect.height;
if (marginHeight > 0) {
gc.fillRectangle (0, rect.height, client.width, marginHeight);
}
// TODO is this where we can tell it to repaint our plotted hexes ???

// redraw any plotted hexes.
// Need to iterate though the list and mark the map again.

if (currUnit != null && plotting) {
Collection<PlottedHex> tempList = currUnit.getListValues();
PlottedHex[] ph = tempList.toArray( new PlottedHex[20] );

PlottedHex tempHex = null;

int i=0;
while ( (i < ph.length) && (ph[i] != null) ) {

tempHex = ph[i];
// now mark hex once we have the X and Y

GC myGC = new GC(canvas);
;
Color frgdColor = new Color(display, 0, 180, 10); // bright green
Color oldFrgd = myGC.getForeground(); // save setting.
myGC.setForeground(frgdColor);
myGC.setLineWidth(2);
myGC.drawOval(tempHex.getX() - 10, tempHex.getY(), 10, 10);
myGC.setForeground(oldFrgd); // restore it.
myGC.dispose();

i++;

}
}


}
});
Re: Resizing works, but scrolling &quot;smears&quot; image. [message #1057681 is a reply to message #1053685] Wed, 08 May 2013 12:33 Go to previous messageGo to next message
Robert Adamson is currently offline Robert Adamson
Messages: 9
Registered: March 2013
Junior Member
Thanks for Responding, here is the code for the Paint Event.

// Handle Paint event.s
canvas.addListener (SWT.Paint, new Listener () {
public void handleEvent (Event e) {
GC gc = e.gc;
gc.drawImage (image, origin.x, origin.y);
Rectangle rect = image.getBounds ();
Rectangle client = canvas.getClientArea ();
int marginWidth = client.width - rect.width;
if (marginWidth > 0) {
gc.fillRectangle (rect.width, 0, marginWidth, client.height);
}
int marginHeight = client.height - rect.height;
if (marginHeight > 0) {
gc.fillRectangle (0, rect.height, client.width, marginHeight);
}
// TODO is this where we can tell it to repaint our plotted hexes ???

// redraw any plotted hexes.
// Need to iterate though the list and mark the map again.

if (currUnit != null && plotting) {
Collection<PlottedHex> tempList = currUnit.getListValues();
PlottedHex[] ph = tempList.toArray( new PlottedHex[20] );

PlottedHex tempHex = null;

int i=0;
while ( (i < ph.length) && (ph[i] != null) ) {

tempHex = ph[i];
// now mark hex once we have the X and Y

GC myGC = new GC(canvas);
;
Color frgdColor = new Color(display, 0, 180, 10); // bright green
Color oldFrgd = myGC.getForeground(); // save setting.
myGC.setForeground(frgdColor);
myGC.setLineWidth(2);
myGC.drawOval(tempHex.getX() - 10, tempHex.getY(), 10, 10);
myGC.setForeground(oldFrgd); // restore it.
myGC.dispose();

i++;

}
}


}
});
Re: Resizing works, but scrolling "smears" image. [message #1057718 is a reply to message #1057499] Wed, 08 May 2013 12:47 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
Use the same paint gc to draw the ovals, instead of a new gc of canvas...

---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Thu, 09 May 2013 05:30]

Report message to a moderator

Re: Resizing works, but scrolling "smears" image. [message #1058094 is a reply to message #1057718] Sat, 11 May 2013 01:11 Go to previous message
Robert Adamson is currently offline Robert Adamson
Messages: 9
Registered: March 2013
Junior Member
That was it! Thanks.

Previous Topic:Why not just Draw Labels,Instead of creating one? ver 1.1
Next Topic:Check Button on StyledText
Goto Forum:
  


Current Time: Thu Sep 18 21:45:23 GMT 2014

Powered by FUDForum. Page generated in 0.02879 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software