00001 #include "Program.h"
00002
00003 const unsigned int GRID_SIZE = 50;
00004
00005 Program::Program(int _windowId)
00006 {
00007 fileNumber = 0;
00008
00009 windowId = _windowId;
00010 rootRes = 2*PI;
00011
00012
00013 linearGrid = new LinearGrid(GRID_SIZE);
00014 rootGrid = new RootGrid(linearGrid, linearGrid->GetTexture() );
00015 rootGrid->Create(rootRes);
00016
00017 polygonMode = GL_FILL;
00018
00019 windowWidth = glutGet (GLUT_WINDOW_WIDTH);
00020 windowHeight = glutGet (GLUT_WINDOW_HEIGHT);
00021
00022 glClearColor (1.0, 1.0, 1.0, 1.0);
00023 glShadeModel (GL_SMOOTH);
00024
00025 glPolygonMode(GL_FRONT_AND_BACK, polygonMode);
00026
00027
00028 HandleReshape (windowWidth, windowHeight);
00029 }
00030
00031 Program::~Program(void)
00032 {
00033
00034 }
00035
00036 void Program::HandleReshape(int _windowWidth, int _windowHeight)
00037 {
00038 glViewport (0, 0, _windowWidth, _windowHeight);
00039
00040 InitProjection();
00041 }
00042
00043 void Program::InitGlui(GLUI* _glui)
00044 {
00045 glui = _glui;
00046
00047 gluiWireframe = 0;
00048 gluiGridSize = linearGrid->GetSize();
00049
00050 glui->add_statictext("Grid Options");
00051 glui->add_separator();
00052
00053 glui->add_checkbox("Wireframe", &gluiWireframe, 1);
00054 glui->add_separator();
00055
00056
00057 glui->add_statictext("Select Texture: ");
00058 gluiRadioGroup = new GLUI_RadioGroup(glui);
00059
00060
00061 glui->add_radiobutton_to_group(gluiRadioGroup, "Galaxie.png");
00062 glui->add_radiobutton_to_group(gluiRadioGroup, "Cantonales.png");
00063 glui->add_radiobutton_to_group(gluiRadioGroup, "Treemap.png");
00064 glui->add_radiobutton_to_group(gluiRadioGroup, "ColorTreemap.png");
00065
00066 glui->set_main_gfx_window(windowId);
00067 }
00068
00069 void Program::HandleDisplay()
00070 {
00071 glLoadIdentity ();
00072
00073 glPolygonMode(GL_FRONT_AND_BACK, polygonMode);
00074 glPointSize(4.0f);
00075
00076 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00077 glColor3f (1.0, 0.0, 0.0);
00078
00079 rootGrid->Draw();
00080
00081 glutSwapBuffers ();
00082 }
00083
00084 void Program::InitProjection()
00085 {
00086 glMatrixMode (GL_PROJECTION);
00087 glLoadIdentity ();
00088 gluOrtho2D (-1, 1, -1, 1);
00089
00090 glMatrixMode (GL_MODELVIEW);
00091 }
00092
00093
00094 void Program::HandleKeyboard(unsigned char key, int x, int y)
00095 {
00096 switch (key)
00097 {
00098 case ESC: exit(0);
00099 break;
00100
00101 case 'f': (polygonMode==GL_FILL) ? polygonMode=GL_LINE : polygonMode = GL_FILL;
00102 break;
00103
00104 default: break;
00105
00106 }
00107
00108 glutPostRedisplay();
00109
00110 }
00111
00112 void Program::HandleSpecialKey(int key, int x, int y)
00113 {
00114 }
00115
00116 void Program::HandleMouse(int button, int state, int x, int y)
00117 {
00118 oldX = x;
00119 oldY = y;
00120
00121 if(state == GLUT_DOWN)
00122 mouseButton = button;
00123
00124 }
00125
00126 void Program::HandleMouseMotion(int x, int y)
00127 {
00128 int dy;
00129 double weight = 0.02;
00130
00131 if(mouseButton == GLUT_RIGHT_BUTTON)
00132 {
00133 dy = (oldY - y)/2;
00134
00135 rootRes += weight * dy;
00136
00137 if(rootRes >= 2*PI)
00138 {
00139 rootRes = 2*PI;
00140 }
00141
00142 if(rootRes <= 0.01)
00143 {
00144 rootRes = 0.01;
00145 }
00146 }
00147
00148 oldX = x;
00149 oldY = y;
00150 }
00151
00152 void Program::UpdateState()
00153 {
00154 if(gluiWireframe == 1)
00155 {
00156 polygonMode = GL_LINE;
00157 }
00158 else
00159 {
00160 polygonMode = GL_FILL;
00161 }
00162
00163 if(gluiRadioGroup->get_int_val() != fileNumber)
00164 {
00165 Texture* texture = (Texture*) linearGrid->GetTexture();
00166 fileNumber = gluiRadioGroup->get_int_val();
00167 texture->GenerateTexture(fileNumber);
00168 }
00169 }
00170
00171 void Program::HandleIdle()
00172 {
00173 rootGrid->Create(rootRes);
00174
00175
00176 glutSetWindow(windowId);
00177
00178 UpdateState();
00179
00180 glutPostRedisplay();
00181 }