# dont perform the libgen and libsocket test in configure for AROS.
[AROS-Contrib.git] / fish / surf / gadgetuse.c
blob0943717a7ef0b5677db121d0cc8891d3a305346f
1 /* this file contains definition for the screen */
3 #include <aros/oldprograms.h>
4 #include "scrnio.ih"
5 #include <exec/memory.h>
6 #ifdef MANX
7 #include <functions.h>
8 #endif
9 #include <stdio.h>
10 #include <string.h>
12 #include "scrndef.h"
13 #include "gadgetdef.h"
14 #include "mytypes.h"
15 #include "poly.h"
16 #include "readilbm.h"
18 #define GetExtens(gei) ((struct GadExtens *)gei->UserData)
19 extern struct GfxBase * GfxBase;
21 void SetPolyDraw();
22 void SetBezMesh( int );
23 void OutErr(char *);
24 void CloseDisplay();
26 void GadgetSetVal(gad)
27 struct Gadget *gad;
29 struct GadExtens *vp;
30 struct PropInfo *prop;
31 long gadval;
33 if( !(gad->GadgetType & PROPGADGET) ) {
34 return;
37 if( !gad->GadgetRender ) {
38 gad->GadgetRender = (APTR) malloc(sizeof(struct Image));
39 if( !gad->GadgetRender ) {
40 OutErr("Not enough memory for gadgets");
41 CloseDisplay();
42 exit( 0 );
45 if( !gad->SpecialInfo ) {
46 static struct PropInfo dummyprop = {
47 FREEHORIZ|AUTOKNOB,
48 0x8000, 1, /* HorizPot = initial value */
49 0xff, 0, /* not really of interest */
50 0,0,0,0,0,0
53 gad->SpecialInfo = (APTR) malloc(sizeof(struct PropInfo));
54 if( !gad->SpecialInfo ) {
55 OutErr("Not enough memory for gadgets");
56 CloseDisplay();
57 exit( 0 );
59 *(struct PropInfo *)gad->SpecialInfo = dummyprop;
62 vp = GetExtens( gad );
63 if(!vp) {
64 return;
66 prop = (struct PropInfo *) gad->SpecialInfo;
68 if( vp->isfloat ) {
69 gadval = (long)( (long)MAXPOT *
70 ( vp->curfval - vp->minfval )/(vp->maxfval - vp->minfval));
71 prop->HorizBody = MAXPOT /( 15 * 8 );
73 else {
74 gadval = ( (long)MAXPOT *
75 ( (long) vp->curival - vp->minival))/(vp->maxival - vp->minival);
76 prop->HorizBody = MAXPOT /( vp->maxival - vp->minival );
79 prop->HorizPot = gadval;
84 void GadgetUpdate(gad, exists)
85 struct Gadget *gad;
86 bool exists; /* has the gadget already been displayed? */
88 struct GadExtens *vp;
89 long potvalue;
90 char dbuff[25];
91 char *tx, *dx;
92 struct IntuiText *it;
94 if(!( gad->GadgetType & PROPGADGET) ) {
95 return;
98 vp = GetExtens( gad );
99 if(!vp) return;
101 potvalue = ((struct PropInfo *) gad->SpecialInfo)->HorizPot;
103 if( vp->isfloat ) {
104 float temp;
105 temp = ( potvalue * (vp->maxfval - vp->minfval ))/ MAXPOT
106 + vp->minfval;
107 vp->curfval = temp;
108 #if !MANX
109 sprintf(dbuff,"%f ", temp);
110 #else
111 ftoa(temp, dbuff, sizeof(dbuff)-4, 1);
112 #endif /* !MANX */
114 else {
115 long temp;
116 temp = (long)( potvalue * (vp->maxival - vp->minival ))/ MAXPOT
117 + vp->minival;
118 vp->curival = temp;
119 sprintf(dbuff,"%-12d", (int)temp);
122 * find '['
124 it = gad->GadgetText;
125 for( tx = (char *)it->IText; *tx && *tx != '['; tx++ ) {
128 if( !*tx ) {
129 return; /* something screwy */
131 tx++; /* skip past opening bracket */
132 dx = dbuff;
133 while( *tx != ']' ) {
134 *tx++ = *dx++;
137 if(exists){
138 long tempx, tempy;
139 tempx = it->LeftEdge + gad->LeftEdge;
140 tempy = it->TopEdge + gad->TopEdge + 6; /*fudge factor for baseline*/
141 Move( CntrlWin->RPort, tempx, tempy );
142 SetAPen(CntrlWin->RPort,it->FrontPen );
143 Text( CntrlWin->RPort, it->IText, strlen(it->IText ));
147 void SetHourGlass() {
148 SetPointer( SurfWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
149 SetPointer( GadWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
150 SetPointer( CntrlWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
153 void ClearHourGlass() {
154 ClearPointer(SurfWin);
155 ClearPointer(GadWin);
156 ClearPointer(CntrlWin);
159 void GadgetHandler(gadaddr)
160 struct Gadget *gadaddr;
162 short curival = 0;
163 float curfval = 0.0;
165 if( gadaddr->UserData ) {
166 GadgetUpdate( gadaddr, true );
167 curival = ((struct GadExtens *) gadaddr->UserData)->curival;
168 curfval = ((struct GadExtens *) gadaddr->UserData)->curfval;
171 switch( (enum GadgetName) gadaddr->GadgetID ) {
172 case N_PtLocX:
173 LightSrc.x = (float)curival;
174 break;
175 case N_PtLocY:
176 LightSrc.y = (float)curival;
177 break;
178 case N_BackPlane:
179 BackColor = curival;
180 break;
181 case N_PtLocZ:
182 LightSrc.z = (float)curival;
183 break;
184 case N_BkIntens:
185 Ambience = curfval;
186 break;
187 case N_PtIntens:
188 PtIntensity = curfval;
189 break;
190 case N_Kdiffuse:
191 Kd = curfval;
192 break;
193 case N_Kspec:
194 Ks = curfval;
195 break;
196 case N_Map:
197 /* ResetCurve(); */
198 SetHourGlass();
199 RevMap();
200 ClearHourGlass();
201 break;
202 case N_Wire:
203 SetHourGlass();
204 RevNoShade();
205 ClearHourGlass();
206 break;
207 case N_Shaded:
208 SetHourGlass();
209 RevShade();
210 ClearHourGlass();
211 break;
212 case N_EditBez:
213 SetFitBez();
214 break;
215 case N_DefLines:
216 SetPolyDraw();
217 break;
218 case N_RevAngle:
219 SetRotRange( curival );
220 break;
221 case N_RevStart:
222 SetRotStart( curival );
223 break;
224 case N_TiltAng:
225 SetSecAng( curival );
226 break;
227 case N_RevSlices:
228 SetRevMesh( curival );
229 break;
230 case N_BezSlices:
231 SetBezMesh( curival );
232 break;
233 case N_SurfDist:
234 SetSurfDist( curival);
235 break;
236 case N_RepV:
237 MapRepV = curival;
238 PrepImgPix();
239 break;
240 case N_RepH:
241 MapRepH = curival;
242 PrepImgPix();
243 break;
244 case N_GoSurf:
245 ScreenToFront( SurfScrn );
246 break;
247 case N_GoPanel:
248 WBenchToFront();
249 WindowToFront( CntrlWin );
250 break;
251 default:
252 break;