Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgcolumnitem.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:16:03 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgcolumnitem.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
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         // fill our vectors with the default values
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 }

Generated on Tue Jun 24 01:27:47 2008 for Advanced Strategic Command by  doxygen 1.4.2