/** * Draws a radial gradient in the given coordinates with the given colors, doesn't take alpha into * consideration when drawing the gradient. Notice that this method differs from * fillRadialGradient since it draws a square gradient at all times and can thus be cached Notice * that a radial gradient will result in a circular shape, to create a square use fillRect or draw * a larger shape and clip to the appropriate size. * * @param startColor the starting RGB color * @param endColor the ending RGB color * @param x the x coordinate * @param y the y coordinate * @param width the width of the region to be filled * @param height the height of the region to be filled * @param relativeX indicates the relative position of the gradient within the drawing region * @param relativeY indicates the relative position of the gradient within the drawing region * @param relativeSize indicates the relative size of the gradient within the drawing region */ public void fillRectRadialGradient( int startColor, int endColor, int x, int y, int width, int height, float relativeX, float relativeY, float relativeSize) { // people do that a lot sadly... if (startColor == endColor) { setColor(startColor); fillRect(x, y, width, height, (byte) 0xff); return; } impl.fillRectRadialGradient( nativeGraphics, startColor, endColor, x + xTranslate, y + yTranslate, width, height, relativeX, relativeY, relativeSize); }
/** * Makes the current color slightly lighter, this is useful for many visual effects * * @param factor the degree of lightening a color per channel a number from 1 to 255 */ public void lighterColor(int factor) { int color = getColor(); int r = color >> 16 & 0xff; int g = color >> 8 & 0xff; int b = color & 0xff; r = Math.min(0xff, r + factor); g = Math.min(0xff, g + factor); b = Math.min(0xff, b + factor); setColor(((r << 16) & 0xff0000) | ((g << 8) & 0xff00) | (b & 0xff)); }
/** * Makes the current color slightly darker, this is useful for many visual effects * * @param factor the degree of lightening a color per channel a number from 1 to 255 */ public void darkerColor(int factor) { int color = getColor(); int r = color >> 16 & 0xff; int g = color >> 8 & 0xff; int b = color & 0xff; r = Math.max(0, r - factor); g = Math.max(0, g - factor); b = Math.max(0, b - factor); setColor(((r << 16) & 0xff0000) | ((g << 8) & 0xff00) | (b & 0xff)); }
/** Invoke this to restore Codename One's graphics settings into the native graphics */ public void endNativeGraphicsAccess() { translate( ((Integer) nativeGraphicsState[0]).intValue(), ((Integer) nativeGraphicsState[1]).intValue()); setColor(((Integer) nativeGraphicsState[2]).intValue()); setAlpha(((Integer) nativeGraphicsState[3]).intValue()); setClip( ((Integer) nativeGraphicsState[4]).intValue(), ((Integer) nativeGraphicsState[5]).intValue(), ((Integer) nativeGraphicsState[6]).intValue(), ((Integer) nativeGraphicsState[7]).intValue()); setAntiAliased(((Boolean) nativeGraphicsState[8]).booleanValue()); setAntiAliasedText(((Boolean) nativeGraphicsState[9]).booleanValue()); nativeGraphicsState = null; }
/** * Draws a linear gradient in the given coordinates with the given colors, doesn't take alpha into * consideration when drawing the gradient * * @param startColor the starting RGB color * @param endColor the ending RGB color * @param x the x coordinate * @param y the y coordinate * @param width the width of the region to be filled * @param height the height of the region to be filled * @param horizontal indicating wheter it is a horizontal fill or vertical */ public void fillLinearGradient( int startColor, int endColor, int x, int y, int width, int height, boolean horizontal) { // people do that a lot sadly... if (startColor == endColor) { setColor(startColor); fillRect(x, y, width, height, (byte) 0xff); return; } impl.fillLinearGradient( nativeGraphics, startColor, endColor, x + xTranslate, y + yTranslate, width, height, horizontal); }