use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class RoundRectBorder method fillShape.
private void fillShape(Graphics g, int color, int opacity, int width, int height, boolean stroke) {
g.setColor(color);
g.setAlpha(opacity);
GeneralPath gp = createShape(width, height);
g.fillShape(gp);
if (stroke && this.stroke != null) {
g.setAlpha(strokeOpacity);
g.setColor(strokeColor);
g.drawShape(gp, this.stroke);
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class RoundRectBorder method createTargetImage.
private Image createTargetImage(Component c, int w, int h, boolean fast) {
Image target = Image.createImage(w, h, 0);
int shapeX = 0;
int shapeY = 0;
int shapeW = w;
int shapeH = h;
Graphics tg = target.getGraphics();
tg.setAntiAliased(true);
int shadowSpreadL = Display.getInstance().convertToPixels(shadowSpread);
if (shadowOpacity > 0) {
shapeW -= shadowSpreadL;
shapeH -= shadowSpreadL;
shapeX += Math.round(((float) shadowSpreadL) * shadowX);
shapeY += Math.round(((float) shadowSpreadL) * shadowY);
// draw a gradient of sort for the shadow
for (int iter = shadowSpreadL - 1; iter >= 0; iter--) {
tg.translate(iter, iter);
fillShape(tg, 0, shadowOpacity / shadowSpreadL, w - (iter * 2), h - (iter * 2), false);
tg.translate(-iter, -iter);
}
if (Display.getInstance().isGaussianBlurSupported() && !fast) {
Image blured = Display.getInstance().gaussianBlurImage(target, shadowBlur / 2);
target = Image.createImage(w, h, 0);
tg = target.getGraphics();
tg.drawImage(blured, 0, 0);
tg.setAntiAliased(true);
}
}
tg.translate(shapeX, shapeY);
GeneralPath gp = createShape(shapeW, shapeH);
Style s = c.getStyle();
if (s.getBgImage() == null) {
byte type = s.getBackgroundType();
if (type == Style.BACKGROUND_IMAGE_SCALED || type == Style.BACKGROUND_NONE) {
byte bgt = c.getStyle().getBgTransparency();
if (bgt != 0) {
tg.setAlpha(bgt & 0xff);
tg.setColor(s.getBgColor());
tg.fillShape(gp);
}
if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
tg.setAlpha(strokeOpacity);
tg.setColor(strokeColor);
tg.drawShape(gp, this.stroke);
}
return target;
}
}
c.getStyle().setBorder(Border.createEmpty());
tg.setClip(gp);
s.getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
tg.setClip(0, 0, w, h);
tg.setAlpha(strokeOpacity);
tg.setColor(strokeColor);
tg.drawShape(gp, this.stroke);
}
c.getStyle().setBorder(this);
return target;
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawComboBox.
/**
* {@inheritDoc}
*/
public void drawComboBox(Graphics g, List cb) {
int border = 2;
Style style = cb.getStyle();
int leftPadding = style.getPaddingLeft(cb.isRTL());
int rightPadding = style.getPaddingRight(cb.isRTL());
setFG(g, cb);
ListModel model = cb.getModel();
ListCellRenderer renderer = cb.getRenderer();
Object value = model.getItemAt(model.getSelectedIndex());
int comboImageWidth;
if (comboImage != null) {
comboImageWidth = comboImage.getWidth();
} else {
comboImageWidth = style.getFont().getHeight();
}
int cellX = cb.getX() + style.getPaddingTop();
if (cb.isRTL()) {
cellX += comboImageWidth;
}
if (model.getSize() > 0) {
Component cmp = renderer.getListCellRendererComponent(cb, value, model.getSelectedIndex(), cb.hasFocus());
cmp.setX(cellX);
cmp.setY(cb.getY() + style.getPaddingTop());
cmp.setWidth(cb.getWidth() - comboImageWidth - rightPadding - leftPadding);
cmp.setHeight(cb.getHeight() - style.getPaddingTop() - style.getPaddingBottom());
cmp.paint(g);
}
g.setColor(style.getBgColor());
int y = cb.getY();
int height = cb.getHeight();
int width = comboImageWidth + border;
int x = cb.getX();
if (cb.isRTL()) {
x += leftPadding;
} else {
x += cb.getWidth() - comboImageWidth - rightPadding;
}
if (comboImage != null) {
g.drawImage(comboImage, x, y + height / 2 - comboImage.getHeight() / 2);
} else {
int color = g.getColor();
// brighten or darken the color slightly
int destColor = findDestColor(color);
g.fillLinearGradient(g.getColor(), destColor, x, y, width, height, false);
g.setColor(color);
g.drawRect(x, y, width, height - 1);
width--;
height--;
// g.drawRect(x, y, width, height);
g.translate(x + 1, y + 1);
g.setColor(0x111111);
int x1 = scaleCoordinate(2.5652081f, 16, width);
int y1 = scaleCoordinate(4.4753664f, 16, height);
int x2 = scaleCoordinate(8.2872691f, 16, width);
int y2 = scaleCoordinate(10f, 16, height);
int x3 = scaleCoordinate(13.516078f, 16, width);
int y3 = y1;
g.fillTriangle(x1, y1, x2, y2, x3, y3);
g.translate(-1, -1);
g.setColor(style.getFgColor());
g.fillTriangle(x1, y1, x2, y2, x3, y3);
// g.setColor(style.getFgColor());
// g.fillTriangle(x1 + 2, y1 + 2, x2, y2 - 2, x3 - 2, y3 + 2);
g.translate(-x, -y);
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawLabelString.
/**
* Implements the drawString for the text component and adjust the valign
* assuming the icon is in one of the sides
*/
private int drawLabelString(Graphics g, Label l, String text, int x, int y, int textSpaceW) {
Style style = l.getStyle();
int cx = g.getClipX();
int cy = g.getClipY();
int cw = g.getClipWidth();
int ch = g.getClipHeight();
// g.pushClip();
g.clipRect(x, cy, textSpaceW, ch);
if (l.isTickerRunning()) {
Font font = style.getFont();
if (l.getShiftText() > 0) {
if (l.getShiftText() > textSpaceW) {
l.setShiftText(x - l.getX() - l.getStringWidth(font));
}
} else if (l.getShiftText() + l.getStringWidth(font) < 0) {
l.setShiftText(textSpaceW);
}
}
int drawnW = drawLabelText(g, l, text, x, y, textSpaceW);
g.setClip(cx, cy, cw, ch);
return drawnW;
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawPullToRefresh.
/**
* {@inheritDoc}
*/
public void drawPullToRefresh(Graphics g, final Component cmp, boolean taskExecuted) {
final Form parentForm = cmp.getComponentForm();
final int scrollY = cmp.getScrollY();
Component cmpToDraw;
if (taskExecuted) {
cmpToDraw = updating;
} else {
if (-scrollY > getPullToRefreshHeight()) {
cmpToDraw = releaseToRefresh;
} else {
cmpToDraw = pullDown;
}
}
if (pull.getComponentAt(0) != updating && cmpToDraw != pull.getComponentAt(0)) {
parentForm.registerAnimated(new Animation() {
int counter = 0;
Image i;
{
i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
if (i == null) {
i = getDefaultRefreshIcon();
}
}
public boolean animate() {
counter++;
if (pull.getComponentAt(0) == releaseToRefresh) {
((Label) releaseToRefresh).setIcon(i.rotate(180 - (180 / 6) * counter));
} else {
((Label) pullDown).setIcon(i.rotate(180 * counter / 6));
}
if (counter == 6) {
((Label) releaseToRefresh).setIcon(i);
((Label) pullDown).setIcon(i.rotate(180));
parentForm.deregisterAnimated(this);
}
cmp.repaint(cmp.getAbsoluteX(), cmp.getAbsoluteY() - getPullToRefreshHeight(), cmp.getWidth(), getPullToRefreshHeight());
return false;
}
public void paint(Graphics g) {
}
});
}
if (pull.getComponentAt(0) != cmpToDraw && cmpToDraw instanceof Label && (pull.getComponentAt(0) instanceof Label)) {
((Label) cmpToDraw).setIcon(((Label) pull.getComponentAt(0)).getIcon());
}
Component current = pull.getComponentAt(0);
if (current != cmpToDraw) {
pull.replace(current, cmpToDraw, null);
}
pull.setWidth(cmp.getWidth());
pull.setX(cmp.getAbsoluteX());
pull.setY(cmp.getY() - scrollY - getPullToRefreshHeight());
pull.layoutContainer();
pull.paintComponent(g);
}
Aggregations