Added base glyph support to calculator
This commit is contained in:
parent
e363c3b162
commit
30a4d6919d
|
@ -1,5 +1,7 @@
|
||||||
package love.distributedrebirth.gdxapp4d.app.calculator;
|
package love.distributedrebirth.gdxapp4d.app.calculator;
|
||||||
|
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
import org.osgi.service.component.annotations.Deactivate;
|
import org.osgi.service.component.annotations.Deactivate;
|
||||||
|
@ -7,6 +9,7 @@ import org.osgi.service.component.annotations.Reference;
|
||||||
|
|
||||||
import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxLog;
|
import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxLog;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService;
|
||||||
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4LocaleService;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection;
|
||||||
|
|
||||||
|
@ -19,10 +22,18 @@ public class CalculatorComponent {
|
||||||
@Reference
|
@Reference
|
||||||
private VrGem4DeskAppService deskAppService;
|
private VrGem4DeskAppService deskAppService;
|
||||||
|
|
||||||
|
@Reference
|
||||||
|
private VrGem4LocaleService localeService;
|
||||||
|
|
||||||
|
private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.calculator.Main";
|
||||||
private final DeskAppLauncher launcher;
|
private final DeskAppLauncher launcher;
|
||||||
|
|
||||||
public CalculatorComponent() {
|
public CalculatorComponent() {
|
||||||
launcher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Calculator", () -> new CalculatorDeskApp());
|
launcher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Calculator", () -> new CalculatorDeskApp(createBundle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResourceBundle createBundle() {
|
||||||
|
return ResourceBundle.getBundle(I18N_BUNDLE, localeService.getTextLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
|
|
|
@ -1,20 +1,37 @@
|
||||||
package love.distributedrebirth.gdxapp4d.app.calculator;
|
package love.distributedrebirth.gdxapp4d.app.calculator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
import imgui.type.ImInt;
|
||||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection;
|
||||||
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer;
|
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer;
|
||||||
|
import love.distributedrebirth.unicode4d.BaseGlyphSet;
|
||||||
|
|
||||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||||
public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRenderer {
|
public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRenderer {
|
||||||
|
|
||||||
|
private ResourceBundle bundle;
|
||||||
private String value = "";
|
private String value = "";
|
||||||
|
private String valueLoc = "";
|
||||||
private String valueArg = "";
|
private String valueArg = "";
|
||||||
private Operation operation = Operation.NONE;
|
private Operation operation = Operation.NONE;
|
||||||
|
private ImInt selectedNumberGlyph = new ImInt();
|
||||||
|
|
||||||
|
public CalculatorDeskApp(ResourceBundle bundle) {
|
||||||
|
this.bundle = bundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTxt(String key) {
|
||||||
|
return bundle.getString(CalculatorDeskApp.class.getSimpleName()+"."+key);
|
||||||
|
}
|
||||||
|
|
||||||
public void create() {
|
public void create() {
|
||||||
getContours().setTitle("Calculator");
|
getContours().setTitle(getTxt("title"));
|
||||||
getContours().registrateContour(DeskAppContourSection.MAIN, this);
|
getContours().registrateContour(DeskAppContourSection.MAIN, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,83 +39,123 @@ public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRendere
|
||||||
NONE,
|
NONE,
|
||||||
PLUS,
|
PLUS,
|
||||||
MINUS,
|
MINUS,
|
||||||
MULTIPLY
|
MULTIPLY,
|
||||||
|
DIVIDE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
|
||||||
|
List<String> bases = new ArrayList<>();
|
||||||
|
for (BaseGlyphSet base:BaseGlyphSet.values()) {
|
||||||
|
bases.add(base.name());
|
||||||
|
}
|
||||||
|
String[] items = new String[bases.size()];
|
||||||
|
items = bases.toArray(items);
|
||||||
|
ImGui.combo(getTxt("selectedNumberGlyph"), selectedNumberGlyph, items);
|
||||||
|
String selectedItem = items[selectedNumberGlyph.get()];
|
||||||
|
BaseGlyphSet baseNumber = BaseGlyphSet.valueOf(selectedItem);
|
||||||
|
|
||||||
ImGui.text("Value:");
|
ImGui.text("Value:");
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
ImGui.text(value);
|
ImGui.text(valueLoc);
|
||||||
ImGui.separator();
|
ImGui.separator();
|
||||||
|
|
||||||
if (ImGui.button("0")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(0))) {
|
||||||
value+="0";
|
value+="0";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(0);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("1")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(1))) {
|
||||||
value+="1";
|
value+="1";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(1);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("2")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(2))) {
|
||||||
value+="2";
|
value+="2";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(2);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("3")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(3))) {
|
||||||
value+="3";
|
value+="3";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(3);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("4")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(4))) {
|
||||||
value+="4";
|
value+="4";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ImGui.button("5")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(5))) {
|
||||||
value+="5";
|
value+="5";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(5);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("6")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(6))) {
|
||||||
value+="6";
|
value+="6";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(6);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("7")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(7))) {
|
||||||
value+="7";
|
value+="7";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(7);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("8")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(8))) {
|
||||||
value+="8";
|
value+="8";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(8);
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("9")) {
|
if (ImGui.button(baseNumber.BȍőnNumber10().BȍőnCharFor(9))) {
|
||||||
value+="9";
|
value+="9";
|
||||||
|
valueLoc+=baseNumber.BȍőnNumber10().BȍőnCharFor(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ImGui.button("C")) {
|
if (ImGui.button("C")) {
|
||||||
value="";
|
value="";
|
||||||
|
valueLoc="";
|
||||||
valueArg="";
|
valueArg="";
|
||||||
operation = Operation.NONE;
|
operation = Operation.NONE;
|
||||||
}
|
}
|
||||||
if (ImGui.button("+")) {
|
if (ImGui.button("+")) {
|
||||||
valueArg=value;
|
valueArg=value;
|
||||||
value="";
|
value="";
|
||||||
|
valueLoc="";
|
||||||
operation = Operation.PLUS;
|
operation = Operation.PLUS;
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("-")) {
|
if (ImGui.button("-")) {
|
||||||
valueArg=value;
|
valueArg=value;
|
||||||
value="";
|
value="";
|
||||||
|
valueLoc="";
|
||||||
operation = Operation.MINUS;
|
operation = Operation.MINUS;
|
||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
if (ImGui.button("*")) {
|
if (ImGui.button("*")) {
|
||||||
valueArg=value;
|
valueArg=value;
|
||||||
value="";
|
value="";
|
||||||
|
valueLoc="";
|
||||||
operation = Operation.MULTIPLY;
|
operation = Operation.MULTIPLY;
|
||||||
}
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("/")) {
|
||||||
|
valueArg=value;
|
||||||
|
value="";
|
||||||
|
valueLoc="";
|
||||||
|
operation = Operation.DIVIDE;
|
||||||
|
}
|
||||||
if (ImGui.button("=")) {
|
if (ImGui.button("=")) {
|
||||||
int v1 = Integer.parseInt(valueArg);
|
if (value.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int v2 = Integer.parseInt(value);
|
int v2 = Integer.parseInt(value);
|
||||||
|
if (valueArg.isEmpty()) {
|
||||||
|
valueLoc = baseNumber.BȍőnPrintNumber10(v2, 9999999);;
|
||||||
|
}
|
||||||
|
int v1 = Integer.parseInt(valueArg);
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case PLUS:
|
case PLUS:
|
||||||
|
@ -110,10 +167,14 @@ public class CalculatorDeskApp extends AbstractDeskApp implements DeskAppRendere
|
||||||
case MULTIPLY:
|
case MULTIPLY:
|
||||||
result = v1*v2;
|
result = v1*v2;
|
||||||
break;
|
break;
|
||||||
|
case DIVIDE:
|
||||||
|
result = v1/v2;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
value = ""+result;
|
value = "" + result;
|
||||||
|
valueLoc = baseNumber.BȍőnPrintNumber10(result, 9999999);;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
CalculatorDeskApp.title=Calculator
|
||||||
|
CalculatorDeskApp.selectedNumberGlyph=Display glyphs
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
CalculatorDeskApp.title=Calculator
|
||||||
|
CalculatorDeskApp.selectedNumberGlyph=Display glyphs
|
Loading…
Reference in a new issue