1 #if HAVE_CONFIG_H
2 #   include "config.h"
3 #endif
4 
5 #if HAVE_STDLIB_H
6 #   include <stdlib.h>
7 #endif
8 
9 #include "xregion.h"
10 
create_main_window()11 void create_main_window()
12 {
13   Display *disp;
14   int screen;
15 
16   disp = XtDisplay(overview_shell);
17   screen = DefaultScreen(disp);
18 
19   /* Create top level shell widget */
20   top_level_widget = XtVaAppCreateShell("xregion","XRegion",
21                      applicationShellWidgetClass,disp,
22                      NULL);
23 
24   /* Create form widget to hold everything else */
25 
26   box_widget = XtVaCreateManagedWidget("box", formWidgetClass,
27                                      top_level_widget,
28                                      XtNbackground, DEFAULT_BG,
29                                      XtNforeground, DEFAULT_FG,
30                                      NULL);
31 
32   /* Create the label to hold the title */
33 
34   (void) strcpy(title, "Array Access Display");
35   title_widget = XtVaCreateManagedWidget("title", labelWidgetClass,
36                                        box_widget,
37                                        XtNbackground, DEFAULT_BG,
38                                        XtNforeground, DEFAULT_FG,
39                                        XtNx, 10,
40                                        XtNy, 5,
41                                        XtNwidth, 300,
42                                        XtNlabel, title,
43                                        XtNborderWidth, 0,
44                                        NULL);
45 
46   coord_widget = XtVaCreateManagedWidget("coords", labelWidgetClass,
47                                        box_widget,
48                                        XtNbackground, DEFAULT_BG,
49                                        XtNforeground, DEFAULT_FG,
50                                        XtNy, 5,
51                                        XtNhorizDistance, 10,
52                                        XtNfromHoriz, title_widget,
53                                        XtNjustify, XtJustifyLeft,
54                                        XtNlabel, "Coordinates x, y:                 ",
55                                        XtNborderWidth, 0,
56                                        NULL);
57 
58   /* Create the Quit command button */
59 
60   quit_button = XtVaCreateManagedWidget("quit", commandWidgetClass,
61                                        box_widget,
62                                        XtNbackground, DEFAULT_BG,
63                                        XtNforeground, DEFAULT_FG,
64                                        XtNx, 10,
65                                        XtNvertDistance, 15,
66                                        XtNfromVert, title_widget,
67                                        XtNlabel, "Quit",
68                                        XtNshapeStyle, XmuShapeOval,
69                                        NULL);
70   XtAddCallback(quit_button, XtNcallback, Quit, NULL);
71 
72   /* Create the Start/Stop command button */
73 
74   start_stop_button = XtVaCreateManagedWidget("start/stop", commandWidgetClass,
75                                        box_widget,
76                                        XtNbackground, DEFAULT_BG,
77                                        XtNforeground, DEFAULT_FG,
78                                        XtNvertDistance, 15,
79                                        XtNfromVert, title_widget,
80                                        XtNhorizDistance, 10,
81                                        XtNfromHoriz, quit_button,
82                                        XtNlabel, "Start",
83                                        XtNshapeStyle, XmuShapeOval,
84                                        NULL);
85   XtAddCallback(start_stop_button, XtNcallback, StartStop, NULL);
86 
87   /* Create the scroll bar for the interval */
88 
89   interval_label = XtVaCreateManagedWidget("interval_label", labelWidgetClass,
90                                        box_widget,
91                                        XtNbackground, DEFAULT_BG,
92                                        XtNforeground, DEFAULT_FG,
93                                        XtNvertDistance, 5,
94                                        XtNfromVert, title_widget,
95                                        XtNhorizDistance, 20,
96                                        XtNfromHoriz, start_stop_button,
97                                        XtNlabel, "Time Interval",
98                                        XtNborderWidth, 0,
99                                        NULL);
100 
101   scroll_widget = XtVaCreateManagedWidget("scroll", scrollbarWidgetClass,
102                                         box_widget,
103                                        XtNbackground, DEFAULT_BG,
104                                        XtNforeground, DEFAULT_FG,
105                                        XtNvertDistance, 5,
106                                        XtNfromVert, interval_label,
107                                        XtNhorizDistance, 20,
108                                        XtNfromHoriz, start_stop_button,
109                                        XtNorientation, XtorientHorizontal,
110                                        XtNlength, 100,
111                                        XtNthickness, 15,
112                                        NULL);
113   XtAddCallback(scroll_widget, XtNscrollProc, ScrollProc, NULL);
114   XtAddCallback(scroll_widget, XtNjumpProc, JumpProc, NULL);
115 
116   /* Create the label widget which displays the interval value
117      associated with the scrollbar. */
118 
119   (void) sprintf(interval_string, "%4d ms", interval);
120   interval_widget = XtVaCreateManagedWidget("interval", labelWidgetClass,
121                                            box_widget,
122                                        XtNbackground, DEFAULT_BG,
123                                        XtNforeground, DEFAULT_FG,
124                                        XtNvertDistance, 5,
125                                        XtNfromVert, interval_label,
126                                        XtNhorizDistance, 5,
127                                        XtNfromHoriz, scroll_widget,
128                                        XtNjustify, XtJustifyRight,
129                                        XtNlabel, interval_string,
130                                        XtNborderWidth, 0,
131                                        NULL);
132 
133   /* Create the scroll bar for the slowdown */
134 
135   slowdown_label = XtVaCreateManagedWidget("slowdown_label", labelWidgetClass,
136                                        box_widget,
137                                        XtNbackground, DEFAULT_BG,
138                                        XtNforeground, DEFAULT_FG,
139                                        XtNvertDistance, 5,
140                                        XtNfromVert, title_widget,
141                                        XtNhorizDistance, 25,
142                                        XtNfromHoriz, interval_widget,
143                                        XtNlabel, "Slowdown Factor",
144                                        XtNborderWidth, 0,
145                                        NULL);
146 
147   scroll_widget2 = XtVaCreateManagedWidget("scroll2", scrollbarWidgetClass,
148                                         box_widget,
149                                        XtNbackground, DEFAULT_BG,
150                                        XtNforeground, DEFAULT_FG,
151                                        XtNvertDistance, 5,
152                                        XtNfromVert, slowdown_label,
153                                        XtNhorizDistance, 25,
154                                        XtNfromHoriz, interval_widget,
155                                        XtNorientation, XtorientHorizontal,
156                                        XtNlength, 100,
157                                        XtNthickness, 15,
158                                        NULL);
159   XtAddCallback(scroll_widget2, XtNscrollProc, ScrollProc2, NULL);
160   XtAddCallback(scroll_widget2, XtNjumpProc, JumpProc2, NULL);
161 
162   /* Create the label widget which displays the slowdown value
163      associated with the scrollbar 2. */
164 
165   (void)  sprintf(slowdown_string, "%5d times", (long)slowdown);
166   slowdown_widget = XtVaCreateManagedWidget("slowdown", labelWidgetClass,
167                                            box_widget,
168                                        XtNbackground, DEFAULT_BG,
169                                        XtNforeground, DEFAULT_FG,
170                                        XtNvertDistance, 5,
171                                        XtNfromVert, slowdown_label,
172                                        XtNhorizDistance, 5,
173                                        XtNfromHoriz, scroll_widget2,
174                                        XtNjustify, XtJustifyRight,
175                                        XtNlabel, slowdown_string,
176                                        XtNborderWidth, 0,
177                                        NULL);
178 
179   /* Now add the actual canvas ... */
180 
181   canvas_widget = XtVaCreateManagedWidget("canvas", formWidgetClass,
182                                         box_widget,
183                                         XtNheight, pict_height * scale,
184                                         XtNwidth, pict_width * scale,
185                                         XtNvertDistance, 20,
186                                         XtNfromVert, quit_button,
187                                         XtNbackground, CANVAS_COLOR,
188                                         XtNborderWidth, 0,
189                                         NULL);
190   /* Add callback for exposure */
191 
192   XtAddEventHandler(canvas_widget,ExposureMask,False,Exposed,NULL);
193   XtAddEventHandler(canvas_widget,PointerMotionMask,False,running_coords,NULL);
194 
195   /* Now add the color scale ... */
196 
197   map_widget = XtVaCreateManagedWidget("colorMap", compositeWidgetClass,
198                                         box_widget,
199                                        XtNbackground, DEFAULT_BG,
200                                        XtNforeground, DEFAULT_FG,
201                                        XtNheight, 350,
202                                        XtNwidth, 80,
203                                        XtNvertDistance, 20,
204                                        XtNfromVert, quit_button,
205                                        XtNhorizDistance, 20,
206                                        XtNfromHoriz, canvas_widget,
207                                        XtNborderWidth, 0,
208                                        NULL);
209 
210 }
211 
212 /* JJU: void running_coords(Widget widget, caddr_t data, XEvent *event) */
running_coords(Widget widget,XtPointer data,XEvent * event,Boolean * bln)213 void running_coords(Widget widget, XtPointer data, XEvent *event, Boolean *bln)
214 {
215   char loc_str[40];
216   int x, y;
217 
218   x = event->xmotion.x;
219   y = event->xmotion.y;
220 
221 /*   sprintf(loc_str, "Coordinates x, y: %d, %d", (int) (x / scale) + left_edge + 1,
222          (int) (y / scale) + top_edge + 1);
223 */
224   sprintf(loc_str, "Coordinates x, y: %d, %d",
225 		(int) (x / scale) + left_edge,
226          	(int) (y / scale) + top_edge);
227   XtVaSetValues(coord_widget, XtNlabel, loc_str, NULL);
228 }
229 
setup_drawing()230 void setup_drawing()
231 {
232   int i, x, y;
233   XGCValues gcv;
234 
235   /* Set up the drawing environment */
236 
237   display = XtDisplay(canvas_widget);
238   window = XtWindow(canvas_widget);
239   window_map = XtWindow(map_widget);
240   screen = DefaultScreen(display);
241   visual = DefaultVisual(display, screen);
242   depth = DisplayPlanes(display, screen);
243   (void) printf("depth = %d\n",depth);
244 
245   gc = XCreateGC(display, window, 0, (XGCValues *) NULL);
246   XSetForeground(display, gc, GRID_COLOR);
247 
248   gcv.font = XLoadFont(display, "8x13");
249   if(!gcv.font)
250   {
251     printf("error font not loaded\n");
252   }
253 
254   gc_map = XCreateGC(display, window_map, GCFont, &gcv);
255 
256   Setcmap();
257 
258   /* Make image to match the size of our canvas */
259   x = pict_width * scale;
260   y = pict_height * scale;
261   pict  = (u_char *) malloc((x + pict_width) * y);
262   image = XCreateImage(display, visual, depth, ZPixmap, 0,
263                        pict, x, y, 8, x);
264 
265   /* Make the byte array which will hold the access data */
266 
267   if (!(grid = (u_char *) malloc((unsigned) (pict_width * pict_height))))
268   {
269     Error("failed to allocate grid", -1);
270   }
271   bzero((char *) grid, pict_width * pict_height);
272 
273   /* Make the byte array which will hold the access flag */
274 
275   if (!(flag = (u_char *) malloc((unsigned) (pict_width * pict_height))))
276   {
277     Error("failed to allocate flag", -1);
278   }
279   bzero((char *) flag, pict_width * pict_height);
280 
281   /* Make the array which will hold the integral */
282 
283   if (!(integr = (double *) malloc(sizeof(double) * (pict_width * pict_height))))
284   {
285     Error("failed to allocate integr", -1);
286   }
287 
288   /* Make the array which will hold the last access time */
289 
290   if (!(ltime = (double *) malloc(sizeof(double) * (pict_width * pict_height))))
291   {
292     Error("failed to allocate ltime", -1);
293   }
294 
295   for(i = 0; i < pict_width * pict_height; i++, *ltime = 0.0, *integr = 0.0);
296 
297   /* clear the array display */
298   UpdatePixRegion(0, pict_height - 1, 0, pict_width - 1, 0, 0.0);
299   DisplayPixRegion(0, pict_height - 1, 0, pict_width - 1);
300 }
301 
302 /**/
303 /* JJU: void Quit(Widget widget, caddr_t data, XEvent *event) */
Quit(Widget widget,XtPointer data,XtPointer event)304 void Quit(Widget widget, XtPointer data, XtPointer event)
305 {
306   exit(0);
307 }
308 
309 
310 /**/
311 /* JJU: void StartStop(Widget widget, caddr_t data, XEvent *event) */
StartStop(Widget widget,XtPointer data,XtPointer event)312 void StartStop(Widget widget, XtPointer data, XtPointer event)
313 {
314   /* Toggle propagation of display */
315 
316   if (working)
317   {
318     XtRemoveTimeOut(timer);
319     working = False;
320     XtSetArg(arg[0], XtNlabel, "Start");   /* Reset button label */
321     XtSetValues(start_stop_button,arg,1);
322     XFlush(display);
323   }
324   else
325   {
326     XtSetArg(arg[0], XtNlabel, "Stop");   /* Reset button label */
327     XtSetValues(start_stop_button,arg,1);
328     timer = XtAppAddTimeOut(xregion_app, interval, TimeOutCallback, NULL);
329     working = True;
330     XFlush(display);
331   }
332 }
333 
334