1 /* Part of XPCE --- The SWI-Prolog GUI toolkit
2
3 Author: Jan Wielemaker and Anjo Anjewierden
4 E-mail: jan@swi.psy.uva.nl
5 WWW: http://www.swi.psy.uva.nl/projects/xpce/
6 Copyright (c) 1985-2002, University of Amsterdam
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 1. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <h/kernel.h>
36 #include <h/graphics.h>
37
38 static status
initialiseCircle(Circle c,Int w)39 initialiseCircle(Circle c, Int w)
40 { initialiseGraphical(c, ZERO, ZERO, w, w);
41 assign(c, fill_pattern, NIL);
42
43 succeed;
44 }
45
46
47 static status
RedrawAreaCircle(Circle c,Area a)48 RedrawAreaCircle(Circle c, Area a)
49 { int x, y, w, h;
50
51 initialiseDeviceGraphical(c, &x, &y, &w, &h);
52 NormaliseArea(x, y, w, h);
53 r_thickness(valInt(c->pen));
54 r_dash(c->texture);
55 r_ellipse(x, y, w, h, c->fill_pattern);
56
57 return RedrawAreaGraphical(c, a);
58 }
59
60
61 static status
radiusCircle(Circle c,Int r)62 radiusCircle(Circle c, Int r)
63 { Int d = mul(r, TWO);
64
65 return setGraphical(c, DEFAULT, DEFAULT, d, d);
66 }
67
68
69 static Int
getRadiusCircle(Circle c)70 getRadiusCircle(Circle c)
71 { answer(div(c->area->w,TWO));
72 }
73
74
75 static status
rotateCircle(Circle c)76 rotateCircle(Circle c)
77 { succeed;
78 }
79
80
81 static status
diameterCircle(Circle c,Int n)82 diameterCircle(Circle c, Int n)
83 { return setGraphical(c, DEFAULT, DEFAULT, n, n);
84 }
85
86
87 static Int
getDiameterCircle(Circle c)88 getDiameterCircle(Circle c)
89 { answer(c->area->w);
90 }
91
92
93 static status
geometryCircle(Circle c,Int x,Int y,Int w,Int h)94 geometryCircle(Circle c, Int x, Int y, Int w, Int h)
95 { Int d;
96
97 if ( isDefault(w) )
98 d = (isDefault(h) ? (Int) DEFAULT : h);
99 else
100 d = (isDefault(h) ? w : valInt(w) < valInt(h) ? w : h);
101
102 return geometryGraphical(c, x, y, d, d);
103 }
104
105
106 /*******************************
107 * CLASS DECLARATION *
108 *******************************/
109
110 /* Type declarations */
111
112 static char *T_geometry[] =
113 { "x=[int]", "y=[int]", "width=[int]", "height=[int]" };
114
115 /* Instance Variables */
116
117 static vardecl var_circle[] =
118 { SV(NAME_fillPattern, "image|colour*", IV_GET|IV_STORE, fillPatternGraphical,
119 NAME_appearance, "Fill pattern for internals")
120 };
121
122 /* Send Methods */
123
124 static senddecl send_circle[] =
125 { SM(NAME_initialise, 1, "diameter=[int]", initialiseCircle,
126 DEFAULT, "Create circle from diameter"),
127 SM(NAME_diameter, 1, "int", diameterCircle,
128 NAME_area, "Set diameter"),
129 SM(NAME_geometry, 4, T_geometry, geometryCircle,
130 NAME_area, "Force width and height to be equal"),
131 SM(NAME_radius, 1, "int", radiusCircle,
132 NAME_area, "Set radius (= half diameter)"),
133 SM(NAME_DrawPostScript, 1, "{head,body}", drawPostScriptCircle,
134 NAME_postscript, "Create PostScript"),
135 SM(NAME_rotate, 1, "int", rotateCircle,
136 NAME_rotate, "Rotate (does nothing)")
137 };
138
139 /* Get Methods */
140
141 static getdecl get_circle[] =
142 { GM(NAME_diameter, 0, "int", NULL, getDiameterCircle,
143 NAME_area, "Diameter (= twice radius)"),
144 GM(NAME_radius, 0, "int", NULL, getRadiusCircle,
145 NAME_area, "Radius (= half diameter")
146 };
147
148 /* Resources */
149
150 static classvardecl rc_circle[] =
151 { RC(NAME_selectionHandles, "name", "sides",
152 "Visual feedback of <->selected")
153 };
154
155 /* Class Declaration */
156
157 static Name circle_termnames[] = { NAME_diameter };
158
159 ClassDecl(circle_decls,
160 var_circle, send_circle, get_circle, rc_circle,
161 1, circle_termnames,
162 "$Rev$");
163
164
165 status
makeClassCircle(Class class)166 makeClassCircle(Class class)
167 { declareClass(class, &circle_decls);
168
169 cloneStyleVariableClass(class, NAME_fillPattern, NAME_reference);
170 setRedrawFunctionClass(class, RedrawAreaCircle);
171
172 succeed;
173 }
174
175