editor_palettes.hpp

Go to the documentation of this file.
00001 /* $Id: editor_palettes.hpp 23842 2008-02-16 08:47:16Z mordante $ */
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_palettes.hpp
00016 //!
00017 
00018 #ifndef EDITOR_PALETTES_H_INCLUDED
00019 #define EDITOR_PALETTES_H_INCLUDED
00020 
00021 #include "global.hpp"
00022 
00023 #include "SDL.h"
00024 
00025 #include "../sdl_utils.hpp"
00026 #include "../display.hpp"
00027 #include "../map.hpp"
00028 #include "../widgets/widget.hpp"
00029 #include "editor_layout.hpp"
00030 
00031 #include <vector>
00032 
00033 class config;
00034 
00035 namespace map_editor {
00036 
00037 //! Stores the info about the data in editor-groups.cfg in a nice format.
00038 // Helper struct which for some reason can't be moved to the cpp file. 
00039 struct terrain_group
00040 {
00041     terrain_group(const config& cfg, display& gui);
00042 
00043     std::string id;
00044     t_string name;
00045     gui::button button;
00046 };
00047 
00048 //! Palette where the terrain to be drawn can be selected.
00049 class terrain_palette : public gui::widget {
00050 public:
00051     terrain_palette(display &gui, const size_specs &sizes,
00052                     const gamemap &map, const config& cfg);
00053 
00054     //! Scroll the terrain-palette up one step if possible.
00055     void scroll_up();
00056 
00057     //! Scroll the terrain-palette down one step if possible.
00058     void scroll_down();
00059 
00060     //! Scroll the terrain-palette to the top.
00061     void scroll_top();
00062 
00063     //! Scroll the terrain-palette to the bottom.
00064     void scroll_bottom();
00065 
00066     //! Sets a group active id == terrain_map_->first
00067     //! The selected terrains remain the same, 
00068     //! this can result in no visible selected items.
00069     void set_group(const std::string& id);
00070 
00071     //! Return the currently selected foreground terrain.
00072     t_translation::t_terrain selected_fg_terrain() const;
00073     //! Return the currently selected background terrain.
00074     t_translation::t_terrain selected_bg_terrain() const;
00075 
00076     //! Select a foreground terrain.
00077     void select_fg_terrain(t_translation::t_terrain);
00078     void select_bg_terrain(t_translation::t_terrain);
00079 
00080     //! Update the selected terrains strings
00081     void update_selected_terrains(void);
00082 
00083     //! Draw the palette. 
00084     //! If force is true everything will be redrawn, 
00085     //! even though it is not invalidated.
00086     void draw(bool force=false);
00087     virtual void draw();
00088     virtual void handle_event(const SDL_Event& event);
00089     void set_dirty(bool dirty=true);
00090 
00091     //! Return the number of terrains in the palette.
00092     size_t num_terrains() const;
00093 
00094     //! Update the size of this widget. 
00095     //! Use if the size_specs have changed.
00096     void adjust_size();
00097 
00098     //! Sets the tooltips used in the palette
00099     void load_tooltips();
00100 
00101 private:
00102     void draw_old(bool);
00103     //! To be called when a mouse click occurs. 
00104     //! Check if the coordinates is a terrain that may be chosen, 
00105     //! and select the terrain if that is the case.
00106     void left_mouse_click(const int mousex, const int mousey);
00107     void right_mouse_click(const int mousex, const int mousey);
00108 
00109 
00110     //! Return the number of the tile that is at coordinates (x, y) in the panel.
00111     int tile_selected(const int x, const int y) const;
00112 
00113     //! Return a string represeting the terrain and the underlying ones.
00114     std::string get_terrain_string(const t_translation::t_terrain);
00115 
00116     //! Update the report with the currently selected terrains.
00117     void update_report();
00118 
00119     const size_specs &size_specs_;
00120     display &gui_;
00121     unsigned int tstart_;
00122 
00123     //! This map contains all editor_group as defined in terrain.cfg 
00124     //! and associate with the group there. 
00125     //! The group 'all' is added automatically, and all terrains 
00126     //! are also automatically stored in this group.
00127     std::map<std::string, t_translation::t_list> terrain_map_;
00128 
00129     //! A copy from the terrain_map_->second for the current active group.
00130     t_translation::t_list terrains_;
00131 
00132     //! The editor_groups as defined in editor-groups.cfg 
00133     //! Note the user must make sure the id's here are the same 
00134     //! as the editor_group in terrain.cfg
00135     std::vector<terrain_group> terrain_groups_;
00136 
00137     //! The group buttons behave like a radio group. 
00138     //! This one points to the selected button, this value should not be 0 
00139     //! otherwise things will fail. Thus should be set in constructor.
00140     gui::button *checked_group_btn_;
00141 
00142     t_translation::t_terrain selected_fg_terrain_, selected_bg_terrain_;
00143     const gamemap &map_;
00144     gui::button top_button_, bot_button_;
00145     size_t button_x_, top_button_y_, bot_button_y_;
00146     size_t nterrains_, terrain_start_;
00147 };
00148 
00149 //! A bar where the brush is drawn
00150 class brush_bar : public gui::widget {
00151 public:
00152     brush_bar(display &gui, const size_specs &sizes);
00153 
00154     //! Return the size of currently selected brush.
00155     unsigned int selected_brush_size();
00156 
00157     //! Select a brush size.
00158     void select_brush_size(int new_size);
00159 
00160     //! Draw the palette. If force is true, everything 
00161     //! will be redrawn, even though it is not dirty.
00162     void draw(bool force=false);
00163     virtual void draw();
00164     virtual void handle_event(const SDL_Event& event);
00165 
00166     //! Update the size of this widget. 
00167     //! Use if the size_specs have changed.
00168     void adjust_size();
00169 
00170 private:
00171     //! To be called when a mouse click occurs. 
00172     //! Check if the coordinates is a terrain that may be chosen, 
00173     //! and select the terrain if that is the case.
00174     void left_mouse_click(const int mousex, const int mousey);
00175 
00176     //! Return the index of the brush that is at coordinates (x, y) in the panel.
00177     int selected_index(const int x, const int y) const;
00178 
00179     const size_specs &size_specs_;
00180     display &gui_;
00181     unsigned int selected_;
00182     const int total_brush_;
00183     const size_t size_;
00184 };
00185 
00186 
00187 }
00188 #endif // EDITOR_PALETTES_H_INCLUDED
00189 

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