static struct timespec add_to_time(struct timespec t, double tm) { struct timespec t1; t1 = double_to_time(tm); t1.tv_sec = t1.tv_sec + t.tv_sec; t1.tv_nsec = t1.tv_nsec + t.tv_nsec; while (t1.tv_nsec >= BILLION) { t1.tv_nsec = t1.tv_nsec - BILLION; t1.tv_sec++; } return t1; }
void Card::move(int dest_x, int dest_y, bool animate) { const int steps = 100; timeout_t start_time, stop_time, mpause; // Time of end of animation get_time (&start_time); stop_time = start_time; incr_time (&stop_time, (unsigned) Option::speedup()); // Delay between steps double_to_time ((double)Option::speedup() / 1000.0 / 2.0 / (double)steps, &mpause); raise(); if (animate && Option::animation()) { int oldx = x(); int oldy = y(); int newx = dest_x; int newy = dest_y; float curx = (float) oldx; float cury = (float) oldy; for (int i = 0; i < steps; i++) { curx += ((float) (newx - oldx)) / steps; cury += ((float) (newy - oldy)) / steps; NSWindow::move((int) curx, (int) cury); XFlush(dpy); add_time (&start_time, &mpause); wait_until (&start_time); } } else { NSWindow::move(dest_x, dest_y); } XFlush(dpy); raise(); if (animate) wait_until (&stop_time); }