Back to index

extremetuxracer  0.5beta
label.cpp
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2005 Volker Stroebel <volker@planetpenguin.de>
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019  
00020 #include "label.h"
00021 
00022 namespace pp {
00023 
00024 Label::Label( pp::Vec2d pos, const char *binding, const char *text )
00025  : mp_insensitiveFont(NULL),
00026    m_text(text)
00027 {
00028        m_position = pos;
00029        mp_font = pp::Font::get(binding);
00030 
00031        if(mp_font){
00032               m_size.x = mp_font->advance(text);
00033               m_size.y = mp_font->ascender();    
00034        }
00035 }
00036 
00037 void
00038 Label::setText(const char* text)
00039 {
00040        m_text=text;
00041        if(mp_font){
00042               m_size.x = mp_font->advance(text);
00043        }
00044 }
00045 
00046 void
00047 Label::setInsensitiveFont(const char* binding)
00048 {
00049        mp_insensitiveFont = pp::Font::get(binding);     
00050 }
00051        
00052 void
00053 Label::draw()
00054 {
00055        pp::Font *font = mp_font;
00056        
00057        if(!m_sensitive && mp_insensitiveFont){
00058               font = mp_insensitiveFont;
00059        }
00060        
00061        if(font){
00062               pp::Vec2d pos = alignment.alignPosition(m_position,m_size);
00063               font->draw(m_text.c_str(),pos);           
00064        }
00065 }
00066        
00067 } //namespace pp