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-2010, 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
#include "openaxiom-c-macros.h"
37
38
#include <stdio.h>
39
#include <stdlib.h>
40
41
#include <X11/Xlib.h>
42
#include <X11/Xutil.h>
43
#include <X11/Xos.h>
44
#include <X11/Intrinsic.h>
45
#include <X11/StringDefs.h>
46
#include <X11/cursorfont.h>
47
48
#define XShadeWidth 4
49
#define XShadeMax 17
50
51
char XShadeBits[] = {
52
0x00, 0x00, 0x00, 0x00,
53
0x01, 0x00, 0x00, 0x00,
54
0x01, 0x00, 0x04, 0x00,
55
0x05, 0x00, 0x04, 0x00,
56
0x05, 0x00, 0x05, 0x00,
57
0x05, 0x02, 0x05, 0x00,
58
0x05, 0x02, 0x05, 0x08,
59
0x05, 0x0a, 0x05, 0x08,
60
0x05, 0x0a, 0x05, 0x0a,
61
0x07, 0x0a, 0x05, 0x0a,
62
0x07, 0x0a, 0x0d, 0x0a,
63
0x0f, 0x0a, 0x0d, 0x0a,
64
0x0f, 0x0a, 0x0f, 0x0a,
65
0x0f, 0x0b, 0x0f, 0x0a,
66
0x0f, 0x0b, 0x0f, 0x0e,
67
0x0f, 0x0f, 0x0f, 0x0e,
68
0x0f, 0x0f, 0x0f, 0x0f};
69
70
#include "XShade.h"
71
72
Pixmap XShade[XShadeMax];
73
GC TileGC;
74
unsigned int INIT = 1;
75
76
/*
77
* This routine has the function of returning the number of characters needed
78
* to store a bitmap. It first calculates the number of bits needed per line.
79
* Then it finds the closest multiple of 8 which is bigger than the number of
80
* bits. Once that is done, it multiplies this number by the number of bits
81
* high the bitmap is.
82
*/
83
int
84
char_bitmap(void)
85
{
86
int bits_line;
87
int total_chars;
88
89
for (bits_line = 8, total_chars = 1; bits_line < XShadeWidth; total_chars++)
90
bits_line += 8;
91
92
total_chars = total_chars * XShadeWidth;
93
94
return total_chars;
95
}
96
97
int
98
XInitShades(Display *display, int screen)
99
{
100
char *bits;
101
int count;
102
int chars_bitmap = char_bitmap();
103
int bit;
104
105
bits = (char *) malloc(chars_bitmap * sizeof(char));
106
107
for (count = 0; count < XShadeMax; count++) {
108
109
/* Load in the next bitmap */
110
111
for (bit = 0; bit < chars_bitmap; bit++)
112
bits[bit] = XShadeBits[count * chars_bitmap + bit];
113
114
/* Create it and put it into the Pixmap array */
115
116
XShade[count] = XCreatePixmapFromBitmapData(display,
117
RootWindow(display, screen),
118
bits,
119
XShadeWidth, XShadeWidth,
120
BlackPixel(display, screen),
121
WhitePixel(display, screen),
122
DisplayPlanes(display, screen));
123
}
124
TileGC = XCreateGC(display, RootWindow(display, screen), 0, NULL);
125
XSetFillStyle(display, TileGC, FillTiled);
126
XSetTile(display, TileGC, XShade[XShadeMax / 2]);
127
return XShadeMax;
128
}
129
130
131
int
132
XChangeShade(Display *display, int shade)
133
{
134
if (shade >= XShadeMax || shade < 0) {
135
fprintf(stderr, "Shade %d, out of range\n",shade);
136
return (-1);
137
}
138
XSetTile(display, TileGC, XShade[shade]);
139
return (1);
140
}
141
142
int
143
XQueryShades(unsigned int *shades)
144
{
145
*shades = XShadeMax;
146
return 1;
147
}
148
149
150
void
151
XShadeRectangle(Display *display, Drawable drawable, int x,int y,
152
unsigned int width, unsigned int height)
153
{
154
if (!INIT) {
155
fprintf(stderr, "XShade Error: Tried to fill before INIT called\n");
156
exit(-1);
157
}
158
XFillRectangle(display, drawable, TileGC, x, y, width, height);
159
}
160
161
162
void
163
XShadeRectangles(Display *display, Drawable drawable,
164
XRectangle *rectangles, int nrectangles)
165
{
166
if (!INIT) {
167
fprintf(stderr, "XShade Error: Tried to fill before INIT called\n");
168
exit(-1);
169
}
170
XFillRectangles(display, drawable, TileGC,
171
rectangles, nrectangles);
172
}
173
174
175
void
176
XShadePolygon(Display *display, Drawable drawable, XPoint * points,
177
int npoints, int shape, int mode)
178
{
179
if (!INIT) {
180
fprintf(stderr, "XShade Error: Tried to fill before INIT called\n");
181
exit(-1);
182
}
183
184
XFillPolygon(display, drawable, TileGC,
185
points, npoints, shape, mode);
186
}
187
188
void
189
XShadeArc(Display *display, Drawable drawable, int x, int y,
190
unsigned int width, unsigned int height, int angle1, int angle2)
191
{
192
if (!INIT) {
193
fprintf(stderr, "XShade Error: Tried to fill before INIT called\n");
194
exit(-1);
195
}
196
XFillArc(display, drawable, TileGC, x, y, width,
197
height, angle1, angle2);
198
}
199
200
201
void
202
XShadeArcs(Display *display, Drawable drawable, XArc *arcs, int narcs)
203
{
204
if (!INIT) {
205
fprintf(stderr, "XShade Error: Tried to fill before INIT called\n");
206
exit(-1);
207
}
208
XFillArcs(display, drawable, TileGC, arcs, narcs);
209
}
210
211
212
213