-
Notifications
You must be signed in to change notification settings - Fork 2
Button hudget #546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Button hudget #546
Changes from all commits
ef177fe
508130f
17c6736
ccaa5c0
6abe92d
de7421f
28dd753
c483e2b
30cbecb
4cb1f33
2025c05
b10a8e4
ff88081
f9cc792
0ffe45d
a8d7c0f
d9bbe2b
e99667f
617ff47
db528bd
96328d3
82f0e35
63b5c80
e37bf54
2f8f3ba
50527ce
85435b5
ec7c65c
287ec9d
3ed3521
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| enum class ClickType { | ||
| None, | ||
| Selection, | ||
| Fire | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include "buttonhudget.h" | ||
|
|
||
| #include "hud.h" | ||
| #include "buttonhudgetvoxels.h" | ||
|
|
||
|
|
||
| ButtonHudget::ButtonHudget(HUD* hud, const glm::vec3 &direction, const std::function<void(ClickType clickType)>& callback, TextOrientation textOrientation, float scale, const std::string& content, FontSize fontSize, ButtonStyle buttonStyle) : | ||
| Hudget(hud), | ||
| m_buttonVoxels(new ButtonHudgetVoxels(this, direction, textOrientation, scale, content, fontSize, buttonStyle)), | ||
| m_callback(callback) | ||
| { | ||
| m_buttonVoxels->updateBounds(); | ||
| } | ||
|
|
||
| ButtonHudget::~ButtonHudget() = default; | ||
|
|
||
| void ButtonHudget::update(float deltaSec) { | ||
| } | ||
|
|
||
| void ButtonHudget::draw() { | ||
| m_buttonVoxels->draw(); | ||
| } | ||
|
|
||
| bool ButtonHudget::isAt(const Ray& ray) const { | ||
| return m_buttonVoxels->isAt(ray); | ||
| } | ||
|
|
||
| void ButtonHudget::onClick(ClickType clickType) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather like if(m_callback) mmh?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we allow setting nullptrs as callbacks? if you want no action on click you should rather use a dummy callback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case it should be possible to not set a callback at all - I know of no GUI-API that requires you to react in some way if some button is pressed. |
||
| if (m_callback) { | ||
| m_callback(clickType); | ||
| } | ||
| } | ||
|
|
||
| void ButtonHudget::setCallback(const std::function<void(ClickType clickType)>& callback) { | ||
| m_callback = callback; | ||
| } | ||
|
|
||
| void ButtonHudget::setText(const std::string& content) { | ||
| m_buttonVoxels->setText(content); | ||
| } | ||
|
|
||
| void ButtonHudget::setTextOrientation(TextOrientation textOrientation) { | ||
| m_buttonVoxels->setTextOrientation(textOrientation); | ||
| } | ||
|
|
||
| ButtonStyle ButtonHudget::buttonStyle() { | ||
| return m_buttonVoxels->buttonStyle(); | ||
| } | ||
|
|
||
| void ButtonHudget::setButtonStyle(ButtonStyle buttonStyle) { | ||
| m_buttonVoxels->setButtonStyle(buttonStyle); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <functional> | ||
|
|
||
| #include "hudget.h" | ||
| #include "ui/voxelfontconstants.h" | ||
|
|
||
|
|
||
| class ButtonHudgetVoxels; | ||
| class TextFieldHudgetVoxels; | ||
|
|
||
| class ButtonHudget : public Hudget { | ||
| public: | ||
| ButtonHudget(HUD* hud, const glm::vec3& direction, const std::function<void(ClickType clickType)>& callback, TextOrientation textOrientation = TextOrientation::FORWARDS, float scale = 0.5f, const std::string& content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle borderStyle = ButtonStyle::BORDERED); | ||
| virtual ~ButtonHudget(); | ||
|
|
||
| virtual void update(float deltaSec) override; | ||
| virtual void draw() override; | ||
|
|
||
| virtual bool isAt(const Ray& ray) const override; | ||
|
|
||
| virtual void onClick(ClickType clicktype) override; | ||
|
|
||
| void setText(const std::string& content); | ||
|
|
||
| void setCallback(const std::function<void(ClickType clickType)>& callback); | ||
|
|
||
| void setTextOrientation(TextOrientation textOrientation); | ||
|
|
||
| ButtonStyle buttonStyle(); | ||
| void setButtonStyle(ButtonStyle buttonStyle); | ||
|
|
||
| protected: | ||
| std::function<void(ClickType clickType)> m_callback; | ||
| std::string m_content; | ||
| std::unique_ptr<ButtonHudgetVoxels> m_buttonVoxels; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nl++