summaryrefslogtreecommitdiff
path: root/amiga/plotters.c
blob: b4c82d15c8b1de5ac5d3cb080e9b0315c0f26267 (plain)
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
/*
 * Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "amiga/plotters.h"
#include "amiga/gui.h"
#include "amiga/bitmap.h"
#include "amiga/font.h"
#include <proto/Picasso96API.h>
#include <proto/graphics.h>
#include <intuition/intuition.h>
#include <graphics/rpattr.h>

#include <proto/exec.h> // for debugprintf only

static clipx,clipy;

struct plotter_table plot;
const struct plotter_table amiplot = {
	ami_clg,
	ami_rectangle,
	ami_line,
	ami_polygon,
	ami_fill,
	ami_clip,
	ami_text,
	ami_disc,
	ami_arc,
	ami_bitmap,
	ami_bitmap_tile,
	NULL, //ami_group_start,
	NULL, //ami_group_end,
	ami_flush, // optional
	ami_path
};

bool ami_clg(colour c)
{
	DebugPrintF("clg %lx\n",c);

	p96RectFill(currp,0,0,clipx,clipy,
				p96EncodeColor(RGBFB_A8B8G8R8,c));

	return true;
}

bool ami_rectangle(int x0, int y0, int width, int height,
			int line_width, colour c, bool dotted, bool dashed)
{
	SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),
					TAG_DONE);
	Move(currp,x0,y0);
	Draw(currp,x0+width,y0);
	Draw(currp,x0+width,y0+height);
	Draw(currp,x0,y0+height);
	Draw(currp,x0,y0);

	return true;
}

bool ami_line(int x0, int y0, int x1, int y1, int width,
			colour c, bool dotted, bool dashed)
{
	DebugPrintF("line\n");
	SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),
					TAG_DONE);
	Move(currp,x0,y0);
	Draw(currp,x1,y1); // NB: does not support width,dotted,dashed
/*There is the line pattern in the rastport, would that help? There are macros in graphics/gfxmacros.h that do it. */

	return true;
}

bool ami_polygon(int *p, unsigned int n, colour fill)
{
	DebugPrintF("poly\n");
	return true;
}

bool ami_fill(int x0, int y0, int x1, int y1, colour c)
{
	DebugPrintF("fill\n");
	p96RectFill(currp,x0,y0,x1,y1,
		p96EncodeColor(RGBFB_A8B8G8R8,c));
	return true;
}

bool ami_clip(int x0, int y0, int x1, int y1)
{
	clipx=x1;
	clipy=y1;

	return true;
}

bool ami_text(int x, int y, const struct css_style *style,
			const char *text, size_t length, colour bg, colour c)
{
/* copied from css/css.h - need to open the correct font here
	* font properties *
	css_font_family font_family;
	struct {
	css_font_size_type size;
	union {
	struct css_length length;
	float absolute;
	float percent;
	} value;
	} font_size;
	css_font_style font_style;
	css_font_variant font_variant;
	css_font_weight font_weight;
*/
	ami_open_font(style);

	SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),
					RPTAG_BPenColor,p96EncodeColor(RGBFB_A8B8G8R8,bg),
//					RPTAG_Font,tfont,
					TAG_DONE);
	Move(currp,x,y);
	Text(currp,text,length);
	return true;
}

bool ami_disc(int x, int y, int radius, colour c, bool filled)
{
	DebugPrintF("disc\n");
	SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),
					TAG_DONE);
	DrawEllipse(currp,x,y,radius,radius); // NB: does not support fill, need to use AreaCircle for that
	return true;
}

bool ami_arc(int x, int y, int radius, int angle1, int angle2,
	    		colour c)
{
/* http://www.crbond.com/primitives.htm
CommonFuncsPPC.lha */
	DebugPrintF("arc\n");
	return true;
}

bool ami_bitmap(int x, int y, int width, int height,
			struct bitmap *bitmap, colour bg)
{
	struct RenderInfo ri;

DebugPrintF("bitmap plotter\n");

//	ami_fill(x,y,x+width,y+height,bg);

	ri.Memory = bitmap->pixdata;
	ri.BytesPerRow = bitmap->width * 4;
	ri.RGBFormat = RGBFB_R8G8B8A8;

	p96WritePixelArray((struct RenderInfo *)&ri,0,0,currp,x,y,width,height);

	return true;
}

bool ami_bitmap_tile(int x, int y, int width, int height,
			struct bitmap *bitmap, colour bg,
			bool repeat_x, bool repeat_y)
{
	struct RenderInfo ri;

DebugPrintF("bitmap tile plotter\n");
/* not implemented properly - needs to tile! */

	ri.Memory = bitmap->pixdata;
	ri.BytesPerRow = bitmap->width * 4;
	ri.RGBFormat = RGBFB_R8G8B8A8;

	p96WritePixelArray((struct RenderInfo *)&ri,0,0,currp,x,y,width,height);

	return true;
}

bool ami_group_start(const char *name)
{
	/** optional */
	return false;
}

bool ami_group_end(void)
{
	/** optional */
	return false;
}

bool ami_flush(void)
{
	DebugPrintF("flush\n");
	return true;
}

bool ami_path(float *p, unsigned int n, colour fill, float width,
			colour c, float *transform)
{
	DebugPrintF("path\n");
	return true;
}