From 29a17ee0005624c696e4331d2f9ed05628f6e34d Mon Sep 17 00:00:00 2001 From: vandalo Date: Thu, 15 Mar 2018 21:02:10 +0100 Subject: [PATCH] EditButton has focus Now the editButton has the variable focus, it sets when clic on hover. --- LCSEngine/ElementGameUI.cpp | 16 ++++++++++++++++ LCSEngine/ElementGameUI.h | 1 + LCSEngine/ModuleGameUI.cpp | 28 ++++++++++++++++++++++++++++ LCSEngine/UIButton.cpp | 23 ++++------------------- LCSEngine/UIButton.h | 1 - LCSEngine/UIEditText.cpp | 14 +++++++++++++- LCSEngine/UIEditText.h | 3 +++ 7 files changed, 65 insertions(+), 21 deletions(-) diff --git a/LCSEngine/ElementGameUI.cpp b/LCSEngine/ElementGameUI.cpp index dc35f73..750657c 100644 --- a/LCSEngine/ElementGameUI.cpp +++ b/LCSEngine/ElementGameUI.cpp @@ -4,6 +4,9 @@ #include "ElementGameUI.h" #include "Imgui/imgui.h" #include "ModuleSceneMain.h" +#include "MathGeoLib/src/Math/MathFunc.h" +#include "MathGeoLib/src/Math/float3x4.h" +#include "ModuleInput.h" ElementGameUI::ElementGameUI(GameObject* parent, int x, int y, int h, int w, bool isVisible) @@ -26,3 +29,16 @@ void ElementGameUI::startGUI() void ElementGameUI::endGUI() { } + +bool ElementGameUI::isHover() +{ + iPoint mousePosition = App->input->getMousePosition(); + if (mousePosition.x > rect.x && mousePosition.x < rect.x + rect.w) + { + if (mousePosition.y > rect.y && mousePosition.y < rect.y + rect.h) + { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/LCSEngine/ElementGameUI.h b/LCSEngine/ElementGameUI.h index 4339d64..41ce98b 100644 --- a/LCSEngine/ElementGameUI.h +++ b/LCSEngine/ElementGameUI.h @@ -12,6 +12,7 @@ class ElementGameUI virtual void drawGUI() = 0; void startGUI(); void endGUI(); + bool isHover(); public: TypeElemeneGametUI type; diff --git a/LCSEngine/ModuleGameUI.cpp b/LCSEngine/ModuleGameUI.cpp index a6c3fcd..81a9eeb 100644 --- a/LCSEngine/ModuleGameUI.cpp +++ b/LCSEngine/ModuleGameUI.cpp @@ -160,6 +160,34 @@ void ModuleGameUI::printGameUI() glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, background->idIdxVAO); + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL); + + UILabel* label = (UILabel*)((UIEditText*)(*it))->label; + UIImage* imageLabel = (UIImage*)label->textImage; + + glUniform1i(glGetUniformLocation(program, "useText"), true); + + if (label->fontData != nullptr) + { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, label->fontData->idTexture); + glUniform1i(glGetUniformLocation(program, "text"), 0); + + glBindBuffer(GL_ARRAY_BUFFER, imageLabel->idTexCoords); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)0); + } + + glBindBuffer(GL_ARRAY_BUFFER, imageLabel->idVertVBO); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); + + glBindBuffer(GL_ARRAY_BUFFER, imageLabel->idColors); + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, imageLabel->idIdxVAO); + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL); break; } diff --git a/LCSEngine/UIButton.cpp b/LCSEngine/UIButton.cpp index 3461b9b..61c3128 100644 --- a/LCSEngine/UIButton.cpp +++ b/LCSEngine/UIButton.cpp @@ -3,8 +3,6 @@ #include "ModuleSceneMain.h" #include "ElementGameUI.h" #include "UIButton.h" -#include "MathGeoLib/src/Math/MathFunc.h" -#include "MathGeoLib/src/Math/float3x4.h" #include "Imgui/imgui.h" #include "GameObject.h" #include "UIImage.h" @@ -12,6 +10,7 @@ #include "ElementFactory.h" #include "ModuleInput.h" + UIButton::UIButton(GameObject* parent, int x, int y, int h, int w, bool isVisible) : ElementGameUI(parent, x, y, h, w, isVisible) { type = BUTTON; @@ -104,23 +103,21 @@ void UIButton::update() label->update(); updateState(); - - } void UIButton::updateState() { KeyState click = App->input->getMouseButtonDown(1); bool mouseHoverButton = isHover(); - if (disabled->textureName != "" && !enable) + if (disabled->textureName[0] != '\0' && !enable) { activeImage = disabled; } - else if (pressed->textureName != "" && ((click == KEY_DOWN && mouseHoverButton) || (click == KEY_REPEAT && activeImage == pressed && mouseHoverButton))) + else if (pressed->textureName[0] != '\0' && ((click == KEY_DOWN && mouseHoverButton) || (click == KEY_REPEAT && activeImage == pressed && mouseHoverButton))) { activeImage = pressed; } - else if (mouseHoverButton && hover->textureName != "") + else if (mouseHoverButton && hover->textureName[0] != '\0') { activeImage = hover; } @@ -130,15 +127,3 @@ void UIButton::updateState() } } -bool UIButton::isHover() -{ - iPoint mousePosition = App->input->getMousePosition(); - if (mousePosition.x > rect.x && mousePosition.x < rect.x + rect.w) - { - if (mousePosition.y > rect.y && mousePosition.y < rect.y + rect.h) - { - return true; - } - } - return false; -} \ No newline at end of file diff --git a/LCSEngine/UIButton.h b/LCSEngine/UIButton.h index dbddf70..caa60b7 100644 --- a/LCSEngine/UIButton.h +++ b/LCSEngine/UIButton.h @@ -21,7 +21,6 @@ class UIButton : public ElementGameUI private: void updateState(); - bool isHover(); private: UIImage* background = nullptr; diff --git a/LCSEngine/UIEditText.cpp b/LCSEngine/UIEditText.cpp index 895522c..737dc5f 100644 --- a/LCSEngine/UIEditText.cpp +++ b/LCSEngine/UIEditText.cpp @@ -10,6 +10,7 @@ #include "ElementFactory.h" #include "UIImage.h" #include "UILabel.h" +#include "ModuleInput.h" UIEditText::UIEditText(GameObject* parent, int x, int y, int h, int w, bool isVisible) : ElementGameUI(parent, x, y, h, w, isVisible) { @@ -55,7 +56,7 @@ void UIEditText::drawGUI() } ImGui::InputText("Selected", &selected->textureName[0], IM_ARRAYSIZE(selected->textureName)); - if (ImGui::Button("Set hover") && selected->textureName != selected->texName) + if (ImGui::Button("Set selected") && selected->textureName != selected->texName) { selected->textureChanged = true; } @@ -68,4 +69,15 @@ void UIEditText::update() selected->rect = rect; background->updateCoords(); selected->updateCoords(); + + KeyState click = App->input->getMouseButtonDown(1); + bool mouseHoverButton = isHover(); + if (mouseHoverButton && click == KEY_DOWN) + { + focus = true; + } + else if (!mouseHoverButton && click == KEY_DOWN) + { + focus = false; + } } diff --git a/LCSEngine/UIEditText.h b/LCSEngine/UIEditText.h index 67ac9dd..68fcfaa 100644 --- a/LCSEngine/UIEditText.h +++ b/LCSEngine/UIEditText.h @@ -18,6 +18,9 @@ class UIEditText : public ElementGameUI UILabel* label = nullptr; UIImage* background = nullptr; UIImage* selected = nullptr; + bool focus = false; + + }; #endif //__UIEDITTEXT_H__ \ No newline at end of file