Skip to content

Commit a0b56fd

Browse files
committed
Merge branch 'flag-feature-0' of https://github.com/Mr00Anderson/jimgui into Mr00Anderson-flag-feature-0
2 parents 53365d5 + 338ec0a commit a0b56fd

23 files changed

+1005
-0
lines changed
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.ice1000.jimgui.flag;
2+
3+
import java.lang.reflect.Array;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
public interface Flag {
8+
int get();
9+
10+
/**
11+
*
12+
* @param flag to check for
13+
* @param flags to check if flag is contained within
14+
* @return boolean true of flag was found
15+
*/
16+
static boolean hasFlag(int flag, Flag... flags) {
17+
for (int i = 0; i < flags.length; i++) {
18+
Flag value = flags[i];
19+
if (value.get() == flag) return true;
20+
}
21+
return false;
22+
}
23+
24+
// Slot enum[0], emum[1] for flags should be nothing and no flag found
25+
26+
/**
27+
* This method assumes that all Flag.Type classes have a enum at position 0
28+
* labeled NoSuchFlag that takes the default or nothing value for error
29+
* prevention.
30+
*
31+
* @param enumType class that and enum type that extends Flag
32+
* @param flag the flag to lookup
33+
* @param <E> the Flag which extends Enum
34+
* @return the Flag which is the flag int value
35+
*/
36+
static <E extends Flag> E reverseLookup(Class<E> enumType, int flag) {
37+
E[] enumConstants = enumType.getEnumConstants();
38+
for (int i = 1; i < enumConstants.length; i++) {
39+
E enumConstant = enumConstants[i];
40+
int flagConstant = enumConstant.get();
41+
if (flagConstant == flag) return enumConstant;
42+
}
43+
return enumConstants[0];
44+
}
45+
46+
/**
47+
* This method assumes that all Flag.Type classes have a enum at position 0
48+
* labeled NoSuchFlag that takes the default or nothing value for error
49+
* prevention.
50+
*
51+
* @param enumType class that and enum type that extends Flag
52+
* @param flags the flags to lookup
53+
* @param <E> the Flag which extends Enum
54+
* @return the flags which is the flags int values
55+
*/
56+
static <E extends Flag> E[] getAsFlags(Class<E> enumType, int flags) {
57+
List<E> setFlags = new ArrayList<>();
58+
E[] enumConstants = enumType.getEnumConstants();
59+
for (int i = 1; i < enumConstants.length; i++) {
60+
E enumConstant = enumConstants[i];
61+
int flagConstant = enumConstant.get();
62+
boolean flagSet = (flags & flagConstant) != 0;
63+
if (flagSet) setFlags.add(enumConstant);
64+
}
65+
final E[] a = (E[]) Array.newInstance(enumType, setFlags.size());
66+
setFlags.toArray(a);
67+
return a;
68+
}
69+
70+
/**
71+
*
72+
* @param flagSelection Flags
73+
* @return value of all the flags set
74+
*/
75+
static int getAsValue(Flag... flagSelection){
76+
int flags = 0;
77+
for (int i = 0; i < flagSelection.length; i++) {
78+
Flag flag = flagSelection[i];
79+
flags |= flag.get();
80+
}
81+
return flags;
82+
}
83+
}

core/src/org/ice1000/jimgui/flag/JImBackendFlags.java

+28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @since v0.1
66
*/
77
public interface JImBackendFlags {
8+
int Nothing = 0;
89
/** Back-end supports and has a connected gamepad. */
910
int HasGamepad = 1;
1011
/** Back-end supports reading GetMouseCursor() to change the OS cursor shape. */
@@ -14,4 +15,31 @@ public interface JImBackendFlags {
1415
* (only used if {@link JImConfigFlags#NavEnableSetMousePos} is set).
1516
*/
1617
int HasSetMousePos = 1 << 2;
18+
19+
enum Type implements Flag {
20+
/**
21+
* Used for reverse lookup results and enum comparison.
22+
* Return the Nothing or Default flag to prevent errors.
23+
*/
24+
NoSuchFlag(JImBackendFlags.Nothing),
25+
/** @see JImBackendFlags#Nothing */
26+
Nothing(JImBackendFlags.Nothing),
27+
/** @see JImBackendFlags#HasGamepad */
28+
HasGamepad(JImBackendFlags.HasGamepad),
29+
/** @see JImBackendFlags#HasMouseCursors */
30+
HasMouseCursors(JImBackendFlags.HasMouseCursors),
31+
/** @see JImBackendFlags#HasSetMousePos */
32+
HasSetMousePos(JImBackendFlags.HasSetMousePos);
33+
34+
public final int flag;
35+
36+
Type(int flag) {
37+
this.flag = flag;
38+
}
39+
40+
@Override
41+
public int get() {
42+
return flag;
43+
}
44+
}
1745
}

core/src/org/ice1000/jimgui/flag/JImColorEditFlags.java

+71
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,75 @@ public interface JImColorEditFlags {
140140
int DataTypeMask = Uint8 | Float;
141141
int PickerMask = PickerHueWheel | PickerHueBar;
142142
int OptionsDefault = Uint8 | RGB | PickerHueBar;
143+
144+
enum Type implements Flag {
145+
/**
146+
* Used for reverse lookup results and enum comparison.
147+
* Return the Nothing or Default flag to prevent errors.
148+
*/
149+
NoSuchFlag(JImColorEditFlags.Nothing),
150+
Nothing(JImColorEditFlags.Nothing),
151+
/** @see JImColorEditFlags#NoAlpha */
152+
NoAlpha(JImColorEditFlags.NoAlpha),
153+
/** @see JImColorEditFlags#NoPicker */
154+
NoPicker(JImColorEditFlags.NoPicker),
155+
/** @see JImColorEditFlags#NoOptions */
156+
NoOptions(JImColorEditFlags.NoOptions),
157+
/** @see JImColorEditFlags#NoSmallPreview */
158+
NoSmallPreview(JImColorEditFlags.NoSmallPreview),
159+
/** @see JImColorEditFlags#NoInputs */
160+
NoInputs(JImColorEditFlags.NoInputs),
161+
/** @see JImColorEditFlags#NoTooltip */
162+
NoTooltip(JImColorEditFlags.NoTooltip),
163+
/** @see JImColorEditFlags#NoLabel */
164+
NoLabel(JImColorEditFlags.NoLabel),
165+
/** @see JImColorEditFlags#NoSidePreview */
166+
NoSidePreview(JImColorEditFlags.NoSidePreview),
167+
/** @see JImColorEditFlags#NoDragDrop */
168+
NoDragDrop(JImColorEditFlags.NoDragDrop),
169+
170+
// user options
171+
172+
/** @see JImColorEditFlags#AlphaBar */
173+
AlphaBar(JImColorEditFlags.AlphaBar),
174+
/** @see JImColorEditFlags#AlphaPreview */
175+
AlphaPreview(JImColorEditFlags.AlphaPreview),
176+
/** @see JImColorEditFlags#AlphaPreviewHalf */
177+
AlphaPreviewHalf(JImColorEditFlags.AlphaPreviewHalf),
178+
/** @see JImColorEditFlags#HDR */
179+
HDR(JImColorEditFlags.HDR),
180+
/** @see JImColorEditFlags#RGB */
181+
RGB(JImColorEditFlags.RGB),
182+
/** @see JImColorEditFlags#HSV */
183+
HSV(JImColorEditFlags.HSV),
184+
/** @see JImColorEditFlags#HEX */
185+
HEX(JImColorEditFlags.HEX),
186+
/** @see JImColorEditFlags#Uint8 */
187+
Uint8(JImColorEditFlags.Uint8),
188+
/** @see JImColorEditFlags#Float */
189+
Float(JImColorEditFlags.Float),
190+
/** @see JImColorEditFlags#PickerHueBar */
191+
PickerHueBar(JImColorEditFlags.PickerHueBar),
192+
/** @see JImColorEditFlags#PickerHueWheel */
193+
PickerHueWheel(JImColorEditFlags.PickerHueWheel),
194+
195+
196+
// [Internal] Masks
197+
198+
InputsMask(JImColorEditFlags.RGB | JImColorEditFlags.HSV | JImColorEditFlags.HEX ),
199+
DataTypeMask(JImColorEditFlags.Uint8 | JImColorEditFlags.Float),
200+
PickerMask (JImColorEditFlags.PickerHueWheel | JImColorEditFlags.PickerHueBar),
201+
OptionsDefault(JImColorEditFlags.Uint8 | JImColorEditFlags.RGB | JImColorEditFlags.PickerHueBar);
202+
203+
public final int flag;
204+
205+
Type(int flag) {
206+
this.flag = flag;
207+
}
208+
209+
@Override
210+
public int get() {
211+
return flag;
212+
}
213+
}
143214
}

core/src/org/ice1000/jimgui/flag/JImComboFlags.java

+36
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,40 @@ public interface JImComboFlags {
2727
/** Display only a square arrow button */
2828
int NoPreview = 1 << 6;
2929
int HeightMask_ = HeightSmall | HeightRegular | HeightLarge | HeightLargest;
30+
31+
enum Type implements Flag {
32+
/**
33+
* Used for reverse lookup results and enum comparison.
34+
* Return the Nothing or Default flag to prevent errors.
35+
*/
36+
NoSuchFlag(JImComboFlags.Nothing),
37+
Nothing(JImComboFlags.Nothing),
38+
/** @see JImComboFlags#PopupAlignLeft */
39+
PopupAlignLeft(JImComboFlags.PopupAlignLeft),
40+
/** @see JImComboFlags#HeightSmall */
41+
HeightSmall(JImComboFlags.HeightSmall),
42+
/** @see JImComboFlags#HeightRegular */
43+
HeightRegular(JImComboFlags.HeightRegular),
44+
/** @see JImComboFlags#HeightLarge */
45+
HeightLarge(JImComboFlags.HeightLarge),
46+
/** @see JImComboFlags#HeightLargest */
47+
HeightLargest(JImComboFlags.HeightLargest),
48+
/** @see JImComboFlags#NoArrowButton */
49+
NoArrowButton(JImComboFlags.NoArrowButton),
50+
/** @see JImComboFlags#NoPreview */
51+
NoPreview(JImComboFlags.NoPreview),
52+
53+
HeightMask_(JImComboFlags.HeightSmall | JImComboFlags.HeightRegular | JImComboFlags.HeightLarge | JImComboFlags.HeightLargest);
54+
55+
public final int flag;
56+
57+
Type(int flag) {
58+
this.flag = flag;
59+
}
60+
61+
@Override
62+
public int get() {
63+
return flag;
64+
}
65+
}
3066
}

core/src/org/ice1000/jimgui/flag/JImCondition.java

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @since v0.1
88
*/
99
public interface JImCondition {
10+
int Nothing = 0;
1011
/** Set the variable */
1112
int Always = 1;
1213
/** Set the variable once per runtime session (only the first call with succeed) */
@@ -15,4 +16,32 @@ public interface JImCondition {
1516
int FirstUseEver = 1 << 2;
1617
/** Set the variable if the object/window is appearing after being hidden/inactive (or the first time) */
1718
int Appearing = 1 << 3;
19+
20+
enum Type implements Flag {
21+
/**
22+
* Used for reverse lookup results and enum comparison.
23+
* Return the Nothing or Default flag to prevent errors.
24+
*/
25+
NoSuchFlag(JImCondition.Nothing),
26+
Nothing(JImCondition.Nothing),
27+
/** @see JImCondition#Always */
28+
Always(JImCondition.Always),
29+
/** @see JImCondition#Once */
30+
Once(JImCondition.Once),
31+
/** @see JImCondition#FirstUseEver */
32+
FirstUseEver(JImCondition.FirstUseEver),
33+
/** @see JImCondition#Appearing */
34+
Appearing(JImCondition.Appearing);
35+
36+
public final int flag;
37+
38+
Type(int flag) {
39+
this.flag = flag;
40+
}
41+
42+
@Override
43+
public int get() {
44+
return flag;
45+
}
46+
}
1847
}

core/src/org/ice1000/jimgui/flag/JImConfigFlags.java

+37
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @since v0.1
88
*/
99
public interface JImConfigFlags {
10+
int Nothing = 0;
1011
/**
1112
* Master keyboard navigation enable flag.
1213
* initNewFrame() will automatically fill getIO().NavInputs[] based on getIO().KeysDown[].
@@ -42,4 +43,40 @@ public interface JImConfigFlags {
4243
int IsSRGB = 1 << 20;
4344
/** Application is using a touch screen instead of a mouse. */
4445
int IsTouchScreen = 1 << 21;
46+
47+
enum Type implements Flag {
48+
/**
49+
* Used for reverse lookup results and enum comparison.
50+
* Return the Nothing or Default flag to prevent errors.
51+
*/
52+
NoSuchFlag(JImConfigFlags.Nothing),
53+
Nothing(JImConfigFlags.Nothing),
54+
/** @see JImConfigFlags#NavEnableKeyboard */
55+
NavEnableKeyboard(JImConfigFlags.NavEnableKeyboard),
56+
/** @see JImConfigFlags#NavEnableGamepad */
57+
NavEnableGamepad(JImConfigFlags.NavEnableGamepad),
58+
/** @see JImConfigFlags#NavEnableSetMousePos */
59+
NavEnableSetMousePos(JImConfigFlags.NavEnableSetMousePos),
60+
/** @see JImConfigFlags#NavNoCaptureKeyboard */
61+
NavNoCaptureKeyboard(JImConfigFlags.NavNoCaptureKeyboard),
62+
/** @see JImConfigFlags#NoMouse */
63+
NoMouse(JImConfigFlags.NoMouse),
64+
/** @see JImConfigFlags#NoMouseCursorChange */
65+
NoMouseCursorChange(JImConfigFlags.NoMouseCursorChange),
66+
/** @see JImConfigFlags#IsSRGB */
67+
IsSRGB(JImConfigFlags.IsSRGB),
68+
/** @see JImConfigFlags#IsTouchScreen */
69+
IsTouchScreen(JImConfigFlags.IsTouchScreen);
70+
71+
public final int flag;
72+
73+
Type(int flag) {
74+
this.flag = flag;
75+
}
76+
77+
@Override
78+
public int get() {
79+
return flag;
80+
}
81+
}
4582
}

core/src/org/ice1000/jimgui/flag/JImDirection.java

+29
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,33 @@ public interface JImDirection {
1010
int Right = 1;
1111
int Up = 2;
1212
int Down = 3;
13+
14+
enum Type implements Flag {
15+
/**
16+
* Used for reverse lookup results and enum comparison.
17+
* Return the Nothing or Default flag to prevent errors.
18+
*/
19+
NoSuchFlag(JImDirection.None),
20+
/** @see JImDirection#None */
21+
None(JImDirection.None),
22+
/** @see JImDirection#Left */
23+
Left(JImDirection.Left),
24+
/** @see JImDirection#Right */
25+
Right(JImDirection.Right),
26+
/** @see JImDirection#Up */
27+
Up(JImDirection.Up),
28+
/** @see JImDirection#Down */
29+
Down(JImDirection.Down);
30+
31+
public final int flag;
32+
33+
Type(int flag) {
34+
this.flag = flag;
35+
}
36+
37+
@Override
38+
public int get() {
39+
return flag;
40+
}
41+
}
1342
}

0 commit comments

Comments
 (0)