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.engine.components.renderers.shape.ShapeToPixmap.java
License:Open Source License
/** Creates a circle **/ private Pixmap createCircle(Circle circle) { int radius = circle.getRadius(); int size = radius * 2; pixmapHeight = size;// w w w. ja va2 s. com originX = 0; originY = 0; Pixmap pixmap = new Pixmap(size, size, Format.RGBA8888); if (useGradient) { for (int i = 0; i < size; i++) { for (int j = 0; j < pixmapHeight; j++) { if (auxVector.set(i - radius, j - radius).len() <= radius - 1) { setGradientColor(pixmap, i, j); pixmap.drawPixel(i, j); } } } } else { pixmap.setColor(color1); pixmap.fillCircle(radius, radius, radius - 1); } if (hasBorder) { pixmap.setColor(borderColor); pixmap.drawCircle(radius, radius, radius - 1); } return pixmap; }
From source file:es.eucm.ead.engine.components.renderers.shape.ShapeToPixmap.java
License:Open Source License
/** Creates a polygon **/ private Pixmap createPolygon(Polygon schemaPolygon) { if (schemaPolygon.getPoints().size < 6) { Gdx.app.error("ShapeFactory", "Invalid polygon. It contains less than 3 points."); return null; }// ww w . j a va 2s . c o m float[] points = new float[schemaPolygon.getPoints().size]; for (int i = 0; i < schemaPolygon.getPoints().size; i++) { points[i] = schemaPolygon.getPoints().get(i); // See comment in setGradientColor to understand this if (i % 2 != 0) { points[i] = pixmapHeight - points[i]; } } com.badlogic.gdx.math.Polygon polygon = new com.badlogic.gdx.math.Polygon(points); com.badlogic.gdx.math.Rectangle rectangle = polygon.getBoundingRectangle(); Pixmap pixmap = new Pixmap((int) rectangle.getWidth(), (int) rectangle.getHeight(), Format.RGBA8888); // Fill pixmap.setColor(color1); for (int i = 0; i < rectangle.getWidth(); i++) { for (int j = 0; j < rectangle.getHeight(); j++) { if (polygon.contains(i, j)) { if (useGradient) { setGradientColor(pixmap, i, j); } pixmap.drawPixel(i, j); } } } // Border if (hasBorder) { pixmap.setColor(borderColor); int prevX = (int) points[0]; int prevY = (int) points[1]; for (int i = 2; i < points.length; i += 2) { int x = (int) points[i]; int y = (int) points[i + 1]; pixmap.drawLine(prevX, prevY, x, y); prevX = x; prevY = y; } } return pixmap; }
From source file:es.eucm.ead.engine.debugger.SimpleDebugger.java
License:Open Source License
public SimpleDebugger(Game game, GameLoader gameLoader) { this.setTouchable(Touchable.disabled); this.history = new Array<String>(); final CommandInterpreter commandInterpreter = new CommandInterpreter(game, gameLoader); BitmapFont font = new BitmapFont( Gdx.files.internal("es/eucm/ead/engine/resources/binary/fonts/ubuntu-16-bold.fnt"), true); this.setX(0); this.setY(580); Pixmap p = new Pixmap(10, 10, Pixmap.Format.RGBA8888); p.setColor(Color.BLACK);// w w w.ja va2s .c om p.fill(); TextureRegionDrawable background = new TextureRegionDrawable(new TextureRegion(new Texture(p))); p.dispose(); p = new Pixmap(2, 30, Pixmap.Format.RGBA8888); p.setColor(Color.WHITE); p.fill(); TextureRegionDrawable cursor = new TextureRegionDrawable(new TextureRegion(new Texture(p))); p.dispose(); Label.LabelStyle style = new Label.LabelStyle(); SpriteDrawable backgroundSprite = new SpriteDrawable(new Sprite(background.getRegion())); backgroundSprite.getSprite().setColor(new Color(0, 0, 0, 0.5f)); style.background = backgroundSprite; style.font = font; style.fontColor = Color.WHITE; result = new Label("", style); result.setWrap(true); int y = -100; result.setBounds(0, y, 800, -y); this.addActor(result); TextField.TextFieldStyle tfStyle = new TextField.TextFieldStyle(); tfStyle.font = font; tfStyle.background = background; tfStyle.selection = cursor; tfStyle.fontColor = Color.WHITE; tfStyle.cursor = cursor; interpreter = new TextField("", tfStyle); interpreter.setBounds(10, 0, 800, 20); interpreter.getStyle().font = font; interpreter.addListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode) { switch (keycode) { case Input.Keys.ENTER: String command = interpreter.getText(); if (history.size == 0 || !history.peek().equals(command)) { history.add(command); } historyPointer = history.size; result.setText(commandInterpreter.interpret(command)); interpreter.setText(""); break; case Input.Keys.ESCAPE: setVisible(false); break; case Input.Keys.UP: previousCommand(); break; case Input.Keys.DOWN: nextCommand(); break; } return true; } }); Button.ButtonStyle buttonStyle = new Button.ButtonStyle(); Label label = new Label(">", style); buttonStyle.up = background; button = new Button(label, buttonStyle); button.setHeight(20); button.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { setVisible(true); return false; } }); this.addActor(interpreter); setVisible(false); this.addActor(button); ((EAdEngine) Gdx.app.getApplicationListener()).getStage().addListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode) { switch (keycode) { case Input.Keys.F12: setVisible(true); break; } return false; } }); }
From source file:es.eucm.ead.engine.renderers.ShapesFactory.java
License:Open Source License
/** Creates a rectangle **/ private Pixmap createRectangle(Rectangle rectangle) { Bounds bounds = rectangle.getBounds(); originX = bounds.getLeft();// w w w. j a v a 2s . co m originY = bounds.getBottom(); int width = bounds.getRight() - bounds.getLeft(); pixmapHeight = bounds.getTop() - bounds.getBottom(); 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; }
From source file:es.eucm.ead.engine.renderers.ShapesFactory.java
License:Open Source License
/** Creates a polygon **/ private Pixmap createPolygon(Polygon schemaPolygon) { if (schemaPolygon.getPoints().size() < 6) { Gdx.app.error("ShapeFactory", "Invalid polygon. It contains less than 3 points."); return null; }/*from w w w. ja va2s .c o m*/ float[] points = new float[schemaPolygon.getPoints().size()]; for (int i = 0; i < schemaPolygon.getPoints().size(); i++) { points[i] = schemaPolygon.getPoints().get(i); // See comment in setGradientColor to understand this if (i % 2 != 0) { points[i] = pixmapHeight - points[i]; } } com.badlogic.gdx.math.Polygon polygon = new com.badlogic.gdx.math.Polygon(points); com.badlogic.gdx.math.Rectangle rectangle = polygon.getBoundingRectangle(); Pixmap pixmap = new Pixmap((int) rectangle.getWidth(), (int) rectangle.getHeight(), Format.RGBA8888); // Fill pixmap.setColor(color1); for (int i = 0; i < rectangle.getWidth(); i++) { for (int j = 0; j < rectangle.getHeight(); j++) { if (polygon.contains(i, j)) { if (useGradient) { setGradientColor(pixmap, i, j); } pixmap.drawPixel(i, j); } } } // Border if (hasBorder) { pixmap.setColor(borderColor); int prevX = (int) points[0]; int prevY = (int) points[1]; for (int i = 2; i < points.length; i += 2) { int x = (int) points[i]; int y = (int) points[i + 1]; pixmap.drawLine(prevX, prevY, x, y); prevX = x; prevY = y; } } return pixmap; }
From source file:es.eucm.ead.engine.utils.assetviewer.AssetApplicationListener.java
License:Open Source License
private void createBackgroundPattern() { Pixmap square = new Pixmap(patternSize * 2, patternSize, Pixmap.Format.RGB888); square.setColor(Color.GRAY);//from w w w .ja va2 s . c om square.fillRectangle(0, 0, patternSize, patternSize); square.setColor(Color.LIGHT_GRAY); square.fillRectangle(patternSize, 0, patternSize, patternSize); squareTexture = new Texture(square); square.dispose(); }
From source file:genuini.game.SkinManager.java
/** * Create a skin whith the parameter color * * @param color : text's color/*from ww w. ja v a 2 s. c o m*/ * @param dark : 1 if the color is dark ; 0 if it's light * @param width : text's width * @param height : text's height * @return skin : a Skin type */ public Skin textSkin(Color color, boolean dark, float width, float height) { if (dark) { skin.add("default", fontBlack); } else { skin.add("default", fontWhite); } Pixmap pixmap = new Pixmap((int) width, (int) height, Pixmap.Format.RGB888); pixmap.setColor(color); pixmap.fill(); skin.add("background", new Texture(pixmap)); return skin; }
From source file:genuini.game.SkinManager.java
/** * Create a skin whith the parameter color * * @param color : text's color/*from w ww . j a va2s . c o m*/ * @param dark : 1 if the color is dark ; 0 if it's light * @param width : text's width * @param height : text's height * @param texture : a special texture for the skin * @return skin : a Skin type */ public Skin textSkin(Color color, boolean dark, float width, float height, Texture texture) { if (dark) { skin.add("default", fontBlack); } else { skin.add("default", fontWhite); } Pixmap pixmap = new Pixmap((int) width, (int) height, Pixmap.Format.RGB888); pixmap.setColor(color); pixmap.fill(); skin.add(texture.toString(), new Texture(pixmap)); return skin; }
From source file:halive.shootinoutside.game.map.GameMapRenderer.java
public GameMapRenderer(GameMap map) { this.map = map; textureSheetPixmap = new Pixmap(map.getTextureSheet(), 0, map.getTextureSheet().length); textureSheet = new Texture(textureSheetPixmap); textureHandler = new GameMapTileTextureHandler(textureSheet); init();//from w w w. j a v a 2s . c o m }
From source file:headmade.arttag.service.FlickrService.java
License:Apache License
private void downloadAvailablePhotos(PhotoList<Photo> photos, final String... tags) { for (final Photo photo : photos) { executor.execute(new Runnable() { @Override//from ww w . ja va 2 s . c om public void run() { final byte[] bytes = new byte[1024 * 1024]; // assuming the content is not bigger than 1mb. final String url = photo.getMedium640Url(); final int numBytes = download(bytes, url); if (numBytes != 0) { // load the pixmap, make it a power of two if necessary (not needed for GL ES 2.0!) final Pixmap pixmap = new Pixmap(bytes, 0, numBytes); // final int originalWidth = pixmap.getWidth(); // final int originalHeight = pixmap.getHeight(); // final int width = MathUtils.nextPowerOfTwo(pixmap.getWidth()); // final int height = MathUtils.nextPowerOfTwo(pixmap.getHeight()); // final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat()); // potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); // pixmap.dispose(); Gdx.app.postRunnable(new Runnable() { @Override public void run() { // Gdx.app.log(TAG, "Successfully downloaded image from flickr " + url); final Texture image = new Texture(pixmap); final WebArt webart = new WebArt(photo, image); if (tags != null && tags.length > 0) { for (final String tag : tags) { Gdx.app.log(TAG, "Putting photo as control art for tag" + tag); if (controlWebArt.get(tag) == null) { controlWebArt.put(tag, new ArrayList<WebArt>()); } controlWebArt.get(tag).add(webart); } } else { availableWebArt.add(webart); } executor2.execute(new Runnable() { @Override public void run() { fetchTags(photo, webart); } }); } }); } } }); } }