Skip to content

Commit 03e252e

Browse files
committed
basic gui for assigning keybinds
1 parent 6ddd1eb commit 03e252e

File tree

13 files changed

+169
-68
lines changed

13 files changed

+169
-68
lines changed

data/cage/texture/keybindAdd.png

4.86 KB
Loading

data/cage/texture/keybindReset.png

15.4 KB
Loading

data/cage/texture/texture.assets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ srgb = true
55
gamma = true
66
gui.png
77
tooltips.png
8+
keybindAdd.png
9+
keybindReset.png
810

911
[]
1012
scheme = texture

sources/include/cage-engine/guiBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ namespace cage
5555
template<StringLiteral Text>
5656
BuilderItem tooltip()
5757
{
58-
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<Text>() };
58+
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<0, Text>() };
5959
return *this;
6060
}
61-
template<uint32 TextId>
61+
template<uint32 TextId, StringLiteral Text = "">
6262
BuilderItem tooltip()
6363
{
64-
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<TextId>() };
64+
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<TextId, Text>() };
6565
return *this;
6666
}
6767

sources/include/cage-engine/guiComponents.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace cage
1818
struct CAGE_ENGINE_API GuiSkinIndex
1919
{
2020
constexpr GuiSkinIndex() = default;
21-
constexpr explicit GuiSkinIndex(uint32 index) : index(index){};
21+
constexpr explicit GuiSkinIndex(uint32 index) : index(index) {};
2222

2323
uint32 index = m; // -1 = inherit
2424
};
@@ -235,7 +235,7 @@ namespace cage
235235
{
236236
Real f;
237237
sint32 i = 0;
238-
Union(){};
238+
Union() {};
239239
} min, max, step;
240240
uint32 cursor = m; // utf32 characters (not bytes)
241241
InputTypeEnum type = InputTypeEnum::Text;
@@ -326,17 +326,10 @@ namespace cage
326326
CAGE_ENGINE_API void guiDestroyChildrenRecursively(Entity *e);
327327
CAGE_ENGINE_API void guiDestroyEntityRecursively(Entity *e);
328328

329-
template<StringLiteral Text>
329+
template<uint32 TextId, StringLiteral Text = "">
330330
GuiTooltipComponent::TooltipCallback guiTooltipText()
331331
{
332-
static constexpr GuiTextComponent txt{ Text.value, 0 };
333-
return privat::guiTooltipText(&txt);
334-
}
335-
336-
template<uint32 TextId>
337-
GuiTooltipComponent::TooltipCallback guiTooltipText()
338-
{
339-
static constexpr GuiTextComponent txt{ "", TextId };
332+
static constexpr GuiTextComponent txt{ Text.value, TextId };
340333
return privat::guiTooltipText(&txt);
341334
}
342335
}

sources/include/cage-engine/inputs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ namespace cage
254254
using Param = typename privat::ExtractParam<Func>::Param;
255255
return inputFilter<Param>([func](const Param &in) { return func(in); });
256256
}
257+
258+
CAGE_ENGINE_API detail::StringBase<27> getKeyName(uint32 key);
259+
CAGE_ENGINE_API detail::StringBase<27> getButtonsNames(MouseButtonsFlags buttons);
260+
CAGE_ENGINE_API detail::StringBase<27> getModifiersNames(ModifiersFlags mods);
257261
}
258262

259263
#endif // guard_inputs_juhgf98ser4g

sources/include/cage-engine/keybinds.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
namespace cage
77
{
88
class Ini;
9+
namespace guiBuilder
10+
{
11+
class GuiBuilder;
12+
}
913

1014
class CAGE_ENGINE_API Keybind : private Immovable
1115
{
1216
public:
17+
const String &id() const;
1318
String name() const;
1419
String value(uint32 index = 0) const;
1520
bool process(const GenericInput &input) const;
@@ -34,13 +39,26 @@ namespace cage
3439
};
3540
GCHL_ENUM_BITS(KeybindDevicesFlags);
3641

42+
enum class KeybindModesFlags : uint32
43+
{
44+
None = 0,
45+
Press = 1 << 0,
46+
Repeat = 1 << 1,
47+
Double = 1 << 2,
48+
Release = 1 << 3,
49+
Scroll = 1 << 4,
50+
Tick = 1 << 5,
51+
};
52+
GCHL_ENUM_BITS(KeybindModesFlags);
53+
3754
struct CAGE_ENGINE_API KeybindCreateConfig
3855
{
3956
String id;
4057
sint32 eventOrder = 0;
4158
ModifiersFlags requiredFlags = ModifiersFlags::None;
4259
ModifiersFlags forbiddenFlags = ModifiersFlags::Super;
43-
KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard;
60+
KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard | KeybindDevicesFlags::Mouse;
61+
KeybindModesFlags modes = KeybindModesFlags::Press;
4462
};
4563

4664
CAGE_ENGINE_API Holder<Keybind> newKeybind(const KeybindCreateConfig &config, const GenericInput &defaults = {}, Delegate<bool(const GenericInput &)> event = {});
@@ -56,6 +74,9 @@ namespace cage
5674
}
5775
CAGE_ENGINE_API void keybindsDispatchTick();
5876

77+
CAGE_ENGINE_API void keybindsGuiWidget(guiBuilder::GuiBuilder *g, Keybind *keybind);
78+
CAGE_ENGINE_API void keybindsGuiTable(guiBuilder::GuiBuilder *g, const String &filterPrefix = {});
79+
5980
CAGE_ENGINE_API Holder<Ini> keybindsExport();
6081
CAGE_ENGINE_API void keybindsImport(const Ini *ini);
6182
}

sources/include/cage-engine/window.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace cage
5757
Vec2i windowedPosition() const;
5858
void windowedPosition(Vec2i pos);
5959

60+
// opengl
6061
void makeCurrent();
6162
void makeNotCurrent();
6263
void swapBuffers();
@@ -69,6 +70,10 @@ namespace cage
6970
};
7071

7172
CAGE_ENGINE_API Holder<Window> newWindow(const WindowCreateConfig &config);
73+
74+
CAGE_ENGINE_API detail::StringBase<27> getKeyName(uint32 key);
75+
CAGE_ENGINE_API detail::StringBase<27> getButtonsNames(MouseButtonsFlags buttons);
76+
CAGE_ENGINE_API detail::StringBase<27> getModifiersNames(ModifiersFlags mods);
7277
}
7378

7479
#endif

sources/libengine/gui/gui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace cage
3737
[this](Entity *e)
3838
{
3939
if (e->has<GuiTooltipMarkerComponent>())
40-
return this->tooltipRemoved(e);
40+
this->tooltipRemoved(e);
4141
});
4242
}
4343

sources/libengine/gui/private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ namespace cage
342342
void ttMouseMove(input::MouseMove in);
343343
void updateTooltips();
344344
void clearTooltips();
345-
bool tooltipRemoved(Entity *e);
345+
void tooltipRemoved(Entity *e);
346346

347347
explicit GuiImpl(const GuiManagerCreateConfig &config);
348348
~GuiImpl();

0 commit comments

Comments
 (0)