Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Eilemann authored and Stefan Eilemann committed Oct 26, 2016
1 parent 9291968 commit e59af62
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 50 deletions.
17 changes: 9 additions & 8 deletions eq/agl/eventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace
{
uint32_t _getButtonState( const EventRef eventRef )
{
// GetCurrentEventButtonState returns the same bits as Eq buttons
uint32 buttons = GetCurrentEventButtonState();

if( buttons == PTR_BUTTON1 )
Expand Down Expand Up @@ -85,18 +86,18 @@ uint32_t _getButtonAction( const EventRef event )
}
}

uint32_t _getKeyModifiers( const EventRef event )
KeyModifier _getKeyModifiers( const EventRef event )
{
uint32_t keys = 0;
uint32_t result = 0;
GetEventParameter( eventRef, kEventParamKeyModifiers,
typeUInt32, 0, sizeof( keys ), 0, &keys );
KeyModifier result = KeyModifier::none;
GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, 0,
sizeof( keys ), 0, &keys );
if( keys & optionKey )
result |= KM_ALT;
result |= KeyModifier::alt;
if( keys & controlKey )
result |= KM_CONTROL;
result |= KeyModifier::control;
if( keys & shiftKey )
result |= KM_SHIFT;
result |= KeyModifier::shift;
return result;
}

Expand Down Expand Up @@ -377,7 +378,6 @@ bool EventHandler::_processMouseEvent( const EventRef eventRef )
event.x = static_cast< int32_t >( pos.x );
event.y = static_cast< int32_t >( pos.y ) - menuHeight;
event.modifiers = _getKeyModifiers( eventRef );
// GetCurrentEventButtonState returns the same bits as Eq buttons
event.buttons = _getButtonState( eventRef );

switch( GetEventKind( eventRef ))
Expand Down Expand Up @@ -449,6 +449,7 @@ bool EventHandler::_processKeyEvent( const EventRef eventRef )
{
KeyEvent event( _getKey( eventRef ));
event.modifiers = _getKeyModifiers( eventRef );

switch( GetEventKind( eventRef ))
{
case kEventRawKeyDown:
Expand Down
2 changes: 1 addition & 1 deletion eq/agl/eventHandler.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2007-2014, Stefan Eilemann <[email protected]>
/* Copyright (c) 2007-2016, Stefan Eilemann <[email protected]>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
Expand Down
50 changes: 44 additions & 6 deletions eq/fabric/eventEnums.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2014, Daniel Nachbaur <[email protected]>
/* Copyright (c) 2014-2016, Daniel Nachbaur <[email protected]>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
Expand All @@ -18,7 +18,9 @@
#ifndef EQFABRIC_EVENTENUMS_H
#define EQFABRIC_EVENTENUMS_H

#include <lunchbox/bitOperation.h>
#include <lunchbox/types.h>
#include <iostream>

namespace eq
{
Expand Down Expand Up @@ -99,15 +101,51 @@ enum PointerButton
* Key modifiers
* @version 2.0
*/
enum KeyModifier
enum class KeyModifier : unsigned
{
KM_NONE = LB_BIT_NONE,
KM_ALT = LB_BIT1,
KM_CONTROL = LB_BIT2,
KM_SHIFT = LB_BIT3,
none = LB_BIT_NONE,
alt = LB_BIT1,
control = LB_BIT2,
shift = LB_BIT3,
};

inline KeyModifier operator & ( const KeyModifier l, const KeyModifier r )
{
return static_cast< KeyModifier >( static_cast< unsigned >( l ) &
static_cast< unsigned >( r ));
}

inline KeyModifier operator | ( const KeyModifier l, const KeyModifier r )
{
return static_cast< KeyModifier >( static_cast< unsigned >( l ) |
static_cast< unsigned >( r ));
}

inline KeyModifier& operator |= ( KeyModifier& l, const KeyModifier r )
{
return l = l | r;
}

inline std::ostream& operator << ( std::ostream& os, const KeyModifier mod )
{
if( (mod & KeyModifier::alt) == KeyModifier::alt )
os << " alt";
if( (mod & KeyModifier::control) == KeyModifier::control )
os << " ctrl";
if( (mod & KeyModifier::shift) == KeyModifier::shift )
os << " shift";
return os;
}

}
}
}

namespace lunchbox
{
template<> inline void byteswap( eq::fabric::eventEnums::KeyModifier& value )
{
byteswap( reinterpret_cast< unsigned& >( value ));
}
}

Expand Down
12 changes: 3 additions & 9 deletions eq/fabric/keyEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@ struct KeyEvent : public Event
KeyEvent( const uint32_t k = 0 ) : key( k ) {}

uint32_t key; //!< KeyCode for special keys, ascii code otherwise
uint32_t modifiers; ; //!< key modifier mask
KeyModifier modifiers; ; //!< key modifier mask
};

/** Print the key event to the given output stream. @version 1.0 */
inline std::ostream& operator << ( std::ostream& os, const KeyEvent& event )
{
os << static_cast< const Event& >( event ) << " key " << event.key;
if( event.modifiers & KM_ALT )
os << " alt";
if( event.modifiers & KM_CONTROL )
os << " ctrl";
if( event.modifiers & KM_SHIFT )
os << " shift";
return os;
return os << static_cast< const Event& >( event ) << " key " << event.key
<< event.modifiers;
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions eq/fabric/pointerEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct PointerEvent : public Event
int32_t dy; //!< Y position change since last event
uint32_t buttons; //!< current state of all buttons
uint32_t button; //!< fired button
uint32_t modifiers; //!< state of modifier keys
KeyModifier modifiers; //!< state of modifier keys
float xAxis; //!< x wheel rotation in clicks
float yAxis; //!< y wheel rotation in clicks
RenderContext context; //!< The last rendering context at position
Expand All @@ -57,13 +57,7 @@ inline std::ostream& operator << ( std::ostream& os, const PointerEvent& event )
if( event.buttons & PTR_BUTTON4 ) os << "4";
if( event.buttons & PTR_BUTTON5 ) os << "5";

os << " modifiers";
if( event.buttons == KM_NONE ) os << " none";
if( event.buttons & KM_ALT ) os << " alt";
if( event.buttons & KM_CONTROL ) os << " ctrl";
if( event.buttons & KM_SHIFT ) os << " shift";

os << " fired ";
os << event.modifiers << " fired ";
if( event.button == PTR_BUTTON_NONE ) os << "none";
if( event.button & PTR_BUTTON1 ) os << "1";
if( event.button & PTR_BUTTON2 ) os << "2";
Expand Down
10 changes: 5 additions & 5 deletions eq/glx/eventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ uint32_t _getKey( const XEvent& event )
}
}

uint32_t _getKeyModifiers( const unsigned int state )
KeyModifier _getKeyModifiers( const unsigned int state )
{
uint32_t result = 0;
KeyModifier result = KeyModifier::none;
if( state & Mod1Mask )
result |= KM_ALT;
result |= KeyModifier::alt;
if( state & ControlMask )
result |= KM_CONTROL;
result |= KeyModifier::control;
if( state & ShiftMask )
result |= KM_SHIFT;
result |= KeyModifier::shift;
return result;
}

Expand Down
10 changes: 5 additions & 5 deletions eq/qt/eventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ uint32_t _getKey( const QKeyEvent& keyEvent )
}
}

uint32_t _getKeyModifiers( const QInputEvent& event )
KeyModifier _getKeyModifiers( const QInputEvent& event )
{
Qt::KeyboardModifiers modifiers = event.modifiers();
uint32_t result = 0;
KeyModifier result = KeyModifier::none;
if( modifiers & Qt::AltModifier )
result |= KM_ALT;
result |= KeyModifier::alt;
if( modifiers & Qt::ControlModifier )
result |= KM_CONTROL;
result |= KeyModifier::control;
if( modifiers & Qt::ShiftModifier )
result |= KM_SHIFT;
result |= KeyModifier::shift;
return result;
}

Expand Down
10 changes: 5 additions & 5 deletions eq/wgl/eventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ uint32_t _getKey( LPARAM lParam, WPARAM wParam )
return KC_VOID;
}

uint32_t _getKeyModifiers()
KeyModifier _getKeyModifiers()
{
uint32_t result = 0;
KeyModifier result = KeyModifier::none;
if( GetKeyState( VK_MENU ) & 0x8000 )
result |= KM_ALT;
result |= KeyModifier::alt;
if( GetKeyState( VK_CONTROL ) & 0x8000 )
result |= KM_CONTROL;
result |= KeyModifier::control;
if( GetKeyState( VK_SHIFT ) & 0x8000 )
result |= KM_SHIFT;
result |= KeyModifier::shift;
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion eq/wgl/eventHandler.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2007-2013, Stefan Eilemann <[email protected]>
/* Copyright (c) 2007-2016, Stefan Eilemann <[email protected]>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
Expand Down
2 changes: 1 addition & 1 deletion eq/wgl/types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2011-2012, Stefan Eilemann <[email protected]>
/* Copyright (c) 2011-2016, Stefan Eilemann <[email protected]>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
Expand Down
6 changes: 5 additions & 1 deletion examples/eqPly/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <admin/addWindow.h>
#include <admin/removeWindow.h>

using eq::KeyModifier;

namespace eqPly
{

Expand Down Expand Up @@ -674,7 +676,9 @@ bool Config::handleEvent( const eq::EventType type,
_spinX = 0;
_spinY = 0;

if( _frameData.usePilotMode())
if( (event.modifiers & KeyModifier::shift) == KeyModifier::shift )
_frameData.moveCamera( 0.f, 0.f, -.005f * event.dy );
else if( _frameData.usePilotMode())
_frameData.spinCamera( -0.005f * event.dy, -0.005f * event.dx );
else
_frameData.spinModel( -0.005f * event.dy, -0.005f * event.dx,
Expand Down

0 comments on commit e59af62

Please sign in to comment.