Implement was_clicked state for rect input listener.
This commit is contained in:
@@ -93,6 +93,7 @@ namespace JUI {
|
||||
float border_radius = 0; // Curves the rectangle corners by n degrees
|
||||
|
||||
MouseButtonState prev_state{false, false, false};
|
||||
bool was_clicked = false;
|
||||
private:
|
||||
bool mouse_hover = false;
|
||||
#pragma endregion
|
||||
|
@@ -87,11 +87,7 @@ namespace JUI {
|
||||
}
|
||||
//SDL_RenderDrawRect(target, &box);
|
||||
|
||||
|
||||
// Debug Draw
|
||||
|
||||
|
||||
|
||||
std::string data = fmt::format("[{}, {}]", Round(abs_pos.x, 2), Round(abs_pos.y, 2));
|
||||
//FC_DrawAlign(JUI::debug_font.fc_font, target, abs_pos.X, abs_pos.Y, FC_ALIGN_LEFT, data.c_str());
|
||||
data = "";
|
||||
@@ -103,9 +99,6 @@ namespace JUI {
|
||||
SDL_RenderSetClipRect(target, old_clip);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Rect::Update(double delta)
|
||||
{
|
||||
Widget::Update(delta);
|
||||
@@ -128,27 +121,33 @@ namespace JUI {
|
||||
|
||||
|
||||
if (!prev_state.LMB && state.LMB && mouse_hover) {
|
||||
was_clicked = true;
|
||||
MousePressed.Invoke(MouseButtonID::LMB);
|
||||
}
|
||||
|
||||
if (prev_state.LMB && !state.LMB) {
|
||||
if (prev_state.LMB && !state.LMB && was_clicked) {
|
||||
MouseReleased.Invoke(MouseButtonID::LMB);
|
||||
was_clicked = false;
|
||||
}
|
||||
|
||||
if (!prev_state.RMB && state.RMB && mouse_hover) {
|
||||
was_clicked = true;
|
||||
MousePressed.Invoke(MouseButtonID::RMB);
|
||||
}
|
||||
|
||||
if (prev_state.RMB && !state.RMB) {
|
||||
if (prev_state.RMB && !state.RMB && was_clicked) {
|
||||
MouseReleased.Invoke(MouseButtonID::RMB);
|
||||
was_clicked = false;
|
||||
}
|
||||
|
||||
if (!prev_state.MMB && state.MMB && mouse_hover) {
|
||||
was_clicked = true;
|
||||
MousePressed.Invoke(MouseButtonID::MMB);
|
||||
}
|
||||
|
||||
if (prev_state.MMB && !state.MMB) {
|
||||
if (prev_state.MMB && !state.MMB && was_clicked) {
|
||||
MouseReleased.Invoke(MouseButtonID::MMB);
|
||||
was_clicked = false;
|
||||
}
|
||||
|
||||
if (drag)
|
||||
|
Reference in New Issue
Block a user