StaticText.cpp
Go to the documentation of this file.00001 //*** StaticText.cpp ** 00002 00003 #include "StaticText.h" 00004 #include "BitmapStrip.h" 00005 #include "Font.h" 00006 #include "DebugFont.h" 00007 00008 00009 //*** Constructor *** 00010 00011 StaticText::StaticText(): 00012 spacing_(0), 00013 width_(0), 00014 vspacing_(0), 00015 text_(0) 00016 { 00017 } 00018 00019 00020 //*** Constructor *** 00021 00022 StaticText::StaticText(SpriteManager* spriteManager): 00023 Sprite(spriteManager), 00024 spacing_(0), 00025 width_(0), 00026 vspacing_(0), 00027 text_(0) 00028 { 00029 } 00030 00031 00032 //*** Destructor *** 00033 00034 StaticText::~StaticText() 00035 { 00036 if (text_) 00037 { 00038 Free(text_); 00039 } 00040 } 00041 00042 00043 //*** GetFont *** 00044 00045 const Resource_Font& StaticText::GetFont() const 00046 { 00047 return font_; 00048 } 00049 00050 00051 //*** SetFont *** 00052 00053 void StaticText::SetFont(const Resource_Font& font) 00054 { 00055 font_=font; 00056 } 00057 00058 00059 //*** GetText *** 00060 00061 const char* StaticText::GetText() const 00062 { 00063 return text_; 00064 } 00065 00066 00067 //*** SetText *** 00068 00069 void StaticText::SetText(const char* text) 00070 { 00071 if (text_) 00072 { 00073 Free(text_); 00074 text_=0; 00075 } 00076 00077 if (text) 00078 { 00079 text_=StrDup(text); 00080 } 00081 } 00082 00083 00084 //*** GetSpacing *** 00085 00086 int StaticText::GetSpacing() const 00087 { 00088 return spacing_; 00089 } 00090 00091 00092 //*** SetSpacing *** 00093 00094 void StaticText::SetSpacing(int spacing) 00095 { 00096 spacing_=spacing; 00097 } 00098 00099 00100 //*** GetWidth *** 00101 00102 int StaticText::GetWidth() const 00103 { 00104 return width_; 00105 } 00106 00107 00108 //*** GetVSpacing *** 00109 00110 int StaticText::GetVSpacing() const 00111 { 00112 return vspacing_; 00113 } 00114 00115 00116 //*** SetWidth *** 00117 00118 void StaticText::SetWidth(int width, int vspacing) 00119 { 00120 width_=width; 00121 vspacing_=vspacing; 00122 } 00123 00124 00125 //*** Render *** 00126 00127 void StaticText::Render(Bitmap& bitmap) 00128 { 00129 Sprite::Render(bitmap); 00130 00131 if (!IsVisible()) 00132 { 00133 return; 00134 } 00135 00136 if (GetAlpha()==0) 00137 { 00138 return; 00139 } 00140 00141 if (!text_) 00142 { 00143 return; 00144 } 00145 00146 if (font_.GetFont().GetSize()==0) 00147 { 00148 DebugFont font; 00149 font.Blit(bitmap,(int)(GetX()-GetOriginX()),(int)(GetY()-GetOriginY()),GetText(),GetColor()); 00150 return; 00151 } 00152 00153 if (width_==0) 00154 { 00155 font_.Blit(bitmap,(int)(GetX()-GetOriginX()),(int)(GetY()-GetOriginY()),GetText(),GetSpacing(),GetColor(),GetAlpha()); 00156 } 00157 else 00158 { 00159 font_.BlitWrap(bitmap,(int)(GetX()-GetOriginX()),(int)(GetY()-GetOriginY()),GetText(),GetWidth(),GetSpacing(),GetVSpacing(),GetColor(),GetAlpha()); 00160 } 00161 } 00162 00163 00164
Reproduction/republishing of any material on this site without permission is strictly prohibited.
