Search in sources :

Example 66 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class IOSImplementation method createAlphaMask.

// -------------------------------------------------------------------------
// METHODS FOR DRAWING SHAPES AND TRANSFORMATIONS
// -------------------------------------------------------------------------
/**
 * Creates a platform-specific alpha mask for a shape.  This is used to cache
 * masks in the {@link com.codename1.ui.GeneralPath} class.  On iOS the alpha
 * mask is an OpenGL texture ID (not a raster of alpha pixels), but other platforms
 * may use different representations if they like.
 *
 * <p>The {@link com.codename1.ui.Graphics#drawAlphaMask} method
 * is used to draw a mask on the graphics context and this will ultimately call {@link #drawAlphaMask}
 * which can be platform specific also.
 * </p>
 * @param shape The shape that will have an alpha mask created.
 * @param stroke The stroke settings for stroking the outline of the mask.  Leave null to produce a fill
 * mask.
 * @return The platform specific alpha mask object or null if it is not supported or failed.
 * @see #deleteAlphaMask
 * @see #drawAlphaMask
 * @see #isAlphaMaskSupported
 * @see com.codename1.ui.Graphics#drawAlphaMask
 * @see com.codename1.ui.GeneralPath#getAlphaMask
 */
public TextureAlphaMask createAlphaMask(Shape shape, Stroke stroke) {
    int[] bounds = new int[] { 0, 0, 0, 0 };
    long tex = nativeCreateAlphaMaskForShape(shape, stroke, bounds);
    Rectangle shapeBounds = shape.getBounds();
    int[] padding = new int[] { // top
    shapeBounds.getY() - bounds[1], // right
    bounds[2] - (shapeBounds.getX() + shapeBounds.getWidth()), // bottom
    bounds[3] - (shapeBounds.getY() + shapeBounds.getHeight()), // left
    shapeBounds.getX() - bounds[0] };
    if (tex == 0) {
        return null;
    }
    return new TextureAlphaMask(tex, new Rectangle(bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]), padding);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 67 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class TestRecorder method eventPointerReleased.

void eventPointerReleased(int x, int y) {
    if (isRecording()) {
        com.codename1.ui.Component cmp = Display.getInstance().getCurrent().getComponentAt(x, y);
        if (isListComponent(cmp)) {
            return;
        }
        if (dragged) {
            if (dragToScroll.isSelected()) {
                com.codename1.ui.Component scrollTo;
                if (y > pointerPressedY) {
                    scrollTo = findLowestVisibleComponent();
                } else {
                    scrollTo = findHighestVisibleComponent();
                }
                if (scrollTo != null && scrollTo != Display.getInstance().getCurrent() && scrollTo != Display.getInstance().getCurrent().getContentPane()) {
                    String name = scrollTo.getName();
                    if (name != null) {
                        generatedCode += "        ensureVisible(\"" + name + "\");\n";
                    } else {
                        String pp = getPathToComponent(scrollTo);
                        if (pp == null) {
                            return;
                        }
                        generatedCode += "        ensureVisible(" + pp + ");\n";
                    }
                    updateTestCode();
                }
            } else {
                addWaitStatement();
                generatedCode += "        pointerRelease" + generatePointerEventArguments(x, y);
                updateTestCode();
            }
        } else {
            if (isToolbarComponent(cmp)) {
                if (cmp instanceof com.codename1.ui.Button) {
                    Command cmd = ((com.codename1.ui.Button) cmp).getCommand();
                    if (cmd != null) {
                        int offset = 0;
                        Command[] commands = TestUtils.getToolbarCommands();
                        for (Command c : commands) {
                            if (c == cmd) {
                                generatedCode += "        assertEqual(getToolbarCommands().length, " + commands.length + ");\n";
                                generatedCode += "        executeToolbarCommandAtOffset(" + offset + ");\n";
                                updateTestCode();
                                return;
                            }
                            offset++;
                        }
                    } else {
                        if (cmp.getUIID().equals("MenuButton")) {
                            // side menu button
                            generatedCode += "        showSidemenu();\n";
                            updateTestCode();
                            return;
                        }
                    }
                }
            }
            if (cmp instanceof com.codename1.ui.Button) {
                com.codename1.ui.Button btn = (com.codename1.ui.Button) cmp;
                // special case for back command on iOS
                if (btn.getCommand() != null && btn.getCommand() == Display.getInstance().getCurrent().getBackCommand()) {
                    generatedCode += "        goBack();\n";
                } else {
                    if (btn.getName() != null && btn.getName().length() > 0) {
                        generatedCode += "        clickButtonByName(\"" + btn.getName() + "\");\n";
                    } else {
                        if (btn.getText() != null && btn.getText().length() > 0) {
                            generatedCode += "        clickButtonByLabel(\"" + btn.getText() + "\");\n";
                        } else {
                            String pp = getPathToComponent(cmp);
                            if (pp == null || pp.equals("(String)null")) {
                                return;
                            }
                            generatedCode += "        clickButtonByPath(" + pp + ");\n";
                        }
                    }
                }
                updateTestCode();
                return;
            }
            if (cmp instanceof com.codename1.ui.TextArea) {
                // ignore this, its probably initiating edit which we will capture soon
                return;
            }
            generatedCode += "        pointerPress" + generatePointerEventArguments(pointerPressedX, pointerPressedY);
            addWaitStatement();
            generatedCode += "        pointerRelease" + generatePointerEventArguments(x, y);
            updateTestCode();
        }
    }
}
Also used : Command(com.codename1.ui.Command) Component(com.codename1.ui.Component)

Example 68 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class TestRecorder method visitComponents.

private void visitComponents(com.codename1.ui.Container cnt, ComponentVisitor v) {
    v.visit(cnt);
    int count = cnt.getComponentCount();
    for (int iter = 0; iter < count; iter++) {
        com.codename1.ui.Component current = cnt.getComponentAt(iter);
        if (current instanceof com.codename1.ui.Container) {
            visitComponents((com.codename1.ui.Container) current, v);
        } else {
            v.visit(current);
        }
    }
}
Also used : Component(com.codename1.ui.Component)

Example 69 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class TestRecorder method generatePointerEventArguments.

private String generatePointerEventArguments(int x, int y) {
    com.codename1.ui.Component cmp = getCodenameOneComponentAt(x, y);
    if (cmp.getParent() instanceof Form) {
        cmp = cmp.getParent();
    }
    String componentName = cmp.getName();
    if (componentName == null) {
        componentName = getPathToComponent(cmp);
    } else {
        componentName = "\"" + componentName + "\"";
    }
    float actualX = ((float) x - cmp.getAbsoluteX()) / ((float) cmp.getWidth());
    float actualY = ((float) y - cmp.getAbsoluteY()) / ((float) cmp.getHeight());
    return "(" + actualX + "f, " + actualY + "f, " + componentName + ");\n";
}
Also used : Form(com.codename1.ui.Form) Component(com.codename1.ui.Component)

Example 70 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class TestRecorder method bindListListener.

private void bindListListener(final com.codename1.ui.Component cmp, final ListModel m) {
    if (cmp.getClientProperty("CN1$listenerBound") == null) {
        cmp.putClientProperty("CN1$listenerBound", Boolean.TRUE);
        m.addSelectionListener(new SelectionListener() {

            public void selectionChanged(int oldSelected, int newSelected) {
                generatedCode += "        selectInList(" + getPathOrName(cmp) + ", " + newSelected + ");\n";
                updateTestCode();
            }
        });
    }
}
Also used : SelectionListener(com.codename1.ui.events.SelectionListener)

Aggregations

IOException (java.io.IOException)39 EncodedImage (com.codename1.ui.EncodedImage)29 ArrayList (java.util.ArrayList)27 Point (java.awt.Point)25 File (java.io.File)24 BufferedImage (java.awt.image.BufferedImage)23 AnimationObject (com.codename1.ui.animations.AnimationObject)22 Form (com.codename1.ui.Form)19 Hashtable (java.util.Hashtable)19 Component (com.codename1.ui.Component)18 Image (com.codename1.ui.Image)18 EditableResources (com.codename1.ui.util.EditableResources)16 FileInputStream (java.io.FileInputStream)16 Timeline (com.codename1.ui.animations.Timeline)15 BorderLayout (com.codename1.ui.layouts.BorderLayout)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)11 FileOutputStream (java.io.FileOutputStream)10 EditorFont (com.codename1.ui.EditorFont)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9