-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphic.c
407 lines (322 loc) · 8.84 KB
/
graphic.c
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/* General and 2D graphics routines
*
* Copyright 1996-2008 pinc Software. All Rights Reserved.
* Licensed under the terms of the GNU General Public License, version 3.
*/
#include "types.h"
#include "funcs.h"
#include "classes.h"
//#include "lib/safeclip/sasc-68k/safeclip.h"
#define AREABUFFERS 300
struct MinList colors;
struct RastPort *grp, *doublerp, *irp;
static struct Layer_Info *gli;
static struct TmpRas sTempRaster;
static struct AreaInfo sAreaInfo;
static PLANEPTR sTempBitmap = NULL;
static APTR *sAreaBuffer = NULL;
#ifdef __amigaos4__
#define PI 3.14159265
#define DEGREE_STEPS PI/128
double
gcalcllength(double vx, double vy)
{
return sqrt(vx*vx + vy*vy);
}
void
gAreaArcMove(struct RastPort *rp, long x, long y, long xradius, long yradius, double degree)
{
gAreaDraw(rp, (long)(x + sin(degree) * xradius + 0.5), (long)(y + cos(degree) * yradius + 0.5));
}
void
gAreaArc(struct RastPort *rp, long x, long y, long xradius, long yradius, double degree)
{
gAreaDraw(rp, (long)(x + sin(degree) * xradius + 0.5), (long)(y + cos(degree) * yradius + 0.5));
}
void
DrawArc(struct RastPort *rp, long x, long y, long xradius, long yradius, double start, double end)
{
double degree;
start = start * PI / 180.0;
end = end * PI / 180.0;
gAreaMove(rp, x, y);
for (degree = start; degree < end; degree += DEGREE_STEPS) {
gAreaArc(rp, x, y, xradius, yradius, degree);
}
if (degree > end)
gAreaArc(rp, x, y, xradius, yradius, end);
gAreaEnd(rp);
}
void
drawSide(struct RastPort *rp, long x, long y, long xradius, long yradius, long height, double start, double end)
{
double degree;
start = start * PI / 180.0;
end = end * PI / 180.0;
gAreaArcMove(rp, x, y + height, xradius, yradius, start);
gAreaArc(rp, x, y, xradius, yradius, start);
for (degree = start; degree < end; degree += DEGREE_STEPS)
gAreaArc(rp, x, y, xradius, yradius, degree);
if (degree > end)
gAreaArc(rp, x, y, xradius, yradius, end);
gAreaArc(rp, x, y + height, xradius, yradius, end);
for (degree = end; degree > start; degree -= DEGREE_STEPS)
gAreaArc(rp, x, y + height, xradius, yradius, degree);
gAreaEnd(rp);
}
#endif
void
gInitArea(long xmin, long ymin, long xmax, long ymax)
{
SafeSetLimits(xmin, ymin, xmax, ymax);
}
void PUBLIC
libAreaMove(REG(a0, struct RastPort *rp), REG(d0, LONG x), REG(d1, LONG y))
{
gAreaMove(rp, x, y);
}
void PUBLIC
libAreaDraw(REG(a0, struct RastPort *rp), REG(d0, LONG x), REG(d1, LONG y))
{
gAreaDraw(rp, x, y);
}
void PUBLIC
libAreaEnd(REG(a0, struct RastPort *rp))
{
gAreaEnd(rp);
}
ULONG PUBLIC
GetDPI(REG(a0, struct Page *page))
{
return page->pg_DPI;
}
LONG PUBLIC
GetOffset(REG(a0, struct Page *page), REG(d0, BOOL horiz))
{
return horiz ? page->pg_wTabX - page->pg_TabX : page->pg_wTabY - page->pg_TabY;
}
void
RectFill32(struct RastPort *rp, long x1, long y1, long x2, long y2)
{
x1 = max(x1, 0); y1 = max(y1, 0);
x2 = min(x2, 32567); y2 = min(y2, 32567);
RectFill(rp, x1, y1, x2, y2);
}
void
DrawHorizBlock(struct RastPort *rp, ULONG dpi, long x1, long y, long x2, ULONG points, UWORD flags)
{
long width;
width = (points * (dpi & 0xffff)) / (72*256);
if (x2 < x1)
RectFill(rp, x2, y - width, x1, y);
else
RectFill(rp, x1, y, x2, y + width);
}
void
DrawVertBlock(struct RastPort *rp, ULONG dpi, long x, long y1, long y2, ULONG points, UWORD flags)
{
long width;
width = (points * (dpi >> 16)) / (72*256);
if (y2 < y1)
RectFill(rp, x - width, y2, x, y1);
else
RectFill(rp, x, y1, x + width, y2);
}
void PUBLIC
DrawLine(REG(a0, struct RastPort *rp), REG(d0, ULONG dpi), REG(d1, long x1), REG(d2, long y1), REG(d3, long x2), REG(d4, long y2), REG(d5, ULONG points), REG(d6, UWORD flags))
{
double f,a,b,c,border;
long pen,xa,yb;
grp->Layer = rp->Layer; /* MERKER: das Zeugs könnte und sollte raus */
grp->BitMap = rp->BitMap;
pen = GetAPen(rp);
SetAPen(grp, pen);
SetOutlinePen(grp, pen); /* MERKER: Darf die das?? */
f = ((double)(dpi >> 16))/((double)(dpi & 0xffff));
a = (double)(y2 - y1)*f;
b = (double)(x2 - x1);
c = sqrt(a*a + b*b);
border = ((double)points*(dpi >> 16))/9437184.0; // (72.0*65536.0*2)
xa = (long)(border * a/c+0.5); yb = -(long)((border*b/c)+0.5)/f;
if (xa || yb) {
gAreaMove(grp, x1 + xa, y1 + yb);
gAreaDraw(grp, x2 + xa, y2 + yb);
gAreaDraw(grp, x2 - xa, y2 - yb);
gAreaDraw(grp, x1 - xa, y1 - yb);
gAreaEnd(grp);
} else {
Move(rp, x1, y1);
Draw(rp, x2, y2);
}
grp->Flags &= ~AREAOUTLINE;
}
void
FreeTmpRas(void)
{
if (sTempBitmap)
FreeVec(sTempBitmap);
}
void
MakeTmpRas(long width, long height)
{
long bytes = ((width + 15) >> 3)*height;
FreeTmpRas();
#ifdef __amigaos4__
if ((sTempBitmap = AllocVecTags(bytes, AVT_Type, MEMF_PRIVATE, AVT_ClearWithValue, 0, TAG_DONE)) != 0)
// if ((sTempBitmap = AllocVecTags(bytes, AVT_Type, MEMF_SHARED, AVT_ClearWithValue, 0, TAG_DONE)) != 0)
#else
if ((sTempBitmap = AllocVec(bytes, MEMF_CHIP | MEMF_CLEAR)) != 0)
#endif
{
InitTmpRas(&sTempRaster, sTempBitmap, bytes);
grp->TmpRas = &sTempRaster;
}
gInitArea(0, 0, width - 1, height - 1);
}
void
FreeDoubleBufferBitMap(void)
{
if (doublerp) {
DeleteLayer(0, doublerp->Layer);
FreeBitMap(doublerp->BitMap);
doublerp->BitMap = NULL;
}
}
void
AllocDoubleBufferBitMap(struct Screen *scr)
{
if (doublerp) {
if ((doublerp->BitMap = AllocBitMap(scr->Width, scr->Height, GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH), BMF_MINPLANES, scr->RastPort.BitMap)) != 0)
doublerp->Layer = CreateUpfrontLayer(gli,doublerp->BitMap,0,0,scr->Width-1,scr->Height-1,LAYERSIMPLE,NULL);
else
FreeDoubleBuffer();
}
}
void
FreeDoubleBuffer(void)
{
if (!doublerp)
return;
if (doublerp->BitMap)
FreeDoubleBufferBitMap();
DisposeLayerInfo(gli);
FreePooled(pool, doublerp, sizeof(struct RastPort));
doublerp = NULL;
}
void
InitDoubleBuffer(void)
{
if ((doublerp = AllocPooled(pool, sizeof(struct RastPort))) != 0)
{
gli = NewLayerInfo();
InitRastPort(doublerp);
}
}
void
FreeGraphics(void)
{
FreeGClasses();
if (sAreaBuffer)
FreePooled(pool, sAreaBuffer, AREABUFFERS * 5);
SafeClose(); /* safe area-functions by Peter Knight */
FreeTmpRas();
if (grp)
FreePooled(pool, grp, sizeof(struct RastPort));
FreeDoubleBuffer();
if (irp)
FreePooled(pool, irp, sizeof(struct RastPort));
}
void
InitGraphics(void)
{
struct colorPen *cp;
long i;
char t[16];
InitGClasses();
if (IsListEmpty((struct List *)&colors)) {
AddColor(&colors, NULL, 170, 170, 170); // grey
AddColor(&colors, NULL, 0, 0, 0); // black
AddColor(&colors, NULL, 255, 255, 255); // white
AddColor(&colors, NULL, 101, 138, 186); // blue
AddColor(&colors, NULL, 85, 223, 85); // green
AddColor(&colors, NULL, 239, 69, 69); // red
AddColor(&colors, NULL, 255, 239, 69); // yellow
AddColor(&colors, NULL, 97, 97, 97); // dark grey
}
//Standardfarben für ignition GUI setzen
#ifdef __amigaos4__
struct Screen *scr;
if ((scr = LockPubScreen("Workbench")) != 0) {
GetRGB32(scr->ViewPort.ColorMap,0,8,(ULONG *)&standardPalette[1]);
UnlockPubScreen(NULL, scr);
}
#endif
MyNewList(&scrcolors);
for (i = 0; i < 8; i++) {
if ((cp = AllocPooled(pool, sizeof(struct colorPen))) != 0) {
sprintf(t, GetString(&gLocaleInfo, MSG_COLOR), i + 1);
cp->cp_Node.ln_Name = AllocString(t);
cp->cp_Pen = i;
cp->cp_Red = standardPalette[i * 3 + 1] >> 24;
cp->cp_Green = standardPalette[i * 3 + 2] >> 24;
cp->cp_Blue = standardPalette[i * 3 + 3] >> 24;
MyAddTail(&scrcolors, cp);
}
}
if ((grp = AllocPooled(pool, sizeof(struct RastPort))) != 0) {
InitRastPort(grp);
if ((sAreaBuffer = AllocPooled(pool, AREABUFFERS * 5)))
InitArea(grp->AreaInfo = &sAreaInfo, sAreaBuffer, AREABUFFERS);
SafeInit(AREABUFFERS * 5);
MakeTmpRas(800, 600);
}
if ((irp = AllocPooled(pool, sizeof(struct RastPort))) != 0)
InitRastPort(irp);
}
#define JSR 0x4ef9
const APTR gClassFuncTable[] = {
/* 0 */ SetOutlineColor,
/* 1 */ SetLowColor,
/* 2 */ gGetLink,
/* 3 */ gSuperDraw,
/* 4 */ TintColor,
/* 5 */ gInsertRemoveCellsTerm,
/* 6 */ gInsertRemoveCellsTablePos,
/* 7 */ CalcTerm,
/* 8 */ CopyTerm,
/* 9 */ DeleteTerm,
/* 10 */ CreateTerm,
/* 11 */ mm,
/* 12 */ pixel,
/* 13 */ OutlineHeight,
/* 14 */ OutlineLength,
/* 15 */ DrawText,
/* 16 */ NewFontInfoA,
/* 17 */ CopyFontInfo,
/* 18 */ SetFontInfoA,
/* 19 */ FreeFontInfo,
/* 20 */ GetOffset,
/* 21 */ GetDPI,
/* 22 */ libAreaEnd,
/* 23 */ libAreaDraw,
/* 24 */ libAreaMove,
/* 25 */ DrawLine,
/* 26 */ DrawRect,
/* 27 */ FindColorPen,
/* 28 */ SetColors,
/* 29 */ SetHighColor,
/* 30 */ gDoSuperMethodA,
/* 31 */ gDoMethodA,
/* 32 */ FreeString,
/* 33 */ AllocString,
/* 34 */ AllocStringLength,
#ifdef __amigaos4__
/* 35 */ gAreaArcMove,
/* 36 */ gAreaArc,
/* 37 */ DrawArc,
/* 38 */ drawSide,
/* 39 */ gcalcllength,
#endif
NULL
};
int32 gClassFuncTableSize = sizeof(gClassFuncTable);