File: do_event_loop.c

package info (click to toggle)
quickplot 0.4.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 352 kB
  • ctags: 276
  • sloc: ansic: 4,124; makefile: 124; sh: 12
file content (124 lines) | stat: -rw-r--r-- 3,683 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/***************************************************************
LanceMan's quickplot --- a fast interactive 2D plotter

Copyright (C) 1998, 1999  Lance Arsenault

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Or look at http://www.gnu.org/copyleft/gpl.html .

**********************************************************************/
/* $Id: do_event_loop.c,v 1.3 1999/01/15 02:19:14 lance Exp $ */
#include <stdio.h>
#include <X11/Xlib.h> 
#include <stdlib.h>

#include "data.h"
#include "xwin.h"

extern void show_true_function_values(PlotXwins *win, Plot *plot, int button);
extern void draw_plot(PlotXwins *win, Plot *plot);
extern void draw_rubber_bands(PlotXwins *win, int *x, int *y, 
			      unsigned int *width, unsigned int *height);
extern int zoom_plot(PlotXwins *win, Plot *plot,  int x, int y, 
		      unsigned int width, unsigned int height);
extern void show_function_values(PlotXwins *win, Plot *plot);
extern void show_point_values(PlotXwins *win, Plot *plot);
extern int get_window_size(Display *display, Window window, 
				 unsigned int *width, 
				 unsigned int *height);

void do_plotbuttomPress(PlotXwins *win, Plot *plot, XEvent *report)
{
  int x,y;
  unsigned int width, height;

  switch(report->xbutton.button)
    {
    case Button1:
      if(win->mode & EDIT_MODE)
	{
	  show_true_function_values(win,plot,Button1);
	}
      else
	show_function_values(win,plot);
      break;
    case Button2:
      draw_rubber_bands(win,&x,&y,&width,&height);
      if(zoom_plot(win,plot,x,y,width,height))
	{
	  draw_plot(win,plot);
	}
      break;
    case Button3:
      if(win->mode & EDIT_MODE)
	{
	  show_true_function_values(win,plot,Button3);
	}
      else
	show_point_values(win,plot);
      break; 
    }
}

void do_event_loop(PlotXwins *win, Plot *plot)
{
  XEvent report;
  XtInputMask mask;
  unsigned int width, height;

  while(XCheckWindowEvent(win->display,win->plotwin,
				      ExposureMask,&report));
  /* go */
  while(1)
    {
      XPeekEvent(win->display, &report); /* blocks until an event looked at */

      if(report.xany.window == win->plotwin) /* plot window */
	{ 
	  XNextEvent(win->display,&report); /* blocks until an event is received */

	  switch(report.type)
	    {
	    case Expose:
	      /* remove any remaining redraw events */
	      while(XCheckWindowEvent(win->display,win->plotwin,
				      ExposureMask| StructureNotifyMask,&report));
	      
	      draw_plot(win,plot);
	      break;
	    case ConfigureNotify: /* look for window resize */
	      if(get_window_size(win->display,win->plotwin,&width,&height))
		{
		  /* remove any remaining redraw events */
		  while(XCheckWindowEvent(win->display,win->plotwin,
				      ExposureMask| StructureNotifyMask,&report));
		  
		  draw_plot(win,plot);
		}
	      break;
	    case ButtonPress:
	      do_plotbuttomPress(win,plot,&report);
	      break;
	    }
	}
      else if((mask = XtAppPending(win->context))) /* Xt event */
	{
	  XtAppProcessEvent(win->context, mask);
	}
      else /* other */
	XNextEvent(win->display,&report); /* blocks until an event is received */
    }
}