Пример #1
0
	void NACLWindow::process_mouse_event( const pp::MouseInputEvent& ev )
	{
		if( ev.GetType() != PP_INPUTEVENT_TYPE_MOUSELEAVE)
		{
			int32 xPos = ev.GetPosition().x();
			int32 yPos = ev.GetPosition().y();

			Vector2 mouse_pos((float)xPos, (float)yPos);

			m_mouse.pos = mouse_pos;
			m_mouse.pos_pixels = Vector2(float(xPos), float(yPos));
		}
		else
		{
			m_mouse.buttons[0] = false;
			m_mouse.buttons[1] = false;
			m_mouse.buttons[2] = false;
		}

		uint8 button_idx  = 0;
		uint8 button_code = 0;

		switch(ev.GetButton())
		{
		case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
			button_idx  = 0;
			button_code = 1;
			break;
		case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
			button_idx  = 1;
			button_code = 2;
			break;
		case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
			button_idx  = 1;
			button_code = 4;
			break;
		}

		if(ev.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE)
		{
			listeners().broadcast(WindowEvent::MouseMove(m_mouse.pos));
		}
		else if(ev.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN)
		{
			m_keyboard.keys[button_code] = true;
			m_mouse.buttons[button_idx] = true;
			listeners().broadcast(WindowEvent::MouseDown(m_mouse.pos, button_idx, false));
		}
		else if(ev.GetType() == PP_INPUTEVENT_TYPE_MOUSEUP)
		{
			m_keyboard.keys[button_code] = false;
			m_mouse.buttons[button_idx] = false;
			listeners().broadcast(WindowEvent::MouseUp(m_mouse.pos, button_idx));
		}
	}
Пример #2
0
  bool GboxInstance::HandleMouse(const pp::MouseInputEvent& event) {
    PP_InputEvent_MouseButton button = event.GetButton();
    int32_t clicks = event.GetClickCount();
    pp::Point pt = event.GetPosition();
    int32_t type = event.GetType();

    if (sca() == 0x3)
      theLog.info("+Mouse:  ty:%d at:%d,%d but:%d clicks:%d",
            type, pt.x(), pt.y(), button, clicks);

    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN && button == 0) {
      m_mouse_down0 = pt;
      m_time_at_mouse_down0 = m_core->GetTimeTicks();
    }
    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN && button == 2) {
      m_mouse_down2 = pt;
      m_time_at_mouse_down2 = m_core->GetTimeTicks();
    }
    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE) {
      if (m_time_at_mouse_down0) {
        // drag dynamics logic
        PP_TimeTicks now = m_core->GetTimeTicks();
        bool is_drag = false;
        double dx = pt.x() - m_mouse_down0.x();
        double dy = pt.y() - m_mouse_down0.y();
        if (sqrt(dx * dx + dy * dy) > 30) is_drag = true;
        if (now - m_time_at_mouse_down0 > 0.2) is_drag = true;
        if (is_drag) {
          Drag(m_mouse_down0.x(), m_mouse_down0.y(),
                    m_mouse_down0.x() - pt.x(), m_mouse_down0.y() - pt.y(), sca());
          m_mouse_down0 = pt;
        }
      }
    }
    if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEUP) {
      PP_TimeTicks now = m_core->GetTimeTicks();
      double diff = now - (button == 0 ? m_time_at_mouse_down0 : m_time_at_mouse_down2);
      Click(pt.x(), pt.y(), button, sca(), diff);

      if (button == 0)
        m_time_at_mouse_down0 = 0;
      else
        m_time_at_mouse_down2 = 0;
    }
    return true;
  }