widgets/label.cpp

Go to the documentation of this file.
00001 /* $Id: label.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2004 - 2012 by Philippe Plantier <ayin@anathas.org>
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 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "global.hpp"
00019 
00020 #include "widgets/label.hpp"
00021 #include "marked-up_text.hpp"
00022 
00023 namespace gui {
00024 
00025 label::label(CVideo& video, const std::string& text, int size, const SDL_Color& color, const bool auto_join) : widget(video, auto_join), text_(text), size_(size), color_(color)
00026 {
00027     update_label_size();
00028 }
00029 
00030 const std::string& label::set_text(const std::string& text)
00031 {
00032     if (text_ == text)
00033         return text_;
00034 
00035     text_ = text;
00036     update_label_size();
00037     set_dirty();
00038     return text_;
00039 }
00040 
00041 const std::string& label::get_text() const
00042 {
00043     return text_;
00044 }
00045 
00046 const SDL_Color& label::set_color(const SDL_Color& color)
00047 {
00048     color_ = color;
00049     set_dirty();
00050     return get_color();
00051 }
00052 
00053 const SDL_Color& label::get_color() const
00054 {
00055     return (enabled()) ? color_ : font::DISABLED_COLOR;
00056 }
00057 
00058 void label::draw_contents()
00059 {
00060     const SDL_Rect& loc = location();
00061     if (!text_.empty() && loc.w > 0 && loc.h > 0)
00062         font::draw_text(&video(), loc, size_, get_color(), text_, loc.x, loc.y);
00063 }
00064 
00065 void label::update_label_size()
00066 {
00067     SDL_Rect area = font::text_area(text_, size_);
00068     set_measurements(area.w, area.h);
00069 }
00070 
00071 
00072 }
 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