Java Code Examples for org.newdawn.slick.Image#getHeight()
The following examples show how to use
org.newdawn.slick.Image#getHeight() .
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: MenuButton.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Set x and y radius of the button based on current scale factor * and expansion direction. */ private void setHoverRadius() { Image image = this.img; if (image == null) image = anim.getCurrentFrame(); int xOffset = 0, yOffset = 0; float currentScale = scale.getValue(); if (dir != Expand.CENTER) { // offset by difference between normal/scaled image dimensions xOffset = (int) ((currentScale - 1f) * image.getWidth()); yOffset = (int) ((currentScale - 1f) * image.getHeight()); if (dir == Expand.UP || dir == Expand.DOWN) xOffset = 0; // no horizontal offset if (dir == Expand.RIGHT || dir == Expand.LEFT) yOffset = 0; // no vertical offset if (dir == Expand.RIGHT || dir == Expand.DOWN_RIGHT || dir == Expand.UP_RIGHT) xOffset *= -1; // flip x for right if (dir == Expand.DOWN || dir == Expand.DOWN_LEFT || dir == Expand.DOWN_RIGHT) yOffset *= -1; // flip y for down } this.xRadius = ((image.getWidth() * currentScale) + xOffset) / 2f; this.yRadius = ((image.getHeight() * currentScale) + yOffset) / 2f; }
Example 2
Source File: UI.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Draws the volume bar on the middle right-hand side of the game container. * Only draws if the volume has recently been changed using with {@link #changeVolume(int)}. * @param g the graphics context */ public static void drawVolume(Graphics g) { if (volumeDisplay == -1) return; int width = container.getWidth(), height = container.getHeight(); Image img = GameImage.VOLUME.getImage(); // move image in/out float xOffset = 0; float ratio = (float) volumeDisplay / VOLUME_DISPLAY_TIME; if (ratio <= 0.1f) xOffset = img.getWidth() * (1 - (ratio * 10f)); else if (ratio >= 0.9f) xOffset = img.getWidth() * (1 - ((1 - ratio) * 10f)); img.drawCentered(width - img.getWidth() / 2f + xOffset, height / 2f); float barHeight = img.getHeight() * 0.9f; float volume = Options.getMasterVolume(); g.setColor(Color.white); g.fillRoundRect( width - (img.getWidth() * 0.368f) + xOffset, (height / 2f) - (img.getHeight() * 0.47f) + (barHeight * (1 - volume)), img.getWidth() * 0.15f, barHeight * volume, 3 ); }
Example 3
Source File: UI.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Draws a tab image and text centered at a location. * @param x the center x coordinate * @param y the center y coordinate * @param text the text to draw inside the tab * @param selected whether the tab is selected (white) or not (red) * @param isHover whether to include a hover effect (unselected only) */ public static void drawTab(float x, float y, String text, boolean selected, boolean isHover) { Image tabImage = GameImage.MENU_TAB.getImage(); float tabTextX = x - (Fonts.MEDIUM.getWidth(text) / 2); float tabTextY = y - (tabImage.getHeight() / 2); Color filter, textColor; if (selected) { filter = Color.white; textColor = Color.black; } else { filter = (isHover) ? Colors.RED_HOVER : Color.red; textColor = Color.white; } tabImage.drawCentered(x, y, filter); Fonts.MEDIUM.drawString(tabTextX, tabTextY, text, textColor); }
Example 4
Source File: GameRanking.java From opsu with GNU General Public License v3.0 | 6 votes |
@Override public void init(GameContainer container, StateBasedGame game) throws SlickException { this.game = game; this.input = container.getInput(); int width = container.getWidth(); int height = container.getHeight(); // buttons Image retry = GameImage.PAUSE_RETRY.getImage(); Image replay = GameImage.PAUSE_REPLAY.getImage(); replayY = (height * 0.985f) - replay.getHeight() / 2f; retryY = replayY - (replay.getHeight() / 2f) - (retry.getHeight() / 1.975f); retryButton = new MenuButton(retry, width - (retry.getWidth() / 2f), retryY); replayButton = new MenuButton(replay, width - (replay.getWidth() / 2f), replayY); retryButton.setHoverFade(); replayButton.setHoverFade(); }
Example 5
Source File: MenuButton.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Set x and y radius of the button based on current scale factor * and expansion direction. */ private void setHoverRadius() { Image image = this.img; if (image == null) image = anim.getCurrentFrame(); int xOffset = 0, yOffset = 0; float currentScale = scale.getValue(); if (dir != Expand.CENTER) { // offset by difference between normal/scaled image dimensions xOffset = (int) ((currentScale - 1f) * image.getWidth()); yOffset = (int) ((currentScale - 1f) * image.getHeight()); if (dir == Expand.UP || dir == Expand.DOWN) xOffset = 0; // no horizontal offset if (dir == Expand.RIGHT || dir == Expand.LEFT) yOffset = 0; // no vertical offset if (dir == Expand.RIGHT || dir == Expand.DOWN_RIGHT || dir == Expand.UP_RIGHT) xOffset *= -1; // flip x for right if (dir == Expand.DOWN || dir == Expand.DOWN_LEFT || dir == Expand.DOWN_RIGHT) yOffset *= -1; // flip y for down } this.xRadius = ((image.getWidth() * currentScale) + xOffset) / 2f; this.yRadius = ((image.getHeight() * currentScale) + yOffset) / 2f; }
Example 6
Source File: ImageCornerTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { image = new Image("testdata/logo.png"); width = image.getWidth() / 3; height = image.getHeight() / 3; images = new Image[] { image.getSubImage(0, 0, width, height), image.getSubImage(width,0,width,height), image.getSubImage(width*2,0,width,height), image.getSubImage(0, height, width, height), image.getSubImage(width,height,width,height), image.getSubImage(width*2,height,width,height), image.getSubImage(0, height*2, width, height), image.getSubImage(width,height*2,width,height), image.getSubImage(width*2,height*2,width,height), }; images[0].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[1].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[1].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[2].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[3].setColor(Image.TOP_RIGHT, 0,1,1,1); images[3].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[4].setColor(Image.TOP_RIGHT, 0,1,1,1); images[4].setColor(Image.TOP_LEFT, 0,1,1,1); images[4].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[4].setColor(Image.BOTTOM_RIGHT, 0,1,1,1); images[5].setColor(Image.TOP_LEFT, 0,1,1,1); images[5].setColor(Image.BOTTOM_LEFT, 0,1,1,1); images[6].setColor(Image.TOP_RIGHT, 0,1,1,1); images[7].setColor(Image.TOP_RIGHT, 0,1,1,1); images[7].setColor(Image.TOP_LEFT, 0,1,1,1); images[8].setColor(Image.TOP_LEFT, 0,1,1,1); }
Example 7
Source File: Beatmap.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Draws the beatmap background image. * @param width the container width * @param height the container height * @param offsetX the x offset (from the screen center) * @param offsetY the y offset (from the screen center) * @param alpha the alpha value * @param stretch if true, stretch to screen dimensions; otherwise, maintain aspect ratio * @return true if successful, false if any errors were produced */ public boolean drawBackground(int width, int height, float offsetX, float offsetY, float alpha, boolean stretch) { if (bg == null) return false; ImageLoader imageLoader = bgImageCache.get(bg); if (imageLoader == null) return false; Image bgImage = imageLoader.getImage(); if (bgImage == null) return true; int swidth = width; int sheight = height; if (!stretch) { // fit image to screen if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height) // x > y sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth()); else swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight()); } else { // fill screen while maintaining aspect ratio if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height) // x > y swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight()); else sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth()); } if (Options.isParallaxEnabled()) { swidth = (int) (swidth * GameImage.PARALLAX_SCALE); sheight = (int) (sheight * GameImage.PARALLAX_SCALE); } bgImage = bgImage.getScaledCopy(swidth, sheight); bgImage.setAlpha(alpha); if (!Options.isParallaxEnabled() && offsetX == 0f && offsetY == 0f) bgImage.drawCentered(width / 2, height / 2); else bgImage.drawCentered(width / 2 + offsetX, height / 2 + offsetY); return true; }
Example 8
Source File: MenuButton.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Creates a new button from an Image. * @param img the image * @param x the center x coordinate * @param y the center y coordinate */ public MenuButton(Image img, float x, float y) { this.img = img; this.x = x; this.y = y; this.xRadius = img.getWidth() / 2f; this.yRadius = img.getHeight() / 2f; }
Example 9
Source File: ButtonMenu.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Initializes the menu state. * @param container the game container * @param game the game * @param button the center button image * @param buttonL the left button image * @param buttonR the right button image */ public void init(GameContainer container, StateBasedGame game, Image button, Image buttonL, Image buttonR) { float center = container.getWidth() / 2f; float baseY = getBaseY(container, game); float offsetY = button.getHeight() * 1.25f; menuButtons = new MenuButton[buttons.length]; for (int i = 0; i < buttons.length; i++) { MenuButton b = new MenuButton(button, buttonL, buttonR, center, baseY + (i * offsetY)); b.setText(String.format("%d. %s", i + 1, buttons[i].getText()), Fonts.XLARGE, Color.white); b.setHoverFade(); menuButtons[i] = b; } }
Example 10
Source File: Beatmap.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Draws the beatmap background image. * @param width the container width * @param height the container height * @param alpha the alpha value * @param stretch if true, stretch to screen dimensions; otherwise, maintain aspect ratio * @return true if successful, false if any errors were produced */ public boolean drawBackground(int width, int height, float alpha, boolean stretch) { if (bg == null) { return false; } ImageLoader imageLoader = bgImageCache.get(bg); if (imageLoader == null) return false; Image bgImage = imageLoader.getImage(); if (bgImage == null) return true; int swidth = width; int sheight = height; if (!stretch) { // fit image to screen if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height) // x > y sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth()); else swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight()); } else { // fill screen while maintaining aspect ratio if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height) // x > y swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight()); else sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth()); } bgImage = bgImage.getScaledCopy(swidth, sheight); bgImage.setAlpha(alpha); bgImage.drawCentered(width / 2, height / 2); return true; }
Example 11
Source File: MenuButton.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Creates a new button from an Image. * @param img the image * @param x the center x coordinate * @param y the center y coordinate */ public MenuButton(Image img, float x, float y) { this.img = img; this.x = x; this.y = y; this.xRadius = img.getWidth() / 2f; this.yRadius = img.getHeight() / 2f; }
Example 12
Source File: UI.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
private static int calcTooltipLocationForImage(GameImage gi) { Image img = gi.getImage(); int w2 = img.getWidth() / 2; int h2 = img.getHeight() / 2; for (int i = 10; i > 0; i--) { float p = i / 10.0f; float a = img.getAlphaAt(w2 + (int) (w2 * p), h2 + (int) (h2 * p)); System.out.printf("%f: %f%n", p, a); if (a > .7f) { return (int) (gi.getWidth() / 2.0f * p); } } return 0; }
Example 13
Source File: GameRanking.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
@Override public void revalidate() { super.revalidate(); // buttons Image retry = GameImage.PAUSE_RETRY.getImage(); Image replay = GameImage.PAUSE_REPLAY.getImage(); replayY = height * 0.985f - replay.getHeight() / 2f; retryY = replayY - (replay.getHeight() / 2f) - (retry.getHeight() / 1.975f); retryButton = new MenuButton(retry, width - (retry.getWidth() / 2f), retryY); replayButton = new MenuButton(replay, width - (replay.getWidth() / 2f), replayY); retryButton.setHoverFade(); replayButton.setHoverFade(); }
Example 14
Source File: ButtonMenu.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Initializes the menu state. */ public void revalidate(Image button, Image buttonL, Image buttonR) { float baseY = getBaseY(); float offsetY = button.getHeight() * 1.25f; menuButtons = new MenuButton[buttons.length]; for (int i = 0; i < buttons.length; i++) { MenuButton b = new MenuButton(button, buttonL, buttonR, width2, baseY + (i * offsetY)); b.setText(String.format("%d. %s", i + 1, buttons[i].getText()), Fonts.XLARGE, Color.white); b.setHoverFade(); menuButtons[i] = b; } }
Example 15
Source File: TextureData.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
public TextureData(Image image) { this.image = image; this.width = image.getWidth(); this.height = image.getHeight(); this.width2 = this.width / 2f; this.height2 = this.height / 2f; Texture text = image.getTexture(); this.id = text.getTextureID(); this.txtw = text.getWidth(); this.txth = text.getHeight(); }
Example 16
Source File: Spinner.java From opsu with GNU General Public License v3.0 | 4 votes |
@Override public void draw(Graphics g, int trackPosition) { // only draw spinners shortly before start time int timeDiff = hitObject.getTime() - trackPosition; final int fadeInTime = game.getFadeInTime(); if (timeDiff - fadeInTime > 0) return; boolean spinnerComplete = (rotations >= rotationsNeeded); float alpha = Utils.clamp(1 - (float) timeDiff / fadeInTime, 0f, 1f); // darken screen if (Options.getSkin().isSpinnerFadePlayfield()) { float oldAlpha = Colors.BLACK_ALPHA.a; if (timeDiff > 0) Colors.BLACK_ALPHA.a *= alpha; g.setColor(Colors.BLACK_ALPHA); g.fillRect(0, 0, width, height); Colors.BLACK_ALPHA.a = oldAlpha; } // rpm Image rpmImg = GameImage.SPINNER_RPM.getImage(); rpmImg.setAlpha(alpha); rpmImg.drawCentered(width / 2f, height - rpmImg.getHeight() / 2f); if (timeDiff < 0) data.drawSymbolString(Integer.toString(drawnRPM), (width + rpmImg.getWidth() * 0.95f) / 2f, height - data.getScoreSymbolImage('0').getHeight() * 1.025f, 1f, 1f, true); // spinner meter (subimage) Image spinnerMetre = GameImage.SPINNER_METRE.getImage(); int spinnerMetreY = (spinnerComplete) ? 0 : (int) (spinnerMetre.getHeight() * (1 - (rotations / rotationsNeeded))); Image spinnerMetreSub = spinnerMetre.getSubImage( 0, spinnerMetreY, spinnerMetre.getWidth(), spinnerMetre.getHeight() - spinnerMetreY ); spinnerMetreSub.setAlpha(alpha); spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight()); // main spinner elements GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha); GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f); GameImage.SPINNER_CIRCLE.getImage().drawCentered(width / 2, height / 2); if (!GameMod.HIDDEN.isActive()) { float approachScale = 1 - Utils.clamp(((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f); Image approachCircleScaled = GameImage.SPINNER_APPROACHCIRCLE.getImage().getScaledCopy(approachScale); approachCircleScaled.setAlpha(alpha); approachCircleScaled.drawCentered(width / 2, height / 2); } GameImage.SPINNER_SPIN.getImage().setAlpha(alpha); GameImage.SPINNER_SPIN.getImage().drawCentered(width / 2, height * 3 / 4); if (spinnerComplete) { GameImage.SPINNER_CLEAR.getImage().drawCentered(width / 2, height / 4); int extraRotations = (int) (rotations - rotationsNeeded); if (extraRotations > 0) data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1f, 1f); } }
Example 17
Source File: TGAWriter.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.imageout.ImageWriter#saveImage(org.newdawn.slick.Image, java.lang.String, java.io.OutputStream, boolean) */ public void saveImage(Image image, String format, OutputStream output, boolean writeAlpha) throws IOException { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(output)); // ID Length out.writeByte((byte) 0); // Color Map out.writeByte((byte) 0); // Image Type out.writeByte((byte) 2); // Color Map - Ignored out.writeShort(flipEndian((short) 0)); out.writeShort(flipEndian((short) 0)); out.writeByte((byte) 0); // X, Y Offset out.writeShort(flipEndian((short) 0)); out.writeShort(flipEndian((short) 0)); // Width, Height, Depth out.writeShort(flipEndian((short) image.getWidth())); out.writeShort(flipEndian((short) image.getHeight())); if (writeAlpha) { out.writeByte((byte) 32); // Image Descriptor (can't be 0 since we're using 32-bit TGAs) // needs to not have 0x20 set to indicate it's not a flipped image out.writeByte((byte) 1); } else { out.writeByte((byte) 24); // Image Descriptor (must be 0 since we're using 24-bit TGAs) // needs to not have 0x20 set to indicate it's not a flipped image out.writeByte((byte) 0); } // Write out the image data Color c; for (int y = image.getHeight()-1; y <= 0; y--) { for (int x = 0; x < image.getWidth(); x++) { c = image.getColor(x, y); out.writeByte((byte) (c.b * 255.0f)); out.writeByte((byte) (c.g * 255.0f)); out.writeByte((byte) (c.r * 255.0f)); if (writeAlpha) { out.writeByte((byte) (c.a * 255.0f)); } } } out.close(); }
Example 18
Source File: MenuButton.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * Draw the button with a color filter at the given scale. * @param filter the color to filter with when drawing * @param scaleOverride the scale to use when drawing (only works for normal images) */ @SuppressWarnings("deprecation") public void draw(Color filter, float scaleOverride) { // animations: get current frame Image image = this.img; if (image == null) { anim.updateNoDraw(); image = anim.getCurrentFrame(); } // normal images if (imgL == null) { float xScaleOffset = 0f, yScaleOffset = 0f; if (scaleOverride != 1f) { image = image.getScaledCopy(scaleOverride); xScaleOffset = image.getWidth() / 2f - xRadius; yScaleOffset = image.getHeight() / 2f - yRadius; } lastScale = scaleOverride; if (hoverEffect == 0) image.draw(x - xRadius, y - yRadius, filter); else { float oldAlpha = image.getAlpha(); float oldAngle = image.getRotation(); if ((hoverEffect & EFFECT_EXPAND) > 0) { if (scale.getValue() != 1f) { image = image.getScaledCopy(scale.getValue()); image.setAlpha(oldAlpha); if (scaleOverride != 1f) { xScaleOffset = image.getWidth() / 2f - xRadius; yScaleOffset = image.getHeight() / 2f - yRadius; } lastScale *= scale.getValue(); } } if ((hoverEffect & EFFECT_FADE) > 0) image.setAlpha(alpha.getValue()); if ((hoverEffect & EFFECT_ROTATE) > 0) image.setRotation(angle.getValue()); image.draw(x - xRadius - xScaleOffset, y - yRadius - yScaleOffset, filter); if (image == this.img) { image.setAlpha(oldAlpha); image.setRotation(oldAngle); } } } // 3-part images else { if (hoverEffect == 0) { image.draw(x - xRadius + imgL.getWidth(), y - yRadius, filter); imgL.draw(x - xRadius, y - yRadius, filter); imgR.draw(x + xRadius - imgR.getWidth(), y - yRadius, filter); } else if ((hoverEffect & EFFECT_FADE) > 0) { float a = image.getAlpha(), aL = imgL.getAlpha(), aR = imgR.getAlpha(); float currentAlpha = alpha.getValue(); image.setAlpha(currentAlpha); imgL.setAlpha(currentAlpha); imgR.setAlpha(currentAlpha); image.draw(x - xRadius + imgL.getWidth(), y - yRadius, filter); imgL.draw(x - xRadius, y - yRadius, filter); imgR.draw(x + xRadius - imgR.getWidth(), y - yRadius, filter); image.setAlpha(a); imgL.setAlpha(aL); imgR.setAlpha(aR); } } // text if (text != null) font.drawString(x - font.getWidth(text) / 2f, y - font.getLineHeight() / 2f, text, color); }
Example 19
Source File: BeatmapSetNode.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * Draws the button. * @param x the x coordinate * @param y the y coordinate * @param grade the highest grade, if any * @param focus true if this is the focused node */ public void draw(float x, float y, Grade grade, boolean focus) { Image bg = GameImage.MENU_BUTTON_BG.getImage(); boolean expanded = (beatmapIndex > -1); Beatmap beatmap = beatmapSet.get(expanded ? beatmapIndex : 0); bg.setAlpha(0.9f); Color bgColor; Color textColor = Options.getSkin().getSongSelectInactiveTextColor(); // get drawing parameters if (expanded) { x -= bg.getWidth() / 10f; if (focus) { bgColor = Color.white; textColor = Options.getSkin().getSongSelectActiveTextColor(); } else bgColor = Colors.BLUE_BUTTON; } else if (beatmapSet.isPlayed()) bgColor = Colors.ORANGE_BUTTON; else bgColor = Colors.PINK_BUTTON; bg.draw(x, y, bgColor); float cx = x + (bg.getWidth() * 0.043f); float cy = y + (bg.getHeight() * 0.18f) - 3; // draw grade if (grade != Grade.NULL) { Image gradeImg = grade.getMenuImage(); gradeImg.drawCentered(cx - bg.getWidth() * 0.01f + gradeImg.getWidth() / 2f, y + bg.getHeight() / 2.2f); cx += gradeImg.getWidth(); } // draw text if (Options.useUnicodeMetadata()) { // load glyphs Fonts.loadGlyphs(Fonts.MEDIUM, beatmap.titleUnicode); Fonts.loadGlyphs(Fonts.DEFAULT, beatmap.artistUnicode); } Fonts.MEDIUM.drawString(cx, cy, beatmap.getTitle(), textColor); Fonts.DEFAULT.drawString(cx, cy + Fonts.MEDIUM.getLineHeight() - 3, String.format("%s // %s", beatmap.getArtist(), beatmap.creator), textColor); if (expanded || beatmapSet.size() == 1) Fonts.BOLD.drawString(cx, cy + Fonts.MEDIUM.getLineHeight() + Fonts.DEFAULT.getLineHeight() - 6, beatmap.version, textColor); // draw stars // (note: in osu!, stars are also drawn for beatmap sets of size 1) if (expanded) { if (beatmap.starRating >= 0) { Image star = GameImage.STAR.getImage(); float starOffset = star.getWidth() * 1.25f; float starX = cx + starOffset * 0.02f; float starY = cy + Fonts.MEDIUM.getLineHeight() + Fonts.DEFAULT.getLineHeight() * 2 - 6f * GameImage.getUIscale(); float starCenterY = starY + star.getHeight() / 2f; final float baseAlpha = focus ? 1f : 0.8f; final float smallStarScale = 0.4f; final int maxStars = 10; star.setAlpha(baseAlpha); int i = 1; for (; i < beatmap.starRating && i <= maxStars; i++) { if (focus) star.drawFlash(starX + (i - 1) * starOffset, starY, star.getWidth(), star.getHeight(), textColor); else star.draw(starX + (i - 1) * starOffset, starY); } if (i <= maxStars) { float partialStarScale = smallStarScale + (float) (beatmap.starRating - i + 1) * (1f - smallStarScale); Image partialStar = star.getScaledCopy(partialStarScale); partialStar.setAlpha(baseAlpha); float partialStarY = starCenterY - partialStar.getHeight() / 2f; if (focus) partialStar.drawFlash(starX + (i - 1) * starOffset, partialStarY, partialStar.getWidth(), partialStar.getHeight(), textColor); else partialStar.draw(starX + (i - 1) * starOffset, partialStarY); } if (++i <= maxStars) { Image smallStar = star.getScaledCopy(smallStarScale); smallStar.setAlpha(0.5f); float smallStarY = starCenterY - smallStar.getHeight() / 2f; for (; i <= maxStars; i++) smallStar.draw(starX + (i - 1) * starOffset, smallStarY); } } } }
Example 20
Source File: MouseOverArea.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Create a new mouse over area * * @param container * The container displaying the mouse over area * @param image * The normalImage to display * @param x * The position of the area * @param y * the position of the area */ public MouseOverArea(GUIContext container, Image image, int x, int y) { this(container, image, x, y, image.getWidth(), image.getHeight()); }