1
0
Fork 0

- improve comments (contents and spelling)

- fix bad indentation (mixed 2/4 spaces or tabs/spaces)
This commit is contained in:
mfranz 2008-04-29 14:49:44 +00:00
parent 3842fa0edc
commit 2ece66aded

View file

@ -15,9 +15,9 @@ const int displayStatsKey = 1;
const int printStatsKey = 2; const int printStatsKey = 2;
// The manipulator is responsible for updating a Viewer's camera. It's // The manipulator is responsible for updating a Viewer's camera. Its
// event handling method is also a convenient place to run the the FG // event handling method is also a convenient place to run the FG idle
// idle and draw handlers. // and draw handlers.
FGManipulator::FGManipulator() : FGManipulator::FGManipulator() :
idleHandler(0), idleHandler(0),
@ -39,9 +39,9 @@ FGManipulator::FGManipulator() :
statsHandler->setKeyEventPrintsOutStats(printStatsKey); statsHandler->setKeyEventPrintsOutStats(printStatsKey);
statsEvent->setEventType(GUIEventAdapter::KEYDOWN); statsEvent->setEventType(GUIEventAdapter::KEYDOWN);
// OSG reports KeyPad keycodes independent of the NumLock modifier. // OSG reports NumPad keycodes independent of the NumLock modifier.
// KP-4/KP-Left is always KEY_KP_Left (ff96), so we have to generate // Both KP-4 and KP-Left are reported as KEY_KP_Left (0xff96), so we
// the locked keys ourselves. // have to generate the locked keys ourselves.
numlockKeyMap[GUIEventAdapter::KEY_KP_Insert] = '0'; numlockKeyMap[GUIEventAdapter::KEY_KP_Insert] = '0';
numlockKeyMap[GUIEventAdapter::KEY_KP_End] = '1'; numlockKeyMap[GUIEventAdapter::KEY_KP_End] = '1';
numlockKeyMap[GUIEventAdapter::KEY_KP_Down] = '2'; numlockKeyMap[GUIEventAdapter::KEY_KP_Down] = '2';
@ -72,7 +72,7 @@ osg::Matrixd FGManipulator::getMatrix() const
osg::Matrixd FGManipulator::getInverseMatrix() const osg::Matrixd FGManipulator::getInverseMatrix() const
{ {
return (osg::Matrixd::translate(-position) return (osg::Matrixd::translate(-position)
* osg::Matrixd::rotate(attitude.inverse())) ; * osg::Matrixd::rotate(attitude.inverse())) ;
} }
// Not used, but part of the interface. // Not used, but part of the interface.
@ -80,7 +80,7 @@ void FGManipulator::setNode(osg::Node* node)
{ {
_node = node; _node = node;
} }
const osg::Node* FGManipulator::getNode() const const osg::Node* FGManipulator::getNode() const
{ {
return _node.get(); return _node.get();
@ -91,7 +91,7 @@ osg::Node* FGManipulator::getNode()
return _node.get(); return _node.get();
} }
// All the usual translation from window system to FG / plib // Translate OSG modifier mask to FG modifier mask.
static int osgToFGModifiers(int modifiers) static int osgToFGModifiers(int modifiers)
{ {
int result = 0; int result = 0;
@ -116,7 +116,7 @@ static int osgToFGModifiers(int modifiers)
} }
void FGManipulator::init(const osgGA::GUIEventAdapter& ea, void FGManipulator::init(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& us) osgGA::GUIActionAdapter& us)
{ {
currentModifiers = osgToFGModifiers(ea.getModKeyMask()); currentModifiers = osgToFGModifiers(ea.getModKeyMask());
(void)handle(ea, us); (void)handle(ea, us);
@ -126,73 +126,73 @@ static bool
eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us, eventToViewport(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us,
int& x, int& y) int& x, int& y)
{ {
x = -1; x = -1;
y = -1; y = -1;
const osgViewer::Viewer* viewer; const osgViewer::Viewer* viewer;
viewer = dynamic_cast<const osgViewer::Viewer*>(&us); viewer = dynamic_cast<const osgViewer::Viewer*>(&us);
if (!viewer) if (!viewer)
return false; return false;
float lx, ly; float lx, ly;
const osg::Camera* camera; const osg::Camera* camera;
camera = viewer->getCameraContainingPosition(ea.getX(), ea.getY(), lx, ly); camera = viewer->getCameraContainingPosition(ea.getX(), ea.getY(), lx, ly);
if (!(camera && fgOSIsMainCamera(camera))) if (!(camera && fgOSIsMainCamera(camera)))
return false; return false;
x = int(lx); x = int(lx);
y = int(camera->getViewport()->height() - ly); y = int(camera->getViewport()->height() - ly);
return true; return true;
} }
bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea, bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& us) osgGA::GUIActionAdapter& us)
{ {
int x = 0; int x = 0;
int y = 0; int y = 0;
handleStats(us);
switch (ea.getEventType()) { switch (ea.getEventType()) {
case osgGA::GUIEventAdapter::FRAME: case osgGA::GUIEventAdapter::FRAME:
if (idleHandler) if (idleHandler)
(*idleHandler)(); (*idleHandler)();
if (drawHandler) if (drawHandler)
(*drawHandler)(); (*drawHandler)();
mouseWarped = false; mouseWarped = false;
return true; handleStats(us);
return true;
case osgGA::GUIEventAdapter::KEYDOWN: case osgGA::GUIEventAdapter::KEYDOWN:
case osgGA::GUIEventAdapter::KEYUP: case osgGA::GUIEventAdapter::KEYUP:
{ {
int key, modmask; int key, modmask;
handleKey(ea, key, modmask); handleKey(ea, key, modmask);
eventToViewport(ea, us, x, y); eventToViewport(ea, us, x, y);
if (keyHandler) if (keyHandler)
(*keyHandler)(key, modmask, x, y); (*keyHandler)(key, modmask, x, y);
return true; return true;
} }
case osgGA::GUIEventAdapter::PUSH: case osgGA::GUIEventAdapter::PUSH:
case osgGA::GUIEventAdapter::RELEASE: case osgGA::GUIEventAdapter::RELEASE:
{ {
bool mainWindow = eventToViewport(ea, us, x, y); bool mainWindow = eventToViewport(ea, us, x, y);
int button = 0; int button = 0;
switch (ea.getButton()) { switch (ea.getButton()) {
case osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON: case osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON:
button = 0; button = 0;
break; break;
case osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON: case osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON:
button = 1; button = 1;
break; break;
case osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON: case osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON:
button = 2; button = 2;
break; break;
} }
if (mouseClickHandler) if (mouseClickHandler)
(*mouseClickHandler)(button, (*mouseClickHandler)(button,
(ea.getEventType() (ea.getEventType()
== osgGA::GUIEventAdapter::RELEASE), x, y, mainWindow, &ea); == osgGA::GUIEventAdapter::RELEASE), x, y, mainWindow, &ea);
return true; return true;
} }
case osgGA::GUIEventAdapter::SCROLL: case osgGA::GUIEventAdapter::SCROLL:
{ {
@ -219,79 +219,82 @@ bool FGManipulator::handle(const osgGA::GUIEventAdapter& ea,
// events for this frame. We really want to flush the event // events for this frame. We really want to flush the event
// queue of mouse events, but don't have the ability to do // queue of mouse events, but don't have the ability to do
// that with osgViewer. // that with osgViewer.
if (mouseWarped) if (mouseWarped)
return true; return true;
if (eventToViewport(ea, us, x, y) && mouseMotionHandler) if (eventToViewport(ea, us, x, y) && mouseMotionHandler)
(*mouseMotionHandler)(x, y); (*mouseMotionHandler)(x, y);
return true; return true;
case osgGA::GUIEventAdapter::RESIZE: case osgGA::GUIEventAdapter::RESIZE:
if (resizable && windowResizeHandler) if (resizable && windowResizeHandler)
(*windowResizeHandler)(ea.getWindowWidth(), ea.getWindowHeight()); (*windowResizeHandler)(ea.getWindowWidth(), ea.getWindowHeight());
return true; return true;
case osgGA::GUIEventAdapter::CLOSE_WINDOW: case osgGA::GUIEventAdapter::CLOSE_WINDOW:
case osgGA::GUIEventAdapter::QUIT_APPLICATION: case osgGA::GUIEventAdapter::QUIT_APPLICATION:
fgOSExit(0); fgOSExit(0);
return true; return true;
default: default:
return false; return false;
} }
} }
void FGManipulator::handleKey(const osgGA::GUIEventAdapter& ea, int& key, void FGManipulator::handleKey(const osgGA::GUIEventAdapter& ea, int& key,
int& modifiers) int& modifiers)
{ {
using namespace osgGA;
key = ea.getKey(); key = ea.getKey();
// XXX Probably other translations are needed too. // XXX Probably other translations are needed too.
switch (key) { switch (key) {
case osgGA::GUIEventAdapter::KEY_Escape: key = 0x1b; break; case GUIEventAdapter::KEY_Escape: key = 0x1b; break;
case osgGA::GUIEventAdapter::KEY_Return: key = '\n'; break; case GUIEventAdapter::KEY_Return: key = '\n'; break;
case osgGA::GUIEventAdapter::KEY_BackSpace: key = '\b'; break; case GUIEventAdapter::KEY_BackSpace: key = '\b'; break;
case osgGA::GUIEventAdapter::KEY_Delete: key = 0x7f; break; case GUIEventAdapter::KEY_Delete: key = 0x7f; break;
case osgGA::GUIEventAdapter::KEY_Tab: key = '\t'; break; case GUIEventAdapter::KEY_Tab: key = '\t'; break;
case osgGA::GUIEventAdapter::KEY_Left: key = PU_KEY_LEFT; break; case GUIEventAdapter::KEY_Left: key = PU_KEY_LEFT; break;
case osgGA::GUIEventAdapter::KEY_Up: key = PU_KEY_UP; break; case GUIEventAdapter::KEY_Up: key = PU_KEY_UP; break;
case osgGA::GUIEventAdapter::KEY_Right: key = PU_KEY_RIGHT; break; case GUIEventAdapter::KEY_Right: key = PU_KEY_RIGHT; break;
case osgGA::GUIEventAdapter::KEY_Down: key = PU_KEY_DOWN; break; case GUIEventAdapter::KEY_Down: key = PU_KEY_DOWN; break;
case osgGA::GUIEventAdapter::KEY_Page_Up: key = PU_KEY_PAGE_UP; break; case GUIEventAdapter::KEY_Page_Up: key = PU_KEY_PAGE_UP; break;
case osgGA::GUIEventAdapter::KEY_Page_Down: key = PU_KEY_PAGE_DOWN; break; case GUIEventAdapter::KEY_Page_Down: key = PU_KEY_PAGE_DOWN; break;
case osgGA::GUIEventAdapter::KEY_Home: key = PU_KEY_HOME; break; case GUIEventAdapter::KEY_Home: key = PU_KEY_HOME; break;
case osgGA::GUIEventAdapter::KEY_End: key = PU_KEY_END; break; case GUIEventAdapter::KEY_End: key = PU_KEY_END; break;
case osgGA::GUIEventAdapter::KEY_Insert: key = PU_KEY_INSERT; break; case GUIEventAdapter::KEY_Insert: key = PU_KEY_INSERT; break;
case osgGA::GUIEventAdapter::KEY_F1: key = PU_KEY_F1; break; case GUIEventAdapter::KEY_F1: key = PU_KEY_F1; break;
case osgGA::GUIEventAdapter::KEY_F2: key = PU_KEY_F2; break; case GUIEventAdapter::KEY_F2: key = PU_KEY_F2; break;
case osgGA::GUIEventAdapter::KEY_F3: key = PU_KEY_F3; break; case GUIEventAdapter::KEY_F3: key = PU_KEY_F3; break;
case osgGA::GUIEventAdapter::KEY_F4: key = PU_KEY_F4; break; case GUIEventAdapter::KEY_F4: key = PU_KEY_F4; break;
case osgGA::GUIEventAdapter::KEY_F5: key = PU_KEY_F5; break; case GUIEventAdapter::KEY_F5: key = PU_KEY_F5; break;
case osgGA::GUIEventAdapter::KEY_F6: key = PU_KEY_F6; break; case GUIEventAdapter::KEY_F6: key = PU_KEY_F6; break;
case osgGA::GUIEventAdapter::KEY_F7: key = PU_KEY_F7; break; case GUIEventAdapter::KEY_F7: key = PU_KEY_F7; break;
case osgGA::GUIEventAdapter::KEY_F8: key = PU_KEY_F8; break; case GUIEventAdapter::KEY_F8: key = PU_KEY_F8; break;
case osgGA::GUIEventAdapter::KEY_F9: key = PU_KEY_F9; break; case GUIEventAdapter::KEY_F9: key = PU_KEY_F9; break;
case osgGA::GUIEventAdapter::KEY_F10: key = PU_KEY_F10; break; case GUIEventAdapter::KEY_F10: key = PU_KEY_F10; break;
case osgGA::GUIEventAdapter::KEY_F11: key = PU_KEY_F11; break; case GUIEventAdapter::KEY_F11: key = PU_KEY_F11; break;
case osgGA::GUIEventAdapter::KEY_F12: key = PU_KEY_F12; break; case GUIEventAdapter::KEY_F12: key = PU_KEY_F12; break;
case osgGA::GUIEventAdapter::KEY_KP_Delete: key = '.'; break; case GUIEventAdapter::KEY_KP_Delete: key = '.'; break;
case osgGA::GUIEventAdapter::KEY_KP_Enter: key = '\r'; break; case GUIEventAdapter::KEY_KP_Enter: key = '\r'; break;
case osgGA::GUIEventAdapter::KEY_KP_Add: key = '+'; break; case GUIEventAdapter::KEY_KP_Add: key = '+'; break;
case osgGA::GUIEventAdapter::KEY_KP_Divide: key = '/'; break; case GUIEventAdapter::KEY_KP_Divide: key = '/'; break;
case osgGA::GUIEventAdapter::KEY_KP_Multiply: key = '*'; break; case GUIEventAdapter::KEY_KP_Multiply: key = '*'; break;
case osgGA::GUIEventAdapter::KEY_KP_Subtract: key = '-'; break; case GUIEventAdapter::KEY_KP_Subtract: key = '-'; break;
} }
osgGA::GUIEventAdapter::EventType eventType = ea.getEventType(); osgGA::GUIEventAdapter::EventType eventType = ea.getEventType();
std::map<int, int>::iterator numPadIter = numlockKeyMap.find(key); std::map<int, int>::iterator numPadIter = numlockKeyMap.find(key);
if (numPadIter != numlockKeyMap.end()) { if (numPadIter != numlockKeyMap.end()) {
if (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_NUM_LOCK) { if (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_NUM_LOCK) {
key = numPadIter->second; key = numPadIter->second;
} }
} }
modifiers = osgToFGModifiers(ea.getModKeyMask()); modifiers = osgToFGModifiers(ea.getModKeyMask());
currentModifiers = modifiers; currentModifiers = modifiers;
if (eventType == osgGA::GUIEventAdapter::KEYUP) if (eventType == osgGA::GUIEventAdapter::KEYUP)
modifiers |= KEYMOD_RELEASED; modifiers |= KEYMOD_RELEASED;
// Release the letter key, for which the keypress was reported // Release the letter key, for which the key press was reported. This
// is to deal with Ctrl-press -> a-press -> Ctrl-release -> a-release
// correctly.
if (key >= 0 && key < 128) { if (key >= 0 && key < 128) {
if (modifiers & KEYMOD_RELEASED) { if (modifiers & KEYMOD_RELEASED) {
key = release_keys[key]; key = release_keys[key];
@ -320,7 +323,7 @@ void FGManipulator::handleStats(osgGA::GUIActionAdapter& us)
if (type != statsType) { if (type != statsType) {
statsEvent->setKey(displayStatsKey); statsEvent->setKey(displayStatsKey);
do { do {
statsType = ++statsType % osgViewer::StatsHandler::LAST; statsType = (statsType + 1) % osgViewer::StatsHandler::LAST;
statsHandler->handle(*statsEvent, us); statsHandler->handle(*statsEvent, us);
} while (statsType != type); } while (statsType != type);