18
18
19
19
#include " supertux/gameconfig.hpp"
20
20
#include " supertux/globals.hpp"
21
+ #include " supertux/resources.hpp"
22
+ #include " util/log.hpp"
21
23
#include " video/viewport.hpp"
22
24
#include " video/video_system.hpp"
23
25
@@ -28,7 +30,9 @@ ButtonWidget::ButtonWidget(SpritePtr sprite, const Vector& pos,
28
30
static_cast<float>(m_sprite->get_height ()))),
29
31
m_grab(false ),
30
32
m_hover(false ),
31
- m_sig_click(std::move(sig_click))
33
+ m_sig_click(std::move(sig_click)),
34
+ m_mouse_pos(),
35
+ m_help_text()
32
36
{
33
37
}
34
38
@@ -49,6 +53,16 @@ ButtonWidget::draw(DrawingContext& context)
49
53
context.color ().draw_filled_rect (m_rect, g_config->editorhovercolor , 4 .0f ,
50
54
LAYER_GUI-5 );
51
55
}
56
+
57
+ if (m_hover && !m_help_text.empty ())
58
+ {
59
+ const auto & font = Resources::console_font;
60
+ const auto text_height = font->get_text_height (m_help_text);
61
+ const auto text_width = font->get_text_width (m_help_text);
62
+ const auto text_rect = Rectf (m_mouse_pos + Vector (32 , 32 ), m_mouse_pos + Vector (32 , 32 ) + Vector (text_width, text_height));
63
+ context.color ().draw_filled_rect (text_rect, Color::BLACK, LAYER_GUI - 5 );
64
+ context.color ().draw_text (font, m_help_text, m_mouse_pos + Vector (32 , 32 ), FontAlignment::ALIGN_LEFT, LAYER_GUI - 5 );
65
+ }
52
66
}
53
67
54
68
void
@@ -71,10 +85,10 @@ ButtonWidget::on_mouse_button_up(const SDL_MouseButtonEvent& button)
71
85
{
72
86
if (button.button != SDL_BUTTON_LEFT) return false ;
73
87
74
- Vector mouse_pos = VideoSystem::current ()->get_viewport ().to_logical (button.x , button.y );
88
+ m_mouse_pos = VideoSystem::current ()->get_viewport ().to_logical (button.x , button.y );
75
89
76
90
if (m_grab) {
77
- if (m_rect.contains (mouse_pos )) {
91
+ if (m_rect.contains (m_mouse_pos )) {
78
92
if (m_sig_click) {
79
93
m_sig_click ();
80
94
}
@@ -92,9 +106,9 @@ ButtonWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
92
106
{
93
107
if (button.button != SDL_BUTTON_LEFT) return false ;
94
108
95
- Vector mouse_pos = VideoSystem::current ()->get_viewport ().to_logical (button.x , button.y );
109
+ m_mouse_pos = VideoSystem::current ()->get_viewport ().to_logical (button.x , button.y );
96
110
97
- if (m_rect.contains (mouse_pos )) {
111
+ if (m_rect.contains (m_mouse_pos )) {
98
112
m_hover = true ;
99
113
m_grab = true ;
100
114
return true ;
@@ -107,12 +121,12 @@ ButtonWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
107
121
bool
108
122
ButtonWidget::on_mouse_motion (const SDL_MouseMotionEvent& motion)
109
123
{
110
- Vector mouse_pos = VideoSystem::current ()->get_viewport ().to_logical (motion.x , motion.y );
124
+ m_mouse_pos = VideoSystem::current ()->get_viewport ().to_logical (motion.x , motion.y );
111
125
112
126
if (m_grab) {
113
- m_hover = m_rect.contains (mouse_pos );
127
+ m_hover = m_rect.contains (m_mouse_pos );
114
128
return true ;
115
- } else if (m_rect.contains (mouse_pos )) {
129
+ } else if (m_rect.contains (m_mouse_pos )) {
116
130
m_hover = true ;
117
131
return false ;
118
132
} else {
@@ -134,4 +148,10 @@ ButtonWidget::set_sprite(const std::string& path)
134
148
set_sprite (SpriteManager::current ()->create (path));
135
149
}
136
150
151
+ void
152
+ ButtonWidget::set_help_text (const std::string& help_text)
153
+ {
154
+ m_help_text = help_text;
155
+ }
156
+
137
157
/* EOF */
0 commit comments