List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap
public Pixmap(byte[] encodedData, int offset, int len)
From source file:at.tugraz.ist.catroid.content.Costume.java
License:Open Source License
protected Pixmap adjustBrightness(Pixmap currentPixmap) { Pixmap newPixmap = new Pixmap(currentPixmap.getWidth(), currentPixmap.getHeight(), currentPixmap.getFormat());//from w ww .j a va 2s .c o m for (int y = 0; y < currentPixmap.getHeight(); y++) { for (int x = 0; x < currentPixmap.getWidth(); x++) { int pixel = currentPixmap.getPixel(x, y); int r = (int) (((pixel >> 24) & 0xff) + (255 * (brightnessValue - 1))); int g = (int) (((pixel >> 16) & 0xff) + (255 * (brightnessValue - 1))); int b = (int) (((pixel >> 8) & 0xff) + (255 * (brightnessValue - 1))); int a = pixel & 0xff; if (r > 255) { r = 255; } else if (r < 0) { r = 0; } if (g > 255) { g = 255; } else if (g < 0) { g = 0; } if (b > 255) { b = 255; } else if (b < 0) { b = 0; } newPixmap.setColor(r / 255f, g / 255f, b / 255f, a / 255f); newPixmap.drawPixel(x, y); } } currentPixmap.dispose(); return newPixmap; }
From source file:at.tugraz.ist.catroid.plugin.Drone.other.DroneVideoCostume.java
License:Open Source License
public void initializeTexture() { Pixmap pixmap = new Pixmap(320, 240, Format.RGB888); pixmap.setColor(Color.BLUE);//from w w w. ja va 2 s . c o m pixmap.fill(); Texture texture = new Texture(pixmap, false); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); this.region = new TextureRegion(texture); this.width = this.region.getRegionWidth(); this.height = this.region.getRegionHeight(); this.x -= (this.width / 2f); this.y -= (this.height / 2f); this.originX = (this.width / 2f); this.originY = (this.height / 2f); pixmap.dispose(); firstStart = false; }
From source file:ateamproject.kezuino.com.github.render.screens.LobbyListScreen.java
private void createGui() { // Back to main menu. TextButton btnBack = new TextButton("Terug", skin); btnBack.addListener(new ClickListener() { @Override/* w w w. j av a2 s . c o m*/ public void clicked(InputEvent event, float x, float y) { game.setScreen(new MainScreen(game)); } }); btnBack.setPosition(10, stage.getHeight() - btnBack.getHeight() - 10); this.stage.addActor(btnBack); // Create game button. TextButton btnCreateGame = new TextButton("Maak spel", skin); btnCreateGame.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Dialog d = new Dialog("Lobby Name", skin); lobbyname = new TextField("", skin); SelectBox<Object> clanDropdown = null; String dropDownResult = ""; if (clanGame) { Client client = Client.getInstance(); PacketGetClans packet = new PacketGetClans(); client.send(packet); ArrayList<String> listclans = packet.getResult(); Object[] arrayClans = new Object[listclans.size()]; for (int i = 0; i < listclans.size(); i++) { arrayClans[i] = listclans.get(i); } clanDropdown = new SelectBox<>(skin); clanDropdown.setItems(arrayClans); clanDropdown.setSelectedIndex(0); d.add(clanDropdown); } TextButton btnsubmit = new TextButton("Maken", skin); lobbyname.setSize(150, 30); d.add(lobbyname); d.add(btnsubmit); final SelectBox dropDownResultFinal = clanDropdown; btnsubmit.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { d.hide(); if (!lobbyname.getText().equals("")) { if (clanGame) { game.setScreen(new LobbyScreen(game, lobbyname.getText(), dropDownResultFinal.getSelected().toString())); } else { game.setScreen(new LobbyScreen(game, lobbyname.getText(), null)); } } } }); d.show(stage); } }); // Create game button btnCreateGame.setPosition(stage.getWidth() - btnCreateGame.getWidth() - 10, stage.getHeight() - btnCreateGame.getHeight() - 10); this.stage.addActor(btnCreateGame); Pixmap pm1 = new Pixmap(1, 1, Pixmap.Format.RGB565); pm1.setColor(Color.GREEN); pm1.fill(); // set table position scrollTable = new Table(skin); scrollTable.setColor(com.badlogic.gdx.graphics.Color.BLUE); final ScrollPane scroller = new ScrollPane(scrollTable); scroller.sizeBy(200, 400); scroller.setColor(com.badlogic.gdx.graphics.Color.BLUE); final Table table = new Table(); table.setFillParent(false); table.add(scroller).fill().expand(); table.setSize(stage.getWidth(), stage.getHeight() - btnCreateGame.getHeight()); table.setColor(com.badlogic.gdx.graphics.Color.BLUE); // get all host from the server and put in the table fillHostTable(); float x = stage.getWidth() / 2 - table.getWidth() / 2; float y = stage.getHeight() - table.getHeight() - btnCreateGame.getHeight() - 20; table.setPosition(x, y); this.stage.addActor(table); }
From source file:base.Engine.java
License:Open Source License
public static Pixmap generatePatternPixmap(PatternEntry basedOn, Color color) { Pixmap returnPixmap = new Pixmap(basedOn.getWrapper().getW(), basedOn.getWrapper().getH(), Pixmap.Format.RGBA8888); returnPixmap.setColor(Color.rgba8888(0, 0, 0, 0)); returnPixmap.fill();/* ww w . ja v a2 s.c om*/ returnPixmap.setColor(Color.DARK_GRAY); returnPixmap.drawPixel(0, 0); returnPixmap.setColor(color); for (int x = 0; x < basedOn.getWrapper().getW(); x++) for (int y = 0; y < basedOn.getWrapper().getH(); y++) if (basedOn.getCells()[x][y] != 0) returnPixmap.drawPixel(x, y); return returnPixmap; }
From source file:be.ac.ucl.lfsab1509.bouboule.game.gameManager.GameLoop.java
License:Open Source License
/** * Launch the creation of the batch thanks to the camera. if debug == true, * set up the debugger matrix// w ww . j ava2 s. c o m * * @param cam : the OrthographicCamera of the game * @param debug : load the debugging matrix * * GameLoop(OrthographicCamera cam, boolean debug) */ public GameLoop(final OrthographicCamera cam, final boolean debug) { // creation of the batch and matrix (physical edges of the bodies) // debugger batch = new SpriteBatch(); batch.setProjectionMatrix(cam.combined); if (debug) { debugMatrix = new Matrix4(cam.combined); debugMatrix.scale(GraphicManager.getGameToWorld(), GraphicManager.getGameToWorld(), 1f); debugRenderer = new Box2DDebugRenderer(); } // Create only once the graphicManager graphicManager = new GraphicManager(); // Load the font fontOswald = new BitmapFont(Gdx.files.internal("fonts/Oswald/Oswald.fnt"), Gdx.files.internal("fonts/Oswald/Oswald.png"), false); fontOsaka = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"), Gdx.files.internal("fonts/Osaka/Osaka.png"), false); fontOsakaRed = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"), Gdx.files.internal("fonts/Osaka/Osaka.png"), false); fontOsakaRed.setColor(.95f, .05f, .05f, 1f); // Pause if (GlobalSettings.GAME.isGdxMenus()) { fontPause = new BitmapFont(Gdx.files.internal("fonts/OsakaBig/OsakaBig.fnt"), Gdx.files.internal("fonts/OsakaBig/OsakaBig.png"), false); fontPause.setColor(.95f, .05f, .05f, 1f); texturePause = new Texture("buttons/home_button.png"); pixmapFade = new Pixmap(1, 1, Format.RGB888); spriteFade = new Sprite(new Texture(pixmapFade)); spriteFade.setColor(0, 0, 0, 0); spriteFade.setSize(GlobalSettings.APPWIDTH * 2, GlobalSettings.APPHEIGHT * 2); // bigger size to cover all the zone spriteFade.setPosition(-GlobalSettings.APPWIDTH / 2, -GlobalSettings.APPHEIGHT / 2); } // load the counter countDown = new CountDown(2, 2, 1f, "anim/countdown.png", true); // 3 sec // new randomGenerator random = new Random(); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.AbstractScreen.java
License:Open Source License
public AbstractScreen(boolean bMusicNeedsDelay) { this.bMusicNeedsDelay = bMusicNeedsDelay; this.stage = new Stage(GlobalSettings.APPWIDTH, GlobalSettings.APPHEIGHT, true); // Added the camera to enter the screen (black borders on each side) this.stage.setCamera(GlobalSettings.GAME.getCamera()); if (GlobalSettings.GAME.isGdxMenus()) { // for the transition spriteFade = new Sprite(new Texture(new Pixmap(1, 1, Format.RGB888))); spriteFade.setColor(Color.BLACK); spriteFade.setSize(GlobalSettings.APPWIDTH, GlobalSettings.APPHEIGHT); }/*w ww . ja v a 2s. c o m*/ textureList = new ArrayList<Texture>(); }
From source file:ca.hiphiparray.amazingmaze.FishMiniGame.java
License:Open Source License
/** * Constructor for FishMiniGame.//from w w w .ja v a 2 s. com * * @param game the {@link AmazingMazeGame} instance that is managing this screen. * @param player the {@link Player} instance that completed the last level. */ public FishMiniGame(final AmazingMazeGame game, Player player) { this.game = game; this.player = player; fishNumber = new int[5]; fishNumber[0] = this.player.blueCollected; fishNumber[1] = this.player.purpleCollected; fishNumber[2] = this.player.greenCollected; fishNumber[3] = this.player.redCollected; fishNumber[4] = this.player.orangeCollected; answer = 0; for (int i = 0; i < fishNumber.length; i++) { answer += fishNumber[i] * fishValue[i]; } stage = new Stage(new ScreenViewport(), this.game.batch); menuTable = new Table(); fishTable = new Table(); canvas = new Canvas( new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() + shift, Pixmap.Format.RGB565)); menuTable.setFillParent(true); menuTable.top(); fishTable.bottom(); fishTable.setFillParent(true); fishImage = new Image[5]; TextureAtlas atlas = this.game.assets.manager.get(Assets.GAME_ATLAS_LOCATION, TextureAtlas.class); fishImage[0] = new Image(atlas.findRegion(Assets.FISH + Assets.BLUE_MODIFIER)); fishImage[0].setScale(4f); fishImage[1] = new Image(atlas.findRegion(Assets.FISH + Assets.PURPLE_MODIFIER)); fishImage[1].setScale(4f); fishImage[2] = new Image(atlas.findRegion(Assets.FISH + Assets.GREEN_MODIFIER)); fishImage[2].setScale(4f); fishImage[3] = new Image(atlas.findRegion(Assets.FISH + Assets.RED_MODIFIER)); fishImage[3].setScale(4f); fishImage[4] = new Image(atlas.findRegion(Assets.FISH + Assets.ORANGE_MODIFIER)); fishImage[4].setScale(4f); pencilButton = new Button(new TextureRegionDrawable( new TextureRegion(this.game.assets.manager.get(Assets.PENCIL_BUTTON, Texture.class)))); pencilButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { if (pencilButton.isPressed()) { canvas.setColor(drawColor); } } }); eraserButton = new Button(new TextureRegionDrawable( new TextureRegion(this.game.assets.manager.get(Assets.ERASER_BUTTON, Texture.class)))); eraserButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { if (eraserButton.isPressed()) { canvas.setColor(clearColor); } } }); helpButton = new Button(new TextureRegionDrawable( new TextureRegion(this.game.assets.manager.get(Assets.HELP_BUTTON, Texture.class)))); helpButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { if (helpButton.isPressed()) { Label.LabelStyle labelStyle = new Label.LabelStyle( game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE); final Dialog dialog = new Dialog("Help", game.assets.skin); final TextButton okButton = new TextButton("OK", game.assets.skin); dialog.getButtonTable().bottom(); Label label = new Label("Find the total value of fish that you retrieved!\n" + "Each colour corresponds to the colour of Canadian money.\n" + "The numbers correspond to each number of fish you got.\n\n" + "In case you forgot: blue is 5, purple is 10, green is 20, red is 50, and orange is 100.", labelStyle); label.setScale(.5f); label.setWrap(true); label.setAlignment(Align.center); dialog.add(label).width(500).pad(50); dialog.add(okButton).bottom(); okButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { if (okButton.isPressed()) { dialog.hide(); canvas.setColor(drawColor); } } }); dialog.key(Keys.ENTER, true); dialog.show(stage); } } }); checkButton = new Button(new TextureRegionDrawable( new TextureRegion(this.game.assets.manager.get(Assets.CHECK_BUTTON, Texture.class)))); checkButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { dialog(); } }); clearButton = new Button(new TextureRegionDrawable( new TextureRegion(this.game.assets.manager.get(Assets.CLEAR_BUTTON, Texture.class)))); clearButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { if (clearButton.isPressed()) { canvas.clear(); canvas.setColor(drawColor); } } }); answerField = new TextField("", game.assets.skin); answerField.setTextFieldListener(new TextFieldListener() { @Override public void keyTyped(TextField textField, char key) { if (key == (char) 13) { stage.unfocus(answerField); dialog(); } } }); stage.addActor(menuTable); stage.addActor(canvas); stage.addActor(fishTable); menuTable.clear(); fishTable.clear(); helpButton.right(); menuTable.background(new TextureRegionDrawable( new TextureRegion(this.game.assets.manager.get(Assets.MINI_BACKGROUND, Texture.class)))); menuTable.add(pencilButton).pad(10).size(64); menuTable.add(eraserButton).pad(10).size(64); menuTable.add(clearButton).pad(10).size(64); menuTable.add(helpButton).pad(10).size(64); menuTable.row(); Label.LabelStyle labelStyle = new Label.LabelStyle( game.assets.getFont(Assets.SANS_REGULAR, Assets.REGULAR_FONT_SIZE), Color.WHITE); for (int i = 0; i < 5; i++) { fishTable.add(fishImage[i]).bottom().left().padLeft(10); } fishTable.add(answerField).minWidth(150).padLeft(150); fishTable.add(checkButton).pad(10).size(64); fishTable.row(); for (int i = 0; i < 5; i++) { fishTable.add(new Label(fishNumber[i] + "", labelStyle)).pad(30).center(); } fishTable.row(); setupPauseMenu(); input = new InputMultiplexer(stage, this); input.addProcessor(pauseMenu); }
From source file:CB_Locator.Map.TileGL_Bmp.java
License:Open Source License
private void createTexture() { if (inCreation) return;/* w w w . java2 s . co m*/ inCreation = true; if (GL.isGlThread()) { if (texture != null) return; if (bytes == null) return; try { Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); texture = new Texture(pixmap, format, CB_UI_Base_Settings.useMipMap.getValue()); pixmap.dispose(); pixmap = null; } catch (Exception ex) { Log.debug(log, "[TileGL] can't create Pixmap or Texture: " + ex.getMessage()); } bytes = null; inCreation = false; } else { // create Texture on next GlThread GL.that.RunOnGL(new IRunOnGL() { @Override public void run() { if (isDisposed) return; if (texture != null) return; if (bytes == null) return; try { Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); texture = new Texture(pixmap, format, CB_UI_Base_Settings.useMipMap.getValue()); pixmap.dispose(); pixmap = null; } catch (Exception ex) { Log.debug(log, "[TileGL] can't create Pixmap or Texture: " + ex.getMessage()); } bytes = null; inCreation = false; GL.that.renderOnce(); } }); } }
From source file:CB_Locator.Map.ZoomScale.java
License:Open Source License
/** * Zeichnet die Scala in eine Bitmap, damit diese als Sprite benutzt werden kann! * //from w ww. j ava 2s. co m * @param rect */ private Sprite drawSprite(CB_RectF rect) { if (rect == null) return null; if (storedRec == null || !(storedRec.equals(rect))) { storedRec = rect.copy(); ValueRec = null; } int y = 0; if (ValueRec == null) { topRow = (int) rect.getHeight() - 2; bottomRow = 2; centerColumn = (int) (rect.getWidth() / 2); halfWidth = (int) (rect.getWidth() / 4); lineHeight = 10; numSteps = maxzoom - minzoom; grundY = rect.getY() - halfWidth; // dist = (bottomRow - topRow) / numSteps; y = (int) ((1 - ((zoom) - minzoom) / numSteps) * (bottomRow - topRow)) + topRow; ValueRec = new CB_RectF( rect.getX() + GL_UISizes.infoShadowHeight + centerColumn - rect.getWidth() / 2 - lineHeight / 2, grundY + y, rect.getWidth(), rect.getWidth() / 2); } else { y = (int) ((1 - ((zoom) - minzoom) / numSteps) * (bottomRow - topRow)) + topRow; ValueRec.setY(grundY + y); } if (CachedScaleSprite != null) return CachedScaleSprite; disposeTexture(); // int w = getNextHighestPO2((int) getWidth()); // int h = getNextHighestPO2((int) getHeight()); int w = (int) getWidth(); int h = (int) getHeight(); CachedScalePixmap = new Pixmap(w, h, Pixmap.Format.RGBA4444); CachedScalePixmap.setColor(0f, 0f, 0f, 1f); CachedScalePixmap.drawLine(centerColumn, bottomRow, centerColumn, topRow); for (int i = minzoom; i <= maxzoom; i++) { y = (int) ((1 - (i - minzoom) / numSteps) * (bottomRow - topRow)) + topRow; CachedScalePixmap.drawRectangle(3, y, (int) getWidth() - 3, 1); } CachedScaleTexture = new Texture(CachedScalePixmap); CachedScaleSprite = new Sprite(CachedScaleTexture, (int) rect.getWidth(), (int) rect.getHeight()); return CachedScaleSprite; }
From source file:CB_UI.GL_UI.Activitys.MeasureCoordinate.java
License:Open Source License
private void repaintPreview() { if (inRepaint.get()) return;/* ww w.j av a 2 s. co m*/ inRepaint.set(true); disposeTexture(); CB_RectF panelRec = new CB_RectF(leftBorder, bOK.getMaxY(), innerWidth, innerWidth); int w = (int) panelRec.getWidth(); int h = (int) panelRec.getHeight(); drawingPixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888); drawingPixmap.setColor(Color.LIGHT_GRAY); drawingPixmap.fillRectangle(0, 0, (int) panelRec.getWidth(), (int) panelRec.getHeight()); int centerX = (int) panelRec.getHalfWidth(); int centerY = (int) panelRec.getHalfHeight(); float minPix = Math.min(panelRec.getWidth(), panelRec.getHeight()); try { synchronized (mMeasureList) { if (mMeasureList.size() > 0) { // Gemittelter Punkt der GPS-Messungen double medianLat = MeasuredCoord.Referenz.getLatitude(); double medianLon = MeasuredCoord.Referenz.getLongitude(); MeasuredCoordList sortetdList = (MeasuredCoordList) mMeasureList.clone(); sortetdList.sort(); double peakLat = Math.max(Math.abs(sortetdList.get(0).getLatitude() - medianLat), Math.abs(sortetdList.get(sortetdList.size() - 1).getLatitude() - medianLat)); double peakLon = Math.max(Math.abs(sortetdList.get(0).getLongitude() - medianLon), Math.abs(sortetdList.get(sortetdList.size() - 1).getLongitude() - medianLon)); // Umrechnung in XY double medianX = Descriptor.LongitudeToTileX(projectionZoom, medianLon); double medianY = Descriptor.LatitudeToTileY(projectionZoom, medianLat); double extremeX = Descriptor.LongitudeToTileX(projectionZoom, peakLon + medianLon); double extremeY = Descriptor.LatitudeToTileY(projectionZoom, peakLat + medianLat); double peakX = Math.abs(extremeX - medianX); double peakY = Math.abs(extremeY - medianY); double maxPeak = Math.max(peakX, peakY); double factor = 1; if (maxPeak > 0) factor = minPix / maxPeak; factor /= 2; int x = (int) centerX; int y = (int) centerY; // Track zeichnen for (int i = 1; i < mMeasureList.size(); i++) { PointD lastDrawEntry = Descriptor.projectCoordinate(mMeasureList.get(i - 1).getLatitude(), mMeasureList.get(i - 1).getLongitude(), projectionZoom); int lastX = (int) (centerX + (lastDrawEntry.X - medianX) * factor); int lastY = (int) (centerY - (lastDrawEntry.Y - medianY) * factor); PointD thisDrawEntry = Descriptor.projectCoordinate(mMeasureList.get(i).getLatitude(), mMeasureList.get(i).getLongitude(), projectionZoom); x = (int) (centerX + (thisDrawEntry.X - medianX) * factor); y = (int) (centerY - (thisDrawEntry.Y - medianY) * factor); drawingPixmap.setColor(Color.RED); drawingPixmap.drawLine(lastX, lastY, x, y); } drawingPixmap.setColor(Color.BLUE); drawingPixmap.drawCircle(x, y, 4); } } // int m2 = (int) ((4 * minPix) / metersPerTile); int m4 = m2 * 2; drawingPixmap.setColor(Color.BLACK); drawingPixmap.drawCircle(centerX, centerY, m2); drawingPixmap.drawCircle(centerX, centerY, m4); drawingPixmap.drawLine(centerX, 0, centerX, (int) panelRec.getHeight()); drawingPixmap.drawLine(0, centerY, (int) panelRec.getWidth(), centerY); drawingTexture = new Texture(drawingPixmap); drawing = new Sprite(drawingTexture, (int) panelRec.getWidth(), (int) panelRec.getHeight()); drawing.setX(leftBorder); drawing.setY(bOK.getMaxY() + this.getBottomHeight()); inRepaint.set(false); } catch (Exception e) { e.printStackTrace(); } redraw = false; GL.that.renderOnce(); }