GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
simple_button.h
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#ifndef DESIGNLAB_SIMPLE_BUTTON_H_
9#define DESIGNLAB_SIMPLE_BUTTON_H_
10
11#include <functional>
12#include <string>
13#include <vector>
14
16#include "interface_dxlib_gui.h"
17
18
19namespace designlab
20{
21
24class SimpleButton final : public IDxlibGui, public IDxlibClickable
25{
26public:
27 SimpleButton() = delete;
28
37 SimpleButton(const std::string& text,
38 int x_pos, int y_pos, int x_size, int y_size,
39 bool fit_size = false);
40
41 ~SimpleButton() = default;
42
45 inline void SetActivateFunction(const std::function<void()>& func)
46 {
47 click_function_ = func;
48 }
49
55 void SetPos(int pos_x, int pos_y, unsigned int option = kDxlibGuiAnchorLeftTop);
56
59 [[nodiscard]] constexpr int GetPosMiddleX() const noexcept
60 {
61 return pos_middle_x;
62 }
63
66 [[nodiscard]] constexpr int GetPosMiddleY() const noexcept
67 {
68 return pos_middle_y;
69 }
70
71 void Update() override;
72
73 void Draw() const override;
74
75 void SetVisible(bool visible) override
76 {
77 visible_ = visible;
78 }
79
80 bool IsVisible() const override
81 {
82 return visible_;
83 }
84
85 void ClickedAction(const DxlibMouseState& state) override;
86
87 bool CursorOnGui(int cursor_x, int cursor_y) const noexcept override;
88
89private:
90 int GetFitButtonSizeX(int now_size_x) const noexcept;
91 int GetFitButtonSizeY(int now_size_y) const noexcept;
92
93 const int kFontSize{ 16 };
94 const std::string kFontPath{ "font/Yu_Gothic_UI.dft" };
95
97 std::vector<std::string> text_;
98
100 int now_color_blue_{ 0 };
101 int target_color_blue_{ 0 };
102
103 bool visible_{ true };
104
105 int pos_middle_x, pos_middle_y;
106 const int kSizeX, kSizeY;
107
109 std::function<void()> click_function_;
110};
111
112} // namespace designlab
113
114
115#endif // DESIGNLAB_SIMPLE_BUTTON_H_
クリック可能なGUIのインターフェース.
Dxlibの画面に表示するGUIのインターフェース.
Dxlibのウィンドウのボタンの処理・描画を管理するクラス.
constexpr int GetPosMiddleX() const noexcept
ボタンのx座標を取得する.
bool IsVisible() const override
GUIの表示を行うかどうかを返す.
void SetPos(int pos_x, int pos_y, unsigned int option=kDxlibGuiAnchorLeftTop)
ボタンの座標を設定する.
constexpr int GetPosMiddleY() const noexcept
ボタンのy座標を取得する.
void Draw() const override
GUIの描画.
void Update() override
GUIの更新,毎フレーム実行すること.
bool CursorOnGui(int cursor_x, int cursor_y) const noexcept override
GUIの上にカーソルがあるかどうかを返す.
void SetVisible(bool visible) override
GUIの表示を行うかどうかを設定する.
SimpleButton()=delete
デフォルトコンストラクタは生成できない.
void SetActivateFunction(const std::function< void()> &func)
ボタンがクリックされたときに実行される関数を設定する.
void ClickedAction(const DxlibMouseState &state) override
GUIがクリックされたときに実行される関数. CursorOnGuiが true を返すときに呼び出される. 複数のGUIが重なっている場合は,優先度の高いものから順に呼び出される.
constexpr unsigned int kDxlibGuiAnchorLeftTop
マウスの状態を表す構造体.