Hallo
ich wollte heute per double buffering das flackern meiner komponente entfernen...
aber anscheinend mach ich da noch was falsch... (hab bis jetzt mit graphik noch ganz wenig gemacht...)
ich hab einen paintlistener draufgesetzt und die funktion so definiert...
cursorPos = die position des cursors als Point
zoom ist eine zoomstufe, also ein einfacher int als multiplikator
getRect(i) gibt ein Rectangle zurück (x,y,width,height)
mMouseIsDown zeigt an ob die maus gedrückt ist oder nicht...
all das sollte doch eigentich keine auswirkungen haben, da ich doch auf meinen backpuffer zeichne und nur einmal zum schluss den buffer auf meine e.gc male...??
ich wollte heute per double buffering das flackern meiner komponente entfernen...
aber anscheinend mach ich da noch was falsch... (hab bis jetzt mit graphik noch ganz wenig gemacht...)
ich hab einen paintlistener draufgesetzt und die funktion so definiert...
cursorPos = die position des cursors als Point
zoom ist eine zoomstufe, also ein einfacher int als multiplikator
getRect(i) gibt ein Rectangle zurück (x,y,width,height)
mMouseIsDown zeigt an ob die maus gedrückt ist oder nicht...
all das sollte doch eigentich keine auswirkungen haben, da ich doch auf meinen backpuffer zeichne und nur einmal zum schluss den buffer auf meine e.gc male...??
Java:
@Override
public void paintControl(PaintEvent e) {
// double buffer
Image image = (Image) getData("double-buffer-image");
if (image == null || image.getBounds().width != getSize().x
|| image.getBounds().height != getSize().y) {
image = new Image(Display.getDefault(), getSize().x, getSize().y);
setData("double-buffer-image", image);
}
// Initializes the graphics context of the image.
GC imageGC = new GC(image);
// end double buffer preparation
Dimension imgDim = new Dimension(backgroundImage.getBounds().width,
backgroundImage.getBounds().height);
imageGC.drawImage(backgroundImage, 0, 0, imgDim.width, imgDim.height, 0, 0,
imgDim.width * zoom, imgDim.height * zoom);
for (int i = 0; i < rects.length; i++) {
Rectangle r = new Rectangle(getRect(i).x * zoom, getRect(i).y
* zoom, getRect(i).width * zoom, getRect(i).height * zoom);
imageGC.setForeground(ColoR.get(i));
imageGC.drawRectangle(r);
}
if (mMouseIsDown) {
// draw the selection
imageGC.setForeground(getCurColor());
imageGC.drawRectangle(curRegion.x * zoom, curRegion.y * zoom,
curRegion.width * zoom, curRegion.height * zoom);
} else {
// any case draw the crosshair
imageGC.setForeground(Display.getDefault().getSystemColor(
SWT.COLOR_WHITE));
imageGC.drawLine((((cursorPos.x - zoom) / 3) * 3),
(((cursorPos.y) / 3) * 3),
(((cursorPos.x + zoom) / 3) * 3), (((cursorPos.y) / 3) * 3));
imageGC.drawLine((((cursorPos.x) / 3) * 3),
(((cursorPos.y - zoom) / 3) * 3),
(((cursorPos.x) / 3) * 3), (((cursorPos.y + zoom) / 3) * 3));
}
// draw the backbuffer and clean up
e.gc.drawImage(image, 0, 0);
imageGC.dispose();
}