Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Scott Moreau |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 23 | #include "config.h" |
| 24 | |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 27 | #include "compositor.h" |
Kristian Høgsberg | 583a236 | 2012-06-25 17:13:58 -0400 | [diff] [blame] | 28 | #include "text-cursor-position-server-protocol.h" |
| 29 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 30 | static void |
| 31 | weston_zoom_frame_z(struct weston_animation *animation, |
| 32 | struct weston_output *output, uint32_t msecs) |
| 33 | { |
| 34 | if (animation->frame_counter <= 1) |
| 35 | output->zoom.spring_z.timestamp = msecs; |
| 36 | |
| 37 | weston_spring_update(&output->zoom.spring_z, msecs); |
| 38 | |
| 39 | if (output->zoom.spring_z.current > output->zoom.max_level) |
| 40 | output->zoom.spring_z.current = output->zoom.max_level; |
| 41 | else if (output->zoom.spring_z.current < 0.0) |
| 42 | output->zoom.spring_z.current = 0.0; |
| 43 | |
| 44 | if (weston_spring_done(&output->zoom.spring_z)) { |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 45 | if (output->zoom.active && output->zoom.level <= 0.0) { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 46 | output->zoom.active = 0; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 47 | output->disable_planes--; |
| 48 | } |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 49 | output->zoom.spring_z.current = output->zoom.level; |
| 50 | wl_list_remove(&animation->link); |
| 51 | wl_list_init(&animation->link); |
| 52 | } |
| 53 | |
| 54 | output->dirty = 1; |
| 55 | weston_output_damage(output); |
| 56 | } |
| 57 | |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 58 | static struct weston_seat * |
| 59 | weston_zoom_pick_seat(struct weston_compositor *compositor) |
| 60 | { |
| 61 | return container_of(compositor->seat_list.next, |
| 62 | struct weston_seat, link); |
| 63 | } |
| 64 | |
| 65 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 66 | static void |
| 67 | weston_zoom_frame_xy(struct weston_animation *animation, |
| 68 | struct weston_output *output, uint32_t msecs) |
| 69 | { |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 70 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 71 | wl_fixed_t x, y; |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 72 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 73 | if (animation->frame_counter <= 1) |
| 74 | output->zoom.spring_xy.timestamp = msecs; |
| 75 | |
| 76 | weston_spring_update(&output->zoom.spring_xy, msecs); |
| 77 | |
| 78 | x = output->zoom.from.x - ((output->zoom.from.x - output->zoom.to.x) * |
| 79 | output->zoom.spring_xy.current); |
| 80 | y = output->zoom.from.y - ((output->zoom.from.y - output->zoom.to.y) * |
| 81 | output->zoom.spring_xy.current); |
| 82 | |
| 83 | output->zoom.current.x = x; |
| 84 | output->zoom.current.y = y; |
| 85 | |
| 86 | if (weston_spring_done(&output->zoom.spring_xy)) { |
| 87 | output->zoom.spring_xy.current = output->zoom.spring_xy.target; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame^] | 88 | output->zoom.current.x = seat->pointer->x; |
| 89 | output->zoom.current.y = seat->pointer->y; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 90 | wl_list_remove(&animation->link); |
| 91 | wl_list_init(&animation->link); |
| 92 | } |
| 93 | |
| 94 | output->dirty = 1; |
| 95 | weston_output_damage(output); |
| 96 | } |
| 97 | |
| 98 | static void |
| 99 | zoom_area_center_from_pointer(struct weston_output *output, |
| 100 | wl_fixed_t *x, wl_fixed_t *y) |
| 101 | { |
| 102 | float level = output->zoom.spring_z.current; |
| 103 | wl_fixed_t offset_x = wl_fixed_from_int(output->x); |
| 104 | wl_fixed_t offset_y = wl_fixed_from_int(output->y); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 105 | wl_fixed_t w = wl_fixed_from_int(output->width); |
| 106 | wl_fixed_t h = wl_fixed_from_int(output->height); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 107 | |
| 108 | *x -= ((((*x - offset_x) / (float) w) - 0.5) * (w * (1.0 - level))); |
| 109 | *y -= ((((*y - offset_y) / (float) h) - 0.5) * (h * (1.0 - level))); |
| 110 | } |
| 111 | |
| 112 | static void |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 113 | weston_zoom_apply_output_transform(struct weston_output *output, |
| 114 | float *x, float *y) |
| 115 | { |
| 116 | float tx, ty; |
| 117 | |
| 118 | switch(output->transform) { |
| 119 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 120 | default: |
| 121 | return; |
| 122 | case WL_OUTPUT_TRANSFORM_90: |
| 123 | tx = -*y; |
| 124 | ty = *x; |
| 125 | break; |
| 126 | case WL_OUTPUT_TRANSFORM_180: |
| 127 | tx = -*x; |
| 128 | ty = -*y; |
| 129 | break; |
| 130 | case WL_OUTPUT_TRANSFORM_270: |
| 131 | tx = *y; |
| 132 | ty = -*x; |
| 133 | break; |
| 134 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 135 | tx = -*x; |
| 136 | ty = *y; |
| 137 | break; |
| 138 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 139 | tx = -*y; |
| 140 | ty = -*x; |
| 141 | break; |
| 142 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 143 | tx = *x; |
| 144 | ty = -*y; |
| 145 | break; |
| 146 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 147 | tx = *y; |
| 148 | ty = *x; |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | *x = tx; |
| 153 | *y = ty; |
| 154 | } |
| 155 | |
| 156 | static void |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 157 | weston_output_update_zoom_transform(struct weston_output *output) |
| 158 | { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 159 | float global_x, global_y; |
| 160 | wl_fixed_t x = output->zoom.current.x; |
| 161 | wl_fixed_t y = output->zoom.current.y; |
| 162 | float trans_min, trans_max; |
| 163 | float ratio, level; |
| 164 | |
| 165 | level = output->zoom.spring_z.current; |
| 166 | ratio = 1 / level; |
| 167 | |
Ander Conselvan de Oliveira | 434e8f3 | 2012-11-21 15:11:36 +0200 | [diff] [blame] | 168 | if (!output->zoom.active || level > output->zoom.max_level || |
| 169 | level == 0.0f) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 170 | return; |
| 171 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame^] | 172 | if (wl_list_empty(&output->zoom.animation_xy.link)) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 173 | zoom_area_center_from_pointer(output, &x, &y); |
| 174 | |
| 175 | global_x = wl_fixed_to_double(x); |
| 176 | global_y = wl_fixed_to_double(y); |
| 177 | |
| 178 | output->zoom.trans_x = |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 179 | ((((global_x - output->x) / output->width) * |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 180 | (level * 2)) - level) * ratio; |
| 181 | output->zoom.trans_y = |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 182 | ((((global_y - output->y) / output->height) * |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 183 | (level * 2)) - level) * ratio; |
| 184 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 185 | weston_zoom_apply_output_transform(output, &output->zoom.trans_x, |
| 186 | &output->zoom.trans_y); |
| 187 | |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 188 | trans_max = level * 2 - level; |
| 189 | trans_min = -trans_max; |
| 190 | |
| 191 | /* Clip zoom area to output */ |
| 192 | if (output->zoom.trans_x > trans_max) |
| 193 | output->zoom.trans_x = trans_max; |
| 194 | else if (output->zoom.trans_x < trans_min) |
| 195 | output->zoom.trans_x = trans_min; |
| 196 | if (output->zoom.trans_y > trans_max) |
| 197 | output->zoom.trans_y = trans_max; |
| 198 | else if (output->zoom.trans_y < trans_min) |
| 199 | output->zoom.trans_y = trans_min; |
| 200 | } |
| 201 | |
| 202 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame^] | 203 | weston_zoom_transition(struct weston_output *output, wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 204 | { |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 205 | if (output->zoom.level != output->zoom.spring_z.current) { |
| 206 | output->zoom.spring_z.target = output->zoom.level; |
| 207 | if (wl_list_empty(&output->zoom.animation_z.link)) { |
| 208 | output->zoom.animation_z.frame_counter = 0; |
| 209 | wl_list_insert(output->animation_list.prev, |
| 210 | &output->zoom.animation_z.link); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | output->dirty = 1; |
| 215 | weston_output_damage(output); |
| 216 | } |
| 217 | |
| 218 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame^] | 219 | weston_output_update_zoom(struct weston_output *output) |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 220 | { |
Kristian Høgsberg | ef6f136 | 2012-08-10 10:07:55 -0400 | [diff] [blame] | 221 | struct weston_seat *seat = weston_zoom_pick_seat(output->compositor); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 222 | wl_fixed_t x = seat->pointer->x; |
| 223 | wl_fixed_t y = seat->pointer->y; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 224 | |
| 225 | zoom_area_center_from_pointer(output, &x, &y); |
| 226 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame^] | 227 | if (wl_list_empty(&output->zoom.animation_xy.link)) { |
| 228 | output->zoom.current.x = seat->pointer->x; |
| 229 | output->zoom.current.y = seat->pointer->y; |
| 230 | } else { |
| 231 | output->zoom.to.x = x; |
| 232 | output->zoom.to.y = y; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 233 | } |
| 234 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame^] | 235 | weston_zoom_transition(output, x, y); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 236 | weston_output_update_zoom_transform(output); |
| 237 | } |
| 238 | |
| 239 | WL_EXPORT void |
| 240 | weston_output_init_zoom(struct weston_output *output) |
| 241 | { |
| 242 | output->zoom.active = 0; |
| 243 | output->zoom.increment = 0.07; |
| 244 | output->zoom.max_level = 0.95; |
| 245 | output->zoom.level = 0.0; |
| 246 | output->zoom.trans_x = 0.0; |
| 247 | output->zoom.trans_y = 0.0; |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 248 | weston_spring_init(&output->zoom.spring_z, 250.0, 0.0, 0.0); |
| 249 | output->zoom.spring_z.friction = 1000; |
| 250 | output->zoom.animation_z.frame = weston_zoom_frame_z; |
| 251 | wl_list_init(&output->zoom.animation_z.link); |
| 252 | weston_spring_init(&output->zoom.spring_xy, 250.0, 0.0, 0.0); |
| 253 | output->zoom.spring_xy.friction = 1000; |
| 254 | output->zoom.animation_xy.frame = weston_zoom_frame_xy; |
| 255 | wl_list_init(&output->zoom.animation_xy.link); |
| 256 | } |