Skip to content

Commit

Permalink
Move some functions to sdl/rect.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jun 3, 2014
1 parent deeaaa7 commit ac96a2b
Show file tree
Hide file tree
Showing 34 changed files with 204 additions and 195 deletions.
12 changes: 6 additions & 6 deletions src/construct_dialog.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/controller_base.cpp
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 12 additions & 12 deletions src/display.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/editor/palette/palette_manager.cpp
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/editor/palette/tristate_button.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/font.cpp
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widgets/scrollbar_container.cpp
Expand Up @@ -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>

Expand Down Expand Up @@ -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_);
}
Expand Down
9 changes: 5 additions & 4 deletions src/gui/widgets/widget.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/window.cpp
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/halo.cpp
Expand Up @@ -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_()
{
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/help.cpp
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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_) {
Expand Down
2 changes: 1 addition & 1 deletion src/loadscreen.cpp
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/menu_events.cpp
Expand Up @@ -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("
Expand Down
2 changes: 1 addition & 1 deletion src/mouse_events.cpp
Expand Up @@ -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*/)
Expand Down
5 changes: 3 additions & 2 deletions src/mouse_handler_base.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/multiplayer_lobby.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/multiplayer_ui.cpp
Expand Up @@ -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_; }
Expand Down
2 changes: 1 addition & 1 deletion src/playsingle_controller.cpp
Expand Up @@ -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()
);
Expand Down

0 comments on commit ac96a2b

Please sign in to comment.