Gl Graph

Gl Graph Source of glutwin.cpp


#include <glutwin.h>
 
GlutWin * glutWin;
 
GlutWin::GlutWin(unsigned int width, unsigned int height)
    : GlWindow(width,height)
{
    glutWin=this;
}
 
GlutWin::GlutWin(unsigned int width, unsigned int height, bool debug)
    : GlWindow(width,height,debug)
{
    glutWin=this;
}
 
void GlutWin::glutDisplay()
{
    if (this->helpTextMode)
        drawHelpText();
    else
        drawAll();
 
 
}
 
static MouseButton convertButtonEnum(unsigned int glutbutton)
{
    MouseButton button;
 
    switch(glutbutton)
    {
    case GLUT_LEFT_BUTTON:
        button= MOUSE_BUTTON_LEFT;
        break;
    case GLUT_MIDDLE_BUTTON:
        button= MOUSE_BUTTON_MIDDLE;
        break;
    case GLUT_RIGHT_BUTTON:
        button= MOUSE_BUTTON_RIGHT;
        break;
    case 3:
        button= MOUSE_BUTTON_MIDDLE_UP;
        break;
    case 4:
        button= MOUSE_BUTTON_MIDDLE_DOWN;
        break;
    default:
        button= MOUSE_NO_BUTTON;
        break;
    }
    return button;
 
}
 
static ModifierButton getModifierEnum()
{
    ModifierButton mod;
    int glutMod =glutGetModifiers();
    if (glutMod & GLUT_ACTIVE_SHIFT)
        mod=SHIFT_MODIFIER;
    else if (glutMod & GLUT_ACTIVE_CTRL )
        mod=CTRL_MODIFIER;
    else if (glutMod & GLUT_ACTIVE_ALT)
        mod=ALT_MODIFIER;
    else
        mod =NO_MODIFIER;
 
    return mod;
}
 
void GlutWin::processButtonPress(int x, int y, unsigned int glutbutton)
{
    MouseButton button =convertButtonEnum(glutbutton);
    currentButton=button;
    onMouseButtonPress(x,y,button,getModifierEnum());
}
 
void GlutWin::processButtonRelease(int x, int y)
{
    onMouseButtonRelease(x,y,currentButton,getModifierEnum());
}
 
void GlutWin::processMotion(int x, int y)
{
    onMouseMotion(x,y,currentButton,getModifierEnum());
}
 
void display(void)
{
    glutWin->glutDisplay();
}
 
void mouseFunc(int button, int state, int x, int y)
{
    if (state==GLUT_UP )
        glutWin->processButtonRelease( x,  y);
    else if (state==GLUT_DOWN )
        glutWin->processButtonPress( x,  y, button);
    glutPostRedisplay();
}
 
void motionFunc(int x,int y)
{
    glutWin->processMotion( x,  y);
    glutPostRedisplay();
}
 
void resizeFunc(int x,int y)
{
    glutWin->processResizeEvent( x,  y);
    glutPostRedisplay();
}
 
void keybordFunc(unsigned char key, int x, int y )
{
    if (glutWin->isDebug())
        std::cout << "keybordFunc x " << x <<" y " << y << std::endl;
    glutWin->processButtonPressChar(key);
}
 
void keybordSpecialFunc(int key, int x, int y )
{
 
    if (glutWin->isDebug())
        std::cout << "keybordSpecialFunc x " << x <<" y " << y << std::endl;
    switch(key) {
    case GLUT_KEY_F1 :
        glutWin->processButtonPressF1();
        break;
    case GLUT_KEY_F2 :
        glutWin->processButtonPressF2();
        break;
    case GLUT_KEY_F3 :
        glutWin->processButtonPressF3();
        break;
    case GLUT_KEY_F4 :
        glutWin->processButtonPressF4();
        break;
    case GLUT_KEY_F5 :
        glutWin->processButtonPressF5();
        break;
    case GLUT_KEY_F6 :
        glutWin->processButtonPressF6();
        break;
    case GLUT_KEY_F7 :
        glutWin->processButtonPressF7();
        break;
    case GLUT_KEY_F8 :
        glutWin->processButtonPressF8();
        break;
    case GLUT_KEY_F9 :
        glutWin->processButtonPressF9();
        break;
    case GLUT_KEY_F10 :
        glutWin->processButtonPressF10();
        break;
    case GLUT_KEY_F11 :
        glutWin->processButtonPressF11();
        break;
    case GLUT_KEY_F12 :
        glutWin->processButtonPressF12();
        break;
    }
    glutPostRedisplay();
}
 
void GlutWin::initGl()
{
    glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH);
    glutInitWindowSize(width, height);
    glutCreateWindow("GlutGraph");
    glutDisplayFunc(display);
    glutReshapeFunc(resizeFunc);
    glutMouseFunc(mouseFunc);
    glutMotionFunc(motionFunc);
    glutPassiveMotionFunc(motionFunc);
    glutKeyboardFunc(keybordFunc);
    glutSpecialFunc(keybordSpecialFunc);
    glutPostRedisplay();
}
 
void GlutWin::setTitle(const char* title)
{
    glutSetWindowTitle(title);
}
 
void GlutWin::run()
{
    glutMainLoop();
}