gui2/text_box: Implement I-beam cursor
This is a backport to 1.14 of multiple commits from master: * gui2/text_box: Implement I-beam cursord7f2595393
* Don't forcefully disable colour cursorsfc04268aa4
* Set the I-beam cursor's hotspot properlyc31047af47
This cursor is active when the widget has the mouse focus. You know, like textboxes are wont to do anywhere else. Took long enough, although there was an interaction issue with tooltips fixed in the previous commit. I still need to figure out how to make this work with GUI1 textboxes (e.g. in-game console). The colour version of the cursor was kindly provided by LordBob, and the B&W version is my own.
This commit is contained in:
parent
487ee0ceec
commit
50494b7f06
6 changed files with 26 additions and 1 deletions
BIN
images/cursors-bw/ibeam.png
Normal file
BIN
images/cursors-bw/ibeam.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
BIN
images/cursors/ibeam.png
Normal file
BIN
images/cursors/ibeam.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -55,6 +55,7 @@ std::array<cursor_data, cursor::NUM_CURSORS> available_cursors {{
|
|||
#ifdef __APPLE__
|
||||
{ nullptr, boost::indeterminate, "normal.png", "normal.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "wait-alt.png", "wait.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "ibeam.png", "ibeam.png", 14, 14 },
|
||||
{ nullptr, boost::indeterminate, "move.png", "move.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "attack.png", "attack.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "select.png", "select.png", 0, 0 },
|
||||
|
@ -64,6 +65,7 @@ std::array<cursor_data, cursor::NUM_CURSORS> available_cursors {{
|
|||
#else
|
||||
{ nullptr, boost::indeterminate, "normal.png", "normal.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "wait.png", "wait.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "ibeam.png", "ibeam.png", 14, 14 },
|
||||
{ nullptr, boost::indeterminate, "move.png", "move.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "attack.png", "attack.png", 0, 0 },
|
||||
{ nullptr, boost::indeterminate, "select.png", "select.png", 0, 0 },
|
||||
|
|
|
@ -27,7 +27,7 @@ struct manager
|
|||
~manager();
|
||||
};
|
||||
|
||||
enum CURSOR_TYPE { NORMAL, WAIT, MOVE, ATTACK, HYPERLINK, MOVE_DRAG, ATTACK_DRAG, NO_CURSOR, NUM_CURSORS };
|
||||
enum CURSOR_TYPE { NORMAL, WAIT, IBEAM, MOVE, ATTACK, HYPERLINK, MOVE_DRAG, ATTACK_DRAG, NO_CURSOR, NUM_CURSORS };
|
||||
|
||||
/**
|
||||
* Use the default parameter to reset cursors.
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "gui/widgets/text_box_base.hpp"
|
||||
|
||||
#include "cursor.hpp"
|
||||
#include "desktop/clipboard.hpp"
|
||||
#include "gui/core/log.hpp"
|
||||
#include "gui/core/timer.hpp"
|
||||
|
@ -72,6 +73,7 @@ text_box_base::text_box_base(const implementation::builder_styled_widget& builde
|
|||
text_box_base::~text_box_base()
|
||||
{
|
||||
toggle_cursor_timer(false);
|
||||
update_mouse_cursor(false);
|
||||
}
|
||||
|
||||
void text_box_base::set_active(const bool active)
|
||||
|
@ -670,6 +672,8 @@ void text_box_base::signal_handler_mouse_enter(const event::ui_event event,
|
|||
set_state(HOVERED);
|
||||
}
|
||||
|
||||
update_mouse_cursor(true);
|
||||
|
||||
handled = true;
|
||||
}
|
||||
|
||||
|
@ -682,6 +686,23 @@ void text_box_base::signal_handler_mouse_leave(const event::ui_event event,
|
|||
set_state(ENABLED);
|
||||
}
|
||||
|
||||
update_mouse_cursor(false);
|
||||
|
||||
handled = true;
|
||||
}
|
||||
|
||||
void text_box_base::update_mouse_cursor(bool enable)
|
||||
{
|
||||
// Someone else may set the mouse cursor for us to something unusual (e.g.
|
||||
// the WAIT cursor) so we ought to mess with that only if it's set to
|
||||
// NORMAL or IBEAM.
|
||||
|
||||
if(enable && cursor::get() == cursor::NORMAL) {
|
||||
cursor::set(cursor::IBEAM);
|
||||
} else if(!enable && cursor::get() == cursor::IBEAM) {
|
||||
cursor::set(cursor::NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -289,6 +289,8 @@ private:
|
|||
|
||||
virtual void reset_cursor_state();
|
||||
|
||||
void update_mouse_cursor(bool enable);
|
||||
|
||||
/**
|
||||
* Current state of the widget.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue