Author: mordante
Date: Fri Apr 4 18:30:48 2008
New Revision: 25541
URL: http://svn.gna.org/viewcvs/wesnoth?rev=25541&view=rev
Log:
Add the basics for the label class.
Added:
trunk/src/gui/widgets/label.cpp (with props)
trunk/src/gui/widgets/label.hpp (with props)
Modified:
trunk/src/gui/widgets/settings.cpp
trunk/src/gui/widgets/settings.hpp
trunk/src/gui/widgets/window_builder.cpp
Added: trunk/src/gui/widgets/label.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/label.cpp?rev=25541&view=auto
==============================================================================
--- trunk/src/gui/widgets/label.cpp (added)
+++ trunk/src/gui/widgets/label.cpp Fri Apr 4 18:30:48 2008
@@ -1,0 +1,126 @@
+/* $Id$ */
+/*
+ copyright (c) 2008 by mark de wever <[EMAIL PROTECTED]>
+ part of the battle for wesnoth project http://www.wesnoth.org/
+
+ this program is free software; you can redistribute it and/or modify
+ it under the terms of the gnu general public license version 2
+ or at your option any later version.
+ this program is distributed in the hope that it will be useful,
+ but without any warranty.
+
+ see the copying file for more details.
+*/
+
+#include "gui/widgets/label.hpp"
+
+#include "log.hpp"
+
+#define DBG_G LOG_STREAM(debug, gui)
+#define LOG_G LOG_STREAM(info, gui)
+#define WRN_G LOG_STREAM(warn, gui)
+#define ERR_G LOG_STREAM(err, gui)
+
+#define DBG_G_D LOG_STREAM(debug, gui_draw)
+#define LOG_G_D LOG_STREAM(info, gui_draw)
+#define WRN_G_D LOG_STREAM(warn, gui_draw)
+#define ERR_G_D LOG_STREAM(err, gui_draw)
+
+#define DBG_G_E LOG_STREAM(debug, gui_event)
+#define LOG_G_E LOG_STREAM(info, gui_event)
+#define WRN_G_E LOG_STREAM(warn, gui_event)
+#define ERR_G_E LOG_STREAM(err, gui_event)
+
+#define DBG_G_P LOG_STREAM(debug, gui_parse)
+#define LOG_G_P LOG_STREAM(info, gui_parse)
+#define WRN_G_P LOG_STREAM(warn, gui_parse)
+#define ERR_G_P LOG_STREAM(err, gui_parse)
+
+
+namespace gui2 {
+
+void tlabel::set_width(const unsigned width)
+{
+ // resize canvasses
+ canvas_.set_width(width);
+
+ // inherited
+ tcontrol::set_width(width);
+}
+
+void tlabel::set_height(const unsigned height)
+{
+ // resize canvasses
+ canvas_.set_height(height);
+
+ // inherited
+ tcontrol::set_height(height);
+}
+
+void tlabel::set_label(const t_string& label)
+{
+
+ // set label in canvases
+ canvas_.set_variable("text", variant(label.str()));
+
+ // inherited
+ tcontrol::set_label(label);
+}
+
+tpoint tlabel::get_best_size() const
+{
+ if(definition_ ==
std::vector<tlabel_definition::tresolution>::const_iterator()) {
+ return tpoint(get_label(definition())->default_width,
get_label(definition())->default_height);
+ } else {
+ return tpoint(definition_->default_width,
definition_->default_height);
+ }
+}
+
+void tlabel::mouse_hover(tevent_handler&)
+{
+ DBG_G_E << "Text_box: mouse hover.\n";
+}
+
+void tlabel::draw(surface& canvas)
+{
+ SDL_Rect rect = get_rect();
+
+ DBG_G_D << "Label: drawing enabled state.\n";
+/* if(!restorer_) {
+ restorer_ = get_surface_portion(canvas, rect);
+ }
+ if(definition_->enabled.full_redraw) {
+ SDL_BlitSurface(restorer_, 0, canvas, &rect);
+ rect = get_rect();
+ }
+*/
+ canvas_.draw(true);
+ SDL_BlitSurface(canvas_.surf(), 0, canvas, &rect);
+
+ set_dirty(false);
+}
+
+void tlabel::set_best_size(const tpoint& origin)
+{
+ resolve_definition();
+
+ set_x(origin.x);
+ set_y(origin.y);
+ set_width(definition_->default_width);
+ set_height(definition_->default_height);
+}
+
+void tlabel::resolve_definition()
+{
+ if(definition_ ==
std::vector<tlabel_definition::tresolution>::const_iterator()) {
+ definition_ = get_label(definition());
+
+ canvas_= definition_->enabled.canvas;
+
+ canvas_.set_variable("text", variant(label()));
+ }
+}
+
+} // namespace gui2
+
+
Propchange: trunk/src/gui/widgets/label.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/gui/widgets/label.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: trunk/src/gui/widgets/label.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/label.hpp?rev=25541&view=auto
==============================================================================
--- trunk/src/gui/widgets/label.hpp (added)
+++ trunk/src/gui/widgets/label.hpp Fri Apr 4 18:30:48 2008
@@ -1,0 +1,59 @@
+/* $Id$ */
+/*
+ copyright (c) 2008 by mark de wever <[EMAIL PROTECTED]>
+ part of the battle for wesnoth project http://www.wesnoth.org/
+
+ this program is free software; you can redistribute it and/or modify
+ it under the terms of the gnu general public license version 2
+ or at your option any later version.
+ this program is distributed in the hope that it will be useful,
+ but without any warranty.
+
+ see the copying file for more details.
+*/
+
+#ifndef __GUI_WIDGETS_LABEL_HPP_INCLUDED__
+#define __GUI_WIDGETS_LABEL_HPP_INCLUDED__
+
+#include "gui/widgets/widget.hpp"
+
+#include "gui/widgets/settings.hpp"
+
+namespace gui2 {
+
+class tlabel : public tcontrol
+{
+public:
+
+ tlabel() :
+ tcontrol(),
+ canvas_()
+ {}
+
+ void set_width(const unsigned width);
+
+ void set_height(const unsigned height);
+
+ void set_label(const t_string& label);
+
+ void mouse_hover(tevent_handler&);
+
+ void draw(surface& canvas);
+
+ // note we should check whether the label fits in the label
+ tpoint get_best_size() const;
+
+ void set_best_size(const tpoint& origin);
+private:
+
+ tcanvas canvas_;
+
+ std::vector<tlabel_definition::tresolution>::const_iterator definition_;
+
+ void resolve_definition();
+};
+
+} // namespace gui2
+
+#endif
+
Propchange: trunk/src/gui/widgets/label.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/gui/widgets/label.hpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: trunk/src/gui/widgets/settings.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=25541&r1=25540&r2=25541&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Fri Apr 4 18:30:48 2008
@@ -21,6 +21,7 @@
#include "filesystem.hpp"
#include "gettext.hpp"
#include "gui/widgets/button.hpp"
+#include "gui/widgets/label.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window_builder.hpp"
#include "log.hpp"
@@ -166,6 +167,18 @@
}
VALIDATE(buttons.find("default") != buttons.end(), _ ("No default
button defined."));
+
+ /***** Label definitions *****/
+ const config::child_list& label_cfgs =
cfg.get_children("label_definition");
+ for(std::vector<config*>::const_iterator itor = label_cfgs.begin();
+ itor != label_cfgs.end(); ++itor) {
+
+ std::pair<std::string, tlabel_definition> child;
+ child.first = child.second.read(**itor);
+ labels.insert(child);
+ }
+
+ VALIDATE(labels.find("default") != labels.end(), _ ("No default label
defined."));
/***** Text box definitions *****/
const config::child_list& text_box_cfg =
cfg.get_children("text_box_definition");
@@ -313,6 +326,99 @@
canvas.set_cfg(*draw);
}
+const std::string& tlabel_definition::read(const config& cfg)
+{
+/*WIKI
+ * [label_definition]
+ * The definition of a normal push label.
+ *
+ * id = (string = "") Unique id for this gui (theme).
+ * description = (t_string = "") Unique translatable name for this gui.
+ *
+ * [resolution] The definitions of the label in various
+ * resolutions.
+ * [/label_definition]
+ */
+ id = cfg["id"];
+ description = cfg["description"];
+
+ VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
+ VALIDATE(!description.empty(), missing_mandatory_wml_key("gui",
"description"));
+
+ std::cerr << "Parsing label " << id << '\n';
+
+ const config::child_list& cfgs = cfg.get_children("resolution");
+ VALIDATE(!cfgs.empty(), _("No resolution defined."));
+ for(std::vector<config*>::const_iterator itor = cfgs.begin();
+ itor != cfgs.end(); ++itor) {
+
+ resolutions.push_back(tresolution(**itor));
+ }
+
+ return id;
+}
+
+tlabel_definition::tresolution::tresolution(const config& cfg) :
+ window_width(lexical_cast_default<unsigned>(cfg["window_width"])),
+ window_height(lexical_cast_default<unsigned>(cfg["window_height"])),
+ min_width(lexical_cast_default<unsigned>(cfg["min_width"])),
+ min_height(lexical_cast_default<unsigned>(cfg["min_height"])),
+ default_width(lexical_cast_default<unsigned>(cfg["default_width"])),
+ default_height(lexical_cast_default<unsigned>(cfg["default_height"])),
+ max_width(lexical_cast_default<unsigned>(cfg["max_width"])),
+ max_height(lexical_cast_default<unsigned>(cfg["max_height"])),
+
text_extra_width(lexical_cast_default<unsigned>(cfg["text_extra_width"])),
+
text_extra_height(lexical_cast_default<unsigned>(cfg["text_extra_height"])),
+ text_font_size(lexical_cast_default<unsigned>(cfg["text_font_size"])),
+ enabled(cfg.child("state_enabled"))
+{
+/*WIKI
+ * [resolution]
+ * window_width = (unsigned = 0) Width of the application window.
+ * window_height = (unsigned = 0)
+ * Height of the application window.
+ * min_width = (unsigned = 0) The minimum width of the widget.
+ * min_height = (unsigned = 0) The minimum height of the widget.
+ *
+ * default_width = (unsigned = 0)
+ * The default width of the widget.
+ * default_height = (unsigned = 0)
+ * The default height of the widget.
+ *
+ * max_width = (unsigned = 0) The maximum width of the widget.
+ * max_height = (unsigned = 0) The maximum height of the widget.
+ *
+ * text_extra_width = (unsigned = 0)
+ * The extra width needed to determine the
+ * minimal size for the text.
+ * text_extra_height = (unsigned = 0)
+ * The extra height needed to determine the
+ * minimal size for the text.
+ * text_font_size = (unsigned =0)
+ * The font size, which needs to be used to
+ * determine the minimal size for the text.
+ *
+ * [state_enabled] Settings for the enabled state.
+ * when the mouse moves over the label).
+ *
+ *
+ * [/resolution]
+ */
+
+ std::cerr << "Parsing resolution "
+ << window_width << ", " << window_height << '\n';
+}
+
+tlabel_definition::tresolution::tstate::tstate(const config* cfg) :
+ canvas()
+{
+ const config* draw = cfg ? cfg->child("draw") : 0;
+
+ VALIDATE(draw, _("No state or draw section defined."));
+
+ canvas.set_cfg(*draw);
+}
+
const std::string& ttext_box_definition::read(const config& cfg)
{
/*WIKI
@@ -478,6 +584,34 @@
assert(false);
}
+std::vector<tlabel_definition::tresolution>::const_iterator get_label(const
std::string& definition)
+{
+ std::map<std::string, tlabel_definition>::const_iterator
+ label = current_gui->second.labels.find(definition);
+
+ if(label == current_gui->second.labels.end()) {
+ label = current_gui->second.labels.find("default");
+ assert(label != current_gui->second.labels.end());
+ }
+
+ for(std::vector<tlabel_definition::tresolution>::const_iterator
+ itor = label->second.resolutions.begin(),
+ end = label->second.resolutions.end();
+ itor != end;
+ ++itor) {
+
+ if(screen_width <= itor->window_width &&
+ screen_height <= itor->window_height) {
+
+ return itor;
+ } else if (itor == end - 1) {
+ return itor;
+ }
+ }
+
+ assert(false);
+}
+
std::vector<ttext_box_definition::tresolution>::const_iterator
get_text_box(const std::string& definition)
{
std::map<std::string, ttext_box_definition>::const_iterator
Modified: trunk/src/gui/widgets/settings.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.hpp?rev=25541&r1=25540&r2=25541&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.hpp (original)
+++ trunk/src/gui/widgets/settings.hpp Fri Apr 4 18:30:48 2008
@@ -92,8 +92,9 @@
std::vector<tresolution> resolutions;
};
-struct ttext_box_definition
-{
+struct tlabel_definition
+{
+
std::string id;
t_string description;
@@ -119,6 +120,55 @@
unsigned max_width;
unsigned max_height;
+ unsigned text_extra_width;
+ unsigned text_extra_height;
+ unsigned text_font_size;
+
+ struct tstate
+ {
+ private:
+ tstate();
+
+ public:
+ tstate(const config* cfg);
+
+ tcanvas canvas;
+ };
+
+ tstate enabled;
+
+ };
+
+ std::vector<tresolution> resolutions;
+};
+
+struct ttext_box_definition
+{
+ std::string id;
+ t_string description;
+
+ const std::string& read(const config& cfg);
+
+ struct tresolution
+ {
+ private:
+ tresolution();
+
+ public:
+ tresolution(const config& cfg);
+
+ unsigned window_width;
+ unsigned window_height;
+
+ unsigned min_width;
+ unsigned min_height;
+
+ unsigned default_width;
+ unsigned default_height;
+
+ unsigned max_width;
+ unsigned max_height;
+
struct tstate
{
private:
@@ -193,6 +243,7 @@
const std::string& read(const config& cfg);
std::map<std::string, tbutton_definition> buttons;
+ std::map<std::string, tlabel_definition> labels;
std::map<std::string, ttext_box_definition> text_boxs;
std::map<std::string, twindow_definition> windows;
@@ -200,6 +251,7 @@
};
std::vector<tbutton_definition::tresolution>::const_iterator
get_button(const std::string& definition);
+ std::vector<tlabel_definition::tresolution>::const_iterator
get_label(const std::string& definition);
std::vector<ttext_box_definition::tresolution>::const_iterator
get_text_box(const std::string& definition);
std::vector<twindow_definition::tresolution>::const_iterator
get_window(const std::string& definition);
Modified: trunk/src/gui/widgets/window_builder.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=25541&r1=25540&r2=25541&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Fri Apr 4 18:30:48 2008
@@ -17,6 +17,7 @@
#include "config.hpp"
#include "gettext.hpp"
#include "gui/widgets/button.hpp"
+#include "gui/widgets/label.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/widget.hpp"
@@ -55,6 +56,18 @@
tbuilder_button();
public:
tbuilder_button(const config& cfg) : tbuilder_widget(cfg) {}
+
+ twidget* build () const;
+
+};
+
+struct tbuilder_label : public tbuilder_widget
+{
+
+private:
+ tbuilder_label();
+public:
+ tbuilder_label(const config& cfg) : tbuilder_widget(cfg) {}
twidget* build () const;
@@ -192,6 +205,8 @@
if((**col_itor).child("button")) {
widgets.push_back(new
tbuilder_button(*((**col_itor).child("button"))));
+ } else if((**col_itor).child("label")) {
+ widgets.push_back(new
tbuilder_label(*((**col_itor).child("label"))));
} else if ((**col_itor).child("text_box")) {
widgets.push_back(new
tbuilder_text_box(*((**col_itor).child("text_box"))));
} else {
@@ -239,9 +254,23 @@
button->set_label(label);
DBG_G << "Window builder: placed button '" << id << "' with defintion
'"
- << definition << '\n';
+ << definition << "'.\n";
return button;
+}
+
+twidget* tbuilder_label::build() const
+{
+ tlabel *tmp_label = new tlabel();
+
+ tmp_label->set_definition(id);
+ tmp_label->set_definition(definition);
+ tmp_label->set_label(label);
+
+ DBG_G << "Window builder: placed label '" << id << "' with defintion '"
+ << definition << "'.\n";
+
+ return tmp_label;
}
twidget* tbuilder_text_box::build() const
@@ -253,7 +282,7 @@
text_box->set_label(label);
DBG_G << "Window builder: placed text box '" << id << "' with defintion
'"
- << definition << '\n';
+ << definition << "'.\n";
return text_box;
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits