Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32 interactive resizing proof-of-concept #1296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/vsg/app/Viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ namespace vsg
/// If still active, poll for pending events and place them in the Events list and advance to the next frame, generate updated FrameStamp to signify the advancement to a new frame and return true.
virtual bool advanceToNextFrame(double simulationTime = UseTimeSinceStartPoint);

virtual bool advanceToNextFramePhaseOne();
virtual bool advanceToNextFramePhaseTwo(double simulationTime = UseTimeSinceStartPoint);

/// pass the Events into any registered EventHandlers
virtual void handleEvents();

Expand Down
2 changes: 2 additions & 0 deletions include/vsg/app/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace vsg

virtual void resize() {}

std::function<void()> resizeCallback = {};

ref_ptr<WindowTraits> traits() { return _traits; }
const ref_ptr<WindowTraits> traits() const { return _traits; }

Expand Down
25 changes: 25 additions & 0 deletions src/vsg/app/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ void Viewer::addWindow(ref_ptr<Window> window)
if (itr != _windows.end()) return;

_windows.push_back(window);

window->resizeCallback = [this]() {
advanceToNextFramePhaseTwo();
handleEvents();
update();
recordAndSubmit();
present();
};
}

void Viewer::removeWindow(ref_ptr<Window> window)
Expand All @@ -88,6 +96,8 @@ void Viewer::removeWindow(ref_ptr<Window> window)

_windows.erase(itr);

window->resizeCallback = nullptr;

// create a new list of CommandGraphs not associated with removed window
CommandGraphs commandGraphs;
for (const auto& task : recordAndSubmitTasks)
Expand Down Expand Up @@ -153,6 +163,14 @@ bool Viewer::pollEvents(bool discardPreviousEvents)
}

bool Viewer::advanceToNextFrame(double simulationTime)
{
if (!advanceToNextFramePhaseOne())
return false;

return advanceToNextFramePhaseTwo(simulationTime);
}

bool vsg::Viewer::advanceToNextFramePhaseOne()
{
static constexpr SourceLocation s_frame_source_location{"Viewer advanceToNextFrame", VsgFunctionName, __FILE__, __LINE__, COLOR_VIEWER, 1};

Expand All @@ -167,6 +185,13 @@ bool Viewer::advanceToNextFrame(double simulationTime)
// poll all the windows for events.
pollEvents(true);

return true;
}

bool vsg::Viewer::advanceToNextFramePhaseTwo(double simulationTime)
{
static constexpr SourceLocation s_frame_source_location{"Viewer advanceToNextFrame", VsgFunctionName, __FILE__, __LINE__, COLOR_VIEWER, 1};

if (!acquireNextFrame()) return false;

// create FrameStamp for frame
Expand Down
2 changes: 2 additions & 0 deletions src/vsg/platform/win32/Win32_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ bool Win32_Window::handleWin32Messages(UINT msg, WPARAM wParam, LPARAM lParam)
_windowMapped = false;
return true;
case WM_PAINT:
if (resizeCallback)
resizeCallback();
ValidateRect(_window, NULL);
return true;
case WM_MOUSEMOVE: {
Expand Down
Loading