fix compile against newer giflib
[rofl0r-obeditor.git] / src / images__MyPalette.h
blobc36db261c111b070e8c672427f782954041e20cf
1 /*
2 * MyPalette.h
4 * Created on: 9 nov. 2008
5 * Author: pat
6 */
8 #ifndef MYPALETTE_H_
9 #define MYPALETTE_H_
11 #include <wx/control.h>
12 #include <wx/image.h>
14 //****************************************************
15 //************ PALETTE CLASS **************
16 //****************************************************
17 class MyPalette : public wxPalette
19 public:
20 MyPalette();
21 MyPalette( wxPalette& _palette );
22 MyPalette( wxImage& _img );
23 ~MyPalette();
25 bool LoadFrom( wxString& _path_palette );
26 bool LoadFrom( wxImage _img );
27 bool SaveAs( wxString& _fullpath );
30 //****************************************************
31 //************ PALETTE ELEMENT CONTROL **************
32 //****************************************************
34 // Throw
35 // - wxPALETTE_ELT_CLICKED when clicked
36 // - wxPALETTE_ELT_COLOR_CHANGE when color change
39 enum
41 AUTO_ELTCOLOR, // Standalone colour chooser
42 ELTPALETTE, // the colour chooser is part of a palette Ctrl
45 class MyPaletteElementCtrl : public wxControl
47 public:
48 MyPaletteElementCtrl(wxWindow* _parent, int _mode = ELTPALETTE );
49 void SetMode( int new_mode );
50 ~MyPaletteElementCtrl();
52 void SetRGB( unsigned char _r, unsigned char _g, unsigned char _b );
53 void GetRGB( unsigned char* _r, unsigned char* _g, unsigned char* _b );
54 void SetColor(const wxColor& _color );
55 wxColour GetColor();
56 void ComputeColorTrans( int hue, int sat, int luz );
57 void ComputeColorDecal( int red, int green, int blue );
58 void RestoreRGBs();
59 void CommitNewColours();
61 virtual void Update();
62 virtual void Refresh();
63 void OnPaint(wxPaintEvent& event);
64 void DoPainting( wxDC& dc );
66 bool Equal( wxColour& _col );
67 void EvtDoubleClick(wxMouseEvent& event);
68 void EvtClick(wxMouseEvent& event);
70 unsigned char r,g,b,a;
71 unsigned char origin_r, origin_g, origin_b;
72 int hue,sat,lum;
73 int selected_state; // 0==NOT ; 1==SELECTED; 2==ASSOCIATED
74 int mappedTo; // The index map for this index
76 virtual wxSize GetMinSize() const;
77 protected:
78 int eltmode;
79 DECLARE_EVENT_TABLE()
83 //****************************************************
84 //************ PALETTE CONTROL **************
85 //****************************************************
86 class ob_object;
87 class imgFile;
89 class MyPaletteCtrl : public wxWindow
91 public:
92 static bool mode8bit;
93 public:
94 MyPaletteCtrl(wxWindow* _parent );
95 void Constructor();
96 virtual ~MyPaletteCtrl();
98 virtual void Refresh();
99 virtual bool Layout();
101 void SetAssociatedObject( ob_object* _obj );
102 void Reset(bool b_layout = true);
104 bool TryToInitWithImage( wxString& strpath);
105 bool InitRemapping_With( wxString& strpath );
106 void UndoRemapping();
108 //-----------------------------------------
109 // <add_mode> meaning for 16bit mode
110 // 0 => deselect other color and toggle select state for this color
111 // 1 => toggle selection state of this colour
112 // 2 => add this colour to selection
113 // <add_mode> meaning for 8bit mode
114 // > 0 => new remapping or undo remapping
115 // == 0 => choose new source colour for remap
116 void SelectColour( int ind, int add_mode = 0 );
118 void EvtPaletteEltClicked( wxCommandEvent& event );
119 void EvtPaletteEltColorChange( wxCommandEvent& event );
120 void DeselectEveryThing();
121 void DoGuessColors();
122 void DoFixSelectedColors();
123 void UnDoFixSelectedColors();
125 wxString FullPath()const;
126 wxString OBPath()const;
127 bool IsInit()const;
128 wxPalette GetNewPalette();
130 ob_object *obj_associated;
131 bool isChanged;
132 bool b_init;
134 // MyPaletteElementCtrl* PalElt_clicked;
136 virtual void EvtSize( wxSizeEvent& event );
137 void OnPaint(wxPaintEvent& event);
139 wxBoxSizer *mainSizer;
140 wxGridSizer *gridSizer;
141 wxStaticText *error_text;
143 MyPalette* thePalette;
144 MyPaletteElementCtrl** paletteElements;
145 int nb_elts;
147 void Reset_HSL();
148 void Apply_HSL();
149 void ValidateHSLs();
150 void InValidateHSLs();
152 void Set_Hue( int _hue );
153 void Set_Sat( int _sat );
154 void Set_Luz( int _luz );
156 void Set_Red( int _red );
157 void Set_Green( int _green );
158 void Set_Blue( int _blue );
160 int hue, sat, luz;
161 int red, green, blue;
163 void SetAssociations();
164 imgFile* theSourceImg;
166 protected:
167 void pr_Make_SrcPalette_To_PaletteElts(bool b_update_sizer );
168 MyPaletteElementCtrl* curr_selected;
169 DECLARE_EVENT_TABLE()
173 //****************************************************
174 //************ NEW EVENT **************
175 //****************************************************
177 BEGIN_DECLARE_EVENT_TYPES()
178 DECLARE_EVENT_TYPE(wxPALETTE_ELT_CLICKED, 7777)
179 DECLARE_EVENT_TYPE(wxPALETTE_ELT_COLOR_CHANGE, 7777)
180 END_DECLARE_EVENT_TYPES()
182 // define an event table macro for this event type
183 #ifndef PALETTE_ELT_CLICKED
184 #define PALETTE_ELT_CLICKED(fn) \
185 DECLARE_EVENT_TABLE_ENTRY( \
186 wxPALETTE_ELT_CLICKED, wxID_ANY, wxID_ANY, \
187 (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
188 (wxObject *) NULL \
190 #endif
193 // define an event table macro for this event type
194 #ifndef PALETTE_ELT_COLOR_CHANGE
195 #define PALETTE_ELT_COLOR_CHANGE(fn) \
196 DECLARE_EVENT_TABLE_ENTRY( \
197 wxPALETTE_ELT_COLOR_CHANGE, wxID_ANY, wxID_ANY, \
198 (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
199 (wxObject *) NULL \
201 #endif
205 #endif /* MYPALETTE_H_ */