-
-
Save voidproc/8a26efd7839678761b47d1ede66998e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Siv3D.hpp> | |
enum class LeadLineTextHAlign | |
{ | |
Left, | |
Right, | |
}; | |
enum class LeadLineTextVAlign | |
{ | |
Top, | |
Middle, | |
Bottom, | |
}; | |
void drawLeadLine(const Vec2& from, const Circular& lead1, const double lead2, const String text, const LeadLineTextHAlign halign, const LeadLineTextVAlign valign, const Font& font) | |
{ | |
const Vec2 p1 = from; | |
const Vec2 p2 = p1 + lead1; | |
const Vec2 p3 = p2 + Circular(lead2, halign == LeadLineTextHAlign::Left ? 270_deg : 90_deg); | |
const Rect region = font(text).region(); | |
Vec2 pText; | |
pText.x = halign == LeadLineTextHAlign::Left ? p3.x : p3.x - region.w; | |
switch (valign) | |
{ | |
case LeadLineTextVAlign::Top: pText.y = p3.y - region.h; break; | |
case LeadLineTextVAlign::Middle: pText.y = p3.y - region.h / 2; break; | |
case LeadLineTextVAlign::Bottom: pText.y = p3.y; break; | |
} | |
Line(p1, p2).draw(Palette::White); | |
Line(p2, p3).draw(Palette::White); | |
font(text).draw(pText, Palette::White); | |
} | |
void Main() | |
{ | |
Graphics::SetBackground(Palette::Black); | |
const Font font(12); | |
while (System::Update()) | |
{ | |
Circle(Window::Center(), 50.0).draw(Palette::Darkorange); | |
drawLeadLine(Window::Center(), Circular(100.0, 60_deg), 150.0, L"引き出し線", LeadLineTextHAlign::Right, LeadLineTextVAlign::Top, font); | |
drawLeadLine(Window::Center() + Circular(50.0, -45_deg), Circular(100.0, -45_deg), 150.0, L"左にも引ける", LeadLineTextHAlign::Left, LeadLineTextVAlign::Top, font); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment