27
27
#include " KeyButton.h"
28
28
#include < LibGUI/Button.h>
29
29
#include < LibGUI/Painter.h>
30
+ #include < LibGUI/Window.h>
30
31
#include < LibGfx/Font.h>
31
32
#include < LibGfx/Palette.h>
32
33
@@ -39,25 +40,30 @@ void KeyButton::paint_event(GUI::PaintEvent& event)
39
40
GUI::Painter painter (*this );
40
41
painter.add_clip_rect (event.rect ());
41
42
42
- auto content_rect = rect (). shrunken ( 5 , 5 );
43
+ auto cont_rect = rect ();
43
44
auto & font = this ->font ();
44
45
45
- Gfx::StylePainter::paint_button (painter, rect (), palette (), Gfx::ButtonStyle::Normal, is_being_pressed (), is_hovered (), is_checked (), true );
46
+ Color color;
47
+ if (m_pressed) {
48
+ color = Color::Cyan;
49
+ } else if (!is_enabled ()) {
50
+ color = Color::LightGray;
51
+ } else {
52
+ color = Color::White;
53
+ }
46
54
47
- if (m_pressed)
48
- painter. fill_rect (content_rect, Color::Cyan );
49
- else if (! is_enabled ())
50
- painter. fill_rect (content_rect, Color::from_rgb ( 0x8C7272 ) );
55
+ painter. fill_rect (cont_rect, Color::Black);
56
+ painter. fill_rect ({ cont_rect. x () + 1 , cont_rect. y () + 1 , cont_rect. width () - 2 , cont_rect. height () - 2 }, Color::from_rgb ( 0x999999 ) );
57
+ painter. fill_rect ({ cont_rect. x () + 6 , cont_rect. y () + 3 , cont_rect. width () - 12 , cont_rect. height () - 12 }, Color::from_rgb ( 0x8C7272 ));
58
+ painter. fill_rect ({ cont_rect. x () + 7 , cont_rect. y () + 4 , cont_rect. width () - 14 , cont_rect. height () - 14 }, color );
51
59
52
60
if (!text ().is_empty ()) {
53
61
Gfx::IntRect text_rect { 0 , 0 , font.width (text ()), font.glyph_height () };
54
- text_rect.align_within (content_rect, Gfx::TextAlignment::Center);
55
-
56
- auto clipped_rect = rect ().intersected (this ->rect ());
62
+ text_rect.align_within ({ cont_rect.x () + 7 , cont_rect.y () + 4 , cont_rect.width () - 14 , cont_rect.height () - 14 }, Gfx::TextAlignment::Center);
57
63
58
- painter.draw_text (clipped_rect , text (), font, Gfx::TextAlignment::Center, palette ().button_text (), Gfx::TextElision::Right);
64
+ painter.draw_text (text_rect , text (), font, Gfx::TextAlignment::Center, palette ().button_text (), Gfx::TextElision::Right);
59
65
if (is_focused ())
60
- painter.draw_rect (clipped_rect .inflated (6 , 4 ), palette ().focus_outline ());
66
+ painter.draw_rect (text_rect .inflated (6 , 4 ), palette ().focus_outline ());
61
67
}
62
68
}
63
69
@@ -66,3 +72,26 @@ void KeyButton::click(unsigned)
66
72
if (on_click)
67
73
on_click ();
68
74
}
75
+
76
+ void KeyButton::mousemove_event (GUI::MouseEvent& event)
77
+ {
78
+ if (!is_enabled ())
79
+ return ;
80
+
81
+ Gfx::IntRect c = { rect ().x () + 7 , rect ().y () + 4 , rect ().width () - 14 , rect ().height () - 14 };
82
+
83
+ if (c.contains (event.position ())) {
84
+ window ()->set_override_cursor (GUI::StandardCursor::Hand);
85
+ return ;
86
+ }
87
+ window ()->set_override_cursor (GUI::StandardCursor::Arrow);
88
+
89
+ AbstractButton::mousemove_event (event);
90
+ }
91
+
92
+ void KeyButton::leave_event (Core::Event& event)
93
+ {
94
+ window ()->set_override_cursor (GUI::StandardCursor::Arrow);
95
+ AbstractButton::leave_event (event);
96
+ }
97
+
0 commit comments