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 XDitherWidth 3
49
#define XDitherMax 10
50
51
char XDitherBits[] = {
52
0x00, 0x00, 0x00,
53
0x00, 0x02, 0x00,
54
0x00, 0x03, 0x00,
55
0x00, 0x03, 0x02,
56
0x00, 0x07, 0x02,
57
0x04, 0x07, 0x02,
58
0x04, 0x07, 0x03,
59
0x05, 0x07, 0x03,
60
0x05, 0x07, 0x07,
61
0x07, 0x07, 0x07 };
62
63
#include "XDither.h"
64
65
Pixmap XDither[XDitherMax];
66
unsigned int DITHERINIT = 0;
67
68
69
70
/*
71
* This routine has the function of returning the number of characters needed
72
* to store a bitmap. It first calculates the number of bits needed per line.
73
* Then it finds the closest multiple of 8 which is bigger than the number of
74
* bits. Once that is done, it multiplies this number by the number of bits
75
* high the bitmap is.
76
*/
77
int
78
dither_char_bitmap(void)
79
{
80
int bits_line;
81
int total_chars;
82
83
for (bits_line = 8, total_chars = 1; bits_line < XDitherWidth; total_chars++)
84
bits_line += 8;
85
86
total_chars = total_chars * XDitherWidth;
87
88
return total_chars;
89
}
90
91
int
92
XInitDither(Display *display, int screen, GC gc, unsigned long fg,
93
unsigned long bg)
94
{
95
96
char *bits;
97
int count;
98
int chars_bitmap = dither_char_bitmap();
99
int bit;
100
XGCValues xgcv;
101
102
DITHERINIT = 1;
103
104
/*
105
* First thing I should do is load in the Pixmaps
106
*/
107
bits = (char *) malloc(chars_bitmap * sizeof(char));
108
109
for (count = 0; count < XDitherMax; count++) {
110
111
/*
112
* Load in the next bitmap
113
*/
114
for (bit = 0; bit < chars_bitmap; bit++)
115
bits[bit] = XDitherBits[count * chars_bitmap + bit];
116
117
/*
118
* Create it and put it into the Pixmap array
119
*/
120
XDither[count] = XCreatePixmapFromBitmapData(display,
121
RootWindow(display, screen),
122
bits,
123
XDitherWidth, XDitherWidth,
124
BlackPixel(display, screen),
125
WhitePixel(display, screen),
126
1);
127
}
128
129
/*
130
* Now reset the gc values to be as I need them
131
*/
132
xgcv.background = bg;
133
xgcv.foreground = fg;
134
xgcv.fill_style = FillOpaqueStippled;
135
xgcv.stipple = XDither[4];
136
137
XChangeGC(display, gc,
138
GCForeground | GCBackground | GCFillStyle | GCStipple, &xgcv);
139
140
return (XDitherMax);
141
142
}
143
144
145
int
146
XChangeDither(Display *display, GC gc, int dither)
147
{
148
if (!DITHERINIT) {
149
fprintf(stderr, "XChange Error: Init Not Called\n");
150
exit(-1);
151
}
152
if (dither >= XDitherMax || dither < 0) {
153
fprintf(stderr, "Dither %d, out of range\n",dither);
154
return (-1);
155
}
156
XSetStipple(display, gc, XDither[dither]);
157
return (1);
158
}
159
160
161
void
162
XDitherRectangle(Display *display, Drawable drawable, GC gc, int x,
163
int y, unsigned int width, unsigned int height)
164
{
165
166
167
if (!DITHERINIT) {
168
fprintf(stderr, "XDither Error: Tried to fill before INIT called\n");
169
exit(-1);
170
}
171
XFillRectangle(display, drawable, gc, x, y, width, height);
172
173
}
174
175
176
void
177
XDitherRectangles(Display *display, Drawable drawable, GC gc,
178
XRectangle *rectangles, int nrectangles)
179
{
180
181
182
if (!DITHERINIT) {
183
fprintf(stderr, "XDither Error: Tried to fill before INIT called\n");
184
exit(-1);
185
}
186
XFillRectangles(display, drawable, gc,
187
rectangles, nrectangles);
188
189
}
190
191
192
void
193
XDitherPolygon(Display * display, Drawable drawable, GC gc,
194
XPoint *points, int npoints, int shape, int mode)
195
{
196
if (!DITHERINIT) {
197
fprintf(stderr, "XDither Error: Tried to fill before INIT called\n");
198
exit(-1);
199
}
200
201
XFillPolygon(display, drawable, gc,
202
points, npoints, shape, mode);
203
204
}
205
206
void
207
XDitherArc(Display *display, Drawable drawable, GC gc, int x,int y,
208
unsigned int width, unsigned int height, int angle1, int angle2)
209
{
210
211
if (!DITHERINIT) {
212
fprintf(stderr, "XDither Error: Tried to fill before INIT called\n");
213
exit(-1);
214
}
215
XFillArc(display, drawable, gc, x, y, width,
216
height, angle1, angle2);
217
}
218
219
220
void
221
XDitherArcs(Display *display,Drawable drawable, GC gc, XArc *arcs,int narcs)
222
{
223
224
if (!DITHERINIT) {
225
fprintf(stderr, "XDither Error: Tried to fill before INIT called\n");
226
exit(-1);
227
}
228
XFillArcs(display, drawable, gc, arcs, narcs);
229
}
230
231