Skip to content

Commit 25dc8de

Browse files
Implement text support
- Text support. - CoreFlags - Better menu annimation - Add clickable to StateList
1 parent e8d30d5 commit 25dc8de

14 files changed

Lines changed: 109 additions & 12 deletions

File tree

res/drawable/menu_item_background.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<selector>
3-
<item hovered="true">
3+
<item hovered="true" clickable="true">
44
<layer-list>
55
<item>
66
<shape

src/br/nullexcept/mux/C.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
package br.nullexcept.mux;
22

33
import br.nullexcept.mux.graphics.BitmapFactory;
4+
import br.nullexcept.mux.utils.Log;
5+
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
48

59
public class C {
610
public static long VG_CONTEXT = -1;
711
public static long GLFW_CONTEXT = 0;
812
public static BitmapFactory BITMAP_FACTORY;
13+
14+
public static class Flags {
15+
public static final boolean FULL_DRAW;
16+
public static final boolean DISABLE_AUTO_REDRAW;
17+
18+
static {
19+
ArrayList<String> flags = new ArrayList<>();
20+
if (System.getenv().containsKey("JMasterUiFlags")) {
21+
flags.addAll(Arrays.asList(System.getenv("JMasterUiFlags").toUpperCase().replaceAll(" ","").split(",")));
22+
Log.log("MasterUI", "Core flags: "+Arrays.toString(flags.toArray()));
23+
}
24+
25+
FULL_DRAW = flags.contains("FULL_DRAW");
26+
DISABLE_AUTO_REDRAW = flags.contains("DISABLE_AUTO_REDRAW");
27+
}
28+
}
929
}

src/br/nullexcept/mux/app/Context.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public Context(){
1818
applets.putAll(TexelAPI.obtainApplets());
1919
}
2020

21+
public String getString(String id) {
22+
return mResource.getString(id);
23+
}
24+
2125
public <T extends Applet> T getApplet(String name) {
2226
return (T) applets.get(name);
2327
}

src/br/nullexcept/mux/core/texel/CanvasTexel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void end() {
3939

4040
public void alpha(float alpha){
4141
this.alpha *= alpha;
42-
VgTexel.setAlpha(alpha);
42+
VgTexel.setAlpha(this.alpha);
4343
}
4444

4545
@Override

src/br/nullexcept/mux/core/texel/WindowContainer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package br.nullexcept.mux.core.texel;
22

3+
import br.nullexcept.mux.C;
34
import br.nullexcept.mux.app.Context;
45
import br.nullexcept.mux.graphics.Color;
56
import br.nullexcept.mux.graphics.Rect;
@@ -149,10 +150,12 @@ public boolean isVisible() {
149150

150151
private long lastRefresh = 0;
151152
public void drawFrame() {
152-
if (System.currentTimeMillis() - lastRefresh >= 7000){
153+
if (!C.Flags.DISABLE_AUTO_REDRAW && System.currentTimeMillis() - lastRefresh >= 7000){
153154
invalidateAll();
154155
lastRefresh = System.currentTimeMillis();
155156
}
157+
if (C.Flags.FULL_DRAW) invalidateAll();
158+
156159
drawer.drawInternal(rootCanvas, this);
157160
}
158161

@@ -250,15 +253,17 @@ private void showMenu() {
250253
icon.setImageDrawable(item.getIcon());
251254
}
252255
((TextView)v.findViewByTag("title")).setText(item.getTitle());
253-
v.setOnClickListener((x)-> {
254-
currentMenu.callOnClick(item);
255-
closeMenu();
256-
});
256+
if (item.isEnable()) {
257+
v.setOnClickListener((x) -> {
258+
currentMenu.callOnClick(item);
259+
closeMenu();
260+
});
261+
}
257262
menuLayout.addChild(v);
258-
new AlphaAnimation(v, 250).play();
259263
}
260264
}
261265

266+
new AlphaAnimation(menuLayout, 100).play();
262267
menuLayout.measure();
263268
requestLayout();
264269
}

src/br/nullexcept/mux/graphics/StateList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class StateList {
77
public static final State PRESSED = State.PRESSED;
88
public static final State HOVERED = State.HOVERED;
99
public static final State CHECKED = State.CHECKED;
10+
public static final State CLICKABLE = State.CLICKABLE;
1011

1112
private final HashMap<State, Boolean> states = new HashMap<>();
1213

@@ -63,6 +64,7 @@ private enum State {
6364
FOCUSED,
6465
PRESSED,
6566
HOVERED,
66-
CHECKED
67+
CHECKED,
68+
CLICKABLE
6769
}
6870
}

src/br/nullexcept/mux/lang/xml/XmlElement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.charset.StandardCharsets;
1111
import java.util.ArrayList;
1212
import java.util.HashMap;
13+
import java.util.List;
1314
import java.util.Map;
1415

1516
public class XmlElement {
@@ -88,4 +89,8 @@ public static XmlElement parse(String value) {
8889
public Map<String, String> attrs() {
8990
return new HashMap<>(attributes);
9091
}
92+
93+
public List<XmlElement> children() {
94+
return new ArrayList<>(children);
95+
}
9196
}

src/br/nullexcept/mux/res/FallbackAttributes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public String getRawValue(String name) {
100100
@Override
101101
public CharSequence getText(String name) {
102102
if (contains(name)){
103-
return resolve(map.get(name));
103+
return Parser.parseText(resources, resolve(map.get(name)));
104104
} else if (fallback != null){
105105
return fallback.getText(name);
106106
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package br.nullexcept.mux.res;
2+
3+
import br.nullexcept.mux.lang.xml.XmlElement;
4+
5+
import java.util.HashMap;
6+
7+
class FallbackLanguage {
8+
private HashMap<String, String> values = new HashMap<>();
9+
10+
public String getString(String id) {
11+
return values.getOrDefault(id, id);
12+
}
13+
14+
public void merge(XmlElement texts) {
15+
for (XmlElement child: texts.children()) {
16+
values.put(child.attr("name"), child.value());
17+
}
18+
}
19+
}

src/br/nullexcept/mux/res/Parser.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,11 @@ public static Drawable parseDrawable(Resources resources, String value) {
217217
}
218218
return null;
219219
}
220+
221+
public static CharSequence parseText(Resources resources, String id) {
222+
if (id.startsWith("@string/")) {
223+
return resources.getString(id.substring("@string/".length()));
224+
}
225+
return id;
226+
}
220227
}

0 commit comments

Comments
 (0)