Skip to content

Commit

Permalink
Texture Eraser
Browse files Browse the repository at this point in the history
  • Loading branch information
Fexcraft committed May 29, 2022
1 parent 2dda623 commit cc0e284
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ editor.texture.brushes.group_bucket=Group Paint Bucket
editor.texture.brushes.pixel_pencil=Pixel Paint Pencil
editor.texture.brushes.color_picker=Color Picker
editor.texture.brushes.current=Current:
editor.texture.brushes.eraser=Eraser:
editor.fields.reset.uppercase=RESET

# Dialogs
Expand Down
3 changes: 2 additions & 1 deletion src/net/fexcraft/app/fmt/ui/editor/Editors.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static void hideAll(){

public static void show(String type){
hideAll();
TextureEditor.toggleBucketMode(null);
TextureEditor.toggleBucketMode(null, null);
TextureEditor.toggleBucketMode(null, false);
switch(type){
case "general": general.show(); break;
case "group": group.show(); break;
Expand Down
37 changes: 26 additions & 11 deletions src/net/fexcraft/app/fmt/ui/editor/TextureEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

public class TextureEditor extends EditorBase {

public static RGB CURRENTCOLOR = new RGB(RGB.WHITE);
private static RGB CURRENTCOLOR = new RGB(RGB.WHITE), ERASE = new RGB(0, 0, 0).setAlpha(0);
public static ColorPanel[] panels = new ColorPanel[18 * 18];
public static ColorField colorfield;
public static ColorPanel current;
public static Icon face, polygon, group, pencil, picker;
public static FunctionButton current_tool;
public static FunctionButton current_tool, eraser_button;
//
private static PaintMode PMODE;
private static boolean eraser;
private static final int rows = 18;

public TextureEditor(){
Expand Down Expand Up @@ -91,12 +92,13 @@ else if(c > (5/6f) && c <= 1 ){
//String off = translate("editor.texture.brushes.tool_off");
pass += 24;
int off = 55;
brushes.getContainer().add(pencil = new Icon(off, pass, 0, "./resources/textures/icons/editors/texture/pixel.png", "editor.texture.brushes.pixel_pencil", () -> toggleBucketMode(PaintMode.PIXEL)));
brushes.getContainer().add(face = new Icon(off, pass, 1, "./resources/textures/icons/editors/texture/face.png", "editor.texture.brushes.face_bucket", () -> toggleBucketMode(PaintMode.FACE)));
brushes.getContainer().add(polygon = new Icon(off, pass, 2, "./resources/textures/icons/editors/texture/polygon.png", "editor.texture.brushes.polygon_bucket", () -> toggleBucketMode(PaintMode.POLYGON)));
brushes.getContainer().add(group = new Icon(off, pass, 3, "./resources/textures/icons/editors/texture/group.png", "editor.texture.brushes.group_bucket", () -> toggleBucketMode(PaintMode.GROUP)));
brushes.getContainer().add(picker = new Icon(off, pass, 4, "./resources/textures/icons/editors/texture/color_picker.png", "editor.texture.brushes.color_picker", () -> toggleBucketMode(PaintMode.COLORPICKER)));
brushes.getContainer().add(current_tool = new FunctionButton(translate("editor.texture.brushes.current") + " NONE", 3, pass += 24 + 12, 290, 20, () -> toggleBucketMode(null)));
brushes.getContainer().add(pencil = new Icon(off, pass, 0, "./resources/textures/icons/editors/texture/pixel.png", "editor.texture.brushes.pixel_pencil", () -> toggleBucketMode(PaintMode.PIXEL, null)));
brushes.getContainer().add(face = new Icon(off, pass, 1, "./resources/textures/icons/editors/texture/face.png", "editor.texture.brushes.face_bucket", () -> toggleBucketMode(PaintMode.FACE, null)));
brushes.getContainer().add(polygon = new Icon(off, pass, 2, "./resources/textures/icons/editors/texture/polygon.png", "editor.texture.brushes.polygon_bucket", () -> toggleBucketMode(PaintMode.POLYGON, null)));
brushes.getContainer().add(group = new Icon(off, pass, 3, "./resources/textures/icons/editors/texture/group.png", "editor.texture.brushes.group_bucket", () -> toggleBucketMode(PaintMode.GROUP, null)));
brushes.getContainer().add(picker = new Icon(off, pass, 4, "./resources/textures/icons/editors/texture/color_picker.png", "editor.texture.brushes.color_picker", () -> toggleBucketMode(PaintMode.COLORPICKER, null)));
brushes.getContainer().add(current_tool = new FunctionButton(translate("editor.texture.brushes.current") + " NONE", 3, pass += 24 + 12, 290, 20, () -> toggleBucketMode(null, null)));
brushes.getContainer().add(eraser_button = new FunctionButton(translate("editor.texture.brushes.eraser") + " OFF", 3, pass += 24 + 12, 290, 20, () -> toggleBucketMode(null, !eraser)));
brushes.setSize(296, pass + 52);
this.addSub(brushes); pass = -20;
//
Expand Down Expand Up @@ -175,9 +177,14 @@ public static int opposite(RGB rgb){
return 0xFFFFFF - rgb.packed;
}

public static void toggleBucketMode(PaintMode mode){
PMODE = mode == null || PMODE == mode ? null : mode;
public static void toggleBucketMode(PaintMode mode, Boolean erase){
if(erase == null){
PMODE = mode == null || PMODE == mode ? null : mode;
if(PMODE == null) eraser = false;
}
else eraser = erase;
current_tool.getTextState().setText(translate("editor.texture.brushes.current") + " " + (PMODE == null ? "none" : PMODE.lang()));
eraser_button.getTextState().setText(translate("editor.texture.brushes.eraser") + " " + (eraser ? "ON" : "OFF"));
}

public static enum PaintMode {
Expand Down Expand Up @@ -224,7 +231,15 @@ public static boolean isPaintActive(){
}

public static void reset(){
toggleBucketMode(null); PMODE = null;
eraser = false;
toggleBucketMode(null, null);
PMODE = null;
}

public static byte[] getCurrentColor(){
byte[] b = (eraser ? ERASE : CURRENTCOLOR).toByteArray();
float a = (eraser ? ERASE : CURRENTCOLOR).alpha;
return new byte[]{ b[0], b[1], b[2], (byte)(Math.floor(a >= 1.0f ? 255 : a * 256.0f) - 128) };
}

}
6 changes: 3 additions & 3 deletions src/net/fexcraft/app/fmt/utils/RayCoastAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void doTest(boolean bool, boolean mouseoff, boolean pencil){
TextureGroup group = lastsel.getTextureGroup();
if(group == null || (tex = group.texture) == null){
DialogBox.show(null, "dialog.button.ok", "polygon_picker.paint_bucket.toggle_off", null, () -> {
TextureEditor.toggleBucketMode(null);
TextureEditor.toggleBucketMode(null, null);
}, "polygon_picker.paint_bucket.no_texture");
return;
}
Expand All @@ -83,7 +83,7 @@ public static void doTest(boolean bool, boolean mouseoff, boolean pencil){
}
else{*/
//log(x + " " + y);
tex.set(x, y, TextureEditor.CURRENTCOLOR.toByteArray());
tex.set(x, y, TextureEditor.getCurrentColor());
tex.rebind();
//TXO tex.save();
return;
Expand Down Expand Up @@ -113,7 +113,7 @@ public static void doTest(boolean bool, boolean mouseoff, boolean pencil){
TextureGroup group = wrapper.getTextureGroup();
if(group == null || (tex = group.texture) == null){
DialogBox.show(null, "dialog.button.ok", "polygon_picker.paint_bucket.toggle_off", null, () -> {
TextureEditor.toggleBucketMode(null);
TextureEditor.toggleBucketMode(null, null);
}, "polygon_picker.paint_bucket.no_texture");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/net/fexcraft/app/fmt/utils/texture/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void set(int x, int y, byte[] rgb){
buffer.put(pos + 0, (byte)(rgb[0] + 128));
buffer.put(pos + 1, (byte)(rgb[1] + 128));
buffer.put(pos + 2, (byte)(rgb[2] + 128));
buffer.put(pos + 3, (byte)255);
buffer.put(pos + 3, (byte)(rgb.length > 3 ? rgb[3] + 128 : 255));
}

public byte[] get(int x, int y){
Expand Down
8 changes: 4 additions & 4 deletions src/net/fexcraft/app/fmt/wrappers/PolygonWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public boolean burnToTexture(Texture tex, Integer face, float[][][] coords, bool
log("error: requested single-face paint, but provided no coordinates");
return false;
}
byte[] color = (negative ? TextureEditor.CURRENTCOLOR : something.getColor(sface)).toByteArray();
byte[] color = (negative ? TextureEditor.getCurrentColor() : something.getColor(sface).toByteArray());
burn(tex, ends, color, detached);
}
else{
Expand All @@ -382,7 +382,7 @@ public boolean burnToTexture(Texture tex, Integer face, float[][][] coords, bool
log("paint data for face " + coord.side().id() + " not found, skipping");
continue;
}
byte[] color = (negative ? TextureEditor.CURRENTCOLOR : something.getColor(coord.side().index())).toByteArray();
byte[] color = (negative ? TextureEditor.getCurrentColor() : something.getColor(coord.side().index()).toByteArray());
burn(tex, ends, color, coord.absolute());
}
}
Expand All @@ -401,12 +401,12 @@ else if(face < (segs * 3)){
ends = coords[1];
} else return false;
if(ends == null || ends.length == 0) return false;
burn(tex, ends, TextureEditor.CURRENTCOLOR.toByteArray(), false);
burn(tex, ends, TextureEditor.getCurrentColor(), false);
}
else if(this.getType().isTexturable()){
float[][] ends = coords[face];
if(ends == null || ends.length == 0) return false;
burn(tex, ends, TextureEditor.CURRENTCOLOR.toByteArray(), cuv.get(getTexturableFaces()[face]).absolute());
burn(tex, ends, TextureEditor.getCurrentColor(), cuv.get(getTexturableFaces()[face]).absolute());
}
else{
log("There is no known way of how to handle texture burning of '" + this.getType().name() + "'!");
Expand Down

0 comments on commit cc0e284

Please sign in to comment.