Now NEDsim maintains the simulator when the window resizes, only resetting the displa...
[screensavers] / hacks / NEDsim / NEDsim.c
index bee5e3b..2b576f0 100644 (file)
@@ -284,6 +284,59 @@ draw_panel(struct NEDsim * nedsim)
             nedsim->cell_size * OVERALL_WIDTH_IN_CELLS,
             nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS)
     );
             nedsim->cell_size * OVERALL_WIDTH_IN_CELLS,
             nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS)
     );
+
+    // Give the panel rounded corners by first deleting the four right-angle corners...
+    set_color(nedsim, &color_list[nedsim->color_index].panel_bg);
+    XFillRectangle(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset,
+            nedsim->origin_y_offset,
+            nedsim->cell_size,
+            nedsim->cell_size
+    );
+    XFillRectangle(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-1)),
+            nedsim->origin_y_offset,
+            nedsim->cell_size,
+            nedsim->cell_size
+    );
+    XFillRectangle(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset,
+            nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 1)),
+            nedsim->cell_size,
+            nedsim->cell_size
+    );
+    XFillRectangle(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-1)),
+            nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 1)),
+            nedsim->cell_size,
+            nedsim->cell_size
+    );
+    // ...and then replacing them with filled arcs, forming rounded corners.
+    set_color(nedsim, &color_list[nedsim->color_index].panel_fg);
+    XFillArc(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset,
+            nedsim->origin_y_offset,
+            nedsim->cell_size * 2, nedsim->cell_size * 2,
+            180*64, -90*64
+    );
+    XFillArc(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-2)),
+            nedsim->origin_y_offset,
+            nedsim->cell_size * 2, nedsim->cell_size * 2,
+            0, 90*64
+    );
+    XFillArc(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset,
+            nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 2)),
+            nedsim->cell_size * 2, nedsim->cell_size * 2,
+            180*64, 90*64
+    );
+    XFillArc(nedsim->dpy, nedsim->win, nedsim->gc,
+            nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-2)),
+            nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 2)),
+            nedsim->cell_size * 2, nedsim->cell_size * 2,
+            0, -90*64
+    );
 }
 
 // TODO: Explain
 }
 
 // TODO: Explain
@@ -728,8 +781,12 @@ NEDsim_reshape(Display * dpy, Window win, void * closure, unsigned int w, unsign
     XGetWindowAttributes(nedsim->dpy, nedsim->win, &xgwa);
     /* Only restart the simulation if the window changed size.                */
     if (nedsim->dpy_width != xgwa.width || nedsim->dpy_height != xgwa.height) {
     XGetWindowAttributes(nedsim->dpy, nedsim->win, &xgwa);
     /* Only restart the simulation if the window changed size.                */
     if (nedsim->dpy_width != xgwa.width || nedsim->dpy_height != xgwa.height) {
-        NEDsim_free(dpy, win, closure);
-        closure = NEDsim_init(dpy, win);
+        struct NEDstate * original_nedstate = nedsim->nedstate;
+        nedsim->nedstate = NULL;
+        NEDsim_free(dpy, win, nedsim);
+        struct NEDsim * new_nedsim = NEDsim_init(dpy, win);
+        new_nedsim->nedstate = original_nedstate;
+        closure = new_nedsim;
     }
 }
 
     }
 }