1 /*=========================================================================
3 Module: $RCSfile: bbwxColourSelectorButton.cxx,v $
5 Date: $Date: 2009/05/15 14:58:03 $
6 Version: $Revision: 1.10 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Short description in one line
40 #ifdef _USE_WXWIDGETS_
42 #include "bbwxColourSelectorButton.h"
43 #include "bbwxPackage.h"
45 #include <wx/clrpicker.h>
49 //-------------------------------------------------------------------------
50 class wxColourPickerCtrlWidget :public wxPanel
54 wxColourPickerCtrlWidget( ColourSelectorButton* box,
60 ~wxColourPickerCtrlWidget();
61 void OnColorChange(wxColourPickerEvent& e);
64 wxColourPickerCtrl *picker;
65 ColourSelectorButton *mBox;
67 //-------------------------------------------------------------------------
69 //-------------------------------------------------------------------------
70 wxColourPickerCtrlWidget::wxColourPickerCtrlWidget( ColourSelectorButton* box,
76 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
79 bbtkDebugMessage("Process",9,"=> wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
81 wxPanel * panel = this;
82 picker = new wxColourPickerCtrl(panel,-1,
88 picker->SetPickerCtrlGrowable(false);
89 picker->SetTextCtrlGrowable(false);
91 Connect ( picker->GetId(),
92 wxEVT_COMMAND_COLOURPICKER_CHANGED,
93 wxColourPickerEventHandler( wxColourPickerCtrlWidget::OnColorChange ) );
95 bbtkDebugMessage("Process",9,"<= wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
96 wxFlexGridSizer *sizer = new wxFlexGridSizer(10);
97 sizer -> AddGrowableRow(0);
98 sizer -> Add( picker, 1, wxEXPAND, 0 );
99 panel -> SetSizer(sizer);
102 wxColourPickerCtrlWidget::~wxColourPickerCtrlWidget()
107 //---------------------------------------------------------------------
108 void wxColourPickerCtrlWidget::OnColorChange(wxColourPickerEvent& e)
114 //---------------------------------------------------------------------
115 void wxColourPickerCtrlWidget::UpdateBox()
118 wxColour c = picker->GetColour();
119 sprintf(col,"%f %f %f",c.Red()/255.,c.Green()/255.,c.Blue()/255.);
121 // std::cout << col << std::endl;
123 ColourSelectorButton* b = (ColourSelectorButton*)mBox;
124 b->bbSetOutputOut( col );
125 b->bbSignalOutputModification("Out");
128 //--------------------------------------------------------------------------
129 //-------------------------------------------------------------------------
130 // WxBlackBox implementation
131 //--------------------------------------------------------------------------
132 //--------------------------------------------------------------------------
134 //--------------------------------------------------------------------------
136 BBTK_BLACK_BOX_IMPLEMENTATION(ColourSelectorButton,bbtk::WxBlackBox);
137 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ColourSelectorButton);
139 //-----------------------------------------------------------------
140 void ColourSelectorButton::bbUserSetDefaultValues()
142 // Default input value
143 bbSetInputIn("1 1 1");
144 // Initial output value = the same than input
145 bbSetOutputOut("1 1 1");
146 // IMPORTANT : Initialize output widget to null pointer to test it after
147 bbSetOutputWidget(0);
150 //-----------------------------------------------------------------
151 void ColourSelectorButton::bbUserInitializeProcessing()
155 //-----------------------------------------------------------------
156 void ColourSelectorButton::bbUserFinalizeProcessing()
160 void ColourSelectorButton::Process()
162 // The widget may not be created : have to test it before using it
163 wxColourPickerCtrlWidget* w = ( wxColourPickerCtrlWidget* )bbGetOutputWidget();
170 // If widget does not exist yet you have to update the output value according
171 // to the input (which may have changed if the user set it)
172 bbSetOutputOut(bbGetInputIn());
178 * \brief Create wxWidget .
182 void ColourSelectorButton::CreateWidget(wxWindow* parent)
186 sscanf( bbGetInputIn().c_str(), "%f %f %f", &r, &g ,&b);
187 unsigned char cr,cg,cb;
188 cr = (unsigned char)(255.*r);
189 cg = (unsigned char)(255.*g);
190 cb = (unsigned char)(255.*b);
192 wxColourPickerCtrlWidget* w = new wxColourPickerCtrlWidget(this, //bbGetWxParent() ,
196 bbSetOutputWidget( w );
202 #endif // _USE_WXWIDGETS_