]> Creatis software - bbtk.git/blob - samples/SampleInsertWxBlackBoxInOwnFrame/bbtkSampleInsertWxBlackBoxInOwnFrame.cxx
Feature #1774
[bbtk.git] / samples / SampleInsertWxBlackBoxInOwnFrame / bbtkSampleInsertWxBlackBoxInOwnFrame.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 #include <bbwxSlider.h>
29 #include <bbwxLayoutLine.h>
30 #include <creaWx.h>
31 //=========================================================================
32 // Illustrates how to insert a WxBlackBox into his own wxFrame
33 //=========================================================================
34
35 //==========================================================================
36 // A custom wxFrame which own a bbwx::Slider widget
37 class Frame : public wxFrame
38 {
39 public:
40   Frame();
41   // Slider callback
42   void OnSlider( bbtk::BlackBox::Pointer p, const std::string& o,
43                  bbtk::IOStatus s);
44 private:
45   bbwx::Slider::Pointer mSlider;
46   wxStaticText* mText;
47 };
48 //==========================================================================
49
50 //==========================================================================
51 Frame::Frame() :
52   wxFrame((wxFrame *)0, -1, _T("A frame which contains a bbwx::Slider"), 
53           wxDefaultPosition, wxDefaultSize)
54 {
55   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
56
57   //========================================  
58   // 1) Create the WxBlackBox
59   mSlider = bbwx::Slider::New("slider");
60   // 2) Create the widget giving it the parent
61   mSlider->bbUserCreateWidget(this);
62   // 3) Add an observer to process output modifications
63   mSlider->bbAddOutputObserver ( "Out", 
64                                  BBTK_MAKE_OUTPUT_OBSERVER ( this,
65                                                              &Frame::OnSlider ) );
66   // 4) Add the created widget in the sizer
67   sizer->Add(mSlider->bbGetOutputWidget(),1,wxGROW);
68   //=========================================
69   
70   //=========================================
71   // Create the static text as usual
72   mText = new wxStaticText ( this, -1 , _T("") );
73   sizer->Add(mText,1,wxGROW);
74   //=========================================
75
76   SetSizer(sizer);
77   SetAutoLayout(true);
78   Layout();
79 }
80 //==========================================================================
81
82 //==========================================================================
83 void Frame::OnSlider( bbtk::BlackBox::Pointer p, const std::string& o,
84                       bbtk::IOStatus s)
85 {
86   std::cout << "New slider value = " << mSlider->bbGetOutputOut() << std::endl;
87   std::ostringstream val;
88   val << mSlider->bbGetOutputOut();
89   mText->SetLabel( bbtk::std2wx ( val.str() ) );
90 }
91 //==========================================================================
92
93 //==========================================================================
94 class App : public wxApp
95 {
96 public:
97   bool OnInit( );
98   int  OnExit() { return true; }
99 };
100 //==========================================================================
101
102 //==========================================================================
103 // The `main program' equivalent, creating the windows and returning the
104 // main frame
105 bool App::OnInit( )
106 {
107   wxApp::OnInit();
108 #ifdef __WXGTK__
109   //See http://www.wxwindows.org/faqgtk.htm#locale
110   setlocale(LC_NUMERIC, "C");
111 #endif
112   Frame* I = new Frame();
113   I->Show(true);
114   return true;
115 }
116 //=========================================================================
117
118 //=========================================================================
119 IMPLEMENT_APP(App);
120 CREA_WXMAIN_WITH_CONSOLE;
121 //=========================================================================