Patch from James H providing lots more paranoid casting. Also one
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 13 Sep 2008 18:29:20 +0000 (18:29 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 13 Sep 2008 18:29:20 +0000 (18:29 +0000)
actual behaviour change: Untangle now permits dragging with the
right mouse button, which has exactly the same effect as it does
with the left. (Harmless on desktop platforms, but helpful when
"right-click" is achieved by press-and-hold; now the drag takes
place even if you hesitate first.)

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@8177 cda61777-01e9-0310-a592-d414129be87e

cube.c
drawing.c
flip.c
guess.c
lightup.c
midend.c
net.c
samegame.c
untangle.c

diff --git a/cube.c b/cube.c
index 5df5fcb..60730c0 100644 (file)
--- a/cube.c
+++ b/cube.c
@@ -1115,8 +1115,8 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
         int cx, cy;
         double angle;
 
-        cx = state->squares[state->current].x * GRID_SCALE + ds->ox;
-        cy = state->squares[state->current].y * GRID_SCALE + ds->oy;
+        cx = (int)(state->squares[state->current].x * GRID_SCALE) + ds->ox;
+        cy = (int)(state->squares[state->current].y * GRID_SCALE) + ds->oy;
 
         if (x == cx && y == cy)
             return NULL;               /* clicked in exact centre!  */
@@ -1476,7 +1476,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
 {
     struct bbox bb = find_bbox(params);
 
-    ds->gridscale = tilesize;
+    ds->gridscale = (float)tilesize;
     ds->ox = (int)(-(bb.l - solids[params->solid]->border) * ds->gridscale);
     ds->oy = (int)(-(bb.u - solids[params->solid]->border) * ds->gridscale);
 }
@@ -1503,7 +1503,8 @@ static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
 {
     struct game_drawstate *ds = snew(struct game_drawstate);
 
-    ds->ox = ds->oy = ds->gridscale = 0.0F;/* not decided yet */
+    ds->ox = ds->oy = 0;
+    ds->gridscale = 0.0F; /* not decided yet */
 
     return ds;
 }
index 9dbcea9..b582b8f 100644 (file)
--- a/drawing.c
+++ b/drawing.c
@@ -281,5 +281,5 @@ void print_line_width(drawing *dr, int width)
      * _square root_ of the main puzzle scale. Double the puzzle
      * size, and the line width multiplies by 1.4.
      */
-    dr->api->line_width(dr->handle, sqrt(dr->scale) * width);
+    dr->api->line_width(dr->handle, (float)sqrt(dr->scale) * width);
 }
diff --git a/flip.c b/flip.c
index d430217..d7fbd8e 100644 (file)
--- a/flip.c
+++ b/flip.c
@@ -1099,12 +1099,12 @@ static void draw_tile(drawing *dr, game_drawstate *ds,
 
        coords[0] = bx + TILE_SIZE;
        coords[1] = by;
-       coords[2] = bx + TILE_SIZE * animtime;
-       coords[3] = by + TILE_SIZE * animtime;
+       coords[2] = bx + (int)((float)TILE_SIZE * animtime);
+       coords[3] = by + (int)((float)TILE_SIZE * animtime);
        coords[4] = bx;
        coords[5] = by + TILE_SIZE;
-       coords[6] = bx + TILE_SIZE - TILE_SIZE * animtime;
-       coords[7] = by + TILE_SIZE - TILE_SIZE * animtime;
+       coords[6] = bx + TILE_SIZE - (int)((float)TILE_SIZE * animtime);
+       coords[7] = by + TILE_SIZE - (int)((float)TILE_SIZE * animtime);
 
        colour = (tile & 1 ? COL_WRONG : COL_RIGHT);
        if (animtime < 0.5)
@@ -1185,7 +1185,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
     }
 
     if (flashtime)
-       flashframe = flashtime / FLASH_FRAME;
+       flashframe = (int)(flashtime / FLASH_FRAME);
     else
        flashframe = -1;
 
diff --git a/guess.c b/guess.c
index e09a066..9a78225 100644 (file)
--- a/guess.c
+++ b/guess.c
@@ -992,9 +992,9 @@ static float *game_colours(frontend *fe, int *ncolours)
 
     /* We also want to be able to tell the difference between BACKGROUND
      * and EMPTY, for similar distinguishing-hint reasons. */
-    ret[COL_EMPTY * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0 / 3.0;
-    ret[COL_EMPTY * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
-    ret[COL_EMPTY * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
+    ret[COL_EMPTY * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0F / 3.0F;
+    ret[COL_EMPTY * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0F / 3.0F;
+    ret[COL_EMPTY * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0F / 3.0F;
 
     *ncolours = NCOLOURS;
     return ret;
index a601130..97c0ec8 100644 (file)
--- a/lightup.c
+++ b/lightup.c
@@ -2171,8 +2171,8 @@ static void game_print_size(game_params *params, float *x, float *y)
      * I'll use 6mm squares by default.
      */
     game_compute_size(params, 600, &pw, &ph);
-    *x = pw / 100.0;
-    *y = ph / 100.0;
+    *x = pw / 100.0F;
+    *y = ph / 100.0F;
 }
 
 static void game_print(drawing *dr, game_state *state, int tilesize)
index a316bcd..5229935 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -335,9 +335,9 @@ void midend_new_game(midend *me)
             char newseed[16];
             int i;
             newseed[15] = '\0';
-            newseed[0] = '1' + random_upto(me->random, 9);
+            newseed[0] = '1' + (char)random_upto(me->random, 9);
             for (i = 1; i < 15; i++)
-                newseed[i] = '0' + random_upto(me->random, 10);
+                newseed[i] = '0' + (char)random_upto(me->random, 10);
             sfree(me->seedstr);
             me->seedstr = dupstr(newseed);
 
@@ -832,9 +832,9 @@ float *midend_colours(midend *me, int *ncolours)
            buf[k] = '\0';
             if ((e = getenv(buf)) != NULL &&
                 sscanf(e, "%2x%2x%2x", &r, &g, &b) == 3) {
-                ret[i*3 + 0] = r / 255.0;
-                ret[i*3 + 1] = g / 255.0;
-                ret[i*3 + 2] = b / 255.0;
+                ret[i*3 + 0] = r / 255.0F;
+                ret[i*3 + 1] = g / 255.0F;
+                ret[i*3 + 2] = b / 255.0F;
             }
         }
     }
@@ -1304,7 +1304,7 @@ char *midend_rewrite_statusbar(midend *me, char *text)
        char timebuf[100], *ret;
        int min, sec;
 
-       sec = me->elapsed;
+       sec = (int)me->elapsed;
        min = sec / 60;
        sec %= 60;
        sprintf(timebuf, "[%d:%02d] ", min, sec);
@@ -1608,7 +1608,7 @@ char *midend_deserialise(midend *me,
                 uistr = val;
                 val = NULL;
             } else if (!strcmp(key, "TIME")) {
-                elapsed = atof(val);
+                elapsed = (float)atof(val);
             } else if (!strcmp(key, "NSTATES")) {
                 nstates = atoi(val);
                 if (nstates <= 0) {
diff --git a/net.c b/net.c
index ab16b1a..1177f80 100644 (file)
--- a/net.c
+++ b/net.c
@@ -232,7 +232,7 @@ static void decode_params(game_params *ret, char const *string)
            ret->wrapping = TRUE;
        } else if (*p == 'b') {
            p++;
-            ret->barrier_probability = atof(p);
+            ret->barrier_probability = (float)atof(p);
            while (*p && (*p == '.' || isdigit((unsigned char)*p))) p++;
        } else if (*p == 'a') {
             p++;
@@ -2863,8 +2863,8 @@ static void game_print_size(game_params *params, float *x, float *y)
      * I'll use 8mm squares by default.
      */
     game_compute_size(params, 800, &pw, &ph);
-    *x = pw / 100.0;
-    *y = ph / 100.0;
+    *x = pw / 100.0F;
+    *y = ph / 100.0F;
 }
 
 static void draw_diagram(drawing *dr, game_drawstate *ds, int x, int y,
index 2b77c26..5a8c2cb 100644 (file)
@@ -1126,7 +1126,7 @@ static char *sel_movedesc(game_ui *ui, game_state *state)
        if (ui->tiles[i] & TILE_SELECTED) {
            sprintf(buf, "%s%d", sep, i);
            sep = ",";
-           if (retlen + strlen(buf) >= retsize) {
+           if (retlen + (int)strlen(buf) >= retsize) {
                retsize = retlen + strlen(buf) + 256;
                ret = sresize(ret, retsize, char);
            }
@@ -1419,9 +1419,9 @@ static float *game_colours(frontend *fe, int *ncolours)
     ret[COL_HIGHLIGHT * 3 + 1] = 1.0F;
     ret[COL_HIGHLIGHT * 3 + 2] = 1.0F;
 
-    ret[COL_LOWLIGHT * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0 / 3.0;
-    ret[COL_LOWLIGHT * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
-    ret[COL_LOWLIGHT * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
+    ret[COL_LOWLIGHT * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0F / 3.0F;
+    ret[COL_LOWLIGHT * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0F / 3.0F;
+    ret[COL_LOWLIGHT * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0F / 3.0F;
 
     *ncolours = NCOLOURS;
     return ret;
index 12e5c75..74a5e10 100644 (file)
@@ -1000,8 +1000,8 @@ static char *solve_game(game_state *state, game_state *currstate,
         pts[i].d = 2;
         ox *= pts[i].d;
         oy *= pts[i].d;
-        pts[i].x = ox + 0.5;
-        pts[i].y = oy + 0.5;
+        pts[i].x = (long)(ox + 0.5F);
+        pts[i].y = (long)(oy + 0.5F);
 
         extra = sprintf(buf, ";P%d:%ld,%ld/%ld", i,
                         pts[i].x, pts[i].y, pts[i].d);
@@ -1077,7 +1077,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
 {
     int n = state->params.n;
 
-    if (button == LEFT_BUTTON) {
+    if (IS_MOUSE_DOWN(button)) {
        int i, best;
         long bestd;
 
@@ -1111,12 +1111,12 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
            return "";
        }
 
-    } else if (button == LEFT_DRAG && ui->dragpoint >= 0) {
+    } else if (IS_MOUSE_DRAG(button) && ui->dragpoint >= 0) {
        ui->newpoint.x = x;
        ui->newpoint.y = y;
        ui->newpoint.d = ds->tilesize;
        return "";
-    } else if (button == LEFT_RELEASE && ui->dragpoint >= 0) {
+    } else if (IS_MOUSE_RELEASE(button) && ui->dragpoint >= 0) {
        int p = ui->dragpoint;
        char buf[80];
 
@@ -1268,8 +1268,8 @@ static point mix(point a, point b, float distance)
     point ret;
 
     ret.d = a.d * b.d;
-    ret.x = a.x * b.d + distance * (b.x * a.d - a.x * b.d);
-    ret.y = a.y * b.d + distance * (b.y * a.d - a.y * b.d);
+    ret.x = (long)(a.x * b.d + distance * (b.x * a.d - a.x * b.d));
+    ret.y = (long)(a.y * b.d + distance * (b.y * a.d - a.y * b.d));
 
     return ret;
 }