Annotation of OpenXM_contrib/gnuplot/term/sun.trm, Revision 1.1.1.1
1.1 maekawa 1: /*
2: * $Id: sun.trm,v 1.15 1998/04/14 00:18:07 drd Exp $
3: *
4: */
5:
6: /* GNUPLOT - sun.trm */
7:
8: /*[
9: * Copyright 1990 - 1993, 1998
10: *
11: * Permission to use, copy, and distribute this software and its
12: * documentation for any purpose with or without fee is hereby granted,
13: * provided that the above copyright notice appear in all copies and
14: * that both that copyright notice and this permission notice appear
15: * in supporting documentation.
16: *
17: * Permission to modify the software is granted, but not the right to
18: * distribute the complete modified source code. Modifications are to
19: * be distributed as patches to the released version. Permission to
20: * distribute binaries produced by compiling modified sources is granted,
21: * provided you
22: * 1. distribute the corresponding source modifications from the
23: * released version in the form of a patch file along with the binaries,
24: * 2. add special version identification to distinguish your version
25: * in addition to the base release version number,
26: * 3. provide your name and address as the primary contact for the
27: * support of your modified version, and
28: * 4. retain our contact information in regard to use of the base
29: * software.
30: * Permission to distribute the released version of the source code along
31: * with corresponding source modifications in the form of a patch file is
32: * granted with same provisions 2 through 4 for binary distributions.
33: *
34: * This software is provided "as is" without express or implied warranty
35: * to the extent permitted by applicable law.
36: ]*/
37:
38: /*
39: * This file is included by ../term.c.
40: *
41: * This terminal driver supports:
42: * SUNview windowing system
43: *
44: * AUTHORS
45: * Maurice Castro
46: *
47: * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
48: *
49: */
50: /*
51: * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
52: */
53:
54: #include "driver.h"
55:
56: #ifdef TERM_REGISTER
57: register_term(sun)
58: #endif
59:
60: #ifdef TERM_PROTO
61: TERM_PUBLIC void SUN_init __PROTO((void));
62: TERM_PUBLIC void SUN_graphics __PROTO((void));
63: TERM_PUBLIC void SUN_text __PROTO((void));
64: TERM_PUBLIC void SUN_linetype __PROTO((int linetype));
65: TERM_PUBLIC void SUN_move __PROTO((unsigned int x, unsigned int y));
66: TERM_PUBLIC void SUN_vector __PROTO((unsigned int x, unsigned int y));
67: TERM_PUBLIC void SUN_put_text __PROTO((unsigned int x, unsigned int y, char *str));
68: TERM_PUBLIC int SUN_justify_text __PROTO((enum JUSTIFY mode));
69: TERM_PUBLIC void SUN_reset __PROTO((void));
70: #define SUN_XMAX 600
71: #define SUN_YMAX 512
72:
73: #define SUN_VCHAR (12) /* default, will be changed */
74: #define SUN_HCHAR (8) /* default, will be changed */
75: #define SUN_VTIC (SUN_YMAX/80)
76: #define SUN_HTIC (SUN_XMAX/80)
77: #endif /* TERM_PROTO */
78:
79: #ifndef TERM_PROTO_ONLY
80: #ifdef TERM_BODY
81: #include <suntool/sunview.h>
82: #include <suntool/canvas.h>
83: #include <suntool/scrollbar.h>
84: #include <suntool/panel.h>
85: #include <pixrect/pixrect_hs.h>
86:
87: void sun_setmaskpixel __PROTO((unsigned int x, unsigned int y, unsigned int value));
88: void sun_line __PROTO((unsigned int x1, unsigned int x2, unsigned int y1, unsigned int y2));
89: static Notify_value local_notice_destroy __PROTO((Frame frame, Destroy_status status));
90:
91: #define MARGIN 5
92: #define MINWIN 128
93:
94: static Frame frame;
95: static Canvas canvas;
96: static Pixwin *pw;
97: static struct pixfont *sun_font = NULL;
98:
99: static enum JUSTIFY sun_justify = LEFT;
100:
101: static Notify_value local_notice_destroy();
102:
103: extern Notify_error notify_dispatch();
104:
105: /* dotted line generator */
106: unsigned int sun_value = 1; /* this can be used for colour */
107: unsigned int sun_line_mask = 0xffff; /* 16 bit mask for dotted lines */
108: static unsigned int sun_pattern[] =
109: {0xffff, 0x1111,
110: 0xffff, 0x5555, 0x3333, 0x7777, 0x3f3f, 0x0f0f, 0x5f5f};
111: int sun_mask_count = 0;
112: unsigned int sun_lastx, sun_lasty; /* last pixel set - used by sun_line */
113:
114:
115: TERM_PUBLIC void SUN_init()
116: {
117: struct termentry *t = term;
118: struct pr_subregion bound;
119:
120: frame = window_create(NULL, FRAME,
121: FRAME_LABEL, "Gnuplot",
122: 0);
123: notify_interpose_destroy_func(frame, local_notice_destroy);
124: canvas = window_create(frame, CANVAS,
125: CANVAS_AUTO_EXPAND, TRUE,
126: CANVAS_AUTO_SHRINK, TRUE,
127: CANVAS_MARGIN, MARGIN,
128: 0);
129: notify_do_dispatch();
130: pw = canvas_pixwin(canvas);
131: window_set(frame, WIN_SHOW, TRUE, 0);
132:
133: /* figure out font and rough size */
134: sun_font = pf_default();
135: pf_textbound(&bound, 1, sun_font, "M");
136: t->v_char = bound.size.y;
137: t->h_char = bound.size.x;
138:
139: return;
140: }
141:
142: TERM_PUBLIC void SUN_graphics()
143: {
144: term->xmax = (int) window_get(canvas, CANVAS_WIDTH);
145: term->ymax = (int) window_get(canvas, CANVAS_HEIGHT);
146: pw_writebackground(pw, 0, 0, term->xmax, term->ymax, PIX_SRC);
147: notify_dispatch();
148: /* do not let the user make the window too small */
149: if ((term->xmax) < MINWIN) {
150: window_set(frame,
151: WIN_WIDTH, MINWIN + 2 * MARGIN + 24,
152: 0);
153: notify_dispatch();
154: SUN_graphics();
155: }
156: if ((term->ymax) < MINWIN) {
157: window_set(frame,
158: WIN_HEIGHT, MINWIN + 2 * MARGIN + 24,
159: 0);
160: notify_dispatch();
161: SUN_graphics();
162: }
163: notify_dispatch();
164: return;
165: }
166:
167: TERM_PUBLIC void SUN_text()
168: {
169: notify_dispatch();
170: return; /* enter text from another window!!! */
171: }
172:
173: TERM_PUBLIC void SUN_linetype(linetype)
174: int linetype;
175: {
176: if (linetype >= 7)
177: linetype %= 7;
178: sun_line_mask = sun_pattern[linetype + 2];
179: sun_mask_count = 0;
180: }
181:
182:
183: TERM_PUBLIC void SUN_move(x, y)
184: unsigned int x, y;
185: {
186: sun_lastx = x;
187: sun_lasty = y;
188: notify_dispatch();
189: return;
190: }
191:
192: TERM_PUBLIC void SUN_vector(x, y)
193: unsigned int x, y;
194: {
195: if ((x >= term->xmax) || (y >= term->ymax))
196: return;
197: sun_line(sun_lastx, x, sun_lasty, y);
198: canvas_pixwin(canvas);
199: notify_dispatch();
200: return;
201: }
202:
203: TERM_PUBLIC void SUN_put_text(x, y, str)
204: unsigned int x, y;
205: char *str;
206: {
207: struct pr_subregion bound;
208:
209: if ((x >= term->xmax) || (y >= term->ymax))
210: return;
211:
212: pf_textbound(&bound, strlen(str), sun_font, str);
213: y = term->ymax - 1 - y + bound.size.y / 3; /* vertical centering */
214:
215: switch (sun_justify) {
216: case LEFT:
217: break;
218: case CENTRE:
219: x -= bound.size.x / 2;
220: break;
221: case RIGHT:
222: x -= bound.size.x;
223: break;
224: }
225: pw_text(pw, x, y, PIX_SRC | PIX_DST, 0, str);
226: canvas_pixwin(canvas);
227: notify_dispatch();
228: return;
229: }
230:
231:
232: TERM_PUBLIC int SUN_justify_text(mode)
233: enum JUSTIFY mode;
234: {
235: sun_justify = mode;
236: return (TRUE);
237: }
238:
239:
240:
241:
242: TERM_PUBLIC void SUN_reset()
243: {
244:
245: term->xmax = SUN_XMAX;
246: term->ymax = SUN_YMAX;
247: window_set(frame, WIN_SHOW, FALSE, 0);
248: return;
249: }
250:
251:
252:
253: void sun_setmaskpixel(x, y, value)
254: unsigned int x, y, value;
255: {
256: /* dotted line generator */
257: if ((sun_line_mask >> sun_mask_count) & (unsigned int) (1)) {
258: pw_put(pw, x, term->ymax - 1 - y, sun_value);
259: }
260: sun_mask_count = (sun_mask_count + 1) % 16;
261: sun_lastx = x; /* last pixel set with mask */
262: sun_lasty = y;
263: }
264:
265:
266:
267:
268: void sun_line(x1, x2, y1, y2)
269: unsigned int x1, x2, y1, y2;
270: {
271: int runcount;
272: int dx, dy;
273: int xinc, yinc;
274: unsigned int xplot, yplot;
275:
276: runcount = 0;
277: dx = ABS((int) (x1) - (int) (x2));
278: if (x2 > x1)
279: xinc = 1;
280: if (x2 == x1)
281: xinc = 0;
282: if (x2 < x1)
283: xinc = -1;
284: dy = ABS((int) (y1) - (int) (y2));
285: if (y2 > y1)
286: yinc = 1;
287: if (y2 == y1)
288: yinc = 0;
289: if (y2 < y1)
290: yinc = -1;
291: xplot = x1;
292: yplot = y1;
293: if (dx > dy) {
294: /* iterate x */
295: if ((sun_line_mask == 0xffff) ||
296: ((xplot != sun_lastx) && (yplot != sun_lasty)))
297: sun_setmaskpixel(xplot, yplot, sun_value);
298: while (xplot != x2) {
299: xplot += xinc;
300: runcount += dy;
301: if (runcount >= (dx - runcount)) {
302: yplot += yinc;
303: runcount -= dx;
304: }
305: sun_setmaskpixel(xplot, yplot, sun_value);
306: }
307: } else {
308: /* iterate y */
309: if ((sun_line_mask == 0xffff) ||
310: ((xplot != sun_lastx) && (yplot != sun_lasty)))
311: sun_setmaskpixel(xplot, yplot, sun_value);
312: while (yplot != y2) {
313: yplot += yinc;
314: runcount += dx;
315: if (runcount >= (dy - runcount)) {
316: xplot += xinc;
317: runcount -= dy;
318: }
319: sun_setmaskpixel(xplot, yplot, sun_value);
320: }
321: }
322: }
323:
324:
325: static Notify_value local_notice_destroy(frame, status)
326: Frame frame;
327: Destroy_status status;
328: {
329: if (status != DESTROY_CHECKING) {
330: SUN_reset();
331: /* extern TBOOLEAN term_init is gone; is it sufficient just */
332: /* to comment it out? -lh */
333: /* term_init = FALSE; */
334: }
335: return (NOTIFY_DONE);
336: }
337:
338: #endif /* TERM_BODY */
339:
340: #ifdef TERM_TABLE
341:
342: TERM_TABLE_START(sun_driver)
343: "sun", "SunView window system",
344: SUN_XMAX, SUN_YMAX, SUN_VCHAR, SUN_HCHAR,
345: SUN_VTIC, SUN_HTIC, options_null, SUN_init, SUN_reset,
346: SUN_text, null_scale, SUN_graphics, SUN_move, SUN_vector,
347: SUN_linetype, SUN_put_text, null_text_angle,
348: SUN_justify_text, line_and_point, do_arrow, set_font_null
349: TERM_TABLE_END(sun_driver)
350:
351: #undef LAST_TERM
352: #define LAST_TERM sun_driver
353:
354: #endif /* TERM_TABLE */
355: #endif /* TERM_PROTO_ONLY */
356:
357: #ifdef TERM_HELP
358: START_HELP(sun)
359: "1 sun",
360: "?commands set terminal sun",
361: "?set terminal sun",
362: "?set term sun",
363: "?terminal sun",
364: "?term sun",
365: "?sun",
366: " The `sun` terminal driver supports the SunView window system. It has no",
367: " options."
368: END_HELP(sun)
369: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>