2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbwxColourSelectorButton.cxx,v $
32 Date: $Date: 2012/11/16 08:52:14 $
33 Version: $Revision: 1.11 $
34 =========================================================================*/
38 * \brief Short description in one line
45 #ifdef _USE_WXWIDGETS_
47 #include "bbwxColourSelectorButton.h"
48 #include "bbwxPackage.h"
50 #include <wx/clrpicker.h>
54 //-------------------------------------------------------------------------
55 class wxColourPickerCtrlWidget :public wxPanel
59 wxColourPickerCtrlWidget( ColourSelectorButton* box,
65 ~wxColourPickerCtrlWidget();
66 void OnColorChange(wxColourPickerEvent& e);
69 wxColourPickerCtrl *picker;
70 ColourSelectorButton *mBox;
72 //-------------------------------------------------------------------------
74 //-------------------------------------------------------------------------
75 wxColourPickerCtrlWidget::wxColourPickerCtrlWidget( ColourSelectorButton* box,
81 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
84 bbtkDebugMessage("Process",9,"=> wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
86 wxPanel * panel = this;
87 picker = new wxColourPickerCtrl(panel,-1,
93 picker->SetPickerCtrlGrowable(false);
94 picker->SetTextCtrlGrowable(false);
96 Connect ( picker->GetId(),
97 wxEVT_COMMAND_COLOURPICKER_CHANGED,
98 wxColourPickerEventHandler( wxColourPickerCtrlWidget::OnColorChange ) );
100 bbtkDebugMessage("Process",9,"<= wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
101 wxFlexGridSizer *sizer = new wxFlexGridSizer(10);
102 sizer -> AddGrowableRow(0);
103 sizer -> Add( picker, 1, wxEXPAND, 0 );
104 panel -> SetSizer(sizer);
107 wxColourPickerCtrlWidget::~wxColourPickerCtrlWidget()
112 //---------------------------------------------------------------------
113 void wxColourPickerCtrlWidget::OnColorChange(wxColourPickerEvent& e)
119 //---------------------------------------------------------------------
120 void wxColourPickerCtrlWidget::UpdateBox()
123 wxColour c = picker->GetColour();
124 sprintf(col,"%f %f %f",c.Red()/255.,c.Green()/255.,c.Blue()/255.);
126 // std::cout << col << std::endl;
128 ColourSelectorButton* b = (ColourSelectorButton*)mBox;
129 b->bbSetOutputOut( col );
130 b->bbSignalOutputModification("Out");
133 //--------------------------------------------------------------------------
134 //-------------------------------------------------------------------------
135 // WxBlackBox implementation
136 //--------------------------------------------------------------------------
137 //--------------------------------------------------------------------------
139 //--------------------------------------------------------------------------
141 BBTK_BLACK_BOX_IMPLEMENTATION(ColourSelectorButton,bbtk::WxBlackBox);
142 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ColourSelectorButton);
144 //-----------------------------------------------------------------
145 void ColourSelectorButton::bbUserSetDefaultValues()
147 // Default input value
148 bbSetInputIn("1 1 1");
149 // Initial output value = the same than input
150 bbSetOutputOut("1 1 1");
151 // IMPORTANT : Initialize output widget to null pointer to test it after
152 bbSetOutputWidget(0);
155 //-----------------------------------------------------------------
156 void ColourSelectorButton::bbUserInitializeProcessing()
160 //-----------------------------------------------------------------
161 void ColourSelectorButton::bbUserFinalizeProcessing()
165 void ColourSelectorButton::Process()
168 // The widget may not be created : have to test it before using it
169 wxColourPickerCtrlWidget* w = ( wxColourPickerCtrlWidget* )bbGetOutputWidget();
176 // If widget does not exist yet you have to update the output value according
177 // to the input (which may have changed if the user set it)
178 bbSetOutputOut(bbGetInputIn());
186 * \brief Create wxWidget .
190 void ColourSelectorButton::CreateWidget(wxWindow* parent)
194 sscanf( bbGetInputIn().c_str(), "%f %f %f", &r, &g ,&b);
195 unsigned char cr,cg,cb;
196 cr = (unsigned char)(255.*r);
197 cg = (unsigned char)(255.*g);
198 cb = (unsigned char)(255.*b);
200 wxColourPickerCtrlWidget* w = new wxColourPickerCtrlWidget(this, //bbGetWxParent() ,
204 bbSetOutputWidget( w );
205 bbSetOutputOut(bbGetInputIn());
211 #endif // _USE_WXWIDGETS_