Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / mgr.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: mgr.trm,v 1.11 2006/07/21 02:35:47 sfeam Exp $
3  */
4
5 /* GNUPLOT - mgr.trm */
6
7 /*[
8  * Copyright 1986 - 1993, 1998, 2004   Thomas Williams, Colin Kelley
9  *
10  * Permission to use, copy, and distribute this software and its
11  * documentation for any purpose with or without fee is hereby granted,
12  * provided that the above copyright notice appear in all copies and
13  * that both that copyright notice and this permission notice appear
14  * in supporting documentation.
15  *
16  * Permission to modify the software is granted, but not the right to
17  * distribute the complete modified source code.  Modifications are to
18  * be distributed as patches to the released version.  Permission to
19  * distribute binaries produced by compiling modified sources is granted,
20  * provided you
21  *   1. distribute the corresponding source modifications from the
22  *    released version in the form of a patch file along with the binaries,
23  *   2. add special version identification to distinguish your version
24  *    in addition to the base release version number,
25  *   3. provide your name and address as the primary contact for the
26  *    support of your modified version, and
27  *   4. retain our contact information in regard to use of the base
28  *    software.
29  * Permission to distribute the released version of the source code along
30  * with corresponding source modifications in the form of a patch file is
31  * granted with same provisions 2 through 4 for binary distributions.
32  *
33  * This software is provided "as is" without express or implied warranty
34  * to the extent permitted by applicable law.
35 ]*/
36
37 /*
38  * This file is included by ../term.c.
39  *
40  * This terminal driver supports:
41  *  Mgr window system, color display
42  *
43  * AUTHOR
44  *  Vincent Broman, broman@nosc.mil
45  */
46 /*
47  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
48  */
49
50 #include "driver.h"
51
52 #ifdef TERM_REGISTER
53 register_term(mgr)
54 #endif
55
56 #ifdef TERM_PROTO
57 TERM_PUBLIC void MGR_init __PROTO((void));
58 TERM_PUBLIC void MGR_graphics __PROTO((void));
59 TERM_PUBLIC void MGR_text __PROTO((void));
60 TERM_PUBLIC void MGR_linetype __PROTO((int linetype));
61 TERM_PUBLIC void MGR_move __PROTO((unsigned int x, unsigned int y));
62 TERM_PUBLIC void MGR_vector __PROTO((unsigned int x, unsigned int y));
63 TERM_PUBLIC void MGR_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
64 TERM_PUBLIC void MGR_reset __PROTO((void));
65 #define MGR_XMAX 640
66 #define MGR_YMAX 400
67 #define MGR_VCHAR 16
68 #define MGR_HCHAR 8
69 #define MGR_VTIC 4
70 #define MGR_HTIC 4
71 #endif /* TERM_PROTO */
72
73 #ifndef TERM_PROTO_ONLY
74 #ifdef TERM_BODY
75 #undef ESC
76 #include <term.h>               /* from Mgr, not gnuplot */
77
78
79
80 static int MGR_border = 5;
81 static int MGR_winnbr = 0;
82
83 static int MGR_rowcount = 24;
84 static int MGR_winwidth = MGR_XMAX;
85 static int MGR_winheight = MGR_YMAX;
86 static int MGR_vchar = MGR_VCHAR;
87 static int MGR_hchar = MGR_HCHAR;
88
89
90 TERM_PUBLIC void
91 MGR_init()
92 {
93     char res[300];
94     int winnbr;
95     int w, h, bor;
96
97     m_setup(0);
98     m_ttyset();
99
100     m_getinfo(G_SYSTEM);
101     if (m_gets(res) && sscanf(res, "%*s%d%d%d", &w, &h, &bor) == 3)
102         MGR_border = bor;
103
104     m_newwin(0, 0, MGR_winwidth + 2 * MGR_border,
105              MGR_winheight + 2 * MGR_border);
106
107     if (m_gets(res) && sscanf(res, "%d", &winnbr) == 1)
108         MGR_winnbr = winnbr;
109
110     /* if no alt window is created, then the main window is used
111      * and if size is different, term_tbl updated later */
112     m_selectwin(MGR_winnbr);
113     m_setmode(M_ABS);
114
115     m_getinfo(G_FONT);
116     if (m_gets(res) && sscanf(res, "%d %d", &w, &h) == 2) {
117         MGR_vchar = h;
118         MGR_hchar = w;
119     }
120     m_ttyreset();
121
122     term->v_char = MGR_vchar;
123     term->h_char = MGR_hchar;
124     term->v_tic = MGR_vchar / 4;
125     term->h_tic = MGR_hchar / 2;
126
127     m_selectwin(0);
128     m_flush();
129 }
130
131
132 TERM_PUBLIC void
133 MGR_graphics()
134 {
135     char res[32];
136     int c, r, w, h;
137
138     m_selectwin(MGR_winnbr);
139     m_setmode(M_ACTIVATE);
140     m_clear();
141
142     /* we permit the user to reshape the window arbitrarily.
143        do_plot calls boundary to recheck the term_tbl for each plot */
144     m_ttyset();
145     m_getinfo(G_WINSIZE);
146     if (m_gets(res) && sscanf(res, "%d %d", &c, &r) == 2)
147         MGR_rowcount = r;
148     m_getinfo(G_COORDS);
149     if (m_gets(res) && sscanf(res, "%d %d %d %d", &c, &r, &w, &h) == 4) {
150         term->xmax = MGR_winwidth = w;
151         term->ymax = MGR_winheight = h;
152     }
153     m_ttyreset();
154     m_flush();
155 }
156
157
158 TERM_PUBLIC void
159 MGR_text()
160 {
161     m_go(0, 0);
162     m_aligntext();
163     if (MGR_winnbr == 0)
164         m_move(0, MGR_rowcount - 1);
165     m_selectwin(0);
166     m_flush();
167 }
168
169
170 TERM_PUBLIC void
171 MGR_linetype(int linetype)
172 {
173 /*
174  * this mapping of colors is intended for a color sun on which
175  * colors 0-23 are defined, 0 is white, 1 is black.
176  */
177     m_linecolor(B_SRC, (linetype < 0) ? 1 : (2 + (linetype % 22)));
178 }
179
180
181 TERM_PUBLIC void
182 MGR_move(unsigned int x, unsigned int y)
183 {
184     m_go(x, MGR_winheight - 1 - y);
185 }
186
187
188 TERM_PUBLIC void
189 MGR_vector(unsigned int x, unsigned int y)
190 {
191     m_draw(x, MGR_winheight - 1 - y);
192 }
193
194
195 TERM_PUBLIC void
196 MGR_put_text(unsigned int x, unsigned int y, const char *str)
197 {
198     MGR_move(x, y - MGR_vchar / 2);
199     m_aligntext();
200     m_printstr(str);
201 }
202
203
204 TERM_PUBLIC void
205 MGR_reset()
206 {
207     m_destroywin(MGR_winnbr);
208     MGR_winnbr = 0;
209     m_setmode(M_ACTIVATE);
210     m_flush();
211 }
212
213 #endif /* TERM_BODY */
214
215 #ifdef TERM_TABLE
216
217 TERM_TABLE_START(mgr_driver)
218     "mgr", "Mgr window system",
219     /* dimensions nominal, replaced during MGR_graphics call */
220     MGR_XMAX, MGR_YMAX, MGR_VCHAR, MGR_HCHAR,
221     MGR_VTIC, MGR_HTIC, options_null, MGR_init, MGR_reset,
222     MGR_text, null_scale, MGR_graphics, MGR_move, MGR_vector,
223     MGR_linetype, MGR_put_text, null_text_angle,
224     null_justify_text, do_point, do_arrow, set_font_null
225 TERM_TABLE_END(mgr_driver)
226
227 #undef LAST_TERM
228 #define LAST_TERM mgr_driver
229
230 #endif /* TERM_TABLE */
231 #endif /* TERM_PROTO_ONLY */
232
233 #ifdef TERM_HELP
234 START_HELP(mgr)
235 "1 mgr",
236 "?commands set terminal mgr",
237 "?set terminal mgr",
238 "?set term mgr",
239 "?terminal mgr",
240 "?term mgr",
241 "?mgr",
242 " The `mgr` terminal driver supports the Mgr Window system.  It has no options."
243 END_HELP(mgr)
244 #endif