Search in sources :

Example 36 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class Label method paintImpl.

void paintImpl(Graphics g) {
    initAutoResize();
    Object icn = null;
    Image i = getIconFromState();
    if (i != null) {
        icn = i.getImage();
    } else {
        // optimize away a common usage pattern for drawing the background only
        if (text == null || text.equals("") || text.equals(" ")) {
            return;
        }
    }
    // getUIManager().getLookAndFeel().drawLabel(g, this);
    int cmpX = getX() + g.getTranslateX();
    int cmpY = getY() + g.getTranslateY();
    int cmpHeight = getHeight();
    int cmpWidth = getWidth();
    Style s = getStyle();
    Font f = s.getFont();
    String t = text;
    if (text == null) {
        t = "";
    }
    Display.impl.drawLabelComponent(g.getGraphics(), cmpX, cmpY, cmpHeight, cmpWidth, s, t, icn, null, 0, gap, isRTL(), false, textPosition, getStringWidth(f), tickerRunning, shiftText, endsWith3Points, valign);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 37 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class CSSBgPainter method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g, Rectangle rect) {
    Style s = parent.getStyle();
    int x = rect.getX();
    int y = rect.getY();
    int width = rect.getSize().getWidth();
    int height = rect.getSize().getHeight();
    if (width <= 0 || height <= 0) {
        return;
    }
    g.setColor(s.getBgColor());
    g.fillRect(x, y, width, height, s.getBgTransparency());
    Image bgImage = s.getBgImage();
    if (bgImage == null) {
        return;
    }
    if (fixedX) {
        if (scrollableParent == null) {
            scrollableParent = getScrollableParent(parent);
        }
        if (scrollableParent != null) {
            x += scrollableParent.getScrollX();
            y += scrollableParent.getScrollY();
            width = scrollableParent.getWidth();
            height = scrollableParent.getHeight();
        }
    }
    int iW = bgImage.getWidth();
    int iH = bgImage.getHeight();
    int offsetX = horizPos;
    int offsetY = vertPos;
    if (horizIsPercentage) {
        offsetX = (width - iW) * offsetX / 100;
    }
    if (vertIsPercentage) {
        offsetY = (height - iH) * offsetY / 100;
    }
    switch(s.getBackgroundType()) {
        case 0:
            g.drawImage(s.getBgImage(), x + offsetX, y + offsetY);
            return;
        case Style.BACKGROUND_IMAGE_TILE_BOTH:
            for (int xPos = getTiledPosition(offsetX, iW); xPos <= width; xPos += iW) {
                for (int yPos = getTiledPosition(offsetY, iH); yPos <= height; yPos += iH) {
                    g.drawImage(s.getBgImage(), x + xPos, y + yPos);
                }
            }
            return;
        case Style.BACKGROUND_IMAGE_TILE_HORIZONTAL:
            for (int xPos = getTiledPosition(offsetX, iW); xPos <= width; xPos += iW) {
                g.drawImage(s.getBgImage(), x + xPos, y + offsetY);
            }
            return;
        case Style.BACKGROUND_IMAGE_TILE_VERTICAL:
            for (int yPos = getTiledPosition(offsetY, iH); yPos <= height; yPos += iH) {
                g.drawImage(s.getBgImage(), x + offsetX, y + yPos);
            }
            return;
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Image(com.codename1.ui.Image)

Example 38 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class TextField method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    // the native input will show the string.
    if (useNativeTextInput && Display.getInstance().isNativeEditorVisible(this)) {
        return;
    }
    UIManager manager = getUIManager();
    manager.getLookAndFeel().drawTextField(g, this);
    if (drawCursor && hasFocus() && isEditable()) {
        manager.getLookAndFeel().drawTextFieldCursor(g, this);
    }
    paintHint(g);
}
Also used : UIManager(com.codename1.ui.plaf.UIManager)

Example 39 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class AnimationObject method draw.

void draw(Graphics g, float scaleX, float scaleY) {
    int o = getOpacity();
    if (o == 0) {
        return;
    }
    Image i = getImage();
    // works in a separate thread
    if (i == null) {
        return;
    }
    int scaledImageW = (int) (getWidth() * scaleX);
    int scaledImageH = (int) (getHeight() * scaleY);
    if (scaledImageH < 1 || scaledImageW < 1) {
        return;
    }
    i = getImage().scaled(scaledImageW, scaledImageH);
    if (o != 255) {
        i = i.modifyAlphaWithTranslucency((byte) o);
    }
    int r = getOrientation();
    if (r != 0) {
        i = i.rotate(r);
    }
    int x = getX();
    int y = getY();
    x = (int) (x * scaleX);
    y = (int) (y * scaleY);
    g.drawImage(i, x, y);
}
Also used : Image(com.codename1.ui.Image)

Example 40 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class BubbleTransition method drawDialogCmp.

private void drawDialogCmp(Graphics g, Dialog dlg) {
    Painter p = dlg.getStyle().getBgPainter();
    dlg.getStyle().setBgPainter(null);
    g.setClip(0, 0, dlg.getWidth(), dlg.getHeight());
    g.translate(-getDialogParent(dlg).getX(), -getDialogParent(dlg).getY());
    getDialogParent(dlg).paintComponent(g, false);
    if (dlg.getCommandCount() > 0) {
        Component menuBar = dlg.getSoftButton(0).getParent();
        if (menuBar != null) {
            g.setClip(0, 0, dlg.getWidth(), dlg.getHeight());
            menuBar.paintComponent(g, false);
        }
    }
    dlg.getStyle().setBgPainter(p);
}
Also used : Painter(com.codename1.ui.Painter) Component(com.codename1.ui.Component)

Aggregations

Image (com.codename1.ui.Image)18 Component (com.codename1.ui.Component)17 Point (com.codename1.ui.geom.Point)16 Style (com.codename1.ui.plaf.Style)15 Graphics (com.codename1.ui.Graphics)14 Form (com.codename1.ui.Form)12 Font (com.codename1.ui.Font)11 GeneralPath (com.codename1.ui.geom.GeneralPath)9 Rectangle (com.codename1.ui.geom.Rectangle)9 Animation (com.codename1.ui.animations.Animation)8 Dialog (com.codename1.ui.Dialog)7 Dimension (com.codename1.ui.geom.Dimension)6 Painter (com.codename1.ui.Painter)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 FontImage (com.codename1.ui.FontImage)4 RGBImage (com.codename1.ui.RGBImage)4 Motion (com.codename1.ui.animations.Motion)4 ActionListener (com.codename1.ui.events.ActionListener)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 IOException (java.io.IOException)4