label.cpp

Go to the documentation of this file.
00001 /* $Id: label.cpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2004 - 2008 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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 #include "global.hpp"
00016 
00017 #include "widgets/label.hpp"
00018 #include "marked-up_text.hpp"
00019 #include "video.hpp"
00020 
00021 namespace gui {
00022 
00023 label::label(CVideo& video, const std::string& text, int size, const SDL_Color& colour, const bool auto_join) : widget(video, auto_join), text_(text), size_(size), colour_(colour)
00024 {
00025     update_label_size();
00026 }
00027 
00028 const std::string& label::set_text(const std::string& text)
00029 {
00030     if (text_ == text)
00031         return text_;
00032 
00033     text_ = text;
00034     update_label_size();
00035     set_dirty();
00036     return text_;
00037 }
00038 
00039 const std::string& label::get_text() const
00040 {
00041     return text_;
00042 }
00043 
00044 int label::set_size(int size)
00045 {
00046     size_ = size;
00047     update_label_size();
00048     set_dirty();
00049     return size_;
00050 }
00051 
00052 int label::get_size() const
00053 {
00054     return size_;
00055 }
00056 
00057 const SDL_Color& label::set_colour(const SDL_Color& colour)
00058 {
00059     colour_ = colour;
00060     set_dirty();
00061     return get_colour();
00062 }
00063 
00064 const SDL_Color& label::get_colour() const
00065 {
00066     return (enabled()) ? colour_ : font::DISABLED_COLOUR;
00067 }
00068 
00069 void label::draw_contents()
00070 {
00071     font::draw_text(&video(), location(), size_, get_colour(), text_, location().x, location().y);
00072 }
00073 
00074 void label::update_label_size()
00075 {
00076     SDL_Rect area = font::text_area(text_, size_);
00077     set_measurements(area.w, area.h);
00078 }
00079 
00080 
00081 }

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs