Ejemplo n.º 1
0
/*
 * Activates a menu pointed by the function argument
 */
void fgActivateMenu( SFG_Window* window, int button )
{
    /*
     * We'll be referencing this menu a lot, so remember its address:
     */
    SFG_Menu* menu = window->Menu[ button ];

    /*
     * Mark the menu as active, so that it gets displayed:
     */
    window->ActiveMenu = menu;
    menu->IsActive = GL_TRUE;
    fgState.ActiveMenus++;

    /*
     * Set up the initial menu position now:
     */
    menu->X = window->State.MouseX + glutGet( GLUT_WINDOW_X );
    menu->Y = window->State.MouseY + glutGet( GLUT_WINDOW_Y );

    if( menu->X + menu->Width > glutGet ( GLUT_SCREEN_WIDTH ) )
        menu->X -=menu->Width;

    if( menu->Y + menu->Height > glutGet ( GLUT_SCREEN_HEIGHT ) )
        menu->Y -=menu->Height;

    fgSetWindow( menu->Window );
    glutPositionWindow( menu->X, menu->Y );
    glutReshapeWindow( menu->Width, menu->Height );
    glutPopWindow( );
    glutShowWindow( );
    menu->Window->ActiveMenu = menu;
}
void showSimulationWindow(bool show)
{
	if (show) 
		glutShowWindow();
	else
		glutHideWindow();
}
Ejemplo n.º 3
0
	/*
	We can't start an application that requires exclusive mode with system() if our GLUT window
	already has exclusive mode. Thus we must wait and perform the system() call after
	we know that the window no longer has exclusive mode. This is the only way to do it.
	*/
	void visibilityFunc(int state)
	{
		// If the window is finally f*****g gone...
		if(state == GLUT_NOT_VISIBLE)
		{
			// Stop the audio no matter what.
			audio::stopBGM();
			
			// If the current Tile's state is above 1.0 (EXECUTE range) we execute the command.
			// The UI halts until that call is returned, at which point we remake the window
			// visible and set it to fullscreen if necessary.
			if(grid->getCurrent()->getIntendedState() == EXECUTE)
			{
				grid->getCurrent()->setState(ACTIVE);
				printf("\ncommand: %s\n", grid->getCurrent()->getCommand());
				if(grid->getCurrent()->isSelectable())
				{
					system(grid->getCurrent()->getCommand());
				}
				glutShowWindow();
				window::setFullScreen(c->fullscr);
				audio::startBGM();
			}
		}

		if(state == GLUT_VISIBLE)
		{
			audio::startBGM();
		}
	}
Ejemplo n.º 4
0
static int l_window_show(lua_State* L)
{
	Window* win = l_checkWindow(L, 1);
	glutSetWindow(win->id);
	glutShowWindow();
	return 0;
}
Ejemplo n.º 5
0
int main(int argc, char **argv) {
	//initialize glut and parse command line arguments @ see glut documentation for more details
	glutInit(&argc, argv);
	//setting up the window display mode
	glutInitDisplayMode(
	GLUT_RGBA |   //use a rgba target framebuffer
	GLUT_DEPTH |  //create a depth (z-)buffer
	GLUT_DOUBLE |  //create a front and back-buffer
	GLUT_MULTISAMPLE); //create a multi-sample framebuffer (use for fullscreen antialiasing)
	//setting up window pos and size
	glutInitWindowPosition(0, 0);
	glutInitWindowSize(800, 600);
	//create the window
	//from this point we can use the opengl api, because
	//glut has created a valid opengl context for us
	glutCreateWindow( "Hausaufgabe 2");
	//init the application and all required resources
	if (!initApplication())
		return EXIT_FAILURE;
	//register the required callback
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	// glutMouseFunc(mouse);
	//show the window
	glutShowWindow();
	//enter mainloop which handle all window events
	glutMainLoop();
	return EXIT_SUCCESS;

}
Ejemplo n.º 6
0
static void KeyPressFunc(unsigned char Key, int x, int y)
{
	switch (Key) {
	case 'F':
	case 'f': //toggle screenmode
		if (!fullscreen) {
			glutFullScreen();
			fullscreen = true;
		}
		else if (fullscreen) {
			glutReshapeWindow(1500, 1000);
			glutPositionWindow(10, 30);
			fullscreen = false;
		}
		break;
	case 'H':
	case 'h': //toggle screenmode
		glutHideWindow();
		break;
	case 'S':
	case 's': //toggle screenmode
		glutShowWindow();
		break;
	case 27:    // Escape key
		exit(1);
	}
}
Ejemplo n.º 7
0
void display()
{
    try
    {
		if (!disconnected)
		{
			// receive scenegraph and do rendering
	        server->render(ract);
			OSGCompat::clearChangelist();
		}
		else
		{
			SLOG << "Attempting to restart ClusterServer..." << endLog;
			// start server, wait for client to connect
			server->start();
			glutShowWindow();
			disconnected = false;
		}
    }
    catch(std::exception &e)
    {
        SLOG << "ERROR: " << e.what() << endLog;
		disconnected = true;
		// try to restart server
        server->stop();
		//after glutHideWindow() control has to be given back to the glutloop for it to have an effect
		glutHideWindow();
	}
}
Ejemplo n.º 8
0
HRESULT CVideoMixerOpenGL::SetViewPortPri(RECT* prPort)
{
	if(prPort==NULL)
		return E_POINTER;

	if((m_rViewPort .left  == prPort->left)&&
		(m_rViewPort .top  == prPort->top) &&
		(m_rViewPort .right  == prPort->right) &&
		(m_rViewPort .bottom  == prPort->bottom))
		return S_OK;

	m_rViewPort  = *prPort;
	
	glutReshapeWindow(prPort->right-prPort->left,prPort->bottom-prPort->top);
	glutPositionWindow(prPort->left,prPort->top );


	if(m_pDMCP)
	{
		HRESULT hr = m_pDMCP->SetTargetRect(&m_rViewPort);
		if(FAILED(hr))
			DP("[GFXPRESENT] SetTargetRect failed :0x%x \n",hr);

		m_bCanDisp = m_pDMCP->CanDisplay(FALSE);

		if(m_bShow && m_bCanDisp)
			glutShowWindow();
		else
			glutHideWindow();

	}

	return S_OK;
}
Ejemplo n.º 9
0
void updateWindows(){
	glui3->hide();
	glutHideWindow();
	glui2->set_main_gfx_window( main_window );
	glutShowWindow();
	if(game_option == 1){
		game->player2->cpu = true;
		if(listbox1->get_int_val() == 1)
			game->player2->cpudiff = "easy";
		else if(listbox1->get_int_val() == 2)
			game->player2->cpudiff = "medium";
		else if(listbox1->get_int_val() == 3)
			game->player2->cpudiff = "hard";

	} else if(game_option == 2){
		game->player1->cpu = true;
		if(listbox1->get_int_val() == 1)
			game->player1->cpudiff = "easy";
		else if(listbox1->get_int_val() == 2)
			game->player1->cpudiff = "medium";
		else if(listbox1->get_int_val() == 3)
			game->player1->cpudiff = "hard";

	} else if(game_option == 3){
		game->player1->cpu = true;
		if(listbox1->get_int_val() == 1)
			game->player1->cpudiff = "easy";
		else if(listbox1->get_int_val() == 2)
			game->player1->cpudiff = "medium";
		else if(listbox1->get_int_val() == 3)
			game->player1->cpudiff = "hard";


		game->player2->cpu = true;
		if(listbox2->get_int_val() == 1)
			game->player2->cpudiff = "easy";
		else if(listbox2->get_int_val() == 2)
			game->player2->cpudiff = "medium";
		else if(listbox2->get_int_val() == 3)
			game->player2->cpudiff = "hard";
	}
	
	delete game->gameboard;
	game->addGameboard(new Gameboard(gameboard_size));
	game->initializeSocket(game_option+1);

	//Contador 
	int timeOption = time_box->get_int_val();
	if(timeOption>0){
		if		(timeOption == 1) max_play_time = 60; //60 segundos
		else if (timeOption == 2) max_play_time = 30; //30 segundos
		else if (timeOption == 3) max_play_time = 15; //15 segundos
		if(!game->player1->cpu)
			game->clock->start_count(); 
	}
}
Ejemplo n.º 10
0
static void
timer(int value)
{
  if (value != 777) {
    printf("FAIL: unexpected timer value\n");
    exit(1);
  }
  damage_expectation = 1;
  glutShowWindow();
}
Ejemplo n.º 11
0
void GlutViewer::show()
{
  OpenGLViewer::show();
  if (!visible)
  {
    glutShowWindow();
    //Restore to set width & height
    glutReshapeWindow(width, height);
  }
  // Update title
  glutSetWindowTitle(title.c_str());
}
Ejemplo n.º 12
0
void display()
{
    if(!running)
    {
        server->start();
        running=true;
        glutShowWindow();
    }
    /*! ignore rendering in zero sized windows */
    if(!winWidth || !winHeight)
        return;
    try
    {                                                       
        OSG::FrameHandler::the()->frame();
        OSG::commitChanges();
        server->render(ract);
        // clear changelist from prototypes
        OSG::Thread::getCurrentChangeList()->clear();
    } 
    catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
    {
        if(exitOnError)
        {
            SLOG << e.what() << std::endl;
            printf("Exit on error %s",e.what());
            try
            {
                cleanup();
            }

            catch(...)
            {
            }

            exit(0);
        }
        else
        {
            window->clearPorts();
            // try to restart server
            try
            {
                server->stop();
            }
            catch(...)
            {
            }
            running=false;
            glutHideWindow();
        }
    }
}
Ejemplo n.º 13
0
	void doSetWindowVisible(bool visible)
	{
		Window::Ptr window = getCurrentWindow();
		if (window) {
			if (visible) {
				glutShowWindow();
				window->onShow();
			} else {
				glutHideWindow();
				window->onHide();
			}
		}
	}
Ejemplo n.º 14
0
HRESULT CVideoMixerOpenGL::Show(BOOL bShow)
{
	if(m_bShow==bShow)
		return S_OK;
	m_bShow = bShow;

	if(m_bShow && m_bCanDisp)
		glutShowWindow();
	else
		glutHideWindow();

	return S_OK;
}
Ejemplo n.º 15
0
// maybe_render() can be called directly by GLUT when a window is 
// uncovered, so we let that happen even if suspend_render is true.
static void maybe_render() {
    int width, height;
    BOINC_STATUS boinc_status;

    if (visible && (current_graphics_mode != MODE_HIDE_GRAPHICS)) {
        width = glutGet(GLUT_WINDOW_WIDTH);
        height = glutGet(GLUT_WINDOW_HEIGHT);
        if (throttled_app_render(width, height, dtime())) {
            glutSwapBuffers();
#ifdef __APPLE__
            switch (current_graphics_mode) {
            case MODE_WINDOW:
                MacGLUTFix(false);
                if (need_show) {
                    glutShowWindow();
                    need_show = false;
                }
                break;
            case MODE_FULLSCREEN:
            case MODE_BLANKSCREEN:
                MacGLUTFix(true);
                if (need_show) {
                    glutShowWindow();
                    need_show = false;
                }
                break;
            }
#endif
            // Always render once after app is suspended in case app displays
            //  different graphics when suspended, then stop rendering
            boinc_get_status(&boinc_status);
            if (boinc_status.suspended)
                suspend_render = true;
        }
    }
}
Ejemplo n.º 16
0
/*
 * Activates a menu pointed by the function argument
 */
static void fghActivateMenu( SFG_Window* window, int button )
{
    int max_x, max_y;

    /* We'll be referencing this menu a lot, so remember its address: */
    SFG_Menu* menu = window->Menu[ button ];
    SFG_Window* current_window = fgStructure.CurrentWindow;

    /* If the menu is already active in another window, deactivate it there */
    if ( menu->ParentWindow )
      menu->ParentWindow->ActiveMenu = NULL ;

    /* Mark the menu as active, so that it gets displayed: */
    window->ActiveMenu = menu;
    menu->IsActive = GL_TRUE;
    fghSetMenuParentWindow ( window, menu );
    fgState.ActiveMenus++;

    /* Set up the initial menu position now: */
    fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y);
    fgSetWindow( window );
    menu->X = window->State.MouseX + glutGet( GLUT_WINDOW_X );
    menu->Y = window->State.MouseY + glutGet( GLUT_WINDOW_Y );

    if( menu->X + menu->Width > max_x )
        menu->X -=menu->Width;

    if( menu->Y + menu->Height > max_y )
    {
        menu->Y -=menu->Height;
        if( menu->Y < 0 )
            menu->Y = 0;
    }

    menu->Window->State.MouseX =
        window->State.MouseX + glutGet( GLUT_WINDOW_X ) - menu->X;
    menu->Window->State.MouseY =
        window->State.MouseY + glutGet( GLUT_WINDOW_Y ) - menu->Y;

    fgSetWindow( menu->Window );
    glutPositionWindow( menu->X, menu->Y );
    glutReshapeWindow( menu->Width, menu->Height );
    glutPopWindow( );
    glutShowWindow( );
    menu->Window->ActiveMenu = menu;
    fghCheckMenuStatus( menu );
    fgSetWindow( current_window );
}
Ejemplo n.º 17
0
void Graphics::SetOpenGLContext(double proportion, int argc, char **argv) {
	gettimeofday(&changeFrame, NULL);

	glutInit(&argc, argv);
	int maxwidth = glutGet(GLUT_SCREEN_WIDTH);
	int maxheight = glutGet(GLUT_SCREEN_HEIGHT);
	windowHeight = maxheight - 100;
	windowWidth = windowHeight * proportion;
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(windowWidth, windowHeight);
	glutInitWindowPosition((maxwidth - windowWidth) / 2, 0);
	glutCreateWindow("Repka");
	glutShowWindow();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
Ejemplo n.º 18
0
void registerWindowCallback::callback() {
    freeglutManager->windows[window->id] = window;
    glutSetWindow(window->id);
    
    glutDisplayFunc(freeglutManager_glutDisplayFunc);
    glutReshapeFunc(freeglutManager_glutReshapeFunc);
    glutKeyboardFunc(freeglutManager_glutKeyboardFunc);
    glutMouseFunc(freeglutManager_glutMouseFunc);
    glutMotionFunc(freeglutManager_glutMotionFunc);
    glutPassiveMotionFunc(freeglutManager_glutPassiveMotionFunc);
    glutVisibilityFunc(freeglutManager_glutVisibilityFunc);
    glutEntryFunc(freeglutManager_glutEntryFunc);
    glutSpecialFunc(freeglutManager_glutSpecialFunc);
    glutTimerFunc(2000, freeglutManager_RenderTimer, window->id);
    
    glutShowWindow();
    waiting = false;
}
int
main(int argc, char **argv)
{
	myAppState.appName = strdup(argv[0]);

	myAppState.triangleAreaInPixels=DEFAULT_TRIANGLE_AREA;
	myAppState.triangleType = DEFAULT_TRIANGLE_TYPE;
	myAppState.testDurationMS=DEFAULT_TEST_DURATION_MS;
	myAppState.imgWidth = DEFAULT_WIN_WIDTH;
	myAppState.imgHeight = DEFAULT_WIN_HEIGHT;
	myAppState.triangleLimit = DEFAULT_TRIANGLE_LIMIT;
	myAppState.vertexBufLimit = DEFAULT_VERTEXBUF_LIMIT;
	myAppState.textureSize = DEFAULT_TEXTURE_SIZE;
	myAppState.enableLighting = DEFAULT_LIGHTING_ENABLED;
	myAppState.enableColorMaterial = DEFAULT_COLOR_MATERIAL;
	myAppState.dumpFileName = strdup(DEFAULT_DUMP_FILE_NAME);
	myAppState.retainedModeEnabled = DEFAULT_RETAINED_MODE_ENABLED;
	myAppState.clearPerFrame = DEFAULT_CLEAR_PER_FRAME;
	myAppState.outlineMode = DEFAULT_OUTLINE_MODE_BOOL;

	glutInit(&argc, argv);

	parseArgs(argc, argv, &myAppState);

	glutInitWindowSize(myAppState.imgWidth, myAppState.imgHeight);

	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

	{
		char buf[256];
		sprintf(buf,"%s -- Lawrence Berkeley National Laboratory -- (C) 2009-2010", argv[0]);
		glutCreateWindow(buf);
	}

	Init();
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutKeyboardFunc(Key);
	glutShowWindow();
	glutMainLoop();
	return 0;
}
Ejemplo n.º 20
0
/////////////////////////////////////////////////////////
// dimensionsMess
//
/////////////////////////////////////////////////////////
void gemglutwindow :: dimensionsMess(unsigned int width, unsigned int height)
{
  if (width <= 0) {
    error("width must be greater than 0");
    return;
  }

  if (height <= 0 ) {
    error ("height must be greater than 0");
    return;
  }
  m_width = width;
  m_height = height;
  if(makeCurrent()){
    glutReshapeWindow(width, height);
    glutHideWindow();glutShowWindow();
    glutPositionWindow(m_xoffset, m_yoffset);
    glutMainLoopEvent();
  }
}
Ejemplo n.º 21
0
    bool EnvironmentDisplay::Init(int width_in, int height_in, char *title_in)
    {
      static bool initialized = false;
      int    argc = 0;
      char **argv = 0;
      width  = width_in;
      height = height_in;
      if(!initialized)
	{
	  glutInit(&argc, argv);
	  glutInitWindowPosition(0,0);
	  glutInitWindowSize(width, height);
	  initialized = true;
	}
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
      window = glutCreateWindow(title_in);

      glClearColor(1.0,1.0,1.0,0);
      glutShowWindow();
      return true;
    }
Ejemplo n.º 22
0
void set_mode(int mode) {
    if (mode == current_graphics_mode) {
        // Bring graphics window to front whenever user presses "Show graphics"
        if (mode == MODE_WINDOW) {
#ifdef __APPLE__
            BringAppToFront();
#else
            if (glut_is_freeglut && FREEGLUT_IS_INITIALIZED && (GLUT_HAVE_WINDOW > 0)) {
//              glutPopWindow();
       	        glutShowWindow();
            }
#endif 
       }
        return;
    }

    if (debug) fprintf(stderr, "set_mode(%d): current_mode = %d.\n", mode, current_graphics_mode);
    if (glut_is_initialized) {
        if (debug) fprintf(stderr, "Calling KillWindow(): win = %d\n", win);
        KillWindow();
        if (debug) fprintf(stderr, "KillWindow() survived.\n");
    }
    
    if (mode != MODE_HIDE_GRAPHICS) {
        if (debug) fprintf(stderr, "set_mode(): Calling make_new_window(%d)\n", mode); 
        make_new_window(mode);
        if (debug) fprintf(stderr, "make_new_window() survived.\n");
    }
#ifdef __APPLE__
    else
        HideThisApp();
#endif

    current_graphics_mode = mode;

    return;
}
Ejemplo n.º 23
0
void freeglut::StartMainLoop() {
    running = true;
    if (MainLoopLock->TryLock() == wxMUTEX_NO_ERROR) {
        int tmpWindow = glutCreateWindow("GLEW init");
        glutShowWindow();
        initGlew();
        std::cout << "OpenGL: " << glGetString(GL_VENDOR) << std::endl;
        std::cout << "OpenGL: " << glGetString(GL_RENDERER) << std::endl;
        std::cout << "OpenGL: " << glGetString(GL_VERSION) << std::endl;
        glutHideWindow();
        glutDestroyWindow(tmpWindow);
        
        unsigned int displayMode = GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
        glutInitDisplayMode (displayMode);
        glutInitContextVersion (3, 0);
        glutInitContextProfile(GLUT_CORE_PROFILE);
        
        glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
        
        while (running) {
            glutMainLoopEvent();
            QueueLock->Lock();
            if (!callbackQueue.empty()) {
                callbackQueue.front()->callback();
                callbackQueue.pop();
            }
            QueueLock->Unlock();
        }
        
        for (std::map<int,freeglutWindow*>::iterator it=windows.begin(); it!=windows.end(); ++it) {
            glutDestroyWindow(it->first);
        }
        windows.clear();
    
        MainLoopLock->Unlock();
    }
}
Ejemplo n.º 24
0
//
// Standard glut idle function
//
void IdleFunc()
{
	glutShowWindow    ();
	glutPostRedisplay ();
}
Ejemplo n.º 25
0
	void CDrawing::ShowWindow()
	{
		glutShowWindow();
	}
Ejemplo n.º 26
0
void GLUTDisplay2::run(PathTracer &pt) {
	ptr = &pt;

	unsigned int buffer_width = 960;
	unsigned int buffer_height = 540;
	glutInitWindowSize(buffer_width, buffer_height);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("test");

	// Initialize GLEW
	if (glewInit() != GLEW_OK) {
		cerr << "Failed to initialize GLEW" << endl;
		return;
	}

	try {
		// Set up scene
		cout << "setup camera" << endl;
		//SampleScene::InitialCameraData camera_data;

		// todo: get camera
		//ptr->initScene(camera_data);

		// Initialize camera according to scene params
		//m_camera = new PinholeCamera(camera_data.eye, camera_data.lookat,
		//		camera_data.up, -1.0f, // hfov is ignored when using keep vertical
		//		camera_data.vfov, PinholeCamera::KeepVertical);
	} catch (optix::Exception& e) {
		sutilReportError(e.getErrorString().c_str());
		exit(2);
	}

	//cout << "make renderer" << endl;
	//renderer = new GLrenderer( pt.getOutputBuffer()->getGLBOId() );

	cout << "init texture" << endl;
	glGenTextures(1, &m_texId);
	glBindTexture(GL_TEXTURE_2D, m_texId);

	// Change these to GL_LINEAR for super- or sub-sampling
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	// GL_CLAMP_TO_EDGE for linear filtering, not relevant for nearest.
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	glBindTexture(GL_TEXTURE_2D, 0);

	// Initialize state
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, 1, 0, 1, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glViewport(0, 0, buffer_width, buffer_height);

	cout << "begin glut loop" << endl;
	glutDisplayFunc(display);
	glutIdleFunc(idle);
	glutShowWindow();
	glutReshapeWindow( buffer_width, buffer_height );
	glutMainLoop();
}
Ejemplo n.º 27
0
void UnhideTimer(int window)
{
    glutSetWindow(window);
    glutShowWindow();
}
Ejemplo n.º 28
0
/*
 * Private function to check for the current menu/sub menu activity state
 */
static GLboolean fghCheckMenuStatus( SFG_Window* window, SFG_Menu* menu )
{
    SFG_MenuEntry* menuEntry;
    int x, y;

    /*
     * First of all check any of the active sub menus...
     */
    for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
         menuEntry;
         menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
    {
        if( menuEntry->SubMenu && menuEntry->IsActive )
        {
            /*
             * OK, have the sub-menu checked, too. If it returns GL_TRUE, it
             * will mean that it caught the mouse cursor and we do not need
             * to regenerate the activity list, and so our parents do...
             */
            GLboolean return_status = fghCheckMenuStatus( window,
                                                          menuEntry->SubMenu );

            /*
             * Reactivate the submenu as the checkMenuStatus may have turned
             * it off if the mouse is in its parent menu entry.
             */
            menuEntry->SubMenu->IsActive = GL_TRUE;
            if ( return_status )
                return GL_TRUE;
        }
    }

    /*
     * That much about our sub menus, let's get to checking the current menu:
     */
    x = window->State.MouseX;
    y = window->State.MouseY;

    for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
         menuEntry;
         menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
        menuEntry->IsActive = GL_FALSE;

    menu->IsActive = GL_FALSE;

    /*
     * Check if the mouse cursor is contained within the current menu box
     */
    if( ( x >= FREEGLUT_MENU_BORDER ) &&
        ( x < menu->Width  - FREEGLUT_MENU_BORDER ) &&
        ( y >= FREEGLUT_MENU_BORDER ) &&
        ( y < menu->Height - FREEGLUT_MENU_BORDER ) &&
        ( window == menu->Window ) )
    {
        int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENU_HEIGHT;

        /*
         * The mouse cursor is somewhere over our box, check it out.
         */
        menuEntry = fghFindMenuEntry( menu, menuID + 1 );
        assert( menuEntry );

        menuEntry->IsActive = GL_TRUE;
        menuEntry->Ordinal = menuID;

        /*
         * If this is not the same as the last active menu entry, deactivate
         * the previous entry.  Specifically, if the previous active entry
         * was a submenu then deactivate it.
         */
        if( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
            if( menu->ActiveEntry->SubMenu )
                fgDeactivateSubMenu( menu->ActiveEntry );

        menu->ActiveEntry = menuEntry;
        menu->IsActive = GL_TRUE;

        /*
         * OKi, we have marked that entry as active, but it would be also
         * nice to have its contents updated, in case it's a sub menu.
         * Also, ignore the return value of the check function:
         */
        if( menuEntry->SubMenu )
        {
            if ( ! menuEntry->SubMenu->IsActive )
            {
                SFG_Window *current_window = fgStructure.Window;

                /*
                 * Set up the initial menu position now...
                 */
                menuEntry->SubMenu->IsActive = GL_TRUE;

                /*
                 * Set up the initial submenu position now:
                 */
                menuEntry->SubMenu->X = menu->X + menu->Width;
                menuEntry->SubMenu->Y = menu->Y +
                    menuEntry->Ordinal * FREEGLUT_MENU_HEIGHT;

                if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width >
                    glutGet( GLUT_SCREEN_WIDTH ) )
                    menuEntry->SubMenu->X = menu->X -
                        menuEntry->SubMenu->Width;

                if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height >
                    glutGet( GLUT_SCREEN_HEIGHT ) )
                    menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
                                               FREEGLUT_MENU_HEIGHT -
                                               2 * FREEGLUT_MENU_BORDER );

                fgSetWindow( menuEntry->SubMenu->Window );
                glutPositionWindow( menuEntry->SubMenu->X,
                                    menuEntry->SubMenu->Y );
                glutReshapeWindow( menuEntry->SubMenu->Width,
                                   menuEntry->SubMenu->Height );
                glutPopWindow( );
                glutShowWindow( );
                menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu;
                fgSetWindow( current_window );
            }

            fghCheckMenuStatus( window, menuEntry->SubMenu );

            /*
             * Activate it because its parent entry is active
             */
            menuEntry->SubMenu->IsActive = GL_TRUE;
        }

        /*
         * Report back that we have caught the menu cursor
         */
        return GL_TRUE;
    }

    /*
     * Looks like the menu cursor is somewhere else...
     */
    return GL_FALSE;
}
Ejemplo n.º 29
0
void
key(unsigned char c, int w, int h)
{
  int transP;

  printf("c=%d  w=%d h=%d\n", c, w, h);
  switch (c) {
  case 'e':
    glutEstablishOverlay();
    independent = 0;
    transP = glutLayerGet(GLUT_TRANSPARENT_INDEX);
    glClearIndex(transP);
    glutSetColor((transP + 1) % 2, 1.0, 1.0, 0.0);
    glIndexi((transP + 1) % 2);
    on = 1;
    break;
  case 'r':
    glutRemoveOverlay();
    on = 0;
    break;
  case 'm':
    if (glutLayerGet(GLUT_HAS_OVERLAY)) {
      int pixel;
      GLfloat red, green, blue;

      transP = glutLayerGet(GLUT_TRANSPARENT_INDEX);
      pixel = (transP + 1) % 2;
      red = glutGetColor(pixel, GLUT_RED) + 0.2;
      if (red > 1.0)
        red = red - 1.0;
      green = glutGetColor(pixel, GLUT_GREEN) - 0.1;
      if (green > 1.0)
        green = green - 1.0;
      blue = glutGetColor(pixel, GLUT_BLUE) + 0.1;
      if (blue > 1.0)
        blue = blue - 1.0;
      glutSetColor(pixel, red, green, blue);
    }
    break;
  case 'h':
    glutSetWindow(hidden_w);
    glutHideWindow();
    glutSetWindow(s2);
    glutHideWindow();
    break;
  case 's':
    glutSetWindow(hidden_w);
    glutShowWindow();
    glutSetWindow(s2);
    glutShowWindow();
    break;
  case 'H':
    glutHideOverlay();
    break;
  case 'S':
    glutShowOverlay();
    break;
  case 'D':
    glutDestroyWindow(main_w);
    exit(0);
    break;
  case ' ':
    printf("overlay possible: %d\n", glutLayerGet(GLUT_OVERLAY_POSSIBLE));
    printf("layer in  use: %d\n", glutLayerGet(GLUT_LAYER_IN_USE));
    printf("has overlay: %d\n", glutLayerGet(GLUT_HAS_OVERLAY));
    printf("transparent index: %d\n", glutLayerGet(GLUT_TRANSPARENT_INDEX));
    break;
  }
}
//-----------------------------------------------------------------------------
// show our glut window (set us first)
//-----------------------------------------------------------------------------
void GlutDisplay::show()
{
   glutSetWindow(winId);
   glutShowWindow();
}