/**
*  @brief
*    Initializes the window connection
*/
void WindowConnection::Initialize(const DisplayMode *pDisplayMode, bool bFullscreen)
{
    // De-init window
    DeInit();

    // Display mode information given?
    if (pDisplayMode) {
        // Just copy over the given information
        m_sDisplayMode = *pDisplayMode;
    } else {
        // Use default settings
        m_sDisplayMode.vSize      = m_pWidget->GetSize();
        m_sDisplayMode.nColorBits = 32;
        m_sDisplayMode.nFrequency = 60;
    }

    // Initialize renderer surface handler
    InitWidget(bFullscreen);

    // Emit the initial events so other components can set their proper initial states
    if (bFullscreen)
        OnFullscreenMode();
    else
        OnDisplayMode();
}
/**
*  @brief
*    Sets a new display mode
*/
void WindowConnection::SetDisplayMode(const DisplayMode &sDisplayMode)
{
    // Even if there's no change within the display mode, the real widget size currently may be another than the display size -
    // in this situation, it's usually nice if the widget size is updated to the set display size, so, we don't perform an early escape test

    // Are we currently within fullscreen mode?
    if (IsFullscreen()) {
        // Any state change?
        if (m_sDisplayMode.vSize         != sDisplayMode.vSize      ||
                m_sDisplayMode.nColorBits    != sDisplayMode.nColorBits ||
                m_sDisplayMode.nFrequency    != sDisplayMode.nFrequency) {
            // Copy over the new settings
            m_sDisplayMode = sDisplayMode;

            // Backup information
            const SurfaceWindow *pSurface  = static_cast<SurfaceWindow*>(GetSurface());
            if (pSurface && pSurface->GetNativeWindowHandle()) {
                // Backup information
                bool			bFullscreen = IsFullscreen();
                SurfacePainter *pPainter    = GetSurface()->GetPainter();
                GetSurface()->SetPainter(nullptr, false);

                // De-init window
                DeInit();

                // Set new widget size
                m_pWidget->SetWindowState(StateNormal);
                m_pWidget->SetSize(GetDisplayMode().vSize);

                // Init widget
                InitWidget(bFullscreen);

                // Set widget into fullscreen state? (the display should now already have the proper size)
                m_pWidget->SetWindowState(StateFullscreen);

                // Set previous surface painter
                GetSurface()->SetPainter(pPainter, false);
            }
        }
    } else {
        // Just copy over the new settings
        m_sDisplayMode = sDisplayMode;
    }

    // Emit event by using the proper virtual method
    OnDisplayMode();
}
Beispiel #3
0
// OnKeyDown():
//  Called on a key-down event.  This stores the state of
//   the modifiers and actually processes the keystrokes.
void OnKeyDown(LWPanelID panel, void *data, DualKey key) {
  if( key == DK_SHIFT )
    fk_int->shift_down = true;

  if( key == DK_CTRL )
    fk_int->ctrl_down  = true;

  if( key == DK_ALT ) {
    if( fk_int->draw_bbox && !fk_int->alt_down ) {
      fk_int->quickdraw_item_list = true;
      fk_int->RedrawItemList();
    }
    fk_int->alt_down  = true;
  }

  fk_int->last_key_down = key;

  // Used to move list up/down
  int list_height = CON_H( fk_int->item_list ) - 20;
  list_height = (list_height/ fk_int->dd.item_height);
  int max_top = fk_int->sorted_items.NumElements() - list_height;

  int value;
  static bool last_was_folded = false;  // Used to determine what to do on a Fold/Unfold All

  switch( fk_int->last_key_down ) {
    case -1:                            // No key deperessed, do nothing
      break;

    case DK_SC_UP:
      if( fk_int->shift_down ) {        // Jump to the top of the Item List
        fk->SetTopItem( 0 );
        SET_INT( fk_int->item_scroll, fk->GetTopItem() );
        fk_int->RedrawItemList();
      } else if( fk_int->alt_down && fk_int->ctrl_down ) {
        ;
      } else if( fk_int->alt_down ) {   // Scroll Group List Up (1 element)
        GET_INT( fk_int->group_list, value );
        if( value > 0 ) {
          SET_INT( fk_int->group_list, --value );
          OnGroupList( fk_int->group_list, fk_int );
        }
      } else if( fk_int->ctrl_down ) {
        fk->SetTopItem( fk->GetTopItem() - list_height );
        if( fk->GetTopItem() < 0 )
          fk->SetTopItem( 0 );
        SET_INT( fk_int->item_scroll, fk->GetTopItem() );
        fk_int->RedrawItemList();
      } else {                          // Scroll Item List Up (1 element)
        fk->SetTopItem( fk->GetTopItem() - 1 );
        if( fk->GetTopItem() < 0 )
          fk->SetTopItem( 0 );
        else {
          SET_INT( fk_int->item_scroll, fk->GetTopItem() );
          fk_int->RedrawItemList();
        }
      }
      break;

    case DK_SC_DOWN:
      if( fk_int->shift_down ) {        // Jump to the bottom of the Item List
        fk->SetTopItem( max_top );
        SET_INT( fk_int->item_scroll, fk->GetTopItem() );
        fk_int->RedrawItemList();
      } else if( fk_int->alt_down && fk_int->ctrl_down ) {
        ;
      } else if( fk_int->alt_down ) {   // Scroll Group List Down (1 element)
        GET_INT( fk_int->group_list, value );
        if( value < (int)fk->GetGroupList().NumElements() - 2 ) {   // Don't go to (new group)!
          SET_INT( fk_int->group_list, ++value );
          OnGroupList( fk_int->group_list, fk_int );
        }
      } else if( fk_int->ctrl_down ) {  // Scroll Item List Down (1 page)
        fk->SetTopItem( fk->GetTopItem() + list_height );
        if( fk->GetTopItem() > max_top )
          fk->SetTopItem( max_top );
        SET_INT( fk_int->item_scroll, fk->GetTopItem() );
        fk_int->RedrawItemList();
      } else {                          // Scroll Item List Down (1 element)
        fk->SetTopItem( fk->GetTopItem() + 1 );
        if( fk->GetTopItem() > max_top )
          fk->SetTopItem( max_top );
        else {
          SET_INT( fk_int->item_scroll, fk->GetTopItem() );
          fk_int->RedrawItemList();
        }
      }
      break;

    case DK_RETURN:
    case DK_PAD_ENTER:
    case '\r':
      if( fk_int->shift_down )          // Add selected to group (Apply)
        OnGroupEditApply( fk_int->group_edit_apply, fk_int );
      else                              // Add to selection (Apply)
        OnApplySelection( fk_int->apply_select_item_name, fk_int );
      break;

    case DK_F1:                         // Keyboard Help
    case DK_HELP:
      OnF1( fk_int->f1, fk_int );
      break;

    case DK_CHAR('='):                  // Add a New Group
    case DK_CHAR('+'):
      fk->SetCurrentGroup( fk->GetGroupList().NumElements() - 1 );
      OnGroupList( fk_int->group_list, fk_int );
      break;

    case DK_CHAR('-'):                  // Remove an Existing Group
      OnGroupDel( fk_int->group_delete, fk_int );
      break;

    case DK_CHAR('['):                  // Scroll Selection Mode Up (1 element)
      GET_INT( fk_int->select_item_mode, value );
      if( value > 0 ) {
        SET_INT( fk_int->select_item_mode, --value );
        OnSelectionMode( fk_int->select_item_mode, fk_int );
      }
      break;

    case DK_CHAR(']'):                  // Scroll Selection Mode Down (1 element)
      GET_INT( fk_int->select_item_mode, value );
      if( value < num_selection_modes - 1) {
        SET_INT( fk_int->select_item_mode, ++value );
        OnSelectionMode( fk_int->select_item_mode, fk_int );
      }
      break;

    case DK_CHAR('{'):                  // Scroll the Group Edit Mode Up (1 element)
      GET_INT( fk_int->group_edit_mode, value );
      if( value > 0 )
        SET_INT( fk_int->group_edit_mode, --value );
      break;

    case DK_CHAR('}'):                  // Scroll the Group Edit Mode Up (1 element)
      GET_INT( fk_int->group_edit_mode, value );
      if( value < num_group_edit_modes - 1 )
        SET_INT( fk_int->group_edit_mode, ++value );
      break;

    case DK_CHAR(' '):                  // Cycle Select/Deselect/Invert
      GET_INT( fk_int->select_toggle, value );
      if( value < num_selection_toggles - 1)
        SET_INT( fk_int->select_toggle, ++value );
      else
        SET_INT( fk_int->select_toggle, 0 );

      OnSelectionMode( fk_int->select_item_mode, fk_int );
      break;

    case DK_CHAR('f'):                  // Fold/Unfold Current Item
      if( fk->IsCurrentItemValid() ) {
        fk_int->sorted_items[ fk->GetCurrentItem() ]->SetFolded( !fk_int->sorted_items[ fk->GetCurrentItem() ]->GetFolded() );
        fk_int->sorted_items.Reset();                       // Rebuild item list to represent fold states
        if( fk->GetScene().GetBaseItem().GetChildren().NumElements() > 0 )
          fk->GetScene().GetBaseItem().BuildFoldedItemList( fk_int->sorted_items, true, false );

        if( fk->GetCurrentItem() > fk_int->sorted_items.NumElements() - 1 )
          fk->SetCurrentItem( fk_int->sorted_items.NumElements() - 1 );

        OnDisplayMode( fk_int->display_item_mode, fk_int );
      }
      break;

    case DK_CHAR('F'):                  // Fold/Unfold All Items
      last_was_folded = !last_was_folded;
      if( last_was_folded )
        OnFoldList( fk_int->list_fold, fk_int );
      else 
        OnUnFoldList( fk_int->list_unfold, fk_int );

      OnDisplayMode( fk_int->display_item_mode, fk_int );
      break;

    case DK_CHAR('a'):
      if( fk_int->alt_down ||           // Select All
          fk_int->ctrl_down ) {
        SelectAll();
        fk_int->RedrawItemList();
        fk_int->UpdateSelectedCount();
      }
      break;

    case DK_CHAR('/'):                  // Deselect All
      DeselectAll();
      fk_int->UpdateSelectedCount();
      fk_int->RedrawItemList();
      break;

    case DK_CHAR('c'):
      if( fk_int->alt_down ) {          // Select Children
        SelectChildren();
        fk_int->UpdateSelectedCount();
      } else {                          // Select Current And It's Children
        fk_int->UpdateSelectedCount();
        SelectItem( fk_int->sorted_items[ fk->GetCurrentItem() ], true );
      }

      fk_int->RedrawItemList();
      break;

    case DK_CHAR('C'):                   // Deselect Current And It's Children
      DeselectItem( fk_int->sorted_items[ fk->GetCurrentItem() ], true );
      fk_int->UpdateSelectedCount();
      fk_int->RedrawItemList();
      break;

    case DK_CHAR('g'):
      if( fk_int->alt_down ||            // Add Selected To Group
          fk_int->ctrl_down ) {
        SetSelectionToGroup( fk->GetCurrentGroup() );
        fk_int->RedrawItemList();
      } else {                           // Select all in group
        SelectAllInGroup( fk->GetCurrentGroup(), false );
        fk_int->RedrawItemList();
      }
      break;

    case DK_CHAR('G'):                   // Deselect all in group
      DeselectAllInGroup( fk->GetCurrentGroup(), false );
      fk_int->UpdateSelectedCount();
      fk_int->RedrawItemList();
      break;

    case DK_CHAR( 9 ):                   // Cyle Display Mode -
      GET_INT( fk_int->display_item_mode, value );
      if( fk_int->shift_down ) {         // - Backward
        if( --value < 0 ) { value = 0; }
      } else {                           // - Forward
        if( ++value > 7 ) { value = 7; }
      }

      SET_INT( fk_int->display_item_mode, value );
      OnDisplayMode( fk_int->display_item_mode, fk_int );
      break;

    case DK_CHAR( '`' ):                 // Draw Style (that's the tilde key)
      if( fk->GetDrawStyle() == DRAWSTYLE_56 ) {
        fk->SetDrawStyle( DRAWSTYLE_L6 );
        fk_int->SetStatusText( "Now using L6 Draw Style", STATUSMODE_INFO, true );
      } else {
        fk->SetDrawStyle( DRAWSTYLE_56 );
        fk_int->SetStatusText( "Now using 5.6 Draw Style", STATUSMODE_INFO, true );
      }
      SET_INT( fk_int->opt_draw_style, fk->GetDrawStyle() );
      fk_int->RedrawItemList();
      break;
  }
}