Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

ColorCubePanel.cpp

00001 #include <gl/glut.h>
00002 
00003 #include "LifeVariables.h"
00004 #include "ColorCubePanel.h"
00005 #include "ColorCube.h"
00006 
00007 ColorCubePanel::ColorCubePanel():
00008     GuiComponent(-1, 1,-1, 1,
00009                  COLOR_CUBE_PANEL_X_POS,
00010                  COLOR_CUBE_PANEL_Y_POS,
00011                  COLOR_CUBE_PANEL_WIDTH,
00012                  COLOR_CUBE_PANEL_HEIGHT) 
00013 {
00014     this->colorCube = new ColorCube(10, 10);
00015     this->point = NULL;
00016     this->dragging = false;
00017 }
00018 
00019 
00020 void ColorCubePanel::render() {
00021     if(this->state == ENABLED) {
00022         this->startCamera();
00023         
00024         glPushAttrib(GL_CURRENT_BIT);
00025         
00026         // the background
00027         glColor3f(0.35f,0.4f,0.3f);
00028         glBegin(GL_QUADS);
00029             glVertex2i(this->left, this->bottom);
00030             glVertex2i(this->left, this->top);
00031             glVertex2i(this->right, this->top);
00032             glVertex2i(this->right, this->bottom);
00033         glEnd();        
00034         
00035         // the mad cube
00036         this->colorCube->render();
00037         
00038         this->stopCamera();
00039 
00040         glPopAttrib();
00041     }
00042 }
00043 
00044 
00045 bool ColorCubePanel::onMouseDown(int x, int y) {
00046     if((this->state == ENABLED)&&(this->hit(x,y))) {
00047         this->colorCube->onMouseDown(x, y);
00048         float *color = this->colorCube->getColor();
00049         this->point->rgba[0] = color[0];
00050         this->point->rgba[1] = color[1];
00051         this->point->rgba[2] = color[2];
00052         this->dragging = false;
00053         this->disable();        
00054         return true;
00055     }
00056     else {        
00057         return false;
00058     }
00059 }
00060 
00061 
00062 void ColorCubePanel::onMouseDrag(int x, int y) {
00063     if(!dragging) {
00064         this->colorCube->onMouseDown(x,y);
00065         dragging = true;
00066     }
00067     else {
00068         this->colorCube->onMouseDrag(x,y);
00069     }
00070 }
00071 
00072 
00073 void ColorCubePanel::refreshDragBounds(int x, int y) {
00074     this->colorCube->setBounds(x,y);    
00075 }

Generated on Mon Dec 12 15:20:26 2005 for CCube by  doxygen 1.4.1