Skip to content

Instantly share code, notes, and snippets.

@voidproc
Created May 20, 2017 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voidproc/8a26efd7839678761b47d1ede66998e1 to your computer and use it in GitHub Desktop.
Save voidproc/8a26efd7839678761b47d1ede66998e1 to your computer and use it in GitHub Desktop.
#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