Esempio n. 1
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);
  }
Esempio n. 2
0
 static void preDraw(MenuItem item) {
   Menu menu = item.menu;
   MenuStyle style = item.getStyle();
   PGraphicsJava2D buff = item.menu.buff;
   rh = menu.buff.g2.getRenderingHints();
   buff.g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   buff.g2.setPaint(style.getC("c.foreground"));
   buff.g2.setStroke(new BasicStroke(style.getF("f.strokeWeight")));
 }
Esempio n. 3
0
  public static void drawText(
      MenuItem item,
      String s,
      boolean centerH,
      boolean centerV,
      float x,
      float y,
      float width,
      float height) {

    try {
      Graphics2D g2 = (Graphics2D) item.menu.buff.g2;

      float descent = getTextDescent(item);

      float xOffset = 0, yOffset = 0;
      if (centerH) {
        float tWidth = getTextWidth(item, s);
        xOffset = (width - tWidth) / 2f;
      }
      if (centerV) {
        float tHeight = getTextHeight(item, s);
        yOffset = (height - tHeight) / 2f + descent;
      } else yOffset = height - descent;

      MenuStyle style = item.getStyle();
      PFont font = style.getFont("font");
      float fs = style.getF("f.fontSize");

      g2.setFont(font.getFont().deriveFont(fs));
      if (!item.isEnabled()) g2.setPaint(style.getC("c.foreground").brighter(120));
      else g2.setPaint(style.getC("c.foreground"));
      g2.setStroke(new BasicStroke(style.getF("f.strokeWeight")));
      g2.drawString(s, x + xOffset, y + yOffset);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 4
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);
  }