File: grphctrl.c

package info (click to toggle)
saoimage 1.35.1-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,188 kB
  • ctags: 4,403
  • sloc: ansic: 52,848; makefile: 243; sh: 31
file content (208 lines) | stat: -rw-r--r-- 7,019 bytes parent folder | download | duplicates (5)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#ifndef lint
static char SccsId[] = "%W%  %G%";
#endif

/* Module:	grphctrl.c (Color Graph Control)
 * Purpose:	Manipulate the color graph
 * Subroutine:	map_graphbox()			returns: void
 * Subroutine:	display_graphbox()			returns: void
 * Subroutine:	control_cgraph()		returns: void
 * Xlib calls:	XUnmapWindow(), XMapWindow()
 * Xlib calls:	XSync(), XCheckWindowEvent(), XStoreColors()
 * Copyright:	1989 Smithsonian Astrophysical Observatory
 *		You may do anything you like with this file except remove
 *		this copyright.  The Smithsonian Astrophysical Observatory
 *		makes no representations about the suitability of this
 *		software for any purpose.  It is provided "as is" without
 *		express or implied warranty.
 * Modified:	{0} Michael VanHilst	initial version		 11 June 1989
 *		{n} <who> -- <does what> -- <when>
 */

#include <stdio.h>		/* stderr, NULL, etc. */
#include <X11/Xlib.h>		/* X window stuff */
#include <X11/Xutil.h>		/* X window manager stuff */
#include "hfiles/constant.h"	/* define codes */
#include "hfiles/struct.h"	/* declare structure types */
#include "hfiles/extern.h"	/* extern main parameter structures */
#include "hfiles/cgraph.h"

#define BUTTONMASK (Button1Mask|Button2Mask|Button3Mask)
#define EVENTMASK (ButtonPressMask|ButtonReleaseMask|ButtonMotionMask)

#include "defs/cgraph.def"	/* declare the cgraph struct */

/*
 * Subroutine:	map_graphbox
 * Purpose:	Varify size and get everything set when mapping the graphbox
 * Xlib calls:	XUnmapWindow(), XMapWindow()
 */
void map_graphbox ( )
{
  int init;
  void create_graphbox(), display_graphbox();

  if( graphbox.active ) {
    XUnmapWindow(graphbox.display, graphbox.ID);
    graphbox.active = 0;
    cgraph.inactive = 1;
  } else {
    if( graphbox.ID == NULL ) {
      init = 1;
      create_graphbox();
    } else
      init = 0;
    XMapWindow(graphbox.display, graphbox.ID);
    display_graphbox(init, 1);
  }
}

/*
 * Subroutine:	display_graphbox
 * Purpose:	Put up the graphbox when it is mapped or reexposed
 */
void display_graphbox ( init, wait )
     int init;	/* i: initialize graphbox parameters */
     int wait;	/* i: wait for result of mapping before getting dimensions */
{
  void draw_colorbar(), draw_cgraph(), label_colorbar();
  void get_window_dimensions(), adjust_color_graph(), init_color_graph_label();
  void init_graph_colorbar(), adjust_graph_colorbar(), label_color_graph();

  get_window_dimensions(&graphbox, wait, 1);
  graphbox.active = 1;
  cgraph.inactive = 0;
  if( init ) {
    init_color_graph_label();
    adjust_color_graph();
    init_graph_colorbar();
  } else {
    adjust_color_graph();
    adjust_graph_colorbar();
  }
  draw_cgraph(1, 0);
  label_color_graph();
  label_colorbar();
  draw_colorbar(1);
}

/*
 * Subroutine:	control_cgraph
 * Purpose:	Mouse controlled interaction to alter color table.
 * Called by:	control_event_loop in MainEvent.c
 * Xlib calls:	XSync(), XCheckWindowEvent(), XStoreColors()
 */
void control_cgraph ( )
{
  static int not_active = 1;
  static int oldmode = MOP;
  int drop_cgraph_vertex();
  void draw_cgraph(), move_cgraph_vertices(), get_cgraph_vertex();
  void highlight_active_cgraph_vertex(), make_cellstore_from_tables();
  void replace_draw_queue_end();

  /* make sure this an event which we want */
  if( (control.event.xbutton.window != cgraph.graph.ID) &&
      (control.priority == 0) )
    return;
  /* we assume this event was meant to be fielded exclusively here */
  control.completed = 1;
  switch( control.event.type ) {
  case MotionNotify:
    /* get only the most recent move */
    XSync(dispbox.display, 0);
    while( XCheckWindowEvent(cgraph.graph.display, cgraph.graph.ID,
			     ButtonMotionMask, &control.event) );
    if( (control.event.xmotion.state & BUTTONMASK) == 0 ) {
      /* if no buttons are down, we must be done */
      control.priority = 0;
      control.mode = oldmode;
      return;
    }
    /* alter table(s) and graph */
    move_cgraph_vertices(control.event.xmotion.x, control.event.xmotion.y);
    /* make color cellmap and send colors to the display */
    make_cellstore_from_tables(&color);
    XStoreColors(color.display, color.colormap,
		 color.cellstore, color.ncolors);
    /* shift will cause the graph to track the changes as well */
    if( ((control.event.xmotion.state & (ShiftMask | LockMask)) !=0) ^
    	(control.tracking !=0) )
      draw_cgraph (0, 1);
    break;
  case ButtonPress:
    /* if one of the three mouse buttons was pressed */
    if( (control.event.xbutton.state & BUTTONMASK) == 0 ) {
      /* if no mouse button was previously down */
      if( control.event.xbutton.state & ControlMask ) {
	/* lone button with control key means delete vertex */
	if( drop_cgraph_vertex(&control.event) == 0 )
	  /* if nothing is deleted, do nothing */
	  return;
      } else if( (control.event.xbutton.button == Button1) ||
		 (control.event.xbutton.button == Button2) ||
		 (control.event.xbutton.button == Button3) ) {
	/* first button to grab a vertex starts priority mode */
	oldmode = control.mode;
	control.mode = GOP;
	/* events to send through here in any case */
	control.priority = EVENTMASK;
      } else {
	return;
      }
    } else if( not_active || (control.event.xbutton.state & ControlMask) )
      /* don't respond if things don't look right */
      return;
    /* if this was not a delete command, it is a grab vertex command */
    if( (control.event.xbutton.state & ControlMask) == 0 ) {
      not_active = 0;
      get_cgraph_vertex(&control.event);
    }
    /* make color cellmap and send colors to the display */
    make_cellstore_from_tables(&color);
    XStoreColors(color.display, color.colormap,
		 color.cellstore, color.ncolors);
    /* redraw the graph with newly grabbed vertex */
    draw_cgraph(0, 1);
    highlight_active_cgraph_vertex();
    break;
  case ButtonRelease:
    /* draw the color graph when any button is released */
    draw_cgraph(0, 0);
    switch( control.event.xbutton.button ) {
    case Button1:
      cgraph.red.active = 0;
      if( (control.event.xbutton.state & BUTTONMASK) == Button1Mask )
	not_active = 1;
      else if( cgraph.queue[2] == &cgraph.red )
	replace_draw_queue_end();
      break;
    case Button2:
      cgraph.green.active = 0;
      if( (control.event.xbutton.state & BUTTONMASK) == Button2Mask )
	not_active = 1;
      else if( cgraph.queue[2] == &cgraph.green )
	replace_draw_queue_end();
      break;
    case Button3:
      cgraph.blue.active = 0;
      if( (control.event.xbutton.state & BUTTONMASK) == Button3Mask )
	not_active = 1;
      else if( cgraph.queue[2] == &cgraph.blue )
	replace_draw_queue_end();
      break;
    }
    if( not_active ) {
      /* if the last button was just released */
      control.priority = 0;
      control.mode = oldmode;
    } else
      /* if there are still active vertices, rehighlight them */
      highlight_active_cgraph_vertex();
    break;
  default:
    /* this event was not meant for us */
    control.completed = 0;
    break;
  }
}