add new files
This commit is contained in:
parent
4e90a93d68
commit
8038516a66
65 changed files with 7996 additions and 0 deletions
51
java/src/game/gui/element/Toggle.java
Normal file
51
java/src/game/gui/element/Toggle.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.renderer.Drawing;
|
||||
import game.util.Formatter;
|
||||
import game.window.Button;
|
||||
|
||||
public class Toggle extends Element {
|
||||
public static interface Callback {
|
||||
void use(Toggle elem, boolean value);
|
||||
}
|
||||
|
||||
private final Callback func;
|
||||
private final boolean def;
|
||||
|
||||
private boolean value;
|
||||
|
||||
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, Formatter<Toggle> formatter) {
|
||||
super(x, y, w, h, formatter);
|
||||
this.func = callback;
|
||||
this.def = def;
|
||||
this.value = init;
|
||||
this.formatText();
|
||||
}
|
||||
|
||||
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, final String text) {
|
||||
this(x, y, w, h, def, init, callback, new Formatter<Toggle>() {
|
||||
public String use(Toggle elem) {
|
||||
return String.format("%s: %s", text, elem.value ? "An" : "Aus");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
boolean prev = this.value;
|
||||
if((this.value = (ctrl || (btn == Button.MOUSE_MIDDLE)) ? this.def : !this.value) != prev) {
|
||||
// this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF;
|
||||
// gui_update_style(this, 1);
|
||||
this.r_dirty = true;
|
||||
this.func.use(this, this.value);
|
||||
this.formatText();
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
if(this.value)
|
||||
Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_btm, this.gm.style.fill_top, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
||||
else
|
||||
super.drawBackground();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue