|
From: Olof S. <sve...@es...> - 2002-07-31 08:41:15
|
Hi,
Jesse Stone send me this piece of code (I have just changed the streams
from 0 and 1 to 1 and 2 after a suggestion from Alan):
> #include <math.h>
> #include "plplot/plplot.h"
>
> int main()
> {
> int i;
> float x[100], y[100];
>
> plsstrm(1); // Open first window and draw a sin curve
> plsdev("win3");
> plinit();
>
> plcol0(1);
> plenv(0.0f, 10.0f, -1.2f, 1.2f, 0, 1);
> plcol0(2);
> pllab("(x)", "sin(x)", "Sin Function");
> for (i = 0; i < 100; i++) {
> x[i] = (float)i/10;
> y[i] = (float)sin(x[i]);
> }
> plcol0(3);
> plline(100, x, y);
>
>
> plsstrm(2); // Open second window and draw a cos curve
> plsdev("win3");
> plinit();
>
> plcol0(1);
> plenv(0.0f, 10.0f, -1.2f, 1.2f, 0, 1);
> plcol0(2);
> pllab("(x)", "cos(x)", "Cos Function");
> for (i = 0; i < 100; i++) {
> x[i] = (float)i/10;
> y[i] = (float)cos(x[i]);
> }
> plcol0(3);
> plline(100, x, y);
>
>
> plend();
>
> return 0;
> }
He's trying to use the win3 driver but the problem is that the two plots
are mixed in the same window. Both Alan and I have tried the code using
the xwin and ntk drivers on Linux with the following results:
* xwin: Both graphs are displayed however only the last one is properly
refreshed. The first one is refreshed as soon as the last one is closed.
* ntk: Both graphs are properly displayed.
The win3 driver (win32) behaves like the xwin driver, with the addition
of mixing the two graphs in the last plot window when resizing or
forcing a refresh of the last window.
I have tried to understand how the two plots can be mixed but failed so
far, so therefore I'd like to ask you if you can see where the problem
is occurring. The piece of code in the win3 driver that takes care of
replotting the graphs after a resize looks like this (slightly changed
with respect to the one in the CVS):
> LRESULT CALLBACK _export PlPlotWndProc (HWND hwnd,UINT message, UINT wParam,LONG lParam)
> {
....
> PLStream *pls = (PLStream *)GetWindowLong(hwnd,GWL_USERDATA);
....
> if (pls)
> dev = (WinDev *)pls->dev;
> printf("DEBUG: in PlPlotWndProc... pls = %d\n",(int)pls);
....
> case WM_PAINT :
> if (dev) {
> if (dev->rePaint) {
> HDC hdc_old = dev->hdc;
> HWND hwnd_old = dev->hwnd;
> dev->rePaint = 0;
> dev->rePaintBsy = 1;
> hcurSave = SetCursor(LoadCursor(NULL,IDC_WAIT));
> dev->hwnd = hwnd;
> dev->hdc = GetDC(hwnd);
> GetClientRect(hwnd,&rect);
> dev->xPhMax = rect.right;
> dev->yPhMax = rect.bottom;
> dev->xScale = rect.right / ((float)PIXELS_X);
> dev->yScale = rect.bottom / ((float)PIXELS_Y);
> plRemakePlot(pls);
> dev->rePaintBsy = 0;
> SetCursor(hcurSave);
> ReleaseDC(hwnd,dev->hdc);
> dev->hdc = hdc_old;
> dev->hwnd = hwnd_old;
> plD_state_win3(pls, PLSTATE_COLOR0); /* Set drawing color */
> }
> BeginPaint(hwnd,&ps);
> EndPaint(hwnd,&ps);
> return 0;
> }
> break;
I have checked that each window retrieves correctly the pointer to its
pls stream and hence the correct pls->dev context by printing out the
address of the pls pointer. When I resize the last window only one pls
pointer is printed out.
So, my question to you is therefore: How is it possible for the two
graphs to be mixed in the same window if plRemakePlot is called with
only one pls stream? Any suggestions are welcome!
Regards,
Olof
|