proj home

Files   Classes   Functions   Hierarchy  

buttonpanel02 Class Reference

Display a panel of 4 buttons. More...

#include <buttonpanel02.h>

Inheritance diagram for buttonpanel02:
Collaboration diagram for buttonpanel02:

List of all members.

Public Member Functions

void update ()
 Convert the ratio values to screen coordinate variables.
point2< int > centerpos (uintc i) const
 Get button's center position.
 buttonpanel02 (zprmouse *zm_)
 Constructor.
void draw ()
 Draw buttons.
void process (bool &isclicked, uint &index, point2< int > const &p)
 Test if a button was clicked.
void drawcircle (point2< int > const &c, point3< uint > const &color) const
 Draws circle at screen coordinates.

Public Attributes

point2< double > ratio_center
 Center as a ratio.
double ratio_centerdelta
 Relative to x-axis.
double ratio_radius
 Radius of button as a ratio.
point2< int > center
 Center of button panel in screen coordinates.
int centerdelta
 Offset from center for buttons.
double radius
 The button's radius in pixels.
point3< uintcolor [4]
 Color corresponds with position.
zprmousezm
 Conversion programs.


Detailed Description

Display a panel of 4 buttons.

In 2D screen coordinate space.

The buttons are defined in an order where 0 is top, right is 1, down is 2, left is 3.

Definition at line 16 of file buttonpanel02.h.


Constructor & Destructor Documentation

buttonpanel02::buttonpanel02 ( zprmouse zm_  ) 

Constructor.

Definition at line 4 of file buttonpanel02.cpp.

References color, ratio_center, ratio_centerdelta, ratio_radius, and update().

00005   : zm(zm_)
00006 {
00007   ratio_center = point2<double>(0.9,0.8);
00008   ratio_centerdelta = 0.012;
00009   ratio_radius = 0.008;
00010 
00011 /*
00012   color[0] = point3<uint>(239,151,255);
00013   color[1] = point3<uint>(127,255,0);
00014   color[2] = point3<uint>(240,192,10);
00015   color[3] = point3<uint>(239,254,240);
00016 */
00017   color[0] = point3<uint>(255,0,0);
00018   color[1] = point3<uint>(0,255,0);
00019   color[2] = point3<uint>(0,0,255);
00020   color[3] = point3<uint>(127,127,127);
00021 
00022   update();
00023 }


Member Function Documentation

point2< int > buttonpanel02::centerpos ( uintc  i  )  const

Get button's center position.

Definition at line 158 of file buttonpanel02.cpp.

References center, centerdelta, point2< T >::x, and point2< T >::y.

Referenced by draw().

00159 {
00160   assert(i<4);
00161 
00162   if (i==0)
00163     return point2<int>(center.x,center.y-centerdelta);
00164   if (i==1)
00165     return point2<int>(center.x+centerdelta,center.y);
00166   if (i==2)
00167     return point2<int>(center.x,center.y+centerdelta);
00168 
00169   return point2<int>(center.x-centerdelta,center.y);
00170 }

void buttonpanel02::draw (  )  [virtual]

Draw buttons.

Implements gobj.

Definition at line 118 of file buttonpanel02.cpp.

References centerpos(), drawcircle(), zpr::height, zpr::width, zm, and zprmouse::zz.

00119 {
00120   assert(zm);
00121 
00122   // Code taken from tutorial
00123   //   http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL
00124 
00125   glMatrixMode(GL_PROJECTION);
00126   glPushMatrix();
00127   glLoadIdentity();
00128   glOrtho(0,zm->zz.width,zm->zz.height,0,0,1);
00129   glDisable(GL_DEPTH_TEST);
00130   glMatrixMode(GL_MODELVIEW);
00131   glPushMatrix();
00132   glLoadIdentity();
00133   glTranslatef(0.375,0.375,0);
00134 
00135 /*
00136   radius=5;
00137   int x1=320;
00138   int y1=240;
00139 
00140   drawcircle(x1,y1,point3<uint>(255,0,0)); 
00141 */
00142 
00143   drawcircle(centerpos(0),color[0]);
00144   drawcircle(centerpos(1),color[1]);
00145   drawcircle(centerpos(2),color[2]);
00146   drawcircle(centerpos(3),color[3]);
00147 
00148   // Returning to previous state.
00149   glPopMatrix();
00150   glMatrixMode(GL_PROJECTION);
00151   glPopMatrix();
00152   glMatrixMode(GL_MODELVIEW);
00153 
00154   glEnable(GL_DEPTH_TEST);
00155 } 

void buttonpanel02::drawcircle ( point2< int > const &  c,
point3< uint > const &  color 
) const

Draws circle at screen coordinates.

Definition at line 87 of file buttonpanel02.cpp.

References point3< T >::x, point2< T >::x, point3< T >::y, point2< T >::y, and point3< T >::z.

Referenced by draw().

00091 {
00092   int x1=c.x;
00093   int y1=c.y;
00094 
00095   glPushAttrib(GL_CURRENT_BIT);
00096   glPushAttrib(GL_LIGHTING_BIT);
00097   glDisable(GL_LIGHTING);
00098   glColor3ub(color.x,color.y,color.z);
00099 
00100   doublec rad=3.141592*2.0/360.0;
00101 
00102   glBegin(GL_TRIANGLE_FAN);
00103   glVertex2f(x1,y1);
00104   for (double angle=0; angle<=360; angle+=2)
00105   {
00106     point2<double> x2(x1+ sin(rad*angle)*radius, y1 + cos(rad*angle)*radius);
00107 //    cout << SHOW(x2) << " ";
00108     glVertex2d(x2.x,x2.y);
00109   }
00110   glEnd();
00111 
00112 //cout << endl;
00113 
00114   glPopAttrib();
00115   glPopAttrib();
00116 }

void buttonpanel02::process ( bool isclicked,
uint index,
point2< int > const &  p 
)

Test if a button was clicked.

Definition at line 42 of file buttonpanel02.cpp.

References point2< T >::x, and point2< T >::y.

00047 {
00048   assert(centerdelta>0);
00049   assert(radius>0);
00050 
00051   isclicked=false;
00052 
00053   assert(zm);
00054   // Pushing the button triggers two calls, one
00055   //   down and the other up.  This rejects up.
00056   if (zm->zz.mouseLeft==false)
00057     return;
00058 
00059 
00060   // Bounding box rejects most cases. 
00061   if (p.x < (center.x - centerdelta - radius))
00062     return;
00063   if (p.x > (center.x + centerdelta + radius))
00064     return;
00065   if (p.y < (center.y - centerdelta - radius))
00066     return;
00067   if (p.y > (center.y + centerdelta + radius))
00068     return;
00069 
00070   point2<double> current(p.x,p.y);
00071   double radius2 = radius*radius;
00072 
00073   for (uint i=0; i<4; ++i)
00074   {
00075     point2<double> b0(centerpos(i).x,centerpos(i).y);
00076     if ((b0-current).dot() < radius2)
00077     {
00078       isclicked=true;
00079       index=i;
00080       return;
00081     }
00082   }
00083 
00084 }

void buttonpanel02::update (  ) 

Convert the ratio values to screen coordinate variables.

eg ratio_radius set the radius variable.

Definition at line 25 of file buttonpanel02.cpp.

References center, centerdelta, zpr::height, radius, ratio_center, ratio_centerdelta, ratio_radius, zpr::width, point2< T >::x, point2< T >::y, zm, and zprmouse::zz.

Referenced by buttonpanel02(), and maze004::reshape01().

00026 {
00027   assert(zm);
00028   if (zm==0)
00029     return;
00030 
00031   center.x = zm->zz.width * ratio_center.x; 
00032   center.y = zm->zz.height * ratio_center.y; 
00033 
00034   centerdelta = zm->zz.width * ratio_centerdelta;
00035 
00036   radius = zm->zz.width * ratio_radius;
00037 
00038 }


Member Data Documentation

Center of button panel in screen coordinates.

Definition at line 35 of file buttonpanel02.h.

Referenced by centerpos(), and update().

Offset from center for buttons.

Definition at line 38 of file buttonpanel02.h.

Referenced by centerpos(), and update().

Color corresponds with position.

Definition at line 44 of file buttonpanel02.h.

Referenced by buttonpanel02().

The button's radius in pixels.

Definition at line 41 of file buttonpanel02.h.

Referenced by update().

Center as a ratio.

Definition at line 21 of file buttonpanel02.h.

Referenced by buttonpanel02(), and update().

Relative to x-axis.

Definition at line 24 of file buttonpanel02.h.

Referenced by buttonpanel02(), and update().

Radius of button as a ratio.

Definition at line 27 of file buttonpanel02.h.

Referenced by buttonpanel02(), and update().

Conversion programs.

Definition at line 53 of file buttonpanel02.h.

Referenced by draw(), and update().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:49:51 2011 for Chelton Evans Source by  doxygen 1.5.8