package love.distributedrebirth.unicode4d.draw; import imgui.ImColor; import imgui.ImDrawList; import imgui.ImGui; import imgui.ImVec2; import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphLineTo; import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphPathCommand; import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphQuadCurveTo; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public class ImCharacter { public static final float HEIGHT = 26f; public static final float WIDTH = 22f; public static final float MARGIN_MENUBAR = 4f; private static final ImVec2 SIZE = new ImVec2(WIDTH, HEIGHT); private static final int DEFAULT_COLOR = ImColor.intToColor(255, 255, 255, 255); public static void render(DrawCharacter drawChar) { ImGui.invisibleButton("canvas", SIZE.x, SIZE.y); ImVec2 p0 = ImGui.getItemRectMin(); ImVec2 p1 = ImGui.getItemRectMax(); // p1 = p0 + size ImDrawList drawList = ImGui.getWindowDrawList(); drawList.pushClipRect(p0.x, p0.y, p1.x, p1.y); drawUnicode4D(drawChar, p0.x, p0.y, DEFAULT_COLOR, drawList); drawList.popClipRect(); } public static void drawUnicode4D(DrawCharacter drawChar, float posX, float posY, int color, ImDrawList drawList) { float xOff = posX; float yOff = posY + 19f; float yFlip = -1f; float scale = 0.0199f; if (drawChar.getyMax() > 900) { scale = 0.0100f; } ImGlyphPathCommand first = null; ImGlyphPathCommand prev = null; for (ImGlyphPathCommand cmd: drawChar.getGlyphPath().getPath()) { if (cmd.isImGlyphMoveTo()) { first = cmd; prev = cmd; continue; } if (cmd.isImGlyphLineTo()) { ImGlyphLineTo lineTo = cmd.toImGlyphLineTo(); drawList.addLine( xOff+prev.getX()*scale, yOff+prev.getY()*scale*yFlip, xOff+lineTo.getX()*scale, yOff+lineTo.getY()*scale*yFlip, color); prev = cmd; continue; } if (cmd.isImGlyphQuadCurveTo()) { ImGlyphQuadCurveTo quadCurveTo = cmd.toImGlyphQuadCurveTo(); drawList.addBezierQuadratic( xOff+prev.getX()*scale, yOff+prev.getY()*scale*yFlip, xOff+quadCurveTo.getX1()*scale, yOff+quadCurveTo.getY1()*scale*yFlip, xOff+quadCurveTo.getX()*scale, yOff+quadCurveTo.getY()*scale*yFlip, color, 1); prev = cmd; continue; } if (cmd.isImGlyphClosePath()) { drawList.addLine( xOff+prev.getX()*scale, yOff+prev.getY()*scale*yFlip, xOff+first.getX()*scale, yOff+first.getY()*scale*yFlip, color); } } } }