]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxColourSelectorButton.cxx
9328d6ae5405c86ce1d40c7fa8261d40448fc882
[bbtk.git] / packages / wx / src / bbwxColourSelectorButton.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxColourSelectorButton.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/11/24 15:45:51 $
6   Version:   $Revision: 1.6 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  * \file
33  * \brief Short description in one line
34  *
35  * Long
36  * description
37  *
38  */
39
40 #ifdef _USE_WXWIDGETS_
41
42 #include "bbwxColourSelectorButton.h"
43 #include "bbwxPackage.h"
44
45
46 namespace bbwx
47 {
48
49 //-------------------------------------------------------------------------
50 wxColourPickerCtrlWidget::wxColourPickerCtrlWidget(     ColourSelectorButton* box,
51                                                                                                         wxWindow *parent, 
52                                                                                                         unsigned char  cr,
53                                                                                                         unsigned char  cg,
54                                                                                                         unsigned char  cb
55                                                                                                         )
56   :   wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
57           mBox(box)
58 {
59     bbtkDebugMessage("Process",9,"=> wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
60
61     wxPanel * panel = this;
62     picker = new wxColourPickerCtrl(panel,-1,
63                                         wxColour(cr,cg,cb),
64                                         wxDefaultPosition,
65                                         wxDefaultSize,
66                                         wxCLRP_USE_TEXTCTRL
67                                 );
68     picker->SetPickerCtrlGrowable(false);
69     picker->SetTextCtrlGrowable(false);
70
71     Connect ( picker->GetId(),
72               wxEVT_COMMAND_COLOURPICKER_CHANGED,
73               wxColourPickerEventHandler( wxColourPickerCtrlWidget::OnColorChange ) );
74
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);
80   }
81
82 wxColourPickerCtrlWidget::~wxColourPickerCtrlWidget()
83 {
84 }
85
86
87 //---------------------------------------------------------------------
88 void wxColourPickerCtrlWidget::OnColorChange(wxColourPickerEvent& e)
89 {
90         UpdateBox();
91 }
92
93
94 //---------------------------------------------------------------------
95 void wxColourPickerCtrlWidget::UpdateBox()
96 {
97     char col[100];
98     wxColour c = picker->GetColour();
99     sprintf(col,"%f %f %f",c.Red()/255.,c.Green()/255.,c.Blue()/255.);
100
101     //    std::cout << col << std::endl;
102
103     ColourSelectorButton* b = (ColourSelectorButton*)mBox;
104     b->bbSetOutputOut( col );
105     b->bbSignalOutputModification("Out");
106 }
107
108   //--------------------------------------------------------------------------
109   //-------------------------------------------------------------------------
110   // WxBlackBox implementation
111   //--------------------------------------------------------------------------
112   //--------------------------------------------------------------------------
113
114   //--------------------------------------------------------------------------
115
116   BBTK_BLACK_BOX_IMPLEMENTATION(ColourSelectorButton,bbtk::WxBlackBox);
117   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ColourSelectorButton);
118   
119   void ColourSelectorButton::bbUserConstructor() 
120   { 
121     bbSetInputIn("1 1 1");
122   }
123
124
125   void ColourSelectorButton::Process() 
126   { 
127     bbtkDebugMessageInc("Process",9,"ColourSelectorButton::Process()"<<std::endl);
128       pickerWidget->UpdateBox();
129     bbtkDebugDecTab("Process",9);
130   }
131
132
133   /**
134    * \brief  Create wxWidget .
135    *
136    *
137    */
138   void ColourSelectorButton::CreateWidget(wxWindow* parent)
139   {
140     bbtkDebugMessage("Process",9,"=> ColourSelectorButton::CreateWidget()"<<std::endl);
141     
142     float r,g,b;
143     sscanf( bbGetInputIn().c_str(), "%f %f %f", &r, &g ,&b);
144     unsigned char cr,cg,cb;
145     cr = (unsigned char)(255.*r);
146     cg = (unsigned char)(255.*g);
147     cb = (unsigned char)(255.*b);
148
149     pickerWidget = new wxColourPickerCtrlWidget(this, //bbGetWxParent() , 
150                                                                                                 parent,
151                                                                                                 cr , cg , cb );    
152     
153     bbtkDebugMessage("Process",9,"<= ColourSelectorButton::CreateWidget()"<<std::endl);
154
155     bbSetOutputWidget( pickerWidget );
156   }
157
158
159 }  //namespace bbwx
160
161 #endif  // _USE_WXWIDGETS_
162