File: ggi.trm

package info (click to toggle)
gnuplot 3.7.2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,212 kB
  • ctags: 4,635
  • sloc: ansic: 43,538; cpp: 970; makefile: 883; lisp: 661; sh: 578; asm: 539; objc: 379; csh: 297; pascal: 192; perl: 138
file content (270 lines) | stat: -rw-r--r-- 7,864 bytes parent folder | download
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 * $Id: ggi.trm,v 1.1.6.1 2000/10/20 18:41:59 lhecking Exp $
 *
 */

/* GNUPLOT - ggi.trm */

/*[
 * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the complete modified source code.  Modifications are to
 * be distributed as patches to the released version.  Permission to
 * distribute binaries produced by compiling modified sources is granted,
 * provided you
 *   1. distribute the corresponding source modifications from the
 *    released version in the form of a patch file along with the binaries,
 *   2. add special version identification to distinguish your version
 *    in addition to the base release version number,
 *   3. provide your name and address as the primary contact for the
 *    support of your modified version, and
 *   4. retain our contact information in regard to use of the base
 *    software.
 * Permission to distribute the released version of the source code along
 * with corresponding source modifications in the form of a patch file is
 * granted with same provisions 2 through 4 for binary distributions.
 *
 * This software is provided "as is" without express or implied warranty
 * to the extent permitted by applicable law.
]*/

/*
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *   General Graphics Interface
 *
 * AUTHOR
 *  Cesar Crusius <crusius@leland.stanford.edu>
 *
 * See also: http://www.ggi-project.org/
 *
 * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
 */

#include "driver.h"
#ifdef TERM_REGISTER
register_term(ggi)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void GGI_graphics __PROTO((void));
TERM_PUBLIC void GGI_init __PROTO((void)); /* Done. */
TERM_PUBLIC void GGI_linetype __PROTO((int));
TERM_PUBLIC void GGI_move __PROTO((unsigned int,unsigned int));
TERM_PUBLIC void GGI_options __PROTO((void)); /* Done. */
TERM_PUBLIC void GGI_put_text __PROTO((unsigned int,unsigned int,char*));
TERM_PUBLIC void GGI_reset __PROTO((void)); /* Done. */
TERM_PUBLIC void GGI_text __PROTO((void));
TERM_PUBLIC void GGI_vector __PROTO((unsigned int,unsigned int));
#define GOT_GGI_PROTO
#endif

#define GGI_XMAX 800
#define GGI_YMAX 600
#define GGI_VCHAR 8
#define GGI_HCHAR 8
#define GGI_VTIC 8
#define GGI_HTIC 8

#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY

#include <ggi/ggi.h>
#include <ggi/wmh.h>

/* First to some global variables
 *
 * GGIvisual is our 'piece of paper.'
 * GGIborderColor and axixColor have the obvious meanings.
 * GGIcolors are the colors for linestyles 0 and up.
 * GGImap is for initializing colors.
 * GGIx,GGIy are the current coordinates.
 * GGIxmax,GGIymax are the maximum coordinates in the visual.
 */
static ggi_visual_t GGIvisual=NULL;
static ggi_pixel GGIborderColor;
static ggi_pixel GGIaxisColor;
static ggi_pixel GGIblack;
static ggi_pixel GGIcolors[6];
static ggi_color GGImap;
static unsigned int GGIx,GGIy;
static unsigned int GGIxmax,GGIymax;
static unsigned int Xenv;

static void init_ggi_driver()
{
    ggi_pixel GGIwhite,GGIred,GGIgreen,GGIblue,GGIcyan,GGImagenta;
    ggi_pixel GGIyellow;
    if(GGIvisual==NULL)
    {
	if(ggiInit()) {}
	if(NULL==(GGIvisual=ggiOpen(NULL))) ggiExit();
	if(ggiSetSimpleMode(GGIvisual,GGI_AUTO,GGI_AUTO,GGI_AUTO,GT_AUTO)) ggiExit();
    }
    ggiAddFlags(GGIvisual, GGIFLAG_ASYNC);
    GGImap.r=0xFFFF; GGImap.g=0xFFFF; GGImap.b=0xFFFF; GGIwhite=ggiMapColor(GGIvisual,&GGImap);
    GGImap.r=0x0000; GGImap.g=0x0000; GGImap.b=0x0000; GGIblack=ggiMapColor(GGIvisual,&GGImap);
    GGImap.r=0xFFFF; GGImap.g=0x0000; GGImap.b=0x0000; GGIred=ggiMapColor(GGIvisual,&GGImap);
    GGImap.r=0x0000; GGImap.g=0xFFFF; GGImap.b=0x0000; GGIgreen=ggiMapColor(GGIvisual,&GGImap);
    GGImap.r=0x0000; GGImap.g=0x0000; GGImap.b=0xFFFF; GGIblue=ggiMapColor(GGIvisual,&GGImap);
    GGImap.r=0x0000; GGImap.g=0xFFFF; GGImap.b=0xFFFF; GGIcyan=ggiMapColor(GGIvisual,&GGImap);
    GGImap.r=0xFFFF; GGImap.g=0x0000; GGImap.b=0xFFFF; GGImagenta=ggiMapColor(GGIvisual,&GGImap);
    GGImap.r=0xFFFF; GGImap.g=0xFFFF; GGImap.b=0x0000; GGIyellow=ggiMapColor(GGIvisual,&GGImap);
    GGIborderColor=GGIwhite;
    GGIaxisColor=GGIwhite;
    GGIcolors[0]=GGIred;
    GGIcolors[1]=GGIgreen;
    GGIcolors[2]=GGIblue;
    GGIcolors[3]=GGImagenta;
    GGIcolors[4]=GGIcyan;
    GGIcolors[5]=GGIyellow;
}

/* Called begore a graphic is displayed */
TERM_PUBLIC void GGI_graphics()
{ 
    if(!Xenv)
    {
	init_ggi_driver();
	return;
    }
    ggiSetGCForeground(GGIvisual,GGIblack);
    ggiDrawBox(GGIvisual,0,0,GGIxmax,GGIymax);
}

/*
 * init
 * -----------------------
 * Called only once, when the terminal is initialized. We have to open the visual here because it
 * is during 'init' that we have to change the terminal dimensions (xmax, ymax).
 */ 
TERM_PUBLIC void GGI_init() 
{ 
    ggi_mode GGImode;
    if(ggiInit()) { }
    if(NULL==(GGIvisual=ggiOpen(NULL))) ggiExit();
    if(ggiSetSimpleMode(GGIvisual,GGI_AUTO,GGI_AUTO,GGI_AUTO,GT_AUTO)) ggiExit();
    ggiGetMode(GGIvisual,&GGImode);
    term->xmax=GGImode.virt.x;
    term->ymax=GGImode.virt.y;
    GGIxmax=term->xmax-1;
    GGIymax=term->ymax-1;
    Xenv=!ggiWmhInit();
    if(!(Xenv=!ggiWmhAttach(GGIvisual))) ggiWmhDetach(GGIvisual);
    else Xenv=!ggiWmhSetTitle(GGIvisual,"GGI Gnuplot Driver");
    if(!Xenv)
    {
	ggiWmhDetach(GGIvisual);
	ggiWmhExit();
    	ggiClose(GGIvisual);
	GGIvisual=NULL;
	ggiExit();
    }
    else init_ggi_driver();
}

TERM_PUBLIC void GGI_linetype(linetype)
int linetype;
{
    if(linetype==-2) ggiSetGCForeground(GGIvisual,GGIborderColor);
    if(linetype==-1) ggiSetGCForeground(GGIvisual,GGIaxisColor);
    if(linetype<0) return;
    if(linetype>=6) linetype%=6;
    ggiSetGCForeground(GGIvisual,GGIcolors[linetype]);
}

TERM_PUBLIC void GGI_move(x,y)
unsigned int x,y;
{
    GGIx=x;
    GGIy=y;
}

TERM_PUBLIC void GGI_options() { }
/* Called when terminal is terminated */
TERM_PUBLIC void GGI_reset() 
{
    if(GGIvisual!=NULL)
    {
	if(Xenv)
	{
	    ggiWmhDetach(GGIvisual);
	    ggiWmhExit();
	}
	ggiClose(GGIvisual); 
    	ggiExit();
    }
}

TERM_PUBLIC void GGI_put_text(x,y,str)
unsigned int x,y;
char *str;
{
    ggi_pixel current_foreground;
    ggiGetGCForeground(GGIvisual,&current_foreground);
    ggiSetGCForeground(GGIvisual,GGIborderColor);
    ggiPuts(GGIvisual,x,GGIymax-y-4,str);
    ggiSetGCForeground(GGIvisual,current_foreground);
}

/* Wait for a key to be pressed and exit graphics mode if running in console mode. */
TERM_PUBLIC void GGI_text(void)
{
    ggiFlush(GGIvisual);
    if(Xenv) return;
    ggiGetc(GGIvisual);
    ggiClose(GGIvisual);
    ggiExit();
    GGIvisual=NULL;
}

TERM_PUBLIC void GGI_vector(x,y)
unsigned int x,y;
{
    ggiDrawLine(GGIvisual,GGIx,GGIymax-GGIy,x,GGIymax-y);
    GGIx=x;
    GGIy=y;
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(ggi_driver)
    "ggi", "GGI target",
    GGI_XMAX, GGI_YMAX, GGI_VCHAR, GGI_HCHAR, GGI_VTIC, GGI_HTIC,
    GGI_options, GGI_init, GGI_reset, GGI_text,
    null_scale, GGI_graphics, GGI_move, GGI_vector,
    GGI_linetype, GGI_put_text,
    0, /* angle */
    0, /* justify text */
    0, /* point */
    0, /* arrow */
    0, /* set_font */
    0, /* set_pointsize */
    0, /* flags */
    0, /* suspend */
    0, /* resume */
    0, /* fillbox */
    0 /* linewidth */
TERM_TABLE_END(ggi_driver)

#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */

#ifdef TERM_HELP
START_HELP(ggi)
"1 ggi",
"?set terminal ggi",
"?ggi",
" The GGI terminal generates output to a GGI target."
END_HELP(ggi)
#endif