+ if (IS_CURSOR_MOVE(button)) {
+ move_cursor(button, &ui->cur_x, &ui->cur_y, state->p.w, state->p.h, 0);
+ ui->cur_visible = 1;
+ ui->cur_moved = 1;
+ ui->cur_lastmove = button;
+ ui->dragx = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(button);
+ ui->dragy = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(button);
+ return "";
+ }
+ if (IS_CURSOR_SELECT(button)) {
+ if (!ui->cur_visible) {
+ ui->dragx = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(ui->cur_lastmove);
+ ui->dragy = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(ui->cur_lastmove);
+ ui->cur_visible = 1;
+ return "";
+ }
+ if (ui->drag_colour == -2) { /* not currently cursor-dragging, start. */
+ int r = region_from_coords(state, ds, ui->dragx, ui->dragy);
+ if (r >= 0) {
+ ui->drag_colour = state->colouring[r];
+ ui->drag_pencil = (ui->drag_colour >= 0) ? 0 : state->pencil[r];
+ } else {
+ ui->drag_colour = -1;
+ ui->drag_pencil = 0;
+ }
+ ui->cur_moved = 0;
+ return "";
+ } else { /* currently cursor-dragging; drop the colour in the new region. */
+ x = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(ui->cur_lastmove);
+ y = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(ui->cur_lastmove);
+ alt_button = (button == CURSOR_SELECT2) ? 1 : 0;
+ /* Double-select removes current colour. */
+ if (!ui->cur_moved) ui->drag_colour = -1;
+ goto drag_dropped;
+ }
+ }
+