use of java.awt.GradientPaint in project openblocks by mikaelhg.
the class CRadioactiveButton method paint.
@Override
public void paint(Graphics g) {
// Set up graphics and buffer
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
BufferedImage buffer = GraphicsManager.gc.createCompatibleImage(this.getWidth(), this.getHeight(), Transparency.TRANSLUCENT);
Graphics2D gb = buffer.createGraphics();
gb.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set up first layer
int buttonHeight = this.getHeight() - INSET * 2;
int buttonWidth = this.getWidth() - INSET * 2;
int arc = buttonHeight;
if (this.pressed || this.selected) {
g2.setPaint(new GradientPaint(0, -buttonHeight, Color.darkGray, 0, buttonHeight, buttonColor, false));
g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
g2.setColor(Color.darkGray);
g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
} else {
//paint highlightlayer
if (this.focus) {
gb.setColor(Color.yellow);
gb.setStroke(new BasicStroke(3));
gb.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
gb.setStroke(new BasicStroke(1));
}
// Paint the first layer
gb.setColor(buttonColor.darker());
gb.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
gb.setColor(Color.darkGray);
gb.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
// set up paint data fields for second layer
int highlightHeight = buttonHeight * 2 / 3;
int highlightWidth = buttonWidth;
int highlightArc = highlightHeight;
// Paint the second layer
gb.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .8f));
gb.setColor(buttonColor);
gb.setClip(new RoundRectangle2D.Float(INSET, INSET, highlightWidth, highlightHeight, highlightArc, highlightArc));
gb.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
// Blur
ConvolveOp blurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
BufferedImage blurredImage = blurOp.filter(buffer, null);
// Draw button
g2.drawImage(blurredImage, 1, 1, null);
}
// Draw the text (if any)
String text = this.getText();
if (text != null && buttonHeight > 4) {
//Font font = g2.getFont().deriveFont((float)(((float)this.getHeight()) * .6));
Font font = g2.getFont().deriveFont((float) (this.getHeight() - INSET * 2 - 2) * .7f);
g2.setFont(font);
FontMetrics metrics = g2.getFontMetrics();
Rectangle2D textBounds = metrics.getStringBounds(this.getText(), g2);
float x = (float) ((this.getWidth() / 2) - (textBounds.getWidth() / 2));
float y = (float) ((this.getHeight() / 2) + (textBounds.getHeight() / 2)) - metrics.getDescent();
g.setColor(Color.black);
for (int i = 0; i < shadowPositionArray.length; i++) {
int dx = shadowPositionArray[i][0];
int dy = shadowPositionArray[i][1];
g2.setColor(new Color(0, 0, 0, shadowColorArray[i]));
g2.drawString(text, x + (int) ((dx) * offsetSize), y + (int) ((dy) * offsetSize));
}
g2.setColor(Color.white);
g2.drawString(text, x, y);
}
}
use of java.awt.GradientPaint in project libgdx by libgdx.
the class GradientEffect method draw.
public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
int ascent = unicodeFont.getAscent();
float height = (ascent) * scale;
float top = -glyph.getYOffset() + unicodeFont.getDescent() + offset + ascent / 2 - height / 2;
g.setPaint(new GradientPaint(0, top, topColor, 0, top + height, bottomColor, cyclic));
g.fill(glyph.getShape());
}
use of java.awt.GradientPaint in project gephi by gephi.
the class BasicRichTooltipPanelUI method paintBackground.
protected void paintBackground(Graphics g) {
Color main = FlamingoUtilities.getColor(Color.gray, "Label.disabledForeground").brighter();
Graphics2D g2d = (Graphics2D) g.create();
g2d.setPaint(new GradientPaint(0, 0, FlamingoUtilities.getLighterColor(main, 0.9), 0, this.richTooltipPanel.getHeight(), FlamingoUtilities.getLighterColor(main, 0.4)));
g2d.fillRect(0, 0, this.richTooltipPanel.getWidth(), this.richTooltipPanel.getHeight());
g2d.setFont(FlamingoUtilities.getFont(this.richTooltipPanel, "Ribbon.font", "Button.font", "Panel.font"));
g2d.dispose();
}
use of java.awt.GradientPaint in project gephi by gephi.
the class DrawerSettings method update.
void update(int width, int height) {
if (lastWidth == width && lastHeight == height) {
return;
}
lastWidth = width;
lastHeight = height;
// background.paint = new GradientPaint(0, 0, background.top, 0, height, background.bottom, true);
selection.paint = new GradientPaint(0, 0, selection.top, 0, height, selection.bottom, true);
selection.mouseOverPaint = new GradientPaint(0, 0, selection.mouseOverTopColor, 0, height, selection.mouseOverBottomColor, true);
selection.activatedPaint = new GradientPaint(0, 0, selection.activatedTopColor, 0, height, selection.activatedBottomColor, true);
}
use of java.awt.GradientPaint in project binnavi by google.
the class CLoadProgressPainter method paint.
/**
* Paints view load progress onto a graphics canvas.
*
* @param view The view whose progress is painted.
* @param graphics The graphics canvas to paint on.
* @param width Width of the canvas.
* @param height Height of the canvas.
* @param background Default background color of the canvas.
*/
public static void paint(final INaviView view, final Graphics graphics, final int width, final int height, final Color background) {
graphics.setColor(background);
graphics.fillRect(0, 0, width, height);
final GradientPaint paint = new GradientPaint(0, 0, Color.WHITE, width, height, new Color(0, 128, 0));
((Graphics2D) graphics).setPaint(paint);
graphics.fillRect(0, 0, (int) (getLoadPercentage(view) * width), height);
}
Aggregations