Пример #1
0
void PassiveMotionCallback(int x, int y)
{
    STPoint2 position = STPoint2(x, gWindowSizeY - y);
    bool redisplay = false;

    UIWidget * receiver = NULL;
    for (list<UIWidget *>::iterator ii = gWidgets.begin();
         ii != gWidgets.end(); ++ii)
    {
        UIWidget* widget = *ii;
        if(widget->HitTest(position))
            receiver = widget;
    }
    
    if(receiver != gEnteredWidget)
    {
        if(gEnteredWidget != NULL)
            gEnteredWidget->HandleMouseLeave();
        if(receiver != NULL)
            receiver->HandleMouseEnter();
        gEnteredWidget = receiver;
        redisplay = true;
    }
    
    if(gEnteredWidget != NULL)
    {
        gEnteredWidget->HandleMouseMove(position);
        redisplay = true;
    }
    
    if(redisplay)
        glutPostRedisplay();
}
Пример #2
0
void MouseCallback(int button, int state, int x, int y)
{
    STPoint2 position = STPoint2(x, gWindowSizeY - y);
    bool redisplay = false;
    
    UIWidget * receiver = NULL;
    if(gCaptureWidget == NULL)
    {
        for (list<UIWidget *>::iterator ii = gWidgets.begin();
             ii != gWidgets.end(); ++ii)
        {
            UIWidget* widget = *ii;
            if(widget->HitTest(position))
                receiver = widget;
        }
    }
    
    if(button == GLUT_LEFT_BUTTON)
    {
        if(state == GLUT_DOWN)
        {
            if(receiver != NULL)
            {
                gCaptureWidget = receiver;
                gCaptureWidget->HandleMouseDown(position);
                redisplay = true;
            }
            else
            {
                char buf[64];
                snprintf(buf, 64, "%i", gCurrentLineID++);
                gActiveLine = new UILine(position, position, string(buf), LineDeleteCallback);
                gWidgets.push_back(gActiveLine);
                
                redisplay = true;
            }
        }
        else if(state == GLUT_UP)
        {
            if(gCaptureWidget)
            {
                gCaptureWidget->HandleMouseUp(position);
                gCaptureWidget = NULL;
                redisplay = true;
            }
            
            if(gActiveLine)
            {
                gActiveLine->finalize();
                gLines.push_back(gActiveLine);
                
                gActiveLine = NULL;
                redisplay = true;
            }
        }
    }
    
    if(redisplay)
        glutPostRedisplay();
}