Skip to content

Commit 4fdc834

Browse files
committed
basic gui for assigning keybinds
1 parent 6ddd1eb commit 4fdc834

File tree

13 files changed

+166
-68
lines changed

13 files changed

+166
-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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
namespace cage
77
{
88
class Ini;
9+
class GuiBuilder;
910

1011
class CAGE_ENGINE_API Keybind : private Immovable
1112
{
1213
public:
14+
const String &id() const;
1315
String name() const;
1416
String value(uint32 index = 0) const;
1517
bool process(const GenericInput &input) const;
@@ -34,13 +36,26 @@ namespace cage
3436
};
3537
GCHL_ENUM_BITS(KeybindDevicesFlags);
3638

39+
enum class KeybindModesFlags : uint32
40+
{
41+
None = 0,
42+
Press = 1 << 0,
43+
Repeat = 1 << 1,
44+
Double = 1 << 2,
45+
Release = 1 << 3,
46+
Scroll = 1 << 4,
47+
Tick = 1 << 5,
48+
};
49+
GCHL_ENUM_BITS(KeybindModesFlags);
50+
3751
struct CAGE_ENGINE_API KeybindCreateConfig
3852
{
3953
String id;
4054
sint32 eventOrder = 0;
4155
ModifiersFlags requiredFlags = ModifiersFlags::None;
4256
ModifiersFlags forbiddenFlags = ModifiersFlags::Super;
43-
KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard;
57+
KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard | KeybindDevicesFlags::Mouse;
58+
KeybindModesFlags modes = KeybindModesFlags::Press;
4459
};
4560

4661
CAGE_ENGINE_API Holder<Keybind> newKeybind(const KeybindCreateConfig &config, const GenericInput &defaults = {}, Delegate<bool(const GenericInput &)> event = {});
@@ -56,6 +71,9 @@ namespace cage
5671
}
5772
CAGE_ENGINE_API void keybindsDispatchTick();
5873

74+
CAGE_ENGINE_API void keybindsGuiWidget(GuiBuilder *g, Keybind *keybind);
75+
CAGE_ENGINE_API void keybindsGuiTable(GuiBuilder *g, const String &filterPrefix = {});
76+
5977
CAGE_ENGINE_API Holder<Ini> keybindsExport();
6078
CAGE_ENGINE_API void keybindsImport(const Ini *ini);
6179
}

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)