Make use of sdl::get_mouse_location() when possible
This commit is contained in:
parent
0e8edd12e4
commit
84c414c58b
7 changed files with 19 additions and 29 deletions
|
@ -131,8 +131,7 @@ common_palette& editor_toolkit::get_palette()
|
|||
void editor_toolkit::update_mouse_action_highlights()
|
||||
{
|
||||
DBG_ED << __func__;
|
||||
int x, y;
|
||||
sdl::get_mouse_state(&x, &y);
|
||||
auto [x, y] = sdl::get_mouse_location();
|
||||
map_location hex_clicked = gui_.hex_clicked_on(x,y);
|
||||
get_mouse_action().update_brush_highlights(gui_, hex_clicked);
|
||||
}
|
||||
|
|
|
@ -429,8 +429,7 @@ void command_executor::show_menu(const std::vector<config>& items_arg, int xloc,
|
|||
std::string id = items[res]["id"];
|
||||
const theme::menu* submenu = gui.get_theme().get_menu_item(id);
|
||||
if (submenu) {
|
||||
int y,x;
|
||||
sdl::get_mouse_state(&x,&y);
|
||||
auto [x, y] = sdl::get_mouse_location();
|
||||
this->show_menu(submenu->items(), x, y, submenu->is_context(), gui);
|
||||
} else {
|
||||
hotkey::ui_command cmd = hotkey::ui_command(id, res);
|
||||
|
|
|
@ -128,13 +128,14 @@ void mouse_handler::touch_motion(int x, int y, const bool browse, bool update, m
|
|||
|
||||
// Fire the drag & drop only after minimal drag distance
|
||||
// While we check the mouse buttons state, we also grab fresh position data.
|
||||
point pos = drag_from_; // some default value to prevent unlikely SDL bug
|
||||
|
||||
if(is_dragging() && !dragging_started_) {
|
||||
if(dragging_touch_) {
|
||||
sdl::get_mouse_state(&pos.x, &pos.y);
|
||||
const double drag_distance = std::pow(static_cast<double>(drag_from_.x - pos.x), 2)
|
||||
+ std::pow(static_cast<double>(drag_from_.y- pos.y), 2);
|
||||
point pos = sdl::get_mouse_location();
|
||||
const double drag_distance =
|
||||
std::pow(static_cast<double>(drag_from_.x - pos.x), 2) +
|
||||
std::pow(static_cast<double>(drag_from_.y - pos.y), 2);
|
||||
|
||||
if(drag_distance > drag_threshold()*drag_threshold()) {
|
||||
dragging_started_ = true;
|
||||
}
|
||||
|
@ -145,11 +146,10 @@ void mouse_handler::touch_motion(int x, int y, const bool browse, bool update, m
|
|||
const auto found_unit = find_unit(selected_hex_);
|
||||
bool selected_hex_has_my_unit = found_unit.valid() && found_unit.get_shared_ptr()->side() == side_num_;
|
||||
if((browse || !found_unit.valid()) && is_dragging() && dragging_started_) {
|
||||
sdl::get_mouse_state(&pos.x, &pos.y);
|
||||
|
||||
if(gui().map_area().contains(x, y)) {
|
||||
point dist = drag_from_ - pos;
|
||||
gui().scroll(dist);
|
||||
point pos = sdl::get_mouse_location();
|
||||
gui().scroll(drag_from_ - pos);
|
||||
drag_from_ = pos;
|
||||
}
|
||||
return;
|
||||
|
@ -672,9 +672,7 @@ const unit* mouse_handler::find_unit_nonowning(const map_location& hex) const
|
|||
|
||||
const map_location mouse_handler::hovered_hex() const
|
||||
{
|
||||
int x = -1;
|
||||
int y = -1;
|
||||
sdl::get_mouse_state(&x, &y);
|
||||
auto [x, y] = sdl::get_mouse_location();
|
||||
return gui_->hex_clicked_on(x, y);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,8 +91,7 @@ void mouse_handler_base::touch_motion_event(const SDL_TouchFingerEvent& event, c
|
|||
|
||||
void mouse_handler_base::mouse_update(const bool browse, map_location loc)
|
||||
{
|
||||
int x, y;
|
||||
sdl::get_mouse_state(&x, &y);
|
||||
auto [x, y] = sdl::get_mouse_location();
|
||||
mouse_motion(x, y, browse, true, loc);
|
||||
}
|
||||
|
||||
|
@ -129,10 +128,11 @@ bool mouse_handler_base::mouse_motion_default(int x, int y, bool /*update*/)
|
|||
|
||||
// Fire the drag & drop only after minimal drag distance
|
||||
// While we check the mouse buttons state, we also grab fresh position data.
|
||||
point pos = drag_from_; // some default value to prevent unlikely SDL bug
|
||||
|
||||
if(is_dragging() && !dragging_started_) {
|
||||
Uint32 mouse_state = dragging_left_ || dragging_right_ ? sdl::get_mouse_state(&pos.x, &pos.y) : 0;
|
||||
point pos = drag_from_; // some default value to prevent unlikely SDL bug
|
||||
uint32_t mouse_state = dragging_left_ || dragging_right_ ? sdl::get_mouse_state(&pos.x, &pos.y) : 0;
|
||||
|
||||
#ifdef MOUSE_TOUCH_EMULATION
|
||||
if(dragging_left_ && (mouse_state & SDL_BUTTON(SDL_BUTTON_RIGHT))) {
|
||||
// Monkey-patch touch controls again to make them look like left button.
|
||||
|
@ -354,8 +354,7 @@ void mouse_handler_base::left_drag_end(int /*x*/, int /*y*/, const bool browse)
|
|||
|
||||
void mouse_handler_base::mouse_wheel(int scrollx, int scrolly, bool browse)
|
||||
{
|
||||
int x, y;
|
||||
sdl::get_mouse_state(&x, &y);
|
||||
auto [x, y] = sdl::get_mouse_location();
|
||||
|
||||
int movex = scrollx * prefs::get().scroll_speed();
|
||||
int movey = scrolly * prefs::get().scroll_speed();
|
||||
|
@ -405,7 +404,7 @@ void mouse_handler_base::right_mouse_up(int x, int y, const bool browse)
|
|||
void mouse_handler_base::init_dragging(bool& dragging_flag)
|
||||
{
|
||||
dragging_flag = true;
|
||||
sdl::get_mouse_state(&drag_from_.x, &drag_from_.y);
|
||||
drag_from_ = sdl::get_mouse_location();
|
||||
drag_from_hex_ = gui().hex_clicked_on(drag_from_.x, drag_from_.y);
|
||||
}
|
||||
|
||||
|
|
|
@ -187,8 +187,7 @@ int switch_theme(lua_State* L) {
|
|||
*/
|
||||
int show_menu(lua_State* L) {
|
||||
std::vector<config> items = lua_check<std::vector<config>>(L, 1);
|
||||
SDL_Rect pos {1,1,1,1};
|
||||
sdl::get_mouse_state(&pos.x, &pos.y);
|
||||
rect pos{ sdl::get_mouse_location(), {1, 1} };
|
||||
|
||||
int initial = -1;
|
||||
bool markup = false;
|
||||
|
|
|
@ -153,9 +153,7 @@ void scrollarea::handle_event(const SDL_Event& event)
|
|||
|
||||
if (event.type == SDL_MOUSEWHEEL) {
|
||||
const SDL_MouseWheelEvent &ev = event.wheel;
|
||||
int x, y;
|
||||
sdl::get_mouse_state(&x, &y);
|
||||
if (inner_location().contains(x, y)) {
|
||||
if (inner_location().contains(sdl::get_mouse_location())) {
|
||||
if (ev.y > 0) {
|
||||
scrollbar_.scroll_up();
|
||||
} else if (ev.y < 0) {
|
||||
|
|
|
@ -272,9 +272,7 @@ void scrollbar::handle_event(const SDL_Event& event)
|
|||
case SDL_MOUSEWHEEL:
|
||||
{
|
||||
const SDL_MouseWheelEvent& e = event.wheel;
|
||||
int x, y;
|
||||
sdl::get_mouse_state(&x, &y);
|
||||
bool on_groove = groove.contains(x, y);
|
||||
bool on_groove = groove.contains(sdl::get_mouse_location());
|
||||
if (on_groove && e.y < 0) {
|
||||
move_position(scroll_rate_);
|
||||
} else if (on_groove && e.y > 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue