* mouseMoveTo */
| 300 | * mouseMoveTo |
| 301 | */ |
| 302 | WD_RESULT mouseMoveTo(WINDOW_HANDLE windowHandle, long duration, long fromX, long fromY, long toX, long toY) |
| 303 | { |
| 304 | init_logging(); |
| 305 | const int timePerEvent = 10 /* ms */; |
| 306 | |
| 307 | LOG(DEBUG) << "---------- starting mouseMoveTo: " << windowHandle << "---------"; |
| 308 | GdkDrawable* hwnd = (GdkDrawable*) windowHandle; |
| 309 | |
| 310 | MouseEventsHandler mousep_handler(hwnd); |
| 311 | |
| 312 | long pointsDistance = distanceBetweenPoints(fromX, fromY, toX, toY); |
| 313 | const int stepSizeInPixels = 5; |
| 314 | int steps = pointsDistance / stepSizeInPixels; |
| 315 | |
| 316 | // If the distance between the points is less than stepSizeInPixels, |
| 317 | // make sure enough move events aregenerated. |
| 318 | // * If the start and finish points are the same, one step is needed. |
| 319 | // Otherwise, generate at least 2 move events: one one the start |
| 320 | // point and the other on the end point. |
| 321 | if ((fromX == toX) && (fromY == toY)) { |
| 322 | steps = 1; |
| 323 | } else { |
| 324 | steps = max(steps, 2); |
| 325 | } |
| 326 | |
| 327 | assert(steps > 0); |
| 328 | LOG(DEBUG) << "From: (" << fromX << ", " << fromY << ") to: (" << toX << ", " << toY << ")"; |
| 329 | LOG(DEBUG) << "Distance: " << pointsDistance << " steps: " << steps; |
| 330 | |
| 331 | for (int i = 0; i < steps; ++i) { |
| 332 | // To avoid integer division rounding and cumulative floating point errors, |
| 333 | // calculate from scratch each time. We adjust the divider to steps - 1 |
| 334 | // to get a move event generated on the exact starting point as well |
| 335 | // as the end point. |
| 336 | int div_by = max(steps - 1, 1); |
| 337 | int currentX = fromX + ((toX - fromX) * ((double)i) / div_by); |
| 338 | int currentY = fromY + ((toY - fromY) * ((double)i) / div_by); |
| 339 | LOG(DEBUG) << "Moving to: (" << currentX << ", " << currentY << ")"; |
| 340 | list<GdkEvent*> events_for_mouse = mousep_handler.CreateEventsForMouseMove(currentX, currentY); |
| 341 | submit_and_free_events_list(events_for_mouse, timePerEvent); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | |
| 346 | if (gLatestEventTime < mousep_handler.get_last_event_time()) { |
| 347 | gLatestEventTime = mousep_handler.get_last_event_time(); |
| 348 | } |
| 349 | |
| 350 | LOG(DEBUG) << "---------- Ending mouseMoveTo ----------"; |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * mouseDownAt |
nothing calls this directly
no test coverage detected