コード例 #1
0
  @Override
  public void paint(GraphicsHandle graphics) {
    // this.fillBackground(); //Fill the background with color just in case

    for (int x = 0; x < width(); x += BG_WIDTH) { // Draw the tiled grey stone background image
      for (int y = 0; y < height(); y += BG_HEIGHT) {
        graphics.drawImage(Resources.bank.BACKGROUND, x, y);
      }
    }
    /* 'WORKSPACE' BUFFER EXPLANATION
    All child children except for one currently being moved are drawn because this Workspace's own
      buffer is then drawn to the 'workspace' buffer, which is a buffer of all Modules not being
      moved / resized. Doing it like this cuts down on the amount of graphical operations greatly
      because instead of drawing all children to both buffers, all static children can be drawn to the Module
      buffer and then that buffer can be drawn to the 'workspace' buffer, containing all the static
      children but not the dynamic child. The dynamaic child is then drawn onto this buffer because it
      needs to, just like every other child.
    */
    for (WorkTool wt : children) {
      if (wt != moveTool) {
        wt.repaint();
      }
    }

    if (moveTool
        != null) { // If a tool is being moved, it should not be drawn to the static buffer, but
      // does need to be drawn to the normal
      // graphics buffer
      moveTool.repaint();
    }
  }
コード例 #2
0
  private void drawTool() {
    /// argh this wording tho
    GraphicsHandle handle = beginDraw();
    handle.drawImage(workspace, 0, 0, null); // Draw the current buffer of the workspace

    Vector start = new Vector(),
        size = new Vector(); // Store where the being created tool should be drawn
    /* WORKTOOL VECTOR ORGANIZATION
    Vector start - stores the start draw position of the tool
    Vector size - stores the size of the tool being draw

    The start will consist of the lesser x and y out of toolStart and toolEnd.
    The size will consist of the size required to draw based on this - it will
      consist of the difference between the greater coordinate and the lesser
      coordinate becauase that is the size of the tool.
    */
    if (toolStart.x < toolEnd.x) {
      start.x = toolStart.x;
      size.x = toolEnd.x - toolStart.x;
    } else {
      start.x = toolEnd.x;
      size.x = toolStart.x - toolEnd.x;
    }

    if (toolStart.y < toolEnd.y) {
      start.y = toolStart.y;
      size.y = toolEnd.y - toolStart.y;
    } else {
      start.y = toolEnd.y;
      size.y = toolStart.y - toolEnd.y;
    }

    /*
    How snapping works with new tools -

    The toolStart and toolEnd are not themselves snapped because
      if the snapping control becomes inactive, toolStart and toolEnd
      will need to revert to what they were before snapping started.
      When drawing the tools, however, if they are being snapped, the
      Vectors used for drawing ('start' and 'size') do need to be snapped
      such that an accurate picture of the new tool is drawn.

    If the snapping control continues to be active when the tool is actually
      created, then both toolStart and toolEnd will be snapped because they had
      not been snapped previously.
    */
    if (Controls.bank.status(Controls.WORKSPACE_GRID_SNAP)) {
      start.snap(GRID_SIZE); // Snap the drawing Vectors if the snapping control is active
      size.snap(GRID_SIZE);
    }

    /*
    The drawn rectangle should appear blue if the tool is valid and red
      if the tool is invalid. The only cases where the tool is invalid
      (currently) are if it is smaller than the minimum size or if it
      intersects a currently existing tool. Therefore, before drawaing the
      tools, it is checked if they are valid to present a real-time picture
      to the user if the tool is valid or not.
    */

    boolean valid =
        true; // If true, the tool is valid and is drawn blue; otherwise, it is invalid and drawn
    // red (and not created when the mouse is released.)
    if (size.x >= MIN_SIZE && size.y >= MIN_SIZE) { // Checks to see if the tool is of a valid size
      Rectangle validator =
          new Rectangle(
              start,
              size); // Create a rectangle with the potential bounds to check for intersections
      for (WorkTool wt :
          children) { // Check to see if the bounds of the potential tool intersect any existing
        // tools
        if (wt.intersects(validator)) {
          valid =
              false; // if the bounds intersect and existing tool, the tool should be drawn as red
        }
      }
    } else {
      valid = false; // If the tool is not of a valid size, it should be drawn red
    }

    handle.setColor(
        valid
            ? TOOL_FILL_COLOR
            : BAD_TOOL_FILL_COLOR); // Set the fill color of the tool based on whether the tool is
    // valid or not
    handle.fillRect(
        start.x + 1,
        start.y + 1,
        size.x - 2,
        size.y - 2); // Fill the projected bounds of the created tool
    handle.setColor(
        valid
            ? TOOL_BORDER_COLOR
            : BAD_TOOL_BORDER_COLOR); // Set the border color based on whether the tool is valid or
    // not
    handle.drawRect(
        start.x,
        start.y,
        size.x - 1,
        size.y - 1); // Border in the projected bounds of the created tool
    endDraw(handle);
  }
コード例 #3
0
 /**
  * Helper method to draw text to the Module.
  *
  * @param text The String of text to draw.
  * @param size The size multiplier of the text to draw.
  * @param x The x position of the top-left corner of the text.
  * @param y The y position of the top-left corner of the text.
  * @param handle The handle to draw the text with.
  */
 protected final void drawText(String text, int size, int x, int y, GraphicsHandle handle) {
   handle.drawImage(Resources.bank.text.draw(text, size), x, y, null);
 }