浮いているボタン
https://scrapbox.io/files/646cb8b5241e43001c9e7fa0.png
使い方
RectButton::update(String 文字,RectF 四角,bool 有効かどうか:省略可);
CircleButton::update(String 文字,Circle 円,bool 有効かどうか:省略可);
コード
code:浮いているボタン.cpp
# include <Siv3D.hpp>
class RectButton {
public:
bool update(const String& str, const RectF& rectf, bool flag = true) {
RoundRect rect{ rectf,5 };
if (flag) {
rect.drawShadow({}, 8, 1);
if (rect.mouseOver())Cursor::RequestStyle(CursorStyle::Hand);
}
const bool click = rect.leftClicked() && flag;
transition.update(not (rect.leftPressed() && flag));
const double value = -2 * transition.value();
rect.moveBy(value, value).draw();
SimpleGUI::GetFont()(str).drawAt(rect.center(), Palette::Black);
return click;
}
Transition transition{ 0.3s, 0s ,1.0 };
};
class CircleButton {
public:
bool update(const String& str, const Circle& circle_, bool flag = true) {
Circle circle = circle_;
if (flag) {
circle.drawShadow({}, 8, 1);
if (circle.mouseOver())Cursor::RequestStyle(CursorStyle::Hand);
}
const bool click = circle.leftClicked() && flag;
transition.update(not (circle.leftPressed() && flag));
const double value = -2 * transition.value();
circle.moveBy(value, value).draw();
SimpleGUI::GetFont()(str).drawAt(circle.center, Palette::Black);
return click;
}
Transition transition{ 0.3s, 0s ,1.0 };
};
void Main()
{
Scene::SetBackground(Palette::Skyblue);
RectButton botton1;
CircleButton botton2;
while (System::Update())
{
if (botton1.update(U"Rect", { Arg::center( 300,300 ), 100 }))Print << U"Rect";
if (botton2.update(U"Circle", { 500,300, 50 }))Print << U"Circle";
}
}