4 * Created on: 9 nov. 2008
11 #include <wx/control.h>
14 //****************************************************
15 //************ PALETTE CLASS **************
16 //****************************************************
17 class MyPalette
: public wxPalette
21 MyPalette( wxPalette
& _palette
);
22 MyPalette( wxImage
& _img
);
25 bool LoadFrom( wxString
& _path_palette
);
26 bool LoadFrom( wxImage _img
);
27 bool SaveAs( wxString
& _fullpath
);
30 //****************************************************
31 //************ PALETTE ELEMENT CONTROL **************
32 //****************************************************
35 // - wxPALETTE_ELT_CLICKED when clicked
36 // - wxPALETTE_ELT_COLOR_CHANGE when color change
41 AUTO_ELTCOLOR
, // Standalone colour chooser
42 ELTPALETTE
, // the colour chooser is part of a palette Ctrl
45 class MyPaletteElementCtrl
: public wxControl
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
);
56 void ComputeColorTrans( int hue
, int sat
, int luz
);
57 void ComputeColorDecal( int red
, int green
, int blue
);
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
;
73 int selected_state
; // 0==NOT ; 1==SELECTED; 2==ASSOCIATED
74 int mappedTo
; // The index map for this index
76 virtual wxSize
GetMinSize() const;
83 //****************************************************
84 //************ PALETTE CONTROL **************
85 //****************************************************
89 class MyPaletteCtrl
: public wxWindow
94 MyPaletteCtrl(wxWindow
* _parent
);
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;
128 wxPalette
GetNewPalette();
130 ob_object
*obj_associated
;
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
;
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
);
161 int red
, green
, blue
;
163 void SetAssociations();
164 imgFile
* theSourceImg
;
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 ), \
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 ), \
205 #endif /* MYPALETTE_H_ */