X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=samples%2FSampleOutputObserver%2FbbtkSampleOutputObserver.cxx;fp=samples%2FSampleOutputObserver%2FbbtkSampleOutputObserver.cxx;h=71ccbd8975b216473a18b3be332ae95993edfb84;hb=e86c3848d48592893231e57fbf513d5d666be0ca;hp=67c40751fd24d000d21ef9be7e7214bcefa1a51c;hpb=a12deb460d12294cc8f3ef4e489b5b28640d0178;p=bbtk.git diff --git a/samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx b/samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx index 67c4075..71ccbd8 100644 --- a/samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx +++ b/samples/SampleOutputObserver/bbtkSampleOutputObserver.cxx @@ -6,12 +6,15 @@ //========================================================================= //========================================================================= -void CallbackFunction ( bbtk::BlackBox::Pointer p, - const std::string& o, - bbtk::IOStatus s) +// FIRST EXAMPLE USING A FUNCTION AS CALLBACK +void CallbackFunction ( bbtk::BlackBox::Pointer p, // The black box which changed + const std::string& o, // The output which changed + bbtk::IOStatus s) // The new status of the output { std::cout << "== Callback function called with p="<bbGetName() <<" o="<bbSetInputWinDialog(true); // mandatory + // Add the observer slider->bbAddOutputObserver( "Out", &CallbackFunction ); slider->bbExecute(); } @@ -42,6 +46,7 @@ void SliderCallback() //========================================================================= +// SECOND EXAMPLE : MEMBER METHOD CALLED WHEN SLIDER IS RELEASED class ClassWithTwoSliders { public: @@ -66,6 +71,9 @@ ClassWithTwoSliders::ClassWithTwoSliders() try { mSlider1 = bbwx::Slider::New("slider1"); + // Add the observer method + // As it is not a FREEHAND function we must use the macro + // BBTK_MAKE_OUTPUT_OBSERVER which takes the object and the method to call mSlider1->bbAddOutputObserver("Out", BBTK_MAKE_OUTPUT_OBSERVER (this,