[ADD] menu now works

menu switches to next item when hand is closed and calls OnClick() when hand is closed
This commit is contained in:
Jasper
2021-06-04 16:32:26 +02:00
parent 7cc918fdf8
commit b3412e414e
8 changed files with 171 additions and 72 deletions

View File

@@ -17,7 +17,6 @@ namespace gui
* position = The center position of the gui
* scale = The size (scale) of the gui
*/
struct GuiTexture
{
int texture;
@@ -27,10 +26,9 @@ namespace gui
virtual GuiType GetType() {
return GuiType::LABEL;
}
GuiTexture(int texture, glm::vec2 position, glm::vec2 scale): texture(texture), position(position), scale(scale)
{
scale.x /= (WINDOW_WIDTH / WINDOW_HEIGT);
scale.x /= (WINDOW_WIDTH / WINDOW_HEIGHT);
}
};
}

View File

@@ -2,6 +2,8 @@
#include <GLFW/glfw3.h>
#include "gui_interactable.h"
#include <iostream>
namespace gui
{
InteractableGui::InteractableGui(int default_texture, glm::vec2 position, glm::vec2 scale)
@@ -41,6 +43,35 @@ namespace gui
}
}
void InteractableGui::ForceClick( int mouseButton)
{
if(mouseButton == GLFW_MOUSE_BUTTON_LEFT)
{
if (clicked_texture != 0)
{
texture = clicked_texture;
}
else
{
texture = default_texture;
}
if (!is_clicking)
{
OnClick();
is_clicking = true;
}
}
else
{
if (is_clicking)
{
is_clicking = false;
}
}
}
bool InteractableGui::IsHoveringAbove(GLFWwindow* window)
{
double x_pos, y_pos;

View File

@@ -1,5 +1,6 @@
#pragma once
#include <iostream>
#include <glm/gtc/matrix_transform.hpp>
#include "../toolbox/toolbox.h"
#include "gui_element.h"
@@ -32,6 +33,14 @@ namespace gui
*/
void Update(GLFWwindow* window);
/*
* @brief: Call this function when you want to perform a mouseclick
*
* @param mousebutton: mouseButton you want to perform the click on
*/
void ForceClick(int mouseButton);
/*
* @brief: This function gets called when the InteractabeGui is clicked
*/
@@ -50,7 +59,10 @@ namespace gui
/*
* @brief: This function sets the texture of the InteractableGUI for when the InteractableGUI is clicked
*/
void SetClickedTexture(int texture) { clicked_texture = texture; }
void SetClickedTexture(int texture)
{
clicked_texture = texture;
}
/*
* @brief: This function sets the texture of the InteractableGUI for when the mouse is hovering above the InteractableGUI