Exemple #1
0
void CKey::OnLButtonDown(const UINT nFlags, const CPoint point) 
{
	switch (m_nKeyType) {
	case NORMAL_KEY:
		SetKeyType(PUSHED_KEY);
		SetDraggingCursor();
		break;
	case REMAPPED_KEY:
		SetKeyType(REMAPPED_PUSHED_KEY);
		break;
	}

	CButton::OnLButtonDown(nFlags, point);
}
// SMsgDirG2ModifyService::Pack
// Virtual method from SmallMessage.  Packs data into message buffer.
void*
SMsgDirG2ModifyService::Pack(void)
{
	WTRACE("SMsgDirG2ModifyService::Pack");
	SetKeyType(KT_SERVICE);
	SetServiceType(WONMsg::SmallDirServerG2);
	if (IsExtended())
	{
		SetMessageType(WONMsg::DirG2ModifyServiceEx);
		SetExtended(true, true);
	}
	else
		SetMessageType(WONMsg::DirG2ModifyService);

	SMsgDirG2UpdateExtendBase::Pack();
	AppendByte(mEntityFlags);
	PackKey(*this);
	Append_PW_STRING(mNewName);

	unsigned char aLen = mNewNetAddress.size();
	AppendByte(aLen);
	if (aLen > 0)
		AppendBytes(aLen, mNewNetAddress.data());

	Append_PW_STRING(mNewDisplayName);
	AppendLong(mNewLifespan);
	PackExtended();
	PackPeerData();

	return GetDataPtr();
}
// SMsgDirG2ModifyService::Unpack
// Virtual method from SmallMessage.  Extracts data from message buffer.
void
SMsgDirG2ModifyService::Unpack(void)
{
	WTRACE("SMsgDirG2ModifyService::Unpack");
	SetKeyType(KT_SERVICE);
	SetExtended((GetMessageType() != WONMsg::DirG2ModifyService), (GetMessageType() == WONMsg::DirG2ModifyServiceEx));
	SMsgDirG2UpdateExtendBase::Unpack();

	if ((GetServiceType() != WONMsg::SmallDirServerG2) ||
	    ((GetMessageType() != WONMsg::DirG2ModifyService) &&
	     (GetMessageType() != WONMsg::DirG2ModifyServiceEx) &&
		 (GetMessageType() != WONMsg::DirG2ModifyServiceExObsolete)))
	{
		WDBG_AH("SMsgDirG2ModifyService::Unpack Not a DirG2ModifyService(Ex) message!");
		throw WONMsg::BadMsgException(*this, __LINE__, __FILE__,
		                              "Not a DirG2ModifyService(Ex) message.");
	}

	mEntityFlags = ReadByte();
	UnpackKey(*this);
	ReadWString(mNewName);

	unsigned char aLen = ReadByte();
	WDBG_LL("SMsgDirG2ModifyService::Unpack Read New Addr len=" << aLen);
	if (aLen > 0)
		mNewNetAddress.assign(reinterpret_cast<const unsigned char*>(ReadBytes(aLen)), aLen);

	ReadWString(mNewDisplayName);
	mNewLifespan = ReadLong();
	UnpackExtended();
	UnpackPeerData();
}
Exemple #4
0
void CKey::OnMouseMove(const UINT nFlags, CPoint point) 
{
	if (nFlags & MK_LBUTTON) {
		ClientToScreen(&point);
		CKeyboardLayout *parent = (CKeyboardLayout *)GetParent();
		if (m_nKeyType == PUSHED_KEY) {
			int nPointedKey = parent->GetPointedKey(point);
			if (nPointedKey) {
				if (nPointedKey != m_nDroppableKey) {
					if (m_nDroppableKey) {
						reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);
						SetNoCursor();
					}
					if (IsDroppableKey(nPointedKey)) {
						m_nDroppableKey = nPointedKey;
						m_nDroppableKeyType = ((CKey*)parent->GetDlgItem(m_nDroppableKey))->GetKeyType();
						reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(DROPPABLE_KEY);
						SetDraggingCursor();
					}
				}
			} else {
				if (m_nDroppableKey) {
					reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);
					m_nDroppableKey = 0;
					m_nDroppableKeyType = NORMAL_KEY;
					SetNoCursor();
				}
			}
		}

		if (m_nKeyType == REMAPPED_PUSHED_KEY) {
			if (m_nKey != parent->GetPointedKey(point)) {
				SetKeyType(REMAPPED_KEY);
			}
		}
		if (m_nKeyType == REMAPPED_KEY) {
			if (m_nKey == parent->GetPointedKey(point)) {
				SetKeyType(REMAPPED_PUSHED_KEY);
			}
		}
	}
	
	CButton::OnMouseMove(nFlags, point);
}
void EventPollerImplSDL::Update(Listeners* pListeners)
{
  EventPollerImpl::Update(pListeners);

  // Init joysticks etc
  static bool first = true;
  if (first)
  {
    first = false;

    SDL_EnableUNICODE(1); // For getting chars from KB

    int numJs = SDL_NumJoysticks();
    for (int i = 0; i < numJs; i++)
    {
      SDL_JoystickOpen(i);  
    }
    SDL_JoystickEventState(SDL_ENABLE);
  }

  SDL_Event e;
  while (SDL_PollEvent(&e))
  {
    KeyEvent ke;
    bool isKeyEvent = false;

    // Remember x and y axis values for each joystick
    static const int MAX_NUM_JOYSTICKS = 4;
    static JoyAxisEvent je[MAX_NUM_JOYSTICKS];
    int joyNum = 0;
    bool isJoyEvent = false;

    CursorEvent ce;
    bool isCursorEvent = false;

    ButtonEvent be;
    bool isButtonEvent = false;

    MouseButtonEvent mbe;
    bool isMouseButtonEvent = false;

    bool isQuit = false;

    switch (e.type)
    {
    case SDL_QUIT:
      isQuit = true;
      QueueEvent(new QuitEvent);
      break;

    case SDL_KEYDOWN:			/* Keys pressed */
    case SDL_KEYUP:			/* Keys released */
      {
        SDL_KeyboardEvent ske = e.key;
        if (ske.keysym.sym < SDLK_NUMLOCK) // i.e. is not a modifier
        {
          SetKeyType(ske, &ke);

#ifdef _DEBUG
static const char* TYPE[] = 
{
  "char",        //AMJU_KEY_CHAR,  // printable character
  "up arrow",    //AMJU_KEY_UP,    // up arrow
  "down arrow",  //AMJU_KEY_DOWN,
  "let arrow",   //AMJU_KEY_LEFT,
  "right arrow", //AMJU_KEY_RIGHT,
  "enter",       //AMJU_KEY_ENTER,
  "space",       //AMJU_KEY_SPACE,
  "esc",         //AMJU_KEY_ESC,
  "backspace",   //AMJU_KEY_BACKSPACE,
  "delete",      //AMJU_KEY_DELETE,
};
std::cout << "Key event: type: " << TYPE[ke.keyType] << " key: " << ke.key << 
  (ke.keyDown ? " DOWN" : " UP") << "\n";
#endif

          isKeyEvent = true;
          NotifyListenersWithPriority(&ke, pListeners);
        }
        break;
      }

    case SDL_MOUSEMOTION:			/* Mouse moved */
      {
        SDL_MouseMotionEvent sme = e.motion;
        ce.controller = 0;
        // Convert screen coords to -1..1 NDCs
        ce.x = ((float)sme.x / (float)Screen::X()) * 2.0f - 1.0f;
        ce.y = (1.0f - (float)sme.y / (float)Screen::Y()) * 2.0f - 1.0f;
        isCursorEvent = true;

        NotifyListenersWithPriority(&ce, pListeners);

        break;
      }

    case SDL_MOUSEBUTTONDOWN:		/* Mouse button pressed */
    case SDL_MOUSEBUTTONUP:		/* Mouse button released */
      {
        SDL_MouseButtonEvent sme = e.button;
        mbe.x = ((float)sme.x / (float)Screen::X()) * 2.0f - 1.0f;
        mbe.y = (1.0f - (float)sme.y / (float)Screen::Y()) * 2.0f - 1.0f;
        
        if ((Uint32)sme.button == 1)
        {
          mbe.button = AMJU_BUTTON_MOUSE_LEFT;
        }
        else if ((Uint32)sme.button == 2)
        {
          mbe.button = AMJU_BUTTON_MOUSE_MIDDLE;
        }
        else if ((Uint32)sme.button == 3)
        {
          mbe.button = AMJU_BUTTON_MOUSE_RIGHT;
        }
        else
        {
          // Don't know why, but sometimes we get here
          //Assert(0);
          break;
        }
        
        mbe.isDown = (sme.state == SDL_PRESSED);
        isMouseButtonEvent = true;

        NotifyListenersWithPriority(&mbe, pListeners);

        break;
      }

    case SDL_JOYAXISMOTION:		/* Joystick axis motion */
      {
        SDL_JoyAxisEvent sje = e.jaxis;
        joyNum = sje.which;
        je[joyNum].controller = joyNum;
        if (sje.axis == 0)
        {
          je[joyNum].x = (float)(sje.value) * (1.0f/32768.0f);
          isJoyEvent = true;

          NotifyListenersWithPriority(&je[joyNum], pListeners);
        }
        else if (sje.axis == 1)
        {
          je[joyNum].y = (float)(sje.value) * (-1.0f/32768.0f);
          isJoyEvent = true;

          NotifyListenersWithPriority(&je[joyNum], pListeners);
        }
        break;
      }

    case SDL_JOYBUTTONDOWN:		/* Joystick button pressed */
    case SDL_JOYBUTTONUP:			/* Joystick button released */
      {
        SDL_JoyButtonEvent jbe = e.jbutton;
        joyNum = jbe.which;
        be.controller = joyNum;
        be.isDown = (jbe.state == SDL_PRESSED);
        // TODO Array to map SDL button num to Amju event enum
        be.button = (Button)jbe.button;
        isButtonEvent = (jbe.button <= 3); // only handle buttons 0-3 right now
          
        NotifyListenersWithPriority(&be, pListeners);
      }
      break;
    } // switch
    /*
    int eaten = AMJU_MAX_PRIORITY + 1;
    int count = 0;
    for (Listeners::iterator it = pListeners->begin(); it != pListeners->end(); ++it)
    {
      int priority = it->first;
      if (priority > eaten)
      {
        break;
      }

      EventListener* ev = it->second;
      Assert(ev);

      if (isQuit && ev->OnQuitEvent() ||
          isKeyEvent && ev->OnKeyEvent(ke) ||
          isCursorEvent && ev->OnCursorEvent(ce) ||
          isJoyEvent && ev->OnJoyAxisEvent(je[joyNum]) ||
          isButtonEvent && ev->OnButtonEvent(be) ||
          isMouseButtonEvent && ev->OnMouseButtonEvent(mbe))
      {
        eaten = it->first;
      }

      count++;
    }
    */

  } // while more events
}
Exemple #6
0
void CKey::OnLButtonUp(const UINT nFlags, CPoint point) 
{
	if (m_nKeyType == PUSHED_KEY) {
		SetKeyType(NORMAL_KEY);
	}

	CKeyboardLayout *parent = reinterpret_cast<CKeyboardLayout *>(GetParent());
	ClientToScreen(&point);
	if (m_nKeyType == REMAPPED_PUSHED_KEY) {
		if (m_nKey == parent->GetPointedKey(point)) {
			KeyboardLayout *pKeyboardLayout = parent->GetKeyboardLayout(m_nKey);
			if (pKeyboardLayout) {
				CString szWindowText;
				parent->GetDlgItem(pKeyboardLayout->nBaseControlID)->GetWindowText(szWindowText);
				SetWindowText(szWindowText);

				parent->ToolTip()->UpdateTipText(parent->GetToolTipID(pKeyboardLayout->nToolTipID), this);

				ScanCodeMapping mapping = {{0, 0}, {pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefix}};
				parent->SetScanCodeMap(m_HkeyType, mapping);
			}
			SetKeyType(ORIGINAL_KEY);
		} else {
			SetKeyType(REMAPPED_KEY);
		}
	}

	int nPointedKey = parent->GetPointedKey(point);
	if (m_nDroppableKey && nPointedKey) {
		if (m_nDroppableKey != nPointedKey) {
			reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType);
			if (IsDroppableKey(nPointedKey)) {
				m_nDroppableKey = nPointedKey;
			} else {
				m_nDroppableKey = 0;
			}
		}

		if (m_nDroppableKey) {
			KeyboardLayout *pKeyboardLayout = parent->GetKeyboardLayout(m_nDroppableKey);
			KeyboardLayout *pBaseKeyboardLayout = parent->GetKeyboardLayout(m_nKey);
			if (pKeyboardLayout && pBaseKeyboardLayout) {
				CString szWindowText;
				GetWindowText(szWindowText);
				parent->GetDlgItem(pKeyboardLayout->nCurrentControlID)->SetWindowText(szWindowText);
				parent->ToolTip()->UpdateTipText(parent->GetToolTipID(pBaseKeyboardLayout->nToolTipID), parent->GetDlgItem(pKeyboardLayout->nCurrentControlID));
				reinterpret_cast<CKey *>(parent->GetDlgItem(pKeyboardLayout->nBaseControlID))->SetKeyType(NORMAL_KEY);
				reinterpret_cast<CKey*>(parent->GetDlgItem(pKeyboardLayout->nCurrentControlID))->SetKeyType(REMAPPED_KEY);

				ScanCodeMapping mapping = {{pBaseKeyboardLayout->scancode.nScanCode, pBaseKeyboardLayout->scancode.nPrefix}, 
											{pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefix}};
				parent->SetScanCodeMap(m_HkeyType, mapping);
			}
		}
	}

	m_nDroppableKey = 0;
	m_nDroppableKeyType = NORMAL_KEY;

	SetNormalCursor();

	CButton::OnLButtonUp(nFlags, point);
}