00001
00002
00003
00004
00005
00006
00007 #include "QFont.h"
00008
00009 #include <math.h>
00010 #include <iostream>
00011 using namespace std;
00012
00013
00014 #include <GL/glut.h>
00015 #include "DrawText.h"
00016
00017
00018
00019 void QFont::draw( const char* aText , int maxLength )
00020 {
00021 glPushMatrix();
00022 drawInternal(aText, maxLength);
00023 glPopMatrix();
00024 }
00025
00026
00027 void QFont::drawInternal( const char* aText , int maxLength )
00028 {
00029 Color->setAsCurrent();
00030
00031 glScalef (Size / 16.0, Size / 16.0, 1.0);
00032
00033 TEXTDRAWER.PrintText(Bold,maxLength, aText);
00034 }
00035
00036
00037 void QFont::drawAtPos( const char* aText , int x , int y , int maxLength )
00038 {
00039 glPushMatrix();
00040 glTranslatef(x,y,0);
00041 drawInternal(aText,maxLength);
00042 glPopMatrix();
00043 }
00044
00045
00046 float QFont::getTextWidth( const char* aText )
00047 {
00048 return strlen(aText) * 12.0 * Size / 16.0;
00049
00050 }
00051
00052
00053 int QFont::getLengthForWidth( const char* aText , int aWidth )
00054 {
00055 unsigned int maxlen = (unsigned int)(ceil(aWidth * 16.0 / (Size * 12.0)));
00056
00057 if (maxlen < strlen(aText)) return maxlen;
00058 else
00059 return strlen(aText);
00060
00061 }
00062
00063
00064 void QFont::Init()
00065 {
00066
00067 }
00068
00069
00070 void QFont::CleanUp()
00071 {
00072
00073 }
00074
00075
00076 int QFont::getSize()
00077 {
00078 return Size;
00079 }
00080
00081
00082 void QFont::setSize( int newValue )
00083 {
00084 Size = newValue;
00085 }
00086
00087
00088 bool QFont::getBold()
00089 {
00090 return Bold;
00091 }
00092
00093
00094 void QFont::setBold( bool newValue )
00095 {
00096 Bold = newValue;
00097 }
00098
00099
00100 QColor* QFont::getColor()
00101 {
00102 return Color;
00103 }
00104
00105
00106
00107
00108 void QFont::copyFrom( QFont* from )
00109 {
00110 setSize(from->getSize());
00111 setBold(from->getBold());
00112 Color->copyFrom(from->getColor());
00113 }
00114
00115
00116
00117
00118 void QFont::print()
00119 {
00120 cout << "Class : QFont" << endl;
00121 cout << "Size = " << Size << endl;
00122 cout << "Bold = " << Bold << endl;
00123 }
00124
00125
00126
00127
00128 QFont::QFont( )
00129 {
00130 Bold = false;
00131 Color = new QColor;
00132 Init();
00133 }
00134
00135
00136
00137
00138 QFont::~QFont()
00139 {
00140 delete Color;
00141 CleanUp();
00142 }
00143
00144
00145
00146