List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap
public Pixmap(byte[] encodedData, int offset, int len)
From source file:es.eucm.ead.editor.utils.ImageBorderTracer.java
License:Open Source License
public static Pixmap createSamplePixmap(int width, int height, Pixmap.Format fmt) { if (fmt == null) { fmt = Pixmap.Format.RGBA8888; }// w w w.j a va 2 s.c om Pixmap p = new Pixmap(width, height, fmt); p.setColor(Color.YELLOW); p.fillCircle(width / 4, height / 2, width / 5); p.fillCircle(width * 3 / 4, height / 2, width / 5); return p; }
From source file:es.eucm.ead.editor.view.builders.scene.draw.MeshHelper.java
License:Open Source License
/** * Saves the minimum amount of pixels that encapsulates the drawn image. * /* w w w . j a v a 2s . c o m*/ * @return */ Region save(FileHandle file) { Pixmap modifPixmap = this.currModifiedPixmap.pixmap; PNG writer = null; Pixmap savedPixmap = null; try { savedPixmap = new Pixmap(savedRegion.w, savedRegion.h, modifPixmap.getFormat()); savedPixmap.drawPixmap(modifPixmap, 0, 0, savedRegion.x, savedRegion.y, savedRegion.w, savedRegion.h); savedRegion.x += currModifiedPixmap.x; savedRegion.y += currModifiedPixmap.y; // Guess at deflated size. writer = new PNG((int) (savedPixmap.getWidth() * savedPixmap.getHeight() * 1.5f)); writer.setFlipY(true); writer.write(file, savedPixmap); } catch (IOException ex) { throw new GdxRuntimeException("Error writing PNG: " + file, ex); } finally { if (writer != null) { writer.dispose(); writer = null; } if (savedPixmap != null) { savedPixmap.dispose(); savedPixmap = null; } } return savedRegion; }
From source file:es.eucm.ead.editor.view.builders.scene.draw.MeshHelper.java
License:Open Source License
/** * Initializes the {@link #frameBuffer}, {@link #showingTexRegion} and * {@link #flusher} to the coordinates the the {@link Stage}, only if they * are null. This method should only be called in {@link #layout()}. If the * {@link Stage} size changed, the resources are translated via * {@link #translateResources(Actor)}./* www .j a v a 2 s .c om*/ */ public void initializeRenderingResources() { createShader(); createMesh(); this.recalculateMatrix = true; if (this.showingTexRegion == null) { this.showingTexRegion = new TextureRegion(); } float w = scaledView.getWidth(), h = scaledView.getHeight(); if (fbo == null) { fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); } showingTexRegion.setRegion(fbo.getColorBufferTexture()); clampMinX = 0f; clampMinY = 0f; clampMaxX = w; clampMaxY = h; scaledView.localToStageCoordinates(temp.set(0f, 0f)); int stageX = MathUtils.round(temp.x), stageY = MathUtils.round(temp.y), width = MathUtils.round(w), height = MathUtils.round(h); showingTexRegion.setRegion(stageX, stageY, width, height); showingTexRegion.flip(false, true); if (this.flusher.pixmap == null) { this.flusher.pixmap = new Pixmap(width, height, Format.RGBA8888); flusher.x = stageX; flusher.y = stageY; } }
From source file:es.eucm.ead.editor.view.scene.SimpleSceneViewer.java
License:Open Source License
private void initTextures() { Pixmap p = new Pixmap(10, 10, Pixmap.Format.RGBA8888); p.setColor(Color.GREEN);//from w w w.j a va2 s . c om p.fillCircle(5, 5, 4); p.setColor(Color.DARK_GRAY); p.drawCircle(5, 5, 4); circle = new Texture(p); p.dispose(); selectionMatrix.translate(-5f, -5.0f, 0f); p = new Pixmap(1, 5, Pixmap.Format.RGB888); vLine = new Texture(p); p.dispose(); p = new Pixmap(5, 1, Pixmap.Format.RGB888); hLine = new Texture(p); p.dispose(); }
From source file:es.eucm.ead.editor.view.widgets.draw.SlideColorPicker.java
License:Open Source License
/** * Generate the slider background./*from w ww . j av a2 s .c o m*/ */ public void initialize() { if (huePixmap == null) { int width = MathUtils.round(backgroundWidth()), height = MathUtils.round(backgroundHeight()); huePixmap = new Pixmap(width, height, Format.RGBA8888); saturationPixmap = new Pixmap(width, height, Format.RGBA8888); brightnessPixmap = new Pixmap(width, height, Format.RGBA8888); float saturation = 1f, brightness = 1f; int minWidth = getClearColorWidth(); int colorMaxPosition = width - minWidth; float colorWidth = width - minWidth * 2f; for (int i = minWidth; i < colorMaxPosition; ++i) { float percentageCompletion = (i - minWidth) / colorWidth; float[] rgb = HSBtoRGB(percentageCompletion, saturation, brightness, tempValues); drawColor(huePixmap, i, rgb[0], rgb[1], rgb[2], 1f); } hueTexture = new Texture(huePixmap); saturationTexture = new Texture(saturationPixmap); brightnessTexture = new Texture(brightnessPixmap); hueSlider.getStyle().background = new TextureRegionDrawable(new TextureRegion(hueTexture)); saturationSlider.getStyle().background = new TextureRegionDrawable( new TextureRegion(saturationTexture = new Texture(saturationPixmap))); brightnessSlider.getStyle().background = new TextureRegionDrawable( new TextureRegion(brightnessTexture)); invalidateHierarchy(); updateAllTexturesExcept(null); } }
From source file:es.eucm.ead.engine.assets.drawables.shapes.GdxBezierShape.java
License:Open Source License
protected Pixmap generatePixmap() { ArrayList<Float> shape = new ArrayList<Float>(); float x0, y0, x1, y1, x2, y2, x3, y3; EAdList<Integer> pointsList = descriptor.getPoints(); x0 = pointsList.get(0);//from w ww. jav a2s .c om y0 = pointsList.get(1); shape.add(x0); shape.add(y0); int pointIndex = 2; while (pointIndex < pointsList.size()) { int length = pointsList.get(pointIndex++); switch (length) { case 1: x1 = pointsList.get(pointIndex++); y1 = pointsList.get(pointIndex++); lineTo(x1, y1, shape); x0 = x1; y0 = y1; break; case 2: x1 = pointsList.get(pointIndex++); y1 = pointsList.get(pointIndex++); x2 = pointsList.get(pointIndex++); y2 = pointsList.get(pointIndex++); quadTo(x0, y0, x1, y1, x2, y2, shape); x0 = x2; y0 = y2; break; case 3: x1 = pointsList.get(pointIndex++); y1 = pointsList.get(pointIndex++); x2 = pointsList.get(pointIndex++); y2 = pointsList.get(pointIndex++); x3 = pointsList.get(pointIndex++); y3 = pointsList.get(pointIndex++); curveTo(x0, y0, x1, y1, x2, y2, x3, y3, shape); x0 = x3; y0 = y3; break; default: } } // TODO Probably this can be improved EAdPaint p = descriptor.getPaint(); if (p == null) { p = ColorFill.WHITE; } float f[] = new float[shape.size()]; for (int i = 0; i < shape.size(); i++) { f[i] = shape.get(i); } Polygon polygon = new Polygon(f); Rectangle rectangle = polygon.getBoundingRectangle(); int borderWidth = p.getBorderWidth(); int x = (int) rectangle.x; int y = (int) rectangle.y; int width = (int) (rectangle.x + rectangle.width); int height = (int) (rectangle.y + rectangle.height); Pixmap pixmap = new Pixmap(width + borderWidth * 2, height + borderWidth * 2, Pixmap.Format.RGBA8888); pixmapContains = new Pixmap(width + borderWidth * 2, height + borderWidth * 2, Pixmap.Format.RGBA8888); pixmapContains.setColor(0, 0, 0, 1); pixmap.setColor(0, 0, 0, 0); pixmap.fill(); if (p.getFill() instanceof ColorFill) { ColorFill c = (ColorFill) p.getFill(); pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f, c.getAlpha() / 255.0f); } else if (p.getFill() instanceof LinearGradientFill) { LinearGradientFill gradient = (LinearGradientFill) p.getFill(); usingGradient = true; this.initGradientParams(gradient.getColor1(), gradient.getX0(), gradient.getY0(), gradient.getColor2(), gradient.getX1(), gradient.getY1()); } else { pixmap.setColor(0, 0, 0, 1); } for (int i = x; i < width; i++) { for (int j = y; j < height; j++) { if (polygon.contains(i, j)) { if (usingGradient) { this.setColor(pixmap, borderWidth + i, borderWidth + j); } pixmap.drawPixel(borderWidth + i, borderWidth + j); pixmapContains.drawPixel(borderWidth + i, borderWidth + j); } } } usingGradient = false; if (p.getBorder() != null) { if (p.getBorder() instanceof ColorFill) { ColorFill c = (ColorFill) p.getBorder(); pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f, c.getAlpha() / 255.0f); } else if (p.getBorder() instanceof LinearGradientFill) { LinearGradientFill gradient = (LinearGradientFill) p.getBorder(); usingGradient = true; initGradientParams(gradient.getColor1(), gradient.getX0(), gradient.getY0(), gradient.getColor2(), gradient.getX1(), gradient.getY1()); } float previousX = 0; float previousY = 0; float currentX; float currentY; for (int k = 0; k < shape.size(); k += 2) { currentX = shape.get(k); currentY = shape.get(k + 1); if (k >= 2) { for (int i = 1; i <= borderWidth; i++) { if (usingGradient) { this.setColor(pixmap, (int) previousX + i, (int) previousY + i); } pixmap.drawLine((int) previousX + i, (int) previousY + i, (int) currentX + i, (int) currentY + i); pixmapContains.drawLine((int) previousX + i, (int) previousY + i, (int) currentX + i, (int) currentY + i); } } previousX = currentX; previousY = currentY; } for (int i = 1; i <= borderWidth; i++) { pixmap.drawLine((int) previousX + i, (int) previousY + i, (int) shape.get(0).intValue() + i, (int) shape.get(1).intValue() + i); pixmapContains.drawLine((int) previousX + i, (int) previousY + i, (int) shape.get(0).intValue() + i, (int) shape.get(1).intValue() + i); } } usingGradient = false; return pixmap; }
From source file:es.eucm.ead.engine.assets.drawables.shapes.GdxCircleShape.java
License:Open Source License
@Override protected Pixmap generatePixmap() { EAdPaint paint = descriptor.getPaint(); EAdFill fill = paint.getFill();// w w w. j a v a 2s. c o m EAdFill border = paint.getBorder(); int borderWidth = paint.getBorderWidth(); int size = descriptor.getRadius() * 2 + borderWidth * 2 + 1; int center = size / 2; Pixmap pixmap = new Pixmap(size, size, Pixmap.Format.RGBA8888); pixmapContains = new Pixmap(size, size, Pixmap.Format.RGBA8888); pixmapContains.setColor(0, 0, 0, 1); pixmapContains.fillCircle(center, center, descriptor.getRadius() + borderWidth); ColorFill c = ColorFill.TRANSPARENT; if (border != null) { if (border instanceof ColorFill) { c = (ColorFill) border; } else if (border instanceof LinearGradientFill) { LinearGradientFill l = (LinearGradientFill) border; c = l.getColor1(); } pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f, c.getAlpha() / 255.0f); pixmap.drawCircle(center, center, descriptor.getRadius() + borderWidth); } if (fill instanceof ColorFill) { c = (ColorFill) fill; pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f, c.getAlpha() / 255.0f); pixmap.fillCircle(center, center, descriptor.getRadius()); } else if (fill instanceof LinearGradientFill) { LinearGradientFill l = (LinearGradientFill) fill; initGradientParams(l.getColor1(), l.getX0(), l.getY0(), l.getColor2(), l.getX1(), l.getY1()); int size2 = descriptor.getRadius() * descriptor.getRadius(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { int s1 = (i - center); s1 = s1 * s1; int s2 = (j - center); s2 = s2 * s2; if (s1 + s2 < size2) { setColor(pixmap, i, j); pixmap.drawPixel(i, j); } } } } return pixmap; }
From source file:es.eucm.ead.engine.assets.drawables.shapes.GdxRectangleShape.java
License:Open Source License
@Override protected Pixmap generatePixmap() { EAdPaint paint = descriptor.getPaint(); EAdFill border = paint.getBorder();// w w w.j a v a 2s . co m EAdFill fill = paint.getFill(); int borderWidth = paint.getBorderWidth(); int pwidth = descriptor.getWidth() + borderWidth * 2; int pheight = descriptor.getHeight() + borderWidth * 2; Pixmap pixmap = new Pixmap(pwidth, pheight, Pixmap.Format.RGBA8888); pixmapContains = new Pixmap(pwidth, pheight, Pixmap.Format.RGBA8888); pixmapContains.setColor(0, 0, 0, 1); pixmapContains.fillRectangle(0, 0, pwidth, pheight); ColorFill c = ColorFill.TRANSPARENT; if (border != null) { if (border instanceof ColorFill) { c = (ColorFill) border; } else if (border instanceof LinearGradientFill) { LinearGradientFill l = (LinearGradientFill) border; c = l.getColor1(); } pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f, c.getAlpha() / 255.0f); pixmap.drawRectangle(0, 0, pwidth, pheight); } if (fill instanceof ColorFill) { c = (ColorFill) fill; pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f, c.getAlpha() / 255.0f); pixmap.fillRectangle(borderWidth, borderWidth, descriptor.getWidth(), descriptor.getHeight()); } else if (fill instanceof LinearGradientFill) { LinearGradientFill l = (LinearGradientFill) fill; initGradientParams(l.getColor1(), l.getX0(), l.getY0(), l.getColor2(), l.getX1(), l.getY1()); for (int i = borderWidth; i < descriptor.getWidth() + borderWidth; i++) { for (int j = borderWidth; j < descriptor.getHeight() + borderWidth; j++) { setColor(pixmap, i, j); pixmap.drawPixel(i, j); } } } return pixmap; }
From source file:es.eucm.ead.engine.assets.loaders.ExtendedSkin.java
License:Open Source License
public ExtendedSkin(Assets assets, TextureAtlas atlas) { super(atlas); this.assets = assets; Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888); pixmap.setColor(1.0f, 1.0f, 1.0f, 1.0f); pixmap.fill();/* ww w .jav a 2 s.com*/ Texture blank = new Texture(pixmap); pixmap.dispose(); add("blank", new TextureRegionDrawable(new TextureRegion(blank)), Drawable.class); }
From source file:es.eucm.ead.engine.components.renderers.shape.ShapeToPixmap.java
License:Open Source License
/** Creates a rectangle **/ private Pixmap createRectangle(Rectangle rectangle) { originX = 0;//from www .ja v a 2 s. c o m originY = 0; int width = rectangle.getWidth(); pixmapHeight = rectangle.getHeight(); if (width <= 0 || pixmapHeight <= 0) { Gdx.app.error("ShapeFactory", "Rectangles can't have negative or zero dimensions: (" + width + ", " + pixmapHeight + ")"); } Pixmap pixmap = new Pixmap(width, pixmapHeight, Format.RGBA8888); if (useGradient) { for (int i = 0; i < width; i++) { for (int j = 0; j < pixmapHeight; j++) { setGradientColor(pixmap, i, j); pixmap.drawPixel(i, j); } } } else { pixmap.setColor(color1); pixmap.fill(); } if (hasBorder) { pixmap.setColor(borderColor); pixmap.drawRectangle(0, 0, width, pixmapHeight); } return pixmap; }