TextWindow.cpp
Go to the documentation of this file.00001 //*** TextWindow.cpp ** 00002 00003 #include "TextWindow.h" 00004 #include "BitmapStrip.h" 00005 #include "Bitmap_16bit.h" 00006 #include "ColorHelper.h" 00007 00008 //*** Constructor *** 00009 00010 TextWindow::TextWindow(): 00011 width_(100), 00012 height_(100), 00013 windowBitmap_(0), 00014 redraw_(true), 00015 currentHighlightOption_(0), 00016 currentHighlightLink_(0), 00017 backgroundColor_(0xffff), 00018 borderColor_(0), 00019 borderSize_(2), 00020 padding_(7) 00021 { 00022 } 00023 00024 00025 //*** Constructor *** 00026 00027 TextWindow::TextWindow(SpriteManager* spriteManager): 00028 Sprite(spriteManager), 00029 width_(100), 00030 height_(100), 00031 windowBitmap_(0), 00032 redraw_(true), 00033 currentHighlightOption_(0), 00034 currentHighlightLink_(0), 00035 backgroundColor_(0xffff), 00036 borderColor_(0), 00037 borderSize_(2), 00038 padding_(7) 00039 { 00040 } 00041 00042 00043 //*** Destructor *** 00044 00045 TextWindow::~TextWindow() 00046 { 00047 if (windowBitmap_) 00048 { 00049 delete windowBitmap_; 00050 windowBitmap_=0; 00051 } 00052 } 00053 00054 00055 //*** SetText *** 00056 00057 void TextWindow::SetText(const char* pmlString) 00058 { 00059 content_.SetString(pmlString); 00060 redraw_=true; 00061 } 00062 00063 00064 //*** AddText *** 00065 00066 void TextWindow::AddText(const char* pmlString) 00067 { 00068 content_.AddString(pmlString); 00069 redraw_=true; 00070 } 00071 00072 00073 //*** GetText *** 00074 00075 const char* TextWindow::GetText() const 00076 { 00077 return content_.GetString(); 00078 } 00079 00080 00081 //*** SetSize *** 00082 00083 void TextWindow::SetSize(float width, float height) 00084 { 00085 if (width==width_ && height==height_) 00086 { 00087 return; 00088 } 00089 width_=width; 00090 height_=height; 00091 if (windowBitmap_) 00092 { 00093 delete windowBitmap_; 00094 windowBitmap_=0; 00095 } 00096 redraw_=true; 00097 } 00098 00099 00100 //*** SetWidth *** 00101 00102 void TextWindow::SetWidth(float width) 00103 { 00104 if (width==width_) 00105 { 00106 return; 00107 } 00108 width_=width; 00109 if (windowBitmap_) 00110 { 00111 delete windowBitmap_; 00112 windowBitmap_=0; 00113 } 00114 redraw_=true; 00115 } 00116 00117 00118 //*** SetHeight *** 00119 00120 void TextWindow::SetHeight(float height) 00121 { 00122 if (height==height_) 00123 { 00124 return; 00125 } 00126 height_=height; 00127 if (windowBitmap_) 00128 { 00129 delete windowBitmap_; 00130 windowBitmap_=0; 00131 } 00132 redraw_=true; 00133 } 00134 00135 00136 //*** GetWidth *** 00137 00138 float TextWindow::GetWidth() const 00139 { 00140 return width_; 00141 } 00142 00143 00144 //*** GetHeight *** 00145 00146 float TextWindow::GetHeight() const 00147 { 00148 return height_; 00149 } 00150 00151 00152 //*** SetBackgroundColor *** 00153 00154 void TextWindow::SetBackgroundColor(unsigned short color) 00155 { 00156 backgroundColor_=color; 00157 redraw_=true; 00158 } 00159 00160 00161 00162 //*** GetBackgroundColor *** 00163 00164 unsigned short TextWindow::GetBackgroundColor() const 00165 { 00166 return backgroundColor_; 00167 } 00168 00169 00170 //*** SetBorderColor *** 00171 00172 void TextWindow::SetBorderColor(unsigned short color) 00173 { 00174 borderColor_=color; 00175 } 00176 00177 00178 //*** GetBorderColor *** 00179 00180 unsigned short TextWindow::GetBorderColor() const 00181 { 00182 return borderColor_; 00183 } 00184 00185 00186 //*** SetBorderSize *** 00187 00188 void TextWindow::SetBorderSize(float size) 00189 { 00190 borderSize_=size; 00191 redraw_=true; 00192 } 00193 00194 00195 //*** GetBorderSize *** 00196 00197 float TextWindow::GetBorderSize() const 00198 { 00199 return borderSize_; 00200 } 00201 00202 00203 //*** SetPadding *** 00204 00205 void TextWindow::SetPadding(float size) 00206 { 00207 padding_=size; 00208 redraw_=true; 00209 } 00210 00211 00212 //*** GetPadding *** 00213 00214 float TextWindow::GetPadding() const 00215 { 00216 return padding_; 00217 } 00218 00219 00220 //*** Render *** 00221 00222 void TextWindow::Render(Bitmap& bitmap) 00223 { 00224 Sprite::Render(bitmap); 00225 00226 if (!IsVisible()) 00227 { 00228 return; 00229 } 00230 00231 if (GetAlpha()==0) 00232 { 00233 return; 00234 } 00235 00236 if (!windowBitmap_) 00237 { 00238 windowBitmap_=new Bitmap_16bit((int)width_,(int)height_); 00239 windowBitmap_->Fill(backgroundColor_); 00240 } 00241 00242 if (redraw_) 00243 { 00244 int bs=(int)borderSize_; 00245 int pd=(int)padding_; 00246 int x1=bs+pd; 00247 int y1=bs+pd; 00248 int x2=windowBitmap_->GetWidth()-bs-pd; 00249 int y2=windowBitmap_->GetHeight()-bs-1-pd; 00250 content_.Render(*windowBitmap_,x1,y1,x2,y2,0,0); 00251 redraw_=false; 00252 } 00253 00254 int x1=(int)GetX(); 00255 int y1=(int)GetY(); 00256 int x2=(int)(GetX()+width_)-1; 00257 int y2=(int)(GetY()+height_)-1; 00258 int bs=(int)borderSize_; 00259 00260 if (windowBitmap_) 00261 { 00262 windowBitmap_->Blit(bs,bs,((int)width_)-1-bs,((int)height_)-1-bs,bitmap,x1+bs,y1+bs,GetColor(),GetAlpha()); 00263 } 00264 else 00265 { 00266 bitmap.Fill(x1+bs,y1+bs,x2-bs,y2-bs,RGBModulate16(backgroundColor_,GetColor()),GetAlpha()); 00267 } 00268 if (bs>0) 00269 { 00270 bitmap.Fill(x1,y1,x2,y1+bs-1,RGBModulate16(borderColor_,GetColor()),GetAlpha()); 00271 bitmap.Fill(x1,y2-(bs-1),x2,y2,RGBModulate16(borderColor_,GetColor()),GetAlpha()); 00272 bitmap.Fill(x1,y1,x1+bs-1,y2,RGBModulate16(borderColor_,GetColor()),GetAlpha()); 00273 bitmap.Fill(x2-(bs-1),y1,x2,y2,RGBModulate16(borderColor_,GetColor()),GetAlpha()); 00274 } 00275 } 00276 00277
Reproduction/republishing of any material on this site without permission is strictly prohibited.
