Java Code Examples for org.newdawn.slick.Graphics#setClip()
The following examples show how to use
org.newdawn.slick.Graphics#setClip() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectTransition.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void preRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException { if (moveBackDone) { g.translate(xp1,yp1); g.scale(scale1, scale1); g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight())); prev.render(container, game, g); g.resetTransform(); g.clearClip(); } g.translate(xp2,yp2); g.scale(scale2, scale2); g.setClip((int) xp2,(int) yp2,(int) (scale2*container.getWidth()),(int) (scale2*container.getHeight())); }
Example 2
Source File: TextField.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
public void render(Graphics g) { 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 (backgroundCol != null) { g.setColor(backgroundCol.multiply(clr)); g.fillRect(x, y, width, height); } g.setColor(textCol.multiply(clr)); Font temp = g.getFont(); int cursorpos = font.getWidth(value); int tx = 0; if (cursorpos > width) { tx = width - cursorpos - font.getWidth("_"); } g.translate(tx + 2, 0); g.setFont(font); g.drawString(value, x + 1, y + 1); if (focused) { g.drawString("|", x + cursorpos, y + 1); } g.translate(-tx - 2, 0); if (borderCol != null) { g.setColor(borderCol.multiply(clr)); g.drawRect(x, y, width, height); } g.setColor(clr); g.setFont(temp); g.clearWorldClip(); g.setClip(oldClip); }
Example 3
Source File: UserSelectOverlay.java From opsu with GNU General Public License v3.0 | 5 votes |
@Override public void render(GUIContext container, Graphics g) throws SlickException { g.setClip((int) x, (int) y, width, height); // background g.setColor(COLOR_BG); g.fillRect(x, y, width, height); // render states if (!stateChangeProgress.isFinished()) { // blend states float t = stateChangeProgress.getValue(); if (prevState == State.USER_SELECT) t = 1f - t; renderUserSelect(g, t); if (state == State.CREATE_USER || prevState == State.CREATE_USER) renderUserCreate(g, 1f - t); else if (state == State.EDIT_USER || prevState == State.EDIT_USER) renderUserEdit(g, 1f - t); } else if (state == State.USER_SELECT) renderUserSelect(g, globalAlpha); else if (state == State.CREATE_USER) renderUserCreate(g, globalAlpha); else if (state == State.EDIT_USER) renderUserEdit(g, globalAlpha); g.clearClip(); }
Example 4
Source File: UserSelectOverlay.java From opsu with GNU General Public License v3.0 | 5 votes |
/** Renders the user icons. */ private void renderUserIcons(Graphics g, int iconId, String header, int cy, float alpha) { Fonts.MEDIUMBOLD.drawString(x + (width - Fonts.MEDIUMBOLD.getWidth(header)) / 2, cy, header, COLOR_WHITE); cy += Fonts.MEDIUMBOLD.getLineHeight() + usersPaddingY; int iconSize = UserButton.getIconSize(); int paddingX = iconSize / 4; int maxPerLine = UserButton.getWidth() / (iconSize + paddingX); // start scroll area here g.setClip((int) x, cy, width, height - (int) (cy - y)); int scrollOffset = ((userIcons.length - 1) / maxPerLine + 1) * (iconSize + usersPaddingY); scrollOffset -= height - cy; scrollOffset = Math.max(scrollOffset, 0); scrolling.setMinMax(0, scrollOffset); cy += -scrolling.getPosition(); for (int i = 0; i < userIcons.length; i += maxPerLine) { // draw line-by-line int n = Math.min(maxPerLine, userIcons.length - i); int cx = (int) (x + usersStartX + (UserButton.getWidth() - iconSize * n - paddingX * (n - 1)) / 2); for (int j = 0; j < n; j++) { MenuButton button = userIcons[i + j]; button.setX(cx + iconSize / 2); button.setY(cy + iconSize / 2); if (cy < height) { button.getImage().setAlpha((iconId == i + j) ? alpha : alpha * button.getHoverAlpha() * 0.9f ); button.getImage().draw(cx, cy); } cx += iconSize + paddingX; } cy += iconSize + usersPaddingY; } }
Example 5
Source File: SelectTransition.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException { g.resetTransform(); if (!moveBackDone) { g.translate(xp1,yp1); g.scale(scale1, scale1); g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight())); prev.render(container, game, g); g.resetTransform(); g.clearClip(); } }
Example 6
Source File: ClipTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.white); g.drawString("1 - No Clipping", 100, 10); g.drawString("2 - Screen Clipping", 100, 30); g.drawString("3 - World Clipping", 100, 50); if (world) { g.drawString("WORLD CLIPPING ENABLED", 200, 80); } if (clip) { g.drawString("SCREEN CLIPPING ENABLED", 200, 80); } g.rotate(400, 400, ang); if (world) { g.setWorldClip(350,302,100,196); } if (clip) { g.setClip(350,302,100,196); } g.setColor(Color.red); g.fillOval(300,300,200,200); g.setColor(Color.blue); g.fillRect(390,200,20,400); g.clearClip(); g.clearWorldClip(); }
Example 7
Source File: TextField.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext, * org.newdawn.slick.Graphics) */ @Override 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); }
Example 8
Source File: UserButton.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * Draws a user button. * @param g the graphics context * @param alpha the alpha multiplier */ public void draw(Graphics g, float alpha) { int padding = 4; int cx = x + padding, cy = y + padding; float t = bgAlpha.getValue(); float oldWhiteAlpha = Colors.WHITE_FADE.a; Colors.WHITE_FADE.a = alpha; // rectangle Color bg; if (flashing) { bg = flashColor; bg.a = t * alpha; } else { bg = bgColor; bg.a = (0.5f * t) * alpha; } g.setColor(bg); g.fillRoundRect(cx, cy, buttonWidth - padding * 2, buttonHeight - padding * 2, 4); // no user? if (user == null && placeholderText != null) { Fonts.LARGE.drawString( x + (buttonWidth - Fonts.LARGE.getWidth(placeholderText)) / 2, y + (buttonHeight - Fonts.LARGE.getLineHeight()) / 2, placeholderText, Colors.WHITE_FADE ); Colors.WHITE_FADE.a = oldWhiteAlpha; return; } // icon int iconSize = buttonHeight - padding * 4; Image img = getIconImage(user.getIconId()); img.setAlpha(alpha); img.draw(cx + padding, cy + padding); // text int textX = cx + iconSize + padding * 3; int textY = cy + padding / 2; Fonts.MEDIUM.drawString(textX, textY, user.getName(), Colors.WHITE_FADE); textY += Fonts.MEDIUM.getLineHeight() - 3; Fonts.SMALL.drawString(textX, textY, String.format("Score: %,d", user.getScore()), Colors.WHITE_FADE); textY += Fonts.SMALL.getLineHeight() - 2; Fonts.SMALL.drawString(textX, textY, String.format("Accuracy: %.2f%%", user.getAccuracy()), Colors.WHITE_FADE); textY += Fonts.SMALL.getLineHeight() - 2; Fonts.SMALL.drawString(textX, textY, String.format("Lv%d", user.getLevel()), Colors.WHITE_FADE); // progress bar int barX = textX + Fonts.SMALL.getWidth("Lv#####"); int barWidth = x + buttonWidth - padding - barX - 1; int barHeight = buttonHeight / 7; int barY = y + buttonHeight - padding - barHeight - 1; int barRadius = 8; float barAlpha = (0.75f + 0.25f * t) * alpha; barBgColor.a = barBorderColor.a = barFillColor.a = barAlpha; g.setColor(barBgColor); g.fillRoundRect(barX, barY, barWidth, barHeight, barRadius); g.setClip(barX, barY, (int) (barWidth * user.getNextLevelProgress()), barHeight); g.setColor(barFillColor); g.fillRoundRect(barX, barY, barWidth, barHeight, barRadius); g.clearClip(); g.setAntiAlias(true); g.setColor(barBorderColor); g.setLineWidth(2f); g.drawRoundRect(barX, barY, barWidth, barHeight, barRadius); g.resetLineWidth(); g.setAntiAlias(false); Colors.WHITE_FADE.a = oldWhiteAlpha; }
Example 9
Source File: TextField.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.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); }
Example 10
Source File: GraphicsTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.white); g.setAntiAlias(true); for (int x=0;x<360;x+=10) { g.drawLine(700,100,(int) (700+(Math.cos(Math.toRadians(x))*100)), (int) (100+(Math.sin(Math.toRadians(x))*100))); } g.setAntiAlias(false); g.setColor(Color.yellow); g.drawString("The Graphics Test!", 300, 50); g.setColor(Color.white); g.drawString("Space - Toggles clipping", 400, 80); g.drawString("Frame rate capped to 100", 400, 120); if (clip) { g.setColor(Color.gray); g.drawRect(100,260,400,100); g.setClip(100,260,400,100); } g.setColor(Color.yellow); g.translate(100, 120); g.fill(poly); g.setColor(Color.blue); g.setLineWidth(3); g.draw(poly); g.setLineWidth(1); g.translate(0, 230); g.draw(poly); g.resetTransform(); g.setColor(Color.magenta); g.drawRoundRect(10, 10, 100, 100, 10); g.fillRoundRect(10, 210, 100, 100, 10); g.rotate(400, 300, ang); g.setColor(Color.green); g.drawRect(200,200,200,200); g.setColor(Color.blue); g.fillRect(250,250,100,100); g.drawImage(image, 300,270); g.setColor(Color.red); g.drawOval(100,100,200,200); g.setColor(Color.red.darker()); g.fillOval(300,300,150,100); g.setAntiAlias(true); g.setColor(Color.white); g.setLineWidth(5.0f); g.drawOval(300,300,150,100); g.setAntiAlias(true); g.resetTransform(); if (clip) { g.clearClip(); } }
Example 11
Source File: ScoreData.java From opsu-dance with GNU General Public License v3.0 | 2 votes |
/** * Sets a vertical clip to the area. * @param g the graphics context */ public static void clipToArea(Graphics g) { g.setClip(0, (int) baseY, containerWidth, (int) buttonAreaHeight); }
Example 12
Source File: DownloadNode.java From opsu with GNU General Public License v3.0 | 2 votes |
/** * Sets a clip to the download result button area. * @param g the graphics context */ public static void clipToResultArea(Graphics g) { g.setClip((int) buttonBaseX, (int) buttonBaseY, (int) buttonWidth, (int) (buttonOffset * maxResultsShown)); }
Example 13
Source File: DownloadNode.java From opsu with GNU General Public License v3.0 | 2 votes |
/** * Sets a clip to the download area. * @param g the graphics context */ public static void clipToDownloadArea(Graphics g) { g.setClip((int) infoBaseX, (int) infoBaseY, (int) infoWidth, (int) (infoHeight * maxDownloadsShown)); }
Example 14
Source File: ScoreData.java From opsu with GNU General Public License v3.0 | 2 votes |
/** * Sets a vertical clip to the area. * @param g the graphics context */ public static void clipToArea(Graphics g) { g.setClip(0, (int) baseY, containerWidth, (int) buttonAreaHeight); }