Advanced Strategic Command
bargraphwidget.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 #include "bargraphwidget.h"
12 
13 #include <pgapplication.h>
14 
15 BarGraphWidget:: BarGraphWidget (PG_Widget *parent, const PG_Rect &rect, Direction direction ) : PG_ThemeWidget( parent, rect, false ), fraction(1), dir(direction)
16 {
17 }
18 
19 void BarGraphWidget::eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
20 {
21  PG_Rect d = dst;
22  if ( dir == l2r ) {
23  d.w = min( max(0, int( float(dst.w) * fraction)), int(dst.w)) ;
24  }
25  if ( dir == r2l ) {
26  int x2 = d.x + d.w;
27  d.w = min( max(0, int( float(dst.w) * fraction)), int(dst.w)) ;
28  d.x = x2 - d.w;
29  }
30  if ( dir == t2b ) {
31  d.h = min( max(0, int( float(dst.h) * fraction)), int(dst.h)) ;
32  }
33  if ( dir == b2t ) {
34  int y2 = d.y + d.h;
35  d.h = min( max(0, int( float(dst.h) * fraction)), int(dst.h)) ;
36  d.y = y2 - d.h;
37  }
38 
39  if ( d.h <= 0 || d.w <= 0 )
40  return;
41 
42 
43 /* PG_Draw::DrawThemedSurface(
44  surface,
45  d,
46  my_has_gradient ? &my_gradient : 0,
47  my_background,
48  my_backgroundMode,
49  my_blendLevel );
50  */
51 
52  Uint32 c = color.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
53  for ( Colors::iterator i = colors.begin(); i != colors.end(); ++i)
54  if ( fraction < i->first ) {
55  PG_Color col = i->second;
56  c = col.MapRGBA( PG_Application::GetScreen()->format, 255-GetTransparency());
57  }
58 
59  SDL_FillRect(PG_Application::GetScreen(), &d, c);
60 
61 }
62 
63 
65 {
66  fraction = f;
67 }
68 
69 
void eventBlit(SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
BarGraphWidget(PG_Widget *parent, const PG_Rect &rect, Direction direction)
void setFraction(float f)
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80