+static int drag_xform(game_ui *ui, int x, int y, int v)
+{
+ int xmin, ymin, xmax, ymax;
+
+ xmin = min(ui->dsx, ui->dex);
+ xmax = max(ui->dsx, ui->dex);
+ ymin = min(ui->dsy, ui->dey);
+ ymax = max(ui->dsy, ui->dey);
+
+ /*
+ * Left-dragging has no effect, so we treat a left-drag as a
+ * single click on dsx,dsy.
+ */
+ if (ui->drag_button == LEFT_BUTTON) {
+ xmin = xmax = ui->dsx;
+ ymin = ymax = ui->dsy;
+ }
+
+ if (x < xmin || x > xmax || y < ymin || y > ymax)
+ return v; /* no change outside drag area */
+
+ if (v == TREE)
+ return v; /* trees are inviolate always */
+
+ if (xmin == xmax && ymin == ymax) {
+ /*
+ * Results of a simple click. Left button sets blanks to
+ * tents; right button sets blanks to non-tents; either
+ * button clears a non-blank square.
+ */
+ if (ui->drag_button == LEFT_BUTTON)
+ v = (v == BLANK ? TENT : BLANK);
+ else
+ v = (v == BLANK ? NONTENT : BLANK);
+ } else {
+ /*
+ * Results of a drag. Left-dragging has no effect.
+ * Right-dragging sets all blank squares to non-tents and
+ * has no effect on anything else.
+ */
+ if (ui->drag_button == RIGHT_BUTTON)
+ v = (v == BLANK ? NONTENT : v);
+ else
+ /* do nothing */;
+ }
+
+ return v;
+}
+