D
D-Dog
Hi,
I'm using a canvas to draw a simple polygon that is slightly
transparent using a double buffer. I'm also clipping the area around
the polygon. Below is some code that I'm using. For the most part
everything works fine, until paint is called through something like an
expose event (I'll just take a window to obscure the canvas, then move
it). The polygon gets plotted over again making it brighter. Obscure
the window again, it gets brighter. It will keep getting brighter each
time paint is called. However, if I initiate a repaint() call
manually, which causes the code to go through update() first, it plots
correctly. For some reason it's related to the clipping because if I
disable the clipping code, it works correctly. New to java, so bear
with me. Thanks for any help!
Dennis
//
-----------------------------------------------------------------------------------
public void update(Graphics g) {
if (thisImage == null) {
thisImage = createImage(getSize().width, getSize().height);
}
Graphics thisG = thisImage.getGraphics();
thisG.setColor(getBackground());
thisG.fillRect(0,0,getSize().width,getSize().height);
thisG.setColor(getForeground());
thisG.setFont(getFont());
paint(thisG);
g.drawImage(thisImage,0,0,this);
}
// -------------------------------------------------------------------
pubic void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
// Setup clipping area
Rectangle2D r = new Rectangle2D.Float();
r.setRect(xoffset,yoffset,xAxis, yAxis);
g2.setClip(r);
g2.clip(r);
// call the custom Polygon plotting routine
plotPoly(g2, plottingPoints, numPoints, new Color(200,200,200,50));
g2.setClip(null);
}
//
-----------------------------------------------------------------------
I'm using a canvas to draw a simple polygon that is slightly
transparent using a double buffer. I'm also clipping the area around
the polygon. Below is some code that I'm using. For the most part
everything works fine, until paint is called through something like an
expose event (I'll just take a window to obscure the canvas, then move
it). The polygon gets plotted over again making it brighter. Obscure
the window again, it gets brighter. It will keep getting brighter each
time paint is called. However, if I initiate a repaint() call
manually, which causes the code to go through update() first, it plots
correctly. For some reason it's related to the clipping because if I
disable the clipping code, it works correctly. New to java, so bear
with me. Thanks for any help!
Dennis
//
-----------------------------------------------------------------------------------
public void update(Graphics g) {
if (thisImage == null) {
thisImage = createImage(getSize().width, getSize().height);
}
Graphics thisG = thisImage.getGraphics();
thisG.setColor(getBackground());
thisG.fillRect(0,0,getSize().width,getSize().height);
thisG.setColor(getForeground());
thisG.setFont(getFont());
paint(thisG);
g.drawImage(thisImage,0,0,this);
}
// -------------------------------------------------------------------
pubic void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
// Setup clipping area
Rectangle2D r = new Rectangle2D.Float();
r.setRect(xoffset,yoffset,xAxis, yAxis);
g2.setClip(r);
g2.clip(r);
// call the custom Polygon plotting routine
plotPoly(g2, plottingPoints, numPoints, new Color(200,200,200,50));
g2.setClip(null);
}
//
-----------------------------------------------------------------------