Example #1
0
void OptionsSpace::PerformInputs(const Input& in)
{
  if (in.Type() == Input::Key)
  {
    const KeyInput& k = static_cast<const KeyInput&>(in);
    if (k.c == GLFW_PRESS)
    {
      switch (k.a)
      {
        case GLFW_KEY_ESCAPE:
          this->UnsetStateBits(Space::Full);
          parent_->SetStateBits(Space::Full);
          break;
        case GLFW_KEY_UP:
          choice_ = choice_ > 0 ? choice_ - 1 : 1;
          break;
        case GLFW_KEY_DOWN:
          choice_ = (choice_ + 1) % 2;
          break;
        case GLFW_KEY_LEFT:
          switch (choice_)
          {
            case 0:
              snd_->SetSFXVolume(snd_->GetSFXVolume() - 5);
              break;
            case 1:
              snd_->SetMusicVolume(snd_->GetMusicVolume() - 5);
              break;
            default:
              break;
          }
          break;
        case GLFW_KEY_RIGHT:
          switch (choice_)
          {
            case 0:
              snd_->SetSFXVolume(snd_->GetSFXVolume() + 5);
              break;
            case 1:
              snd_->SetMusicVolume(snd_->GetMusicVolume() + 5);
              break;
            default:
              break;
          }
          break;
        default:
          break;
      }
    }
  }
}
Example #2
0
void Compositor::DoKey(ClientWindow *mouse_win, const Input& input) {

    ace_event_t     event;

    if (m_focussed_win) {
        if (input.Type() == INPUT_TYPE_KEY_PRESS) {
            event.type = ACE_EVTYPE_KEY_PRESS;
        }
        else {
            event.type = ACE_EVTYPE_KEY_RELEASE;
        }
        event.key.keycode     = input.Key();
        event.key.shift_state = input.ShiftState();
        //anvil_syslog(0, "Key to window (%02x)\n", key);
        m_focussed_win->AddEvent(event);
    }

}
Example #3
0
void Compositor::Deliver(const Input& input) {

    int             delta_x;
    int             delta_y;

    // Calculate m_cursor_x and delta_x
    {
        int new_x = m_cursor_x + input.DeltaX();
        if (new_x < 0) {
            new_x = 0;
        }
        if (new_x >= anvil_sysinfo->vbe_info.width) {
            new_x = anvil_sysinfo->vbe_info.width - 1;
        }
        delta_x = new_x - m_cursor_x;
        m_cursor_x = new_x;
    }

    // Calculate m_cursor_y and delta_y
    {
        int new_y = m_cursor_y - input.DeltaY();
        if (new_y < 0) {
            new_y = 0;
        }
        if (new_y >= anvil_sysinfo->vbe_info.height) {
            new_y = anvil_sysinfo->vbe_info.height - 1;
        }
        delta_y = new_y - m_cursor_y;
        m_cursor_y = new_y;
    }

    // Work out who gets the event
    ClientWindow    *event_win;
    if (m_mouse_mode == MOUSE_MODE_NONE) {
        event_win = (ClientWindow *)(m_windowlist.CheckBounds(m_cursor_x, m_cursor_y, (int&)m_cursor_type));
        if (event_win && !event_win->isResizable())
        {
            m_cursor_type = CURSOR_NORM;
        }
    }
    else {
        event_win = m_focussed_win;
    }

    //anvil_syslog(0, "Compositor::Deliver %016lx %d\n", mouse_win, cur_type);
    /*
     * We know the window but not every event goes directly to the
     * window. It depends on the mouse_mode and the shift_state
     */

    switch (input.Type()) {

        case INPUT_TYPE_KEY_PRESS:
        case INPUT_TYPE_KEY_RELEASE:
            DoKey(event_win, input);
            break;

        case INPUT_TYPE_MOUSE_DOWN:
            switch (input.Button()) {
                case INPUT_MOUSE_BTN_LEFT:
                    DoPressLeft(event_win, input);
                    break;
                case INPUT_MOUSE_BTN_MIDDLE:
                    DoPressMiddle(event_win, input);
                    break;
                case INPUT_MOUSE_BTN_RIGHT:
                    DoPressRight(event_win, input);
                    break;
            }
            break;

        case INPUT_TYPE_MOUSE_UP:
            switch (input.Button()) {
                case INPUT_MOUSE_BTN_LEFT:
                    DoReleaseLeft(event_win, input);
                    break;
                case INPUT_MOUSE_BTN_MIDDLE:
                    DoReleaseMiddle(event_win, input);
                    break;
                case INPUT_MOUSE_BTN_RIGHT:
                    DoReleaseRight(event_win, input);
                    break;
            }
            break;
        case INPUT_TYPE_MOUSE_MOVE:
            if (m_mouse_mode == MOUSE_MODE_NONE) {
                // Detect mouse entry and exit events here
            }
            else if (m_mouse_mode == MOUSE_MODE_MOVE) {
                if (m_focussed_win && m_focussed_win->isMoveable()) {
                    m_focussed_win->Move(delta_x, delta_y);
                    m_windowlist.SetDirty();
                }
            }
            else {
                if (m_focussed_win && m_focussed_win->isResizable()) {
                    // Create a resize message to the window
                    int x1, y1, x2, y2, w, h;
                    m_focussed_win->GetPos(x1, y1);
                    m_focussed_win->GetSize(w, h);
                    x2 = x1 + w;
                    y2 = y1 + h;
                    if (m_mouse_mode & MOUSE_MODE_RESIZE_L) {
                        x1 = m_cursor_x;
                        if (x1 >= x2) x1 = x2 - 1;
                    }
                    if (m_mouse_mode & MOUSE_MODE_RESIZE_T) {
                        y1 = m_cursor_y;
                        if (y1 >= y2) y1 = y2 - 1;
                    }
                    if (m_mouse_mode & MOUSE_MODE_RESIZE_R) {
                        x2 = m_cursor_x;
                        if (x2 <= x1) x2 = x1 + 1;
                    }
                    if (m_mouse_mode & MOUSE_MODE_RESIZE_B) {
                        y2 = m_cursor_y;
                        if (y2 <= y1) y2 = y1 + 1;
                    }
                    //anvil_syslog(0, "Checking move %d %d %d %d\n", x1, x2, y1, y2);
                    ace_event_t event;
                    event.type = ACE_EVTYPE_SIZE;
                    event.size.width = x2 - x1;
                    event.size.height = y2 - y1;
                    m_focussed_win->AddEvent(event);
                    m_focussed_win->setResizeMode(m_mouse_mode);
                    //m_windowlist.SetDirty();
                }
            }

            break;
    }

    ChooseCursor();

    RedoAll();
}