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

bargraphwidget.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 #include "bargraphwidget.h"
00012 
00013 #include <pgapplication.h>
00014 
00015 BarGraphWidget:: BarGraphWidget (PG_Widget *parent, const PG_Rect &rect, Direction direction ) : PG_ThemeWidget( parent, rect, false ), fraction(1), dir(direction)
00016 {
00017 }
00018 
00019 void BarGraphWidget::eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
00020 {
00021    PG_Rect d = dst;
00022    if ( dir == l2r ) {
00023       d.w = min( max(0, int( float(dst.w) * fraction)), int(dst.w)) ;
00024    }
00025    if ( dir == r2l ) {
00026       int x2 = d.x + d.w;
00027       d.w = min( max(0, int( float(dst.w) * fraction)), int(dst.w)) ;
00028       d.x = x2 - d.w;
00029    }
00030    if ( dir == t2b ) {
00031       d.h = min( max(0, int( float(dst.h) * fraction)), int(dst.h)) ;
00032    }
00033    if ( dir == b2t ) {
00034       int y2 = d.y + d.h;
00035       d.h = min( max(0, int( float(dst.h) * fraction)), int(dst.h)) ;
00036       d.y = y2 - d.h;
00037    }
00038 
00039    if ( d.h <= 0 || d.w <= 0 )
00040       return;
00041 
00042 
00043 /*   PG_Draw::DrawThemedSurface(
00044    surface,
00045    d,
00046    my_has_gradient ? &my_gradient : 0,
00047    my_background,
00048    my_backgroundMode,
00049    my_blendLevel );
00050           */
00051 
00052    Uint32 c = color.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
00053    for ( Colors::iterator i = colors.begin(); i != colors.end(); ++i)
00054       if ( fraction < i->first ) {
00055       PG_Color col = i->second;
00056       c = col.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
00057       }
00058 
00059 
00060       SDL_FillRect(PG_Application::GetScreen(), &d, c);
00061 
00062 }
00063 
00064 
00065 void BarGraphWidget::setFraction( float f )
00066 {
00067    fraction = f;
00068 }
00069 
00070 

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