예제 #1
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);
  }
예제 #2
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);
  }
예제 #3
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")));
 }
예제 #4
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();
    }
  }
예제 #5
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);
  }
예제 #6
0
  public static void drawRoundOutline(MenuItem item, RoundRectangle2D r2) {
    MenuStyle style = item.getStyle();
    float sw = style.getF("f.strokeWeight");

    //		float newX = (float) (Math.floor(r2.getX())-sw);
    //		float newY = (float) (Math.ceil(r2.getY())-sw);
    //
    //		float newWidth = (float) (Math.ceil(r2.getWidth()+r2.getX()-newX));
    //		float newHeight = (float) (Math.ceil(r2.getHeight()+r2.getY()-newY));

    //		RoundRectangle2D clone = (RoundRectangle2D) r2.clone();
    RoundRectangle2D clone = r2;

    //		clone.setRoundRect(newX, newY, newWidth, newHeight, r2.getArcWidth(),
    //				r2.getArcHeight());

    preDraw(item);
    item.menu.buff.g2.draw(clone);
    postDraw(item);
  }
예제 #7
0
 public static float getTextDescent(MenuItem item) {
   MenuStyle style = item.getStyle();
   return UIUtils.getTextAscent(
       item.menu.buff, style.getFont("font"), style.getF("f.fontSize"), true);
 }
예제 #8
0
 public static float getTextHeight(MenuItem item, String s) {
   MenuStyle style = item.getStyle();
   return UIUtils.getTextHeight(
       item.menu.buff, style.getFont("font"), style.getF("f.fontSize"), s, true);
 }