We should turn off the dragging variables in the UI _whenever_
[sgt/puzzles] / windows.c
index 87f4284..7689993 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -88,6 +88,7 @@ struct frontend {
     HPEN *pens;
     HRGN clip;
     UINT timer;
+    DWORD timer_last_tickcount;
     int npresets;
     game_params **presets;
     struct font *fonts;
@@ -302,7 +303,10 @@ void deactivate_timer(frontend *fe)
 
 void activate_timer(frontend *fe)
 {
-    fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL);
+    if (!fe->timer) {
+       fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL);
+       fe->timer_last_tickcount = GetTickCount();
+    }
 }
 
 static frontend *new_window(HINSTANCE inst)
@@ -324,6 +328,9 @@ static frontend *new_window(HINSTANCE inst)
 
     fe->timer = 0;
 
+    fe->fonts = NULL;
+    fe->nfonts = fe->fontsize = 0;
+
     {
        int i, ncolours;
         float *colours;
@@ -680,6 +687,7 @@ static int get_config(frontend *fe, int which)
            mkctrl(fe, col1l, col2r, y, y+height, "BUTTON",
                   BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP,
                   0, i->name, (j->ctlid = id++));
+           CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0));
            y += height;
            break;
 
@@ -931,7 +939,50 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                button = LEFT_BUTTON;
            else
                button = RIGHT_BUTTON;
-               
+
+           if (!midend_process_key(fe->me, LOWORD(lParam),
+                                   HIWORD(lParam), button))
+               PostQuitMessage(0);
+
+           SetCapture(hwnd);
+       }
+       break;
+      case WM_LBUTTONUP:
+      case WM_RBUTTONUP:
+      case WM_MBUTTONUP:
+       {
+           int button;
+
+           /*
+            * Shift-clicks count as middle-clicks, since otherwise
+            * two-button Windows users won't have any kind of
+            * middle click to use.
+            */
+           if (message == WM_MBUTTONUP || (wParam & MK_SHIFT))
+               button = MIDDLE_RELEASE;
+           else if (message == WM_LBUTTONUP)
+               button = LEFT_RELEASE;
+           else
+               button = RIGHT_RELEASE;
+
+           if (!midend_process_key(fe->me, LOWORD(lParam),
+                                   HIWORD(lParam), button))
+               PostQuitMessage(0);
+
+           ReleaseCapture();
+       }
+       break;
+      case WM_MOUSEMOVE:
+       {
+           int button;
+
+           if (wParam & (MK_MBUTTON | MK_SHIFT))
+               button = MIDDLE_DRAG;
+           else if (wParam & MK_LBUTTON)
+               button = LEFT_DRAG;
+           else
+               button = RIGHT_DRAG;
+           
            if (!midend_process_key(fe->me, LOWORD(lParam),
                                    HIWORD(lParam), button))
                PostQuitMessage(0);
@@ -942,8 +993,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
            PostQuitMessage(0);
        return 0;
       case WM_TIMER:
-       if (fe->timer)
-           midend_timer(fe->me, (float)0.02);
+       if (fe->timer) {
+           DWORD now = GetTickCount();
+           float elapsed = (float) (now - fe->timer_last_tickcount) * 0.001F;
+           midend_timer(fe->me, elapsed);
+           fe->timer_last_tickcount = now;
+       }
        return 0;
     }