Skip to content

Commit

Permalink
basic gui for assigning keybinds
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Jan 25, 2025
1 parent 6ddd1eb commit 4fdc834
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 68 deletions.
Binary file added data/cage/texture/keybindAdd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/cage/texture/keybindReset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/cage/texture/texture.assets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ srgb = true
gamma = true
gui.png
tooltips.png
keybindAdd.png
keybindReset.png

[]
scheme = texture
Expand Down
6 changes: 3 additions & 3 deletions sources/include/cage-engine/guiBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ namespace cage
template<StringLiteral Text>
BuilderItem tooltip()
{
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<Text>() };
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<0, Text>() };
return *this;
}
template<uint32 TextId>
template<uint32 TextId, StringLiteral Text = "">
BuilderItem tooltip()
{
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<TextId>() };
(*this)->template value<GuiTooltipComponent>() = GuiTooltipComponent{ .tooltip = detail::guiTooltipText<TextId, Text>() };
return *this;
}

Expand Down
15 changes: 4 additions & 11 deletions sources/include/cage-engine/guiComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace cage
struct CAGE_ENGINE_API GuiSkinIndex
{
constexpr GuiSkinIndex() = default;
constexpr explicit GuiSkinIndex(uint32 index) : index(index){};
constexpr explicit GuiSkinIndex(uint32 index) : index(index) {};

uint32 index = m; // -1 = inherit
};
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace cage
{
Real f;
sint32 i = 0;
Union(){};
Union() {};
} min, max, step;
uint32 cursor = m; // utf32 characters (not bytes)
InputTypeEnum type = InputTypeEnum::Text;
Expand Down Expand Up @@ -326,17 +326,10 @@ namespace cage
CAGE_ENGINE_API void guiDestroyChildrenRecursively(Entity *e);
CAGE_ENGINE_API void guiDestroyEntityRecursively(Entity *e);

template<StringLiteral Text>
template<uint32 TextId, StringLiteral Text = "">
GuiTooltipComponent::TooltipCallback guiTooltipText()
{
static constexpr GuiTextComponent txt{ Text.value, 0 };
return privat::guiTooltipText(&txt);
}

template<uint32 TextId>
GuiTooltipComponent::TooltipCallback guiTooltipText()
{
static constexpr GuiTextComponent txt{ "", TextId };
static constexpr GuiTextComponent txt{ Text.value, TextId };
return privat::guiTooltipText(&txt);
}
}
Expand Down
4 changes: 4 additions & 0 deletions sources/include/cage-engine/inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ namespace cage
using Param = typename privat::ExtractParam<Func>::Param;
return inputFilter<Param>([func](const Param &in) { return func(in); });
}

CAGE_ENGINE_API detail::StringBase<27> getKeyName(uint32 key);
CAGE_ENGINE_API detail::StringBase<27> getButtonsNames(MouseButtonsFlags buttons);
CAGE_ENGINE_API detail::StringBase<27> getModifiersNames(ModifiersFlags mods);
}

#endif // guard_inputs_juhgf98ser4g
20 changes: 19 additions & 1 deletion sources/include/cage-engine/keybinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
namespace cage
{
class Ini;
class GuiBuilder;

class CAGE_ENGINE_API Keybind : private Immovable
{
public:
const String &id() const;
String name() const;
String value(uint32 index = 0) const;
bool process(const GenericInput &input) const;
Expand All @@ -34,13 +36,26 @@ namespace cage
};
GCHL_ENUM_BITS(KeybindDevicesFlags);

enum class KeybindModesFlags : uint32
{
None = 0,
Press = 1 << 0,
Repeat = 1 << 1,
Double = 1 << 2,
Release = 1 << 3,
Scroll = 1 << 4,
Tick = 1 << 5,
};
GCHL_ENUM_BITS(KeybindModesFlags);

struct CAGE_ENGINE_API KeybindCreateConfig
{
String id;
sint32 eventOrder = 0;
ModifiersFlags requiredFlags = ModifiersFlags::None;
ModifiersFlags forbiddenFlags = ModifiersFlags::Super;
KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard;
KeybindDevicesFlags devices = KeybindDevicesFlags::Keyboard | KeybindDevicesFlags::Mouse;
KeybindModesFlags modes = KeybindModesFlags::Press;
};

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

CAGE_ENGINE_API void keybindsGuiWidget(GuiBuilder *g, Keybind *keybind);
CAGE_ENGINE_API void keybindsGuiTable(GuiBuilder *g, const String &filterPrefix = {});

CAGE_ENGINE_API Holder<Ini> keybindsExport();
CAGE_ENGINE_API void keybindsImport(const Ini *ini);
}
Expand Down
5 changes: 5 additions & 0 deletions sources/include/cage-engine/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace cage
Vec2i windowedPosition() const;
void windowedPosition(Vec2i pos);

// opengl
void makeCurrent();
void makeNotCurrent();
void swapBuffers();
Expand All @@ -69,6 +70,10 @@ namespace cage
};

CAGE_ENGINE_API Holder<Window> newWindow(const WindowCreateConfig &config);

CAGE_ENGINE_API detail::StringBase<27> getKeyName(uint32 key);
CAGE_ENGINE_API detail::StringBase<27> getButtonsNames(MouseButtonsFlags buttons);
CAGE_ENGINE_API detail::StringBase<27> getModifiersNames(ModifiersFlags mods);
}

#endif
2 changes: 1 addition & 1 deletion sources/libengine/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace cage
[this](Entity *e)
{
if (e->has<GuiTooltipMarkerComponent>())
return this->tooltipRemoved(e);
this->tooltipRemoved(e);
});
}

Expand Down
2 changes: 1 addition & 1 deletion sources/libengine/gui/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ namespace cage
void ttMouseMove(input::MouseMove in);
void updateTooltips();
void clearTooltips();
bool tooltipRemoved(Entity *e);
void tooltipRemoved(Entity *e);

explicit GuiImpl(const GuiManagerCreateConfig &config);
~GuiImpl();
Expand Down
3 changes: 1 addition & 2 deletions sources/libengine/gui/tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,9 @@ namespace cage
ttHasMovedSinceLast = false;
}

bool GuiImpl::tooltipRemoved(Entity *e)
void GuiImpl::tooltipRemoved(Entity *e)
{
std::erase_if(ttData, [&](const TooltipData &tt) { return tt.tooltip == e; });
return false;
}

namespace
Expand Down
Loading

0 comments on commit 4fdc834

Please sign in to comment.