1 /*=========================================================================
3 Module: $RCSfile: bbwxColourSelectorButton.cxx,v $
5 Date: $Date: 2008/11/25 13:01:32 $
6 Version: $Revision: 1.8 $
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"
49 //-------------------------------------------------------------------------
50 wxColourPickerCtrlWidget::wxColourPickerCtrlWidget( ColourSelectorButton* box,
56 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
59 bbtkDebugMessage("Process",9,"=> wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
61 wxPanel * panel = this;
62 picker = new wxColourPickerCtrl(panel,-1,
68 picker->SetPickerCtrlGrowable(false);
69 picker->SetTextCtrlGrowable(false);
71 Connect ( picker->GetId(),
72 wxEVT_COMMAND_COLOURPICKER_CHANGED,
73 wxColourPickerEventHandler( wxColourPickerCtrlWidget::OnColorChange ) );
75 bbtkDebugMessage("Process",9,"<= wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
76 wxFlexGridSizer *sizer = new wxFlexGridSizer(10);
77 sizer -> AddGrowableRow(0);
78 sizer -> Add( picker, 1, wxEXPAND, 0 );
79 panel -> SetSizer(sizer);
82 wxColourPickerCtrlWidget::~wxColourPickerCtrlWidget()
87 //---------------------------------------------------------------------
88 void wxColourPickerCtrlWidget::OnColorChange(wxColourPickerEvent& e)
94 //---------------------------------------------------------------------
95 void wxColourPickerCtrlWidget::UpdateBox()
98 wxColour c = picker->GetColour();
99 sprintf(col,"%f %f %f",c.Red()/255.,c.Green()/255.,c.Blue()/255.);
101 // std::cout << col << std::endl;
103 ColourSelectorButton* b = (ColourSelectorButton*)mBox;
104 b->bbSetOutputOut( col );
105 b->bbSignalOutputModification("Out");
108 //--------------------------------------------------------------------------
109 //-------------------------------------------------------------------------
110 // WxBlackBox implementation
111 //--------------------------------------------------------------------------
112 //--------------------------------------------------------------------------
114 //--------------------------------------------------------------------------
116 BBTK_BLACK_BOX_IMPLEMENTATION(ColourSelectorButton,bbtk::WxBlackBox);
117 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ColourSelectorButton);
119 void ColourSelectorButton::bbUserConstructor()
121 // Default input value
122 bbSetInputIn("1 1 1");
123 // Initial output value = the same than input
124 bbSetOutputOut("1 1 1");
125 // IMPORTANT : Initialize output widget to null pointer to test it after
126 bbSetOutputWidget(0);
130 void ColourSelectorButton::Process()
132 // The widget may not be created : have to test it before using it
133 wxColourPickerCtrlWidget* w = ( wxColourPickerCtrlWidget* )bbGetOutputWidget();
140 // If widget does not exist yet you have to update the output value according
141 // to the input (which may have changed if the user set it)
142 bbSetOutputOut(bbGetInputIn());
148 * \brief Create wxWidget .
152 void ColourSelectorButton::CreateWidget(wxWindow* parent)
156 sscanf( bbGetInputIn().c_str(), "%f %f %f", &r, &g ,&b);
157 unsigned char cr,cg,cb;
158 cr = (unsigned char)(255.*r);
159 cg = (unsigned char)(255.*g);
160 cb = (unsigned char)(255.*b);
162 wxColourPickerCtrlWidget* w = new wxColourPickerCtrlWidget(this, //bbGetWxParent() ,
166 bbSetOutputWidget( w );
172 #endif // _USE_WXWIDGETS_