mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Add precise trackpad support on Skia/OSX port
This commit is contained in:
parent
47f493df78
commit
2fe612fd00
@ -134,9 +134,15 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
|
|||||||
case WHEEL_HSCROLL:
|
case WHEEL_HSCROLL:
|
||||||
case WHEEL_VSCROLL: {
|
case WHEEL_VSCROLL: {
|
||||||
View* view = View::getView(editor);
|
View* view = View::getView(editor);
|
||||||
gfx::Rect vp = view->getViewportBounds();
|
gfx::Point scroll = view->getViewScroll();
|
||||||
gfx::Point delta(0, 0);
|
gfx::Point delta(0, 0);
|
||||||
|
|
||||||
|
if (msg->preciseWheel()) {
|
||||||
|
delta = msg->wheelDelta();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gfx::Rect vp = view->getViewportBounds();
|
||||||
|
|
||||||
if (wheelAction == WHEEL_HSCROLL) {
|
if (wheelAction == WHEEL_HSCROLL) {
|
||||||
delta.x = dz * vp.w;
|
delta.x = dz * vp.w;
|
||||||
}
|
}
|
||||||
@ -150,8 +156,8 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
|
|||||||
else {
|
else {
|
||||||
delta /= 10;
|
delta /= 10;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gfx::Point scroll = view->getViewScroll();
|
|
||||||
editor->setEditorScroll(scroll+delta, true);
|
editor->setEditorScroll(scroll+delta, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,14 @@ namespace she {
|
|||||||
|
|
||||||
typedef std::vector<std::string> Files;
|
typedef std::vector<std::string> Files;
|
||||||
|
|
||||||
Event() : m_type(None) { }
|
Event() : m_type(None),
|
||||||
|
m_display(nullptr),
|
||||||
|
m_scancode(kKeyNil),
|
||||||
|
m_unicodeChar(0),
|
||||||
|
m_repeat(0),
|
||||||
|
m_preciseWheel(false),
|
||||||
|
m_button(NoneButton) {
|
||||||
|
}
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
Display* display() const { return m_display; }
|
Display* display() const { return m_display; }
|
||||||
@ -56,6 +63,7 @@ namespace she {
|
|||||||
int repeat() const { return m_repeat; }
|
int repeat() const { return m_repeat; }
|
||||||
gfx::Point position() const { return m_position; }
|
gfx::Point position() const { return m_position; }
|
||||||
gfx::Point wheelDelta() const { return m_wheelDelta; }
|
gfx::Point wheelDelta() const { return m_wheelDelta; }
|
||||||
|
bool preciseWheel() const { return m_preciseWheel; }
|
||||||
MouseButton button() const { return m_button; }
|
MouseButton button() const { return m_button; }
|
||||||
|
|
||||||
void setType(Type type) { m_type = type; }
|
void setType(Type type) { m_type = type; }
|
||||||
@ -67,6 +75,7 @@ namespace she {
|
|||||||
void setRepeat(int repeat) { m_repeat = repeat; }
|
void setRepeat(int repeat) { m_repeat = repeat; }
|
||||||
void setPosition(const gfx::Point& pos) { m_position = pos; }
|
void setPosition(const gfx::Point& pos) { m_position = pos; }
|
||||||
void setWheelDelta(const gfx::Point& delta) { m_wheelDelta = delta; }
|
void setWheelDelta(const gfx::Point& delta) { m_wheelDelta = delta; }
|
||||||
|
void setPreciseWheel(bool precise) { m_preciseWheel = precise; }
|
||||||
void setButton(MouseButton button) { m_button = button; }
|
void setButton(MouseButton button) { m_button = button; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -78,6 +87,7 @@ namespace she {
|
|||||||
int m_repeat; // repeat=0 means the first time the key is pressed
|
int m_repeat; // repeat=0 means the first time the key is pressed
|
||||||
gfx::Point m_position;
|
gfx::Point m_position;
|
||||||
gfx::Point m_wheelDelta;
|
gfx::Point m_wheelDelta;
|
||||||
|
bool m_preciseWheel;
|
||||||
MouseButton m_button;
|
MouseButton m_button;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
- (void)handleMouseDown:(NSEvent*)event;
|
- (void)handleMouseDown:(NSEvent*)event;
|
||||||
- (void)handleMouseUp:(NSEvent*)event;
|
- (void)handleMouseUp:(NSEvent*)event;
|
||||||
- (void)handleMouseDragged:(NSEvent*)event;
|
- (void)handleMouseDragged:(NSEvent*)event;
|
||||||
|
- (void)scrollWheel:(NSEvent*)event;
|
||||||
- (void)setFrameSize:(NSSize)newSize;
|
- (void)setFrameSize:(NSSize)newSize;
|
||||||
- (void)createMouseTrackingArea;
|
- (void)createMouseTrackingArea;
|
||||||
- (void)destroyMouseTrackingArea;
|
- (void)destroyMouseTrackingArea;
|
||||||
|
@ -25,7 +25,6 @@ inline gfx::Point get_local_mouse_pos(NSView* view, NSEvent* event)
|
|||||||
NSPoint point = [view convertPoint:[event locationInWindow]
|
NSPoint point = [view convertPoint:[event locationInWindow]
|
||||||
fromView:nil];
|
fromView:nil];
|
||||||
int scale = 1;
|
int scale = 1;
|
||||||
|
|
||||||
if ([view window])
|
if ([view window])
|
||||||
scale = [(OSXWindow*)[view window] scale];
|
scale = [(OSXWindow*)[view window] scale];
|
||||||
|
|
||||||
@ -286,6 +285,30 @@ inline Event::MouseButton get_mouse_buttons(NSEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)scrollWheel:(NSEvent*)event
|
||||||
|
{
|
||||||
|
Event ev;
|
||||||
|
ev.setType(Event::MouseWheel);
|
||||||
|
ev.setPosition(get_local_mouse_pos(self, event));
|
||||||
|
ev.setButton(get_mouse_buttons(event));
|
||||||
|
|
||||||
|
int scale = 1;
|
||||||
|
if (self.window)
|
||||||
|
scale = [(OSXWindow*)self.window scale];
|
||||||
|
|
||||||
|
if (event.hasPreciseScrollingDeltas) {
|
||||||
|
ev.setWheelDelta(gfx::Point(-event.scrollingDeltaX / scale,
|
||||||
|
-event.scrollingDeltaY / scale));
|
||||||
|
ev.setPreciseWheel(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ev.setWheelDelta(gfx::Point(-event.scrollingDeltaX,
|
||||||
|
-event.scrollingDeltaY));
|
||||||
|
}
|
||||||
|
|
||||||
|
queue_event(ev);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)createMouseTrackingArea
|
- (void)createMouseTrackingArea
|
||||||
{
|
{
|
||||||
// Create a tracking area to receive mouseMoved events
|
// Create a tracking area to receive mouseMoved events
|
||||||
|
@ -367,7 +367,8 @@ void Manager::generateMessagesFromSheEvents()
|
|||||||
}
|
}
|
||||||
|
|
||||||
case she::Event::MouseWheel: {
|
case she::Event::MouseWheel: {
|
||||||
handleMouseWheel(sheEvent.position(), m_mouseButtons, sheEvent.wheelDelta());
|
handleMouseWheel(sheEvent.position(), m_mouseButtons,
|
||||||
|
sheEvent.wheelDelta(), sheEvent.preciseWheel());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,12 +435,13 @@ void Manager::handleMouseDoubleClick(const gfx::Point& mousePos, MouseButtons mo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::handleMouseWheel(const gfx::Point& mousePos, MouseButtons mouseButtons, const gfx::Point& wheelDelta)
|
void Manager::handleMouseWheel(const gfx::Point& mousePos, MouseButtons mouseButtons,
|
||||||
|
const gfx::Point& wheelDelta, bool preciseWheel)
|
||||||
{
|
{
|
||||||
enqueueMessage(newMouseMessage(
|
enqueueMessage(newMouseMessage(
|
||||||
kMouseWheelMessage,
|
kMouseWheelMessage,
|
||||||
(capture_widget ? capture_widget: mouse_widget),
|
(capture_widget ? capture_widget: mouse_widget),
|
||||||
mousePos, mouseButtons, wheelDelta));
|
mousePos, mouseButtons, wheelDelta, preciseWheel));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles Z order: Send the window to top (only when you click in a
|
// Handles Z order: Send the window to top (only when you click in a
|
||||||
@ -1336,11 +1338,14 @@ Widget* Manager::findMagneticWidget(Widget* widget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
Message* Manager::newMouseMessage(MessageType type,
|
Message* Manager::newMouseMessage(
|
||||||
|
MessageType type,
|
||||||
Widget* widget, const gfx::Point& mousePos,
|
Widget* widget, const gfx::Point& mousePos,
|
||||||
MouseButtons buttons, const gfx::Point& wheelDelta)
|
MouseButtons buttons,
|
||||||
|
const gfx::Point& wheelDelta, bool preciseWheel)
|
||||||
{
|
{
|
||||||
Message* msg = new MouseMessage(type, buttons, mousePos, wheelDelta);
|
Message* msg = new MouseMessage(type, buttons, mousePos,
|
||||||
|
wheelDelta, preciseWheel);
|
||||||
|
|
||||||
if (widget != NULL)
|
if (widget != NULL)
|
||||||
msg->addRecipient(widget);
|
msg->addRecipient(widget);
|
||||||
|
@ -106,16 +106,19 @@ namespace ui {
|
|||||||
void handleMouseDown(const gfx::Point& mousePos, MouseButtons mouseButtons);
|
void handleMouseDown(const gfx::Point& mousePos, MouseButtons mouseButtons);
|
||||||
void handleMouseUp(const gfx::Point& mousePos, MouseButtons mouseButtons);
|
void handleMouseUp(const gfx::Point& mousePos, MouseButtons mouseButtons);
|
||||||
void handleMouseDoubleClick(const gfx::Point& mousePos, MouseButtons mouseButtons);
|
void handleMouseDoubleClick(const gfx::Point& mousePos, MouseButtons mouseButtons);
|
||||||
void handleMouseWheel(const gfx::Point& mousePos, MouseButtons mouseButtons, const gfx::Point& wheelDelta);
|
void handleMouseWheel(const gfx::Point& mousePos, MouseButtons mouseButtons,
|
||||||
|
const gfx::Point& wheelDelta, bool preciseWheel);
|
||||||
void handleWindowZOrder();
|
void handleWindowZOrder();
|
||||||
|
|
||||||
void pumpQueue();
|
void pumpQueue();
|
||||||
static void removeWidgetFromRecipients(Widget* widget, Message* msg);
|
static void removeWidgetFromRecipients(Widget* widget, Message* msg);
|
||||||
static bool someParentIsFocusStop(Widget* widget);
|
static bool someParentIsFocusStop(Widget* widget);
|
||||||
static Widget* findMagneticWidget(Widget* widget);
|
static Widget* findMagneticWidget(Widget* widget);
|
||||||
static Message* newMouseMessage(MessageType type,
|
static Message* newMouseMessage(
|
||||||
|
MessageType type,
|
||||||
Widget* widget, const gfx::Point& mousePos,
|
Widget* widget, const gfx::Point& mousePos,
|
||||||
MouseButtons buttons, const gfx::Point& wheelDelta = gfx::Point(0, 0));
|
MouseButtons buttons, const gfx::Point& wheelDelta = gfx::Point(0, 0),
|
||||||
|
bool preciseWheel = false);
|
||||||
void broadcastKeyMsg(Message* msg);
|
void broadcastKeyMsg(Message* msg);
|
||||||
|
|
||||||
static Manager* m_defaultManager;
|
static Manager* m_defaultManager;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite UI Library
|
// Aseprite UI Library
|
||||||
// Copyright (C) 2001-2013 David Capello
|
// Copyright (C) 2001-2013, 2015 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -100,11 +100,13 @@ namespace ui {
|
|||||||
public:
|
public:
|
||||||
MouseMessage(MessageType type, MouseButtons buttons,
|
MouseMessage(MessageType type, MouseButtons buttons,
|
||||||
const gfx::Point& pos,
|
const gfx::Point& pos,
|
||||||
const gfx::Point& wheelDelta = gfx::Point(0, 0))
|
const gfx::Point& wheelDelta = gfx::Point(0, 0),
|
||||||
|
bool preciseWheel = false)
|
||||||
: Message(type),
|
: Message(type),
|
||||||
m_buttons(buttons),
|
m_buttons(buttons),
|
||||||
m_pos(pos),
|
m_pos(pos),
|
||||||
m_wheelDelta(wheelDelta) {
|
m_wheelDelta(wheelDelta),
|
||||||
|
m_preciseWheel(preciseWheel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseButtons buttons() const { return m_buttons; }
|
MouseButtons buttons() const { return m_buttons; }
|
||||||
@ -112,6 +114,7 @@ namespace ui {
|
|||||||
bool right() const { return (m_buttons & kButtonRight) == kButtonRight; }
|
bool right() const { return (m_buttons & kButtonRight) == kButtonRight; }
|
||||||
bool middle() const { return (m_buttons & kButtonMiddle) == kButtonMiddle; }
|
bool middle() const { return (m_buttons & kButtonMiddle) == kButtonMiddle; }
|
||||||
gfx::Point wheelDelta() const { return m_wheelDelta; }
|
gfx::Point wheelDelta() const { return m_wheelDelta; }
|
||||||
|
bool preciseWheel() const { return m_preciseWheel; }
|
||||||
|
|
||||||
const gfx::Point& position() const { return m_pos; }
|
const gfx::Point& position() const { return m_pos; }
|
||||||
|
|
||||||
@ -119,6 +122,7 @@ namespace ui {
|
|||||||
MouseButtons m_buttons; // Pressed buttons
|
MouseButtons m_buttons; // Pressed buttons
|
||||||
gfx::Point m_pos; // Mouse position
|
gfx::Point m_pos; // Mouse position
|
||||||
gfx::Point m_wheelDelta; // Wheel axis variation
|
gfx::Point m_wheelDelta; // Wheel axis variation
|
||||||
|
bool m_preciseWheel;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TimerMessage : public Message
|
class TimerMessage : public Message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user