summaryrefslogtreecommitdiffstats
path: root/src/Widget.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-09-16 17:48:19 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-01-13 03:39:31 +0100
commit892b9732751b64c2016ba476801e1fe4ed4e750f (patch)
tree99aa40953de5d61e30d47bdf345ee2cb9c3c18e1 /src/Widget.cpp
parent2017-09-15 (diff)
downloadAltCraft-892b9732751b64c2016ba476801e1fe4ed4e750f.tar
AltCraft-892b9732751b64c2016ba476801e1fe4ed4e750f.tar.gz
AltCraft-892b9732751b64c2016ba476801e1fe4ed4e750f.tar.bz2
AltCraft-892b9732751b64c2016ba476801e1fe4ed4e750f.tar.lz
AltCraft-892b9732751b64c2016ba476801e1fe4ed4e750f.tar.xz
AltCraft-892b9732751b64c2016ba476801e1fe4ed4e750f.tar.zst
AltCraft-892b9732751b64c2016ba476801e1fe4ed4e750f.zip
Diffstat (limited to '')
-rw-r--r--src/Widget.cpp124
1 files changed, 0 insertions, 124 deletions
diff --git a/src/Widget.cpp b/src/Widget.cpp
deleted file mode 100644
index 1a522ca..0000000
--- a/src/Widget.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-#include "Widget.hpp"
-
-void RootWidget::AttachWidget(std::unique_ptr<Widget> widget, Widget * parent)
-{
- parent->childs.push_back(widget.get());
- this->allWidgets.push_back(std::move(widget));
-}
-
-void RootWidget::AttachWidget(std::unique_ptr<Widget> widget) {
- widget->parent = nullptr;
- this->childs.push_back(widget.get());
- this->allWidgets.push_back(std::move(widget));
-}
-
-std::vector<Widget*> RootWidget::GetRenderList()
-{
- std::vector<Widget*> renderList;
-
- std::function<void(Widget*)> treeWalker = [&](Widget* node) {
- for (auto it : node->childs)
- treeWalker(it);
- renderList.push_back(node);
- };
-
- for (auto& it : this->childs)
- treeWalker(it);
-
- return renderList;
-}
-
-void RootWidget::UpdateEvents(double mouseX, double mouseY, bool mouseButton) {
-
- LOG(INFO) << mouseX << "x" << mouseY;
-
- auto testIsHover = [&](double x, double y, Widget* widget) {
- bool isOnX = widget->x > x && widget->x + widget->w < x;
- bool isOnY = widget->y > y && widget->y + widget->h < y;
- if (mouseButton)
- LOG(INFO) << "X: " << isOnX << " Y: " << isOnY;
- return isOnX && isOnY;
- };
-
- std::function<void(Widget*)> treeWalker = [&](Widget* node) {
- for (auto it : node->childs)
- treeWalker(it);
-
- if (testIsHover(mouseX,mouseY,node)) {
- if (node->onHover)
- node->onHover(node);
- if (mouseButton && !prevBut)
- if (node->onPress)
- node->onPress(node);
- else if (!mouseButton && prevBut)
- if (node->onRelease)
- node->onRelease(node);
- }
- else {
- if (testIsHover(prevX, prevY, node))
- if (node->onUnhover)
- node->onUnhover(node);
- }
-
- if (node->onUpdate)
- node->onUpdate(node);
- };
-
- for (auto it : childs)
- treeWalker(it);
-
- prevX = mouseX;
- prevY = mouseY;
- prevBut = mouseButton;
-}
-
-WidgetButton::WidgetButton()
-{
- this->state = WidgetState::Idle;
-
- onHover = [](Widget* widget) {
- WidgetButton* w = dynamic_cast<WidgetButton*>(widget);
- if (w->state != WidgetState::Pressed)
- w->state = WidgetState::Hovering;
- LOG(INFO) << "Hover";
- };
-
- onPress = [](Widget* widget) {
- WidgetButton* w = dynamic_cast<WidgetButton*>(widget);
- w->state = WidgetState::Pressed;
- LOG(INFO) << "Press";
- };
-
- onRelease = [](Widget* widget) {
- WidgetButton* w = dynamic_cast<WidgetButton*>(widget);
- w->state = WidgetState::Idle;
- w->onClick(w);
- LOG(INFO) << "Release";
- };
-
- onUnhover = [](Widget *widget) {
- WidgetButton* w = dynamic_cast<WidgetButton*>(widget);
- if (w->state!=WidgetState::Pressed)
- w->state = WidgetState::Idle;
- LOG(INFO) << "Unhover";
- };
-
-}
-
-std::tuple<double, double, double, double> WidgetButton::GetTexture()
-{
- double yOffset;
- switch (this->state) {
- case WidgetState::Idle:
- yOffset = 0.2578;
- break;
- case WidgetState::Hovering:
- yOffset = 0.3359;
- break;
- case WidgetState::Pressed:
- yOffset = 0.1796;
- }
-
- TextureCoordinates texture = AssetManager::Instance().GetTextureByAssetName("minecraft/textures/gui/widgets");
- return { texture.x,texture.y + texture.h * yOffset,texture.w * 0.7812,texture.h * 0.07812 };
-}