Example #1
0
  public static synchronized void drawSingleGradientRect(
      MenuItem item, float x, float y, float width, float height, float roundOff) {
    Menu menu = item.menu;
    MenuStyle style = item.getStyle();

    roundRect.setRoundRect(x, y, width, height, roundOff, roundOff);
    Graphics2D g2 = menu.buff.g2;
    /*
     * Set the correct fill gradient
     */
    if (item.isOpen()) {
      g2.setPaint(item.getStyle().getGradient(MenuItem.DOWN, y, y + height));
    } else {
      g2.setPaint(item.getStyle().getGradient(MenuItem.OVER, y, y + height));
    }
    /*
     * Only perform the fill if the mood is right.
     */
    if (item.getState() != MenuItem.UP || item.isOpen()) {
      g2.fill(roundRect);
    }
    /*
     * Draw the rounded rectangle outline.
     */
    if (item.getState() != MenuItem.UP || item.isOpen()) {
      drawRoundOutline(item, roundRect);
    }
  }
Example #2
0
  public static synchronized void drawBlankRect(MenuItem item, float x, float y, float w, float h) {
    MenuItem menu = item.menu;
    MenuStyle style = item.getStyle();

    roundRect.setRoundRect(x, y, w, h, 0, 0);
    drawRoundOutline(item, roundRect);
  }
Example #3
0
  public static synchronized void drawDoubleGradientRect(
      MenuItem item, float x, float y, float width, float height) {
    PGraphicsJava2D buff = item.menu.buff;
    MenuStyle style = item.getStyle();
    Menu menu = item.menu;

    float ro = style.getF("f.roundOff");

    roundRect.setRoundRect(x, y, width, height, ro, ro);

    /*
     * Draw the first gradient: a full-height gradient.
     */
    buff.g2.setPaint(style.getGradient(MenuItem.UP, x, y, x, y + height));
    buff.g2.fill(roundRect);
    /*
     * Draw a translucent gradient on top of the first, starting halfway and
     * going to the bottom.
     */
    Composite oldC = buff.g2.getComposite();
    AlphaComposite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f * menu.alpha);
    buff.g2.setComposite(c);
    buff.g2.setPaint(style.getGradient(MenuItem.UP, x, y + height, x, y + height / 3));
    buff.g2.fillRect((int) x, (int) (y + height / 2), (int) width, (int) height / 2);
    buff.g2.setComposite(oldC);
    /*
     * Finally, draw the stroke on top of everything.
     */
    drawRoundOutline(item, roundRect);
  }
Example #4
0
 protected boolean containsPoint(Point p) {
   if (scrolling) return true;
   float ro = menu.getStyle().getF("f.roundOff");
   buffRoundRect.setRoundRect(x, y, width, height, ro, ro);
   // buffRoundRect.setRoundRect(x + nOffset, y, nWidth, height,
   // menu.getStyle().roundOff, menu.getStyle().roundOff);
   return buffRoundRect.contains(p);
 }
Example #5
0
  public static synchronized void drawWhiteTextRect(
      MenuItem item, float x, float y, float w, float h) {
    Graphics2D g2 = item.menu.buff.g2;

    roundRect.setRoundRect(x, y, w, h, h / 3, h / 3);
    if (!item.isEnabled()) g2.setPaint(item.getStyle().getC("c.disabled"));
    else g2.setPaint(Color.white);
    g2.fill(roundRect);
    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(item.getStyle().getF("f.strokeWeight")));
    g2.draw(roundRect);
  }
Example #6
0
  public static synchronized void drawBackgroundRoundRect(
      MenuItem item, float x, float y, float width, float height) {
    PGraphicsJava2D buff = item.menu.buff;
    MenuStyle style = item.getStyle();
    MenuItem menu = item.menu;

    float ro = style.getF("f.roundOff");

    roundRect.setRoundRect(x, y, width, height, ro, ro);

    buff.g2.setPaint(style.getC("c.background"));
    buff.g2.fill(roundRect);

    buff.g2.setStroke(new BasicStroke(style.getF("f.strokeWeight")));
    buff.g2.setPaint(style.getC("c.foreground"));
    buff.g2.draw(roundRect);
  }
Example #7
0
  public static synchronized void drawVerticalGradientRect(
      MenuItem item, float x, float y, float width, float height) {
    PGraphicsJava2D buff = item.menu.buff;
    MenuStyle style = item.getStyle();
    Menu menu = item.menu;

    float ro = style.getF("f.roundOff");

    roundRect.setRoundRect(x, y, width, height, ro, ro);
    /*
     * Draw the first gradient: a full-width gradient.
     */
    buff.g2.setPaint(style.getGradient(MenuItem.UP, x, y, x + width, y));
    buff.g2.fill(roundRect);
    /*
     * Draw a translucent gradient on top of the first, starting halfway and
     * going to the bottom.
     */
    Composite oldC = buff.g2.getComposite();
    AlphaComposite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f * menu.alpha);
    buff.g2.setComposite(c);
    buff.g2.setPaint(style.getGradient(MenuItem.UP, x + item.width, y, x + item.width / 3, y));
    buff.g2.fillRect((int) (x + width / 2), (int) (y), (int) (width / 2), (int) height);
    buff.g2.setComposite(oldC);
    /*
     * Finally, draw the stroke on top of everything.
     */
    RenderingHints rh = menu.buff.g2.getRenderingHints();
    buff.g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    buff.g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    buff.g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    buff.g2.setPaint(style.getC("c.foreground"));
    buff.g2.setStroke(new BasicStroke(style.getF("f.strokeWeight")));
    buff.g2.draw(roundRect);
    buff.g2.setRenderingHints(rh);
  }
Example #8
0
  protected void drawMyself() {
    float ro = getStyle().getF("f.roundOff");
    Color strokeC = getStrokeColor();
    Stroke stroke = getStroke();
    float px = getStyle().getF("f.padX");
    float py = getStyle().getF("f.padY");

    roundRect.setRoundRect(x, y, width, height, ro, ro);
    Graphics2D g2 = menu.buff.g2;

    /*
     * Set the correct fill gradient
     */
    //		if (!isEnabled())
    //		{
    //			g2.setPaint(getStyle().getC("c.disabled"));
    //		} else
    if (isOpen() && parent == menu) {
      g2.setPaint(getStyle().getGradient(MenuItem.DOWN, y, y + height));
    } else if (!hasChildren() && getState() == MenuItem.DOWN) {
      g2.setPaint(getStyle().getGradient(MenuItem.DOWN, y, y + height));
    } else g2.setPaint(getStyle().getGradient(getState(), y, y + height));

    /*
     * Only perform the fill if the mood is right.
     */
    //		if (getState() != MenuItem.UP || isOpen())
    //		{
    //			if (!isEnabled())
    //			{
    //				;
    //			} else if (menu.hovered != null && menu.hovered != this
    //					&& !isAncestorOfHovered())
    //			{
    //				;
    //			} else
    //			{
    //				g2.fill(roundRect);
    //				g2.setPaint(strokeC);
    //				g2.setStroke(stroke);
    //				g2.draw(roundRect);
    //			}
    //		}
    if (shouldPerformFill()) {
      g2.fill(roundRect);
      g2.setPaint(strokeC);
      g2.setStroke(stroke);
      g2.draw(roundRect);
    }

    /*
     * Draw the text, triangle, and shortcut.
     */
    float curX = x + px;
    MenuUtils.drawLeftText(this, getName(), curX);
    curX += tWidth;
    if (shortcut != null) {
      PFont font = getStyle().getFont("font");
      float fs = getStyle().getF("f.fontSize");

      float rightX = getX() + getWidth();
      curX = rightX - shortcutWidth;
      // curX += getStyle().padX;
      float shortSize = fs * shortcutTextSize;
      float descent = UIUtils.getTextDescent(menu.buff, font, shortSize, true);
      g2.setFont(font.getFont().deriveFont(shortSize));
      g2.setPaint(strokeC.brighter(100));
      float ht = UIUtils.getTextHeight(menu.canvas.g, font, shortSize, shortcut.label, true);
      float yOffset = (height - ht) / 2f + descent;
      yOffset += ht / 2;
      g2.drawString(shortcut.label, curX, y + yOffset);
    }
    curX += shortcutWidth;
    if (drawChildrenTriangle && items.size() > 0) {
      if (layoutMode == LAYOUT_BELOW && getState() != MenuItem.UP && !isOpen()) {
        curX = x + width / 2;
        at.setToIdentity();
        at.translate(curX, y + height + py / 2);
        at.rotate(PApplet.HALF_PI);
        Area a2 = tri.createTransformedArea(at);
        g2.setPaint(strokeC);
        g2.fill(a2);
      } else if (layoutMode != LAYOUT_BELOW) {
        curX = x + width - triWidth - px;
        at.setToIdentity();
        at.translate(curX, y + height / 2);
        Area a2 = tri.createTransformedArea(at);
        g2.setPaint(strokeC);
        g2.fill(a2);
      }
    }
  }
Example #9
0
 protected boolean containsPoint(Point p) {
   float ro = getStyle().getF("f.roundOff");
   buffRoundRect.setRoundRect(x, y, width, height, ro, ro);
   return buffRoundRect.contains(p);
 }