Gui: [skip ci] add method NavigationStyle::handleKeyboardEvent() to achieve consistent handling and reduce code duplication

This commit is contained in:
wmayer
2021-11-02 15:32:20 +01:00
parent 1c93d3ee15
commit 0b802eb717
9 changed files with 64 additions and 229 deletions

View File

@@ -118,41 +118,8 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev)
// Keyboard handling
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::R:
processed = true;
viewer->resetToHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
default:
break;
}
const SoKeyboardEvent * const event = static_cast<const SoKeyboardEvent *>(ev);
processed = handleKeyboardEvent(event, posn);
}
// Mouse Button / Spaceball Button handling

View File

@@ -122,37 +122,8 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev)
// Keyboard handling
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
default:
break;
}
const SoKeyboardEvent * const event = static_cast<const SoKeyboardEvent *>(ev);
processed = handleKeyboardEvent(event, posn);
}
// Mouse Button / Spaceball Button handling

View File

@@ -126,37 +126,8 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
// Keyboard handling
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
default:
break;
}
const SoKeyboardEvent * const event = static_cast<const SoKeyboardEvent *>(ev);
processed = handleKeyboardEvent(event, posn);
}
// Mouse Button / Spaceball Button handling

View File

@@ -1387,6 +1387,55 @@ void NavigationStyle::syncModifierKeys(const SoEvent * const ev)
}
}
SbBool NavigationStyle::handleKeyboardEvent(const SoKeyboardEvent * const event, const SbVec2f & posn)
{
SbBool processed = false;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::R:
processed = true;
viewer->resetToHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
case SoKeyboardEvent::PAGE_UP:
processed = true;
doZoom(viewer->getSoRenderManager()->getCamera(), getDelta(), posn);
break;
case SoKeyboardEvent::PAGE_DOWN:
processed = true;
doZoom(viewer->getSoRenderManager()->getCamera(), -getDelta(), posn);
break;
default:
break;
}
return processed;
}
// The viewer is a state machine, and all changes to the current state
// are made through this call.
void NavigationStyle::setViewingMode(const ViewerMode newmode)

View File

@@ -214,6 +214,7 @@ protected:
void addToLog(const SbVec2s pos, const SbTime time);
void syncModifierKeys(const SoEvent * const ev);
SbBool handleKeyboardEvent(const SoKeyboardEvent * const event, const SbVec2f & posn);
protected:
struct { // tracking mouse movement in a log

View File

@@ -118,37 +118,8 @@ SbBool OpenCascadeNavigationStyle::processSoEvent(const SoEvent * const ev)
// Keyboard handling
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
default:
break;
}
const SoKeyboardEvent * const event = static_cast<const SoKeyboardEvent *>(ev);
processed = handleKeyboardEvent(event, posn);
}
// Mouse Button / Spaceball Button handling

View File

@@ -118,37 +118,8 @@ SbBool OpenSCADNavigationStyle::processSoEvent(const SoEvent * const ev)
// Keyboard handling
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
default:
break;
}
const SoKeyboardEvent * const event = static_cast<const SoKeyboardEvent *>(ev);
processed = handleKeyboardEvent(event, posn);
}
// Mouse Button / Spaceball Button handling

View File

@@ -118,37 +118,8 @@ SbBool RevitNavigationStyle::processSoEvent(const SoEvent * const ev)
// Keyboard handling
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
default:
break;
}
const SoKeyboardEvent * const event = static_cast<const SoKeyboardEvent *>(ev);
processed = handleKeyboardEvent(event, posn);
}
// Mouse Button / Spaceball Button handling

View File

@@ -118,45 +118,8 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev)
// Keyboard handling
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
switch (event->getKey()) {
case SoKeyboardEvent::LEFT_CONTROL:
case SoKeyboardEvent::RIGHT_CONTROL:
this->ctrldown = press;
break;
case SoKeyboardEvent::LEFT_SHIFT:
case SoKeyboardEvent::RIGHT_SHIFT:
this->shiftdown = press;
break;
case SoKeyboardEvent::LEFT_ALT:
case SoKeyboardEvent::RIGHT_ALT:
this->altdown = press;
break;
case SoKeyboardEvent::H:
processed = true;
viewer->saveHomePosition();
break;
case SoKeyboardEvent::S:
case SoKeyboardEvent::HOME:
case SoKeyboardEvent::LEFT_ARROW:
case SoKeyboardEvent::UP_ARROW:
case SoKeyboardEvent::RIGHT_ARROW:
case SoKeyboardEvent::DOWN_ARROW:
if (!this->isViewing())
this->setViewing(true);
break;
case SoKeyboardEvent::PAGE_UP:
doZoom(viewer->getSoRenderManager()->getCamera(), getDelta(), posn);
processed = true;
break;
case SoKeyboardEvent::PAGE_DOWN:
doZoom(viewer->getSoRenderManager()->getCamera(), -getDelta(), posn);
processed = true;
break;
default:
break;
}
const SoKeyboardEvent * const event = static_cast<const SoKeyboardEvent *>(ev);
processed = handleKeyboardEvent(event, posn);
}
// Mouse Button / Spaceball Button handling