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