Move some functions to sdl/rect.
This commit is contained in:
parent
deeaaa7168
commit
ac96a2b91b
34 changed files with 204 additions and 195 deletions
|
@ -66,9 +66,9 @@ dialog_textbox::~dialog_textbox()
|
|||
dialog::dimension_measurements::dimension_measurements() :
|
||||
x(-1),
|
||||
y(-1),
|
||||
interior(empty_rect),
|
||||
message(empty_rect),
|
||||
textbox(empty_rect),
|
||||
interior(sdl::empty_rect),
|
||||
message(sdl::empty_rect),
|
||||
textbox(sdl::empty_rect),
|
||||
menu_width(0),
|
||||
panes(),
|
||||
label_x(-1),
|
||||
|
@ -288,7 +288,7 @@ int dialog::show()
|
|||
}
|
||||
|
||||
LOG_DP << "showing dialog '" << title_ << "' '" << message_->get_text() << "'\n";
|
||||
if(dim_.interior == empty_rect) { layout(); }
|
||||
if(dim_.interior == sdl::empty_rect) { layout(); }
|
||||
|
||||
//create the event context, remember to instruct any passed-in widgets to join it
|
||||
const events::event_context dialog_events_context;
|
||||
|
@ -771,7 +771,7 @@ int dialog::process(dialog_process_info &info)
|
|||
|
||||
//left-clicking outside of a drop-down or context-menu should close it
|
||||
if (info.new_left_button && !info.left_button) {
|
||||
if (standard_buttons_.empty() && !point_in_rect(mousex,mousey, menu_->location())) {
|
||||
if (standard_buttons_.empty() && !sdl::point_in_rect(mousex,mousey, menu_->location())) {
|
||||
if (use_menu)
|
||||
sound::play_UI_sound(game_config::sounds::button_press);
|
||||
return CLOSE_DIALOG;
|
||||
|
@ -783,7 +783,7 @@ int dialog::process(dialog_process_info &info)
|
|||
// but that may be changed to allow right-click selection instead.
|
||||
if (info.new_right_button && !info.right_button) {
|
||||
if( standard_buttons_.empty()
|
||||
|| (!point_in_rect(mousex,mousey,get_frame().get_layout().exterior)
|
||||
|| (!sdl::point_in_rect(mousex,mousey,get_frame().get_layout().exterior)
|
||||
&& type_ != YES_NO && !(type_ == OK_ONLY && has_input))) {
|
||||
sound::play_UI_sound(game_config::sounds::button_press);
|
||||
return CLOSE_DIALOG;
|
||||
|
|
|
@ -155,7 +155,7 @@ bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse
|
|||
int scroll_threshold = (preferences::mouse_scroll_enabled())
|
||||
? preferences::mouse_scroll_threshold() : 0;
|
||||
BOOST_FOREACH(const theme::menu& m, get_display().get_theme().menus()) {
|
||||
if (point_in_rect(mousex, mousey, m.get_location())) {
|
||||
if (sdl::point_in_rect(mousex, mousey, m.get_location())) {
|
||||
scroll_threshold = 0;
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse
|
|||
|
||||
if (get_mouse_handler_base().scroll_started()) {
|
||||
const SDL_Rect& rect = get_display().map_outside_area();
|
||||
if (point_in_rect(mousex, mousey,rect) &&
|
||||
if (sdl::point_in_rect(mousex, mousey,rect) &&
|
||||
get_mouse_handler_base().scroll_started()) {
|
||||
// Scroll speed is proportional from the distance from the first
|
||||
// middle click and scrolling speed preference.
|
||||
|
|
|
@ -152,7 +152,7 @@ display::display(unit_map* units, CVideo& video, const gamemap* map, const std::
|
|||
zoom_(DefaultZoom),
|
||||
builder_(new terrain_builder(level, map, theme_.border().tile_image)),
|
||||
minimap_(NULL),
|
||||
minimap_location_(empty_rect),
|
||||
minimap_location_(sdl::empty_rect),
|
||||
redrawMinimap_(false),
|
||||
redraw_background_(true),
|
||||
invalidateAll_(true),
|
||||
|
@ -650,7 +650,7 @@ bool display::outside_area(const SDL_Rect& area, const int x, const int y) const
|
|||
const map_location display::hex_clicked_on(int xclick, int yclick) const
|
||||
{
|
||||
const SDL_Rect& rect = map_area();
|
||||
if(point_in_rect(xclick,yclick,rect) == false) {
|
||||
if(sdl::point_in_rect(xclick,yclick,rect) == false) {
|
||||
return map_location();
|
||||
}
|
||||
|
||||
|
@ -798,7 +798,7 @@ map_location display::minimap_location_on(int x, int y)
|
|||
//TODO: don't return location for this,
|
||||
// instead directly scroll to the clicked pixel position
|
||||
|
||||
if (!point_in_rect(x, y, minimap_area())) {
|
||||
if (!sdl::point_in_rect(x, y, minimap_area())) {
|
||||
return map_location();
|
||||
}
|
||||
|
||||
|
@ -930,7 +930,7 @@ void display::create_buttons()
|
|||
if (!i->tooltip().empty()){
|
||||
s.set_tooltip_string(i->tooltip());
|
||||
}
|
||||
if(rects_overlap(s.location(),map_outside_area())) {
|
||||
if(sdl::rects_overlap(s.location(),map_outside_area())) {
|
||||
s.set_volatile(true);
|
||||
}
|
||||
|
||||
|
@ -960,7 +960,7 @@ void display::create_buttons()
|
|||
if (!i->tooltip().empty()){
|
||||
b.set_tooltip_string(i->tooltip());
|
||||
}
|
||||
if(rects_overlap(b.location(),map_outside_area())) {
|
||||
if(sdl::rects_overlap(b.location(),map_outside_area())) {
|
||||
b.set_volatile(true);
|
||||
}
|
||||
|
||||
|
@ -982,7 +982,7 @@ void display::create_buttons()
|
|||
if (!i->tooltip(0).empty()){
|
||||
b.set_tooltip_string(i->tooltip(0));
|
||||
}
|
||||
if(rects_overlap(b.location(),map_outside_area())) {
|
||||
if(sdl::rects_overlap(b.location(),map_outside_area())) {
|
||||
b.set_volatile(true);
|
||||
}
|
||||
|
||||
|
@ -1345,7 +1345,7 @@ void display::flip()
|
|||
SDL_Rect r = map_outside_area(); // Use frameBuffer to also test the UI
|
||||
const Uint32 color = SDL_MapRGBA(video().getSurface()->format,0,0,0,255);
|
||||
// Adjust the alpha if you want to balance cpu-cost / smooth sunset
|
||||
fill_rect_alpha(r, color, 1, frameBuffer);
|
||||
sdl::fill_rect_alpha(r, color, 1, frameBuffer);
|
||||
update_rect(r);
|
||||
}
|
||||
|
||||
|
@ -1555,7 +1555,7 @@ void display::render_image(int x, int y, const display::tdrawing_layer drawing_l
|
|||
|
||||
SDL_Rect image_rect = sdl::create_rect(x, y, image->w, image->h);
|
||||
SDL_Rect clip_rect = map_area();
|
||||
if (!rects_overlap(image_rect, clip_rect))
|
||||
if (!sdl::rects_overlap(image_rect, clip_rect))
|
||||
return;
|
||||
|
||||
surface surf(image);
|
||||
|
@ -1898,7 +1898,7 @@ void display::draw_minimap()
|
|||
int view_h = static_cast<int>(map_out_rect.h * yscaling);
|
||||
|
||||
const Uint32 box_color = SDL_MapRGB(minimap_->format,0xFF,0xFF,0xFF);
|
||||
draw_rectangle(minimap_location_.x + view_x - 1,
|
||||
sdl::draw_rectangle(minimap_location_.x + view_x - 1,
|
||||
minimap_location_.y + view_y - 1,
|
||||
view_w + 2, view_h + 2,
|
||||
box_color, screen);
|
||||
|
@ -1984,7 +1984,7 @@ bool display::scroll(int xmove, int ymove, bool force)
|
|||
SDL_Rect dstrect = map_area();
|
||||
dstrect.x += dx;
|
||||
dstrect.y += dy;
|
||||
dstrect = intersect_rects(dstrect, map_area());
|
||||
dstrect = sdl::intersect_rects(dstrect, map_area());
|
||||
|
||||
SDL_Rect srcrect = dstrect;
|
||||
srcrect.x -= dx;
|
||||
|
@ -2541,7 +2541,7 @@ void display::draw_invalidated() {
|
|||
|
||||
const bool on_map = get_map().on_board(loc);
|
||||
SDL_Rect hex_rect = sdl::create_rect(xpos, ypos, zoom_, zoom_);
|
||||
if(!rects_overlap(hex_rect,clip_rect)) {
|
||||
if(!sdl::rects_overlap(hex_rect,clip_rect)) {
|
||||
continue;
|
||||
}
|
||||
draw_hex(loc);
|
||||
|
@ -3008,7 +3008,7 @@ bool display::propagate_invalidation(const std::set<map_location>& locs)
|
|||
|
||||
bool display::invalidate_visible_locations_in_rect(const SDL_Rect& rect)
|
||||
{
|
||||
return invalidate_locations_in_rect(intersect_rects(map_area(),rect));
|
||||
return invalidate_locations_in_rect(sdl::intersect_rects(map_area(),rect));
|
||||
}
|
||||
|
||||
bool display::invalidate_locations_in_rect(const SDL_Rect& rect)
|
||||
|
|
|
@ -155,7 +155,7 @@ void palette_manager::handle_event(const SDL_Event& event) {
|
|||
|
||||
if (event.type == SDL_MOUSEMOTION) {
|
||||
// If the mouse is inside the palette, give it focus.
|
||||
if (point_in_rect(event.button.x, event.button.y, location())) {
|
||||
if (sdl::point_in_rect(event.button.x, event.button.y, location())) {
|
||||
if (!focus(&event)) set_focus(true);
|
||||
}
|
||||
// If the mouse is outside, remove focus.
|
||||
|
|
|
@ -272,7 +272,7 @@ void tristate_button::draw_contents() {
|
|||
|
||||
//TODO move to widget
|
||||
bool tristate_button::hit(int x, int y) const {
|
||||
return point_in_rect(x, y, location());
|
||||
return sdl::point_in_rect(x, y, location());
|
||||
}
|
||||
|
||||
void tristate_button::mouse_motion(SDL_MouseMotionEvent const &event) {
|
||||
|
|
|
@ -1135,7 +1135,7 @@ SDL_Rect get_floating_label_rect(int handle)
|
|||
}
|
||||
}
|
||||
|
||||
return empty_rect;
|
||||
return sdl::empty_rect;
|
||||
}
|
||||
|
||||
floating_label_context::floating_label_context()
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "gui/widgets/spacer.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "utils/foreach.tpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
@ -416,7 +417,7 @@ void tscrollbar_container::set_visible_rectangle(const SDL_Rect& rectangle)
|
|||
|
||||
// Now get the visible part of the content.
|
||||
content_visible_area_
|
||||
= intersect_rects(rectangle, content_->get_rectangle());
|
||||
= sdl::intersect_rects(rectangle, content_->get_rectangle());
|
||||
|
||||
content_grid_->set_visible_rectangle(content_visible_area_);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "gui/widgets/window.hpp"
|
||||
#include "gui/auxiliary/event/message.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -451,11 +452,11 @@ SDL_Rect twidget::get_dirty_rectangle() const
|
|||
|
||||
void twidget::set_visible_rectangle(const SDL_Rect& rectangle)
|
||||
{
|
||||
clipping_rectangle_ = intersect_rects(rectangle, get_rectangle());
|
||||
clipping_rectangle_ = sdl::intersect_rects(rectangle, get_rectangle());
|
||||
|
||||
if(clipping_rectangle_ == get_rectangle()) {
|
||||
redraw_action_ = tredraw_action::full;
|
||||
} else if(clipping_rectangle_ == empty_rect) {
|
||||
} else if(clipping_rectangle_ == sdl::empty_rect) {
|
||||
redraw_action_ = tredraw_action::none;
|
||||
} else {
|
||||
redraw_action_ = tredraw_action::partly;
|
||||
|
@ -531,7 +532,7 @@ void twidget::draw_debug_border(surface& frame_buffer)
|
|||
/* DO NOTHING */
|
||||
break;
|
||||
case 1:
|
||||
draw_rectangle(
|
||||
sdl::draw_rectangle(
|
||||
r.x, r.y, r.w, r.h, debug_border_colour_, frame_buffer);
|
||||
break;
|
||||
|
||||
|
@ -557,7 +558,7 @@ twidget::draw_debug_border(surface& frame_buffer, int x_offset, int y_offset)
|
|||
break;
|
||||
|
||||
case 1:
|
||||
draw_rectangle(
|
||||
sdl::draw_rectangle(
|
||||
r.x, r.y, r.w, r.h, debug_border_colour_, frame_buffer);
|
||||
break;
|
||||
|
||||
|
|
|
@ -762,7 +762,7 @@ void twindow::draw()
|
|||
const Uint32 color
|
||||
= SDL_MapRGBA(frame_buffer->format, 0, 0, 0, 255);
|
||||
|
||||
fill_rect_alpha(r, color, 1, frame_buffer);
|
||||
sdl::fill_rect_alpha(r, color, 1, frame_buffer);
|
||||
update_rect(r);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ effect::effect(int xpos, int ypos, const animated<image::locator>::anim_descript
|
|||
y_(ypos),
|
||||
surf_(NULL),
|
||||
buffer_(NULL),
|
||||
rect_(empty_rect),
|
||||
rect_(sdl::empty_rect),
|
||||
loc_(loc),
|
||||
overlayed_hexes_()
|
||||
{
|
||||
|
@ -184,7 +184,7 @@ bool effect::render()
|
|||
}
|
||||
}
|
||||
|
||||
if(rects_overlap(rect,clip_rect) == false) {
|
||||
if(sdl::rects_overlap(rect,clip_rect) == false) {
|
||||
buffer_.assign(NULL);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2895,7 +2895,7 @@ void help_text_area::draw_contents()
|
|||
dst.y += loc.y;
|
||||
if (it->box) {
|
||||
for (int i = 0; i < box_width; ++i) {
|
||||
draw_rectangle(dst.x, dst.y, it->rect.w - i * 2, it->rect.h - i * 2,
|
||||
sdl::draw_rectangle(dst.x, dst.y, it->rect.w - i * 2, it->rect.h - i * 2,
|
||||
0, screen);
|
||||
++dst.x;
|
||||
++dst.y;
|
||||
|
@ -2916,7 +2916,7 @@ void help_text_area::scroll(unsigned int)
|
|||
}
|
||||
|
||||
bool help_text_area::item_at::operator()(const item& item) const {
|
||||
return point_in_rect(x_, y_, item.rect);
|
||||
return sdl::point_in_rect(x_, y_, item.rect);
|
||||
}
|
||||
|
||||
std::string help_text_area::ref_at(const int x, const int y)
|
||||
|
@ -3008,7 +3008,7 @@ void help_browser::process_event()
|
|||
SDL_GetMouseState(&mousex,&mousey);
|
||||
|
||||
/// Fake focus functionality for the menu, only process it if it has focus.
|
||||
if (point_in_rect(mousex, mousey, menu_.location())) {
|
||||
if (sdl::point_in_rect(mousex, mousey, menu_.location())) {
|
||||
menu_.process();
|
||||
const topic *chosen_topic = menu_.chosen_topic();
|
||||
if (chosen_topic != NULL && chosen_topic != shown_topic_) {
|
||||
|
|
|
@ -188,7 +188,7 @@ void loadscreen::draw_screen(const std::string &text)
|
|||
textarea_.x = scrx/2 + bw + bispw - textarea_.w / 2;
|
||||
textarea_.y = pby + pbh + 4*(bw + bispw);
|
||||
textarea_ = font::draw_text(&screen_,textarea_,font::SIZE_NORMAL,font::NORMAL_COLOR,text,textarea_.x,textarea_.y);
|
||||
SDL_Rect refresh = union_rects(oldarea, textarea_);
|
||||
SDL_Rect refresh = sdl::union_rects(oldarea, textarea_);
|
||||
update_rect(refresh.x, refresh.y, refresh.w, refresh.h);
|
||||
}
|
||||
// Update the rectangle.
|
||||
|
|
|
@ -2876,7 +2876,7 @@ void console_handler::do_layers() {
|
|||
|
||||
// cut and mask the image
|
||||
// ~CROP and ~BLIT have limitations, we do some math to avoid them
|
||||
SDL_Rect r2 = intersect_rects(r, sdl::create_rect(0,0,surf->w,surf->h));
|
||||
SDL_Rect r2 = sdl::intersect_rects(r, sdl::create_rect(0,0,surf->w,surf->h));
|
||||
if(r2.w > 0 && r2.h > 0) {
|
||||
str << "~BLIT("
|
||||
<< name << "~CROP("
|
||||
|
|
|
@ -447,7 +447,7 @@ void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool br
|
|||
bool mouse_handler::right_click_show_menu(int x, int y, const bool /*browse*/)
|
||||
{
|
||||
return ( selected_hex_.valid() ? false :
|
||||
point_in_rect(x, y, gui().map_area()) );
|
||||
sdl::point_in_rect(x, y, gui().map_area()) );
|
||||
}
|
||||
|
||||
void mouse_handler::left_mouse_up(int /*x*/, int /*y*/, const bool /*browse*/)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "log.hpp"
|
||||
#include "preferences.hpp"
|
||||
#include "tooltips.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
static lg::log_domain log_display("display");
|
||||
#define WRN_DP LOG_STREAM(warn, log_display)
|
||||
|
@ -204,7 +205,7 @@ void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bo
|
|||
|
||||
// Don't scroll map and map zoom slider at same time
|
||||
gui::slider* s = gui().find_slider("map-zoom-slider");
|
||||
if (s && point_in_rect(event.x, event.y, s->location())) {
|
||||
if (s && sdl::point_in_rect(event.x, event.y, s->location())) {
|
||||
scrollx = 0; scrolly = 0;
|
||||
}
|
||||
}
|
||||
|
@ -296,7 +297,7 @@ void mouse_handler_base::mouse_wheel(int scrollx, int scrolly, bool browse)
|
|||
|
||||
// Don't scroll map and map zoom slider at same time
|
||||
gui::slider* s = gui().find_slider("map-zoom-slider");
|
||||
if (s && point_in_rect(x, y, s->location())) {
|
||||
if (s && sdl::point_in_rect(x, y, s->location())) {
|
||||
movex = 0; movey = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -396,11 +396,11 @@ void gamebrowser::handle_event(const SDL_Event& event)
|
|||
}
|
||||
const SDL_Rect& loc = inner_location();
|
||||
|
||||
if(!games_.empty() && point_in_rect(x, y, loc)) {
|
||||
if(!games_.empty() && sdl::point_in_rect(x, y, loc)) {
|
||||
for(size_t i = visible_range_.first; i != visible_range_.second; ++i) {
|
||||
const SDL_Rect& item_rect = get_item_rect(i);
|
||||
|
||||
if(point_in_rect(x, y, item_rect)) {
|
||||
if(sdl::point_in_rect(x, y, item_rect)) {
|
||||
set_focus(true);
|
||||
selected_ = i;
|
||||
break;
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace {
|
|||
user_menu_style() : gui::menu::imgsel_style("dialogs/selection", false,
|
||||
0x000000, 0x4a4440, 0x999999,
|
||||
0.0, 0.2, 0.2),
|
||||
item_size_(empty_rect)
|
||||
item_size_(sdl::empty_rect)
|
||||
{}
|
||||
virtual void init();
|
||||
virtual SDL_Rect item_size(const std::string& /*item*/) const { return item_size_; }
|
||||
|
|
|
@ -463,7 +463,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
|
|||
throw;
|
||||
} catch (end_level_exception &end_level_exn) {
|
||||
if(!past_prestart) {
|
||||
draw_solid_tinted_rectangle(
|
||||
sdl::draw_solid_tinted_rectangle(
|
||||
0, 0, gui_->video().getx(), gui_->video().gety(), 0, 0, 0, 1.0,
|
||||
gui_->video().getSurface()
|
||||
);
|
||||
|
|
|
@ -13,10 +13,14 @@
|
|||
*/
|
||||
|
||||
#include "sdl/rect.hpp"
|
||||
#include "sdl/alpha.hpp"
|
||||
#include "sdl_utils.hpp"
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
const SDL_Rect empty_rect = { 0, 0, 0, 0 };
|
||||
|
||||
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
|
@ -27,4 +31,93 @@ SDL_Rect create_rect(const int x, const int y, const int w, const int h)
|
|||
return rect;
|
||||
}
|
||||
|
||||
bool point_in_rect(int x, int y, const SDL_Rect& rect)
|
||||
{
|
||||
return x >= rect.x && y >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h;
|
||||
}
|
||||
|
||||
bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2)
|
||||
{
|
||||
return (rect1.x < rect2.x+rect2.w && rect2.x < rect1.x+rect1.w &&
|
||||
rect1.y < rect2.y+rect2.h && rect2.y < rect1.y+rect1.h);
|
||||
}
|
||||
|
||||
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2)
|
||||
{
|
||||
SDL_Rect res;
|
||||
res.x = std::max<int>(rect1.x, rect2.x);
|
||||
res.y = std::max<int>(rect1.y, rect2.y);
|
||||
int w = std::min<int>(rect1.x + rect1.w, rect2.x + rect2.w) - res.x;
|
||||
int h = std::min<int>(rect1.y + rect1.h, rect2.y + rect2.h) - res.y;
|
||||
if (w <= 0 || h <= 0) return empty_rect;
|
||||
res.w = w;
|
||||
res.h = h;
|
||||
return res;
|
||||
}
|
||||
|
||||
SDL_Rect union_rects(SDL_Rect const &rect1, SDL_Rect const &rect2)
|
||||
{
|
||||
if (rect1.w == 0 || rect1.h == 0) return rect2;
|
||||
if (rect2.w == 0 || rect2.h == 0) return rect1;
|
||||
SDL_Rect res;
|
||||
res.x = std::min<int>(rect1.x, rect2.x);
|
||||
res.y = std::min<int>(rect1.y, rect2.y);
|
||||
res.w = std::max<int>(rect1.x + rect1.w, rect2.x + rect2.w) - res.x;
|
||||
res.h = std::max<int>(rect1.y + rect1.h, rect2.y + rect2.h) - res.y;
|
||||
return res;
|
||||
}
|
||||
|
||||
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface target)
|
||||
{
|
||||
if(alpha == SDL_ALPHA_OPAQUE) {
|
||||
sdl_fill_rect(target,&rect,color);
|
||||
return;
|
||||
} else if(alpha == SDL_ALPHA_TRANSPARENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
surface tmp(create_compatible_surface(target,rect.w,rect.h));
|
||||
if(tmp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Rect r = {0,0,rect.w,rect.h};
|
||||
sdl_fill_rect(tmp,&r,color);
|
||||
SDL_SetAlpha(tmp,SDL_SRCALPHA,alpha);
|
||||
sdl_blit(tmp,NULL,target,&rect);
|
||||
}
|
||||
|
||||
void draw_rectangle(int x, int y, int w, int h, Uint32 color, surface target)
|
||||
{
|
||||
|
||||
SDL_Rect top = create_rect(x, y, w, 1);
|
||||
SDL_Rect bot = create_rect(x, y + h - 1, w, 1);
|
||||
SDL_Rect left = create_rect(x, y, 1, h);
|
||||
SDL_Rect right = create_rect(x + w - 1, y, 1, h);
|
||||
|
||||
sdl_fill_rect(target,&top,color);
|
||||
sdl_fill_rect(target,&bot,color);
|
||||
sdl_fill_rect(target,&left,color);
|
||||
sdl_fill_rect(target,&right,color);
|
||||
}
|
||||
|
||||
void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
||||
int r, int g, int b,
|
||||
double alpha, surface target)
|
||||
{
|
||||
|
||||
SDL_Rect rect = create_rect(x, y, w, h);
|
||||
fill_rect_alpha(rect,SDL_MapRGB(target->format,r,g,b),Uint8(alpha*255),target);
|
||||
}
|
||||
|
||||
} // namespace sdl
|
||||
|
||||
bool operator==(const SDL_Rect& a, const SDL_Rect& b)
|
||||
{
|
||||
return a.x == b.x && a.y == b.y && a.w == b.w && a.h == b.h;
|
||||
}
|
||||
|
||||
bool operator!=(const SDL_Rect& a, const SDL_Rect& b)
|
||||
{
|
||||
return !operator==(a,b);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
#include <SDL_version.h>
|
||||
#include <sdl_utils.hpp>
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
#include <SDL_rect.h>
|
||||
|
@ -28,9 +29,13 @@
|
|||
#include <SDL_video.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
extern const SDL_Rect empty_rect;
|
||||
|
||||
/**
|
||||
* Creates an empty SDL_Rect.
|
||||
*
|
||||
|
@ -39,6 +44,21 @@ namespace sdl
|
|||
*/
|
||||
SDL_Rect create_rect(const int x, const int y, const int w, const int h);
|
||||
|
||||
bool point_in_rect(int x, int y, const SDL_Rect& rect);
|
||||
bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2);
|
||||
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2);
|
||||
SDL_Rect union_rects(const SDL_Rect &rect1, const SDL_Rect &rect2);
|
||||
|
||||
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface target);
|
||||
|
||||
void draw_rectangle(int x, int y, int w, int h, Uint32 color, surface tg);
|
||||
|
||||
void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
||||
int r, int g, int b,
|
||||
double alpha, surface target);
|
||||
} // namespace sdl
|
||||
|
||||
bool operator==(const SDL_Rect& a, const SDL_Rect& b);
|
||||
bool operator!=(const SDL_Rect& a, const SDL_Rect& b);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,8 +34,6 @@
|
|||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
const SDL_Rect empty_rect = { 0, 0, 0, 0 };
|
||||
|
||||
surface_lock::surface_lock(surface &surf) : surface_(surf), locked_(false)
|
||||
{
|
||||
if (SDL_MUSTLOCK(surface_))
|
||||
|
@ -118,42 +116,6 @@ SDLKey sdl_keysym_from_name(std::string const &keyname)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool point_in_rect(int x, int y, const SDL_Rect& rect)
|
||||
{
|
||||
return x >= rect.x && y >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h;
|
||||
}
|
||||
|
||||
bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2)
|
||||
{
|
||||
return (rect1.x < rect2.x+rect2.w && rect2.x < rect1.x+rect1.w &&
|
||||
rect1.y < rect2.y+rect2.h && rect2.y < rect1.y+rect1.h);
|
||||
}
|
||||
|
||||
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2)
|
||||
{
|
||||
SDL_Rect res;
|
||||
res.x = std::max<int>(rect1.x, rect2.x);
|
||||
res.y = std::max<int>(rect1.y, rect2.y);
|
||||
int w = std::min<int>(rect1.x + rect1.w, rect2.x + rect2.w) - res.x;
|
||||
int h = std::min<int>(rect1.y + rect1.h, rect2.y + rect2.h) - res.y;
|
||||
if (w <= 0 || h <= 0) return empty_rect;
|
||||
res.w = w;
|
||||
res.h = h;
|
||||
return res;
|
||||
}
|
||||
|
||||
SDL_Rect union_rects(SDL_Rect const &rect1, SDL_Rect const &rect2)
|
||||
{
|
||||
if (rect1.w == 0 || rect1.h == 0) return rect2;
|
||||
if (rect2.w == 0 || rect2.h == 0) return rect1;
|
||||
SDL_Rect res;
|
||||
res.x = std::min<int>(rect1.x, rect2.x);
|
||||
res.y = std::min<int>(rect1.y, rect2.y);
|
||||
res.w = std::max<int>(rect1.x + rect1.w, rect2.x + rect2.w) - res.x;
|
||||
res.h = std::max<int>(rect1.y + rect1.h, rect2.y + rect2.h) - res.y;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool operator<(const surface& a, const surface& b)
|
||||
{
|
||||
return a.get() < b.get();
|
||||
|
@ -2049,28 +2011,6 @@ void blit_surface(const surface& surf,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface &target)
|
||||
{
|
||||
if(alpha == SDL_ALPHA_OPAQUE) {
|
||||
sdl_fill_rect(target,&rect,color);
|
||||
return;
|
||||
} else if(alpha == SDL_ALPHA_TRANSPARENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
surface tmp(create_compatible_surface(target,rect.w,rect.h));
|
||||
if(tmp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Rect r = {0,0,rect.w,rect.h};
|
||||
sdl_fill_rect(tmp,&r,color);
|
||||
SDL_SetAlpha(tmp,SDL_SRCALPHA,alpha);
|
||||
sdl_blit(tmp,NULL,target,&rect);
|
||||
}
|
||||
|
||||
surface get_surface_portion(const surface &src, SDL_Rect &area, bool optimize_format)
|
||||
{
|
||||
if (src == NULL) {
|
||||
|
@ -2186,16 +2126,6 @@ SDL_Rect get_non_transparent_portion(const surface &surf)
|
|||
return res;
|
||||
}
|
||||
|
||||
bool operator==(const SDL_Rect& a, const SDL_Rect& b)
|
||||
{
|
||||
return a.x == b.x && a.y == b.y && a.w == b.w && a.h == b.h;
|
||||
}
|
||||
|
||||
bool operator!=(const SDL_Rect& a, const SDL_Rect& b)
|
||||
{
|
||||
return !operator==(a,b);
|
||||
}
|
||||
|
||||
bool operator==(const SDL_Color& a, const SDL_Color& b) {
|
||||
return a.r == b.r && a.g == b.g && a.b == b.b;
|
||||
}
|
||||
|
@ -2217,7 +2147,7 @@ SDL_Color inverse(const SDL_Color& color) {
|
|||
return inverse;
|
||||
}
|
||||
|
||||
surface_restorer::surface_restorer() : target_(NULL), rect_(empty_rect), surface_(NULL)
|
||||
surface_restorer::surface_restorer() : target_(NULL), rect_(sdl::empty_rect), surface_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2236,7 +2166,7 @@ void surface_restorer::restore(SDL_Rect const &dst) const
|
|||
{
|
||||
if (surface_.null())
|
||||
return;
|
||||
SDL_Rect dst2 = intersect_rects(dst, rect_);
|
||||
SDL_Rect dst2 = sdl::intersect_rects(dst, rect_);
|
||||
if (dst2.w == 0 || dst2.h == 0)
|
||||
return;
|
||||
SDL_Rect src = dst2;
|
||||
|
@ -2268,29 +2198,6 @@ void surface_restorer::cancel()
|
|||
surface_.assign(NULL);
|
||||
}
|
||||
|
||||
void draw_rectangle(int x, int y, int w, int h, Uint32 color,surface target)
|
||||
{
|
||||
|
||||
SDL_Rect top = sdl::create_rect(x, y, w, 1);
|
||||
SDL_Rect bot = sdl::create_rect(x, y + h - 1, w, 1);
|
||||
SDL_Rect left = sdl::create_rect(x, y, 1, h);
|
||||
SDL_Rect right = sdl::create_rect(x + w - 1, y, 1, h);
|
||||
|
||||
sdl_fill_rect(target,&top,color);
|
||||
sdl_fill_rect(target,&bot,color);
|
||||
sdl_fill_rect(target,&left,color);
|
||||
sdl_fill_rect(target,&right,color);
|
||||
}
|
||||
|
||||
void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
||||
int r, int g, int b,
|
||||
double alpha, surface target)
|
||||
{
|
||||
|
||||
SDL_Rect rect = sdl::create_rect(x, y, w, h);
|
||||
fill_rect_alpha(rect,SDL_MapRGB(target->format,r,g,b),Uint8(alpha*255),target);
|
||||
}
|
||||
|
||||
void draw_centered_on_background(surface surf, const SDL_Rect& rect, const SDL_Color& color, surface target)
|
||||
{
|
||||
clip_rect_setter clip_setter(target, &rect);
|
||||
|
|
|
@ -47,15 +47,8 @@
|
|||
#define SDL_BUTTON_WHEELRIGHT 7
|
||||
#endif
|
||||
|
||||
extern const SDL_Rect empty_rect;
|
||||
|
||||
SDLKey sdl_keysym_from_name(std::string const &keyname);
|
||||
|
||||
bool point_in_rect(int x, int y, const SDL_Rect& rect);
|
||||
bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2);
|
||||
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2);
|
||||
SDL_Rect union_rects(const SDL_Rect &rect1, const SDL_Rect &rect2);
|
||||
|
||||
|
||||
struct surface
|
||||
{
|
||||
|
@ -120,6 +113,7 @@ inline void sdl_blit(const surface& src, SDL_Rect* src_rect, surface& dst, SDL_R
|
|||
SDL_BlitSurface(src, src_rect, dst, dst_rect);
|
||||
}
|
||||
|
||||
// and this
|
||||
inline void sdl_fill_rect(surface& dst, SDL_Rect* dst_rect, const Uint32 color){
|
||||
SDL_FillRect(dst, dst_rect, color);
|
||||
}
|
||||
|
@ -390,12 +384,8 @@ surface create_compatible_surface(const surface &surf, int width = -1, int heigh
|
|||
void blit_surface(const surface& src,
|
||||
const SDL_Rect* srcrect, surface& dst, const SDL_Rect* dstrect);
|
||||
|
||||
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface &target);
|
||||
|
||||
SDL_Rect get_non_transparent_portion(const surface &surf);
|
||||
|
||||
bool operator==(const SDL_Rect& a, const SDL_Rect& b);
|
||||
bool operator!=(const SDL_Rect& a, const SDL_Rect& b);
|
||||
bool operator==(const SDL_Color& a, const SDL_Color& b);
|
||||
bool operator!=(const SDL_Color& a, const SDL_Color& b);
|
||||
SDL_Color inverse(const SDL_Color& color);
|
||||
|
@ -486,13 +476,6 @@ private:
|
|||
const bool operate_;
|
||||
};
|
||||
|
||||
|
||||
void draw_rectangle(int x, int y, int w, int h, Uint32 color, surface tg);
|
||||
|
||||
void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
||||
int r, int g, int b,
|
||||
double alpha, surface target);
|
||||
|
||||
// blit the image on the center of the rectangle
|
||||
// and a add a colored background
|
||||
void draw_centered_on_background(surface surf, const SDL_Rect& rect,
|
||||
|
|
|
@ -104,7 +104,7 @@ dialog_frame::~dialog_frame()
|
|||
}
|
||||
|
||||
dialog_frame::dimension_measurements::dimension_measurements() :
|
||||
interior(empty_rect), exterior(empty_rect), title(empty_rect), button_row(empty_rect)
|
||||
interior(sdl::empty_rect), exterior(sdl::empty_rect), title(sdl::empty_rect), button_row(sdl::empty_rect)
|
||||
{}
|
||||
|
||||
dialog_frame::dimension_measurements dialog_frame::layout(SDL_Rect const& rect) {
|
||||
|
|
|
@ -231,7 +231,7 @@ void part_ui::prepare_floating_images()
|
|||
|
||||
void part_ui::render_background()
|
||||
{
|
||||
draw_solid_tinted_rectangle(
|
||||
sdl::draw_solid_tinted_rectangle(
|
||||
0, 0, video_.getx(), video_.gety(), 0, 0, 0, 1.0,
|
||||
video_.getSurface()
|
||||
);
|
||||
|
@ -321,7 +321,7 @@ void part_ui::render_title_box()
|
|||
break; // already set before
|
||||
}
|
||||
|
||||
draw_solid_tinted_rectangle(
|
||||
sdl::draw_solid_tinted_rectangle(
|
||||
base_rect_.x + titlebox_x - titleshadow_padding,
|
||||
base_rect_.y + titlebox_y - titleshadow_padding,
|
||||
titlebox_w + 2*titleshadow_padding,
|
||||
|
@ -467,7 +467,7 @@ void part_ui::render_story_box()
|
|||
blur_area(video_, fix_text_y, fix_text_h);
|
||||
#endif
|
||||
|
||||
draw_solid_tinted_rectangle(
|
||||
sdl::draw_solid_tinted_rectangle(
|
||||
0, fix_text_y, screen_area().w, fix_text_h,
|
||||
storyshadow_r, storyshadow_g, storyshadow_b,
|
||||
storyshadow_opacity,
|
||||
|
@ -516,7 +516,7 @@ void part_ui::render_story_box()
|
|||
}
|
||||
}
|
||||
|
||||
draw_solid_tinted_rectangle(
|
||||
sdl::draw_solid_tinted_rectangle(
|
||||
0, 0, video_.getx(), video_.gety(), 0, 0, 0,
|
||||
1.0, video_.getSurface()
|
||||
);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "theme.hpp"
|
||||
#include "utils/foreach.tpp"
|
||||
#include "wml_exception.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
static lg::log_domain log_display("display");
|
||||
#define DBG_DP LOG_STREAM(debug, log_display)
|
||||
|
@ -278,9 +279,9 @@ static void do_resolve_rects(const config& cfg, config& resolved_config, config*
|
|||
theme::object::object() :
|
||||
location_modified_(false),
|
||||
id_(),
|
||||
loc_(empty_rect),
|
||||
relative_loc_(empty_rect),
|
||||
last_screen_(empty_rect),
|
||||
loc_(sdl::empty_rect),
|
||||
relative_loc_(sdl::empty_rect),
|
||||
last_screen_(sdl::empty_rect),
|
||||
xanchor_(object::FIXED),
|
||||
yanchor_(object::FIXED)
|
||||
{
|
||||
|
@ -288,7 +289,7 @@ theme::object::object() :
|
|||
|
||||
theme::object::object(const config& cfg) :
|
||||
location_modified_(false), id_(cfg["id"]), loc_(read_sdl_rect(cfg)),
|
||||
relative_loc_(empty_rect), last_screen_(empty_rect),
|
||||
relative_loc_(sdl::empty_rect), last_screen_(sdl::empty_rect),
|
||||
xanchor_(read_anchor(cfg["xanchor"])), yanchor_(read_anchor(cfg["yanchor"]))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ void clear_tooltips()
|
|||
void clear_tooltips(const SDL_Rect& rect)
|
||||
{
|
||||
for(std::vector<tooltip>::iterator i = tips.begin(); i != tips.end(); ) {
|
||||
if(rects_overlap(i->rect,rect)) {
|
||||
if(sdl::rects_overlap(i->rect,rect)) {
|
||||
if (i==current_tooltip) {
|
||||
clear_tooltip();
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ void clear_tooltips(const SDL_Rect& rect)
|
|||
void add_tooltip(const SDL_Rect& rect, const std::string& message, const std::string& action, bool use_markup)
|
||||
{
|
||||
for(std::vector<tooltip>::iterator i = tips.begin(); i != tips.end(); ++i) {
|
||||
if(rects_overlap(i->rect,rect)) {
|
||||
if(sdl::rects_overlap(i->rect,rect)) {
|
||||
*i = tooltip(rect, message, action, use_markup);
|
||||
return;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ void process(int mousex, int mousey)
|
|||
bool click(int mousex, int mousey)
|
||||
{
|
||||
BOOST_FOREACH(tooltip tip, tips) {
|
||||
if(!tip.action.empty() && point_in_rect(mousex, mousey, tip.rect)) {
|
||||
if(!tip.action.empty() && sdl::point_in_rect(mousex, mousey, tip.rect)) {
|
||||
display* disp = resources::screen;
|
||||
help::show_help(*disp, tip.action);
|
||||
return true;
|
||||
|
|
|
@ -1989,7 +1989,7 @@ void unit::redraw_unit()
|
|||
if (draw_bars) {
|
||||
const int d = disp.hex_size();
|
||||
SDL_Rect unit_rect = sdl::create_rect(xsrc, ysrc +adjusted_params.y, d, d);
|
||||
draw_bars = rects_overlap(unit_rect, disp.map_outside_area());
|
||||
draw_bars = sdl::rects_overlap(unit_rect, disp.map_outside_area());
|
||||
}
|
||||
|
||||
surface ellipse_front(NULL);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "sound.hpp"
|
||||
#include "video.hpp"
|
||||
#include "wml_separators.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
#include "filesystem.hpp"
|
||||
|
||||
|
@ -375,7 +376,7 @@ void button::draw_contents()
|
|||
|
||||
bool button::hit(int x, int y) const
|
||||
{
|
||||
return point_in_rect(x,y,location());
|
||||
return sdl::point_in_rect(x,y,location());
|
||||
}
|
||||
|
||||
static bool not_image(const std::string& str) { return !str.empty() && str[0] != IMAGE_PREFIX; }
|
||||
|
|
|
@ -851,7 +851,7 @@ void menu::style::draw_row_bg(menu& menu_ref, const size_t /*row_index*/, const
|
|||
break;
|
||||
}
|
||||
|
||||
draw_solid_tinted_rectangle(rect.x, rect.y, rect.w, rect.h,
|
||||
sdl::draw_solid_tinted_rectangle(rect.x, rect.y, rect.w, rect.h,
|
||||
(rgb&0xff0000) >> 16,(rgb&0xff00) >> 8,rgb&0xff,alpha,
|
||||
menu_ref.video().getSurface());
|
||||
}
|
||||
|
@ -936,9 +936,9 @@ void menu::draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
|
|||
xpos -= widths[i];
|
||||
if(type == HEADING_ROW) {
|
||||
if(highlight_heading_ == int(i)) {
|
||||
draw_solid_tinted_rectangle(xpos,rect.y,widths[i],rect.h,255,255,255,0.3,video().getSurface());
|
||||
sdl::draw_solid_tinted_rectangle(xpos,rect.y,widths[i],rect.h,255,255,255,0.3,video().getSurface());
|
||||
} else if(sortby_ == int(i)) {
|
||||
draw_solid_tinted_rectangle(xpos,rect.y,widths[i],rect.h,255,255,255,0.1,video().getSurface());
|
||||
sdl::draw_solid_tinted_rectangle(xpos,rect.y,widths[i],rect.h,255,255,255,0.1,video().getSurface());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1124,7 +1124,7 @@ SDL_Rect menu::get_item_rect_internal(size_t item) const
|
|||
unsigned int first_item_on_screen = get_position();
|
||||
if (item < first_item_on_screen ||
|
||||
item >= first_item_on_screen + max_items_onscreen()) {
|
||||
return empty_rect;
|
||||
return sdl::empty_rect;
|
||||
}
|
||||
|
||||
const std::map<int,SDL_Rect>::const_iterator i = itemRects_.find(item);
|
||||
|
@ -1144,13 +1144,13 @@ SDL_Rect menu::get_item_rect_internal(size_t item) const
|
|||
SDL_Rect const &screen_area = ::screen_area();
|
||||
|
||||
if(res.x > screen_area.w) {
|
||||
return empty_rect;
|
||||
return sdl::empty_rect;
|
||||
} else if(res.x + res.w > screen_area.w) {
|
||||
res.w = screen_area.w - res.x;
|
||||
}
|
||||
|
||||
if(res.y > screen_area.h) {
|
||||
return empty_rect;
|
||||
return sdl::empty_rect;
|
||||
} else if(res.y + res.h > screen_area.h) {
|
||||
res.h = screen_area.h - res.y;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include "widgets/scrollarea.hpp"
|
||||
#include "sdl/rect.hpp"
|
||||
|
||||
|
||||
namespace gui {
|
||||
|
@ -157,7 +158,7 @@ void scrollarea::handle_event(const SDL_Event& event)
|
|||
return;
|
||||
|
||||
SDL_MouseButtonEvent const &e = event.button;
|
||||
if (point_in_rect(e.x, e.y, inner_location())) {
|
||||
if (sdl::point_in_rect(e.x, e.y, inner_location())) {
|
||||
if (e.button == SDL_BUTTON_WHEELDOWN) {
|
||||
scrollbar_.scroll_down();
|
||||
} else if (e.button == SDL_BUTTON_WHEELUP) {
|
||||
|
@ -171,7 +172,7 @@ void scrollarea::handle_event(const SDL_Event& event)
|
|||
const SDL_MouseWheelEvent &ev = event.wheel;
|
||||
int x, y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
if (point_in_rect(x, y, inner_location())) {
|
||||
if (sdl::point_in_rect(x, y, inner_location())) {
|
||||
if (ev.y > 0) {
|
||||
scrollbar_.scroll_up();
|
||||
} else if (ev.y < 0) {
|
||||
|
|
|
@ -335,15 +335,15 @@ void scrollbar::handle_event(const SDL_Event& event)
|
|||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
SDL_MouseButtonEvent const &e = event.button;
|
||||
bool on_grip = point_in_rect(e.x, e.y, grip);
|
||||
bool on_grip = sdl::point_in_rect(e.x, e.y, grip);
|
||||
new_state = on_grip ? ACTIVE : NORMAL;
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
SDL_MouseButtonEvent const &e = event.button;
|
||||
bool on_grip = point_in_rect(e.x, e.y, grip);
|
||||
bool on_groove = point_in_rect(e.x, e.y, groove);
|
||||
bool on_grip = sdl::point_in_rect(e.x, e.y, grip);
|
||||
bool on_groove = sdl::point_in_rect(e.x, e.y, groove);
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
if (on_groove && e.button == SDL_BUTTON_WHEELDOWN) {
|
||||
move_position(scroll_rate_);
|
||||
|
@ -370,7 +370,7 @@ void scrollbar::handle_event(const SDL_Event& event)
|
|||
{
|
||||
SDL_MouseMotionEvent const &e = event.motion;
|
||||
if (state_ == NORMAL || state_ == ACTIVE) {
|
||||
bool on_grip = point_in_rect(e.x, e.y, grip);
|
||||
bool on_grip = sdl::point_in_rect(e.x, e.y, grip);
|
||||
new_state = on_grip ? ACTIVE : NORMAL;
|
||||
} else if (state_ == DRAGGED && groove.h != grip.h) {
|
||||
int y_dep = e.y - grip.y - mousey_on_grip_;
|
||||
|
@ -385,7 +385,7 @@ void scrollbar::handle_event(const SDL_Event& event)
|
|||
const SDL_MouseWheelEvent& e = event.wheel;
|
||||
int x, y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
bool on_groove = point_in_rect(x, y, groove);
|
||||
bool on_groove = sdl::point_in_rect(x, y, groove);
|
||||
if (on_groove && e.y < 0) {
|
||||
move_position(scroll_rate_);
|
||||
} else if (on_groove && e.y > 0) {
|
||||
|
|
|
@ -193,7 +193,7 @@ void slider::set_slider_position(int x)
|
|||
void slider::mouse_motion(const SDL_MouseMotionEvent& event)
|
||||
{
|
||||
if (state_ == NORMAL || state_ == ACTIVE) {
|
||||
bool on = point_in_rect(event.x, event.y, location());
|
||||
bool on = sdl::point_in_rect(event.x, event.y, location());
|
||||
state_ = on ? ACTIVE : NORMAL;
|
||||
} else if (state_ == CLICKED || state_ == DRAGGED) {
|
||||
state_ = DRAGGED;
|
||||
|
@ -212,7 +212,7 @@ void slider::mouse_down(const SDL_MouseButtonEvent& event)
|
|||
{
|
||||
bool prev_change = value_change_;
|
||||
|
||||
if (!point_in_rect(event.x, event.y, location()))
|
||||
if (!sdl::point_in_rect(event.x, event.y, location()))
|
||||
return;
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
|
@ -242,7 +242,7 @@ void slider::mouse_down(const SDL_MouseButtonEvent& event)
|
|||
return;
|
||||
|
||||
state_ = CLICKED;
|
||||
if (point_in_rect(event.x, event.y, slider_area())) {
|
||||
if (sdl::point_in_rect(event.x, event.y, slider_area())) {
|
||||
sound::play_UI_sound(game_config::sounds::button_press);
|
||||
} else {
|
||||
value_change_ = false;
|
||||
|
@ -262,7 +262,7 @@ void slider::mouse_wheel(const SDL_MouseWheelEvent& event) {
|
|||
int x, y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
|
||||
if (!point_in_rect(x, y, location()))
|
||||
if (!sdl::point_in_rect(x, y, location()))
|
||||
return;
|
||||
|
||||
if (event.y > 0 || event.x > 0) {
|
||||
|
@ -322,7 +322,7 @@ void slider::handle_event(const SDL_Event& event)
|
|||
switch(event.type) {
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (!mouse_locked()) {
|
||||
bool on = point_in_rect(event.button.x, event.button.y, slider_area());
|
||||
bool on = sdl::point_in_rect(event.button.x, event.button.y, slider_area());
|
||||
state_ = on ? ACTIVE : NORMAL;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -183,7 +183,7 @@ void textbox::draw_contents()
|
|||
SDL_Rect const &loc = inner_location();
|
||||
|
||||
surface surf = video().getSurface();
|
||||
draw_solid_tinted_rectangle(loc.x,loc.y,loc.w,loc.h,0,0,0,
|
||||
sdl::draw_solid_tinted_rectangle(loc.x,loc.y,loc.w,loc.h,0,0,0,
|
||||
focus(NULL) ? alpha_focus_ : alpha_, surf);
|
||||
|
||||
SDL_Rect src;
|
||||
|
@ -224,7 +224,7 @@ void textbox::draw_contents()
|
|||
const clip_rect_setter clipper(surf, &loc);
|
||||
|
||||
Uint32 color = SDL_MapRGB(surf->format, 0, 0, 160);
|
||||
fill_rect_alpha(rect, color, 140, surf);
|
||||
sdl::fill_rect_alpha(rect, color, 140, surf);
|
||||
|
||||
starty += int(line_height_);
|
||||
startx = 0;
|
||||
|
@ -466,7 +466,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
|||
SDL_Rect const &loc = inner_location();
|
||||
bool clicked_inside = !mouse_locked() && (event.type == SDL_MOUSEBUTTONDOWN
|
||||
&& (mousebuttons & SDL_BUTTON(1))
|
||||
&& point_in_rect(mousex, mousey, loc));
|
||||
&& sdl::point_in_rect(mousex, mousey, loc));
|
||||
if(clicked_inside) {
|
||||
set_focus(true);
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
|
|||
//if we don't have the focus, then see if we gain the focus,
|
||||
//otherwise return
|
||||
if(!was_forwarded && focus(&event) == false) {
|
||||
if (!mouse_locked() && event.type == SDL_MOUSEMOTION && point_in_rect(mousex, mousey, loc))
|
||||
if (!mouse_locked() && event.type == SDL_MOUSEMOTION && sdl::point_in_rect(mousex, mousey, loc))
|
||||
events::focus_handler(this);
|
||||
|
||||
return;
|
||||
|
|
|
@ -198,7 +198,7 @@ void widget::set_clip_rect(const SDL_Rect& rect)
|
|||
bool widget::hidden() const
|
||||
{
|
||||
return (state_ == HIDDEN || hidden_override_ || state_ == UNINIT
|
||||
|| (clip_ && !rects_overlap(clip_rect_, rect_)));
|
||||
|| (clip_ && !sdl::rects_overlap(clip_rect_, rect_)));
|
||||
}
|
||||
|
||||
void widget::enable(bool new_val)
|
||||
|
@ -323,7 +323,7 @@ void widget::set_tooltip_string(const std::string& str)
|
|||
|
||||
void widget::process_help_string(int mousex, int mousey)
|
||||
{
|
||||
if (!hidden() && point_in_rect(mousex, mousey, rect_)) {
|
||||
if (!hidden() && sdl::point_in_rect(mousex, mousey, rect_)) {
|
||||
if(help_string_ == 0 && help_text_ != "") {
|
||||
//std::cerr << "setting help string to '" << help_text_ << "'\n";
|
||||
help_string_ = video().set_help_string(help_text_);
|
||||
|
@ -336,7 +336,7 @@ void widget::process_help_string(int mousex, int mousey)
|
|||
|
||||
void widget::process_tooltip_string(int mousex, int mousey)
|
||||
{
|
||||
if (!hidden() && point_in_rect(mousex, mousey, rect_)) {
|
||||
if (!hidden() && sdl::point_in_rect(mousex, mousey, rect_)) {
|
||||
if (!tooltip_text_.empty())
|
||||
tooltips::add_tooltip(rect_, tooltip_text_ );
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue