editor_display.cpp

Go to the documentation of this file.
00001 /* $Id: editor_display.cpp 25683 2008-04-08 14:59:32Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file editor/editor_display.cpp 
00016 //! Draw the screen for the map-editor.
00017 
00018 #include "global.hpp"
00019 
00020 #include "display.hpp"
00021 #include "game_config.hpp"
00022 #include "gamestatus.hpp"
00023 #include "gettext.hpp"
00024 #include "hotkeys.hpp"
00025 #include "language.hpp"
00026 #include "preferences.hpp"
00027 #include "sdl_utils.hpp"
00028 #include "theme.hpp"
00029 #include "tooltips.hpp"
00030 #include "util.hpp"
00031 
00032 #include "SDL_image.h"
00033 
00034 #include <cassert>
00035 
00036 editor_display::editor_display(CVideo& video, const gamemap& map,
00037         const config& theme_cfg, const config& cfg,
00038         const config& level) :
00039     display(video, map, theme_cfg, cfg, level)
00040 {
00041     // Clear the screen contents
00042     surface const disp(screen_.getSurface());
00043     SDL_Rect area = screen_area();
00044     SDL_FillRect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
00045 }
00046 
00047 void editor_display::draw(bool update,bool force)
00048 {
00049     bool changed = display::draw_init();
00050 
00051     //!@todo FIXME: this should be done from the preferences dialog as well,
00052     //! to reflect changes for the user before closing it
00053     this->update_light_levels();
00054     image::set_colour_adjustment(lr_, lg_, lb_);
00055 
00056     //int simulate_delay = 0;
00057     if(!map_.empty() && !invalidated_.empty()) {
00058         changed = true;
00059 
00060         SDL_Rect clip_rect = map_outside_area();
00061         surface const screen(get_screen_surface());
00062         clip_rect_setter set_clip_rect(screen, clip_rect);
00063 
00064         std::set<gamemap::location>::const_iterator it;
00065         for(it = invalidated_.begin(); it != invalidated_.end(); ++it) {
00066             image::TYPE image_type = image::SCALED_TO_HEX;
00067 
00068             if(*it == mouseoverHex_ && map_.on_board(mouseoverHex_, true)) {
00069                 image_type = image::BRIGHTENED;
00070             }
00071             else if (highlighted_locations_.find(*it) != highlighted_locations_.end()) {
00072                 image_type = image::SEMI_BRIGHTENED;
00073             }
00074 
00075             if(screen_.update_locked()) {
00076                 continue;
00077             }
00078 
00079             int xpos = int(get_location_x(*it));
00080             int ypos = int(get_location_y(*it));
00081             int drawing_order = gamemap::get_drawing_order(*it);
00082 
00083             if(xpos >= clip_rect.x + clip_rect.w || ypos >= clip_rect.y + clip_rect.h ||
00084                xpos + zoom_ < clip_rect.x || ypos + zoom_ < clip_rect.y) {
00085                 continue;
00086             }
00087 
00088             //!@todo FIXME: this seems to have no effect, and to be left-over of the
00089             //! time of day light system used before around version 0.9
00090             const std::string nodarken = "morning";
00091             drawing_buffer_add(LAYER_TERRAIN_BG, drawing_order, tblit(xpos, ypos,
00092                 get_terrain_images(*it,nodarken,image_type,ADJACENT_BACKGROUND)));
00093             drawing_buffer_add(LAYER_TERRAIN_FG, drawing_order, tblit(xpos, ypos,
00094                 get_terrain_images(*it,nodarken,image_type,ADJACENT_FOREGROUND)));
00095 
00096             // Draw the grid, if it has been enabled
00097             if(grid_ && map_.on_board(*it)) {
00098                 drawing_buffer_add(LAYER_TERRAIN_TMP_BG, drawing_order, tblit(xpos, ypos,
00099                     image::get_image(game_config::grid_image, image::SCALED_TO_HEX)));
00100             }
00101 
00102             // Paint selection and mouseover overlays
00103             if(*it == selectedHex_ && map_.on_board(selectedHex_, true) && selected_hex_overlay_ != NULL) {
00104                 drawing_buffer_add(LAYER_TERRAIN_TMP_BG, drawing_order, tblit(xpos, ypos, selected_hex_overlay_));
00105             }
00106             if(*it == mouseoverHex_ && map_.on_board(mouseoverHex_, true) && mouseover_hex_overlay_ != NULL) {
00107                 drawing_buffer_add(LAYER_TERRAIN_TMP_BG, drawing_order, tblit(xpos, ypos, mouseover_hex_overlay_));
00108             }
00109 
00110             drawing_buffer_commit();
00111 
00112             // If the tile is at the border, we start to blend it
00113             if(!map_.on_board(*it) &&
00114                     (map_.get_terrain(*it) != t_translation::OFF_MAP_USER)) { 
00115                  draw_border(*it, xpos, ypos);
00116             }
00117         }
00118 
00119         invalidated_.clear();
00120     } else if (!map_.empty()) {
00121         assert(invalidated_.empty());
00122     }
00123 
00124     // Fill in the terrain report
00125     if(map_.on_board(mouseoverHex_, true)) {
00126         const t_translation::t_terrain terrain = map_.get_terrain(mouseoverHex_);
00127         const t_translation::t_list& underlying = map_.underlying_union_terrain(terrain);
00128 
00129         std::stringstream str;
00130         str << map_.get_terrain_info(terrain).name();
00131         if(underlying.size() != 1 || underlying.front() != terrain) {
00132             str << " (";
00133 
00134             for(t_translation::t_list::const_iterator i =
00135                     underlying.begin(); i != underlying.end(); ++i) {
00136 
00137             str << map_.get_terrain_info(*i).name();
00138                 if(i+1 != underlying.end()) {
00139                     str << ",";
00140                 }
00141             }
00142             str << ")";
00143         }
00144         refresh_report(reports::TERRAIN, reports::report(str.str()));
00145 
00146         std::stringstream str2;
00147         str2 << mouseoverHex_;
00148         refresh_report(reports::POSITION, reports::report(str2.str()));
00149     }
00150 
00151     {
00152       std::stringstream str3;
00153       str3 << map_.villages().size();
00154       refresh_report(reports::VILLAGES, reports::report(str3.str()));
00155     }
00156 
00157     display::draw_wrap(update, force, changed);
00158 }
00159 
00160 void editor_display::update_light_levels(void)
00161 {
00162     this->lr_ = preferences::editor_r();
00163     this->lg_ = preferences::editor_g();
00164     this->lb_ = preferences::editor_b();
00165 }
00166 

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs