コード例 #1
0
  /**
   * Renders the shape that is currently being sized by the user as they drag the mouse across the
   * canvas. We render this separately because we have not yet put it in the shapes list for the
   * pose.
   *
   * @param g2 The graphics context for this canvas.
   * @param poseArea The area in the middle of the canvas where the pose will be rendered.
   */
  private void renderShapeInProgress(Graphics2D g2, Rectangle2D.Double poseArea) {
    AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor();
    PoseurStateManager poseurStateManager = singleton.getStateManager().getPoseurStateManager();
    PoseurShape shapeInProgress = poseurStateManager.getShapeInProgress();

    // ONLY DO THIS ON THE RIGHT SIDE
    if (state.isZoomable() && (shapeInProgress != null)) {
      float zoomLevel = state.getZoomLevel();
      shapeInProgress.render(g2, (int) poseArea.getX(), (int) poseArea.getY(), zoomLevel, true);
    }
  }
コード例 #2
0
  /** Default constructor for this abstract class, it initializes */
  public PoseurShape() {
    // LET'S FILL IN THIS CLASS' DATA WITH SETTINGS
    // FROM THE GUI CONTROLS
    AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor();
    AnimatedSpriteEditorGUI gui = singleton.getGUI();

    // ASK THE GUI FOR ALL THESE VALUES
    outlineColor = gui.getOutlineColor();
    fillColor = gui.getFillColor();
    int lineThickness = gui.getLineThickness();
    outlineThickness = new BasicStroke(lineThickness);
    alpha = gui.getAlphaTransparency();
  }
コード例 #3
0
  /**
   * This method renders all debug text in the canvas. Doing is useful in a graphical application
   * because it's tricky stopping the debugger while rendering, so using this technique we can view
   * variable data in the app while it is running.
   *
   * @param g2 The graphics context for this canvas.
   */
  private void renderDebugText(Graphics2D g2) {
    // AND FINALLY, THE DEBUG TEXT, IF THE OPTION IS TURNED ON
    AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor();
    if (singleton.isDebugTextEnabled()) {
      // SET THE CORRECT FONT AND COLOR
      g2.setFont(DEBUG_TEXT_FONT);
      g2.setColor(DEBUG_TEXT_COLOR);

      // GET EACH ITEM ONE AT A TIME
      Iterator<String> debugTextIt = singleton.getDebugTextIterator();
      int x = DEBUG_TEXT_START_X;
      int y = DEBUG_TEXT_START_Y;
      while (debugTextIt.hasNext()) {
        String text = debugTextIt.next();
        g2.drawString(text, x, y);
        y += DEBUG_TEXT_LINE_SPACING;
      }
      singleton.clearDebugText();
    }
  }
コード例 #4
0
  /**
   * Renders all the shapes in the corresponding canvas state object for this canvas.
   *
   * @param g2 The graphics context of this panel.
   */
  private void renderShapes(Graphics2D g2, Rectangle2D.Double poseArea) {
    // LET'S GET THE POSE AREA AND THE POSE
    PoseurPose pose = state.getPose();
    float zoomLevel = state.getZoomLevel();

    // RENDER THE ENTIRE POSE
    Iterator<PoseurShape> shapesIt = pose.getShapesIterator();
    AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor();
    PoseurStateManager poseurStateManager = singleton.getStateManager().getPoseurStateManager();
    while (shapesIt.hasNext()) {
      PoseurShape shape = shapesIt.next();
      boolean isSelected = poseurStateManager.isSelectedShape(shape);

      // NOTE THAT WE NEVER DEPICT SELECTED SHAPES DIFFERENTLY
      // IN THE TRUE CANVAS, ONLY THE ZOOMABLE CANVAS
      if (!state.isZoomable()) {
        isSelected = false;
      }
      shape.render(g2, (int) poseArea.getX(), (int) poseArea.getY(), zoomLevel, isSelected);
    }
  }
コード例 #5
0
  /**
   * This method renders what would be in the pose area into the imageToPaintTo image argument. The
   * paintComponent method paints to a canvas (i.e. the screen), which this one is paints to an
   * image that can then be saved to a file
   *
   * @param imageToPaintTo The image we will paint what is in this canvas' pose area to.
   */
  public void paintToImage(BufferedImage imageToPaintTo) {
    Graphics2D imageG2 = (Graphics2D) imageToPaintTo.getGraphics();
    imageG2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor();
    PoseurStateManager poseurStateManager = singleton.getStateManager().getPoseurStateManager();
    PoseurPose pose = poseurStateManager.getPose();

    // FIRST LET'S PUT A TRANSPARENT BACKGROUND THE SIZE OF THE POSE
    Rectangle2D.Double transparentRect =
        new Rectangle2D.Double(0, 0, pose.getPoseWidth(), pose.getPoseHeight());
    imageG2.setColor(TRANSPARENT_BACKGROUND_COLOR);
    imageG2.fill(transparentRect);
    imageG2.draw(transparentRect);

    // NOW LET'S DRAW ALL THE SHAPES ON TOP, BUT WE'LL
    // FAKE THE POSE AREA SO WE ONLY DRAW THE MIDDLE PART
    Rectangle2D.Double poseArea =
        new Rectangle2D.Double(0, 0, pose.getPoseWidth(), pose.getPoseHeight());
    renderShapes(imageG2, poseArea);

    // ALL DONE, WE'VE JUST PAINTED TO THE IMAGE WHAT WE
    // WOULD NORMALLY DRAW INSIDE THE POSE AREA
  }