org.newdawn.slick.Font Java Examples
The following examples show how to use
org.newdawn.slick.Font.
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: VolumeControl.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
private Dial( String name, NumericOption option, Font numberFont, float textxoff, float textyoff) { this.name = name; this.option = option; this.numberFont = numberFont; this.textxoff = textxoff; this.textyoff = textyoff; final float value = option.val / 100f; this.val = new AnimatedValue(VALUE_ANIMATION_TIME, value, value, LINEAR); }
Example #2
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Calculates and returns the width of a single justified space for the * given {@link String}, in pixels. * * @param font The font to draw with * @param s * The given non-null {@link String} to use to calculate the * width of a space for. * @param leftWidth * The integer specifying the left width buffer to use to * calculate how much space a space should take up in * justification. * @return The width of a single justified space for the given * {@link String}, in pixels. */ private static int calculateWidthOfJustifiedSpaceInPixels(final Font font, final String s, final int leftWidth) { int space = 0; // hold total space; hold space width in pixel int curpos = 0; // current string position // count total space while (curpos < s.length()) { if (s.charAt(curpos++) == ' ') { space++; } } if (space > 0) { // width left plus with total space // space width (in pixel) = width left / total space space = (leftWidth + (font.getWidth(" ") * space)) / space; } return space; }
Example #3
Source File: SimpleButton.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
public SimpleButton(int x, int y, int width, int height, Font font, String text, Color bg, Color fg, Color border, Color hoverBorder) { this.bg = bg; this.fg = fg; this.border = border; this.hoverBorder = hoverBorder; this.hitbox = new Rectangle(x, y, width, height); this.font = font; this.text = text; this.textY = y + (height - font.getLineHeight()) / 2; }
Example #4
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 #5
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Draw a string * * @param font The font to draw with * @param s The text to draw * @param alignment The alignment to apply * @param x The x location to draw at * @param y The y location to draw at * @param width The width to fill with the string * @param color The color to draw in * @return The final x coordinate of the text */ public static final int drawString(Font font, final String s, final int alignment, final int x, final int y, final int width, Color color) { int resultingXCoordinate = 0; if (alignment == Alignment.LEFT) { font.drawString(x, y, s, color); } else if (alignment == Alignment.CENTER) { font.drawString(x + (width / 2) - (font.getWidth(s) / 2), y, s, color); } else if (alignment == Alignment.RIGHT) { font.drawString(x + width - font.getWidth(s), y, s, color); } else if (alignment == Alignment.JUSTIFY) { // calculate left width int leftWidth = width - font.getWidth(s); if (leftWidth <= 0) { // no width left, use standard draw string font.drawString(x, y, s, color); } return FontUtils.drawJustifiedSpaceSeparatedSubstrings(font, s, x, y, FontUtils.calculateWidthOfJustifiedSpaceInPixels(font, s, leftWidth)); } return resultingXCoordinate; }
Example #6
Source File: FontUtil.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
public static void drawCentered(Font font, int width, int xoffset, int y, String text, Color color) { int x = (width - font.getWidth(text)) / 2; font.drawString(x + xoffset, y, text, color); }
Example #7
Source File: FontUtil.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
public static void drawRightAligned(Font font, int width, int xoffset, int y, String text, Color color) { int x = width - font.getWidth(text); font.drawString(x + xoffset, y, text, color); }
Example #8
Source File: DropdownMenu.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
@Override public void render(Graphics g) { int delta = renderDelta; // update animation expandProgress.update((expanded) ? delta : -delta * 2); // get parameters int idx = getIndexAt(mouseY); float t = expandProgress.getValue(); if (expanded) { t = AnimationEquation.OUT_CUBIC.calc(t); } // background and border Color oldGColor = g.getColor(); float oldLineWidth = g.getLineWidth(); final int cornerRadius = 6; g.setLineWidth(1f); g.setColor((idx == -1) ? highlightColor : backgroundColor); g.fillRoundRect(x, y, width, baseHeight, cornerRadius); g.setColor(borderColor); g.drawRoundRect(x, y, width, baseHeight, cornerRadius); if (expanded || t >= 0.0001) { float oldBackgroundAlpha = backgroundColor.a; backgroundColor.a *= t; g.setColor(backgroundColor); g.fillRoundRect(x, y + offsetY, width, (height - offsetY) * t, cornerRadius); backgroundColor.a = oldBackgroundAlpha; } if (idx >= 0 && t >= 0.9999) { g.setColor(highlightColor); float yPos = y + offsetY + (offsetY * idx); int yOff = 0, hOff = 0; if (idx == 0 || idx == items.length - 1) { g.fillRoundRect(x, yPos, width, offsetY, cornerRadius); if (idx == 0) yOff = cornerRadius; hOff = cornerRadius; } g.fillRect(x, yPos + yOff, width, offsetY - hOff); } g.setColor(oldGColor); g.setLineWidth(oldLineWidth); // text chevronDown.draw(x + width - chevronDown.getWidth() - width * CHEVRON_X, y + (baseHeight - chevronDown.getHeight()) / 2f, chevronDownColor); fontNormal.drawString(x + (width * 0.03f), y + (fontNormal.getPaddingTop() + fontNormal.getPaddingBottom()) / 2f, itemNames[selectedItemIndex], textColor); float oldTextAlpha = textColor.a; textColor.a *= t; if (expanded || t >= 0.0001) { for (int i = 0; i < itemNames.length; i++) { Font f = (i == selectedItemIndex) ? fontSelected : fontNormal; if (i == idx && t >= 0.999) chevronRight.draw(x, y + offsetY + (offsetY * i) + (offsetY - chevronRight.getHeight()) / 2f, chevronRightColor); f.drawString(x + chevronRight.getWidth(), y + offsetY + (offsetY * i * t), itemNames[i], textColor); } } textColor.a = oldTextAlpha; }
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: 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 #11
Source File: DropdownMenu.java From opsu with GNU General Public License v3.0 | 4 votes |
@Override public void render(GUIContext container, Graphics g) throws SlickException { // update animation long time = container.getTime(); if (lastUpdateTime > 0) { int delta = (int) (time - lastUpdateTime); expandProgress.update((expanded) ? delta : -delta * 2); } this.lastUpdateTime = time; // get parameters Input input = container.getInput(); int idx = getIndexAt(input.getMouseX(), input.getMouseY()); float t = expandProgress.getValue(); if (expanded) t = AnimationEquation.OUT_CUBIC.calc(t); // background and border Color oldGColor = g.getColor(); float oldLineWidth = g.getLineWidth(); final int cornerRadius = 6; g.setLineWidth(1f); g.setColor((idx == -1) ? highlightColor : backgroundColor); g.fillRoundRect((int) x, (int) y, width, baseHeight, cornerRadius); g.setColor(borderColor); g.drawRoundRect((int) x, (int) y, width, baseHeight, cornerRadius); if (expanded || t >= 0.0001) { float oldBackgroundAlpha = backgroundColor.a; backgroundColor.a *= t; g.setColor(backgroundColor); g.fillRoundRect((int) x, (int) (y + offsetY), width, (height - offsetY) * t, cornerRadius); backgroundColor.a = oldBackgroundAlpha; } if (idx >= 0 && t >= 0.9999) { g.setColor(highlightColor); float yPos = y + offsetY + (offsetY * idx); int yOff = 0, hOff = 0; if (idx == 0 || idx == items.length - 1) { g.fillRoundRect((int) x, (int) yPos, width, offsetY, cornerRadius); if (idx == 0) yOff = cornerRadius; hOff = cornerRadius; } g.fillRect((int) x, (int) (yPos + yOff), width, offsetY - hOff); } g.setColor(oldGColor); g.setLineWidth(oldLineWidth); // text chevronDown.draw(x + width - chevronDown.getWidth() - width * CHEVRON_X, y + (baseHeight - chevronDown.getHeight()) / 2f, chevronDownColor); fontNormal.drawString(x + (width * 0.03f), y + (fontNormal.getPaddingTop() + fontNormal.getPaddingBottom()) / 2f, itemNames[itemIndex], textColor); float oldTextAlpha = textColor.a; textColor.a *= t; if (expanded || t >= 0.0001) { for (int i = 0; i < itemNames.length; i++) { Font f = (i == itemIndex) ? fontSelected : fontNormal; if (i == idx && t >= 0.999) chevronRight.draw(x, y + offsetY + (offsetY * i) + (offsetY - chevronRight.getHeight()) / 2f, chevronRightColor); f.drawString(x + chevronRight.getWidth(), y + offsetY + (offsetY * i * t), itemNames[i], textColor); } } textColor.a = oldTextAlpha; }
Example #12
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Draws justified-space separated substrings based on the given * {@link String} and the given starting x and y coordinates to the given * {@link Graphics2D} instance. * * @param font * The font to draw with * @param s * The non-null {@link String} to draw as space-separated * substrings. * @param x * The given starting x-coordinate position to use to draw the * {@link String}. * @param y * The given starting y-coordinate position to use to draw the * {@link String}. * @param justifiedSpaceWidth * The integer specifying the width of a justified space * {@link String}, in pixels. * @return The resulting x-coordinate of the current cursor after the * drawing operation completes. * @throws NullPointerException * Throws a {@link NullPointerException} if any of the given * arguments are null. */ private static int drawJustifiedSpaceSeparatedSubstrings(Font font, final String s, final int x, final int y, final int justifiedSpaceWidth) { int curpos = 0; int endpos = 0; int resultingXCoordinate = x; while (curpos < s.length()) { endpos = s.indexOf(' ', curpos); // find space if (endpos == -1) { endpos = s.length(); // no space, draw all string directly } String substring = s.substring(curpos, endpos); font.drawString(resultingXCoordinate, y, substring); resultingXCoordinate += font.getWidth(substring) + justifiedSpaceWidth; // increase // x-coordinate curpos = endpos + 1; } return resultingXCoordinate; }
Example #13
Source File: TextField.java From opsu with GNU General Public License v3.0 | 3 votes |
/** * Create a new text field * * @param container * The container rendering this field * @param font * The font to use in the text field * @param x * The x coordinate of the top left corner of the text field * @param y * The y coordinate of the top left corner of the text field * @param width * The width of the text field * @param height * The height of the text field */ public TextField(GUIContext container, Font font, int x, int y, int width, int height) { super(container); this.font = font; setLocation(x, y); this.width = width; this.height = height; }
Example #14
Source File: TextField.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Create a new text field * * @param container * The container rendering this field * @param font * The font to use in the text field * @param x * The x coordinate of the top left corner of the text field * @param y * The y coordinate of the top left corner of the text field * @param width * The width of the text field * @param height * The height of the text field */ public TextField(GUIContext container, Font font, int x, int y, int width, int height) { super(container); this.font = font; setLocation(x, y); this.width = width; this.height = height; }
Example #15
Source File: GUIContext.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Get the default system font * * @return The default system font */ public Font getDefaultFont();
Example #16
Source File: TextField.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Create a new text field * * @param container * The container rendering this field * @param font * The font to use in the text field * @param x * The x coordinate of the top left corner of the text field * @param y * The y coordinate of the top left corner of the text field * @param width * The width of the text field * @param height * The height of the text field * @param listener * The listener to add to the text field */ public TextField(GUIContext container, Font font, int x, int y, int width, int height, ComponentListener listener) { this(container,font,x,y,width,height); addListener(listener); }
Example #17
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Draw text right justified * * @param font The font to draw with * @param s The string to draw * @param x The x location to draw at * @param y The y location to draw at * @param width The width to fill with the text * @param color The color to draw in */ public static void drawRight(Font font, String s, int x, int y, int width, Color color) { drawString(font, s, Alignment.RIGHT, x, y, width, color); }
Example #18
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Draw text right justified * * @param font The font to draw with * @param s The string to draw * @param x The x location to draw at * @param y The y location to draw at * @param width The width to fill with the text */ public static void drawRight(Font font, String s, int x, int y, int width) { drawString(font, s, Alignment.RIGHT, x, y, width, Color.white); }
Example #19
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Draw text center justified * * @param font The font to draw with * @param s The string to draw * @param x The x location to draw at * @param y The y location to draw at * @param width The width to fill with the text * @param color The color to draw in */ public static void drawCenter(Font font, String s, int x, int y, int width, Color color) { drawString(font, s, Alignment.CENTER, x, y, width, color); }
Example #20
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Draw text center justified * * @param font The font to draw with * @param s The string to draw * @param x The x location to draw at * @param y The y location to draw at * @param width The width to fill with the text */ public static void drawCenter(Font font, String s, int x, int y, int width) { drawString(font, s, Alignment.CENTER, x, y, width, Color.white); }
Example #21
Source File: FontUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Draw text left justified * * @param font The font to draw with * @param s The string to draw * @param x The x location to draw at * @param y The y location to draw at */ public static void drawLeft(Font font, String s, int x, int y) { drawString(font, s, Alignment.LEFT, x, y, 0, Color.white); }
Example #22
Source File: MenuButton.java From opsu with GNU General Public License v3.0 | 2 votes |
/** * Sets text to draw in the middle of the button. * @param text the text to draw * @param font the font to use when drawing * @param color the color to draw the text */ public void setText(String text, Font font, Color color) { this.text = text; this.font = font; this.color = color; }
Example #23
Source File: TextField.java From opsu with GNU General Public License v3.0 | 2 votes |
/** * Create a new text field * * @param container * The container rendering this field * @param font * The font to use in the text field * @param x * The x coordinate of the top left corner of the text field * @param y * The y coordinate of the top left corner of the text field * @param width * The width of the text field * @param height * The height of the text field * @param listener * The listener to add to the text field */ public TextField(GUIContext container, Font font, int x, int y, int width, int height, ComponentListener listener) { this(container,font,x,y,width,height); addListener(listener); }
Example #24
Source File: MenuButton.java From opsu-dance with GNU General Public License v3.0 | 2 votes |
/** * Sets text to draw in the middle of the button. * @param text the text to draw * @param font the font to use when drawing * @param color the color to draw the text */ public void setText(String text, Font font, Color color) { this.text = text; this.font = font; this.color = color; }