矢印ボタン
https://scrapbox.io/files/646ac09580042e001c5b6bfc.png
使い方
UpButton(RoundRect ボタンの丸い四角,ColorF 色:省略可,ColorF ▲の色:省略可);
DownButton、LeftButton、RightButtonも同様。
コード
code:矢印ボタン.cpp
# include <Siv3D.hpp>
bool DirectionButton(RoundRect rrect,RectF rect, ColorF color, ColorF triangleColor,double rad) {
if (rrect.mouseOver()||rect.mouseOver())Cursor::RequestStyle(CursorStyle::Hand);
rrect.draw(color);
rect.draw(color);
Triangle{ rrect.center(),Min(rrect.w,rrect.h) / 2,rad }.draw(triangleColor);
return rrect.leftClicked() || rect.leftClicked();
}
bool UpButton(RoundRect rrect,ColorF color=Palette::White, ColorF triangleColor = Palette::Black) {
return DirectionButton(rrect, { Arg::center(rrect.center().x,rrect.rect.bottomCenter().y - rrect.r / 2), rrect.w ,rrect.r },color, triangleColor, 0_deg);
}
bool DownButton(RoundRect rrect, ColorF color = Palette::White, ColorF triangleColor = Palette::Black) {
return DirectionButton(rrect, { Arg::center(rrect.center().x,rrect.rect.topCenter().y + rrect.r / 2), rrect.w ,rrect.r },color, triangleColor, 180_deg);
}
bool LeftButton(RoundRect rrect, ColorF color = Palette::White, ColorF triangleColor = Palette::Black) {
return DirectionButton(rrect, { Arg::center(rrect.rect.right().center().x - rrect.r / 2, rrect.center().y), rrect.r, rrect.h },color, triangleColor, -90_deg);
}
bool RightButton(RoundRect rrect, ColorF color = Palette::White, ColorF triangleColor = Palette::Black) {
return DirectionButton(rrect, { Arg::center(rrect.rect.left().center().x + rrect.r / 2, rrect.center().y), rrect.r, rrect.h },color, triangleColor, 90_deg);
}
void Main()
{
Scene::SetBackground(Palette::Skyblue);
int32 num1 = 10,num2=10;
while (System::Update())
{
ClearPrint();
Print << num1;
Print << num2;
num1 += UpButton(RoundRect{Arg::center(300,250),100,80,15});
num1 -= DownButton(RoundRect{ Arg::center(300,350),100,80,15});
num2 += RightButton(RoundRect{ Arg::center(550,300),80,100,15 });
num2 -= LeftButton(RoundRect{ Arg::center(450,300),80,100,15 });
}
}