GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
abstract_dxlib_gui.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_ABSTRACT_DXLIB_GUI_H_
9#define DESIGNLAB_ABSTRACT_DXLIB_GUI_H_
10
11#include <memory>
12#include <string>
13#include <vector>
14
17#include "interface_dxlib_gui.h"
18#include "simple_button.h"
19
20namespace designlab
21{
22
29 public IDxlibGui,
30 public IDxlibClickable,
31 public IDxlibDraggable
32{
33public:
34 AbstractDxlibGui() = delete;
35 AbstractDxlibGui(int width, int height);
36 virtual ~AbstractDxlibGui() = default;
37
48 void SetPos(int pos_x, int pos_y,
49 unsigned int option = kDxlibGuiAnchorLeftTop,
50 bool this_is_first_time = false);
51
52 // IDxlibGui interface
53
54 virtual void Update() = 0;
55 virtual void Draw() const = 0;
56
57 void SetVisible(bool visible) override;
58
59 [[nodiscard]] constexpr bool IsVisible() const override { return visible_; }
60
61 // IDxlibClickable interface
62
63 void ClickedAction(const DxlibMouseState& state) override;
64
65 bool CursorOnGui(int cursor_x, int cursor_y) const noexcept override;
66
67 // IDxlibDraggable interface
68
69 bool IsDraggable(int cursor_x, int cursor_y) const override;
70
71 bool IsDragged() const override
72 {
73 return is_dragging_;
74 };
75
76 void SetDragged(const bool is_dragged) override
77 {
78 is_dragging_ = is_dragged;
79 };
80
81 void DraggedAction(
82 int cursor_dif_x, int cursor_dif_y, unsigned int mouse_key_bit) override;
83
84protected:
85 void DrawBackground(const std::string& str) const;
86
87 std::vector<std::unique_ptr<SimpleButton>> button_;
88
89 static constexpr int kTitleBarHeight{ 32 };
90
91 const int width_;
92 const int height_;
93
95 bool visible_{ true };
96
98 bool is_dragging_{ false };
99
101 int gui_top_pos_y_{ 0 };
102
103 int init_pos_x_{ 0 };
104 int init_pos_y_{ 0 };
105
106 int font_handle_{ -1 };
107};
108
109} // namespace designlab
110
111
112#endif // DESIGNLAB_ABSTRACT_DXLIB_GUI_H_
Dxlibを使ったGUIの抽象クラス.
int init_pos_y_
SetされたGUIの左上のY座標.
void SetDragged(const bool is_dragged) override
ドラッグ中かどうかを設定する.
void SetPos(int pos_x, int pos_y, unsigned int option=kDxlibGuiAnchorLeftTop, bool this_is_first_time=false)
GUIの位置を設定する. Dxlibの画面の座標は左上を原点とし,右下に行くほど値が大きくなる. 横方向にx軸,縦方向にy軸をとる.
void DrawBackground(const std::string &str) const
bool visible_
GUIが表示されているかどうかのフラグ.
int gui_left_pos_x_
GUIの左端の位置.
static constexpr int kTitleBarHeight
タイトルバーの高さ.
const int width_
GUIの横幅.
int gui_top_pos_y_
GUIの上端の位置.
bool IsDragged() const override
ドラッグ中かどうかを取得する.
virtual void Draw() const =0
GUIの描画.
void SetVisible(bool visible) override
GUIの表示を行うかどうかを設定する.
void DraggedAction(int cursor_dif_x, int cursor_dif_y, unsigned int mouse_key_bit) override
ドラッグ中の処理を行う. カーソルは上にあるけど,ドラッグ中ではない場合でも呼び出される.
virtual ~AbstractDxlibGui()=default
bool IsDraggable(int cursor_x, int cursor_y) const override
ドラッグ可能な位置にあるかを判定する.
constexpr bool IsVisible() const override
GUIの表示を行うかどうかを返す.
virtual void Update()=0
GUIの更新,毎フレーム実行すること.
bool CursorOnGui(int cursor_x, int cursor_y) const noexcept override
GUIの上にカーソルがあるかどうかを返す.
int init_pos_x_
SetされたGUIの左上のX座標.
int font_handle_
フォントハンドル.
std::vector< std::unique_ptr< SimpleButton > > button_
ボタンのリスト.
const int height_
GUIの縦幅.
void ClickedAction(const DxlibMouseState &state) override
GUIがクリックされたときに実行される関数. CursorOnGuiが true を返すときに呼び出される. 複数のGUIが重なっている場合は,優先度の高いものから順に呼び出される.
クリック可能なGUIのインターフェース.
ドラッグ可能なGUIのインターフェース.
Dxlibの画面に表示するGUIのインターフェース.
constexpr unsigned int kDxlibGuiAnchorLeftTop
マウスの状態を表す構造体.