AbacusP.h 11.5 KB
Newer Older
1 2 3
/*
 * @(#)AbacusP.h
 *
4
 * Copyright 1994 - 2014  David A. Bagley, bagleyd@tux.org
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Abacus demo and neat pointers from
 * Copyright 1991 - 1998  Luis Fernandes, elf@ee.ryerson.ca
 *
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of the author not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.
 *
 * This program 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.
 */
23 24 25 26 27

/* Private header file for Abacus */

#ifndef _AbacusP_h
#define _AbacusP_h
28 29
#include "xwin.h"
#include "timer.h"
30 31
#include "Abacus.h"

32 33 34 35 36 37 38 39 40 41 42 43 44 45
#ifdef HAVE_LONG_LONG
#define LONG long long
#ifndef LONG_LONG_MAX
#define LONG_LONG_MAX 9223372036854775807LL
#endif
#define MAX_INT LONG_LONG_MAX
#else
#define LONG long
#ifndef LONG_MAX
#define LONG_MAX 2147483647L
#endif
#define MAX_INT LONG_MAX
#endif

46
#ifdef WINVER
47
#ifndef DEMOPATH
48 49
#ifdef UNIXDELIM
#define DEMOPATH "c:/WINDOWS"
50
#else
51
#define DEMOPATH "c:\\WINDOWS"
52 53 54
#endif
#endif

55 56 57 58 59 60
extern void destroyAbacus(AbacusWidget w, HBRUSH brush);
extern void resizeAbacus(AbacusWidget w);
extern void initializeAbacus(AbacusWidget w, HBRUSH brush);
extern void exposeAbacus(AbacusWidget w);
extern void hideAbacus(AbacusWidget w);
extern void selectAbacus(AbacusWidget w, const int x, const int y);
61
extern void releaseAbacus(AbacusWidget w, const int x, const int y);
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
extern void clearAbacus(AbacusWidget w);
extern void complementAbacus(AbacusWidget w);
extern void incrementAbacus(AbacusWidget w);
extern void decrementAbacus(AbacusWidget w);
extern void changeFormatAbacus(AbacusWidget w);
extern void changeMuseumAbacus(AbacusWidget w);
extern void toggleRomanNumeralsAbacus(AbacusWidget w);
extern void toggleGroupingAbacus(AbacusWidget w);
extern void toggleNegativeSignAbacus(AbacusWidget w);
extern void toggleQuartersAbacus(AbacusWidget w);
extern void toggleQuarterPercentsAbacus(AbacusWidget w);
extern void toggleTwelfthsAbacus(AbacusWidget w);
extern void toggleSubdecksAbacus(AbacusWidget w);
extern void toggleEighthsAbacus(AbacusWidget w);
extern void toggleAnomalyAbacus(AbacusWidget w);
extern void toggleWatchAbacus(AbacusWidget w);
extern void speedUpAbacus(AbacusWidget w);
extern void slowDownAbacus(AbacusWidget w);
extern void toggleSoundAbacus(AbacusWidget w);
extern void toggleRightToLeftAddAbacus(AbacusWidget w);
extern void toggleRightToLeftMultAbacus(AbacusWidget w);
extern void enterAbacus(AbacusWidget w);
extern void leaveAbacus(AbacusWidget w);
85 86
extern void moveAbacusInput(AbacusWidget w,
        int x, int y, char letter, int control);
87 88 89 90 91 92 93 94 95 96 97 98
extern Boolean checkSubdeck(AbacusWidget w, int position);
extern void setAbacusString(AbacusWidget w, int reason, char *string);

extern void initializeAbacusDemo(AbacusWidget w);
extern void exposeAbacusDemo(AbacusWidget w);
extern void clearAbacusDemo(AbacusWidget w);
extern void toggleDemoAbacusDemo(AbacusWidget w);
extern void showNextAbacusDemo(AbacusWidget w);
extern void showRepeatAbacusDemo(AbacusWidget w);
extern void showJumpAbacusDemo(AbacusWidget w);
extern void showMoreAbacusDemo(AbacusWidget w);
extern void showChapterAbacusDemo(AbacusWidget w, int chapt);
99 100

#else
101
extern Pixel darker(AbacusWidget w, Pixel pixel);
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

#ifdef VMS
#ifndef DEMOPATH
#define DEMOPATH "[.]"
#endif
#else
#ifndef DEMOPATH
#if 0
#define DEMOPATH "/usr/share/games/xabacus"
#endif
#define DEMOPATH "/usr/local/share/games/xabacus"
#endif
#endif

typedef struct _AbacusClassPart {
	int         ignore;
} AbacusClassPart;

typedef struct _AbacusClassRec {
121 122
	CoreClassPart coreClass;
	AbacusClassPart abacusClass;
123 124 125
} AbacusClassRec;

extern AbacusClassRec abacusClassRec;
126
#endif
127

128 129 130 131 132
#ifndef BUMPSOUND
#define BUMPSOUND "bump"
#endif
#ifndef MOVESOUND
#define MOVESOUND "move"
133
#endif
134 135 136
#ifndef DRIPSOUND
#define DRIPSOUND "drip"
#endif
137

138 139
#define MAX_DECKS 2
#define PLACE_SETTING 2
140 141 142 143
#define UP 1
#define DOWN 0
#define TOP 1
#define BOTTOM 0
144
#define CARRY 1
145
#define SPECIAL_PIECES 2 /* Pieces, PiecePercents */
146

147 148
#define MAX_FORMAT_LENGTH 9
#define CHAPTERS 5
149 150 151 152

#define LINES 4
#define CHARS 64

153 154 155 156
#define MAX_SLICES 10
#define COUNTRY_SIZE 3
#define STRING_SIZE 81
#define MAX_SHADES 12
157

158 159 160 161 162
#define NORMAL 1
#define DOUBLE 2
#define INSTANT 3

#define NEWPOS(dir,x) ((((dir)==UP)?-1:1)*(x))
163 164 165 166 167 168 169 170 171 172 173
#define VDRAWLINE(w,dr,c,x1,y1,x2,y2) if (w->abacus.vertical) \
	{DRAWLINE(w,dr,c,y1,x1,y2,x2);} else {DRAWLINE(w,dr,c,x1,y1,x2,y2);}
#define VDRAWRECTANGLE(w,dr,c,i,j,l,h) if (w->abacus.vertical) \
	{DRAWRECTANGLE(w,dr,c,j,i,h,l);} else {DRAWRECTANGLE(w,dr,c,i,j,l,h);}
#define VFILLRECTANGLE(w,dr,c,i,j,l,h) if (w->abacus.vertical) \
	{FILLRECTANGLE(w,dr,c,j,i,h,l);} else {FILLRECTANGLE(w,dr,c,i,j,l,h);}
#define VDRAWCIRCLE(w,dr,c,d,x,y) if (w->abacus.vertical) \
	{DRAWCIRCLE(w,dr,c,d,y,x);} else {DRAWCIRCLE(w,dr,c,d,x,y);}
#define VFILLCIRCLE(w,dr,c,d,x,y) if (w->abacus.vertical) \
	{FILLCIRCLE(w,dr,c,d,y,x);} else {FILLCIRCLE(w,dr,c,d,x,y);}
#define VPOLYGON(w,dr,c,cl,l,n,b1,b2) if (w->abacus.vertical) \
174
	{int i,t; for (i=0;i<=n;i++) {t=l[i].x; l[i].x=l[i].y; l[i].y=t;} \
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
	POLYGON(w,dr,c,cl,l,n,b1,b2);} else {POLYGON(w,dr,c,cl,l,n,b1,b2);}
#define vfillRectClip(w,dr,c,dx,dy,sx,sy,o,wo,ws) if (w->abacus.vertical) \
	{fillRectClipX(w,dr,c,dy,dx,sy,sx,o,wo,ws);} else \
	{fillRectClipY(w,dr,c,dx,dy,sx,sy,o,wo,ws);}

typedef struct _MuseumPart {
	char        museum[MAX_MUSEUMS];	/* 2 char country code of museum */
	Boolean     separateSlots;
} MuseumPart;

typedef struct _SubdeckPart {
	int         number;
	int         factor;
	int         position;
	int         spaces;	/* spaces between beads */
	int         room;	/* spaces + number */
	Position    height;
} SubdeckPart;
193

194
typedef struct _DeckPart {
195 196 197 198
	int         number;
	Boolean     orientation;
	int         factor;
	int        *position;
199
	int         spaces;	/* spaces between beads */
200
	int         room;	/* spaces + number */
201
	Position    height;
202
	int         piece, piecePercent;
203
} DeckPart;
204 205

typedef struct _AbacusPart {
206 207
	DeckPart    decks[MAX_DECKS];
	SubdeckPart *subdecks;
208 209
	int         currentDeck, currentRail, currentPosition;
	int         rails;	/* number of columns of beads */
210 211
	int         decimalPosition, numDigits;
	int         base, displayBase;	/* 10 usually */
212
	int         subdeck, subbead, subbase;
213 214
	int         shiftPercent, shiftAnomaly, shiftAnomalySq;
	int         groupSize, anomaly, anomalySq;
215 216 217
	int         delay, numSlices, mode, submode, colorScheme, railIndex;
	int         leftAuxRails, rightAuxRails;
	int         aux, deck, rail, number;
218
	Position    middleBarHeight, middleBarPositionY, railWidth;
219
	Point       frameSize, beadSize;
220
	Point       pos, totalSize, delta, offset, pressOffset;
221 222 223 224 225
	Boolean     sign, minusSign, romanNumerals, group, decimalComma;
	Boolean     carryAnomaly, carryAnomalySq;
	Boolean     mono, reverse, focus, vertical;
	Boolean     script, demo, teach, lee;
	Boolean     latin, modernRoman, ancientRoman;
226
	Boolean     versionOnly;
227 228 229
	Boolean     slot, diamond, sound;
	char       *digits, *mathBuffer;
	FILE       *fp;
230
	GC          frameGC, borderGC, symbolGC, lineGC, railGC[4], inverseGC;
231
	GC          beadShadeGC[MAX_SHADES];
232
	Pixmap      bufferBead[4][2][2];
233
	TimeVal     oldTime;
234
	Boolean     rightToLeftAdd, rightToLeftMult;
235 236 237
	int         step, carry[2], lower, upper, carryStep;
	int         state; /* explain or carrying out operation */
	int         reg, regCount, qDigit, qPosition, auxCount, primarySteps;
238 239 240 241
	double      divisor;
	char        op;
	int        *intGroup;
	struct _AbacusPart *leftAux, *rightAux;
242
#ifdef WINVER
243
	char        format[STRING_SIZE], museum[COUNTRY_SIZE];
244
	char        bumpSound[STRING_SIZE], moveSound[STRING_SIZE], dripSound[STRING_SIZE];
245 246 247 248
	char        aString[STRING_SIZE], bString[STRING_SIZE];
	char        cString[STRING_SIZE], rString[STRING_SIZE];
	char        sString[STRING_SIZE];
	char        helperBuffer[STRING_SIZE];
249
#else
250
	char       *format, *museum, *bumpSound, *moveSound, *dripSound;
251 252 253
	char       *aString, *bString, *cString, *rString, *sString;
	char       *teachBuffer;
	int         menu, pixmapSize;
254 255
	Colormap    colormap;
	Pixel       foreground, background;
256
	Pixel       borderColor, frameColor;
257
	Pixel       beadColor[4], railColor[4];
258
	Pixel       leftAuxColor, rightAuxColor;
259
	XtCallbackList select;
260
#endif
261 262
} AbacusPart;

263
typedef struct _AbacusDemoPart {
264 265
	int         chapterCount;
	int         lessons[CHAPTERS], lessonLength, lessonCount;
266
	int         aux, deck, rail, number, lines;
267 268
	int         fontHeight;
	FILE       *fp;
269
	Boolean     chapter, query, started, framed;
270 271
	GC          foregroundGC;
#ifdef WINVER
272
	char        path[STRING_SIZE];
273 274 275 276 277
#else
	GC          inverseGC;
	char       *path, *font;
	XFontStruct *fontInfo;
	Pixel       background, foreground;
278
	XtCallbackList select;
279
#endif
280 281
} AbacusDemoPart;

282 283 284
typedef struct _AbacusRec {
	CorePart    core;
	AbacusPart  abacus;
285
	AbacusDemoPart abacusDemo;
286 287
} AbacusRec;

288 289 290
extern void setAbacus(AbacusWidget w, int reason);
extern void setAbacusDemo(AbacusWidget w, int reason);
extern void setAbacusMove(AbacusWidget w, int reason, int aux,
291
	int deck, int rail, int number);
292
extern void setAbacusText(AbacusWidget w, int reason, char * text, int line);
293 294
extern int char2Int(char character);
extern char int2Char(int digit);
295 296
extern char *strAddChar(char *buf, char c);
extern char *strAddInt(char *buf, int value);
297

298
extern void dividePieces(char * buf, int base, int pieces,
299 300 301
	int mult, int places, char decimalPoint);
extern void shiftDecimal(char *buf, char *aBuf, int shift, int place,
	char decimalPoint);
302
extern void addStrings(char *finalBuf, char *buf, char *pieceBuf,
303
	int base, char decimalPoint);
304 305 306
extern void subStrings(char *finalBuf, char *buf, char *pieceBuf,
	int base);
extern void convertString(char * buf, char * inbuf,
307
	int base, int displayBase, int decimalPosition,
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
	int anomaly, int shiftAnomaly, Boolean carryAnomaly,
	int anomalySq, int shiftAnomalySq, Boolean carryAnomalySq,
	char decimalPoint);

extern int sizeofRoman(int base, Boolean romanNumerals, Boolean ancientRoman);
extern int string2Roman(char *buf, char *inbuf, int base,
	int pieces, int number, int subnumber, int subbase,
	char decimalPoint, Boolean ancientRoman, Boolean latin);
extern void string2Group(char *buf, char *inbuf, int groupSize,
	char decimalPoint, char groupSeparator);
extern void calculate(AbacusWidget w, char *buffer, int aux);
extern void teachStep(AbacusWidget w, char *buffer, int aux);
extern LONG multPower(int m, int x, int n);
extern Boolean checkPiece(AbacusWidget w);
extern Boolean checkPiecePercent(AbacusWidget w);
extern Boolean checkSubdeck(AbacusWidget w, int position);
324
extern void drawBeadRail(AbacusWidget w, int rail, Boolean highlight);
325 326
extern int convertBaseToBottom(int base);
extern int rootInt(int i, int n);
327

328 329 330 331 332 333 334 335 336 337
extern void clearRails(AbacusWidget w);
extern void addBackAnomaly(char * buf, int anomaly, int shift, int base);
extern void zeroFractionalPart(char * buf);
extern void convertStringToAbacus(AbacusWidget w, char *string, int aux);
extern double convertToDecimal(int base, char *inputString);
extern void convertFromInteger(char *outputString, int base, int x);
extern void convertFromDouble(char *outputString, int base, double x);
#ifdef WINVER
extern void drawDemoText(const char* line, int i);
extern void drawTeachText(const char* line, int i);
338 339
#else
extern void clearAuxRails(AbacusWidget w, int aux);
340
#endif
341 342

#endif /* _AbacusP_h */