editor/palette/editor_palettes.hpp

Go to the documentation of this file.
00001 /* $Id: editor_palettes.hpp 53695 2012-03-30 15:42:21Z fendrin $ */
00002 /*
00003    Copyright (C) 2003 - 2012 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 as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef EDITOR_PALETTES_H_INCLUDED
00017 #define EDITOR_PALETTES_H_INCLUDED
00018 
00019 #include "../editor_display.hpp"
00020 #include "palette_layout.hpp"
00021 #include "common_palette.hpp"
00022 
00023 namespace editor {
00024 
00025 template<class Item>
00026 class editor_palette : public common_palette {
00027 
00028 public:
00029 
00030     editor_palette(editor_display &gui, const size_specs &sizes, const config& /*cfg*/
00031             , size_t item_size, size_t item_width, mouse_action** active_mouse_action)
00032         : groups_()
00033         , gui_(gui)
00034         , size_specs_(sizes)
00035         , item_size_(item_size)
00036         , item_width_(item_width)
00037         , item_space_(item_size + 3)
00038         , palette_y_(sizes.palette_y)
00039         , palette_x_(sizes.palette_x)
00040         , group_map_()
00041         , item_map_()
00042         , nitems_(0)
00043         , nmax_items_(0)
00044         , items_start_(0)
00045         , non_core_items_()
00046         , active_group_()
00047         , selected_fg_item_()
00048         , selected_bg_item_()
00049         , active_mouse_action_(active_mouse_action)
00050     {
00051     };
00052 
00053     void set_start_item(size_t index) { items_start_ = index; };
00054 
00055     size_t start_num(void) { return items_start_; };
00056 
00057     /** Menu expanding for palette group list */
00058     void expand_palette_groups_menu(std::vector<std::string>& items);
00059 
00060     void set_group(size_t index);
00061 
00062     const std::vector<item_group>& get_groups() const { return groups_; };
00063 
00064     virtual void draw(bool);
00065 
00066     bool left_mouse_click(const int, const int);
00067     bool right_mouse_click(const int, const int);
00068 
00069     void next_group() {
00070         set_group( (active_group_index() +1) % (groups_.size() -1) );
00071     };
00072     void prev_group() {
00073         set_group( (active_group_index() -1) % (groups_.size() -1) );
00074     };
00075 
00076     /**
00077      * Update the size of this widget.
00078      *
00079      * Use if the size_specs have changed.
00080      */
00081     void adjust_size(const size_specs& size);
00082 
00083     virtual bool scroll_up();
00084     virtual bool scroll_down();
00085 
00086     virtual const config active_group_report();
00087 
00088     void swap();
00089 
00090     /** Return the currently selected foreground/background item. */
00091     const Item& selected_fg_item() const { return item_map_.find(selected_fg_item_)->second; };
00092     const Item& selected_bg_item() const { return item_map_.find(selected_bg_item_)->second; };
00093 
00094 private:
00095 
00096     /** Return the number of the tile that is at coordinates (x, y) in the panel. */
00097     int tile_selected(const int x, const int y) const;
00098 
00099     /** TODO */
00100     size_t active_group_index();
00101 
00102     /** Scroll the editor-palette to the top. */
00103     void scroll_top();
00104 
00105     /** Scroll the editor-palette to the bottom. */
00106     void scroll_bottom();
00107 
00108     virtual void draw_item(SDL_Rect& dstrect, const Item& item, std::stringstream& tooltip) = 0;
00109 
00110     virtual const std::string& get_id(const Item& item) = 0;
00111 
00112     /** Setup the internal data structure. */
00113     virtual void setup(const config& cfg) = 0;
00114 
00115     virtual const std::string& active_group_id() {return active_group_;};
00116 
00117     /** Return the number of items in the palette. */
00118     size_t num_items();
00119 
00120     void draw_old(bool);
00121 
00122 protected:
00123     /**
00124      * Sets a group active id
00125      *
00126      * This can result in no visible
00127      * selected items.
00128      */
00129     virtual void set_group(const std::string& id);
00130     const std::vector<std::string>& active_group() { return group_map_[active_group_]; };
00131 
00132     /** Select a foreground item. */
00133     virtual void select_fg_item(std::string item_id);
00134     virtual void select_bg_item(std::string item_id);
00135 
00136     /**
00137      * The editor_groups as defined in editor-groups.cfg.
00138      *
00139      * Note the user must make sure the id's here are the same as the
00140      * editor_group in terrain.cfg.
00141      */
00142     std::vector<item_group> groups_;
00143 
00144     editor_display &gui_;
00145     const size_specs &size_specs_;
00146 
00147     int item_size_;
00148     int item_width_;
00149     int item_space_;
00150 
00151 private:
00152     unsigned int palette_y_;
00153     unsigned int palette_x_;
00154 
00155 protected:
00156     std::map<std::string, std::vector<std::string> > group_map_;
00157 
00158     std::map<std::string, Item> item_map_;
00159     size_t nitems_, nmax_items_, items_start_;
00160     std::set<std::string> non_core_items_;
00161 
00162 private:
00163     std::string active_group_;
00164     std::string selected_fg_item_;
00165     std::string selected_bg_item_;
00166 
00167     mouse_action** active_mouse_action_;
00168 };
00169 
00170 
00171 } //end namespace editor
00172 #endif // EDITOR_PALETTES_H_INCLUDED
00173 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:35 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs