00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (C) 2010 Sacha Schutz <istdasklar@free.fr> 00004 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include "textrenderercomponent.h" 00022 00023 #include <graphics/textitem.h> 00024 #include <gameobject.h> 00025 #include <graphics/meshes/polygonmesh.h> 00026 00027 #include <QMessageBox> 00028 REGISTER_OBJECTTYPE( GluonEngine, TextRendererComponent ) 00029 00030 using namespace GluonEngine; 00031 00032 class TextRendererComponent::TextRendererComponentPrivate 00033 { 00034 public: 00035 TextRendererComponentPrivate() 00036 { 00037 textItem = 0; 00038 text = "empty"; 00039 } 00040 00041 QString text; 00042 QFont font; 00043 QColor color; 00044 GluonGraphics::TextItem* textItem; 00045 }; 00046 00047 00048 TextRendererComponent::TextRendererComponent( QObject* parent ) 00049 : Component( parent ) 00050 , d( new TextRendererComponentPrivate ) 00051 { 00052 } 00053 00054 TextRendererComponent::~TextRendererComponent() 00055 { 00056 delete d; 00057 } 00058 00059 QString TextRendererComponent::category() const 00060 { 00061 return QString( "Graphics Rendering" ); 00062 } 00063 00064 QString TextRendererComponent::text() const 00065 { 00066 return d->text; 00067 } 00068 00069 void TextRendererComponent::setText( const QString& text ) 00070 { 00071 d->text = text; 00072 if( d->textItem ) 00073 d->textItem->setText( text ); 00074 } 00075 00076 QFont TextRendererComponent::font() const 00077 { 00078 return d->font; 00079 } 00080 00081 void TextRendererComponent::setFont( const QFont& font ) 00082 { 00083 d->font = font; 00084 if( d->textItem ) 00085 d->textItem->setFont( font ); 00086 } 00087 00088 QColor TextRendererComponent::color() const 00089 { 00090 return d->color; 00091 } 00092 00093 void TextRendererComponent::setColor( const QColor& color ) 00094 { 00095 d->color = color; 00096 if( d->textItem ) 00097 d->textItem->setColor( color ); 00098 } 00099 00100 void TextRendererComponent::initialize() 00101 { 00102 d->textItem = new GluonGraphics::TextItem( d->text, d->font ); 00103 } 00104 00105 void TextRendererComponent::start() 00106 { 00107 d->textItem->setColor( d->color ); 00108 } 00109 00110 void TextRendererComponent::draw( int timeLapse ) 00111 { 00112 if( d->textItem ) 00113 d->textItem->setMatrix( gameObject()->transform() ); 00114 } 00115 00116 void TextRendererComponent::cleanup() 00117 { 00118 delete d->textItem; 00119 d->textItem = 0; 00120 } 00121 00122 Q_EXPORT_PLUGIN2( gluon_component_textrenderer, GluonEngine::TextRendererComponent ); 00123 00124 #include "textrenderercomponent.moc"