mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 13:57:51 +00:00
GUI2: simplified some in-rect checks using sdl::point_in_rect
This commit is contained in:
parent
ec388ebe55
commit
68ed124449
@ -72,11 +72,11 @@ unsigned horizontal_scrollbar::offset_after() const
|
||||
|
||||
bool horizontal_scrollbar::on_positioner(const point& coordinate) const
|
||||
{
|
||||
SDL_Rect positioner_rect =
|
||||
sdl::create_rect(get_positioner_offset(), 0, get_positioner_length(), get_height());
|
||||
|
||||
// Note we assume the positioner is over the entire height of the widget.
|
||||
return coordinate.x >= static_cast<int>(get_positioner_offset())
|
||||
&& coordinate.x < static_cast<int>(get_positioner_offset()
|
||||
+ get_positioner_length())
|
||||
&& coordinate.y > 0 && coordinate.y < static_cast<int>(get_height());
|
||||
return sdl::point_in_rect(coordinate, positioner_rect);
|
||||
}
|
||||
|
||||
int horizontal_scrollbar::on_bar(const point& coordinate) const
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "gui/core/event/message.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "lexical_cast.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
#include "utils/functional.hpp"
|
||||
|
||||
@ -73,11 +74,7 @@ struct pane_implementation
|
||||
* If the adjusted coordinate is in the item's grid let the grid
|
||||
* resolve the coordinate.
|
||||
*/
|
||||
const SDL_Rect rect = item.item_grid->get_rectangle();
|
||||
if(coordinate.x >= rect.x && coordinate.y >= rect.y
|
||||
&& coordinate.x < rect.x + rect.w
|
||||
&& coordinate.y < rect.y + rect.h) {
|
||||
|
||||
if(sdl::point_in_rect(coordinate, item.item_grid->get_rectangle())) {
|
||||
return item.item_grid->find_at(coordinate, must_be_active);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "gui/core/notifier.hpp"
|
||||
#include "gui/widgets/styled_widget.hpp"
|
||||
|
||||
#include "sdl/rect.hpp"
|
||||
#include "utils/functional.hpp"
|
||||
|
||||
namespace gui2
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "gui/core/register_widget.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "gettext.hpp"
|
||||
@ -132,12 +133,11 @@ unsigned slider::offset_after() const
|
||||
|
||||
bool slider::on_positioner(const point& coordinate) const
|
||||
{
|
||||
SDL_Rect positioner_rect =
|
||||
sdl::create_rect(get_positioner_offset(), 0, get_positioner_length(), get_height());
|
||||
|
||||
// Note we assume the positioner is over the entire height of the widget.
|
||||
return
|
||||
coordinate.x >= static_cast<int>(get_positioner_offset()) &&
|
||||
coordinate.x < static_cast<int>(get_positioner_offset() + get_positioner_length()) &&
|
||||
coordinate.y > 0 &&
|
||||
coordinate.y < static_cast<int>(get_height());
|
||||
return sdl::point_in_rect(coordinate, positioner_rect);
|
||||
}
|
||||
|
||||
int slider::on_bar(const point& coordinate) const
|
||||
@ -265,14 +265,14 @@ void slider::set_step_size(int step_size)
|
||||
{
|
||||
const int old_min_value = get_minimum_value();
|
||||
const int old_max_value = get_maximum_value();
|
||||
|
||||
|
||||
const int range_diff = get_item_count() - 1;
|
||||
const int old_value = get_value();
|
||||
|
||||
step_size_ = gcd(range_diff, step_size);
|
||||
slider_set_item_last(range_diff / step_size_);
|
||||
set_value(old_value);
|
||||
|
||||
|
||||
assert(old_min_value == get_minimum_value());
|
||||
assert(old_max_value == get_maximum_value());
|
||||
}
|
||||
|
@ -63,11 +63,11 @@ unsigned vertical_scrollbar::offset_after() const
|
||||
|
||||
bool vertical_scrollbar::on_positioner(const point& coordinate) const
|
||||
{
|
||||
// Note we assume the positioner is over the entire width of the widget.
|
||||
return coordinate.y >= static_cast<int>(get_positioner_offset())
|
||||
&& coordinate.y < static_cast<int>(get_positioner_offset()
|
||||
+ get_positioner_length())
|
||||
&& coordinate.x > 0 && coordinate.x < static_cast<int>(get_width());
|
||||
SDL_Rect positioner_rect =
|
||||
sdl::create_rect(0, get_positioner_offset(), get_width(), get_positioner_length());
|
||||
|
||||
// Note we assume the positioner is over the entire height of the widget.
|
||||
return sdl::point_in_rect(coordinate, positioner_rect);
|
||||
}
|
||||
|
||||
int vertical_scrollbar::on_bar(const point& coordinate) const
|
||||
|
@ -625,9 +625,7 @@ bool widget::is_at(const point& coordinate, const bool must_be_active) const
|
||||
return false;
|
||||
}
|
||||
|
||||
return coordinate.x >= x_ && coordinate.x < (x_ + static_cast<int>(width_))
|
||||
&& coordinate.y >= y_
|
||||
&& coordinate.y < (y_ + static_cast<int>(height_));
|
||||
return sdl::point_in_rect(coordinate, get_rectangle());
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
Loading…
x
Reference in New Issue
Block a user