WINDEX
guage.h
1 namespace wex {
4 class gauge : public gui
5 {
6 public:
7  gauge( gui* parent )
8  : gui( parent )
9  , myMax( 10 )
10  {
11 
12  }
13  void range( int max )
14  {
15  myMax = max;
16  }
17 
18  void value( double v )
19  {
20  myValue = v;
21  }
22 protected:
23  virtual void draw( PAINTSTRUCT& ps )
24  {
25  int w = ps.rcPaint.right - ps.rcPaint.left;
26  int h = ps.rcPaint.bottom - ps.rcPaint.top;
27  int x0 = ps.rcPaint.left + w / 2;
28  int y0 = ps.rcPaint.top + h / 2;
29  shapes S( ps );
30  S.circle( x0, y0, w / 2 );
31  int inc = myMax / 10;
32  int theta = 30;
33  double r = w;
34  if( h < w )
35  r = h;
36  r *= 0.95;
37  r /= 2;
38  std::cout << "radius " << r << "\n";
39  for( int k = 1; k <= 10; k++ )
40  {
41  theta += 20;
42  double rads = 0.0174533 * theta;
43  int x = x0 - sin( rads ) * r * 0.8;
44  int y = y0 + cos( rads ) * r * 0.8;
45  S.text( std::to_string( k * inc ), { x,y,30,30});
46  S.line( { x, y,
47  (int)(x0 - sin( rads ) * r),
48  (int)(y0 + cos( rads ) * r) });
49 
50  }
51  theta = 30 + 200 * myValue / myMax;
52  double rads = 0.0174533 * theta;
53  S.penThick( 3 );
54  S.color( 0 );
55  S.line( { x0,y0,
56  (int)( x0 - sin( rads ) * r * 0.9),
57  (int)( y0 + cos( rads ) * r * 0.9 )});
58  }
59 private:
60 
61  int myMax;
62  double myValue;
63 };
64 }
65 
Widget to display a value on a circular clock face.
Definition: guage.h:5
The base class for all windex gui elements.
Definition: wex.h:824
gui()
Construct top level window with no parent.
Definition: wex.h:831
A class that offers application code methods to draw on a window.
Definition: wex.h:525
void penThick(int t)
Set pen thickness in pixels.
Definition: wex.h:597
void text(const std::string &t, const std::vector< int > &v)
Draw text.
Definition: wex.h:727
void line(const std::vector< int > &v)
Draw line between two points.
Definition: wex.h:616
void circle(int x0, int y0, double r)
Draw circle.
Definition: wex.h:714
void color(int r, int g, int b)
Set color for drawings.
Definition: wex.h:559