public void resetClip() { if (clips.isEmpty()) { if (currentClip != null) { g.setClip(null); currentClip = null; } return; } currentClip = clips.pop(); g.setClip(currentClip); }
/** @see AbstractComponent#render(GUIContext, org.newdawn.slick.Graphics) */ public void render(GUIContext container, Graphics g) { if (lastKey != -1) { if (input.isKeyDown(lastKey)) { if (repeatTimer < System.currentTimeMillis()) { repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL; keyPressed(lastKey, lastChar); } } else { lastKey = -1; } } Rectangle oldClip = g.getClip(); g.setWorldClip(x, y, width, height); // Someone could have set a color for me to blend... Color clr = g.getColor(); if (background != null) { g.setColor(background.multiply(clr)); g.fillRect(x, y, width, height); } g.setColor(text.multiply(clr)); Font temp = g.getFont(); int cpos = font.getWidth(value.substring(0, cursorPos)); int tx = 0; if (cpos > width) { tx = width - cpos - font.getWidth("_"); } g.translate(tx + 2, 0); g.setFont(font); g.drawString(value, x + 1, y + 1); if (hasFocus() && visibleCursor) { g.drawString("_", x + 1 + cpos + 2, y + 1); } g.translate(-tx - 2, 0); if (border != null) { g.setColor(border.multiply(clr)); g.drawRect(x, y, width, height); } g.setColor(clr); g.setFont(temp); g.clearWorldClip(); g.setClip(oldClip); }
@Override public void draw(Graphics g) { int width = getWidth(); int height = getHeight(); if (width == -1 || height == -1) return; g.setClip(getRealX(), getRealY(), width, height); if (this.hasBackground()) g.setColor(getBackground()); else g.setColor(Color.darkGray); g.fillRect(getRealX(), getRealY(), width, height); if (this.hasBorder()) g.setColor(getBorder().getColor()); else g.setColor(new Color(150, 150, 150)); g.drawRect(getRealX(), getRealY(), width - 1, height - 1); if (hasText()) { g.setColor(getTextColor()); int x = getRealX(), y = getRealY(); if (textcenterx) { x -= g.getFont().getWidth(getDisplayText()) / 2; if (hasWidth()) x += getWidth() / 2; } if (textcentery) { y -= g.getFont().getHeight(getDisplayText()) / 2; if (hasHeight()) y += getHeight() / 2; } g.drawString(getDisplayText(), x, y); } g.clearClip(); }
public void setClip(Rectangle rect) { if (currentClip != null) clips.push(currentClip); currentClip = rect; g.setClip(rect); }