Java Code Examples for com.badlogic.gdx.graphics.Pixmap#setColor()

The following examples show how to use com.badlogic.gdx.graphics.Pixmap#setColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextureCache.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static SmartTexture createSolid( int color ) {
	final String key = "1x1:" + color;
	
	if (all.containsKey( key )) {
		
		return all.get( key );
		
	} else {

		final Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
		// In the rest of the code ARGB is used
		pixmap.setColor( (color << 8) | (color >>> 24) );
		pixmap.fill();

		SmartTexture tx = new SmartTexture( pixmap );
		all.put(key, tx);

		return tx;
	}
}
 
Example 2
Source File: TextureCache.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static SmartTexture createSolid( int color ) {
	final String key = "1x1:" + color;
	
	if (all.containsKey( key )) {
		
		return all.get( key );
		
	} else {
		
		Pixmap pixmap =new Pixmap( 1, 1, Pixmap.Format.RGBA8888 );
		// In the rest of the code ARGB is used
		pixmap.setColor( (color << 8) | (color >>> 24) );
		pixmap.fill();
		
		SmartTexture tx = new SmartTexture( pixmap );
		all.put( key, tx );
		
		return tx;
	}
}
 
Example 3
Source File: Palette.java    From riiablo with Apache License 2.0 6 votes vote down vote up
/**
 * Renders a pixmap as a sheet with each pixel taking {@code cellsize} square pixels. Used to show
 * a more user-readable representation of the palette.
 */
public Texture render(int cellsize) {
  final int cells   = 16;
  final int size    = cells * cellsize;
  final int rows    = cells;
  final int columns = cells;

  Pixmap pixmap = new Pixmap(size, size, Pixmap.Format.RGBA8888);
  for (int r = 0, i = 0, x = 0, y = 0; r < rows; r++, x = 0, y += cellsize) {
    for (int c = 0; c < columns; c++, i++, x += cellsize) {
      pixmap.setColor(colors[i] | 0xFF); // Removes alpha transparency
      pixmap.fillRectangle(x, y, cellsize, cellsize);
    }
  }

  Texture texture = new Texture(pixmap);
  texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
  pixmap.dispose();
  return texture;
}
 
Example 4
Source File: Textures.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public Texture createTexture(Color color) {
  Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
  pixmap.setColor(color);
  pixmap.fill();
  Texture texture = new Texture(pixmap);
  pixmap.dispose();
  return texture;
}
 
Example 5
Source File: AOTextureGenerator.java    From Cubes with MIT License 5 votes vote down vote up
private static void setupPixmap(Pixmap p, int i, Color c) {
  p.setColor(c);

  if ((i & AmbientOcclusion.A) == AmbientOcclusion.A) p.fillRectangle(0, 0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.B) == AmbientOcclusion.B) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE, 0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.C) == AmbientOcclusion.C) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, 0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);

  if ((i & AmbientOcclusion.D) == AmbientOcclusion.D) p.fillRectangle(0, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.E) == AmbientOcclusion.E) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);

  if ((i & AmbientOcclusion.F) == AmbientOcclusion.F) p.fillRectangle(0, AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.G) == AmbientOcclusion.G) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
  if ((i & AmbientOcclusion.H) == AmbientOcclusion.H) p.fillRectangle(AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE * 2, AmbientOcclusion.INDIVIDUAL_SIZE, AmbientOcclusion.INDIVIDUAL_SIZE);
}
 
Example 6
Source File: FogOfWar.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public FogOfWar( int mapWidth, int mapHeight ) {
	
	super();

	this.mapWidth = mapWidth;
	this.mapHeight = mapHeight;
	mapLength = mapHeight * mapWidth;
	
	pWidth = mapWidth * PIX_PER_TILE;
	pHeight = mapHeight * PIX_PER_TILE;
	
	width2 = 1;
	while (width2 < pWidth) {
		width2 <<= 1;
	}
	
	height2 = 1;
	while (height2 < pHeight) {
		height2 <<= 1;
	}
	
	float size = DungeonTilemap.SIZE / PIX_PER_TILE;
	width = width2 * size;
	height = height2 * size;

	//TODO might be nice to compartmentalize the pixmap access and modification into texture/texturecache
	Pixmap px = new Pixmap(width2, height2, Pixmap.Format.RGBA8888);
	px.setBlending(Pixmap.Blending.None);
	px.setColor(0x000000FF);
	px.fill();
	SmartTexture tx = new SmartTexture(px, Texture.LINEAR, Texture.CLAMP, false);
	TextureCache.add(FogOfWar.class, tx);
	texture( tx );
	
	scale.set( size, size );

	toUpdate = new ArrayList<>();
	toUpdate.add(new Rect(0, 0, mapWidth, mapHeight));
}
 
Example 7
Source File: ShapeTextureCache.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a filled rectangular texture for the provided {@link LibgdxColor}
 *
 * @param color
 *            The {@link LibgdxColor} to fetch a texture of
 * @return A new {@link Texture} if this is first time it has been
 *         requested, otherwise it will return a cached instance of the
 *         {@link Texture} for the given {@link LibgdxColor}
 */
public Texture getFilledRectangleTexture(LibgdxColor color) {
	int bits = color.color.toIntBits();
	if (!filledRectangleTextures.containsKey(bits)) {
		Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
		pixmap.setColor(color.color);
		pixmap.fillRectangle(0, 0, 1, 1);
		filledRectangleTextures.put(bits, new Texture(pixmap));
		pixmap.dispose();
	}
	return filledRectangleTextures.get(bits);
}
 
Example 8
Source File: PickerCommons.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void createPixmap () {
	Pixmap whitePixmap = new Pixmap(2, 2, Format.RGB888);
	whitePixmap.setColor(Color.WHITE);
	whitePixmap.drawRectangle(0, 0, 2, 2);
	whiteTexture = new Texture(whitePixmap);
	whiteTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
	whitePixmap.dispose();
}
 
Example 9
Source File: BGDrawer.java    From libGDX-Path-Editor with Apache License 2.0 5 votes vote down vote up
public BGDrawer() {
	renderer = new ShapeRenderer();
	
	Pixmap p = new Pixmap(4, 4, Format.RGBA4444);
	p.setColor(0.698f, 0.698f, 0.698f, 1f);
	p.fill();
	overlay = new Texture(p);
	p.dispose();
	
	t = new Sprite(overlay);
	b = new Sprite(overlay);
	l = new Sprite(overlay);
	r = new Sprite(overlay);
}
 
Example 10
Source File: Theme.java    From Klooni1010 with GNU General Public License v3.0 5 votes vote down vote up
public static Texture getBlankTexture() {
    final Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    final Texture result = new Texture(pixmap);
    pixmap.dispose();
    return result;
}
 
Example 11
Source File: ColorFadeTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
/** @param color the {@link Color} to fade to
 * @param interpolation the {@link Interpolation} method */
public ColorFadeTransition (Color color, Interpolation interpolation) {
	this.color = new Color(Color.WHITE);
	this.interpolation = interpolation;

	texture = new Texture(1, 1, Format.RGBA8888);
	Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
	pixmap.setColor(color);
	pixmap.fillRectangle(0, 0, 1, 1);
	texture.draw(pixmap, 0, 0);
}
 
Example 12
Source File: NinePatchEditorModel.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** @return original image pixmap with 1-pixel border 9-patch markup. */
public Pixmap prepareNinePatchPixmap() {
    Pixmap patchPixmap = new Pixmap(this.pixmap.getWidth() + 2, this.pixmap.getHeight() + 2, this.pixmap.getFormat());
    patchPixmap.setBlending(Pixmap.Blending.None);
    patchPixmap.drawPixmap(pixmap, 1, 1);

    patchPixmap.setColor(0x000000ff);
    if (patchValues.left.get() != 0 && patchValues.right.get() != 0) {
        for (int x = patchValues.left.get(); x < (pixmap.getWidth() - patchValues.right.get()); x++) {
            patchPixmap.drawPixel(x+1, 0);
        }
    }
    if (patchValues.top.get() != 0 && patchValues.bottom.get() != 0) {
        for (int y = patchValues.top.get(); y < (pixmap.getHeight() - patchValues.bottom.get()); y++) {
            patchPixmap.drawPixel(0, y+1);
        }
    }
    if (contentValues.left.get() != 0 && contentValues.right.get() != 0) {
        for (int x = contentValues.left.get(); x < (pixmap.getWidth() - contentValues.right.get()); x++) {
            patchPixmap.drawPixel(x+1, pixmap.getHeight()+1);
        }
    }
    if (contentValues.top.get() != 0 && contentValues.bottom.get() != 0) {
        for (int y = contentValues.top.get(); y < (pixmap.getHeight() - contentValues.bottom.get()); y++) {
            patchPixmap.drawPixel(pixmap.getWidth()+1, y+1);
        }
    }
    return patchPixmap;
}
 
Example 13
Source File: Halo.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public Halo() {
	super();
	
	if (!TextureCache.contains( CACHE_KEY )) {
		Pixmap pixmap = new Pixmap(RADIUS * 2, RADIUS * 2, Pixmap.Format.RGBA8888);
		pixmap.setColor( 0xFFFFFF0A );
		for (int i = 0; i < 50; i++) {
			pixmap.fillCircle(RADIUS, RADIUS, (int)(RADIUS * (i+1)/50f));
		}
		TextureCache.add( CACHE_KEY, new SmartTexture( pixmap ) );
	}
	
	texture( CACHE_KEY );
}
 
Example 14
Source File: TImage.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
public static TImage makeAlphaImage(float w, float h) {
    Pixmap pixmap = new Pixmap((int) w, (int) h, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.BLACK);
    pixmap.fill();
    Texture texture = new Texture(pixmap);
    TImage image = new TImage(texture);
    image.addAction(Actions.alpha(0.5f));
    return image;
}
 
Example 15
Source File: CCPanel.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    Table table = new Table();

    Size size = widget.getSize();
    if (widget.getComboBoxIndex() == 0) { // 无颜色

    } else if (widget.getComboBoxIndex() == 1 && widget.getBackColorAlpha() != 0) {// 单色
        Pixmap pixmap = new Pixmap((int) size.getX(), (int) size.getY(),
            Format.RGBA8888);

        pixmap.setColor(editor.getColor(widget.getSingleColor(),
            widget.getBackColorAlpha()));

        pixmap.fill();

        Drawable d = new TextureRegionDrawable(new TextureRegion(
            new Texture(pixmap)));
        table.setBackground(d);
        pixmap.dispose();
    }

    if (widget.getFileData() != null) {// Panel的图片并不是拉伸平铺的!!.但是这里修改为填充
        Drawable tr = editor.findDrawable(widget, widget.getFileData());
        if (tr != null) {
            Image bg = new Image(tr);
            bg.setPosition((size.getX() - bg.getWidth()) / 2,
                (size.getY() - bg.getHeight()) / 2);
            // bg.setFillParent(true);
            bg.setTouchable(Touchable.disabled);

            table.addActor(bg);
        }
    }

    table.setClip(widget.isClipAble());

    return table;
}
 
Example 16
Source File: SplatMap.java    From Mundus with Apache License 2.0 4 votes vote down vote up
public void clear() {
    Pixmap pixmap = getPixmap();
    pixmap.setColor(0, 0, 0, 0);
    pixmap.fillRectangle(0, 0, pixmap.getWidth(), pixmap.getHeight());
    updateTexture();
}
 
Example 17
Source File: FogOfWar.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
private void fillRight( Pixmap fog, int x, int y, int color){
	fog.setColor((color << 8) | (color >>> 24));
	fog.fillRectangle(x * PIX_PER_TILE + PIX_PER_TILE/2, y*PIX_PER_TILE, PIX_PER_TILE/2, PIX_PER_TILE);
}
 
Example 18
Source File: FogOfWar.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
private void fillCell( Pixmap fog, int x, int y, int color){
	fog.setColor((color << 8) | (color >>> 24));
	fog.fillRectangle(x * PIX_PER_TILE, y*PIX_PER_TILE, PIX_PER_TILE, PIX_PER_TILE);
}
 
Example 19
Source File: Hud.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
public Hud(SpriteBatch batch, float width, float height) {
    this.batch = batch;

    AssetManager assetManager = GameManager.getInstance().getAssetManager();
    textureAtlas = assetManager.get("img/actors.pack", TextureAtlas.class);
    bombSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Bomb"), 0, 0, 16, 16));
    bombSprite.setBounds(15.0f, 11.5f, 1, 1);

    Pixmap pixmap = new Pixmap(5, 15, Pixmap.Format.RGBA8888);
    pixmap.setColor(240.0f / 255.0f, 128 / 255.0f, 0, 1.0f);
    pixmap.fill();

    bgTexture = new Texture(pixmap);

    pixmap.setColor(1, 1, 1, 1);
    pixmap.fill();
    bombTimerTexture = new Texture(pixmap);
    pixmap.dispose();

    bombTimerSprite = new Sprite(bombTimerTexture);
    bombTimerSprite.setBounds(16f, 12.5f, 3.0f, 0.2f);

    TextureRegion itemTextureRegion = textureAtlas.findRegion("Items");
    powerSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 1, 0, 16, 16));
    powerSprite.setBounds(leftAlignment, 9.0f, 1, 1);

    speedSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 2, 0, 16, 16));
    speedSprite.setBounds(leftAlignment, 8.0f, 1, 1);

    kickSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 3, 0, 16, 16));
    kickSprite.setBounds(leftAlignment, 7.0f, 1, 1);

    remoteSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 4, 0, 16, 16));
    remoteSprite.setBounds(leftAlignment, 6.0f, 1, 1);

    Array<TextureRegion> keyFrames = new Array<TextureRegion>();
    for (int i = 0; i < 5; i++) {
        keyFrames.add(new TextureRegion(textureAtlas.findRegion("Bomberman_big"), 32 * i, 0, 32, 48));
    }
    bigBombermanAnimation = new Animation(0.2f, keyFrames, Animation.PlayMode.LOOP_PINGPONG);
    bigBombermanSprite = new Sprite(bigBombermanAnimation.getKeyFrame(0));
    bigBombermanSprite.setBounds(17.5f, 0.5f, 2f, 3f);
    stateTime = 0;

    FitViewport viewport = new FitViewport(width * SCALE, height * SCALE);
    stage = new Stage(viewport, batch);
    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
    fpsLabel = new Label("FPS:", labelStyle);
    fpsLabel.setFontScale(0.3f);
    fpsLabel.setPosition(16 * SCALE, -0.8f * SCALE);
    fpsLabel.setVisible(showFPS);
    
    levelLabel = new Label("Level", labelStyle);
    levelLabel.setPosition(15.5f * SCALE, 3 * SCALE);
    levelLabel.setFontScale(0.4f);

    playerLivesLabel = new Label("" + GameManager.playerLives, labelStyle);
    playerLivesLabel.setFontScale(0.5f);
    playerLivesLabel.setPosition(16.8f * SCALE, 12.8f * SCALE);

    Image bombermanImage = new Image(new TextureRegion(textureAtlas.findRegion("Items"), 16 * 5, 0, 16, 16));
    bombermanImage.setPosition(leftAlignment * SCALE, 13.5f * SCALE);

    xLabel = new Label("X", labelStyle);
    xLabel.setFontScale(0.4f);
    xLabel.setPosition(16.8f * SCALE, 6.3f * SCALE);

    zLabel = new Label("Z", labelStyle);
    zLabel.setFontScale(0.4f);
    zLabel.setPosition(16.8f * SCALE, 5.3f * SCALE);

    stage.addActor(fpsLabel);
    stage.addActor(levelLabel);
    stage.addActor(playerLivesLabel);
    stage.addActor(bombermanImage);
    stage.addActor(xLabel);
    stage.addActor(zLabel);
    
    stringBuilder = new StringBuilder();
    
}
 
Example 20
Source File: NinePatchEditorDialog.java    From gdx-skineditor with Apache License 2.0 2 votes vote down vote up
public void refreshPreview() {

		Gdx.app.log("NinePatchEditorDialog","refresh preview.");

		Pixmap pixmapImage = new Pixmap(Gdx.files.internal(textSourceImage.getText()));
		
		Pixmap pixmap = new Pixmap((int) (pixmapImage.getWidth()+2), (int) (pixmapImage.getHeight()+2), Pixmap.Format.RGBA8888);
		pixmap.drawPixmap(pixmapImage,1,1);

		pixmap.setColor(Color.BLACK);
		
		// Range left
		int h = pixmapImage.getHeight()+1;
		pixmap.drawLine(0, (int) (h * rangeLeft.rangeStart),0, (int) (h * rangeLeft.rangeStop));
		

		// Range top
		int w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeTop.rangeStart), 0,(int) (w * rangeTop.rangeStop), 0);

		// Range right
		h = pixmapImage.getHeight()+1;
		pixmap.drawLine(pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStart),pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStop));

		// Range bottom
		w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeBottom.rangeStart), pixmap.getHeight()-1,(int) (w * rangeBottom.rangeStop), pixmap.getHeight()-1);
		
		
		PixmapIO.writePNG(tmpFile, pixmap);
		
		pixmapImage.dispose();
		pixmap.dispose();

		FileHandle fh = new FileHandle(System.getProperty("java.io.tmpdir")).child("skin_ninepatch");
		TexturePacker.Settings settings = new TexturePacker.Settings();
		TexturePacker.process(settings, fh.path(), fh.path(), "pack");

		TextureAtlas ta = new TextureAtlas(fh.child("pack.atlas"));
		NinePatch np = ta.createPatch("button");
		NinePatchDrawable drawable = new NinePatchDrawable(np);
		reviewTablePreview();	
		buttonPreview1.getStyle().up = drawable;
		

	}