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
00027
00028
00029 #include "pgcolumnitem.h"
00030
00031 PG_ColumnItem::PG_ColumnItem(PG_Widget* parent, Uint32 columns, Uint16 height, void* userdata, const std::string& style) : PG_ListBoxItem(parent, height, PG_NULLSTR, NULL, NULL, style) {
00032 SetUserData(userdata);
00033 my_columncount = columns;
00034 static PG_String YEmpty;
00035
00036 my_columnwidth.reserve(columns);
00037 my_columntext.reserve(columns);
00038
00039
00040 for(Uint32 i=0; i<my_columncount; i++) {
00041 my_columnwidth.push_back(Width()/my_columncount);
00042 my_columntext.push_back(YEmpty);
00043 }
00044
00045 }
00046
00047 PG_ColumnItem::~PG_ColumnItem() {
00048 my_columnwidth.clear();
00049 my_columntext.clear();
00050 }
00051
00052 void PG_ColumnItem::SetColumnWidth(Uint32 column, Uint32 width) {
00053 my_columnwidth[column] = width;
00054 }
00055
00056 void PG_ColumnItem::SetColumnText(Uint32 column, const std::string& text) {
00057 my_columntext[column] = text;
00058 Update();
00059 }
00060
00061 void PG_ColumnItem::eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst) {
00062 int xshift = 0;
00063
00064 if((dst.my_width == 0) || (dst.my_height == 0)) {
00065 return;
00066 }
00067
00068 PG_ListBoxItem::eventBlit(srf, src, dst);
00069
00070 if(my_srfIcon != NULL) {
00071 xshift = my_srfIcon->w;
00072 }
00073
00074 for(Uint32 i=0; i<my_columncount; i++) {
00075
00076 if(my_columntext[i].empty()) {
00077 xshift += my_columnwidth[i];
00078 continue;
00079 }
00080
00081 Uint16 w, h;
00082 GetTextSize(w, h, my_columntext[i]);
00083
00084 int cw = my_columnwidth[i];
00085 if(xshift + cw > my_width) {
00086 cw -= ((xshift + cw) - my_width);
00087 }
00088 DrawText(xshift, (my_height - h)/2, my_columntext[i], PG_Rect(xshift, 0, cw-5, my_height));
00089 xshift += my_columnwidth[i];
00090 }
00091
00092 }
00093
00094 int PG_ColumnItem::GetColumnWidth(Uint32 column) {
00095 return my_columnwidth[column];
00096 }
00097
00098 const PG_String& PG_ColumnItem::GetColumnText(Uint32 column) {
00099 return my_columntext[column];
00100 }
00101
00102 int PG_ColumnItem::GetColumnCount() {
00103 return my_columncount;
00104 }