Move the point code to a new file and library.
Trying to offload some code into seperate libraries to improve (re)build time.
This commit is contained in:
parent
2f27cecc0d
commit
29d487773e
12 changed files with 154 additions and 63 deletions
|
@ -104,6 +104,7 @@ src/gui/dialogs/transient_message.cpp
|
|||
src/gui/dialogs/unit_attack.cpp
|
||||
src/gui/dialogs/unit_create.cpp
|
||||
src/gui/dialogs/wml_message.cpp
|
||||
src/gui/lib/types/point.cpp
|
||||
src/gui/widgets/button.cpp
|
||||
src/gui/widgets/container.cpp
|
||||
src/gui/widgets/control.cpp
|
||||
|
|
|
@ -313,6 +313,28 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
|||
COMPILE_FLAGS "-Wno-old-style-cast")
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
########### Helper libraries ###############
|
||||
|
||||
# The main library is rather huge especially in debug mode, causing quite a bit
|
||||
# of overhead packing objects that haven't been changed for quite a while.
|
||||
# Attempting to solve the issue with several smaller libraries when adding new
|
||||
# files.
|
||||
|
||||
##### Gui types
|
||||
|
||||
# This library contains the basic types for the gui library.
|
||||
# - Public Enumerates
|
||||
# - Small structs
|
||||
set(wesnoth-gui_types_SRC
|
||||
gui/lib/types/point.cpp
|
||||
)
|
||||
|
||||
add_library(wesnoth-gui_types
|
||||
${LIBRARY_TYPE}
|
||||
EXCLUDE_FROM_ALL
|
||||
${wesnoth-gui_types_SRC}
|
||||
)
|
||||
|
||||
|
||||
########### Wesnoth main source files ###############
|
||||
|
||||
|
@ -739,10 +761,12 @@ if(ENABLE_GAME)
|
|||
)
|
||||
set(wesnoth_LIB
|
||||
wesnoth-game
|
||||
wesnoth-gui_types
|
||||
)
|
||||
else(ENABLE_TESTS)
|
||||
set(wesnoth_SRC
|
||||
game.cpp
|
||||
${wesnoth-gui_types_SRC}
|
||||
${wesnoth-main_SRC}
|
||||
)
|
||||
set(wesnoth_LIB
|
||||
|
@ -950,20 +974,31 @@ if(ENABLE_TESTS)
|
|||
tests/gui/visitor.cpp
|
||||
tests/gui/test_save_dialog.cpp
|
||||
)
|
||||
if(NOT ENABLE_GAME)
|
||||
if(ENABLE_GAME)
|
||||
set(test_LIB
|
||||
wesnoth-core
|
||||
wesnoth-game
|
||||
wesnoth-gui_types
|
||||
wesnoth-lua
|
||||
)
|
||||
else(ENABLE_GAME)
|
||||
set(test_SRC
|
||||
${test_SRC}
|
||||
${wesnoth-gui_types_SRC}
|
||||
${wesnoth-main_SRC}
|
||||
)
|
||||
endif(NOT ENABLE_GAME)
|
||||
set(test_LIB
|
||||
wesnoth-core
|
||||
wesnoth-game
|
||||
wesnoth-lua
|
||||
)
|
||||
endif(ENABLE_GAME)
|
||||
|
||||
add_executable(test
|
||||
${test_SRC}
|
||||
)
|
||||
target_link_libraries(test
|
||||
wesnoth-core
|
||||
wesnoth-game
|
||||
wesnoth-lua
|
||||
${test_LIB}
|
||||
${game-external-libs}
|
||||
boost_unit_test_framework
|
||||
)
|
||||
|
|
|
@ -368,6 +368,7 @@ wesnoth_sources = Split("""
|
|||
gui/dialogs/unit_attack.cpp
|
||||
gui/dialogs/unit_create.cpp
|
||||
gui/dialogs/wml_message.cpp
|
||||
gui/lib/types/point.cpp
|
||||
gui/widgets/button.cpp
|
||||
gui/widgets/container.cpp
|
||||
gui/widgets/control.cpp
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include "gui/auxiliary/event/dispatcher.hpp"
|
||||
#include "gui/widgets/event_executor.hpp"
|
||||
#include "gui/widgets/helper.hpp"
|
||||
#include "gui/lib/types/point.hpp"
|
||||
|
||||
namespace gui2{
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "gui/auxiliary/placer/horizontal_list.hpp"
|
||||
|
||||
#include "gui/widgets/helper.hpp"
|
||||
#include "gui/lib/types/point.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <numeric>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "gui/auxiliary/placer/vertical_list.hpp"
|
||||
|
||||
#include "gui/widgets/helper.hpp"
|
||||
#include "gui/lib/types/point.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <numeric>
|
||||
|
|
44
src/gui/lib/types/point.cpp
Normal file
44
src/gui/lib/types/point.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/lib/types/point.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
tpoint& tpoint::operator+=(const tpoint& point)
|
||||
{
|
||||
x += point.x;
|
||||
y += point.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tpoint& tpoint::operator-=(const tpoint& point)
|
||||
{
|
||||
x -= point.x;
|
||||
y -= point.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const tpoint& point)
|
||||
{
|
||||
stream << point.x << ',' << point.y;
|
||||
return stream;
|
||||
}
|
||||
|
||||
} // namespace gui2
|
61
src/gui/lib/types/point.hpp
Normal file
61
src/gui/lib/types/point.hpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_LIB_TYPES_POINT_HPP_INCLUDED
|
||||
#define GUI_LIB_TYPES_POINT_HPP_INCLUDED
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
/** Holds a 2D point. */
|
||||
struct tpoint
|
||||
{
|
||||
tpoint(const int x_, const int y_) :
|
||||
x(x_),
|
||||
y(y_)
|
||||
{}
|
||||
|
||||
/** x coodinate. */
|
||||
int x;
|
||||
|
||||
/** y coodinate. */
|
||||
int y;
|
||||
|
||||
bool operator==(const tpoint& point) const { return x == point.x && y == point.y; }
|
||||
bool operator!=(const tpoint& point) const { return x != point.x || y != point.y; }
|
||||
bool operator<(const tpoint& point) const
|
||||
{ return x < point.x || (x == point.x && y < point.y); }
|
||||
|
||||
bool operator<=(const tpoint& point) const
|
||||
{ return x < point.x || (x == point.x && y <= point.y); }
|
||||
|
||||
tpoint operator+(const tpoint& point) const
|
||||
{ return tpoint(x + point.x, y + point.y); }
|
||||
|
||||
tpoint& operator+=(const tpoint& point);
|
||||
|
||||
tpoint operator-(const tpoint& point) const
|
||||
{ return tpoint(x - point.x, y - point.y); }
|
||||
|
||||
tpoint& operator-=(const tpoint& point);
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const tpoint& point);
|
||||
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
|
@ -47,26 +47,6 @@ SDL_Rect create_rect(const tpoint& origin, const tpoint& size)
|
|||
return ::create_rect(origin.x, origin.y, size.x, size.y);
|
||||
}
|
||||
|
||||
tpoint& tpoint::operator+=(const tpoint& point)
|
||||
{
|
||||
x += point.x;
|
||||
y += point.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tpoint& tpoint::operator-=(const tpoint& point)
|
||||
{
|
||||
x -= point.x;
|
||||
y -= point.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const tpoint& point)
|
||||
{
|
||||
stream << point.x << ',' << point.y;
|
||||
return stream;
|
||||
}
|
||||
|
||||
unsigned decode_font_style(const std::string& style)
|
||||
{
|
||||
if(style == "bold") {
|
||||
|
|
|
@ -34,6 +34,8 @@ class map_formula_callable;
|
|||
|
||||
namespace gui2 {
|
||||
|
||||
class tpoint;
|
||||
|
||||
/**
|
||||
* Initializes the gui subsystems.
|
||||
*
|
||||
|
@ -42,41 +44,6 @@ namespace gui2 {
|
|||
*/
|
||||
bool init();
|
||||
|
||||
/** Holds a 2D point. */
|
||||
struct tpoint
|
||||
{
|
||||
tpoint(const int x_, const int y_) :
|
||||
x(x_),
|
||||
y(y_)
|
||||
{}
|
||||
|
||||
/** x coodinate. */
|
||||
int x;
|
||||
|
||||
/** y coodinate. */
|
||||
int y;
|
||||
|
||||
bool operator==(const tpoint& point) const { return x == point.x && y == point.y; }
|
||||
bool operator!=(const tpoint& point) const { return x != point.x || y != point.y; }
|
||||
bool operator<(const tpoint& point) const
|
||||
{ return x < point.x || (x == point.x && y < point.y); }
|
||||
|
||||
bool operator<=(const tpoint& point) const
|
||||
{ return x < point.x || (x == point.x && y <= point.y); }
|
||||
|
||||
tpoint operator+(const tpoint& point) const
|
||||
{ return tpoint(x + point.x, y + point.y); }
|
||||
|
||||
tpoint& operator+=(const tpoint& point);
|
||||
|
||||
tpoint operator-(const tpoint& point) const
|
||||
{ return tpoint(x - point.x, y - point.y); }
|
||||
|
||||
tpoint& operator-=(const tpoint& point);
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const tpoint& point);
|
||||
|
||||
/**
|
||||
* Creates a rectangle.
|
||||
*
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define GUI_WIDGETS_WIDGET_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/event/dispatcher.hpp"
|
||||
#include "gui/lib/types/point.hpp"
|
||||
#include "gui/widgets/event_executor.hpp"
|
||||
#include "gui/widgets/helper.hpp"
|
||||
#include "utils/const_clone.tpp"
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "gettext.hpp"
|
||||
#include "gui/widgets/helper.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/lib/types/point.hpp"
|
||||
#include "font.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "tstring.hpp"
|
||||
|
|
Loading…
Add table
Reference in a new issue