mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-28 06:49:32 -05:00
More work on transitioning to windowwrapper for keyboard and mouse interaction
This commit is contained in:
@@ -689,44 +689,33 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
_renderEngine->postSynchronizationPreDraw();
|
||||
|
||||
|
||||
if (_isMaster && _gui->isEnabled()) {
|
||||
if (_isMaster && _gui->isEnabled() && _windowHandler->isRegularRendering()) {
|
||||
glm::vec2 mousePosition = _windowHandler->mousePosition();
|
||||
glm::ivec2 windowResolution = _windowHandler->currentWindowResolution();
|
||||
uint32_t mouseButtons = _windowHandler->mouseButtons(2);
|
||||
|
||||
double dt = _windowHandler->averageDeltaTime();
|
||||
|
||||
int button0 = sgct::Engine::instance()->getMouseButton(0, 0);
|
||||
int button1 = sgct::Engine::instance()->getMouseButton(0, 1);
|
||||
bool buttons[2] = { button0 != 0, button1 != 0 };
|
||||
|
||||
double dt = std::max(sgct::Engine::instance()->getDt(), 1.0/60.0);
|
||||
_gui->startFrame(static_cast<float>(dt), glm::vec2(windowResolution), mousePosition, buttons);
|
||||
_gui->startFrame(static_cast<float>(dt), glm::vec2(windowResolution), mousePosition, mouseButtons);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) {
|
||||
_renderEngine->render(projectionMatrix, viewMatrix);
|
||||
|
||||
if (_isMaster) {
|
||||
// If currently writing a command, render it to screen
|
||||
sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr();
|
||||
// !w->isUsingFisheyeRendering() does not exist anymore ---abock
|
||||
// if (_isMaster && !w->isUsingFisheyeRendering() && _console->isVisible()) {
|
||||
if (_isMaster && _console->isVisible()) {
|
||||
if (_isMaster && _windowHandler->isRegularRendering()) {
|
||||
if (_console->isVisible())
|
||||
_console->render();
|
||||
}
|
||||
|
||||
if (_gui->isEnabled())
|
||||
_gui->endFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::postDraw() {
|
||||
//if (_isMaster)
|
||||
//_interactionHandler.unlockControls();
|
||||
|
||||
_renderEngine->postDraw();
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::keyboardCallback(int key, int action) {
|
||||
void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) {
|
||||
if (_isMaster) {
|
||||
if (_gui->isEnabled()) {
|
||||
bool isConsumed = _gui->keyCallback(key, action);
|
||||
@@ -734,7 +723,7 @@ void OpenSpaceEngine::keyboardCallback(int key, int action) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<unsigned int>(key) == _console->commandInputButton() && (action == SGCT_PRESS || action == SGCT_REPEAT))
|
||||
if (key == _console->commandInputButton() && (action == KeyAction::Press || action == KeyAction::Release))
|
||||
_console->toggleVisibility();
|
||||
|
||||
if (!_console->isVisible()) {
|
||||
@@ -760,15 +749,15 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint) {
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::mouseButtonCallback(int key, int action) {
|
||||
void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action) {
|
||||
if (_isMaster) {
|
||||
if (_gui->isEnabled()) {
|
||||
bool isConsumed = _gui->mouseButtonCallback(key, action);
|
||||
if (isConsumed && action != SGCT_RELEASE)
|
||||
bool isConsumed = _gui->mouseButtonCallback(button, action);
|
||||
if (isConsumed && action != MouseAction::Release)
|
||||
return;
|
||||
}
|
||||
|
||||
_interactionHandler->mouseButtonCallback(key, action);
|
||||
_interactionHandler->mouseButtonCallback(button, action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,20 +48,44 @@ double SGCTWindowHandler::averageDeltaTime() {
|
||||
}
|
||||
|
||||
glm::vec2 SGCTWindowHandler::mousePosition() {
|
||||
int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId();
|
||||
double posX, posY;
|
||||
sgct::Engine::instance()->getMousePos(0, &posX, &posY);
|
||||
sgct::Engine::instance()->getMousePos(id, &posX, &posY);
|
||||
return glm::vec2(posX, posY);
|
||||
}
|
||||
|
||||
uint32_t SGCTWindowHandler::mouseButtons(int maxNumber) {
|
||||
int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId();
|
||||
uint32_t result = 0;
|
||||
for (int i = 0; i < maxNumber; ++i) {
|
||||
bool button = (sgct::Engine::instance()->getMouseButton(id, i) != 0);
|
||||
if (button)
|
||||
result |= (1 << i);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
glm::ivec2 SGCTWindowHandler::currentWindowSize() {
|
||||
return glm::ivec2(0);
|
||||
return glm::ivec2(sgct::Engine::instance()->getCurrentWindowPtr()->getXResolution(),
|
||||
sgct::Engine::instance()->getCurrentWindowPtr()->getYResolution());
|
||||
}
|
||||
|
||||
glm::ivec2 SGCTWindowHandler::currentWindowResolution() {
|
||||
int x,y;
|
||||
sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y);
|
||||
sgct::Engine::instance()->getCurrentWindowPtr()->getFinalFBODimensions(x, y);
|
||||
return glm::ivec2(x, y);
|
||||
}
|
||||
|
||||
bool SGCTWindowHandler::isRegularRendering() {
|
||||
// TODO: Needs to implement the nonlinear rendering check ---abock
|
||||
|
||||
// sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr();
|
||||
// !w->isUsingFisheyeRendering() does not exist anymore ---abock
|
||||
// if (_isMaster && !w->isUsingFisheyeRendering() && _console->isVisible()) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//void forEachWindow(std::function<void (void)> function) {
|
||||
// size_t n = sgct::Engine::instance()->getNumberOfWindows();
|
||||
|
||||
Reference in New Issue
Block a user