//================================================================
// 2DPanel
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-Jul-12 23:39:46
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================

#ifndef _EPicPanel_h
#define _EPicPanel_h

#ifndef EpGUI
#define EpGUI
#endif

#include <Image/Tools.h>

#ifdef EX11
#ifndef USEOpenGL
#define USEOpenGL
#endif
#include <GL/gl.h>
#include <GL/glx.h>
#include <Xe/GLDraw.h>
#endif // EX11

#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
extern "C" {
#endif

extern XeApp   Xe_App;

#define EpZOOM_EPSILON  0.00001

// Identifiers for built-in functions
//
enum
{
	EpCR_90DEGREE_LEFT,
	EpCR_90DEGREE_RIGHT,
	EpCR_FLIP_HORIZONTALLY,
	EpCR_FLIP_VERTICALLY,
	EpCR_INVERT_COLOR,
	EpCR_INVERT_ALPHA
};


#define	MAX_NUMOFCOUNTABLECOLORS  500000

#define EpZOOMMULT         600  // Divisible by 2, 3, 5, 6, 8, 10, 12, 15 and 20
#define EpMAX_SUBIMAGENUM   64


// Network status of EPicturePanel
//
enum
{
	EpONLINE = 0,
	EpEXPECTING_IMAGE,
	EpSENDING_IMAGE
};


// IDs of "busy" dialogs with progress indicator
//
enum
{
	EpQFWORKINGDIALOGID = 0,
	EpCROPANIM_WORKINGDIALOGID
};


// Status values
//EpWindow
enum
{
	EpNORMAL = 0,
	EpGET_VIMAGE_DIALOG_ON,
	EpSEND_IMAGE_DIALOG_ON,
	EpEXIT_REMOTE_APP_DIALOG_ON,
	EpERROR_MESSAGE_ON
};


//------------------------------------------------
// Image representation in COLORINDEX mode
//------------------------------------------------
enum
{
	EpCIMODE_COLORREDUCTION,  // Colorindex (automatic color reduction)
	EpCIMODE_GRAYSCALE,       // Grayscale
	EpCIMODE_TRICKRGB,        // 'Trick' RGB
	EpCIMODE_TRICKRGB2        // 'Trick' RGB-2
};



enum
{
	EpGRAB_NONE = 0, EpGRAB_AREAFRAME
};


enum
{
	EpORIG_TOP_LEFT = 0,
	EpORIG_TOP_RIGHT,
	EpORIG_BOTTOM_LEFT,
	EpORIG_BOTTOM_RIGHT
};




typedef struct
{
	EpImageIOModule*  ImageSaveFormat;            // Image file format for saving
	EBool             SaveAlpha;                  // Save Alpha channel when possible
	EBool             MenuBarOn, InfoPanelOn, DrawModePanelOn,
	                  ColorPanelOn, DrawingPanelOn,  TimePanelOn, TimeExtPanelOn,
	                  VideoPanelOn, ZoomPanelOn;
	EcRGBAiColor      ImageWindowBackgroundRGBAiColor, MarginRGBAiColor;           // Color of added areas
	int               WindowDisplayType;          // Type of windows (WT_TRUECOLOR or WT_COLORINDEX)
	int               DefPicXOffset, DefPicYOffset,
	                  DefPicSizeX, DefPicSizeY;
	int               DefPicDepth, DefNumOfColors;
	EBool             DoubleBuffering;
	EBool             TurboColorCount;            // Fast count of different colors in an image by keeping flags of already found colors (needs 2 MB of RAM)
	EBool             TurboLuma;                  // Fast luma calculation by using a pre-generated luma-table for all the 1677712 colors (needs 16 MB of RAM)
	int               ColorIndexSubMode;

	int               UndoLevels, MaxUndoableImageSize;
	EBool             QuickRedo;                  // Don't free UnodStatus after undo, to allow fast redo

	int               ThumbnailSize;
	int               GrayScaleNumOfColors, TrickRGBNumOfColors;
	float             TrickRGBBrightness;
	EBool             FilteredDownZoom, TrickRGBAutoBrightness;
	EBool             ZoomAroundPointer, CenterToNew;
	EBool             KeepFileSelBoxAfterOk, GetFileFormatFromImage;
	char              PicFileSelBoxFilterList[4096];
	char              NetName[64];
	char              LogFile[1024];
	char              ResourcePath[1024];
	char              PluginPath[1048];
	char              Hosts[8192];
} EpSettings;


typedef struct
{
	XeWidget  MainW;
} EpPanel;


#define EpM_FillGLRectangle(pX, pY,  pSizeX, pSizeY,  pWSizeX, pWSizeY)  do { glScissor((pX), (pWSizeY) - (pY) - (pSizeY), pSizeX, pSizeY);EpglClear(GL_COLOR_BUFFER_BIT); } while(0)

extern int   Ep_MaxZoomIndex;


extern void  EpWindow_GetPointerPosition(EpWindow* PPWindow,  EIndex* PX, EIndex* PY);
extern void  Ep_Log(const int PType, const char* PPrefix, const char* PMessage, ...);

extern XeWidget  Ep_TopShellW;

extern XeCursor  Ep_NormalCursor,
                 Ep_BusyCursor,
                 Ep_FourArrowsCursor,
                 Ep_TopLeftCursor, Ep_TopRightCursor, Ep_BottomRightCursor, Ep_BottomLeftCursor,
                 Ep_LeftCursor, Ep_RightCursor, Ep_TopCursor, Ep_BottomCursor,
                 Ep_CrosshairCursor, Ep_PickCursor;

extern XeCursor  Ep_ZoomCursor;


EListA_s(extern, EpWindowPtr, Ep_PictureWindows);

extern EpSettings  Ep_Settings;
extern void        EpSettings_Init(EpSettings* PSettings);

extern char*      Ep_Trans(char* PString);

extern void       EpWindow_UpdateTitle(EpWindow* P2DWindow);
extern EBool      EpWindow_UpdatePalette(EpWindow* P2DWindow,  const uint16_t PColorComponentType,  const EIndex PNColors, const EcRGBAiColor* PRGBAiColors, const EcRGBAf32Color* PRGBAfColors);


extern void       EpPicture_UpdateName(EpPicture*);


//--------------------------------
// Panel/2DPanel.c
//--------------------------------
extern double        Ep_CurrentFrame;

extern int           EpPanel_Init(XeWidget PTopShellW, void (*PExitFunction)(void), int (*PToolClassRegisterFunction)(EpToolClass*), int (*PToolClassRemoveFunction)(EpToolClass*));
extern void          EpPanel_Exit(void);

extern void          EpWindow_SetPaletteColors(EpWindow* PPWindow, EpPicture* PPicture);


//--------------------------------
// Panel/GUI.c
//--------------------------------
extern int  Ep_ZoomValues[];


//--------------------------------
// Panel/SaveImageAs.c
//--------------------------------
typedef struct
{
	int               Reason;
	char*             FileName;
	EpImageIOModule*  Format;
} EpImageSaveAsCallbackStruct;

extern void  EpImage_SaveAs(EpImage* PImage, const char* PName, const char* PDialogTitle, XeWidget PTopShellW, EpImageIOModule* PFormat,  const XeCallbackFunc PCallback, EPointer PClientData);



extern XeVisual*     Ep_8BitColorIndexVisual;
extern XeVisual*     Ep_12BitRGBVisual;
extern XeVisual*     Ep_15BitRGBVisual;
extern XeVisual*     Ep_16BitRGBVisual;
extern XeVisual*     Ep_24BitRGBVisual;
extern EBool         EpWindow_CalcWindowRect(EpWindow* P2DWindow, const EBool PForceUpdate);
extern void          _EpEH_DrawWidget(XeWidget PW, XeEvent* PEvent, EPointer PClientData, EBool* PCDr);


extern int           Ep_Status;
extern EBool         Ep_GLColorIndexAvailable,Ep_GLColorIndexDoubleAvailable;
extern EBool         Ep_GLRGB12Available,Ep_GLRGB12DoubleAvailable;
extern EBool         Ep_GLRGB15Available,Ep_GLRGB15DoubleAvailable;
extern EBool         Ep_GLRGB16Available,Ep_GLRGB16DoubleAvailable;
extern EBool         Ep_GLRGB24Available,Ep_GLRGB24DoubleAvailable;

extern char   Ep_AppName[32];


extern void      EpWindow_CenterToPicture(EpWindow* PPWindow, EpPicture* PPicture);
extern void      EpWindow_SetCursor(EpWindow* P2DWindow, XeCursor* PCursor);
extern void      EpWindow_UpdatePicture(EpWindow* PWindow, EBool, EBool);
extern void      EpWindows_RedrawByPicture(EpPicture* PPicture, const EChangeFlags PChangeFlags);
extern void      EpWindow_UpdateDisplayBuffer(EpWindow* PPWindow);

extern void      EpWindow_AreasUndraw(EpWindow* PPWindow, unsigned long PStateMask);
extern void      EpWindow_AreasRedraw(EpWindow* PPWindow, unsigned long PStateMask);
extern void      EpWindow_AreasUpdate(EpWindow* PPWindow, unsigned long PStateMask);
extern EpAreaID  EpWindow_AreaAdd(EpWindow* PPWindow, EpPicture* PPicture,  const EpCoordinate PX, const EpCoordinate PY,  const EpCoordinate PSizeX, const EpCoordinate PSizeY,  const int PShape, const int PState, EpAreaCallbackFunc PCallback, EPointer PClientData);
extern EBool     EpWindow_AreaRemove(EpWindow* P2DWindow, const int LAreaID);
extern EBool     EpWindow_AreaGetGeometry(EpWindow* P2DWindow, const int PAreaID, EIndex* PX, EIndex* PY,  EIndex* PSizeX, EIndex* PSizeY);
extern EBool     EpWindow_AreaSetGeometry(EpWindow* PPWindow, const int PAreaID,  EpCoordinate PX, EpCoordinate PY,  EpCoordinate PSizeX, EpCoordinate PSizeY);
extern void      EpWindow_AreasFree(EpWindow* P2DWindow);

extern void   EpWindow_CreateColorIndexPicture(EpWindow* PPWindow, EpPicture* PPicture, EBool PInteractive, EBool (*PPaletteUpdateProc)(EpWindow* P2DWindow,  const uint16_t PColorComponentType,  const EIndex PNColors, const EcRGBAiColor* PRGBAiColors, const EcRGBAf32Color* PRGBAfColors));

extern void   Ep_ReadAndInitPlugins(char* PPath, char* PFileName);

extern int       EpPixelStats_ToXeString(const EpPixelStats* PStats, const EpPixelFormat* PPixelFormat, XeString* PXeString);

//--------------------------------
// Panel/Window.c
//--------------------------------
extern EBool  _Ep_AreaHandler(EpWindow* P2DWindow,  const EIndex PPX, const EIndex PPY,  XeEvent* PEvent);

extern EpImage*  _Image_Zoom;
extern EpImage*  _Image_Grid;


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
}	// Close scope of 'extern "C"' declaration
#endif

#endif // _EPicPanel_h
