Author: esr
Date: Fri Jun 22 13:06:11 2007
New Revision: 18370
URL: http://svn.gna.org/viewcvs/wesnoth?rev=18370&view=rev
Log:
Lift map_, theme_, and zoom_ to the new map_display superclass.
Modified:
trunk/src/display.cpp
trunk/src/display.hpp
Modified: trunk/src/display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=18370&r1=18369&r2=18370&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Fri Jun 22 13:06:11 2007
@@ -48,16 +48,7 @@
#define ERR_DP LOG_STREAM(err, display)
#define INFO_DP LOG_STREAM(info, display)
-
-map_display::map_display()
-{
-}
-
-map_display::~map_display()
-{
-}
-
-std::map<gamemap::location,fixed_t> display::debugHighlights_;
+// Methods for subclass aware only of terrain go here
namespace {
#ifdef USE_TINY_GUI
@@ -72,12 +63,61 @@
size_t sunset_timer = 0;
}
+map_display::map_display(const gamemap& map, const config& theme_cfg) :
map_(map), theme_(theme_cfg,screen_area()), zoom_(DefaultZoom)
+{
+}
+
+map_display::~map_display()
+{
+}
+
+const SDL_Rect& map_display::map_area() const
+{
+ static SDL_Rect res = {0, 0, 0, 0};
+ res = map_outside_area();
+
+ // hex_size() is always a multiple of 4 and hex_width() a multiple of
+ // 3 so there shouldn't be off by one errors due to rounding
+ // To display a hex fully on screen a little bit extra space is needed
+ // Also added 2 hexes for the border.
+ const int width = lexical_cast<int>((map_.x() + (7.0/3.0)) *
hex_width());
+ const int height = lexical_cast<int>((map_.y() + 2.5) * hex_size());
+
+ if(width < res.w) {
+ // map is smaller, center
+ res.x += (res.w - width)/2;
+ res.w = width;
+ }
+
+ if(height < res.h) {
+ // map is smaller, center
+ res.y += (res.h - height)/2;
+ res.h = height;
+ }
+
+ return res;
+}
+
+bool display::outside_area(const SDL_Rect& area, const int x, const int y)
const
+{
+ const int x_thresh = hex_width();
+ const int y_thresh = hex_size();
+ return (x < area.x || x > area.x + area.w - x_thresh ||
+ y < area.y || y > area.y + area.h - y_thresh);
+}
+
+
+// Methods for superclass aware of units go here
+
+std::map<gamemap::location,fixed_t> display::debugHighlights_;
+
display::display(unit_map& units, CVideo& video, const gamemap& map,
const gamestatus& status, const std::vector<team>& t,
const config& theme_cfg, const config& cfg, const config&
level) :
+ map_display(map, theme_cfg),
_scroll_event("scrolled"),
screen_(video), xpos_(0), ypos_(0),
- zoom_(DefaultZoom), map_(map), units_(units),
+ units_(units),
temp_unit_(NULL),
minimap_(NULL), redrawMinimap_(false), redraw_background_(true),
status_(status),
@@ -86,7 +126,7 @@
invalidateGameStatus_(true), panelsDrawn_(false),
currentTeam_(0), activeTeam_(0),
turbo_speed_(2), turbo_(false), grid_(false), sidebarScaling_(1.0),
- theme_(theme_cfg,screen_area()), builder_(cfg, level, map),
+ builder_(cfg, level, map),
first_turn_(true), in_game_(false), map_labels_(*this,map, 0),
tod_hex_mask1(NULL), tod_hex_mask2(NULL), reach_map_changed_(true),
diagnostic_label_(0), fps_handle_(0)
@@ -209,41 +249,6 @@
{
const time_of_day& tod = status_.get_time_of_day();
image::set_colour_adjustment(tod.red+r,tod.green+g,tod.blue+b);
-}
-
-const SDL_Rect& display::map_area() const
-{
- static SDL_Rect res = {0, 0, 0, 0};
- res = map_outside_area();
-
- // hex_size() is always a multiple of 4 and hex_width() a multiple of
- // 3 so there shouldn't be off by one errors due to rounding
- // To display a hex fully on screen a little bit extra space is needed
- // Also added 2 hexes for the border.
- const int width = lexical_cast<int>((map_.x() + (7.0/3.0)) *
hex_width());
- const int height = lexical_cast<int>((map_.y() + 2.5) * hex_size());
-
- if(width < res.w) {
- // map is smaller, center
- res.x += (res.w - width)/2;
- res.w = width;
- }
-
- if(height < res.h) {
- // map is smaller, center
- res.y += (res.h - height)/2;
- res.h = height;
- }
-
- return res;
-}
-
-bool display::outside_area(const SDL_Rect& area, const int x, const int y)
const
-{
- const int x_thresh = hex_width();
- const int y_thresh = hex_size();
- return (x < area.x || x > area.x + area.w - x_thresh ||
- y < area.y || y > area.y + area.h - y_thresh);
}
void display::select_hex(gamemap::location hex)
Modified: trunk/src/display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.hpp?rev=18370&r1=18369&r2=18370&view=diff
==============================================================================
--- trunk/src/display.hpp (original)
+++ trunk/src/display.hpp Fri Jun 22 13:06:11 2007
@@ -53,8 +53,38 @@
class map_display
{
public:
- map_display();
+ map_display(const gamemap& map, const config& theme_cfg);
~map_display();
+
+ static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
+ { return 0xFF000000 | (red << 16) | (green << 8) | blue; }
+
+ /**
+ * Returns the area used for the map
+ */
+ const SDL_Rect& map_area() const;
+
+ /**
+ * Returns the available area for a map, this may differ
+ * from the above. This area will get the background area
+ * applied to it.
+ */
+ const SDL_Rect& map_outside_area() const
+ { return theme_.main_map_location(screen_area()); }
+
+ //function which returns the width of a pixel, up to where the
+ //next hex starts (i.e. not entirely from tip to tip -- use
+ //hex_size() to get the distance from tip to tip)
+ int hex_width() const { return (zoom_*3)/4; }
+
+ //function which returns the size of a hex in pixels
+ //(from top tip to bottom tip or left edge to right edge)
+ int hex_size() const { return zoom_; }
+
+protected:
+ const gamemap& map_;
+ theme theme_;
+ int zoom_;
};
class display : public map_display
@@ -67,9 +97,6 @@
~display();
static display* get_singleton() { return singleton_ ;}
- static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
- { return 0xFF000000 | (red << 16) | (green << 8) | blue; }
-
//new_turn should be called on every new turn, to update
//lighting settings.
void new_turn();
@@ -92,14 +119,6 @@
// Returns the current zoom factor.
double get_zoom_factor() { return
double(zoom_)/double(image::tile_size); }
-
- //function which returns the size of a hex in pixels
- //(from top tip to bottom tip or left edge to right edge)
- int hex_size() const { return zoom_; }
-
- //function which returns the width of a pixel, up to where the next hex
starts
- //(i.e. not entirely from tip to tip -- use hex_size() to get the
distance from tip to tip)
- int hex_width() const { return (zoom_*3)/4; }
//function to make a screenshot and save it in a default location
void screenshot();
@@ -140,18 +159,6 @@
int w() const { return screen_.getx(); }
int h() const { return screen_.gety(); }
- /**
- * Returns the area used for the map
- */
- const SDL_Rect& map_area() const;
-
- /**
- * Returns the available area for a map, this may differ
- * from the above. This area will get the background area
- * applied to it.
- */
- const SDL_Rect& map_outside_area() const
- { return theme_.main_map_location(screen_area()); }
const SDL_Rect& minimap_area() const
{ return theme_.mini_map_location(screen_area()); }
const SDL_Rect& unit_image_area() const
@@ -469,8 +476,7 @@
CVideo& screen_;
CKey keys_;
- int xpos_, ypos_, zoom_;
- const gamemap& map_;
+ int xpos_, ypos_;
std::map<gamemap::location, surface> hex_overlay_;
surface selected_hex_overlay_;
@@ -536,7 +542,6 @@
bool turbo_, grid_;
double sidebarScaling_;
- theme theme_;
terrain_builder builder_;
void create_buttons();
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits