doxygen, comments
This commit is contained in:
parent
a22d742e62
commit
b3a9641175
2 changed files with 73 additions and 67 deletions
|
@ -12,6 +12,9 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file editor/editor_palettes.cpp
|
||||
//! Manage the terrain-palette in the editor.
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_keysym.h"
|
||||
|
||||
|
@ -48,30 +51,30 @@ terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
|
|||
bot_button_(gui.video(), "", gui::button::TYPE_PRESS, "downarrow-button")
|
||||
{
|
||||
|
||||
// get the available terrains temporary in terrains_
|
||||
// Get the available terrains temporary in terrains_
|
||||
terrains_ = map_.get_terrain_list();
|
||||
terrains_.erase(std::remove_if(terrains_.begin(), terrains_.end(), is_invalid_terrain),
|
||||
terrains_.end());
|
||||
|
||||
// get the available groups and add them to the structure
|
||||
// Get the available groups and add them to the structure
|
||||
const config::child_list& groups = cfg.get_children("editor_group");
|
||||
config::child_list::const_iterator g_itor = groups.begin();
|
||||
for(; g_itor != groups.end(); ++ g_itor) {
|
||||
terrain_groups_.push_back(terrain_group(**g_itor, gui));
|
||||
|
||||
// by default the all button is pressed
|
||||
// By default the 'all'-button is pressed
|
||||
if(terrain_groups_.back().id == "all") {
|
||||
terrain_groups_.back().button.set_check(true);
|
||||
checked_group_btn_ = &terrain_groups_.back().button;
|
||||
}
|
||||
}
|
||||
// the rest of the code assumes this is a valid pointer
|
||||
// The rest of the code assumes this is a valid pointer
|
||||
wassert(checked_group_btn_ != 0);
|
||||
|
||||
// add the groups for all terrains to the map
|
||||
// Add the groups for all terrains to the map
|
||||
t_translation::t_list::const_iterator t_itor = terrains_.begin();
|
||||
for(; t_itor != terrains_.end(); ++t_itor) {
|
||||
// add the terrain to the requested groups
|
||||
// Add the terrain to the requested groups
|
||||
const std::vector<std::string>& key =
|
||||
utils::split(map_.get_terrain_info(*t_itor).editor_group());
|
||||
|
||||
|
@ -81,11 +84,11 @@ terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
|
|||
terrain_map_[*k_itor].push_back(*t_itor);
|
||||
}
|
||||
|
||||
// add the terrain to the default group
|
||||
// Add the terrain to the default group
|
||||
terrain_map_["all"].push_back(*t_itor);
|
||||
}
|
||||
|
||||
// set the default group
|
||||
// Set the default group
|
||||
terrains_ = terrain_map_["all"];
|
||||
|
||||
if(terrains_.empty()) {
|
||||
|
@ -105,13 +108,13 @@ void terrain_palette::adjust_size() {
|
|||
const size_t button_height = 24;
|
||||
const size_t button_palette_padding = 8;
|
||||
|
||||
//values for the group buttons fully hardcoded for now
|
||||
//will be fixed later
|
||||
const size_t group_button_height = 24;
|
||||
const size_t group_button_padding = 2;
|
||||
const size_t group_buttons_per_row = 5;
|
||||
// Values for the group buttons fully hardcoded for now
|
||||
//! @todo will be fixed later
|
||||
const size_t group_button_height = 24;
|
||||
const size_t group_button_padding = 2;
|
||||
const size_t group_buttons_per_row = 5;
|
||||
|
||||
//determine number of theme button rows
|
||||
// Determine number of theme button rows
|
||||
size_t group_rows = terrain_groups_.size() / group_buttons_per_row;
|
||||
if(terrain_groups_.size() % group_buttons_per_row != 0) {
|
||||
++group_rows;
|
||||
|
@ -522,8 +525,7 @@ void brush_bar::draw(bool force) {
|
|||
const SDL_Rect loc = location();
|
||||
int x = loc.x;
|
||||
// Everything will be redrawn even though only one little part may
|
||||
// have changed, but that happens so seldom so we'll settle with
|
||||
// this.
|
||||
// have changed, but that happens so seldom so we'll settle with this.
|
||||
SDL_Surface* const screen = gui_.video().getSurface();
|
||||
for (int i = 1; i <= total_brush_; i++) {
|
||||
std::stringstream filename;
|
||||
|
@ -577,4 +579,5 @@ int brush_bar::selected_index(const int x, const int y) const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
} // end namespace map_editor
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
//! @file editor/editor_palettes.hpp
|
||||
//!
|
||||
|
||||
#ifndef EDITOR_PALETTES_H_INCLUDED
|
||||
#define EDITOR_PALETTES_H_INCLUDED
|
||||
|
||||
|
@ -31,9 +34,8 @@ class config;
|
|||
|
||||
namespace map_editor {
|
||||
|
||||
// a helper struct which for some reason can't be moved to
|
||||
// the cpp file. Stores the info about the data in
|
||||
// editor-groups.cfg in a nice format
|
||||
//! Stores the info about the data in editor-groups.cfg in a nice format.
|
||||
// Helper struct which for some reason can't be moved to the cpp file.
|
||||
struct terrain_group
|
||||
{
|
||||
terrain_group(const config& cfg, display& gui);
|
||||
|
@ -43,97 +45,98 @@ struct terrain_group
|
|||
gui::button button;
|
||||
};
|
||||
|
||||
/// A palette where the terrain to be drawn can be selected.
|
||||
//! Palette where the terrain to be drawn can be selected.
|
||||
class terrain_palette : public gui::widget {
|
||||
public:
|
||||
terrain_palette(display &gui, const size_specs &sizes,
|
||||
const gamemap &map, const config& cfg);
|
||||
|
||||
/// Scroll the terrain palette up one step if possible.
|
||||
//! Scroll the terrain-palette up one step if possible.
|
||||
void scroll_up();
|
||||
|
||||
/// Scroll the terrain palette down one step if possible.
|
||||
//! Scroll the terrain-palette down one step if possible.
|
||||
void scroll_down();
|
||||
|
||||
/// Scroll the terrain palette to the top.
|
||||
//! Scroll the terrain-palette to the top.
|
||||
void scroll_top();
|
||||
|
||||
/// Scroll the terrain palette to the bottom.
|
||||
//! Scroll the terrain-palette to the bottom.
|
||||
void scroll_bottom();
|
||||
|
||||
/// sets a group active id == terrain_map_->first
|
||||
//the selected terrains remain the same, this can
|
||||
//result in no visible selected items
|
||||
//! Sets a group active id == terrain_map_->first
|
||||
//! The selected terrains remain the same,
|
||||
//! this can result in no visible selected items.
|
||||
void set_group(const std::string& id);
|
||||
|
||||
/// Return the currently selected foreground terrain.
|
||||
//! Return the currently selected foreground terrain.
|
||||
t_translation::t_letter selected_fg_terrain() const;
|
||||
/// Return the currently selected background terrain.
|
||||
//! Return the currently selected background terrain.
|
||||
t_translation::t_letter selected_bg_terrain() const;
|
||||
|
||||
/// Select a foreground terrain.
|
||||
//! Select a foreground terrain.
|
||||
void select_fg_terrain(t_translation::t_letter);
|
||||
void select_bg_terrain(t_translation::t_letter);
|
||||
|
||||
// Update the selected terrains strings
|
||||
//! Update the selected terrains strings
|
||||
void update_selected_terrains(void);
|
||||
|
||||
// Draw the palette. If force is true everything will be redrawn
|
||||
// even though it is not invalidated.
|
||||
//! Draw the palette.
|
||||
//! If force is true everything will be redrawn,
|
||||
//! even though it is not invalidated.
|
||||
void draw(bool force=false);
|
||||
virtual void draw();
|
||||
virtual void handle_event(const SDL_Event& event);
|
||||
void set_dirty(bool dirty=true);
|
||||
|
||||
/// Return the number of terrains in the palette.
|
||||
//! Return the number of terrains in the palette.
|
||||
size_t num_terrains() const;
|
||||
|
||||
/// Update the size of this widget. Use if the size_specs have
|
||||
/// changed.
|
||||
//! Update the size of this widget.
|
||||
//! Use if the size_specs have changed.
|
||||
void adjust_size();
|
||||
|
||||
/// sets the tooltips used in the palette
|
||||
//! Sets the tooltips used in the palette
|
||||
void load_tooltips();
|
||||
|
||||
private:
|
||||
void draw_old(bool);
|
||||
/// To be called when a mouse click occurs. Check if the coordinates
|
||||
/// is a terrain that may be chosen, select the terrain if that is
|
||||
/// the case.
|
||||
//! To be called when a mouse click occurs.
|
||||
//! Check if the coordinates is a terrain that may be chosen,
|
||||
//! and select the terrain if that is the case.
|
||||
void left_mouse_click(const int mousex, const int mousey);
|
||||
void right_mouse_click(const int mousex, const int mousey);
|
||||
|
||||
|
||||
/// Return the number of the tile that is at coordinates (x, y) in the
|
||||
/// panel.
|
||||
//! Return the number of the tile that is at coordinates (x, y) in the panel.
|
||||
int tile_selected(const int x, const int y) const;
|
||||
|
||||
/// Return a string represeting the terrain and the underlying ones.
|
||||
//! Return a string represeting the terrain and the underlying ones.
|
||||
std::string get_terrain_string(const t_translation::t_letter);
|
||||
|
||||
/// Update the report with the currently selected terrains.
|
||||
//! Update the report with the currently selected terrains.
|
||||
void update_report();
|
||||
|
||||
const size_specs &size_specs_;
|
||||
display &gui_;
|
||||
unsigned int tstart_;
|
||||
|
||||
//this map contains all editor_group as defined in terrain.cfg and
|
||||
//associate with the group there. The group all is added automatically
|
||||
//and all terrains are also automatically stored in this group
|
||||
//! This map contains all editor_group as defined in terrain.cfg
|
||||
//! and associate with the group there.
|
||||
//! The group 'all' is added automatically, and all terrains
|
||||
//! are also automatically stored in this group.
|
||||
std::map<std::string, t_translation::t_list> terrain_map_;
|
||||
|
||||
// a copy from the terrain_map_->second for the current active group
|
||||
//! A copy from the terrain_map_->second for the current active group.
|
||||
t_translation::t_list terrains_;
|
||||
|
||||
//the editor_groups as defined in editor-groups.cfg, note the
|
||||
//user must make sure the id's here are the same as the
|
||||
//editor_group in terrain.cfg
|
||||
//! The editor_groups as defined in editor-groups.cfg
|
||||
//! Note the user must make sure the id's here are the same
|
||||
//! as the editor_group in terrain.cfg
|
||||
std::vector<terrain_group> terrain_groups_;
|
||||
|
||||
//the group buttons behave like a radio group this one points to the
|
||||
//selected button, this value should not be 0 otherwise things will
|
||||
//fail. Thus should be set in constructor
|
||||
//! The group buttons behave like a radio group.
|
||||
//! This one points to the selected button, this value should not be 0
|
||||
//! otherwise things will fail. Thus should be set in constructor.
|
||||
gui::button *checked_group_btn_;
|
||||
|
||||
t_translation::t_letter selected_fg_terrain_, selected_bg_terrain_;
|
||||
|
@ -143,35 +146,34 @@ private:
|
|||
size_t nterrains_, terrain_start_;
|
||||
};
|
||||
|
||||
/// A bar where the brush is drawin
|
||||
//! A bar where the brush is drawn
|
||||
class brush_bar : public gui::widget {
|
||||
public:
|
||||
brush_bar(display &gui, const size_specs &sizes);
|
||||
|
||||
/// Return the size of currently selected brush.
|
||||
//! Return the size of currently selected brush.
|
||||
unsigned int selected_brush_size();
|
||||
|
||||
/// Select a brush size.
|
||||
//! Select a brush size.
|
||||
void select_brush_size(int new_size);
|
||||
|
||||
// Draw the palette. If force is true everything will be redrawn
|
||||
// even though it is not dirty.
|
||||
//! Draw the palette. If force is true, everything
|
||||
//! will be redrawn, even though it is not dirty.
|
||||
void draw(bool force=false);
|
||||
virtual void draw();
|
||||
virtual void handle_event(const SDL_Event& event);
|
||||
|
||||
/// Update the size of this widget. Use if the size_specs have
|
||||
/// changed.
|
||||
//! Update the size of this widget.
|
||||
//! Use if the size_specs have changed.
|
||||
void adjust_size();
|
||||
|
||||
private:
|
||||
/// To be called when a mouse click occurs. Check if the coordinates
|
||||
/// is a terrain that may be chosen, select the terrain if that is
|
||||
/// the case.
|
||||
//! To be called when a mouse click occurs.
|
||||
//! Check if the coordinates is a terrain that may be chosen,
|
||||
//! and select the terrain if that is the case.
|
||||
void left_mouse_click(const int mousex, const int mousey);
|
||||
|
||||
/// Return the index of the brush that is at coordinates (x, y) in the
|
||||
/// panel.
|
||||
//! Return the index of the brush that is at coordinates (x, y) in the panel.
|
||||
int selected_index(const int x, const int y) const;
|
||||
|
||||
const size_specs &size_specs_;
|
||||
|
@ -184,3 +186,4 @@ private:
|
|||
|
||||
}
|
||||
#endif // EDITOR_PALETTES_H_INCLUDED
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue