Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical ALgorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2008, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
37
/* main procedure to test out Gdraw functions in this directory */
38
#include <stdio.h>
39
#include "Gdraws0.h"
40
#include "../view3D/header.h"
41
42
GC gc, gc1;
43
Display *dsply;
44
int scrn;
45
viewPoints *viewport;
46
47
int psInit=no;
48
GCptr GChead=NULL;
49
char *PSfilename="OUTPUT.ps";
50
char *envAXIOM;
51
52
int
53
main(int argc, char **argv)
54
{
55
56
XGCValues values;
57
58
XEvent report;
59
int x0=0, y0=0, width=300, height=200, border=3;
60
61
char *fontname = "6x13";
62
XFontStruct *dsp_font;
63
64
Window menu;
65
char *str1 = " Print out the PostScript file? ",
66
*str0 = "Generate a PostScript file (OUTPUT.ps)?";
67
int m_width, m_height, flag=yes;
68
69
/* open display */
70
if ((dsply = XOpenDisplay(NULL)) == NULL) {
71
printf("Can't open display NULL\n");
72
exit(-1);
73
}
74
75
scrn = DefaultScreen(dsply);
76
77
/* access font */
78
Gdraws_load_font(&dsp_font, fontname);
79
80
values.background = WhitePixel(dsply, scrn);
81
values.foreground = BlackPixel(dsply, scrn);
82
83
gc = XCreateGC(dsply, RootWindow(dsply, scrn),
84
(GCForeground | GCBackground), &values);
85
PSGlobalInit(); /* must initiate before using G/PS functions */
86
PSCreateContext(gc, "gc", psNormalWidth, psButtCap,
87
psMiterJoin, psWhite, psBlack);
88
XSetFont(dsply, gc, dsp_font->fid);
89
gc1 = XCreateGC(dsply, RootWindow(dsply, scrn),
90
(GCForeground | GCBackground), &values);
91
PSCreateContext(gc1, "gc1", psNormalWidth, psButtCap, psMiterJoin,
92
psWhite, psBlack);
93
XSetFont(dsply, gc1, dsp_font->fid);
94
95
if (!(viewport = (viewPoints *)malloc(sizeof(viewPoints)))) {
96
fprintf(stderr,"Ran out of memory (malloc) trying to create a viewport.\n");
97
exit(-1);
98
}
99
100
viewport->titleWindow = XCreateSimpleWindow(dsply, RootWindow(dsply,scrn),
101
x0, y0, width+6,
102
height+32+height/4, border,
103
BlackPixel(dsply, scrn),
104
WhitePixel(dsply, scrn));
105
106
viewport->viewWindow = XCreateSimpleWindow(dsply, viewport->titleWindow,
107
x0, y0+20, width, height, border,
108
BlackPixel(dsply, scrn),
109
WhitePixel(dsply, scrn));
110
111
strcpy(viewport->title, "what is a test title?");
112
113
m_width = width; m_height = height/4;
114
menu = XCreateSimpleWindow(dsply, viewport->titleWindow, x0, y0+20+height+6,
115
m_width, m_height, border,
116
BlackPixel(dsply,scrn), WhitePixel(dsply,scrn));
117
118
XSelectInput(dsply, viewport->viewWindow,
119
KeyPressMask|ButtonPressMask|ExposureMask);
120
XSelectInput(dsply, viewport->titleWindow, KeyPressMask|ExposureMask);
121
XSelectInput(dsply, menu, KeyPressMask|ButtonPressMask|ExposureMask);
122
123
XMapWindow(dsply, viewport->viewWindow);
124
XMapWindow(dsply, viewport->titleWindow);
125
XFlush(dsply);
126
127
while (yes) {
128
XNextEvent(dsply, &report);
129
switch (report.type) {
130
131
case Expose:
132
if (report.xexpose.window==viewport->titleWindow) {
133
if (GDrawImageString(gc, viewport->titleWindow,
134
20, 15, viewport->title,
135
strlen(viewport->title),X) == psError)
136
printf("screen draw image string failed.\n");
137
if (Gdraws_data(X) == psError)
138
printf("screen Gdraws_data failed.\n");
139
}
140
if (report.xexpose.window==viewport->viewWindow) {
141
if (Gdraws_data(X) == psError)
142
printf("screen Gdraws_data failed.\n");
143
}
144
else if (report.xexpose.window==menu) {
145
if (flag)
146
Gdraws_draw_menu(menu, str0, m_width, m_height);
147
else
148
Gdraws_draw_menu(menu, str1, m_width, m_height);
149
}
150
break;
151
152
case ButtonPress:
153
if (report.xbutton.window==viewport->viewWindow) {
154
XMapWindow(dsply, menu);
155
XFlush(dsply);
156
}
157
else if (report.xbutton.window==menu && flag) {
158
XUnmapWindow(dsply, menu);
159
if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x,
160
report.xbutton.y)) {
161
flag=no;
162
XMapWindow(dsply, menu);
163
PSInit(viewport->viewWindow, viewport->titleWindow);
164
if (Gdraws_data(PS) != psError)
165
PSCreateFile(3,viewport->viewWindow,
166
viewport->titleWindow,viewport->title);
167
else printf("PS Gdraws_data failed.\n");
168
}
169
}
170
else if (report.xbutton.window==menu && !flag) {
171
XUnmapWindow(dsply, menu);
172
if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x,
173
report.xbutton.y))
174
system("print OUTPUT.ps");
175
flag = yes;
176
}
177
break;
178
179
case KeyPress:
180
if (report.xkey.window==viewport->viewWindow ||
181
report.xkey.window==viewport->titleWindow) {
182
XFreeGC(dsply, gc);
183
XFreeGC(dsply, gc1);
184
XCloseDisplay(dsply);
185
PSClose();
186
exit(1);
187
}
188
else if (report.xkey.window==menu) XUnmapWindow(dsply, menu);
189
190
default:
191
break;
192
}
193
}
194
return 0;
195
}
196
197