Exemple #1
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);
 }
Exemple #2
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);
    }
  }
Exemple #3
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);
  }
Exemple #4
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);
  }
Exemple #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);
  }
Exemple #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);
  }
Exemple #7
0
  /**
   * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla
   * en todas partes...
   */
  static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) {
    ButtonModel model = menuItem.getModel();
    Color oldColor = g.getColor();

    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();

    if (menuItem.isOpaque()) {
      g.setColor(menuItem.getBackground());
      g.fillRect(0, 0, menuWidth, menuHeight);
    }

    if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected())
        || model.isArmed()) {
      RoundRectangle2D.Float boton = new RoundRectangle2D.Float();
      boton.x = 1;
      boton.y = 0;
      boton.width = menuWidth - 3;
      boton.height = menuHeight - 1;
      boton.arcwidth = 8;
      boton.archeight = 8;

      GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu());

      Graphics2D g2D = (Graphics2D) g;
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(bgColor);
      g2D.fill(boton);

      g.setColor(bgColor.darker());
      g2D.draw(boton);

      g2D.setPaint(grad);
      g2D.fill(boton);

      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    }

    g.setColor(oldColor);
  }
Exemple #8
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);
  }
Exemple #9
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);
      }
    }
  }
Exemple #10
0
 protected boolean containsPoint(Point p) {
   float ro = getStyle().getF("f.roundOff");
   buffRoundRect.setRoundRect(x, y, width, height, ro, ro);
   return buffRoundRect.contains(p);
 }