//========================================================================
// Color library GUI
//
// AUTHOR:  Gabor Nagy
// DATE:    2026-Apr-25 21:48:16
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//========================================================================
#ifndef	_EColorPanel_h
#define	_EColorPanel_h

#include <Color/ColorWheel.h>
#include <Image/Graphs.h>

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

extern EcRGBAiColor  Ec_DefaultColors[];

#define Ec_MAX_NUM_OF_COLORS	65536	// Max 16-bit palette

// Color definition modes
//
enum
{
	EcSLIDERS_RGBA = 0,
	EcSLIDERS_HSVA
};

typedef struct EcColorPanel_S  EcColorPanel;

typedef void  (*EcColorPanelCallbackFunc)(EcColorPanel* PColorPanel, EPointer PClientData, EPointer PCallData);


typedef struct
{
	XeWidget         DrawW,
	                 SpectrumXW, SpectrumYW;

	EpGraphDisplay*  GraphDisplay;
	EpLineGraph*     Graph;

	EpImage*         BandsImage;
	EListA_s(, XeStringBinarySegment, WavelengthMinStr);
	EListA_s(, XeStringBinarySegment, WavelengthMaxStr);

	int              Mode;                            // EcSpectrumWavelengthDescending (default) etc.
	float            WavelengthMin, WavelengthMax;    // In nanometers
	int              NSpectralSamples;                // For displaying spectrum of an RGB color
} EcSpectrumDisplay;


struct EcColorPanel_S
{
	XeWidget  TopMatrixW, HTopMatrixW,
	          ColorCmdMatrixW, CopyColW, ExgColW, SpreadColW, LightM,
	          PaletteFrameW, PaletteDrawW,
	          DrawColorsFrameW, ColorSwatchDrawW,
	          RScaleW, GScaleW, BScaleW, IScaleW, AScaleW,
	          SpectrumPanelW;

	EcSpectrumDisplay         SpectrumDisplay;

	EcColorPanelCallbackFunc  ColorChangedCallback;
	EPointer                  ColorChangedCallbackClientData;
	int                       ComponentType;
	int                       DecimalPoints;
	int                       NumOfAllocatedColors;    // Number of colors allocated
	int                       NumOfColors;             // Current number of colors and bitplane depth in the current palette
	EcRGBAiColor*             RGBAiColors;             // The array of colors in the palette
	EcRGBAf32Color*           RGBAfColors;             // The array of colors in the palette

	EcColor                   Color;                         // RGB and spectrum for the current color

	float                     RGBtoXYZ[16], XYZtoRGB[16];

	EInt32_2                  ColorButtonSize;
	EInt32_2                  PaletteSize;
	int                       PaletteColumns, PaletteRows;

	int                       DrawColor0, DrawColor1, DrawColor2;
	EcColorWheel*             ColorWheel;
	EBool                     AlphaOn,
	                          Truecolor,               // All the drawing widgets have truecolor visual
	                          PaletteValid;

#ifdef EX11
	Colormap                  X_Colormap;              // Associated X Colormap of this ColorPanel
	Pixel*                    X_PixelValues;           // Pointer to the current array of X11 color pixel values
#endif
};


typedef struct
{
	int   Reason;
	int   NumOfColors;  // Number of colors that were changed
	int*  ColorIDs;     // IDs of colors that were changed
} EcColorPanelCallbackStruct;

extern ECoreClass    EcColorPanelCallbackStruct_class[];

extern EcRGBAiColor  Ec_ThermoColorR, Ec_ThermoColorG, Ec_ThermoColorB, Ec_ThermoColorW;


extern EpImage*  Ec_RedRampImage;
extern EpImage*  Ec_GreenRampImage;
extern EpImage*  Ec_BlueRampImage;
extern EpImage*  Ec_IntensityRampImage;
extern EpImage*  Ec_AlphaRampImage;


extern EcColorPanel*  EcColorPanel_NewVa(XeWidget PParentW, char* PName, ...);
extern void           EcColorPanel_Free(EcColorPanel* PColorPanel);
extern void           EcColorPanel_Exit(void);

extern void    EcColorPanel_SetDrawColor(EcColorPanel* PColorPanel, const int PColorIndex, const int PColorID);

extern void    EcColorPanel_SetColor(EcColorPanel* PColorPanel, const int PColorIndex, const EcColor* PColor);

extern void    EcColorPanel_SetRGBfColor(EcColorPanel* PColorPanel, const int PColorIndex, const EcRGBf32Color* PRGBfColorIn);
extern void    EcColorPanel_SetRGBAfColor(EcColorPanel* PColorPanel, const int PColorIndex, const EcRGBAf32Color* PRGBAfColorIn);
extern void    EcColorPanel_SetRGBAiColor(EcColorPanel* PColorPanel, const int PColorIndex, const EcRGBAiColor* PRGBAiColorIn);

extern XeWidget  EcColorSwatch_NewRGBf(const char* PName, XeWidget PParentW, XeWidget* PLabeWRet, EcRGBf32Color* PRGBfColor,  XeCallbackFunc PCallback, EPointer PClientData);
extern XeWidget  EcColorSwatch_NewRGBAi(const char* PName, XeWidget PParentW, XeWidget* PLabeWRet, EcRGBAiColor* PRGBAiColor,  XeCallbackFunc PCallback, EPointer PClientData,  const EArg* PArgs, const int PNArgs);
extern XeWidget  EcColorSwatch_NewRGBAf32(const char* PName, XeWidget PParentW, XeWidget* PLabeWRet, EcRGBAf32Color* PRGBAf32Color,  XeCallbackFunc PCallback, EPointer PClientData);

extern void      EcColorSwatch_SetColorRGBAi(XeWidget PW, EcRGBAiColor* PColor);

extern EBool   EcColorPanel_Configure(EcColorPanel* PColorPanel,  const uint16_t PColorComponentType,  const int PNColors, const int PDepth, const EcRGBAiColor* PRGBAiColors, const EcRGBAf32Color* PRGBAfColors);
extern EBool   EcColorPanel_Redraw(EcColorPanel* PColorPanel);

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

#endif // _EColorPanel_h
