/*************************************************************************/
/*				FedUP					 */
/* 		    Font Editor for User Programs			 */
/* 		 Compile with lc -Lt -cist -b0 FedUP                     */
/*************************************************************************/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <graphics/gfx.h>
#include <graphics/gfxmacros.h>
#include <graphics/gfxbase.h>
#include <stdio.h>

int CXBRK(void) {return(0);}

struct NewScreen FedUpScreen = {
	0,0,				/* Top left corner */
	320,STDSCREENHEIGHT,		/* Width,height */
	3,				/* Depth */
	7,1,				/* Default pens */
	NULL,				/* No special mode */
	CUSTOMSCREEN,
	NULL,				/* Usual font */
	"FedUP",			/* The title */
	NULL,				/* No gadgets yet */
	NULL				/* No custom bitmap */
};

struct NewWindow FedUpWindow = {
	0,12,
	320,200,			/* Max width */
	7,1,				/* White and red, please */
	CLOSEWINDOW | MOUSEBUTTONS | GADGETUP | MENUPICK | INTUITICKS,
	WINDOWCLOSE | SMART_REFRESH | ACTIVATE |
	NOCAREREFRESH | REPORTMOUSE,
	NULL,				/* Init gadget pointer later */
	NULL,				/* No checkmark ? */
	"FedUP v1.0",			/* Initial title */
	NULL,				/* Space for screen */
	NULL,				/* No bitmap */
	319,199,
	320,200,
	CUSTOMSCREEN
};

/* Gadget ID numbers */

#define	BLUESLIDER 	1
#define	GREENSLIDER	2
#define	REDSLIDER	3
#define	OKBUTTON	4
#define	FILEGADGET	5
#define	FILEOK		6
#define	FILECANCEL	7

/* RGB Slider variables */

struct PropInfo BlueInfo = {
	AUTOKNOB | FREEHORIZ,
	0x1111,0xFFFF,
	0x1111,0xFFFF
};
struct PropInfo GreenInfo = {
	AUTOKNOB | FREEHORIZ,
	0x1111,0xFFFF,
	0x1111,0xFFFF
};
struct PropInfo RedInfo = {
	AUTOKNOB | FREEHORIZ,
	0x1111,0xFFFF,
	0x1111,0xFFFF
};
struct Image PropImageBlue;
struct Image PropImageGreen;
struct Image PropImageRed;
struct IntuiText RedText = {1,0,JAM2,-10,1,NULL,"R",NULL};
struct IntuiText GreenText = {1,0,JAM2,-10,1,NULL,"G",NULL};
struct IntuiText BlueText = {1,0,JAM2,-10,1,NULL,"B",NULL};
struct Gadget BlueSlider = {
	NULL,
	252,185,
	60,8,
	GADGHCOMP,
	RELVERIFY,
	PROPGADGET,
	(APTR)&PropImageBlue,
	NULL,
	&BlueText,
	NULL,
	(APTR)&BlueInfo,
	BLUESLIDER,
	NULL
};
struct Gadget GreenSlider = {
	&BlueSlider,
	252,170,
	60,8,
	GADGHCOMP,
	RELVERIFY,
	PROPGADGET,
	(APTR)&PropImageGreen,
	NULL,
	&GreenText,
	NULL,
	(APTR)&GreenInfo,
	BLUESLIDER,
	NULL
};
struct Gadget RedSlider = {
	&GreenSlider,
	252,155,
	60,8,
	GADGHCOMP,
	RELVERIFY,
	PROPGADGET,
	(APTR)&PropImageRed,
	NULL,
	&RedText,
	NULL,
	(APTR)&RedInfo,
	BLUESLIDER,
	NULL
};


	
/* String gadget stuff */

UBYTE FileBuffer[128];
UBYTE UndoBuffer[128];
struct StringInfo FileInfo = {
	FileBuffer,
	UndoBuffer,
	0,
	128,
	0,
	0,
	0,
	0,
	0,0,
	NULL,
	NULL,
	NULL
};
struct Image FileImage;
struct IntuiText FileText = {0,7,JAM2,40,8,NULL,"Enter file name:",NULL};
struct IntuiText FileOkText = {0,7,JAM2,2,2,NULL,"OK",NULL};
struct IntuiText FileCancelText = {0,7,JAM2,2,2,NULL,"Cancel",NULL};
struct Gadget FileGadget = {
	NULL,
	40,30,
	120,12,
	GADGHCOMP|SELECTED,
	NULL,
	STRGADGET|REQGADGET,
	(APTR)&FileImage,
	NULL,
	NULL,
	NULL,
	(APTR)&FileInfo,
	FILEGADGET,
	NULL
};
SHORT FileOkXY[] = {0,0, 20,0, 20,10, 0,10, 0,0};
SHORT FileCancelXY[] = {0,0, 50,0, 50,10, 0,10, 0,0};
SHORT FileBorderXY[] = {0,0, 195,0, 195,75, 0,75, 0,0};
struct Border FileOkBorder = {
	0,0,
	1,7,JAM1,
	5,
	FileOkXY,
	NULL
};
struct Border FileCancelBorder = {
	0,0,
	1,7,JAM1,
	5,
	FileCancelXY,
	NULL
};
struct Border FileBorder = {
	2,2,
	0,7,JAM1,
	5,
	FileBorderXY,
	NULL
};
struct Gadget FileOK = {
	&FileGadget,
	10,65,
	20,12,
	GADGHCOMP,
	RELVERIFY|ENDGADGET,
	BOOLGADGET|REQGADGET,
	(APTR)&FileOkBorder,
	NULL,
	&FileOkText,
	NULL,
	NULL,
	FILEOK,
	NULL
};
struct Gadget FileCancel = {
	&FileOK,
	140,65,
	50,12,
	GADGHCOMP,
	RELVERIFY|ENDGADGET,
	BOOLGADGET|REQGADGET,
	(APTR)&FileCancelBorder,
	NULL,
	&FileCancelText,
	NULL,
	NULL,
	FILECANCEL,
	NULL
};
struct Requester FileRequest = {
	NULL,
	20,20,
	200,80,
	0,0,
	&FileCancel,
	&FileBorder,
	&FileText,
	NULL,
	4,
	NULL,
	{NULL},
	NULL,
	NULL,
	{NULL}
};

/* Now the menus */	

#define	IWIDTH		96
#define	IHEIGHT		10
struct IntuiText ProjectText[] = {
	{7,1,JAM2,1,1,NULL,"Open...",NULL},
	{7,1,JAM2,1,1,NULL,"Save As...",NULL},
	{7,1,JAM2,1,1,NULL,"Save",NULL},
	{7,1,JAM2,1,1,NULL,"New Font",NULL},
	{7,1,JAM2,1,1,NULL,"About...",NULL},
	{7,1,JAM2,1,1,NULL,"Quit",NULL}
};
struct IntuiText FontText[] = {
	{7,1,JAM2,CHECKWIDTH,1,NULL,"Default colours",NULL},
	{7,1,JAM2,CHECKWIDTH,1,NULL,"Make Module    ",NULL},
	{7,1,JAM2,CHECKWIDTH,1,NULL,"Clear Grid     ",NULL},
	{7,1,JAM2,1,1,NULL,"» Copy",NULL},
	{7,1,JAM2,CHECKWIDTH,1,NULL,"Refine Grid    ",NULL},
	{7,1,JAM2,1,1,NULL,"» Pixel Size ",NULL},
	{7,1,JAM2,1,1,NULL,"» Reflect",NULL},
	{7,1,JAM2,1,1,NULL,"» Flood  ",NULL}
};
struct IntuiText CopyText[] = {
	{7,1,JAM2,1,1,NULL,"To  ",NULL},
	{7,1,JAM2,1,1,NULL,"From",NULL}
};
struct IntuiText PixelText[] = {
	{7,1,JAM2,CHECKWIDTH,1,NULL,"1",NULL},
	{7,1,JAM2,CHECKWIDTH,1,NULL,"2",NULL}
};
struct IntuiText ReflectText[] = {
	{7,1,JAM2,1,1,NULL,"X-axis",NULL},
	{7,1,JAM2,1,1,NULL,"Y-axis",NULL},
	{7,1,JAM2,1,1,NULL,"X = Y ",NULL}
};
struct IntuiText FloodText[] = {
	{7,1,JAM2,1,1,NULL,"All",NULL},
	{7,1,JAM2,1,1,NULL,"B-G",NULL}
};
struct MenuItem ProjectItem[] = {
	{
		&ProjectItem[1],
		0,0,
		IWIDTH,IHEIGHT,
		ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,
		0,
		(APTR)&ProjectText[0],
		NULL,
		'O',
		NULL,
		MENUNULL
	},
	{
		&ProjectItem[2],
		0,10,
		IWIDTH,IHEIGHT,
		ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,
		0,
		(APTR)&ProjectText[1],
		NULL,
		'A',
		NULL,
		MENUNULL
	},
	{
		&ProjectItem[3],
		0,20,
		IWIDTH,IHEIGHT,
		ITEMTEXT|HIGHCOMP|COMMSEQ,
	 	0,
		(APTR)&ProjectText[2],
		NULL,
		'S',
		NULL,
		MENUNULL
	}, 
	{
		&ProjectItem[4],
		0,30,
		IWIDTH,IHEIGHT,
		ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 	0,
		(APTR)&ProjectText[3],
		NULL,
		NULL,
		NULL,
		MENUNULL
	},
	{
		&ProjectItem[5],
		0,40,
		IWIDTH,IHEIGHT,
		ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 	0,
		(APTR)&ProjectText[4],
		NULL,
		NULL,
		NULL,
		MENUNULL
	},
	{
		NULL,
		0,50,
		IWIDTH,IHEIGHT,
		ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,
		 0,
		 (APTR)&ProjectText[5],
		 NULL,
		 'Q',
		 NULL,
		 MENUNULL
	} 
};
#undef IWIDTH
#define	IWIDTH	64
struct MenuItem PixelItem[] = {
	{&PixelItem[1],130,-1,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP
	 |CHECKIT|COMMSEQ,2,(APTR)&PixelText[0],NULL,'1',NULL,MENUNULL},
	{NULL,130,9,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP|CHECKIT
	 |CHECKED|COMMSEQ,1,(APTR)&PixelText[1],NULL,'2',NULL,MENUNULL}
};
#undef IWIDTH
#define	IWIDTH	54
struct MenuItem ReflectItem[] = {
	{&ReflectItem[1],130,-1,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&ReflectText[0],NULL,NULL,NULL,MENUNULL},
	{&ReflectItem[2],130,9,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	0,(APTR)&ReflectText[1],NULL,NULL,NULL,MENUNULL},
	{NULL,130,19,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&ReflectText[2],NULL,NULL,NULL,MENUNULL}
};
struct MenuItem CopyItem[] = {
	{&CopyItem[1],130,-1,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&CopyText[0],NULL,NULL,NULL,MENUNULL},
	{NULL,130,9,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&CopyText[1],NULL,NULL,NULL,MENUNULL}
};
struct MenuItem FloodItem[] = {
	{&FloodItem[1],130,-1,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FloodText[0],NULL,NULL,NULL,MENUNULL},
	{NULL,130,9,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FloodText[1],NULL,NULL,NULL,MENUNULL}
};
#undef IWIDTH
#define	IWIDTH	152
struct MenuItem FontItem[] = {
	{&FontItem[1],0,0,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FontText[0],NULL,NULL,NULL,MENUNULL},
	{&FontItem[2],0,10,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FontText[1],NULL,NULL,NULL,MENUNULL},
	{&FontItem[3],0,20,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP
	 |COMMSEQ,0,(APTR)&FontText[2],NULL,'G',NULL,MENUNULL},
	{&FontItem[4],0,30,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FontText[3],NULL,NULL,&CopyItem[0],MENUNULL},
	{&FontItem[5],0,40,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP
	 |CHECKIT|MENUTOGGLE,0,(APTR)&FontText[4],NULL,NULL,NULL,MENUNULL},
	{&FontItem[6],0,50,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FontText[5],NULL,NULL,&PixelItem[0],MENUNULL},
	{&FontItem[7],0,60,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FontText[6],NULL,NULL,&ReflectItem[0],MENUNULL},
	{NULL,0,70,IWIDTH,IHEIGHT,ITEMTEXT|ITEMENABLED|HIGHCOMP,
	 0,(APTR)&FontText[7],NULL,NULL,&FloodItem[0],MENUNULL}
};
struct Menu MyMenu[] = {
	{&MyMenu[1],0,0,64,0,MENUENABLED,"Project",&ProjectItem[0]},
	{NULL,70,0,120,0,MENUENABLED,"Font",&FontItem[0]}
};
struct IntuiText OKText = {0,7,JAM2,4,2,NULL,"OK",NULL};
SHORT ButtonXY[10] = { 0,0, 24,0, 24,10, 0,10, 0,0}; 
SHORT ReqXY[10] = {0,0, 237,0, 237,77, 0,77, 0,0};
struct Border OKBorder = {
	0,0,
	1,7,JAM1,
	5,
	ButtonXY,
	NULL
};
struct Border ReqBorder = {
	1,1,
	1,7,JAM1,
	5,
	ReqXY,
	NULL
};
struct Gadget OKButton = {
	NULL,
	10,64,
	24,10,
	GADGHCOMP,
	RELVERIFY | ENDGADGET,
	BOOLGADGET | REQGADGET,
	(APTR)&OKBorder,
	NULL,
	&OKText,
	NULL,
	NULL,
	OKBUTTON,
	NULL
};
struct IntuiText AboutText[] = {
	{0,7,JAM2,96,45,NULL,"J.Gold",NULL},
	{0,7,JAM2,112,35,NULL,"by",&AboutText[0]},
	{0,7,JAM2,4,25,NULL,"Font Editor for User Programs",&AboutText[1]},
	{0,7,JAM2,100,5,NULL,"FedUP",&AboutText[2]}
};
struct Requester AboutRequest = {
	NULL,
	40,35,
	240,80,
	0,0,
	&OKButton,
	&ReqBorder,
	&AboutText[3],
	NULL,
	7,
	NULL,
	{NULL},
	NULL,
	NULL,
	{NULL},
};
struct IntuiText HoldOn = {0,7,JAM2,72,30,NULL,"Please Wait!",NULL};
struct IntuiText Saving = {0,7,JAM2,44,50,NULL,"Saving font to disk",NULL};
struct IntuiText Loading = 
		       {0,7,JAM2,32,50,NULL,"Loading font from disk",NULL};
struct Requester PleaseWait = {
	NULL,
	40,35,
	240,80,
	0,0,
	NULL,
	&ReqBorder,
	&HoldOn,
	NULL,
	7,
	NULL,
	{NULL},
	NULL,
	NULL,
	{NULL},
};

struct IntuiText YesNo[] = {
		{7,1,JAM2,5,4,NULL,"Yes",NULL},
		{7,1,JAM2,6,4,NULL,"NO!",NULL},
		{7,1,JAM2,80,15,NULL,"Are You Sure?",NULL}
};


#define	RP		Window->RPort
#define	GRIDXMIN	25
#define	GRIDYMIN	30
#define	GRIDYMAX	GRIDYMIN+16*8
#define	GRIDXMAX	GRIDXMIN+16*8
#define	FONTXMIN	181
#define	FONTYMIN	31
#define	FONTXMAX	277
#define	FONTYMAX	127
#define	IMAGXMIN	181
#define	IMAGYMIN	142
#define	AUREVOIR	"QUIT"
#define	DFLTCOLS	"DEFAULT"
#define	CLRGRID		"CLEAR"
#define	NEWFONT		"WIPE"
#define	FLOOD		"FLOOD"
#define	ALL		1
#define	BG		0
#define	TO		0
#define	FROM		1
#define	FedUP		SetWindowTitles(Window,"FedUP v1.0",-1)

void DrawGrid(struct RastPort *,int,int);
void ShowColours(struct RastPort *);
void ShowCurrentColour(void);
void CleanExit(struct Screen *,struct Window *,int);
UBYTE HandleIDCMP(struct Window *);
void WhatBox(struct RastPort *,int,int);
USHORT CheckBox(int,int,int,int,int,int);
void CheckDrag(SHORT,SHORT);
void BoxAt(struct RastPort*,int,int);
void DrawFont(struct RastPort *);
void ChangeCurrentChar(struct RastPort *,int,int);
void FillGrid(struct RastPort *);
void HiLite(struct RastPort *);
void EditColours(void);
void InitProps(struct Gadget *,struct Gadget *,struct Gadget *);
void About(void);
BOOL AreYouSure(char *);
void OpenFile(void);
void SaveFileAs(void);
void SaveFile(char *);
char *GetFileName(struct Window *);
void SetDefaultColours(void);
void NoSuchFile(void);
void ClearGrid(void);
void ClearFont(void);
void MakeModule(void);
void CopyToChar(void);
void CopyChar(int);
void ReflectX(void);
void ReflectY(void);
void Transpose(void);
void CoarseGrid(void);
void ShowPixelSize(void);
void Flood(USHORT);

struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;
struct Screen *Screen = NULL;
struct Window *Window = NULL;

UWORD CurrColour = 1;			/* Current pen colour */
UBYTE CurrChar = 0;			/* Current character */
char *CurrFile = NULL;			/* Current file */
USHORT Drawing = 0;			/* Drawing flag */
USHORT Pix = 2;				/* Pixel size to plot */
USHORT Refined = 0;			/* Grid refinement flag */
UBYTE Undo[32][32];			/* Undo buffer and temp storage */
					/* (undo not implemented in v1.0)*/

char Alphabet[] = 
	" !`#$%&~()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ      ";

struct Letter {
	UBYTE Grid[32][32];		/* Grid data for character */
};

struct MyNewFont {
	UWORD FontColour[8]; 		/* Letter colours */
	struct Letter CharSet[59];	/* Letter definitions */
} MyFont;

UWORD ColourTable[8] = {
	0x000,0xf00,0x0f0,0x00f,
	0xff0,0xf0f,0x0ff,0xfff
};
main() {
	UBYTE ByeBye = 0;
	ULONG SignalMask,Signal;
	
	GfxBase = (struct GfxBase *)
			OpenLibrary("graphics.library",33L);
	if (!GfxBase) CleanExit(Screen,Window,RETURN_WARN);
	
	IntuitionBase = (struct IntuitionBase *)
			 OpenLibrary("intuition.library",33L);
	if (!IntuitionBase) CleanExit(Screen,Window,RETURN_WARN);
	
	/* Open a screen */
	Screen = (struct Screen *)OpenScreen(&FedUpScreen);
	if (!Screen) CleanExit(Screen,Window,RETURN_WARN);
	
	/* Attach the screen to the window */
	FedUpWindow.Screen = Screen;
	
	/* Open the window */
	Window = (struct Window *) OpenWindow(&FedUpWindow);
	if (!Window) CleanExit(Screen,Window,RETURN_WARN);
	
	/* Set new screen colours */
	SetDefaultColours();
	
	/* Make pointer boundary white */
	SetRGB4(&Screen->ViewPort,18,0xf,0xf,0xf);
	
	SignalMask = 1L << Window->UserPort->mp_SigBit;

	SetAPen(RP,7);
	DrawGrid(RP,17,8);
	DrawFont(RP);
	HiLite(RP);
	ShowPixelSize();
	AddGList(Window,&RedSlider,0,3,NULL);
	RefreshGadgets(&RedSlider,Window,NULL);
	InitProps(&RedSlider,&GreenSlider,&BlueSlider);
	SetMenuStrip(Window,&MyMenu[0]);
	while (!ByeBye) {
		Signal = Wait(SignalMask);
		if (Signal & SignalMask)
			ByeBye = HandleIDCMP(Window);
	}
	CleanExit(Screen,Window,RETURN_OK);
}

UBYTE HandleIDCMP(struct Window *win) {
	UBYTE flag = 0;
	struct IntuiMessage *Message = NULL;
	ULONG Class,MenuNum,ItemNum,SubNum;
	USHORT Code,selection;
	SHORT MouseX,MouseY;

	while(Message = (struct IntuiMessage *)GetMsg(win->UserPort)) {
		Class = Message->Class;
		Code = Message->Code;
		MouseX = Message->MouseX;
		MouseY = Message->MouseY;
		ReplyMsg((struct Message *)Message);
		switch (Class) {
			case INTUITICKS :
				CheckDrag(MouseX,MouseY);
				break;
			case CLOSEWINDOW : 
				if (AreYouSure(AUREVOIR)) flag = 1;
				break;
			case MOUSEBUTTONS:
				switch (Code) {
					case SELECTDOWN :
						WhatBox(RP,MouseX,MouseY);
						break;
					case SELECTUP :
						Drawing = 0;
						break;
					default: break;
				}
				break;
			case GADGETUP :
				selection = 
				       ((struct Gadget *)Message->IAddress)->GadgetID; 
				switch(selection) {
					case REDSLIDER:
					case GREENSLIDER:
					case BLUESLIDER:  EditColours();
						          break;
					default:          break;
				}
				break;	
			case MENUPICK :
				selection = Code;
				while( selection != MENUNULL ) {
 				  MenuNum = MENUNUM(selection);
				  ItemNum = ITEMNUM(selection);
				  SubNum = SUBNUM(selection);
				  switch (MenuNum) {
				    case 0:		/* Project */
				     switch(ItemNum) {
				       case 0: OpenFile();
				       	       break;
				       case 1: SaveFileAs();
				       	       break;
				       case 2: SaveFile(CurrFile);
				       	       break;
				       case 3: if (AreYouSure(NEWFONT))
				       			ClearFont();
					       break;
				       case 4: About();
				               break;
				       case 5: if (AreYouSure(AUREVOIR))
				       			flag = 1;
				               break;
				       default: break;
				     }
				     break;
				     case 1:
				      switch(ItemNum) {
					case 0: if (AreYouSure(DFLTCOLS))
						       SetDefaultColours();
						break;
					case 1: MakeModule();
						break;
					case 2: if (AreYouSure(CLRGRID))
					 		ClearGrid();
						break;
					case 3:	CopyChar((int)SubNum);
						break;
					case 4: if (!Refined){
							SetAPen(RP,7);
							DrawGrid(RP,33,4);
							Refined = 1;
						}
						else{
							CoarseGrid();
							Refined = 0;
						}
						break;
					case 5: Pix = (SubNum) ? 2 : 1;
						ShowPixelSize();
						break;
					case 6:	switch(SubNum) {
						  case 0: ReflectX();
						  	  break;
					          case 1: ReflectY();
						          break;
						  case 2: Transpose();
						  	  break;
					          default: break;
						}
						break;
					case 7:	if (SubNum) 
							Flood(BG);
						else
							Flood(ALL);
						break;
					default: break;
				      }
				     default:break;
				  }
				  selection = ((struct MenuItem *)
				  ItemAddress(&MyMenu[0],(LONG)selection))->NextSelect;
				}
				break;				
				default: break;
		}
	}
	return(flag);
}

/* Exit, closing everything we opened */
void CleanExit(struct Screen *scr,struct Window *win,int RetVal) {
	if (win->MenuStrip) ClearMenuStrip(win);
	if (win) CloseWindow(win);
	if (scr) CloseScreen(scr);
	if (IntuitionBase) CloseLibrary(IntuitionBase);
	if (GfxBase) CloseLibrary(GfxBase);
	exit(RetVal);
} 

/* Draw the grid with n lines, box size = size */		
void DrawGrid(struct RastPort *RastPort,int n,int size) {
	register int i;
	
	for(i = 0 ; i < n ; i++) {
		Move(RastPort,GRIDXMIN,GRIDYMIN+size*i);
		Draw(RastPort,GRIDXMAX,GRIDYMIN+size*i);
	}
	for(i = 0 ; i < n ; i++) {
		Move(RastPort,GRIDXMIN+size*i,GRIDYMIN);
		Draw(RastPort,GRIDXMIN+size*i,GRIDYMAX);
	}
	ShowColours(RastPort);
}

/* Show user the palette, Ami! */
void ShowColours(struct RastPort *RastPort) {
	int i;
	
	SetOPen(RastPort,0);
	for(i = 0 ; i < 8 ; i++){
		SetAPen(RastPort,i);
		RectFill(RastPort,GRIDXMIN+16*i,GRIDYMAX+20,
					GRIDXMIN+16*i+16,GRIDYMAX+36);
	}
	BNDRYOFF(RastPort);
	ShowCurrentColour();
}

/* Plot a box of the required size at the mouse */		
void BoxAt(struct RastPort *RastPort,int x,int y) {
	int gx,gy;
	int WndwX,WndwY;
	int BoxX1,BoxY1,BoxX2,BoxY2;
	if (Pix == 1) {
		gx = (x - GRIDXMIN) / 4;
		gy = (y - GRIDYMIN) / 4;
		MyFont.CharSet[CurrChar].Grid[gx][gy] = CurrColour;
		SetAPen(RastPort,CurrColour);
		WndwX = 4 * gx + GRIDXMIN;
		WndwY = 4 * gy + GRIDYMIN;
		BoxX1 = (gx % 2) ? WndwX   : WndwX+1;
		BoxX2 = (gx % 2) ? WndwX+3 : WndwX+4;
		BoxY1 = (gy % 2) ? WndwY   : WndwY+1;
		BoxY2 = (gy % 2) ? WndwY+3 : WndwY+4;
		RectFill(RastPort,BoxX1,BoxY1,BoxX2,BoxY2);
		WritePixel(RastPort,gx+IMAGXMIN,gy+IMAGYMIN);
		MyFont.CharSet[CurrChar].Grid[gx][gy] = CurrColour;
	}
	else {
		gx = (x - GRIDXMIN) / 8;
		gy = (y - GRIDYMIN) / 8;
		SetAPen(RastPort,CurrColour);
		WndwX = 8 * gx + GRIDXMIN;
		WndwY = 8 * gy + GRIDYMIN;
		RectFill(RastPort,WndwX+1,WndwY+1,WndwX+7,WndwY+7);
		RectFill(RastPort,2*gx+IMAGXMIN,2*gy+IMAGYMIN,
					2*gx+IMAGXMIN+1,2*gy+IMAGYMIN+1);
		MyFont.CharSet[CurrChar].Grid[2*gx][2*gy] = CurrColour;
		MyFont.CharSet[CurrChar].Grid[2*gx+1][2*gy] = CurrColour;
		MyFont.CharSet[CurrChar].Grid[2*gx][2*gy+1] = CurrColour;
		MyFont.CharSet[CurrChar].Grid[2*gx+1][2*gy+1] = CurrColour;
	}
}
			
/* If user clicks left mouse button,find out what he/she wants */		
void WhatBox(struct RastPort *RastPort,int x,int y) {
	if (CheckBox(x,y,GRIDXMIN,GRIDXMAX,GRIDYMIN,GRIDYMAX)){
		Drawing = 1;
		BoxAt(RastPort,x,y);
	}
	if (CheckBox(x,y,GRIDXMIN,GRIDXMAX,GRIDYMAX+20,GRIDYMAX+36)) {
		SetAPen(RP,0);
		Move(RP,GRIDXMIN+16*CurrColour,GRIDYMAX+20);
		Draw(RP,GRIDXMIN+16*CurrColour+16,GRIDYMAX+20);
		Draw(RP,GRIDXMIN+16*CurrColour+16,GRIDYMAX+36);
		Draw(RP,GRIDXMIN+16*CurrColour,GRIDYMAX+36);
		Draw(RP,GRIDXMIN+16*CurrColour,GRIDYMAX+20);
		CurrColour = (x - GRIDXMIN) / 16;
		ShowCurrentColour();
		InitProps(&RedSlider,&GreenSlider,&BlueSlider);
	}
	if (CheckBox(x,y,FONTXMIN,FONTXMAX,FONTYMIN,FONTYMAX))
		ChangeCurrentChar(RastPort,x,y);
}

/* Checks (x,y) is inside the required rectangle */
USHORT CheckBox(int x,int y,int xmin,int xmax,int ymin,int ymax) {
	if ((x>xmin) && (x<xmax) && (y>ymin) && (y<ymax))
		return(1);
	else
		return(0);
}

/* Allows the user to paint rather than 'click click' all the time */ 
void CheckDrag(SHORT x,SHORT y) {
	if (CheckBox(x,y,GRIDXMIN,GRIDXMAX,GRIDYMIN,GRIDYMAX) && (Drawing))
		BoxAt(RP,x,y);
}

/* Draw the table of letters */
void DrawFont(struct RastPort *RastPort) {
	int i,j;
	char cchar = 0;
	int LetterX,LetterY;
	
	SetAPen(RastPort,7);
	for(i = 0 ; i < 8 ; i++) {
		for(j = 0 ; j < 8 ; j++) {
			LetterX = FONTXMIN + 1 + i*12;
			LetterY = FONTYMIN + 1 + j*12+RastPort->TxBaseline;
			Move(RastPort,LetterX,LetterY);
			Text(RastPort,&Alphabet[cchar++],1);
		}
	}
	Move(RastPort,FONTXMIN-1,FONTYMIN-1);
	Draw(RastPort,FONTXMIN+97,FONTYMIN-1);
	Draw(RastPort,FONTXMIN+97,FONTYMIN+97);
	Draw(RastPort,FONTXMIN-1,FONTYMIN+97);
	Draw(RastPort,FONTXMIN-1,FONTYMIN-1);
}

/* Draw a box around the current hue and make the pointer that colour */
void ShowCurrentColour(){
	UWORD rgb,Red,Green,Blue;
	
	rgb = GetRGB4(Screen->ViewPort.ColorMap,CurrColour);
	Red = (rgb >> 8) & 15;
	Green = (rgb >> 4) & 15;
	Blue = rgb & 15;
	SetRGB4(&Screen->ViewPort,17,Red,Green,Blue);
	SetAPen(RP,7);
	Move(RP,GRIDXMIN+16*CurrColour,GRIDYMAX+20);
	Draw(RP,GRIDXMIN+16*CurrColour+16,GRIDYMAX+20);
	Draw(RP,GRIDXMIN+16*CurrColour+16,GRIDYMAX+36);
	Draw(RP,GRIDXMIN+16*CurrColour,GRIDYMAX+36);
	Draw(RP,GRIDXMIN+16*CurrColour,GRIDYMAX+20);
	SetAPen(RP,CurrColour);
}

/* Change the current character (!) */
void ChangeCurrentChar(struct RastPort *RastPort,int x,int y) {
	int k,i,j;
	const char *msg = "FedUP: Getting data for x";
	
	i = (x - FONTXMIN) / 12;
	j = (y - FONTYMIN) / 12;
	k = 8 * i + j;
	if (k < 59) {
		*(msg+24) = k+32;
		SetWindowTitles(Window,msg,-1);
		HiLite(RastPort);
		CurrChar = k;
		FillGrid(RastPort);
		HiLite(RastPort);
		FedUP;
	}
}

/* Current char in inverse video */
void HiLite(struct RastPort *RastPort) {
	int x,y;
	
	x = FONTXMIN + 12*(CurrChar / 8);
	y = FONTYMIN + 12*(CurrChar % 8);
	SetDrMd(RastPort,COMPLEMENT);
	SetAPen(RastPort,7);
	RectFill(RastPort,x,y,x+8,y+8);
	SetDrMd(RastPort,JAM2);
}

/* Stuff the relevant info into the grid on screen */
void FillGrid(struct RastPort *RastPort) {
	register int i,j;
	int Colour,WndwX,WndwY;
	int BoxX1,BoxX2,BoxY1,BoxY2;
	
	for(i = 0 ; i < 32 ; i++) {
		for(j = 0 ; j < 32 ; j++) {
			Colour = MyFont.CharSet[CurrChar].Grid[i][j];
			SetAPen(RastPort,Colour);
			WritePixel(RastPort,IMAGXMIN+i,IMAGYMIN+j);
			WndwX = 4 * i  + GRIDXMIN;
			WndwY = 4 * j  + GRIDYMIN;
			BoxX1 = (i % 2) ? WndwX   : WndwX+1;
			BoxX2 = (i % 2) ? WndwX+3 : WndwX+4;
			BoxY1 = (j % 2) ? WndwY   : WndwY+1;
			BoxY2 = (j % 2) ? WndwY+3 : WndwY+4;
			RectFill(RastPort,BoxX1,BoxY1,BoxX2,BoxY2);
		}
	}
}

/* User altered sliders, so find out what he/she's been up to */
void EditColours() {
	UWORD Red,Green,Blue;
	struct PropInfo *pr,*pg,*pb;
	
	pr = (struct PropInfo *)RedSlider.SpecialInfo;
	pg = (struct PropInfo *)GreenSlider.SpecialInfo;
	pb = (struct PropInfo *)BlueSlider.SpecialInfo;

	Blue = pb->HorizPot / 0x1111;
	Green = pg->HorizPot / 0x1111;
	Red = pr->HorizPot / 0x1111;
	SetRGB4(&Screen->ViewPort,CurrColour,Red,Green,Blue);
	MyFont.FontColour[CurrColour] = 
			GetRGB4(Screen->ViewPort.ColorMap,CurrColour);
}

/* Initialise sliders */
void InitProps(struct Gadget *r,struct Gadget *g,struct Gadget *b) {
	UWORD rgb,Red,Green,Blue;
	
	rgb = GetRGB4(Screen->ViewPort.ColorMap,CurrColour);
	Red = 0x1111 * ((rgb >> 8) & 15);
	Green = 0x1111 * ((rgb >> 4) & 15);
	Blue = 0x1111 * (rgb & 15);
	NewModifyProp(r,Window,NULL,AUTOKNOB|FREEHORIZ,
					Red,MAXBODY,0x1111,MAXBODY,1L);
	NewModifyProp(g,Window,NULL,AUTOKNOB|FREEHORIZ,
					Green,MAXBODY,0x1111,MAXBODY,1L);
	NewModifyProp(b,Window,NULL,AUTOKNOB|FREEHORIZ,
					Blue,MAXBODY,0x1111,MAXBODY,1L);
}

/* A bit of egotism! */
void About() {
	Request(&AboutRequest,Window);
}

/* Are you sure ? requester */
BOOL AreYouSure(char *QuitText) {
	BOOL flag;
	struct IntuiText ActionText;
	
	ActionText.IText = (UBYTE *)QuitText;
	ActionText.FrontPen = 7;
	ActionText.BackPen = 1;
	ActionText.LeftEdge = 10;
	ActionText.TopEdge = 15;
	ActionText.ITextFont = NULL;
	ActionText.DrawMode = JAM2;
	ActionText.NextText = &YesNo[2];
	
	flag = AutoRequest(Window,&ActionText,
			  &YesNo[0],&YesNo[1],NULL,NULL,210,80);
	return(flag);
}

/* Enter a valid file name or not as the case may be */
char *GetFileName(struct Window *win) {
	struct IntuiMessage *msg = NULL;
	struct Gadget *Gadget;
	ULONG sig,sigmask,class;
	USHORT code,done=0;
	USHORT gadgetID;
	
	OffMenu(win,NOITEM);
	Request(&FileRequest,win);
	sigmask = 1L << win->UserPort->mp_SigBit;
	while (!done) {
	  sig = Wait(sigmask);
	   if (sig & sigmask) {
	     while(msg = (struct IntuiMessage *)GetMsg(win->UserPort)) {
	        class = msg->Class;
		code = msg->Code;
		Gadget = (struct Gadget *)msg->IAddress;
		gadgetID = Gadget->GadgetID;
		ReplyMsg((struct Message *)msg);
		if (class == GADGETUP)  
			if ((gadgetID == FILEOK)||(gadgetID==FILECANCEL)){
				done = 1;
				break;	
				/* MUSTN'T process any more msg's */
			}
							 
	     }
	  }
	}
	OnMenu(win,NOITEM);
	if (gadgetID == FILEOK)
		return((char *)FileBuffer);
	else
		return(NULL);
}

/* Macro extracts the nth bit from w */

#define	BIT(n,w)	(((w) >> (n)) & 1)	

/* Obvious, the next few :-) */
void SaveFileAs() {
	char *FileName;
	
	SetWindowTitles(Window,"FedUP: Save As...",-1);
	FileName = GetFileName(Window);
	if (FileName) SaveFile(FileName);
	FedUP;
}

void SaveFile(char *FileName) {
	FILE *fp,*fopen();
	USHORT i,j,letter;
	int Colour;
	int plane1,plane2,plane3;
	
	SetWindowTitles(Window,"FedUP: Saving...",-1);
	if (!FileName) {
		NoSuchFile();
		FedUP;
		return;
	}
	if(!(fp = fopen(FileName,"w"))){
		NoSuchFile();
		FedUP;
		return;
	}
	HoldOn.NextText = &Saving;
	Request(&PleaseWait,Window);
	OffMenu(Window,NOITEM);
	/* First save the colour table */
	for(i = 0 ; i < 8 ; i++) 
		fprintf(fp,"%d\n",(int)MyFont.FontColour[i]);
	/* Now the letter table */
	for(letter = 0 ; letter < 59 ; letter++) {
	  for(i = 0 ; i < 32 ; i++) {
	    plane1 = plane2 = plane3 = 0;
	    for(j = 0 ; j < 16 ; j++) {
		Colour = MyFont.CharSet[letter].Grid[j][i];
		plane3 += (BIT(2,Colour)) << (15-j);
		plane2 += (BIT(1,Colour)) << (15-j);
		plane1 += (BIT(0,Colour)) << (15-j);
	     }
	     fprintf(fp,"%d %d %d\n",plane1,plane2,plane3);
	     plane1 = plane2 = plane3 = 0;
	     for(j = 16 ; j < 32 ; j++) {
		Colour = MyFont.CharSet[letter].Grid[j][i];
		plane3 += (BIT(2,Colour)) << (31-j);
		plane2 += (BIT(1,Colour)) << (31-j);
		plane1 += (BIT(0,Colour)) << (31-j);
	     }
	     fprintf(fp,"%d %d %d\n",plane1,plane2,plane3);
	  }
	}
	EndRequest(&PleaseWait,Window); 
	fclose(fp);
	OnMenu(Window,NOITEM);
	OnMenu(Window,64);
	FedUP;
}

void OpenFile() {
	char *FileName=NULL;
	FILE *fp,*fopen();
	USHORT i,j,letter;
	int Colour,plane1,plane2,plane3;
	
	SetWindowTitles(Window,"FedUP: Loading...",-1);
	if(!(FileName = GetFileName(Window))){
		FedUP;
		return;
	}
	if (!(fp = fopen(FileName,"r"))){
		NoSuchFile();
		return;
	}
	HoldOn.NextText = &Loading;
	Request(&PleaseWait,Window);
	OffMenu(Window,NOITEM);
	for(i = 0 ; i < 8 ; i++){
		fscanf(fp,"%d",&Colour);
		MyFont.FontColour[i] = (UWORD)Colour;
	}
	for(letter = 0 ; letter < 59 ; letter++) {
	  for(i = 0 ; i < 32 ; i++) {
	    fscanf(fp,"%d %d %d",&plane1,&plane2,&plane3);
	    for(j = 0 ; j < 16 ; j++) {
		Colour = 
		    4 * (BIT(15-j,plane3))
		    	+2 * (BIT(15-j,plane2))
				+ BIT(15-j,plane1);
		MyFont.CharSet[letter].Grid[j][i] = (UBYTE)Colour;
	    }
	    fscanf(fp,"%d %d %d",&plane1,&plane2,&plane3);
	    for(j = 16 ; j < 32 ; j++) {
		Colour = 
		    4 * (BIT(31-j,plane3))
		    	+2 * (BIT(31-j,plane2))
				+ BIT(31-j,plane1);
		MyFont.CharSet[letter].Grid[j][i] = (UBYTE)Colour;
	    }
	  }
	} 
	fclose(fp);
	EndRequest(&PleaseWait,Window);
	OnMenu(Window,NOITEM);
	LoadRGB4(&Screen->ViewPort,&MyFont.FontColour[0],8); 
	RemakeDisplay();
	FillGrid(RP);
	CurrFile = FileName;
	OnMenu(Window,64); 
	FedUP;
}

void SetDefaultColours() {
	USHORT i;
	
	for(i = 0 ; i < 8 ; i++) 
		MyFont.FontColour[i] = ColourTable[i];
	LoadRGB4(&Screen->ViewPort,&MyFont.FontColour[0],8);
	RemakeDisplay();
}

void NoSuchFile() {
	struct IntuiText NoSuchText = {
		7,1,JAM2,54,10,NULL,"No such file !",NULL
	};
	struct IntuiText NoSuchOK = {
		7,1,JAM2,2,2,NULL,"OK",NULL
	};
	
	AutoRequest(Window,&NoSuchText,&NoSuchOK,NULL,NULL,NULL,220,50);
}

void ClearGrid() {
	register int i,j;
	
	SetWindowTitles(Window,"FedUP: Clearing Grid...",-1);
	for(i = 0 ; i < 32 ; i++)
		for(j = 0 ; j < 32 ; j++)
			MyFont.CharSet[CurrChar].Grid[i][j] = 0;
	FillGrid(RP);
	FedUP;
}			

void ClearFont() {
	register int letter,i,j;
	
	SetWindowTitles(Window,"FedUP: Clearing font...",-1);
	for(letter = 0 ; letter < 59 ; letter++)
		for(i = 0 ; i < 32 ; i++)
			for(j = 0 ; j < 32 ; j++)
				MyFont.CharSet[letter].Grid[i][j] = 0;
	FillGrid(RP);
	FedUP;
}			
	
void MakeModule() {
	FILE *fp,*fopen();
	USHORT i,j,letter;
	USHORT Plane;
	int Colour,PlaneWord1,PlaneWord2;
	char Hi,Lo;

	struct IntuiText Module={0,7,JAM2,68,50,NULL,"Saving module",NULL};
	char *FileName;
		
	if (!(FileName = GetFileName(Window))) return;
	if(!(fp = fopen(FileName,"w"))){
		NoSuchFile();
		return;
	}
	HoldOn.NextText = &Module;
	Request(&PleaseWait,Window);
	OffMenu(Window,NOITEM);
	/* First save the colour table */
	for(i = 0 ; i < 8 ; i++){
		Colour = (int)MyFont.FontColour[i];
		Hi = (char)(Colour >> 8);
		Lo = (char)(Colour & 0x00FF);
		putc(Hi,fp);
		putc(Lo,fp);
	}
	/* Now the letter table */
	for(letter = 0 ; letter < 59 ; letter++) {
	  for(Plane=0 ; Plane < 3 ; Plane++) {
           for(i = 0 ; i < 32; i++) {
	    PlaneWord1 = PlaneWord2 = 0;
	    /* Compute first word */
	    for(j = 0 ; j < 16 ; j++) {
		Colour = MyFont.CharSet[letter].Grid[j][i];
		PlaneWord1 += (BIT(Plane,Colour)) << (15-j);
	    }
	    /* Now the second word */
	    for(j = 16 ; j < 32 ; j++) {
		Colour = MyFont.CharSet[letter].Grid[j][i];
		PlaneWord2 += (BIT(Plane,Colour)) << (31-j);
	    }
	    Hi = (char)(PlaneWord1 >> 8);
	    Lo = (char)(PlaneWord1 & 0x00FF);
	    putc(Hi,fp);
	    putc(Lo,fp);
	    Hi = (char)(PlaneWord2 >> 8);
	    Lo = (char)(PlaneWord2 & 0x00FF);
	    putc(Hi,fp);
	    putc(Lo,fp);
	  }
	 }
	}
	EndRequest(&PleaseWait,Window); 
	fclose(fp);
	OnMenu(Window,NOITEM);
	/* Restore current file name to string gadget */
	for(i = 0 ; FileBuffer[i] = *(CurrFile+i) ; i++);
} 

/* Copy the data for the present character to another */
void CopyChar(int WhichWay) {
	UBYTE CopyOK = 0;
	struct IntuiMessage *msg = NULL;
	ULONG class,sig,sigmask;
	USHORT x,y,k,code;
	USHORT Char1,Char2;
	register int i,j;
	UBYTE TempChar;
	const char *ToTitle = "FedUP: Pick a character to copy to...";
	const char *FromTitle = "FedUP: Pick a character to copy from...";
	
	sigmask = 1L << Window->UserPort->mp_SigBit;
	if (WhichWay == TO)
		SetWindowTitles(Window,ToTitle,-1);
	else
		SetWindowTitles(Window,FromTitle,-1);
	while(!CopyOK) {
	  sig = Wait(sigmask);
           if (sig & sigmask) {
		while(msg=(struct IntuiMessage *)GetMsg(Window->UserPort)){
		  class = msg->Class;
		  code = msg->Code;
		  ReplyMsg((struct Message *)msg);
		  if (class == MOUSEBUTTONS && code == SELECTDOWN){
		   x = msg->MouseX;
		   y = msg->MouseY;
		   if (CheckBox(x,y,FONTXMIN,FONTXMAX,FONTYMIN,FONTYMAX)){
		     CopyOK = 1;
		     i = (x - FONTXMIN) / 12;
		     j = (y - FONTYMIN) / 12;
		     k = 8 * i + j;
		     TempChar = CurrChar;
		     CurrChar = k;
		     HiLite(RP);
		     if (WhichWay == TO) {
			Char1 = k;
			Char2 = TempChar;
		     }
		     else {
			Char1 = TempChar;
			Char2 = k;
		     }
		     for(i = 0 ; i < 32 ; i++)
		 	for(j = 0 ; j < 32 ; j++) 
			  MyFont.CharSet[Char1].Grid[i][j] =
				       MyFont.CharSet[Char2].Grid[i][j];
		    HiLite(RP);
		    CurrChar = TempChar;
		    if (WhichWay == FROM) FillGrid(RP);
		   }
		   else 
		   	DisplayBeep(NULL);
		}
	    }
	 }
      }
      FedUP;
}

/* Next two do the mirrorrorrorring */
void ReflectY() {
	register int i,j;
	UBYTE Temp;
	
	SetWindowTitles(Window,"FedUP: YReflection",-1);
	for(j = 0 ; j < 32 ; j++){
		for(i = 0 ; i < 16 ; i++){
			Temp = MyFont.CharSet[CurrChar].Grid[i][j];
			MyFont.CharSet[CurrChar].Grid[i][j] =
  				    MyFont.CharSet[CurrChar].Grid[31-i][j];
			MyFont.CharSet[CurrChar].Grid[31-i][j] = Temp;
		}
	}
	FillGrid(RP);
	FedUP;
}

void ReflectX() {
	register int i,j;
	UBYTE Temp;
	
	SetWindowTitles(Window,"FedUP: X-Reflection",-1);
	for(i = 0 ; i < 32 ; i++){
		for(j = 0 ; j < 16 ; j++){
			Temp = MyFont.CharSet[CurrChar].Grid[i][j];
			MyFont.CharSet[CurrChar].Grid[i][j] =
  				    MyFont.CharSet[CurrChar].Grid[i][31-j];
			MyFont.CharSet[CurrChar].Grid[i][31-j] = Temp;
		}
	}
	FillGrid(RP);
	FedUP;
}

void Transpose() {
	register int i,j;
	
	SetWindowTitles(Window,"FedUP : X=Y Reflect",-1);
	for(i = 0 ; i < 32 ; i++)
		for(j = 0 ; j < 32 ; j++)
			Undo[i][j] = MyFont.CharSet[CurrChar].Grid[j][i];
	for(i = 0 ; i < 32 ; i++)
		for(j = 0 ; j < 32 ; j++)
			MyFont.CharSet[CurrChar].Grid[i][j] = Undo[i][j];
	FillGrid(RP);
	FedUP;
}

/* Back to the coarse grid again */
void CoarseGrid() {
	SetAPen(RP,0);
	RectFill(RP,GRIDXMIN,GRIDYMIN,GRIDXMAX,GRIDYMAX);
	SetAPen(RP,7);
	DrawGrid(RP,17,8);
	FillGrid(RP);
}

void ShowPixelSize() {
	SetAPen(RP,0);
	RectFill(RP,GRIDXMIN+56,GRIDYMAX+5,GRIDXMIN+65,GRIDYMAX+13);
	SetAPen(RP,7);
	if (Pix == 1)
 	    RectFill(RP,GRIDXMIN+59,GRIDYMAX+7,GRIDXMIN+61,GRIDYMAX+9);
	else
	    RectFill(RP,GRIDXMIN+57,GRIDYMAX+5,GRIDXMIN+65,GRIDYMAX+13);
	SetAPen(RP,CurrColour);
}

void Flood(USHORT FloodType) {
	register int i,j;
	
	SetWindowTitles(Window,"FedUP: Flood...",-1);
	if (!AreYouSure(FLOOD)) {
		FedUP;
		return;
	}
	for(i = 0 ; i < 32 ; i++) {
         for(j = 0 ; j < 32 ; j++) {
          if (!MyFont.CharSet[CurrChar].Grid[i][j] || FloodType)
	  	MyFont.CharSet[CurrChar].Grid[i][j] = CurrColour;
	 }
	}
	FillGrid(RP);
	FedUP;
}
