Crystal Space
Welcome, Guest. Please login or register.
October 21, 2014, 02:10:09 am

Login with username, password and session length
Search:     Advanced search
9010 Posts in 2044 Topics by 8765 Members
Latest Member: Damianwwnarta
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Game Content Creation
| | |-+  mouse event issues
« previous next »
Pages: [1] Print
Author Topic: mouse event issues  (Read 2498 times)
Panch
Jr. Member
**
Posts: 80


View Profile Email
« on: July 04, 2007, 04:38:35 am »

sorry for the flurry of posts, i've just been trying to patch up some final things i need. I'm having trouble getting my mouse events to work. My keyboard events work ok, but i don't seem to be catching my mouse events correctly.

Working keyboard:
Code:
// Buttons have been pressed
bool Time::OnKeyboard(iEvent& ev)
{
  // We got a keyboard event.
  csKeyEventType eventtype = csKeyEventHelper::GetEventType(&ev);
  if (eventtype == csKeyEventTypeDown)
  {
    // The user pressed a key (as opposed to releasing it).
    utf32_char code = csKeyEventHelper::GetCookedCode(&ev);
  //The user pressed tab to toggle console
if (console->IsVisible() )
        return console->HandleEvent(ev);
if (LevelFlag)
{
if (code == CSKEY_ESC)
{
if (GuiFlag)
{
HideGui();
}
else if(!GuiFlag)
{
ShowGui();
}
MouseFlag = !MouseFlag;
}
if (code == CSKEY_TAB)
{
console->Toggle();
return false;
}
}
  }
  return false;
}

Test mouse #2:
Code:
// Buttons have been pressed
bool Time::OnKeyboard(iEvent& ev)
{
  // We got a keyboard event.
  csKeyEventType eventtype = csKeyEventHelper::GetEventType(&ev);
  if (eventtype == csKeyEventTypeDown)
  {
    // The user pressed a key (as opposed to releasing it).
    utf32_char code = csKeyEventHelper::GetCookedCode(&ev);
  //The user pressed tab to toggle console
if (console->IsVisible() )
        return console->HandleEvent(ev);
if (LevelFlag)
{
if (code == CSKEY_ESC)
{
if (GuiFlag)
{
HideGui();
}
else if(!GuiFlag)
{
ShowGui();
}
MouseFlag = !MouseFlag;
}
if (code == CSKEY_TAB)
{
console->Toggle();
return false;
}
}
  }
    // We got a mouse event
  csMouseEventType MouseEvent = csMouseEventHelper::GetEventType(&ev);
  if (MouseEvent == csMouseEventTypeClick)
  {
  // The user clicked a mouse button (once)
  uint MouseKey = csMouseEventHelper::GetButton(&ev);
  if (MouseKey == csmbLeft)
  {
player_health++;
  }
  if (MouseKey == csmbRight)
  {
player_health--;
  }
  if (MouseKey == csmbMiddle)
  {
  player_health = 0;
  }
  }
  return false;
}

test mouse #1:
Code:
// Mouse button events
bool Time::OnMouse(iEvent& ev)
{
  // We got a mouse event
  csMouseEventType MouseEvent = csMouseEventHelper::GetEventType(&ev);
  if (MouseEvent == csMouseEventTypeClick)
  {
  // The user clicked a mouse button (once)
  uint MouseKey = csMouseEventHelper::GetButton(&ev);
  if (MouseKey == csmbLeft)
  {
player_health++;
  }
  if (MouseKey == csmbRight)
  {
player_health--;
  }
  if (MouseKey == csmbMiddle)
  {
  player_health = 0;
  }
  }

}

event registration:
Code:
bool Time::OnInitialize(int /*argc*/, char* /*argv*/[])
{
...

  csBaseEventHandler::Initialize(GetObjectRegistry());
  if (!RegisterQueue(GetObjectRegistry(), csevAllEvents(GetObjectRegistry())))
    return ReportError("Failed to set up event handler!");
...
}

thanks :/
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #1 on: July 05, 2007, 05:55:29 pm »

silly mistake here, that's what happens when you start programming late night Smiley

::OnMouseClick

Smiley
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.16 seconds with 17 queries.