//================================================================
// 2DPanel
//
// EpPicture: A higher-level structure, built on EpImage.
// EpPicture supports:
// - Position
// - Callbacks
//
// AUTHOR:  Gabor Nagy
// DATE:    2023-Jun-20 20:40:03
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//================================================================

#ifndef _EPicture_h
#define _EPicture_h

#include <Image/Image.h>

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


typedef void  (*EpCallbackFunc)(void* PW, EPointer PClientData, EPointer PCallData);

typedef struct
{
	EpCallbackFunc  Function;
	EPointer        ClientData;
	uint16_t        Enabled : 1, TypeExclusive : 1;
} EpCallback;


// GUI wrapper object for EpImage that contains position, virtual size, callbacks etc.
//
typedef struct EpPicture
{
	EObjectCore(EObject);

	EpImageIOModule*  FileFormat;                     // File format of the Picture

	EpCoord2          Position;
	EIndex2           VirtualSize;
	unsigned int      UptodateFlags;                  // These flags indicate which buffers are up-to-date

	EList(, EpCallback, ContentChangedCallbacks);
	EList(, EpCallback, SizeChangedCallbacks);
	EList(, EpCallback, PointerButtonCallbacks);
	EList(, EpCallback, PointerMotionCallbacks);

	EpImage*          Image;
	char              Changed;    // '-' or '*' depending on whether the image is modified

#ifdef EX11
	Pixmap            XPixmap;    // X pixmap of the Image
	Pixel             X_PixelValues[EpMAX_COLORNUM];  // PixelValues of colors for XeDrawing
#endif
} EpPicture;




typedef struct
{
	ECallbackStructCore;

	int            Button;                           // For BUTTON
	unsigned long  State;                            // For MOTION (Modifier and button masks)
	EInt32_2       Pointer;                          // The latest pointer position
	XePosAndTime   Positions[XeMAX_MOTION_SAMPLES];  // The latest pointer N positions
	int            NPositions;
} EpPictureCallbackStruct;

extern ECoreClass  EpPictureCallbackStruct_class[];

//------------------------------------------------
// Picture callback types
//------------------------------------------------
enum
{
	EpCR_CONTENT_CHANGED = 1,  // Picture content changed
	EpCR_SIZE_CHANGED,         // Picture size changed
	EpCR_POINTER_BUTTON,       // Pointer button pressed or released on Picture
	EpCR_POINTER_MOTION        // Pointer moved on Picture
};

#define EpCR_TYPE_MASK         0x000F

#define EpCR_TYPE_EXCLUSIVE    0x0100  // Ignore all other callbacks of this type until this callback is removed

//------------------------------------------------
// Picture callback reasons
//------------------------------------------------
enum
{
	EpCR_BUTTON_PRESS = 1,  // Pointer button pressed
	EpCR_BUTTON_RELEASE,    // Pointer button released
	EpCR_MOTION             // Pointer moved on Picture
};


//------------------------------------------------
// Picture.c
//------------------------------------------------
extern const EObjectClass  EpPicture_class[];

extern EpPicture*  EpPicture_New(const EIndex PSizeX, const EIndex PSizeY,  const int PPixelType, const int PComponentsPerPixel, const int PPixelComponentType);
extern EpPicture*  EpPicture_NewFromImage(EpImage* PImage);

extern int     EpPicture_Resize(EpPicture* PPicture,  const EIndex PNewSizeX, const EIndex PNewSizeY,   const int PPixelType, const int PComponentsPerPixel, const int PPixelComponentType);

extern void    EpPicture_CallPointerButtonCallbacks(EpPicture* PPicture, EpPictureCallbackStruct* PCBS);
extern void    EpPicture_CallContentChangedCallbacks(EpPicture* PPicture);
extern void    EpPicture_CallSizeChangedCallbacks(EpPicture* PPicture, const EBool PCallContentChanged);
extern void    EpPicture_CallbackAdd(EpPicture* PPicture, const int PType, EpCallbackFunc PFunction, EPointer PClientData);
extern void    EpPicture_RemoveCallback(EpPicture* PPicture, const int PType, EpCallbackFunc PFunction, EPointer PClientData);



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

#endif // _EPicture_h
