00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "Renderer.h"
00018 #include "TextPrimitive.h"
00019 #include "State.h"
00020
00021 using namespace Fluxus;
00022
00023 TextPrimitive::TextPrimitive(float charw, float charh, int charstride, int wrapchars) :
00024 PolyPrimitive(PolyPrimitive::QUADS),
00025 m_CharWidth(charw),
00026 m_CharHeight(charh),
00027 m_CharStride(charstride),
00028 m_WrapChars(wrapchars)
00029 {
00030 }
00031
00032 TextPrimitive::TextPrimitive(const TextPrimitive &other) :
00033 PolyPrimitive(other),
00034 m_CharWidth(other.m_CharWidth),
00035 m_CharHeight(other.m_CharHeight),
00036 m_CharStride(other.m_CharStride),
00037 m_TextWidth(other.m_TextWidth),
00038 m_TextHeight(other.m_TextHeight),
00039 m_WrapChars(other.m_WrapChars)
00040 {
00041 }
00042
00043 TextPrimitive* TextPrimitive::Clone() const
00044 {
00045 return new TextPrimitive(*this);
00046 }
00047
00048 void TextPrimitive::SetText(const string &s, float Width, float Height, float Zoom)
00049 {
00050 float x=0,y=0;
00051 dVector Normal(0,0,1);
00052
00053 float w=m_CharWidth*Width;
00054 float h=m_CharHeight*Height;
00055
00056 m_TextWidth=w*s.size();
00057 m_TextHeight=h;
00058 int wrapcount=0;
00059
00060 w-=Zoom*50;
00061
00062
00063 for (unsigned int n=0; n<s.size(); n++)
00064 {
00065 int pos=(int)s[n];
00066
00067 float S=(pos%m_CharStride)*m_CharWidth;
00068 float T=(pos/m_CharStride)*m_CharHeight;
00069
00070 dVector min(S,T,0);
00071 dVector max(S+m_CharWidth,T+m_CharHeight,0);
00072
00073 min.x+=Zoom;
00074 max.x-=Zoom;
00075
00076 AddVertex(dVertex(dVector(x,y,0),Normal,min.x,min.y));
00077 AddVertex(dVertex(dVector(x+w,y,0),Normal,max.x,min.y));
00078 AddVertex(dVertex(dVector(x+w,y+h,0),Normal,max.x,max.y));
00079 AddVertex(dVertex(dVector(x,y+h,0),Normal,min.x,max.y));
00080 if (m_WrapChars) wrapcount++;
00081
00082 if (s[n]=='\n' || (m_WrapChars && wrapcount>m_WrapChars))
00083 {
00084 y+=h;
00085 m_TextHeight+=h;
00086 x=0;
00087 wrapcount=0;
00088 }
00089 else
00090 {
00091 x+=w;
00092 }
00093 }
00094 }
00095
00096 void TextPrimitive::Render()
00097 {
00098 glDisable(GL_CULL_FACE);
00099 PolyPrimitive::Render();
00100 glEnable(GL_CULL_FACE);
00101 }
00102
00103 istream &Fluxus::operator>>(istream &s, TextPrimitive &o)
00104 {
00105 return s;
00106 }
00107
00108 ostream &Fluxus::operator<<(ostream &s, TextPrimitive &o)
00109 {
00110 return s;
00111 }