gui/widgets/label.hpp

Go to the documentation of this file.
00001 /* $Id: label.hpp 54038 2012-04-30 19:37:24Z mordante $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
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 GUI_WIDGETS_LABEL_HPP_INCLUDED
00017 #define GUI_WIDGETS_LABEL_HPP_INCLUDED
00018 
00019 #include "gui/widgets/control.hpp"
00020 
00021 namespace gui2 {
00022 
00023 /** Label showing a text. */
00024 class tlabel : public tcontrol
00025 {
00026 public:
00027 
00028     tlabel()
00029         : tcontrol(COUNT)
00030         , state_(ENABLED)
00031         , can_wrap_(false)
00032         , characters_per_line_(0)
00033     {
00034     }
00035 
00036     /** Inherited from twidget. */
00037     bool can_wrap() const;
00038 
00039     /** Inherited from tcontrol. */
00040     unsigned get_characters_per_line() const;
00041 
00042     /** Inherited from tcontrol. */
00043     void set_active(const bool active)
00044         { if(get_active() != active) set_state(active ? ENABLED : DISABLED); }
00045 
00046     /** Inherited from tcontrol. */
00047     bool get_active() const { return state_ != DISABLED; }
00048 
00049     /** Inherited from tcontrol. */
00050     unsigned get_state() const { return state_; }
00051 
00052     /** Inherited from tcontrol. */
00053     bool disable_click_dismiss() const { return false; }
00054 
00055     /***** ***** ***** setters / getters for members ***** ****** *****/
00056 
00057     void set_can_wrap(const bool wrap) { can_wrap_ = wrap; }
00058 
00059     void set_characters_per_line(const unsigned set_characters_per_line);
00060 
00061 private:
00062 
00063     /**
00064      * Possible states of the widget.
00065      *
00066      * Note the order of the states must be the same as defined in settings.hpp.
00067      */
00068     enum tstate { ENABLED, DISABLED, COUNT };
00069 
00070     void set_state(const tstate state);
00071 
00072     /**
00073      * Current state of the widget.
00074      *
00075      * The state of the widget determines what to render and how the widget
00076      * reacts to certain 'events'.
00077      */
00078     tstate state_;
00079 
00080     /** Holds the label can wrap or not. */
00081     bool can_wrap_;
00082 
00083     /**
00084      * The maximum number of characters per line.
00085      *
00086      * The maximum is not an exact maximum, it uses the average character width.
00087      */
00088     unsigned characters_per_line_;
00089 
00090     /** Inherited from tcontrol. */
00091     const std::string& get_control_type() const;
00092 };
00093 
00094 } // namespace gui2
00095 
00096 #endif
00097 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:55 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs