summaryrefslogtreecommitdiff
path: root/plot/plot.c
diff options
context:
space:
mode:
Diffstat (limited to 'plot/plot.c')
-rw-r--r--plot/plot.c54
1 files changed, 45 insertions, 9 deletions
diff --git a/plot/plot.c b/plot/plot.c
index e3cd5bf..d7b4799 100644
--- a/plot/plot.c
+++ b/plot/plot.c
@@ -120,7 +120,7 @@ static plot_info pd;
static int do_plot_imp(
int flags,
double xmin, double xmax, double ymin, double ymax, /* Bounding box */
- double ratio, /* Aspect ratio of window, X/Y */
+ double ratio, /* Aspect ratio of window, X/Y, 1.0 = nominal */
int dowait, /* > 0 wait for user to hit space key, < 0 delat dowait seconds. */
double *x1, double *x2,
double *yy[MXGPHS], char **ntext,
@@ -369,7 +369,7 @@ int n) { /* Number of values */
xmin = ymin = 1e6;
xmax = ymax = -1e6;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < nn; i++) {
if (xmin > x[i])
xmin = x[i];
if (xmax < x[i])
@@ -433,7 +433,7 @@ int m) {
xmin = ymin = 1e6;
xmax = ymax = -1e6;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < nn; i++) {
if (xmin > x[i])
xmin = x[i];
if (xmax < x[i])
@@ -892,6 +892,8 @@ static int do_plot_imp(
/* ------------------------------------------- */
/* Setup windows stuff */
{
+ ui_UsingGUI();
+
/* It would be nice to reduce number of globals. */
/* We don't clean up properly either - ie. don't delete thread etc. */
@@ -908,11 +910,14 @@ static int do_plot_imp(
}
while (plot_hwnd == NULL)
Sleep(50);
+
+ SetForegroundWindow(plot_hwnd); /* Raise */
}
plot_signal = 0;
- SetForegroundWindow(plot_hwnd);
+ if (dowait > 0)
+ SetForegroundWindow(plot_hwnd); /* Raise */
/* Force a repaint with the new data */
if (!InvalidateRgn(plot_hwnd,NULL,TRUE)) {
@@ -1321,6 +1326,14 @@ static void DoPlot(NSRect *rect, plot_info *pdp);
@end
+/* Function called back by main thread to trigger a drawRect */
+
+static void doSetNeedsDisplay(void *cntx) {
+ cntx_t *cx = (cntx_t *)cntx;
+
+ [cx->view setNeedsDisplay: YES ];
+}
+
// - - - - - - - - - - - - - - - - - - - - - - - - -
@interface PLWin : NSWindow {
@@ -1362,7 +1375,8 @@ static void DoPlot(NSRect *rect, plot_info *pdp);
@end
/* Create our window */
-static void create_my_win(cntx_t *cx) {
+static void create_my_win(void *cntx) {
+ cntx_t *cx = (cntx_t *)cntx;
NSRect wRect;
/* Create Window */
@@ -1491,6 +1505,8 @@ static int do_plot_imp(
pd.o = abs(o);
}
+ ui_UsingGUI();
+
/* If we may be in a different thread to the main thread or */
/* the application thread, establish our own pool. */
NSAutoreleasePool *tpool = nil;
@@ -1511,10 +1527,26 @@ static int do_plot_imp(
if ((plot_cx = (cntx_t *)calloc(sizeof(cntx_t), 1)) == NULL)
error("new_dispwin: Malloc failed (cntx_t)\n");
- create_my_win(plot_cx);
+ /* Prepare to wait for events */
+ ui_aboutToWait();
+
+ /* Run the window creation in the main thread and wait for it */
+ ui_runInMainThreadAndWait((void *)plot_cx, create_my_win);
+
+ /* Wait for events generated by window creation to complete */
+ ui_waitForEvents();
} else { /* Trigger an update */
- [plot_cx->view setNeedsDisplay: YES ];
+// [plot_cx->view setNeedsDisplay: YES ];
+
+ /* Prepare to wait for events */
+ ui_aboutToWait();
+
+ /* Run the window creation in the main thread and wait for it */
+ ui_runInMainThreadAndWait((void *)plot_cx, doSetNeedsDisplay);
+
+ /* Wait for any events generated by paint to complete */
+ ui_waitForEvents();
}
/* (Main thread will service events) */
@@ -1960,6 +1992,8 @@ static int do_plot_imp(
unsigned long myforeground,mybackground;
int done;
+ ui_UsingGUI();
+
/* open the display */
if (mydisplay == NULL) {
mydisplay = XOpenDisplay("");
@@ -2013,8 +2047,10 @@ static int do_plot_imp(
XSendEvent(mydisplay, mywindow, False, ExposureMask, (XEvent *)&ev);
} else {
- XMapRaised(mydisplay,mywindow);
- debugf(("Raised window\n"));
+ if (pd.dowait > 0) {
+ XMapRaised(mydisplay,mywindow);
+ debugf(("Raised window\n"));
+ }
}
/* Main event loop */