Ejemplo n.º 1
0
  public void render(GUIContext ctx, Graphics g, Component comp, Skin skin, Theme theme) {
    // makes sure it's the same as what we're attached to
    checkComponent(comp);

    CheckBox check = (CheckBox) comp;
    Rectangle cachedRect = null;
    boolean roundRectEnabled = SimpleSkin.isRoundRectanglesEnabled();

    // make sure we are showing outline
    // also, the outline will only render if we aren't rendering a background
    if (isShowOutline() && (!check.isOpaque() || check.getBackground() == null)) {
      // get the cached rectangle from the component bounds
      cachedRect = check.getAbsoluteBounds();
      Rectangle bounds = cachedRect;

      // if we have round rectangles, use them
      if (roundRectEnabled && roundBounds != null) {
        roundBounds.setBounds(bounds);
        bounds = roundBounds;
      }

      Color oldCol = g.getColor();
      boolean oldAA = g.isAntiAlias();
      Color back;

      if (check.getState() != Button.UP) // hover
      back = theme.getPrimary1();
      else // still
      back = theme.getPrimary3();

      g.setColor(back);
      g.setAntiAlias(true);
      g.fill(bounds);

      g.setAntiAlias(oldAA);
      g.setColor(oldCol);
    }

    // renders base
    SkinUtil.renderComponentBase(g, check);

    // renders text/image
    SkinUtil.renderCheckBoxBase(g, check);

    // get cached bounds from the "check" box button area
    Rectangle cachedBox = check.getAbsoluteBoxBounds();
    Rectangle btnRect = cachedBox;

    // try to use round rectangle
    if (roundRectEnabled && roundBoxBounds != null) {
      roundBoxBounds.setBounds(cachedBox);
      btnRect = roundBoxBounds;
    }

    // renders the actual button state for the small box area, using rounded edges
    SimpleButtonAppearance.renderButtonState(g, theme, check, btnRect, grad);

    Image def = getDefaultImage();
    if (def != null && check.isSelected()) {
      float x = btnRect.getX() + (btnRect.getWidth() / 2f - def.getWidth() / 2f);
      float y = btnRect.getY() + (btnRect.getHeight() / 2f - def.getHeight() / 2f);
      g.drawImage(def, (int) x, (int) y, check.getImageFilter());
    }
  }