/** * Примечание: по умолчанию метод возвращает белый цвет. * * @param color Цвет из нашего кастомного enum * @return Color, с которым работает LWJGL */ private Color convertColor(TpReadableColor color) { switch (color){ case RED: return new Color(ReadableColor.RED); case GREEN: return new Color(ReadableColor.GREEN); case BLUE: return new Color(ReadableColor.BLUE); case AQUA: return new Color(ReadableColor.CYAN); case YELLOW: return new Color(ReadableColor.YELLOW); case ORANGE: return new Color(ReadableColor.ORANGE); case PURPLE: return new Color(ReadableColor.PURPLE); case BLACK: return new Color(ReadableColor.BLACK); default: return new Color(ReadableColor.WHITE); } }
@Override public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { super.draw(renderer, size, renderInfo); int color = 0xe0e0e0; if (!isEnabled()) { color = 0xa0a0a0; } int boxSize = size.getHeight(); renderer.drawRect(0, 0, boxSize, boxSize, ReadableColor.BLACK); renderer.drawRect(1, 1, boxSize - 2, boxSize - 2, BOX_BACKGROUND_COLOR); if(isChecked()) { renderer.drawCenteredString(boxSize / 2 + 1, 1, color, "x", true); } renderer.drawString(boxSize + 2, 2, color, label); }
@Override public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { super.draw(renderer, size, renderInfo); FontRenderer fontRenderer = getMinecraft().fontRendererObj; int width = size.getWidth(); int height = size.getHeight(); int barTotalWidth = width - 2 * BORDER; int barDoneWidth = (int) (barTotalWidth * progress); renderer.drawRect(0, 0, width, height, ReadableColor.BLACK); // Border renderer.drawRect(BORDER, BORDER, barTotalWidth, height - 2 * BORDER, ReadableColor.WHITE); // Background renderer.drawRect(BORDER, BORDER, barDoneWidth, height - 2 * BORDER, ReadableColor.GREY); // Progress String text = String.format(label, (int)(progress * 100)); renderer.drawCenteredString(width / 2, size.getHeight() / 2 - fontRenderer.FONT_HEIGHT / 2, ReadableColor.BLACK, text); }
private static void initColorMap(IntBuffer colorMap, int stepSize, ReadableColor... colors) { for ( int n = 0; n < colors.length - 1; n++ ) { ReadableColor color = colors[n]; int r0 = color.getRed(); int g0 = color.getGreen(); int b0 = color.getBlue(); color = colors[n + 1]; int r1 = color.getRed(); int g1 = color.getGreen(); int b1 = color.getBlue(); int deltaR = r1 - r0; int deltaG = g1 - g0; int deltaB = b1 - b0; for ( int step = 0; step < stepSize; step++ ) { float alpha = (float)step / (stepSize - 1); int r = (int)(r0 + alpha * deltaR); int g = (int)(g0 + alpha * deltaG); int b = (int)(b0 + alpha * deltaB); colorMap.put((r << 0) | (g << 8) | (b << 16)); } } }
@Override protected void drawShape() { GL11.glBegin(GL11.GL_LINE_LOOP); GL11.glVertex2f(-width, -height); GL11.glVertex2f(+width, -height); GL11.glVertex2f(+width, +height); GL11.glVertex2f(-width, +height); GL11.glEnd(); final ReadableColor color = getColor(); if (nonNull(color)) { GL11.glColor4f(color.getRed(), color.getGreen(), color.getBlue(), HALF); } GL11.glBegin(GL11.GL_POLYGON); GL11.glVertex2f(-width, -height); GL11.glVertex2f(+width, -height); GL11.glVertex2f(+width, +height); GL11.glVertex2f(-width, +height); GL11.glEnd(); }
public void create(final float breadth, final float borderWidth, final float borderHeight) { final FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = BORDER_WALL_DENSITY; fixtureDef.friction = BORDER_WALL_FRICTION; fixtureDef.restitution = BORDER_WALL_RESTITUTION; bamScene.getBamSceneCreator().addShape( new CreateNewRectangleRequest(fixtureDef, ReadableColor.YELLOW, borderWidth, breadth), new Vec2(0, borderHeight), BodyType.STATIC); bamScene.getBamSceneCreator().addShape( new CreateNewRectangleRequest(fixtureDef, ReadableColor.YELLOW, borderWidth, breadth), new Vec2(0, 0), BodyType.STATIC); bamScene.getBamSceneCreator().addShape( new CreateNewRectangleRequest(fixtureDef, ReadableColor.YELLOW, breadth, borderHeight), new Vec2(0, 0), BodyType.STATIC); bamScene.getBamSceneCreator().addShape( new CreateNewRectangleRequest(fixtureDef, ReadableColor.YELLOW, breadth, borderHeight), new Vec2(borderWidth, 0), BodyType.STATIC); }
public void setVerticalGradient(ReadableColor col1, ReadableColor col2) { ReadableColor[] cols = new ReadableColor[9]; cols[0] = col1; cols[1] = col1; cols[2] = col1; cols[6] = col2; cols[7] = col2; cols[8] = col2; Color inter = ColorInterpolator.interpolate(col1, col2, .5f); cols[3] = inter; cols[4] = inter; cols[5] = inter; setColors(cols); }
public void setCentralGradient(ReadableColor col1, ReadableColor col2) { ReadableColor[] cols = new ReadableColor[9]; cols[4] = col1; cols[0] = col2; cols[2] = col2; cols[6] = col2; cols[8] = col2; // ~1/sqrt(2), the factor to adjust the colors by to produce a circular pattern. Color temp = ColorInterpolator.interpolate(col1, col2, .707107f); cols[1] = temp; cols[3] = temp; cols[5] = temp; cols[7] = temp; setColors(cols); }
public void setHorizontalGradient(ReadableColor col1, ReadableColor col2) { ReadableColor[] cols = new ReadableColor[9]; cols[0] = col1; cols[3] = col1; cols[6] = col1; cols[1] = col2; cols[4] = col2; cols[7] = col2; Color inter = ColorInterpolator.interpolate(col1, col2, .5f); cols[2] = inter; cols[5] = inter; cols[8] = inter; setColors(cols); }
/** * Interpolates between the given {@link Color}s according to the given * amount. The amount should be between 0 and 1, all other numbers are produce * undefined results. * * @param col1 The first {@link Color} in the interpolation. * @param col2 The second {@link Color} in the interpolation. * @param amt The amount to interpolate. * @param out The {@link Color} to store the output in. * @return The interpolated {@link Color}. */ public static Color interpolate(ReadableColor col1, ReadableColor col2, float amt, Color out) { int num = (int) (col1.getAlpha() * (1 - amt) + col2.getAlpha() * amt); out.setAlpha(num); num = (int) (col1.getRed()* (1 - amt) + col2.getRed() * amt); out.setRed(num); num = (int) (col1.getGreen()* (1 - amt) + col2.getGreen() * amt); out.setGreen(num); num = (int) (col1.getBlue()* (1 - amt) + col2.getBlue() * amt); out.setBlue(num); return out; }
@Override public void setValue(double value, ReadableColor color) { if (color == null) { if (value < 50) if (value < 25) color = ReadableColor.RED; else color = ReadableColor.YELLOW; else color = ReadableColor.GREEN; } super.setValue(value, color); }
private void createCheckerTexture(final ReadableColor a, final ReadableColor b, final int size) { int i = 0; for ( int y = 0; y < HEIGHT; y++ ) { for ( int x = 0; x < WIDTH; x++ ) { ReadableColor c = (x / size) % 2 == 0 ? ((y / size) % 2 == 0 ? a : b) : ((y / size) % 2 == 0 ? b : a); texture.put(i + 0, c.getRedByte()); texture.put(i + 1, c.getGreenByte()); texture.put(i + 2, c.getBlueByte()); i += 3; } } }
private void createGradientTexture(final ReadableColor a, final ReadableColor b) { float l = 0.0f; int i = 0; for ( int y = 0; y < HEIGHT; y++ ) { for ( int x = 0; x < WIDTH; x++ ) { texture.put(i + 0, lerp(a.getRed(), b.getRed(), l)); texture.put(i + 1, lerp(a.getGreen(), b.getGreen(), l)); texture.put(i + 2, lerp(a.getBlue(), b.getBlue(), l)); i += 3; } l += (1.0f / (HEIGHT - 1)); } }
public void draw() { GL11.glLoadIdentity(); GL11.glTranslatef(getXPos(), getYPos(), 0); final float angle = body.getAngle() * ANGLE_TO_RAD_COEFFICIENT; GL11.glRotatef(angle, 0, 0, 1); ReadableColor color1 = nonNull(color) ? color : ReadableColor.WHITE; GL11.glColor3f(color1.getRed(), color1.getGreen(), color1.getBlue()); GL11.glDisable(GL11.GL_TEXTURE_2D); this.drawShape(); }
public Circle(Body body, FixtureDef fixtureDef, ReadableColor color, float radius) { super(body, fixtureDef, color); this.radius = radius; int initEdges = (int) (radius / FACTOR_FOUR); this.numberOfEdges = initEdges < MINIMUM_EDGES_NUMBER ? MINIMUM_EDGES_NUMBER : initEdges; this.x = new float[numberOfEdges]; this.y = new float[numberOfEdges]; this.tx = new float[numberOfEdges]; this.ty = new float[numberOfEdges]; this.init(); }
@Override protected void drawShape() { GL11.glPointSize(FACTOR_FOUR); GL11.glBegin(GL11.GL_POINTS); GL11.glVertex2f(0, 0); GL11.glVertex2f(0, radius); GL11.glEnd(); GL11.glBegin(GL11.GL_LINE_LOOP); GL11.glVertex2f(0, 0); GL11.glVertex2f(0, radius); GL11.glEnd(); GL11.glBegin(GL11.GL_LINE_LOOP); for (int index = 0; index < numberOfEdges; ++index) { GL11.glVertex2f(x[index], y[index]); } GL11.glEnd(); final ReadableColor color = getColor(); GL11.glBegin(GL11.GL_POLYGON); if (nonNull(color)) { GL11.glColor4f(color.getRed(), color.getGreen(), color.getBlue(), HALF); } for (int index = 0; index < numberOfEdges; ++index) { GL11.glVertex2f(x[index], y[index]); } GL11.glEnd(); }
public void setColor(ReadableColor color) { for(int i = 0; i < 9; i++) { color.writeARGB(colors); } colors.flip(); }
public void setGradient(ReadableColor color1, ReadableColor color2, GradientType type) { switch(type) { case vertical: setVerticalGradient(color1, color2); break; case horizontal: setHorizontalGradient(color1, color2); break; case center: setCentralGradient(color1, color2); break; } }
public void setColors(ReadableColor[] cols) { if(cols.length != 9) { throw new IllegalArgumentException(); } for(ReadableColor c : cols) { c.writeARGB(colors); } }
/** * Löscht die Farbe des Bildes und ersetzt sie durch die angegebene Farbe. * @param color */ public void clear(ReadableColor color) { setColor(color); int temp = blendMode; setBlendMode(COMPOSITE_ABSOLUT); drawRect(0, 0, rect.width, rect.height, true); setBlendMode(temp); }
public static void setColor(ReadableColor color) { if (GLCache.color.equals(color)) return; GLCache.color = color; glColor4f(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); }
public static void setColor(ReadableColor color, int alpha) { Color c = new Color(color); c.setAlpha(alpha); setColor(c); }