mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:58:12 +00:00
LibGUI: GButton should only react to the left mouse button (for pushing.)
This commit is contained in:
parent
35c06f1520
commit
83228d03d8
1 changed files with 28 additions and 18 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include "GButton.h"
|
#include "GButton.h"
|
||||||
#include <SharedGraphics/Painter.h>
|
#include <SharedGraphics/Painter.h>
|
||||||
|
|
||||||
|
//#define GBUTTON_DEBUG
|
||||||
|
|
||||||
GButton::GButton(GWidget* parent)
|
GButton::GButton(GWidget* parent)
|
||||||
: GWidget(parent)
|
: GWidget(parent)
|
||||||
{
|
{
|
||||||
|
@ -58,10 +60,10 @@ void GButton::paint_event(GPaintEvent&)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!caption().is_empty()) {
|
if (!caption().is_empty()) {
|
||||||
auto textRect = rect();
|
auto text_rect = rect();
|
||||||
if (m_being_pressed)
|
if (m_being_pressed)
|
||||||
textRect.move_by(1, 1);
|
text_rect.move_by(1, 1);
|
||||||
painter.draw_text(textRect, caption(), Painter::TextAlignment::Center, Color::Black);
|
painter.draw_text(text_rect, caption(), Painter::TextAlignment::Center, Color::Black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,26 +81,34 @@ void GButton::mousemove_event(GMouseEvent& event)
|
||||||
|
|
||||||
void GButton::mousedown_event(GMouseEvent& event)
|
void GButton::mousedown_event(GMouseEvent& event)
|
||||||
{
|
{
|
||||||
dbgprintf("Button::mouseDownEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
|
#ifdef GBUTTON_DEBUG
|
||||||
m_being_pressed = true;
|
dbgprintf("GButton::mouse_down_event: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
|
||||||
m_tracking_cursor = true;
|
#endif
|
||||||
set_global_cursor_tracking(true);
|
if (event.button() == GMouseButton::Left) {
|
||||||
update();
|
m_being_pressed = true;
|
||||||
|
m_tracking_cursor = true;
|
||||||
|
set_global_cursor_tracking(true);
|
||||||
|
update();
|
||||||
|
}
|
||||||
GWidget::mousedown_event(event);
|
GWidget::mousedown_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GButton::mouseup_event(GMouseEvent& event)
|
void GButton::mouseup_event(GMouseEvent& event)
|
||||||
{
|
{
|
||||||
dbgprintf("Button::mouseUpEvent: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
|
#ifdef GBUTTON_DEBUG
|
||||||
bool was_being_pressed = m_being_pressed;
|
dbgprintf("GButton::mouse_up_event: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
|
||||||
m_being_pressed = false;
|
#endif
|
||||||
m_tracking_cursor = false;
|
if (event.button() == GMouseButton::Left) {
|
||||||
set_global_cursor_tracking(false);
|
bool was_being_pressed = m_being_pressed;
|
||||||
update();
|
m_being_pressed = false;
|
||||||
GWidget::mouseup_event(event);
|
m_tracking_cursor = false;
|
||||||
if (was_being_pressed) {
|
set_global_cursor_tracking(false);
|
||||||
if (on_click)
|
update();
|
||||||
on_click(*this);
|
if (was_being_pressed) {
|
||||||
|
if (on_click)
|
||||||
|
on_click(*this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
GWidget::mouseup_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue