Add support to move the Preview window with a styles/pen on Windows

Fix part of https://github.com/aseprite/aseprite/issues/2783
This commit is contained in:
David Capello 2021-08-12 16:25:20 -03:00
parent ecbd13caf3
commit 8b5d7be104
4 changed files with 33 additions and 4 deletions

2
laf

@ -1 +1 @@
Subproject commit 14e0c17207868c2473571232b5f63d6ede9044a7
Subproject commit d76cc1af5564ed510fb31270d06f36dc1e426f40

View File

@ -212,7 +212,7 @@ int init_module_gui()
// messages, and flip the window.
os::instance()->handleWindowResize =
[](os::Window* window) {
Display* display = manager->getDisplayFromNativeWindow(window);
Display* display = Manager::getDisplayFromNativeWindow(window);
if (!display)
display = manager->display();
ASSERT(display);

View File

@ -161,6 +161,29 @@ public:
}
};
os::Hit handle_native_hittest(os::Window* osWindow,
const gfx::Point& pos)
{
Display* display = Manager::getDisplayFromNativeWindow(osWindow);
if (display) {
auto window = static_cast<Window*>(display->containedWidget());
switch (window->hitTest(pos)) {
case HitTestNowhere: return os::Hit::Content;
case HitTestCaption: return os::Hit::TitleBar;
case HitTestClient: return os::Hit::Content;
case HitTestBorderNW: return os::Hit::TopLeft;
case HitTestBorderN: return os::Hit::Top;
case HitTestBorderNE: return os::Hit::TopRight;
case HitTestBorderE: return os::Hit::Right;
case HitTestBorderSE: return os::Hit::BottomRight;
case HitTestBorderS: return os::Hit::Bottom;
case HitTestBorderSW: return os::Hit::BottomLeft;
case HitTestBorderW: return os::Hit::Left;
}
}
return os::Hit::None;
}
} // anonymous namespace
// static
@ -245,7 +268,8 @@ Manager::~Manager()
}
}
Display* Manager::getDisplayFromNativeWindow(os::Window* window) const
// static
Display* Manager::getDisplayFromNativeWindow(os::Window* window)
{
if (window)
return window->userData<Display>();
@ -1359,6 +1383,10 @@ void Manager::_openWindow(Window* window, bool center)
// Move all widgets to the os::Display origin (0,0)
window->offsetWidgets(-window->origin().x, -window->origin().y);
// Handle native hit testing. Required to be able to move/resize
// a window with a non-mouse pointer (e.g. stylus) on Windows.
newNativeWindow->handleHitTest = handle_native_hittest;
}
else {
// Same display for desktop window or when multiple displays is

View File

@ -37,7 +37,8 @@ namespace ui {
~Manager();
Display* display() const { return &const_cast<Manager*>(this)->m_display; }
Display* getDisplayFromNativeWindow(os::Window* window) const;
static Display* getDisplayFromNativeWindow(os::Window* window);
// Executes the main message loop.
void run();