00001
00002
00003
00004
00005
00006
00007
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
00044
00045
00046
00047
00048
00049
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