-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1 Property System instead of Floats
... while I'm at it, right? :P Properties are stored in an CSBFloat object, which handles min, max, slider values and shit like that. Very clean! looong overdue. + layouting done with calculation, not trial and error.
- Loading branch information
TeNNoX
committed
Apr 8, 2015
1 parent
dc74f58
commit 5c55732
Showing
4 changed files
with
160 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package tennox.customselectionbox; | ||
|
||
public class CSBFloat { | ||
|
||
private float value; | ||
private float min, max; | ||
private float mcDefault, csbDefault; | ||
|
||
private String name; | ||
private float maxInt; | ||
|
||
public CSBFloat(String name, float maxInt, float mcDefault, float csbDefault) { | ||
this.name = name; | ||
this.mcDefault = mcDefault; | ||
this.csbDefault = csbDefault; | ||
this.maxInt = maxInt; | ||
this.min = 0f; | ||
this.max = 1f; | ||
validate(); | ||
} | ||
|
||
public String displayString() { | ||
return name + ": " + getAsInt(); | ||
} | ||
|
||
public float sliderVal() { | ||
validate(); | ||
return (get() - min) / (max - min); | ||
} | ||
|
||
public void setFromSlider(float sliderValue) { | ||
set(sliderValue * (max - min) + min); | ||
} | ||
|
||
private void validate() { | ||
if (value < min) | ||
value = min; | ||
if (value > max) | ||
value = max; | ||
} | ||
|
||
public CSBFloat setMinMax(float min, float max) { | ||
this.min = min; | ||
this.max = max; | ||
validate(); | ||
return this; | ||
} | ||
|
||
public int getAsInt() { | ||
return Math.round(get() * (maxInt / max)); | ||
} | ||
|
||
public void setFromInt(int val) { | ||
set((float) val / ((float) maxInt / max)); | ||
} | ||
|
||
public float get() { | ||
validate(); | ||
return value; | ||
} | ||
|
||
public void set(float val) { | ||
value = val; | ||
validate(); | ||
} | ||
|
||
public void mcDefault() { | ||
this.set(mcDefault); | ||
} | ||
|
||
public void csbDefault() { | ||
this.set(csbDefault); | ||
} | ||
|
||
public String toString() { | ||
return name + "[" + get() + ", min=" + min + ", max=" + max + "|" + maxInt + " mc=" + mcDefault + " csb=" + csbDefault + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.