27 G_DEFINE_TYPE(FlScrollingManager, fl_scrolling_manager, G_TYPE_OBJECT);
30 FlScrollingManager*
self = FL_SCROLLING_MANAGER(
object);
32 if (self->view_delegate !=
nullptr) {
33 g_object_remove_weak_pointer(
34 object,
reinterpret_cast<gpointer*
>(&self->view_delegate));
35 self->view_delegate =
nullptr;
38 G_OBJECT_CLASS(fl_scrolling_manager_parent_class)->dispose(
object);
48 FlScrollingViewDelegate* view_delegate) {
49 g_return_val_if_fail(FL_IS_SCROLLING_VIEW_DELEGATE(view_delegate),
nullptr);
51 FlScrollingManager*
self = FL_SCROLLING_MANAGER(
52 g_object_new(fl_scrolling_manager_get_type(),
nullptr));
54 self->view_delegate = view_delegate;
55 g_object_add_weak_pointer(
56 G_OBJECT(view_delegate),
57 reinterpret_cast<gpointer*
>(&(self->view_delegate)));
59 self->pan_started = FALSE;
60 self->zoom_started = FALSE;
61 self->rotate_started = FALSE;
69 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
75 GdkEventScroll* scroll_event,
77 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
79 GdkEvent*
event =
reinterpret_cast<GdkEvent*
>(scroll_event);
81 guint event_time = gdk_event_get_time(
event);
82 gdouble event_x = 0.0, event_y = 0.0;
83 gdk_event_get_coords(
event, &event_x, &event_y);
84 gdouble scroll_delta_x = 0.0, scroll_delta_y = 0.0;
85 GdkScrollDirection event_direction = GDK_SCROLL_SMOOTH;
86 if (gdk_event_get_scroll_direction(
event, &event_direction)) {
87 if (event_direction == GDK_SCROLL_UP) {
90 }
else if (event_direction == GDK_SCROLL_DOWN) {
93 }
else if (event_direction == GDK_SCROLL_LEFT) {
96 }
else if (event_direction == GDK_SCROLL_RIGHT) {
101 gdk_event_get_scroll_deltas(
event, &scroll_delta_x, &scroll_delta_y);
106 const int kScrollOffsetMultiplier = 53;
107 scroll_delta_x *= kScrollOffsetMultiplier * scale_factor;
108 scroll_delta_y *= kScrollOffsetMultiplier * scale_factor;
110 if (gdk_device_get_source(gdk_event_get_source_device(
event)) ==
111 GDK_SOURCE_TOUCHPAD) {
112 scroll_delta_x *= -1;
113 scroll_delta_y *= -1;
114 if (gdk_event_is_scroll_stop_event(
event)) {
117 event_x * scale_factor, event_y * scale_factor, kPanZoomEnd,
118 self->pan_x, self->pan_y, 0, 0);
119 self->pan_started = FALSE;
121 if (!self->pan_started) {
126 event_x * scale_factor, event_y * scale_factor, kPanZoomStart, 0, 0,
128 self->pan_started =
TRUE;
130 self->pan_x += scroll_delta_x;
131 self->pan_y += scroll_delta_y;
134 event_x * scale_factor, event_y * scale_factor, kPanZoomUpdate,
135 self->pan_x, self->pan_y, 1, 0);
138 self->last_x = event_x * scale_factor;
139 self->last_y = event_y * scale_factor;
142 FlutterPointerPhase::kMove
146 event_y * scale_factor, kFlutterPointerDeviceKindMouse, scroll_delta_x,
152 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
154 self->rotate_started =
TRUE;
155 if (!self->zoom_started) {
159 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
160 kPanZoomStart, 0, 0, 0, 0);
166 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
168 self->rotation = rotation;
170 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
171 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
175 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
177 self->rotate_started = FALSE;
178 if (!self->zoom_started) {
180 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
181 kPanZoomEnd, 0, 0, 0, 0);
186 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
188 self->zoom_started =
TRUE;
189 if (!self->rotate_started) {
193 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
194 kPanZoomStart, 0, 0, 0, 0);
200 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
204 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
205 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
209 g_return_if_fail(FL_IS_SCROLLING_MANAGER(
self));
211 self->zoom_started = FALSE;
212 if (!self->rotate_started) {
214 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
215 kPanZoomEnd, 0, 0, 0, 0);