00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "elements/CEGUIListboxTextItem.h"
00027 #include "CEGUIFontManager.h"
00028 #include "CEGUIFont.h"
00029 #include "CEGUIWindow.h"
00030 #include "CEGUIImage.h"
00031
00032
00033 namespace CEGUI
00034 {
00035
00036
00037
00038 const colour ListboxTextItem::DefaultTextColour = 0xFFFFFFFF;
00039
00040
00041
00042
00043
00044 ListboxTextItem::ListboxTextItem(const String& text, uint item_id, void* item_data, bool disabled, bool auto_delete) :
00045 ListboxItem(text, item_id, item_data, disabled, auto_delete),
00046 d_textCols(DefaultTextColour, DefaultTextColour, DefaultTextColour, DefaultTextColour),
00047 d_font(NULL)
00048 {
00049 }
00050
00051
00052
00053
00054
00055 const Font* ListboxTextItem::getFont(void) const
00056 {
00057
00058 if (d_font != NULL)
00059 {
00060 return d_font;
00061 }
00062
00063 else if (d_owner != NULL)
00064 {
00065 return d_owner->getFont();
00066 }
00067
00068 else
00069 {
00070 return System::getSingleton().getDefaultFont();
00071 }
00072
00073 }
00074
00075
00076
00077
00078
00079 void ListboxTextItem::setFont(const String& font_name)
00080 {
00081 setFont(FontManager::getSingleton().getFont(font_name));
00082 }
00083
00084
00085
00086
00087 Size ListboxTextItem::getPixelSize(void) const
00088 {
00089 Size tmp(0,0);
00090
00091 const Font* fnt = getFont();
00092
00093 if (fnt != NULL)
00094 {
00095 tmp.d_height = PixelAligned(fnt->getLineSpacing());
00096 tmp.d_width = PixelAligned(fnt->getTextExtent(d_itemText));
00097 }
00098
00099 return tmp;
00100 }
00101
00102
00103
00104
00105
00106 void ListboxTextItem::draw(const Vector3& position, float alpha, const Rect& clipper) const
00107 {
00108 if (d_selected && (d_selectBrush != NULL))
00109 {
00110 d_selectBrush->draw(clipper, position.d_z, clipper, getModulateAlphaColourRect(d_selectCols, alpha));
00111 }
00112
00113 const Font* fnt = getFont();
00114
00115 if (fnt != NULL)
00116 {
00117 Vector3 finalPos(position);
00118 finalPos.d_y -= PixelAligned((fnt->getLineSpacing() - fnt->getBaseline()) * 0.5f);
00119 fnt->drawText(d_itemText, finalPos, clipper, getModulateAlphaColourRect(d_textCols, alpha));
00120 }
00121
00122 }
00123
00124 void ListboxTextItem::draw(RenderCache& cache,const Rect& targetRect, float zBase, float alpha, const Rect* clipper) const
00125 {
00126 if (d_selected && d_selectBrush != 0)
00127 {
00128 cache.cacheImage(*d_selectBrush, targetRect, zBase, getModulateAlphaColourRect(d_selectCols, alpha), clipper);
00129 }
00130
00131 const Font* font = getFont();
00132
00133 if (font)
00134 {
00135 Rect finalPos(targetRect);
00136 finalPos.d_top -= (font->getLineSpacing() - font->getBaseline()) * 0.5f;
00137 cache.cacheText(d_itemText, font, LeftAligned, finalPos, zBase, getModulateAlphaColourRect(d_textCols, alpha), clipper);
00138 }
00139 }
00140
00141
00142
00143
00144
00145 void ListboxTextItem::setTextColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour)
00146 {
00147 d_textCols.d_top_left = top_left_colour;
00148 d_textCols.d_top_right = top_right_colour;
00149 d_textCols.d_bottom_left = bottom_left_colour;
00150 d_textCols.d_bottom_right = bottom_right_colour;
00151 }
00152
00153
00154 }