death to unicode

This commit is contained in:
Willem Cazander 2022-10-16 15:55:25 +02:00
parent 023710722c
commit 555a59080b
4 changed files with 147 additions and 111 deletions

View file

@ -3,9 +3,7 @@ package love.distributedrebirth.gdxapp4d.app.glyphdemo.apps;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import imgui.ImGui; import imgui.ImGui;
import imgui.flag.ImGuiStyleVar;
import imgui.flag.ImGuiTableFlags; import imgui.flag.ImGuiTableFlags;
import imgui.flag.ImGuiWindowFlags;
import imgui.type.ImBoolean; import imgui.type.ImBoolean;
import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注;
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService; import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService;
@ -13,7 +11,6 @@ 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.numberxd.unicode.UnicodePlane; import love.distributedrebirth.numberxd.unicode.UnicodePlane;
import love.distributedrebirth.unicode4d.draw.DrawCharacter;
import love.distributedrebirth.unicode4d.draw.ImCharacter; import love.distributedrebirth.unicode4d.draw.ImCharacter;
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
@ -46,37 +43,26 @@ public class DemoUnicodePlaneDeskApp extends AbstractDeskApp implements DeskAppR
ImGui.tableSetupColumn(getTxt("colText")); ImGui.tableSetupColumn(getTxt("colText"));
ImGui.tableHeadersRow(); ImGui.tableHeadersRow();
for (UnicodePlane plane:UnicodePlane.values()) { for (UnicodePlane plane:UnicodePlane.values()) {
if (!plane.isPlaneValid()) {
continue;
}
StringBuilder buf = new StringBuilder();
int offset = 33;
for (int i=plane.getStart()+offset;i<plane.getStart()+33+offset;i++) {
buf.appendCodePoint(i);
if (plane.isPlane0() && render4DPlane0.get() == false) {
buf.append(" ");
}
}
ImGui.tableNextRow(); ImGui.tableNextRow();
ImGui.tableNextColumn(); ImGui.tableNextColumn();
ImGui.text(plane.name()); ImGui.text(plane.name());
ImGui.tableNextColumn(); ImGui.tableNextColumn();
if (plane.isPlane0() && render4DPlane0.get() == false) { if (plane.isPlane0() && render4DPlane0.get() == false) {
StringBuilder buf = new StringBuilder();
int offset = 33;
for (int i=plane.getStart()+offset;i<plane.getStart()+33+offset;i++) {
if (i < 65536) {
buf.append((char)i);
}
buf.append(" ");
}
ImGui.text(buf.toString()); ImGui.text(buf.toString());
} else { } else {
ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, 0f, 0f); ImCharacter.render("row"+plane.name(), buf.toString(), '?', v -> unicode4DService.getCharacterForUnicode(v));
int offset = 33;
// workaround for error; Too many vertices in ImDrawList using 16-bit indices.
// hard coded height to fix line height and row0 height + no scoll to disable mouse scroll
ImGui.beginChild("row"+plane.name(), 0f, ImCharacter.HEIGHT, false, ImGuiWindowFlags.NoScrollWithMouse);
for (int i=plane.getStart()+offset;i<plane.getStart()+33+offset;i++) {
DrawCharacter drawChar = unicode4DService.getCharacterForUnicode(i);
if (drawChar != null) {
ImCharacter.render(drawChar);
} else {
ImGui.text("?");
}
ImGui.sameLine();
}
ImGui.endChild();
ImGui.popStyleVar();
} }
} }
ImGui.endTable(); ImGui.endTable();

View file

@ -6,6 +6,7 @@ import imgui.ImDrawList;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;
import imgui.type.ImInt; import imgui.type.ImInt;
import love.distributedrebirth.bassboonyd.BãßBȍőnConstantsʸᴰ;
import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注;
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService; import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
@ -62,8 +63,12 @@ public class NotepadDeskApp extends AbstractDeskApp implements DeskAppRenderer {
@Override @Override
public void render() { public void render() {
ImGui.sliderInt("RunSpeed", runSpeed.getData(), 0, 60); ImGui.sliderInt(BãßBȍőnConstantsʸᴰ.STR_SPACE, runSpeed.getData(), 0, 60); // empty ID not allowed in ImGui, but whitespace is an ID :)
ImGui.invisibleButton("matrix", ImGui.getWindowWidth(), ImGui.getWindowHeight()-(2*ImGui.getFontSize())); ImGui.sameLine();
ImCharacter.render("speedId", "RunSpeed", 'ﷲ', v -> unicode4DService.getCharacterForUnicode(v));
ImGui.text(BãßBȍőnConstantsʸᴰ.STR_SPACE);
ImGui.invisibleButton("matrix", ImGui.getWindowWidth(), ImGui.getWindowHeight()-(3*ImGui.getFontSize()));
ImVec2 p0 = ImGui.getItemRectMin(); ImVec2 p0 = ImGui.getItemRectMin();
ImVec2 p1 = ImGui.getItemRectMax(); ImVec2 p1 = ImGui.getItemRectMax();
ImDrawList drawList = ImGui.getWindowDrawList(); ImDrawList drawList = ImGui.getWindowDrawList();

View file

@ -395,6 +395,10 @@ public enum UnicodePlane {
return getStart() < 0xFFFF; return getStart() < 0xFFFF;
} }
public boolean isPlaneValid() {
return this != UNKNOWN;
}
public static UnicodePlane valueOfUnicode(int unicode) { public static UnicodePlane valueOfUnicode(int unicode) {
for (UnicodePlane value:values()) { for (UnicodePlane value:values()) {
if (unicode >= value.getStart() && unicode <= value.getStop()) { if (unicode >= value.getStart() && unicode <= value.getStop()) {

View file

@ -1,82 +1,123 @@
package love.distributedrebirth.unicode4d.draw; /* DEATH TO UNICODE */ package love.distributedrebirth.unicode4d.draw; // death to unicode
/* DEATH TO UNICODE */ //death to unicode
import imgui.ImColor; /* DEATH TO UNICODE */ import java.util.function.Function; // death to unicode
import imgui.ImDrawList; /* DEATH TO UNICODE */ //death to unicode
import imgui.ImGui; /* DEATH TO UNICODE */ import imgui.ImColor; // death to unicode
import imgui.ImVec2; /* DEATH TO UNICODE */ import imgui.ImDrawList; // death to unicode
import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; /* DEATH TO UNICODE */ import imgui.ImGui; // death to unicode
import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphLineTo; /* DEATH TO UNICODE */ import imgui.ImVec2; // death to unicode
import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphPathCommand; /* DEATH TO UNICODE */ import imgui.flag.ImGuiStyleVar; // death to unicode
import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphQuadCurveTo; /* DEATH TO UNICODE */ import imgui.flag.ImGuiWindowFlags; // death to unicode
/* DEATH TO UNICODE */ import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; // death to unicode
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") /* DEATH TO UNICODE */ import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphLineTo; // death to unicode
public class ImCharacter { /* DEATH TO UNICODE */ import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphPathCommand; // death to unicode
/* DEATH TO UNICODE */ import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphQuadCurveTo; // death to unicode
public static final float HEIGHT = 26f; /* DEATH TO UNICODE */ //death to unicode
public static final float WIDTH = 22f; /* DEATH TO UNICODE */ @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") // death to unicode
public static final float MARGIN_MENUBAR = 4f; /* DEATH TO UNICODE */ public class ImCharacter { // death to unicode
private static final ImVec2 SIZE = new ImVec2(WIDTH, HEIGHT); /* DEATH TO UNICODE */ // death to unicode
private static final int DEFAULT_COLOR = ImColor.intToColor(255, 255, 255, 255); /* DEATH TO UNICODE */ public static final float HEIGHT = 26f; // death to unicode
/* DEATH TO UNICODE */ public static final float WIDTH = 22f; // death to unicode
public static void render(DrawCharacter drawChar) { /* DEATH TO UNICODE */ public static final float MARGIN_MENUBAR = 4f; // death to unicode
ImGui.invisibleButton("canvas", SIZE.x, SIZE.y); /* DEATH TO UNICODE */ private static final ImVec2 SIZE = new ImVec2(WIDTH, HEIGHT); // death to unicode
ImVec2 p0 = ImGui.getItemRectMin(); /* DEATH TO UNICODE */ private static final int DEFAULT_COLOR = ImColor.intToColor(255, 255, 255, 255); // death to unicode
ImVec2 p1 = ImGui.getItemRectMax(); // p1 = p0 + size /* DEATH TO UNICODE */ // death to unicode
ImDrawList drawList = ImGui.getWindowDrawList(); /* DEATH TO UNICODE */ public static void render(String childId, String text, int fallbackChar, Function<Integer, DrawCharacter> letterResolver) { // death to unicode
drawList.pushClipRect(p0.x, p0.y, p1.x, p1.y); /* DEATH TO UNICODE */ // death to unicode
drawUnicode4D(drawChar, p0.x, p0.y, DEFAULT_COLOR, drawList); /* DEATH TO UNICODE */ // death to unicode
drawList.popClipRect(); /* DEATH TO UNICODE */ // death to unicode
} /* DEATH TO UNICODE */ // death to unicode
/* DEATH TO UNICODE */ ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, 0f, 0f); // death to unicode
public static void drawUnicode4D(DrawCharacter drawChar, float posX, float posY, int color, ImDrawList drawList) { /* DEATH TO UNICODE */ // death to unicode
float xOff = posX; /* DEATH TO UNICODE */ // death to unicode
float yOff = posY + 19f; /* DEATH TO UNICODE */ // death to unicode
float yFlip = -1f; /* DEATH TO UNICODE */ // death to unicode
float scale = 0.0199f; /* DEATH TO UNICODE */ // workaround for error; Too many vertices in ImDrawList using 16-bit indices. DEATH TO UNICODE
if (drawChar.getyMax() > 900) { /* DEATH TO UNICODE */ // hard coded height to fix line height and row0 height + no scoll to disable mouse scroll DEATH TO UNICODE
scale = 0.0100f; /* DEATH TO UNICODE */ ImGui.beginChild(childId, 0f, ImCharacter.HEIGHT, false, ImGuiWindowFlags.NoScrollWithMouse); // death to unicode
} /* DEATH TO UNICODE */ // NOTE: java never ever use String class its shit, just rename length() to lengthBytes() and break all buggy fake unicode loops. DEATH TO UNICODE
ImGlyphPathCommand first = null; /* DEATH TO UNICODE */ // codePoints() is the only valid iterator, all methods should be removed from String, humans are not allowed to write code, DEATH TO UNICODE
ImGlyphPathCommand prev = null; /* DEATH TO UNICODE */ // death to unicode
for (ImGlyphPathCommand cmd: drawChar.getGlyphPath().getPath()) { /* DEATH TO UNICODE */ // death to unicode
if (cmd.isImGlyphMoveTo()) { /* DEATH TO UNICODE */ // death to unicode
first = cmd; /* DEATH TO UNICODE */ // death to unicode
prev = cmd; /* DEATH TO UNICODE */ text.codePoints().forEach(unicodeChar -> { // death to unicode
continue; /* DEATH TO UNICODE */ DrawCharacter drawChar = letterResolver.apply(unicodeChar); // death to unicode
} /* DEATH TO UNICODE */ // death to unicode
if (cmd.isImGlyphLineTo()) { /* DEATH TO UNICODE */ if (drawChar == null) { // death to unicode
ImGlyphLineTo lineTo = cmd.toImGlyphLineTo(); /* DEATH TO UNICODE */ drawChar = letterResolver.apply(fallbackChar); // death to unicode
drawList.addLine( /* DEATH TO UNICODE */ } // death to unicode
xOff+prev.getX()*scale, /* DEATH TO UNICODE */ ImCharacter.render(drawChar); // death to unicode
yOff+prev.getY()*scale*yFlip, /* DEATH TO UNICODE */ ImGui.sameLine(); // death to unicode
xOff+lineTo.getX()*scale, /* DEATH TO UNICODE */ }); // death to unicode
yOff+lineTo.getY()*scale*yFlip, /* DEATH TO UNICODE */ ImGui.endChild(); // death to unicode
color); /* DEATH TO UNICODE */ ImGui.popStyleVar(); // death to unicode
prev = cmd; /* DEATH TO UNICODE */ // death to unicode
continue; /* DEATH TO UNICODE */ // death to unicode
} /* DEATH TO UNICODE */ // death to unicode
if (cmd.isImGlyphQuadCurveTo()) { /* DEATH TO UNICODE */ // death to unicode
ImGlyphQuadCurveTo quadCurveTo = cmd.toImGlyphQuadCurveTo(); /* DEATH TO UNICODE */ } // death to unicode
drawList.addBezierQuadratic( /* DEATH TO UNICODE */ // death to unicode
xOff+prev.getX()*scale, /* DEATH TO UNICODE */ public static void render(DrawCharacter drawChar) { // death to unicode
yOff+prev.getY()*scale*yFlip, /* DEATH TO UNICODE */ ImGui.invisibleButton("canvas", SIZE.x, SIZE.y); // death to unicode
xOff+quadCurveTo.getX1()*scale, /* DEATH TO UNICODE */ ImVec2 p0 = ImGui.getItemRectMin(); // death to unicode
yOff+quadCurveTo.getY1()*scale*yFlip, /* DEATH TO UNICODE */ ImVec2 p1 = ImGui.getItemRectMax(); // death to unicode
xOff+quadCurveTo.getX()*scale, /* DEATH TO UNICODE */ ImDrawList drawList = ImGui.getWindowDrawList(); // death to unicode
yOff+quadCurveTo.getY()*scale*yFlip, /* DEATH TO UNICODE */ drawList.pushClipRect(p0.x, p0.y, p1.x, p1.y); // death to unicode
color, /* DEATH TO UNICODE */ drawUnicode4D(drawChar, p0.x, p0.y, DEFAULT_COLOR, drawList); // death to unicode
1); /* DEATH TO UNICODE */ drawList.popClipRect(); // death to unicode
prev = cmd; /* DEATH TO UNICODE */ } // death to unicode
continue; /* DEATH TO UNICODE */ // death to unicode
} /* DEATH TO UNICODE */ public static void drawUnicode4D(DrawCharacter drawChar, float posX, float posY, int color, ImDrawList drawList) { // death to unicode
if (cmd.isImGlyphClosePath()) { /* DEATH TO UNICODE */ float xOff = posX; // death to unicode
drawList.addLine( /* DEATH TO UNICODE */ float yOff = posY + 19f; // death to unicode
xOff+prev.getX()*scale, /* DEATH TO UNICODE */ float yFlip = -1f; // death to unicode
yOff+prev.getY()*scale*yFlip, /* DEATH TO UNICODE */ float scale = 0.0199f; // death to unicode
xOff+first.getX()*scale, /* DEATH TO UNICODE */ if (drawChar.getyMax() > 900) { // death to unicode
yOff+first.getY()*scale*yFlip, /* DEATH TO UNICODE */ scale = 0.0100f; // death to unicode
color); /* DEATH TO UNICODE */ } // death to unicode
} /* DEATH TO UNICODE */ ImGlyphPathCommand first = null; // death to unicode
} /* DEATH TO UNICODE */ ImGlyphPathCommand prev = null; // death to unicode
} /* DEATH TO UNICODE */ for (ImGlyphPathCommand cmd: drawChar.getGlyphPath().getPath()) { // death to unicode
} /* DEATH TO UNICODE */ if (cmd.isImGlyphMoveTo()) { // death to unicode
/* DEATH TO UNICODE */ first = cmd; // death to unicode
/* DEATH TO UNICODE */ prev = cmd; // death to unicode
/* DEATH TO UNICODE */ continue; // death to unicode
/* DEATH TO UNICODE */ } // death to unicode
/* DEATH TO UNICODE */ if (cmd.isImGlyphLineTo()) { // death to unicode
/* DEATH TO UNICODE */ ImGlyphLineTo lineTo = cmd.toImGlyphLineTo(); // death to unicode
/* DEATH TO UNICODE */ drawList.addLine( // death to unicode
/* DEATH TO UNICODE */ xOff+prev.getX()*scale, // death to unicode
/* DEATH TO UNICODE */ yOff+prev.getY()*scale*yFlip, // death to unicode
/* DEATH TO UNICODE */ xOff+lineTo.getX()*scale, // death to unicode
/* DEATH TO UNICODE */ yOff+lineTo.getY()*scale*yFlip, // death to unicode
/* DEATH TO UNICODE */ color); // death to unicode
/* DEATH TO UNICODE */ prev = cmd; // death to unicode
/* DEATH TO UNICODE */ continue; // death to unicode
/* DEATH TO UNICODE */ } // death to unicode
/* DEATH TO UNICODE */ if (cmd.isImGlyphQuadCurveTo()) { // death to unicode
/* DEATH TO UNICODE */ ImGlyphQuadCurveTo quadCurveTo = cmd.toImGlyphQuadCurveTo(); // death to unicode
/* DEATH TO UNICODE */ drawList.addBezierQuadratic( // death to unicode
/* DEATH TO UNICODE */ xOff+prev.getX()*scale, // death to unicode
/* DEATH TO UNICODE */ yOff+prev.getY()*scale*yFlip, // death to unicode
/* DEATH TO UNICODE */ xOff+quadCurveTo.getX1()*scale, // death to unicode
/* DEATH TO UNICODE */ yOff+quadCurveTo.getY1()*scale*yFlip, // death to unicode
/* DEATH TO UNICODE */ xOff+quadCurveTo.getX()*scale, // death to unicode
/* DEATH TO UNICODE */ yOff+quadCurveTo.getY()*scale*yFlip, // death to unicode
/* DEATH TO UNICODE */ color, // death to unicode
/* DEATH TO UNICODE */ 1); // death to unicode
/* DEATH TO UNICODE */ prev = cmd; // death to unicode
/* DEATH TO UNICODE */ continue; // death to unicode
/* DEATH TO UNICODE */ } // death to unicode
/* DEATH TO UNICODE */ if (cmd.isImGlyphClosePath()) { // death to unicode
/* DEATH TO UNICODE */ drawList.addLine( // death to unicode
/* DEATH TO UNICODE */ xOff+prev.getX()*scale, // death to unicode
/* DEATH TO UNICODE */ yOff+prev.getY()*scale*yFlip, // death to unicode
/* DEATH TO UNICODE */ xOff+first.getX()*scale, // death to unicode
/* DEATH TO UNICODE */ yOff+first.getY()*scale*yFlip, // death to unicode
/* DEATH TO UNICODE */ color); // death to unicode
/* DEATH TO UNICODE */ } // death to unicode
/* DEATH TO UNICODE */ } // death to unicode
/* DEATH TO UNICODE */ } // death to unicode
/* DEATH TO UNICODE */ } // death to unicode
/* DEATH TO UNICODE */ //death to unicode