#include <info_box_line.hpp>
Public Types | |
enum | LineType { NORMAL, NORMAL_LEFT, SMALL, HEADING, REFERENCE, IMAGE } |
Public Member Functions | |
InfoBoxLine (char format_char, const std::string &text) | |
~InfoBoxLine () | |
void | draw (DrawingContext &context, const Rectf &bbox, int layer) |
float | get_height () |
Static Public Member Functions | |
static const std::vector< InfoBoxLine * > | split (const std::string &text, float width) |
Private Member Functions | |
InfoBoxLine (const InfoBoxLine &) | |
InfoBoxLine & | operator= (const InfoBoxLine &) |
Private Attributes | |
InfoBoxLine::LineType | lineType |
FontPtr | font |
Color | color |
std::string | text |
SurfacePtr | image |
Definition at line 34 of file info_box_line.hpp.
InfoBoxLine::InfoBoxLine | ( | char | format_char, | |
const std::string & | text | |||
) |
Definition at line 104 of file info_box_line.cpp.
References color, Surface::create(), font, get_color_by_format_char(), get_font_by_format_char(), get_linetype_by_format_char(), image, IMAGE, and lineType.
Referenced by split().
00104 : 00105 lineType(NORMAL), 00106 font(Resources::normal_font), 00107 color(), 00108 text(text), 00109 image() 00110 { 00111 font = get_font_by_format_char(format_char); 00112 lineType = get_linetype_by_format_char(format_char); 00113 color = get_color_by_format_char(format_char); 00114 if (lineType == IMAGE) 00115 { 00116 image = Surface::create(text); 00117 } 00118 }
InfoBoxLine::~InfoBoxLine | ( | ) |
InfoBoxLine::InfoBoxLine | ( | const InfoBoxLine & | ) | [private] |
void InfoBoxLine::draw | ( | DrawingContext & | context, | |
const Rectf & | bbox, | |||
int | layer | |||
) |
Definition at line 172 of file info_box_line.cpp.
References ALIGN_CENTER, ALIGN_LEFT, color, DrawingContext::draw_surface(), DrawingContext::draw_text(), font, image, IMAGE, lineType, NORMAL_LEFT, Rectf::p1, Rectf::p2, text, Vector::x, and Vector::y.
00173 { 00174 Vector position = bbox.p1; 00175 switch (lineType) { 00176 case IMAGE: 00177 context.draw_surface(image, Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer); 00178 break; 00179 case NORMAL_LEFT: 00180 context.draw_text(font, text, Vector(position.x, position.y), ALIGN_LEFT, layer, color); 00181 break; 00182 default: 00183 context.draw_text(font, text, Vector((bbox.p1.x + bbox.p2.x) / 2, position.y), ALIGN_CENTER, layer, color); 00184 break; 00185 } 00186 }
float InfoBoxLine::get_height | ( | ) |
Definition at line 189 of file info_box_line.cpp.
References font, image, IMAGE, ITEMS_SPACE, lineType, and NORMAL_LEFT.
00190 { 00191 switch (lineType) { 00192 case IMAGE: 00193 return image->get_height() + ITEMS_SPACE; 00194 case NORMAL_LEFT: 00195 return font->get_height() + ITEMS_SPACE; 00196 default: 00197 return font->get_height() + ITEMS_SPACE; 00198 } 00199 }
const std::vector< InfoBoxLine * > InfoBoxLine::split | ( | const std::string & | text, | |
float | width | |||
) | [static] |
Definition at line 125 of file info_box_line.cpp.
References font, get_font_by_format_char(), and InfoBoxLine().
Referenced by InfoBlock::InfoBlock(), InfoBox::InfoBox(), and TextScroller::TextScroller().
00126 { 00127 std::vector<InfoBoxLine*> lines; 00128 00129 std::string::size_type i = 0; 00130 std::string::size_type l; 00131 char format_char = '#'; 00132 while(i < text.size()) { 00133 // take care of empty lines - represent them as blank lines of normal text 00134 if (text[i] == '\n') { 00135 lines.push_back(new InfoBoxLine('\t', "")); 00136 i++; 00137 continue; 00138 } 00139 00140 // extract the format_char 00141 format_char = text[i]; 00142 i++; 00143 if (i >= text.size()) break; 00144 00145 // extract one line 00146 l = text.find("\n", i); 00147 if (l == std::string::npos) l=text.size(); 00148 std::string s = text.substr(i, l-i); 00149 i = l+1; 00150 00151 // if we are dealing with an image, just store the line 00152 if (format_char == '!') { 00153 lines.push_back(new InfoBoxLine(format_char, s)); 00154 continue; 00155 } 00156 00157 // append wrapped parts of line into list 00158 std::string overflow; 00159 do { 00160 FontPtr font = get_font_by_format_char(format_char); 00161 std::string s2 = s; 00162 if (font) s2 = font->wrap_to_width(s2, width, &overflow); 00163 lines.push_back(new InfoBoxLine(format_char, s2)); 00164 s = overflow; 00165 } while (s.length() > 0); 00166 } 00167 00168 return lines; 00169 }
InfoBoxLine& InfoBoxLine::operator= | ( | const InfoBoxLine & | ) | [private] |
InfoBoxLine::LineType InfoBoxLine::lineType [private] |
Definition at line 48 of file info_box_line.hpp.
Referenced by draw(), get_height(), and InfoBoxLine().
FontPtr InfoBoxLine::font [private] |
Definition at line 49 of file info_box_line.hpp.
Referenced by draw(), get_height(), InfoBoxLine(), and split().
Color InfoBoxLine::color [private] |
std::string InfoBoxLine::text [private] |
SurfacePtr InfoBoxLine::image [private] |
Definition at line 52 of file info_box_line.hpp.
Referenced by draw(), get_height(), and InfoBoxLine().