//---------------------------------------------------------------------------

#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <Graphics.hpp>
#include <Menus.hpp>
#include <ImgList.hpp>
#include <Dialogs.hpp>


#define XRES 240
#define YRES 128





#define obNone 0x00
#define obLabel 0x01
#define obLine 0x02
#define obFrame 0x03
#define obIcon 0x04
#define obButton 0x05

#define obMove 0x20
#define obSelect 0x21


#define obsNone 0x00
#define obsDown 0x01
#define obsUp 0x02
#define obsMoveSelect 0x03
#define obsMove 0x04
#define obsSelect 0x05



#define atNone 0
#define atPrevScr 1
#define atNewScr 2
#define atAddChar 3
#define atAddInt 4
#define atCall 5

#define fstSingle 0x00
#define fstDouble 0x01
#define fstFilled 0x02

#define bcaYes 0x00
#define bcaNo 0x01


typedef struct{
	int obj;
	int state;
	int xa,ya;
	int xb,yb;
	int dx,dy;
	int dx2,dy2;
	int xr,yr;
	unsigned char srcimg[128][240];
	unsigned char destimg[128][240];
	char str[1024];
	int font;
	int btn;
	int btnact;
	char *btnactscr;
	int btnanim;
	int style;
} TNewObj;

typedef struct{
	int Ax,Ay;
	int Bx,By;
} TObjLine;

typedef struct{
	int Ax,Ay;
	int Bx,By;
	int style;
} TObjFrame;

typedef struct{
	int Ax,Ay;
	char *str;
	int font;
	int btn;
	int btnact;
	int btnanim;
	char *btnactscr;
} TObjLabel;

typedef struct{
	int Ax,Ay;
	int xr,yr;
	unsigned char *srcimg;
	unsigned char *destimg;
} TObjIcon;

typedef struct{
	void *objptr;
	int type;
} TObj;

typedef struct{
	TObj *obj;
	int objects;
	char *name;
} TScr;

typedef struct{
	TScr *scr;
	int screens;
	char *name;
} TProject;



typedef struct{
	int	type;
	void *ptr;
	int	dt;
	int pt;
	int obj_id;
} TMoveRec;

typedef struct{
	void *ptr;
	int type;
	int obj_id;
}TSelObjs;


typedef struct{
	char img[8][16];
	int xres;
	char name[32];
} TCFchar;

typedef struct{
	TCFchar data[257];
	int yres;
	char prefix[256];
} TCFont;

typedef struct{
	int fonts;
	TCFont *font;
} TFonts;




extern AnsiString apppath;
extern AnsiString genpath;
extern AnsiString genpathimg;
extern AnsiString SFDpath;

extern int wbmp[128][240];
extern TNewObj NewObj;

extern TProject *Project;
extern int screen;
extern int object;

extern TFonts *Fonts;

extern TMoveRec MoveRec[512];
extern int MoveRecN;
extern TMoveRec MovePts[512];
extern int MovePtsN;
extern int MovePtsS;

extern TSelObjs	SelObjs[512];
extern int SelObjsN;

extern bool edit;


//---------------------------------------------------------------------------
class TMForm : public TForm
{
__published:	// IDE-managed Components
	TStatusBar *SB1;
	TGroupBox *GroupBox1;
	TPanel *Panel1;
	TImage *wimg;
	TGroupBox *GroupBox2;
	TBitBtn *BtnOlabel;
	TBitBtn *BtnOline;
	TBitBtn *BtnOframe;
	TBitBtn *BtnOicon;
	TBitBtn *BtnOmove;
	TBitBtn *BtnOselect;
	TImage *Image1;
	TImage *Image4;
	TImage *Image2;
	TImage *Image3;
	TImage *Image5;
	TImage *Image6;
	TImage *Image7;
	TImage *Image8;
	TMainMenu *MainMenu1;
	TMenuItem *File1;
	TMenuItem *Edit1;
	TMenuItem *MBtnObjEdit;
	TMenuItem *MBtnOpen;
	TMenuItem *MBtnClose;
	TMenuItem *N1;
	TMenuItem *MBtnExit;
	TMenuItem *N2;
	TMenuItem *MBtnOlabel;
	TMenuItem *MBtnOline;
	TMenuItem *MBtnOframe;
	TMenuItem *MBtnOicon;
	TBevel *Bevel1;
	TMenuItem *MBtnObjDelete;
	TMenuItem *MBtnObjNew;
	TMenuItem *MBtnScrNew;
	TMenuItem *MBtnScrDelete;
	TGroupBox *GroupBox3;
	TComboBoxEx *ComboScreens;
	TLabel *LblScr;
	TButton *BtnNewScreen;
	TButton *BtnDeleteScreen;
	TMenuItem *MBtnNewPrj;
	TMenuItem *MBtnScrEdit;
	TMenuItem *MBtnSave;
	TImageList *ImageList1;
	TBitBtn *BtnOmouse;
	TMenuItem *N3;
	TMenuItem *MBtnOselect;
	TMenuItem *MBtnOmove;
	TMenuItem *Generate1;
	TMenuItem *MBtnGenerateSrc;
	TSaveDialog *SD1;
	TOpenDialog *OD1;
	TMenuItem *MBtnGenImgs;
	TGroupBox *GroupBox4;
	TLabel *Label1;
	TLabel *Label2;
	TLabel *LblScrs;
	TLabel *LblObjs;
	TImageList *ImageList2;
	TGroupBox *GroupBox5;
	TComboBoxEx *ComboFontList;
	TLabel *Label4;
	TLabel *Label3;
	TLabel *LblFonts;
	TLabel *Label5;
	TLabel *LblFontHeight;
	TMenuItem *MbtnAbout;
	TTimer *Timer1;
	TImage *Image9;
	void __fastcall wimgMouseMove(TObject *Sender, TShiftState Shift, int X,
					int Y);
	void __fastcall wimgMouseDown(TObject *Sender, TMouseButton Button,
					TShiftState Shift, int X, int Y);
	void __fastcall BtnOlineClick(TObject *Sender);
	void __fastcall wimgMouseUp(TObject *Sender, TMouseButton Button,
					TShiftState Shift, int X, int Y);
	void __fastcall BtnOframeClick(TObject *Sender);
	void __fastcall BtnOmoveClick(TObject *Sender);
	void __fastcall BtnOlabelClick(TObject *Sender);
	void __fastcall MBtnObjDeleteClick(TObject *Sender);
	void __fastcall MBtnObjEditClick(TObject *Sender);
	void __fastcall BtnOiconClick(TObject *Sender);
	void __fastcall BtnOselectClick(TObject *Sender);
	void __fastcall MBtnNewPrjClick(TObject *Sender);
	void __fastcall BtnNewScreenClick(TObject *Sender);
	void __fastcall ComboScreensChange(TObject *Sender);
	void __fastcall MBtnScrEditClick(TObject *Sender);
	void __fastcall BtnDeleteScreenClick(TObject *Sender);
	void __fastcall MBtnCloseClick(TObject *Sender);
	void __fastcall MBtnScrNewClick(TObject *Sender);
	void __fastcall MBtnScrDeleteClick(TObject *Sender);
	void __fastcall BtnOmouseClick(TObject *Sender);
	void __fastcall MBtnOlineClick(TObject *Sender);
	void __fastcall MBtnOframeClick(TObject *Sender);
	void __fastcall MBtnOlabelClick(TObject *Sender);
	void __fastcall MBtnOiconClick(TObject *Sender);
	void __fastcall MBtnOselectClick(TObject *Sender);
	void __fastcall MBtnOmoveClick(TObject *Sender);
	void __fastcall MBtnSaveClick(TObject *Sender);
	void __fastcall MBtnOpenClick(TObject *Sender);
	void __fastcall MBtnGenerateSrcClick(TObject *Sender);
	void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
	void __fastcall MBtnExitClick(TObject *Sender);
	void __fastcall MBtnGenImgsClick(TObject *Sender);
	void __fastcall ComboFontListChange(TObject *Sender);
	void __fastcall FormShow(TObject *Sender);
	void __fastcall MbtnAboutClick(TObject *Sender);
	void __fastcall Timer1Timer(TObject *Sender);
	void __fastcall Image1MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image1MouseLeave(TObject *Sender);
	void __fastcall Image2MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image2MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image2MouseLeave(TObject *Sender);
	void __fastcall Image3MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image3MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image3MouseLeave(TObject *Sender);
	void __fastcall Image4MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image4MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image4MouseLeave(TObject *Sender);
	void __fastcall Image5MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image5MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image5MouseLeave(TObject *Sender);
	void __fastcall Image6MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image6MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image6MouseLeave(TObject *Sender);
	void __fastcall Image7MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image7MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image7MouseLeave(TObject *Sender);
	void __fastcall Image8MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image8MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall Image8MouseLeave(TObject *Sender);

private:	// User declarations
public:		// User declarations
	__fastcall TMForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TMForm *MForm;
//---------------------------------------------------------------------------

// ------ graphical funstions ------
extern void PaintWorkImg(void);
void RepaintWimg(void);
void DrawText(int x, int y, int font, int color, int bcolor, char *str, int action);
void DrawImg(int x, int y, int color, int bcolor, int src, TObjIcon *obj);
void DrawLine(int Ax, int Ay, int Bx, int By, int color);

// ------ fonts ------
int LoadFonts(void);
void RemoveAllFonts(void);
void DeallocateLastFont(void);


// ------ objects ------
int CreateObjLine(void);
int CreateObjFrame(void);
int CreateObjLabel(void);
int CreateObjIcon(void);
int RemoveObject(void);
void EditClose(void);
void FindObjects2move(void);
void FindObject2move(void);
bool ObjIsSelMember(void *obj);
bool FO2mMember(int Ax,int Ay,int x1,int y1,int x2,int y2);
void EditClose(void);
void ObjEditEnable(bool active);
void ObjectsActivated(bool active);

// ------ screens ------
int CreateScreen(void);
int	RemoveScreen(void);
void RefreshScreenList(void);

// ------ project ------
int SaveProject(void);
int LoadProject(void);
int CreateProject(void);
int RemoveProject(void);

// ------ other ------
extern int EditObjCstr(char **dest,char *src);
extern int strcmp_ci(char *str1, char *str2);
void RefreshInfo(void);



#endif
