/** Disable and delete children display lists. */ public void disableAndDeleteChildrenDisplayLists() { MTComponent[] childs = this.getChildren(); for (int i = 0; i < childs.length; i++) { MTComponent child = childs[i]; if (child instanceof MTPolygon) { MTPolygon poly = (MTPolygon) child; poly.disableAndDeleteDisplayLists(); } } }
@Override public Vector3D getCenterPointLocal() { final int n = this.polygons.length; int mid = n / 2; MTPolygon middle = this.polygons[mid]; Vector3D center = middle.getCenterPointLocal(); if (n % 2 == 0) { Vector3D center2 = this.polygons[mid - 1].getCenterPointLocal(); center.x = (center.x + center2.x) / 2f; center.y = (center.y + center2.y) / 2f; center.z = (center.z + center2.z) / 2f; } return center; }
@Override public void setNoFill(boolean b) { for (MTPolygon p : polygons) { p.setNoFill(b); } }
@Override public void setFillColor(MTColor color) { for (MTPolygon p : this.polygons) { p.setFillColor(color); } }
public static void addEditableImage( final MTApplication mtApplication, AbstractScene slideScene, ImagenVO imagenVO, int xOffset, int yOffset) { System.out.println("******************** Entré al addEditableImage ********************"); final MTRectangle textureBrush; final MTEllipse pencilBrush; final DrawSurfaceScene drawingScene; String path = StartYPYIShell.getPathToIconsYPYI(); PImage pImage = mtApplication.loadImage(imagenVO.getDireccionFisicaImagen()); float x = new Float(imagenVO.getImagen().getAnchor().getCenterX()).floatValue(); float y = new Float(imagenVO.getImagen().getAnchor().getCenterY()).floatValue(); float w = new Float(imagenVO.getImagen().getAnchor().getWidth()).floatValue(); float h = new Float(imagenVO.getImagen().getAnchor().getHeight()).floatValue(); final MTRectangle frame = new MTRectangle( -50, -50, 0, mtApplication.width + 100, mtApplication.height + 100, mtApplication); frame.setSizeXYGlobal(w, h); frame.setPositionGlobal(new Vector3D(x + xOffset, y + yOffset)); frame.setTexture(pImage); // frame.setPickable(imagenVO.isPickable()); frame.setNoStroke(true); slideScene.getCanvas().addChild(frame); // Create the scene in which we actually draw drawingScene = new DrawSurfaceScene(mtApplication, "DrawSurface Scene"); drawingScene.setClear(false); // Create texture brush PImage brushImage = mtApplication.loadImage(path + "brush1.png"); textureBrush = new MTRectangle(brushImage, mtApplication); textureBrush.setPickable(false); textureBrush.setNoFill(false); textureBrush.setNoStroke(true); textureBrush.setDrawSmooth(true); textureBrush.setFillColor(new MTColor(0, 0, 0)); // Set texture brush as default drawingScene.setBrush(textureBrush); // Create pencil brush pencilBrush = new MTEllipse( mtApplication, new Vector3D(brushImage.width / 2f, brushImage.height / 2f, 0), brushImage.width / 2f, brushImage.width / 2f, 60); pencilBrush.setPickable(false); pencilBrush.setNoFill(false); pencilBrush.setNoStroke(false); pencilBrush.setDrawSmooth(true); pencilBrush.setStrokeColor(new MTColor(0, 0, 0, 255)); pencilBrush.setFillColor(new MTColor(0, 0, 0, 255)); // Create the frame/window that displays the drawing scene through a FBO // final MTSceneTexture sceneWindow = new MTSceneTexture(0,0, pa, drawingScene); // We have to create a fullscreen fbo in order to save the image uncompressed int wi = new Float(frame.getWidthXY(TransformSpace.GLOBAL)).intValue(); int hi = new Float(frame.getHeightXY(TransformSpace.GLOBAL)).intValue(); final MTSceneTexture sceneTexture = new MTSceneTexture(mtApplication, 0, 0, wi, hi, drawingScene); sceneTexture.getFbo().clear(true, 255, 255, 255, 0, true); sceneTexture.setStrokeColor(new MTColor(155, 155, 155)); frame.addChild(sceneTexture); // Eraser button PImage eraser = mtApplication.loadImage(path + "Kde_crystalsvg_eraser.png"); final MTImageButton eraserButton = new MTImageButton(eraser, mtApplication); eraserButton.setNoStroke(true); eraserButton.translate(new Vector3D(-50, 70, 0)); eraserButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { switch (ae.getID()) { case TapEvent.BUTTON_CLICKED: case TapEvent.BUTTON_UP: { // //As we are messing with opengl here, we make sure it happens in the // rendering thread mtApplication.invokeLater( new Runnable() { public void run() { sceneTexture.getFbo().clear(true, 255, 255, 255, 0, true); } }); } break; default: break; } } }); frame.addChild(eraserButton); // Pen brush selector button PImage penIcon = mtApplication.loadImage(path + "pen.png"); final MTImageButton penButton = new MTImageButton(penIcon, mtApplication); frame.addChild(penButton); penButton.translate(new Vector3D(-50f, 120, 0)); penButton.setNoStroke(true); penButton.setStrokeColor(new MTColor(0, 0, 0)); // Texture brush selector button PImage brushIcon = mtApplication.loadImage(path + "paintbrush.png"); final MTImageButton brushButton = new MTImageButton(brushIcon, mtApplication); frame.addChild(brushButton); brushButton.translate(new Vector3D(-50f, 170, 0)); brushButton.setStrokeColor(new MTColor(0, 0, 0)); brushButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { switch (ae.getID()) { case TapEvent.BUTTON_CLICKED: case TapEvent.BUTTON_UP: { drawingScene.setBrush(textureBrush); brushButton.setNoStroke(false); penButton.setNoStroke(true); } break; default: break; } } }); penButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { switch (ae.getID()) { case TapEvent.BUTTON_CLICKED: case TapEvent.BUTTON_UP: { drawingScene.setBrush(pencilBrush); penButton.setNoStroke(false); brushButton.setNoStroke(true); } break; default: break; } } }); ///////////////////////// // ColorPicker and colorpicker button PImage colPick = mtApplication.loadImage(path + "colorcircle.png"); // final MTColorPicker colorWidget = new MTColorPicker(0, pa.height-colPick.height, // colPick, pa); final MTColorPicker colorWidget = new MTColorPicker(0, 0, colPick, mtApplication); colorWidget.translate(new Vector3D(0f, 175, 0)); colorWidget.setStrokeColor(new MTColor(0, 0, 0)); colorWidget.addGestureListener( DragProcessor.class, new IGestureEventListener() { public boolean processGestureEvent(MTGestureEvent ge) { if (ge.getId() == MTGestureEvent.GESTURE_ENDED) { if (colorWidget.isVisible()) { colorWidget.setVisible(false); } } else { drawingScene.setBrushColor(colorWidget.getSelectedColor()); } return false; } }); frame.addChild(colorWidget); colorWidget.setVisible(false); PImage colPickIcon = mtApplication.loadImage(path + "ColorPickerIcon.png"); final MTImageButton colPickButton = new MTImageButton(colPickIcon, mtApplication); frame.addChild(colPickButton); colPickButton.translate(new Vector3D(-50f, 235, 0)); colPickButton.setNoStroke(true); colPickButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { switch (ae.getID()) { case TapEvent.BUTTON_CLICKED: case TapEvent.BUTTON_UP: { if (colorWidget.isVisible()) { colorWidget.setVisible(false); } else { colorWidget.setVisible(true); colorWidget.sendToFront(); } } break; default: break; } } }); // Add a slider to set the brush width final MTSlider slider = new MTSlider(0, 0, 200, 38, 0.05f, 2.0f, mtApplication); slider.setValue(1.0f); frame.addChild(slider); slider.rotateZ(new Vector3D(), 90, TransformSpace.LOCAL); slider.translate(new Vector3D(-7, 325)); slider.setStrokeColor(new MTColor(0, 0, 0)); slider.setFillColor(new MTColor(220, 220, 220)); slider.getKnob().setFillColor(new MTColor(70, 70, 70)); slider.getKnob().setStrokeColor(new MTColor(70, 70, 70)); slider.addPropertyChangeListener( "value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent p) { drawingScene.setBrushScale((Float) p.getNewValue()); } }); // Add triangle in slider to indicate brush width MTPolygon p = new MTPolygon( new Vertex[] { new Vertex( 2 + slider.getKnob().getWidthXY(TransformSpace.LOCAL), slider.getHeightXY(TransformSpace.LOCAL) / 2f, 0), new Vertex( slider.getWidthXY(TransformSpace.LOCAL) - 3, slider.getHeightXY(TransformSpace.LOCAL) / 4f + 2, 0), new Vertex( slider.getWidthXY(TransformSpace.LOCAL) - 1, slider.getHeightXY(TransformSpace.LOCAL) / 2f, 0), new Vertex( slider.getWidthXY(TransformSpace.LOCAL) - 3, -slider.getHeightXY(TransformSpace.LOCAL) / 4f - 2 + slider.getHeightXY(TransformSpace.LOCAL), 0), new Vertex(2, slider.getHeightXY(TransformSpace.LOCAL) / 2f, 0), }, mtApplication); p.setFillColor(new MTColor(150, 150, 150, 150)); p.setStrokeColor(new MTColor(160, 160, 160, 190)); p.unregisterAllInputProcessors(); p.setPickable(false); slider.getOuterShape().addChild(p); slider.getKnob().sendToFront(); PImage editIcon = mtApplication.loadImage(path + "edit_icon.jpg"); final MTImageButton editButton = new MTImageButton(editIcon, mtApplication); frame.addChild(editButton); editButton.translate(new Vector3D(-50f, 20, 0)); editButton.setNoStroke(true); editButton.setStrokeColor(new MTColor(0, 0, 0)); PImage handIcon = mtApplication.loadImage(path + "hand2.png"); final MTImageButton handButton = new MTImageButton(handIcon, mtApplication); frame.addChild(handButton); handButton.translate(new Vector3D(-50f, -40, 0)); handButton.setNoStroke(true); handButton.setStrokeColor(new MTColor(0, 0, 0)); penButton.setVisible(false); brushButton.setVisible(false); slider.setVisible(false); colPickButton.setVisible(false); eraserButton.setVisible(false); sceneTexture.setVisible(false); handButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { switch (ae.getID()) { case TapEvent.BUTTON_CLICKED: case TapEvent.BUTTON_UP: { handButton.setNoStroke(false); penButton.setVisible(false); brushButton.setVisible(false); slider.setVisible(false); colPickButton.setVisible(false); eraserButton.setVisible(false); sceneTexture.setVisible(false); } break; default: break; } } }); editButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { switch (ae.getID()) { case TapEvent.BUTTON_CLICKED: case TapEvent.BUTTON_UP: { editButton.setNoStroke(false); penButton.setVisible(true); brushButton.setVisible(true); slider.setVisible(true); colPickButton.setVisible(true); eraserButton.setVisible(true); sceneTexture.setVisible(true); // sceneTexture.sendToFront(); // frame.sendToFront(); } break; default: break; } } }); }
/** * Calculate the Coordinates needed for placing the Rectangle. * * @param rect the Rectangle * @param ta the TextArea * @param xo the x-offset * @param yo the y-offset * @return the position as Vector3D */ private Vector3D calcPos(MTRectangle rect, MTPolygon ta, float xo, float yo) { return new Vector3D( (ta.getWidthXY(TransformSpace.LOCAL) / 2) + rect.getVerticesLocal()[0].getX() + xo, (ta.getHeightXY(TransformSpace.LOCAL) / 2) + rect.getVerticesLocal()[0].getY() + yo); }