List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap
public Pixmap(byte[] encodedData, int offset, int len)
From source file:mobi.shad.s3lib.gfx.node.util.FxPixmapSize.java
License:Apache License
/** * *///w ww.j av a 2 s. co m @Override protected void processLocal() { if (formGui != null) { pixmapSize = formGui.getInt("FxPixmapSize"); } data.type = Data.Type.EFFECT_2D; switch (pixmapSize) { default: xSize = 16; ySize = 16; break; case 1: xSize = 32; ySize = 32; break; case 2: xSize = 64; ySize = 64; break; case 3: xSize = 128; ySize = 128; break; case 4: xSize = 256; ySize = 256; break; case 5: xSize = 512; ySize = 512; break; case 6: xSize = 1024; ySize = 1024; break; case 7: xSize = 64; ySize = 32; break; case 8: xSize = 128; ySize = 64; break; case 9: xSize = 256; ySize = 128; break; } data.pixmap = new Pixmap(xSize, ySize, Pixmap.Format.RGBA8888); data.pixmap.setColor(Color.BLACK); data.pixmap.fill(); data.texture = null; data.textureChange = true; }
From source file:mobi.shad.s3lib.gfx.pixmap.disort.Disort.java
License:Apache License
/** * * @param pixmapDest/* www .j a va 2s. c o m*/ * @param pixmapMask * @param power */ public static void generate(final Pixmap pixmapDest, final Pixmap pixmapMask, float power) { int widthDest = pixmapDest.getWidth(); int heightDest = pixmapDest.getHeight(); int widthMask = pixmapMask.getWidth(); int heightMask = pixmapMask.getHeight(); int rgb = 0; int r = 0; int g = 0; int b = 0; int a = 0; Pixmap dstPixmap = new Pixmap(widthDest, widthDest, pixmapDest.getFormat()); Vector3 norm = new Vector3(); for (int y = 0; y < heightDest; y++) { for (int x = 0; x < widthDest; x++) { rgb = pixmapMask.getPixel(x % widthMask, y % heightMask); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; a = (rgb & 0x000000ff); norm.x = r - 127; norm.y = g - 127; norm.z = b - 127; norm.nor(); float v = (x + (norm.x * power)) % widthDest; float u = (y + (norm.y * power)) % heightDest; int vt = v >= 0 ? (int) v : (int) v - 1; int ut = u >= 0 ? (int) u : (int) u - 1; // // Texel1 // rgb = pixmapDest.getPixel(vt, ut); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; int outR = r; int outG = g; int outB = b; int outA = 255; // // Texel2 // rgb = pixmapDest.getPixel(vt, ut + heightDest); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; outR += r; outG += g; outB += b; // // Texel3 // rgb = pixmapDest.getPixel((vt + widthDest), ut); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; outR += r; outG += g; outB += b; // // Texel 4 // rgb = pixmapDest.getPixel(vt + widthDest, ut + heightDest); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; outR += r; outG += g; outB += b; // // Clamp // outR = (outR < 255) ? outR : 255; outR = (outR > 0) ? outR : 0; outG = (outG < 255) ? outG : 255; outG = (outG > 0) ? outG : 0; outB = (outB < 255) ? outB : 255; outB = (outB > 0) ? outB : 0; dstPixmap.drawPixel(x, y, ((int) outR << 24) | ((int) outG << 16) | ((int) outB << 8) | outA); } } pixmapDest.drawPixmap(dstPixmap, 0, 0); }
From source file:mobi.shad.s3lib.gfx.pixmap.disort.RotoZoom.java
License:Apache License
/** * * @param pixmap//from ww w.ja v a 2s .c om * @param amplify - The bulge value */ public static void generate(final Pixmap pixmap, float centerX, float centerY, float rotate, float zoomX, float zoomY) { int width = pixmap.getWidth(); int height = pixmap.getHeight(); // // Rotate // rotate = rotate * S3Math.PI2; // // Zoom // zoomX = (float) Math.pow(.5f, zoomX - 1); zoomY = (float) Math.pow(.5f, zoomY - 1); float c = (float) (Math.cos(rotate)); float s = (float) (Math.sin(rotate)); float tw2 = (float) width / 2.0f; float th2 = (float) height / 2.0f; float ys = s * -th2; float yc = c * -th2; Pixmap dstPixmap = new Pixmap(width, height, pixmap.getFormat()); dstPixmap.setColor(Color.RED); dstPixmap.fill(); for (int y = 0; y < height; y++) { // // x' = cos(x)-sin(y) + Center X; // float u = (((c * -tw2) - ys) * zoomX) + centerX; // // y' = sin(x)+cos(y) + Center Y; // float v = (((s * -tw2) + yc) * zoomY) + centerY; for (int x = 0; x < width; x++) { int ut = u >= 0 ? (int) u : (int) u - 1; int vt = v >= 0 ? (int) v : (int) v - 1; // // Texels // 1 | 2 // ------- // 3 | 4 // // // Texel1 // int rgb = pixmap.getPixel(vt, ut); int r = (rgb & 0xff000000) >>> 24; int g = (rgb & 0x00ff0000) >>> 16; int b = (rgb & 0x0000ff00) >>> 8; int a = (rgb & 0x000000ff); int outR = r; int outG = g; int outB = b; int outA = 255; // // Texel2 // rgb = pixmap.getPixel(vt, ut + height); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; outR += r; outG += g; outB += b; // // Texel3 // rgb = pixmap.getPixel((vt + width), ut); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; outR += r; outG += g; outB += b; // // Texel 4 // rgb = pixmap.getPixel(vt + width, ut + height); r = (rgb & 0xff000000) >>> 24; g = (rgb & 0x00ff0000) >>> 16; b = (rgb & 0x0000ff00) >>> 8; outR += r; outG += g; outB += b; // // Clamp // outR = (outR < 255) ? outR : 255; outR = (outR > 0) ? outR : 0; outG = (outG < 255) ? outG : 255; outG = (outG > 0) ? outG : 0; outB = (outB < 255) ? outB : 255; outB = (outB > 0) ? outB : 0; dstPixmap.drawPixel(x, y, ((int) outR << 24) | ((int) outG << 16) | ((int) outB << 8) | outA); // // Vectors X // u += c * zoomX; v += s * zoomY; } // // Vectors Y // ys += s; yc += c; } pixmap.drawPixmap(dstPixmap, 0, 0); }
From source file:mobi.shad.s3lib.gfx.pixmap.disort.Vortex.java
License:Apache License
/** * * @param pixmap//from w w w .ja v a 2 s. com * @param centerX * @param centerY * @param rayX * @param rayY * @param twist */ public static void generate(final Pixmap pixmap, float centerX, float centerY, float rayX, float rayY, float twist) { int width = pixmap.getWidth(); int height = pixmap.getHeight(); // // Process operator // int dwCenterX = (int) (centerX * width); int dwCenterY = (int) (centerY * height); int dwRadiusX = (int) (rayX * width); int dwRadiusY = (int) (rayY * height); float f1_RadiusX = 1.0f / (float) dwRadiusX; float f1_RadiusY = 1.0f / (float) dwRadiusY; float radians = twist * S3Math.PI2; Pixmap dstPixmap = new Pixmap(width, height, pixmap.getFormat()); dstPixmap.setColor(Color.BLACK); dstPixmap.fill(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // // Calculate distance // float dx = (float) (x - dwCenterX) * f1_RadiusX; float dy = (float) (y - dwCenterY) * f1_RadiusY; float d = (float) Math.sqrt(dx * dx + dy * dy); // // If distance more radius, olny copy pixels // if (d > 1.0) { int rgb = pixmap.getPixel(x, y); dstPixmap.drawPixel(x, y, rgb); } else { d = (float) S3Math.fastCos(d * S3Math.PI1_2 - S3Math.PI1_2); d = 1.0f - d; // // Rotate around middle // float nx = x - dwCenterX; float ny = y - dwCenterY; float rad = radians * d; float bx = nx; nx = bx * S3Math.fastCos(rad) - nx * S3Math.fastSin(rad) + dwCenterX; ny = bx * S3Math.fastSin(rad) + ny * S3Math.fastCos(rad) + dwCenterY; if (nx >= width) { nx = nx - width; } if (ny >= height) { ny = ny - height; } if (nx < 0) { nx = width + nx; } if (ny < 0) { ny = height + ny; } // // Bilinear sample nearest 4 pixels at rotated pos // int ix, iy; ix = (int) nx; iy = (int) ny; float fracX = nx - ix; float fracY = ny - iy; float ul = (1.0f - fracX) * (1.0f - fracY); float ll = (1.0f - fracX) * fracY; float ur = fracX * (1.0f - fracY); float lr = fracX * fracY; int wrapx = (ix + 1); int wrapy = (iy + 1); int rgb = pixmap.getPixel(ix, iy); int r = (rgb & 0xff000000) >>> 24; int g = (rgb & 0x00ff0000) >>> 16; int b = (rgb & 0x0000ff00) >>> 8; rgb = pixmap.getPixel(wrapx, iy); int r2 = (rgb & 0xff000000) >>> 24; int g2 = (rgb & 0x00ff0000) >>> 16; int b2 = (rgb & 0x0000ff00) >>> 8; rgb = pixmap.getPixel(ix, wrapy); int r3 = (rgb & 0xff000000) >>> 24; int g3 = (rgb & 0x00ff0000) >>> 16; int b3 = (rgb & 0x0000ff00) >>> 8; rgb = pixmap.getPixel(wrapx, wrapy); int r4 = (rgb & 0xff000000) >>> 24; int g4 = (rgb & 0x00ff0000) >>> 16; int b4 = (rgb & 0x0000ff00) >>> 8; r = (int) (r * ul + r2 * ur + r3 * ll + r4 * lr); g = (int) (g * ul + g2 * ur + g3 * ll + g4 * lr); b = (int) (b * ul + b2 * ur + b3 * ll + b4 * lr); // // Clamp // r = (r < 255) ? r : 255; r = (r > 0) ? r : 0; g = (g < 255) ? g : 255; g = (g > 0) ? g : 0; b = (b < 255) ? b : 255; b = (b > 0) ? b : 0; dstPixmap.drawPixel(x, y, ((int) r << 24) | ((int) g << 16) | ((int) b << 8) | 255); } } } pixmap.drawPixmap(dstPixmap, 0, 0); }
From source file:mobi.shad.s3lib.gfx.pixmap.filter.Normals.java
License:Apache License
/** * Main normal map filter process//from www . j a va 2 s . c o m * * @param pixmap * @param amplify - The bulge value */ public static void generate(final Pixmap pixmap, int amplify) { int width = pixmap.getWidth(); int height = pixmap.getHeight(); Pixmap dstPixmap = new Pixmap(width, height, pixmap.getFormat()); Vector3 norm = new Vector3(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int rgb = pixmap.getPixel(x, y); int r = (rgb & 0xff000000) >>> 24; int g = (rgb & 0x00ff0000) >>> 16; int b = (rgb & 0x0000ff00) >>> 8; int a = (rgb & 0x000000ff); // // 1 Column // int rgbXnYn = pixmap.getPixel(x - 1, y - 1); int rXnYn = (rgbXnYn & 0xff000000) >>> 24; // int gXnYn=(rgbXnYn & 0x00ff0000) >>> 16; // int bXnYn=(rgbXnYn & 0x0000ff00) >>> 8; int rgbXnY = pixmap.getPixel(x - 1, y); int rXnY = (rgbXnY & 0xff000000) >>> 24; // int gXnY=(rgbXnY & 0x00ff0000) >>> 16; // int bXnY=(rgbXnY & 0x0000ff00) >>> 8; int rgbXnYp = pixmap.getPixel(x - 1, y + 1); int rXnYp = (rgbXnYp & 0xff000000) >>> 24; // int gXnYp=(rgbXnYp & 0x00ff0000) >>> 16; // int bXnYp=(rgbXnYp & 0x0000ff00) >>> 8; // // 2 Column // int rgbXYn = pixmap.getPixel(x, y - 1); int rXYn = (rgbXYn & 0xff000000) >>> 24; // int gXYn=(rgbXYn & 0x00ff0000) >>> 16; // int bXYn=(rgbXYn & 0x0000ff00) >>> 8; int rgbXYp = pixmap.getPixel(x, y + 1); int rXYp = (rgbXYp & 0xff000000) >>> 24; // int gXYp=(rgbXYp & 0x00ff0000) >>> 16; // int bXYp=(rgbXYp & 0x0000ff00) >>> 8; // // 3 Column // int rgbXpYn = pixmap.getPixel(x + 1, y - 1); int rXpYn = (rgbXpYn & 0xff000000) >>> 24; // int gXpYn=(rgbXpYn & 0x00ff0000) >>> 16; // int bXpYn=(rgbXpYn & 0x0000ff00) >>> 8; int rgbXpY = pixmap.getPixel(x + 1, y); int rXpY = (rgbXpY & 0xff000000) >>> 24; // int gXpY=(rgbXpY & 0x00ff0000) >>> 16; // int bXpY=(rgbXpY & 0x0000ff00) >>> 8; int rgbXpYp = pixmap.getPixel(x + 1, y + 1); int rXpYp = (rgbXpYp & 0xff000000) >>> 24; // int gXpYp=(rgbXpYp & 0x00ff0000) >>> 16; // int bXpYp=(rgbXpYp & 0x0000ff00) >>> 8; // // Y Sobel filter operation // // [ 1 2 1] // [ // [-1 -2 -1] // float dY = 0; dY += rXnYn * 1.0f; dY += rXYn * 2.0f; dY += rXpYn * 1.0f; dY += rXnYp * -1.0f; dY += rXYp * -2.0f; dY += rXpYp * -1.0f; // // X Sobel filter // // [-1 1] // [-2 2] // [-1 1] // float dX = 0; dX = rXnYn * -1.0f; dX += rXnY * -2.0f; dX += rXnYp * -1.0f; dX += rXpYn * 1.0f; dX += rXpY * 2.0f; dX += rXpYp * 1.0f; // // Compute the cross product of the two vectors // norm.x = -dX * amplify / 255.0f; norm.y = -dY * amplify / 255.0f; norm.z = 1.0f; // // Normalize // norm.nor(); // // Store // [-1.0f->1.0f] -> [0 -> 255] // r = (int) ((norm.x + 1.0f) / 2.0f * 255.0f); g = (int) ((norm.y + 1.0f) / 2.0f * 255.0f); b = (int) ((norm.z + 1.0f) / 2.0f * 255.0f); dstPixmap.drawPixel(x, y, ((int) r << 24) | ((int) g << 16) | ((int) b << 8) | a); } } pixmap.drawPixmap(dstPixmap, 0, 0); }
From source file:mobi.shad.s3lib.gfx.util.ScreenShot.java
License:Apache License
/** * @param x/*w w w . j ava2 s. c o m*/ * @param y * @param w * @param h * @param flipY * @return */ public static Pixmap getScreenShot(int x, int y, int w, int h, boolean flipY) { Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1); final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888); ByteBuffer pixels = pixmap.getPixels(); Gdx.gl.glReadPixels(x, y, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels); final int numBytes = w * h * 4; byte[] lines = new byte[numBytes]; if (flipY) { final int numBytesPerLine = w * 4; for (int i = 0; i < h; i++) { pixels.position((h - i - 1) * numBytesPerLine); pixels.get(lines, i * numBytesPerLine, numBytesPerLine); } pixels.clear(); pixels.put(lines); } else { pixels.clear(); pixels.get(lines); } return pixmap; }
From source file:mobi.shad.s3lib.gui.dialog.ColorBrowser.java
License:Apache License
public void show(boolean alphaChanel) { super.create(); //// www. j a v a 2 s .c o m // Wygenerowanie buttonow // sliderR = GuiResource.slider(0, 100, 1, "colorDialogSliderR"); sliderG = GuiResource.slider(0, 100, 1, "colorDialogSliderG"); sliderB = GuiResource.slider(0, 100, 1, "colorDialogSliderB"); sliderA = GuiResource.slider(0, 100, 1, "colorDialogSliderA"); labelTextR = GuiResource.label("R", "colorTextDialogLabelR"); labelTextG = GuiResource.label("G", "colorTextDialogLabelG"); labelTextB = GuiResource.label("B", "colorTextDialogLabelB"); labelTextA = GuiResource.label("A", "colorTextDialogLabelA"); labelR = GuiResource.label("red", "colorDialogLabelR"); labelG = GuiResource.label("green", "colorDialogLabelG"); labelB = GuiResource.label("blue", "colorDialogLabelB"); labelA = GuiResource.label("alpha", "colorDialogLabelA"); final Button buttonOk = GuiResource.textButton("Ok", "colorDialogButtonOk"); color = new Color(); // // Tworzenie image textury podgladu // pixmap = new Pixmap(128, 32, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888); pixmap.setColor(1, 1, 1, 1); pixmap.fillRectangle(0, 0, 128, 32); texture = new Texture(pixmap); region = new TextureRegion(texture); imageActor = new Image(region); // // Podpiecie akcji do buttonow i sliderow // buttonOk.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:click", "click x:" + x + " y:" + y + " event: " + event.toString()); } hide(); if (listener != null) { listener.Action(color); } } }); sliderR.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { float value = sliderR.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderR", " value: " + value); } colorR = value / 100; setBtnColorSampleColor(); } }); sliderG.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { float value = sliderR.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderG", " value: " + value); } colorG = value / 100; setBtnColorSampleColor(); } }); sliderB.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { float value = sliderB.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderB", " value: " + value); } colorB = value / 100; setBtnColorSampleColor(); } }); sliderA.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { float value = sliderA.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderA", " value: " + value); } colorA = value / 100; setBtnColorSampleColor(); } }); // // Utworzenie okna // mainWindow.setTitle(S3Lang.get("colorBrowser")); mainWindow.row().fill().expandX(); mainWindow.add(labelTextR); mainWindow.add(sliderR); mainWindow.add(labelR).left(); mainWindow.row(); mainWindow.add(labelTextG); mainWindow.add(sliderG); mainWindow.add(labelG).left(); mainWindow.row(); mainWindow.add(labelTextB); mainWindow.add(sliderB); mainWindow.add(labelB).left(); if (alphaChanel) { mainWindow.row(); mainWindow.add(labelTextA); mainWindow.add(sliderA); mainWindow.add(labelA).left(); } mainWindow.row(); mainWindow.add(); mainWindow.add(imageActor).align(Align.left).colspan(2); mainWindow.add(buttonOk).fillX().minWidth(50); mainWindow.pack(); mainWindow.setModal(true); GuiUtil.windowPosition(mainWindow, 5, 5); // S3.stage.addActor(backendWindow); S3.stage.addActor(mainWindow); // // Inicjacja stanw // sliderR.setValue(colorR * 100); sliderG.setValue(colorG * 100); sliderB.setValue(colorB * 100); sliderA.setValue(colorA * 100); setBtnColorSampleColor(); super.show(); }
From source file:mobi.shad.s3lib.gui.dialog.Editor2d.java
License:Apache License
public void create(Texture areaTexture, final float startX, final float startY, final float width, final float height, final ChangeListener changeListener) { super.create(); backendWindow = GuiResource.windowBackend(); backendWindow.setColor(1f, 1f, 1f, 0f); backendWindow.setVisible(false);/*from ww w .j av a2s . c om*/ S3.stage.addActor(backendWindow); mainWindow = GuiResource.window("WidgetBase", "WidgetBase"); mainWindow.setColor(1f, 1f, 1f, 0f); mainWindow.setVisible(false); mainWindow.setModal(true); mainWindow.setMovable(false); this.currentX = startX; this.currentY = startY; this.currentWidth = width; this.currentHeight = height; // // Grid Layer // Pixmap pixmap = new Pixmap(10, 10, Pixmap.Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fill(); gridtextureLayer = new Texture(pixmap); gridLayer = new Widget() { @Override public void draw(Batch batch, float parentAlpha) { batch.setColor(0.8f, 0.8f, 0.8f, 0.3f); batch.draw(gridtextureLayer, 0, S3Constans.gridY1, S3Screen.width, 1); batch.draw(gridtextureLayer, 0, S3Constans.gridY2, S3Screen.width, 1); batch.draw(gridtextureLayer, 0, S3Constans.gridY3, S3Screen.width, 1); batch.draw(gridtextureLayer, 0, S3Constans.gridY4, S3Screen.width, 1); batch.draw(gridtextureLayer, 0, S3Constans.gridY5, S3Screen.width, 3); batch.draw(gridtextureLayer, 0, S3Constans.gridY6, S3Screen.width, 1); batch.draw(gridtextureLayer, 0, S3Constans.gridY7, S3Screen.width, 1); batch.draw(gridtextureLayer, 0, S3Constans.gridY8, S3Screen.width, 1); batch.draw(gridtextureLayer, 0, S3Constans.gridY9, S3Screen.width, 1); batch.draw(gridtextureLayer, S3Constans.gridX1, 0, 1, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX2, 0, 1, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX3, 0, 1, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX4, 0, 1, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX5, 0, 3, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX6, 0, 1, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX7, 0, 1, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX8, 0, 1, S3Screen.height); batch.draw(gridtextureLayer, S3Constans.gridX9, 0, 1, S3Screen.height); } }; gridLayer.setX(0); gridLayer.setY(0); gridLayer.setWidth(S3Screen.width); gridLayer.setHeight(S3Screen.height); // // // final TextureRegion areaRegion = new TextureRegion(areaTexture); areaImage = new Widget() { @Override public void draw(Batch batch, float parentAlpha) { Color color = getColor(); batch.setColor(color.r, color.g, color.b, parentAlpha); batch.draw(areaRegion, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); } }; areaImage.setX(currentX); areaImage.setY(currentY); areaImage.setWidth(currentWidth); areaImage.setHeight(currentHeight); // // Create texture // Pixmap redPixmap = new Pixmap(32, 32, Pixmap.Format.RGBA8888); redPixmap.setColor(Color.RED); redPixmap.fillCircle(16, 16, 14); Texture redTexture = new Texture(redPixmap); Pixmap yellowPixmap = new Pixmap(32, 32, Pixmap.Format.RGBA8888); yellowPixmap.setColor(Color.YELLOW); yellowPixmap.fillCircle(16, 16, 14); Texture yellowTexture = new Texture(yellowPixmap); Pixmap greenPixmap = new Pixmap(32, 32, Pixmap.Format.RGBA8888); greenPixmap.setColor(Color.GREEN); greenPixmap.fillCircle(16, 16, 14); Texture greenTexture = new Texture(greenPixmap); // // // TextButton textButtonOk = GuiResource.textButton("Save", "Save"); TextButton textButtonFullScreen = GuiResource.textButton("Full", "Full"); TextButton textButtonCenter = GuiResource.textButton("Center", "Center"); TextButton textButtonCancel = GuiResource.textButton("Cancel", "Cancel"); // // // textButtonOk.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { S3Log.log("Editor2d::textButtonOk::clicked", " event: " + event + " actor: " + actor.toString(), 2); hide(); if (changeListener != null) { changeListener.changed(event, areaImage); } } }); textButtonFullScreen.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { S3Log.log("Editor2d::textButtonFullScreen::clicked", " event: " + event + " x: " + x + " y: " + y, 2); currentX = 0; currentY = 0; currentWidth = S3Screen.width; currentHeight = S3Screen.height; setAreaPosistion(); setTouchPosistion(); } }); textButtonCenter.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { S3Log.log("Editor2d::textButtonCenter::clicked", " event: " + event + " x: " + x + " y: " + y, 2); currentX = S3Screen.centerX - (float) S3Screen.centerX / 2; currentY = S3Screen.centerY - (float) S3Screen.centerY / 2; currentWidth = (float) S3Screen.centerX; currentHeight = (float) S3Screen.centerY; setAreaPosistion(); setTouchPosistion(); } }); textButtonCancel.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { S3Log.log("Editor2d::textButtonCancel::clicked", " event: " + event + " x: " + x + " y: " + y, 2); currentX = startX; currentY = startY; currentWidth = width; currentHeight = height; hide(); } }); sizeElementLabel = GuiResource.label("X: Y: Width: Height:", "sizeElementLabel"); mainWindow.row(); mainWindow.add(textButtonOk); mainWindow.add(textButtonFullScreen); mainWindow.add(textButtonCenter); mainWindow.add(textButtonCancel); mainWindow.row(); mainWindow.add(sizeElementLabel).colspan(4).left(); GuiUtil.windowPosition(mainWindow, 0, 0); S3.stage.addActor(gridLayer); S3.stage.addActor(areaImage); // // Create AreaPlot // dotLeftImage = createAreaPoint("dotLeftImage", redTexture, (int) (currentX - 16), (int) (currentY + (currentHeight / 2) - 16)); dotRightImage = createAreaPoint("dotRightImage", redTexture, (int) (currentX + currentWidth - 16), (int) (currentY + (currentHeight / 2) - 16)); dotTopImage = createAreaPoint("dotTopImage", redTexture, (int) (currentX + (currentWidth / 2) - 16), (int) (currentY + currentHeight - 16)); dotBottomImage = createAreaPoint("dotBottomImage", redTexture, (int) (currentX + (currentWidth / 2) - 16), (int) (currentY - 16)); dotTopLeftImage = createAreaPoint("dotTopLeftImage", yellowTexture, (int) (currentX - 16), (int) (currentY + currentHeight - 16)); dotTopRightImage = createAreaPoint("dotTopRightImage", yellowTexture, (int) (currentX + currentWidth - 16), (int) (currentY + currentHeight - 16)); dotBottomLeftImage = createAreaPoint("dotBottomLeftImage", yellowTexture, (int) (currentX + currentWidth - 16), (int) (currentY - 16)); dotBottomRightImage = createAreaPoint("dotBottomRightImage", yellowTexture, (int) (currentX + currentWidth - 16), (int) (currentY - 16)); dotCenterImage = createAreaPoint("dotCenter", greenTexture, (int) (currentX + (currentWidth / 2) - 16), (int) (currentY + (currentHeight / 2) - 16)); S3.stage.addActor(mainWindow); // // Assign Listener // mainWindow.addListener(new InputListener() { @Override public void touchDragged(InputEvent event, float x, float y, int pointer) { lastPointX = pointX; lastPointY = pointY; pointX = x; pointY = y; deltaX = pointX - lastPointX; deltaY = pointY - lastPointY; S3Log.log("dotCenterImage::touchDragged", " event: " + event + " x: " + x + " y: " + y + " pointer: " + pointer + " deltaX: " + deltaX + " deltaY: " + deltaY, 3); if (pointClick != null) { S3Log.log("dotCenterImage::touchDragged", " Point click: " + pointClickName + " aX: " + aspectRatioX + " aY: " + aspectRatioY, 2); if (pointClickName.equalsIgnoreCase("dotLeftImage")) { if (currentX > 0 && deltaX < 0 && currentWidth >= 32) { currentX += deltaX; currentWidth -= deltaX; } else if (currentX < S3Screen.width && deltaX > 0 && currentWidth > 32) { currentX += deltaX; currentWidth -= deltaX; } setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotRightImage")) { if (currentX + currentWidth > 0 && currentX + currentWidth < S3Screen.width && currentWidth >= 32 && currentX > -1 && deltaX > 0) { currentWidth += deltaX; } else if (currentX + currentWidth > 0 && currentX + currentWidth <= S3Screen.width && currentWidth >= 32 && currentX > -1 && deltaX < 0) { currentWidth += deltaX; } setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotTopImage")) { if (currentY + currentHeight > 0 && currentY + currentHeight < S3Screen.height && currentHeight >= 32 && currentY > -1 && deltaY > 0) { currentHeight += deltaY; } else if (currentY + currentHeight > 0 && currentY + currentHeight <= S3Screen.height && currentHeight >= 32 && currentY > -1 && deltaY < 0) { currentHeight += deltaY; } setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotBottomImage")) { if (currentY > 0 && deltaY < 0 && currentHeight >= 32) { currentY += deltaY; currentHeight -= deltaY; } else if (currentY < S3Screen.height && deltaY > 0 && currentHeight > 32) { currentY += deltaY; currentHeight -= deltaY; } setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotTopRightImage")) { float delta = (deltaX + deltaY) / 2; currentHeight += delta * aspectRatioY; currentWidth += delta * aspectRatioX; setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotBottomLeftImage")) { float delta = (deltaX + deltaY) / 2; currentX += delta * aspectRatioX; currentY += delta * aspectRatioY; currentHeight -= delta * aspectRatioY; currentWidth -= delta * aspectRatioX; setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotCenter")) { currentX += deltaX; currentY += deltaY; setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotTopLeftImage")) { float delta = (deltaX - deltaY) / 2; currentX += delta * aspectRatioY; currentHeight -= delta * aspectRatioY; currentWidth -= delta * aspectRatioY; setAreaPosistion(); setTouchPosistion(); } else if (pointClickName.equalsIgnoreCase("dotBottomRightImage")) { float delta = (deltaX - deltaY) / 2; currentY -= delta * aspectRatioY; currentHeight += delta * aspectRatioY; currentWidth += delta * aspectRatioY; setAreaPosistion(); setTouchPosistion(); } // // dotBottomRightImage } else if (isAreaImageClick) { currentX += deltaX; currentY += deltaY; setAreaPosistion(); setTouchPosistion(); } } @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { S3Log.log("dotCenterImage::touchDown", " event: " + event + " x: " + x + " y: " + y + " pointer: " + pointer + " button: " + button, 3); pointX = x; pointY = y; lastPointX = x; lastPointY = y; isAreaImageClick = checkAreaClick(x, y); pointClick = checkPointClick(x, y); return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { S3Log.log("dotCenterImage::touchUp", " event: " + event + " x: " + x + " y: " + y + " pointer: " + pointer + " button: " + button, 2); isAreaImageClick = false; pointClick = null; pointClickName = ""; } }); setAreaPosistion(); setTouchPosistion(); }
From source file:mobi.shad.s3lib.gui.Gui.java
License:Apache License
public void addSeparator(final Color color, final boolean newRow, final int colSpan) { Pixmap px = new Pixmap(1, 1, Pixmap.Format.RGB888); px.setColor(color);//w ww . j a v a 2 s . c o m px.fill(); Texture tex = new Texture(px); Image img = new Image(tex); if (newRow) { table.row(); } table.add(img).left().expandX().fillX().height(1).colspan(colSpan); }
From source file:mobi.shad.s3lib.gui.widget.ColorBrowser.java
License:Apache License
public Table getTable() { ////from w w w . j a v a2s .c o m // Wygenerowanie buttonow // sliderR = GuiResource.slider(0, 100, 1, "colorDialogSliderR"); sliderG = GuiResource.slider(0, 100, 1, "colorDialogSliderG"); sliderB = GuiResource.slider(0, 100, 1, "colorDialogSliderB"); sliderA = GuiResource.slider(0, 100, 1, "colorDialogSliderA"); // // Fix slider FixScroll // sliderR.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.stop(); return false; } }); sliderG.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.stop(); return false; } }); sliderB.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.stop(); return false; } }); sliderA.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { event.stop(); return false; } }); labelTextR = GuiResource.label("R", "colorTextDialogLabelR"); labelTextG = GuiResource.label("G", "colorTextDialogLabelG"); labelTextB = GuiResource.label("B", "colorTextDialogLabelB"); labelTextA = GuiResource.label("A", "colorTextDialogLabelA"); labelR = GuiResource.label("red", "colorDialogLabelR"); labelG = GuiResource.label("green", "colorDialogLabelG"); labelB = GuiResource.label("blue", "colorDialogLabelB"); labelA = GuiResource.label("alpha", "colorDialogLabelA"); color = new Color(); // // Tworzenie image textury podgladu // pixmap = new Pixmap(128, 32, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888); pixmap.setColor(1, 1, 1, 1); pixmap.fillRectangle(0, 0, 128, 32); texture = new Texture(pixmap); region = new TextureRegion(texture); imageActor = new Image(region); // // Podpiecie akcji do buttonow i sliderow // sliderR.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { float value = sliderR.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderR", " value: " + value); } colorR = value / 100; setBtnColorSampleColor(); } }); sliderG.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { float value = sliderG.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderG", " value: " + value); } colorG = value / 100; setBtnColorSampleColor(); } }); sliderB.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { float value = sliderB.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderB", " value: " + value); } colorB = value / 100; setBtnColorSampleColor(); } }); sliderA.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { float value = sliderA.getValue(); if (S3Constans.NOTICE) { S3Log.log("WidgetColorBrowser:sliderA", " value: " + value); } colorA = value / 100; setBtnColorSampleColor(); } }); // // Utworzenie okna // window = GuiResource.table("colorBrowserTable"); window.row(); window.add(labelTextR).left().width(S3Constans.gridX0_30); window.add(sliderR).left().fillX().expandX(); window.add(labelR).left().width(S3Constans.gridX0_30); window.row(); window.add(labelTextG).left().width(S3Constans.gridX0_30); window.add(sliderG).left().fillX().expandX(); window.add(labelG).left().width(S3Constans.gridX0_30); window.row(); window.add(labelTextB).left().width(S3Constans.gridX0_30); window.add(sliderB).left().fillX().expandX(); window.add(labelB).left().width(S3Constans.gridX0_30); if (alphaChanel) { window.row(); window.add(labelTextA).left().width(S3Constans.gridX0_30); window.add(sliderA).left().fillX().expandX(); window.add(labelA).left().width(S3Constans.gridX0_30); } window.row(); window.add().left().width(S3Constans.gridX0_30); window.add(imageActor).left().colspan(2); // // Inicjacja stanw // if (colorR < 0) { colorR = 0; } if (colorR > 1) { colorR = 1; } if (colorG < 0) { colorG = 0; } if (colorG > 1) { colorG = 1; } if (colorB < 0) { colorB = 0; } if (colorB > 1) { colorB = 1; } if (colorA < 0) { colorA = 0; } if (colorA > 1) { colorA = 1; } sliderR.setValue(colorR * 100); sliderG.setValue(colorG * 100); sliderB.setValue(colorB * 100); sliderA.setValue(colorA * 100); setBtnColorSampleColor(); return window; }