Wednesday, December 10, 2014

Example CEGUI Slider event registration handler class used in a Ogre3D application


 #ifndef __FreqAmpOctEventReg_CPP  

 #define __FreqAmpOctEventReg_CPP
 //#include "PerlinTest.cpp"
 #include <iostream>
 #include <string>
 #include <sstream>
 #include <CEGUI/CEGUI.h>
 //#include <CEGUISchemeManager.h>
 #include <CEGUI/RendererModules/Ogre/Renderer.h>
 #include "BaseApplication.h"
 class FreqAmpOctEventReg{
      public:
           FreqAmpOctEventReg(void);
           void updateF(const CEGUI::EventArgs &e);
           void updateA(const CEGUI::EventArgs &e);
           void updateO(const CEGUI::EventArgs &e);
      private:
           CEGUI::Window *cnewWindow;
           CEGUI::Window *Frequencyslider;
           CEGUI::Window *Amplitudeslider;
           CEGUI::Window *Octavesslider;
 };
 FreqAmpOctEventReg::FreqAmpOctEventReg(){
      cnewWindow = CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow()->getChild("DemoWindow");
      Frequencyslider = cnewWindow ->getChild("FrequencySlider");
      Amplitudeslider = cnewWindow ->getChild("AmplitudeSlider");
      Octavesslider = cnewWindow ->getChild("OctavesSlider");
      Frequencyslider->subscribeEvent(CEGUI::Slider::EventValueChanged, CEGUI::Event::Subscriber(&FreqAmpOctEventReg::updateF, this));
      Amplitudeslider->subscribeEvent(CEGUI::Slider::EventValueChanged, CEGUI::Event::Subscriber(&FreqAmpOctEventReg::updateA, this));
      Octavesslider->subscribeEvent(CEGUI::Slider::EventValueChanged, CEGUI::Event::Subscriber(&FreqAmpOctEventReg::updateO, this));
 }
 void FreqAmpOctEventReg::updateF(const CEGUI::EventArgs &e){
      CEGUI::Window* flabel = cnewWindow ->getChild("Freqlabel");
      CEGUI::Slider* FSlider = static_cast<CEGUI::Slider*>(Frequencyslider);
      float val = FSlider->getCurrentValue();
      std::ostringstream ss5;
      ss5<<val;
      flabel->setText(ss5.str());
 }
 void FreqAmpOctEventReg::updateA(const CEGUI::EventArgs &e){
      CEGUI::Window* alabel = cnewWindow ->getChild("Amplabel");
      CEGUI::Slider* ASlider = static_cast<CEGUI::Slider*>(Amplitudeslider);
      float val = ASlider->getCurrentValue();
      std::ostringstream ss5;
      ss5<<val;
      alabel->setText(ss5.str());
 }
 void FreqAmpOctEventReg::updateO(const CEGUI::EventArgs &e){
      CEGUI::Window* olabel = cnewWindow ->getChild("Octaveslabel");
      CEGUI::Slider* OSlider = static_cast<CEGUI::Slider*>(Octavesslider);
      float val = OSlider->getCurrentValue();
      std::ostringstream ss5;
      ss5<<val;
      olabel->setText(ss5.str());
 }
 #endif

This is an example CEGUI::Slider class events registration handler.

Watch out for the object state change handler type for sliders I used
CEGUI::Slider::EventValueChanged

or check the documentation for the given CEGUI window object type.

Also I found that it were important to do a static_cast call  to convert from a CEGUI::Window object to CEGUI::Slider object here.  Not sure if there is a faster quicker way to do this, but it appears for now likely one would call the slider child window from its given parent window, and then having the child window converting this to the appropriate CEGUI type object, that is, in order to use specific method calls pertinent to such object.



No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...