~tomprogs/gewoopi/trunk

« back to all changes in this revision

Viewing changes to src/video/OpenGL/window.cpp

  • Committer: Thomas Geymayer
  • Date: 2010-03-26 11:56:05 UTC
  • Revision ID: tomgey@gmail.com-20100326115605-iir4j91614620ij3
Fixed .obj loading, enable grabbing and general cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
318
318
                  % glGetString(GL_VENDOR)
319
319
                  % glGetString(GL_RENDERER) );
320
320
 
 
321
    SDL_ShowCursor(0);
 
322
    SDL_WM_GrabInput(SDL_GRAB_ON);
 
323
 
321
324
    glEnable( GL_DEPTH_TEST );
322
325
    glEnable( GL_LIGHTING );
323
326
    glEnable( GL_LIGHT0 );
354
357
  //----------------------------------------------------------------------------
355
358
  void OGLWindow::processMessages()
356
359
  {
 
360
    //--------------------------------------------------------------------------
 
361
    // reset relative mouse movement
 
362
 
 
363
    static core::uint32 x_rel =
 
364
      input::Device::getId(input::Device::MOUSE, "X_REL");
 
365
    static core::uint32 y_rel =
 
366
      input::Device::getId(input::Device::MOUSE, "Y_REL");
 
367
 
 
368
    _input_manager->notifyAbsoluteChange(_mouse_id, x_rel, 0);
 
369
    _input_manager->notifyAbsoluteChange(_mouse_id, y_rel, 0);
 
370
 
 
371
    static bool has_focus = true;
 
372
 
 
373
    //--------------------------------------------------------------------------
 
374
    // and now handle the pending events
 
375
 
357
376
    SDL_Event event;
358
377
 
359
378
    while( SDL_PollEvent(&event) )
364
383
          _alive = false;
365
384
          break;
366
385
        case SDL_ACTIVEEVENT:
367
 
          if( event.active.state & SDL_APPACTIVE );
 
386
          LOG_FMT_INFO("Active: state=%d gain=%d", (int)event.active.state % (int)event.active.gain);
 
387
//SDL_APPMOUSEFOCUS 0x01        /* The app has mouse coverage */
 
388
//SDL_APPINPUTFOCUS   0x02        /* The app has input focus */
 
389
//SDL_APPACTIVE       0x04        /* The application is active */
 
390
          if( !has_focus && event.active.state && event.active.gain )
 
391
          {
 
392
            SDL_ShowCursor(0);
 
393
            SDL_WM_GrabInput(SDL_GRAB_ON);
 
394
 
 
395
            has_focus = true;
 
396
          }
368
397
          break;
369
398
        case SDL_VIDEOEXPOSE:
370
399
          break;
371
400
        case SDL_KEYDOWN:
372
401
        case SDL_KEYUP:
373
 
            _input_manager
 
402
        {
 
403
          _input_manager
374
404
              // event.key.state is 0 if released and 1 if pressed
375
405
              ->notifyAbsoluteChange( _keyboard_id,
376
406
                                      keyboard_keymap[event.key.keysym.sym],
377
407
                                      event.key.state );
378
 
            /*event.key.keysym.sym,
379
 
            event.key.state,
380
 
            event.key.which;*/
 
408
 
 
409
          // Handle system key combinations to leave grab mode
 
410
#ifdef linux
 
411
          const core::uint16 system_command = KMOD_LALT | KMOD_LCTRL;
 
412
 
 
413
          if( (event.key.keysym.mod & system_command) == system_command )
 
414
#else
 
415
          if( SDL_GetKeyState(0)[SDLK_LSUPER] )
 
416
#endif
 
417
          {
 
418
            // TODO also handle tab window change
 
419
            if( event.key.keysym.sym == SDLK_d )
 
420
            {
 
421
              // show desktop
 
422
              SDL_WM_GrabInput(SDL_GRAB_OFF);
 
423
              SDL_ShowCursor(1);
 
424
              SDL_WM_IconifyWindow();
 
425
              has_focus = false;
 
426
            }
 
427
          }
381
428
          break;
 
429
        }
382
430
        case SDL_MOUSEBUTTONDOWN:
383
431
        case SDL_MOUSEBUTTONUP:
384
432
            /*event.button.button,
386
434
            event.button.which;*/
387
435
          break;
388
436
        case SDL_MOUSEMOTION:
389
 
            /*event.motion.xrel,
390
 
            event.motion.yrel,
391
 
            event.motion.which;*/
 
437
        {
 
438
          _input_manager->notifyAbsoluteChange( _mouse_id,
 
439
                                                x_rel,
 
440
                                                event.motion.xrel );
 
441
          _input_manager->notifyAbsoluteChange( _mouse_id,
 
442
                                                y_rel,
 
443
                                                event.motion.yrel );
392
444
          break;
 
445
        }
393
446
        default:
394
447
          std::cout << "[OGL-Window] Warning: Unknown message type."
395
448
                    << std::endl;