From ac96a2b91b3276e20b682210617cf87d1e0d366a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boldizs=C3=A1r=20Lipka?= Date: Mon, 2 Jun 2014 22:49:56 +0200 Subject: [PATCH] Move some functions to sdl/rect. --- src/construct_dialog.cpp | 12 +-- src/controller_base.cpp | 4 +- src/display.cpp | 24 +++--- src/editor/palette/palette_manager.cpp | 2 +- src/editor/palette/tristate_button.cpp | 2 +- src/font.cpp | 2 +- src/gui/widgets/scrollbar_container.cpp | 3 +- src/gui/widgets/widget.cpp | 9 ++- src/gui/widgets/window.cpp | 2 +- src/halo.cpp | 4 +- src/help.cpp | 6 +- src/loadscreen.cpp | 2 +- src/menu_events.cpp | 2 +- src/mouse_events.cpp | 2 +- src/mouse_handler_base.cpp | 5 +- src/multiplayer_lobby.cpp | 4 +- src/multiplayer_ui.cpp | 2 +- src/playsingle_controller.cpp | 2 +- src/sdl/rect.cpp | 93 ++++++++++++++++++++++++ src/sdl/rect.hpp | 20 +++++ src/sdl_utils.cpp | 97 +------------------------ src/sdl_utils.hpp | 19 +---- src/show_dialog.cpp | 2 +- src/storyscreen/render.cpp | 8 +- src/theme.cpp | 9 ++- src/tooltips.cpp | 6 +- src/unit.cpp | 2 +- src/widgets/button.cpp | 3 +- src/widgets/menu.cpp | 12 +-- src/widgets/scrollarea.cpp | 5 +- src/widgets/scrollbar.cpp | 10 +-- src/widgets/slider.cpp | 10 +-- src/widgets/textbox.cpp | 8 +- src/widgets/widget.cpp | 6 +- 34 files changed, 204 insertions(+), 195 deletions(-) diff --git a/src/construct_dialog.cpp b/src/construct_dialog.cpp index 2835b944a22b..aedc030842b8 100644 --- a/src/construct_dialog.cpp +++ b/src/construct_dialog.cpp @@ -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; diff --git a/src/controller_base.cpp b/src/controller_base.cpp index 9718aa666eb4..5dab1216cc59 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -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. diff --git a/src/display.cpp b/src/display.cpp index 05b354a48bec..50cdda9ea9de 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -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(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& 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) diff --git a/src/editor/palette/palette_manager.cpp b/src/editor/palette/palette_manager.cpp index b3ff0600f789..24819d118392 100644 --- a/src/editor/palette/palette_manager.cpp +++ b/src/editor/palette/palette_manager.cpp @@ -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. diff --git a/src/editor/palette/tristate_button.cpp b/src/editor/palette/tristate_button.cpp index a2aff860393e..82f9dc331fb1 100644 --- a/src/editor/palette/tristate_button.cpp +++ b/src/editor/palette/tristate_button.cpp @@ -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) { diff --git a/src/font.cpp b/src/font.cpp index 21e070df6b1a..00d0235c80a9 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -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() diff --git a/src/gui/widgets/scrollbar_container.cpp b/src/gui/widgets/scrollbar_container.cpp index caece95082af..09b1ad3437e6 100644 --- a/src/gui/widgets/scrollbar_container.cpp +++ b/src/gui/widgets/scrollbar_container.cpp @@ -23,6 +23,7 @@ #include "gui/widgets/spacer.hpp" #include "gui/widgets/window.hpp" #include "utils/foreach.tpp" +#include "sdl/rect.hpp" #include @@ -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_); } diff --git a/src/gui/widgets/widget.cpp b/src/gui/widgets/widget.cpp index b1ba3fffe605..479a5687eed9 100644 --- a/src/gui/widgets/widget.cpp +++ b/src/gui/widgets/widget.cpp @@ -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; diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index f5b022dc2b31..95616e27fce6 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -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); } } diff --git a/src/halo.cpp b/src/halo.cpp index e941f583bd13..c8e30bc46015 100644 --- a/src/halo.cpp +++ b/src/halo.cpp @@ -105,7 +105,7 @@ effect::effect(int xpos, int ypos, const animated::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; } diff --git a/src/help.cpp b/src/help.cpp index 704d658e1fbf..96d4bd3837df 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -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_) { diff --git a/src/loadscreen.cpp b/src/loadscreen.cpp index 23de3141a85b..be5d44d0d482 100644 --- a/src/loadscreen.cpp +++ b/src/loadscreen.cpp @@ -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. diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 67bd5a2ca4aa..7697b2b3519e 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -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(" diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index 2247b7420116..cceebc9e1fcb 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -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*/) diff --git a/src/mouse_handler_base.cpp b/src/mouse_handler_base.cpp index 5582d875535f..7607628bd228 100644 --- a/src/mouse_handler_base.cpp +++ b/src/mouse_handler_base.cpp @@ -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; } diff --git a/src/multiplayer_lobby.cpp b/src/multiplayer_lobby.cpp index 120121e47af3..4c261f47f97d 100644 --- a/src/multiplayer_lobby.cpp +++ b/src/multiplayer_lobby.cpp @@ -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; diff --git a/src/multiplayer_ui.cpp b/src/multiplayer_ui.cpp index 19de518cb26b..63f1c421bdfe 100644 --- a/src/multiplayer_ui.cpp +++ b/src/multiplayer_ui.cpp @@ -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_; } diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 7518d4335937..33e11e96f36e 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -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() ); diff --git a/src/sdl/rect.cpp b/src/sdl/rect.cpp index 65e07c38b75e..62e46d6963ef 100644 --- a/src/sdl/rect.cpp +++ b/src/sdl/rect.cpp @@ -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(rect1.x, rect2.x); + res.y = std::max(rect1.y, rect2.y); + int w = std::min(rect1.x + rect1.w, rect2.x + rect2.w) - res.x; + int h = std::min(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(rect1.x, rect2.x); + res.y = std::min(rect1.y, rect2.y); + res.w = std::max(rect1.x + rect1.w, rect2.x + rect2.w) - res.x; + res.h = std::max(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); +} diff --git a/src/sdl/rect.hpp b/src/sdl/rect.hpp index b5548f37063c..b7fe5c258f45 100644 --- a/src/sdl/rect.hpp +++ b/src/sdl/rect.hpp @@ -21,6 +21,7 @@ */ #include +#include #if SDL_VERSION_ATLEAST(2, 0, 0) #include @@ -28,9 +29,13 @@ #include #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 diff --git a/src/sdl_utils.cpp b/src/sdl_utils.cpp index 5df578564fc3..f851153811f8 100644 --- a/src/sdl_utils.cpp +++ b/src/sdl_utils.cpp @@ -34,8 +34,6 @@ #include -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(rect1.x, rect2.x); - res.y = std::max(rect1.y, rect2.y); - int w = std::min(rect1.x + rect1.w, rect2.x + rect2.w) - res.x; - int h = std::min(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(rect1.x, rect2.x); - res.y = std::min(rect1.y, rect2.y); - res.w = std::max(rect1.x + rect1.w, rect2.x + rect2.w) - res.x; - res.h = std::max(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); diff --git a/src/sdl_utils.hpp b/src/sdl_utils.hpp index f5572b2b8c95..92338f188d4b 100644 --- a/src/sdl_utils.hpp +++ b/src/sdl_utils.hpp @@ -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 @@ struct clip_rect_setter 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, diff --git a/src/show_dialog.cpp b/src/show_dialog.cpp index 33ab03f7830c..a60af4c51445 100644 --- a/src/show_dialog.cpp +++ b/src/show_dialog.cpp @@ -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) { diff --git a/src/storyscreen/render.cpp b/src/storyscreen/render.cpp index 1c2a55682540..7210f6a3c747 100644 --- a/src/storyscreen/render.cpp +++ b/src/storyscreen/render.cpp @@ -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() ); diff --git a/src/theme.cpp b/src/theme.cpp index 43a6eb3dec68..6a7f495ace7e 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -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"])) { } diff --git a/src/tooltips.cpp b/src/tooltips.cpp index 8d7093a2de4e..14aaaf77361d 100644 --- a/src/tooltips.cpp +++ b/src/tooltips.cpp @@ -127,7 +127,7 @@ void clear_tooltips() void clear_tooltips(const SDL_Rect& rect) { for(std::vector::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::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; diff --git a/src/unit.cpp b/src/unit.cpp index f8fe5fcbb34d..fbbe28906fe5 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -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); diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index db901303722b..c80c8021ca2e 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -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; } diff --git a/src/widgets/menu.cpp b/src/widgets/menu.cpp index 2f27beaeafc0..257a8abe84d3 100644 --- a/src/widgets/menu.cpp +++ b/src/widgets/menu.cpp @@ -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::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; } diff --git a/src/widgets/scrollarea.cpp b/src/widgets/scrollarea.cpp index 724d60db3af0..fcc94cc445a9 100644 --- a/src/widgets/scrollarea.cpp +++ b/src/widgets/scrollarea.cpp @@ -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) { diff --git a/src/widgets/scrollbar.cpp b/src/widgets/scrollbar.cpp index 889309d1accb..c5b772300549 100644 --- a/src/widgets/scrollbar.cpp +++ b/src/widgets/scrollbar.cpp @@ -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) { diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp index 225792380e19..e0a8c7df3215 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -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; diff --git a/src/widgets/textbox.cpp b/src/widgets/textbox.cpp index 019620e039c9..7e8fb63d0db0 100644 --- a/src/widgets/textbox.cpp +++ b/src/widgets/textbox.cpp @@ -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; diff --git a/src/widgets/widget.cpp b/src/widgets/widget.cpp index b993be3e8671..ce796e6735c9 100644 --- a/src/widgets/widget.cpp +++ b/src/widgets/widget.cpp @@ -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_ ); }