Browse Source

anttweakbar namespace

Former-commit-id: 83c77cbb5d749ef165198d1d45d0b1cbe5497ac4
Alec Jacobson 10 years ago
parent
commit
76c8fb8871

+ 36 - 24
include/igl/anttweakbar/ReAntTweakBar.cpp

@@ -17,10 +17,12 @@
 // GLOBAL WRAPPERS
 namespace 
 {
-  std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > > ReTw_custom_types;
+  std::map<
+    TwType,std::pair<const char *,std::vector<TwEnumVal> > 
+    > ReTw_custom_types;
 }
 
-IGL_INLINE TwType igl::ReTwDefineEnum(
+IGL_INLINE TwType igl::anttweakbar::ReTwDefineEnum(
   const char *name, 
   const TwEnumVal *enumValues, 
   unsigned int nbValues)
@@ -41,7 +43,7 @@ IGL_INLINE TwType igl::ReTwDefineEnum(
   return type;
 }
 
-IGL_INLINE TwType igl::ReTwDefineEnumFromString(
+IGL_INLINE TwType igl::anttweakbar::ReTwDefineEnumFromString(
   const char * _Name,
   const char * _EnumString)
 {
@@ -81,7 +83,10 @@ IGL_INLINE TwType igl::ReTwDefineEnumFromString(
         Vals[i].Label = c_label;
     }
 
-    const TwType type = ReTwDefineEnum(_Name, Vals.empty() ? NULL : &(Vals[0]), (unsigned int)Vals.size());
+    const TwType type = 
+      ReTwDefineEnum(_Name, Vals.empty() ? 
+        NULL : 
+        &(Vals[0]), (unsigned int)Vals.size());
     return type;
   }
 }
@@ -123,14 +128,15 @@ namespace
   };
 }
 
-IGL_INLINE igl::ReTwBar::ReTwBar():
+IGL_INLINE igl::anttweakbar::ReTwBar::ReTwBar():
  bar(NULL),
   name(),
   rw_items(),cb_items()
 {
 }
 
-IGL_INLINE igl::ReTwBar::ReTwBar(const igl::ReTwBar & that):
+IGL_INLINE igl::anttweakbar::ReTwBar::ReTwBar(
+    const igl::anttweakbar::ReTwBar & that):
   bar(that.bar),
   name(that.name),
   rw_items(that.rw_items),
@@ -138,7 +144,8 @@ IGL_INLINE igl::ReTwBar::ReTwBar(const igl::ReTwBar & that):
 {
 }
 
-IGL_INLINE igl::ReTwBar & igl::ReTwBar::operator=(const igl::ReTwBar & that)
+IGL_INLINE igl::anttweakbar::ReTwBar & 
+igl::anttweakbar::ReTwBar::operator=(const igl::anttweakbar::ReTwBar & that)
 {
   // check for self assignment
   if(this != &that)
@@ -152,7 +159,7 @@ IGL_INLINE igl::ReTwBar & igl::ReTwBar::operator=(const igl::ReTwBar & that)
 
 
 // BAR WRAPPERS
-IGL_INLINE void igl::ReTwBar::TwNewBar(const char * _name)
+IGL_INLINE void igl::anttweakbar::ReTwBar::TwNewBar(const char * _name)
 {
   this->bar = ::TwNewBar(_name);
   // Alec: This causes trouble (not sure why) in multiple applications
@@ -162,7 +169,7 @@ IGL_INLINE void igl::ReTwBar::TwNewBar(const char * _name)
   //this->name = "foobar";
 }
 
-IGL_INLINE int igl::ReTwBar::TwAddVarRW(
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwAddVarRW(
   const char *name, 
   TwType type, 
   void *var, 
@@ -177,7 +184,7 @@ IGL_INLINE int igl::ReTwBar::TwAddVarRW(
   return ret;
 }
 
-IGL_INLINE int igl::ReTwBar::TwAddVarCB(
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwAddVarCB(
   const char *name, 
   TwType type, 
   TwSetVarCallback setCallback, 
@@ -195,7 +202,7 @@ IGL_INLINE int igl::ReTwBar::TwAddVarCB(
   return ret;
 }
 
-IGL_INLINE int igl::ReTwBar::TwAddVarRO(
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwAddVarRO(
   const char *name, 
   TwType type, 
   void *var, 
@@ -210,7 +217,7 @@ IGL_INLINE int igl::ReTwBar::TwAddVarRO(
   return ret;
 }
 
-IGL_INLINE int igl::ReTwBar::TwAddButton(
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwAddButton(
   const char *name, 
   TwButtonCallback buttonCallback, 
   void *clientData, 
@@ -226,7 +233,7 @@ IGL_INLINE int igl::ReTwBar::TwAddButton(
   return ret;
 }
 
-IGL_INLINE int igl::ReTwBar::TwSetParam(
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwSetParam(
   const char *varName, 
   const char *paramName, 
   TwParamValueType paramValueType, 
@@ -244,7 +251,7 @@ IGL_INLINE int igl::ReTwBar::TwSetParam(
       inValues);
 }
 
-IGL_INLINE int igl::ReTwBar::TwGetParam(
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwGetParam(
   const char *varName, 
   const char *paramName, 
   TwParamValueType paramValueType, 
@@ -261,12 +268,12 @@ IGL_INLINE int igl::ReTwBar::TwGetParam(
       outValues);
 }
 
-IGL_INLINE int igl::ReTwBar::TwRefreshBar()
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwRefreshBar()
 {
   return ::TwRefreshBar(this->bar);
 }
 
-IGL_INLINE int igl::ReTwBar::TwTerminate()
+IGL_INLINE int igl::anttweakbar::ReTwBar::TwTerminate()
 {
   //std::cout<<"TwTerminate"<<std::endl;
   int r = ::TwTerminate();
@@ -274,7 +281,7 @@ IGL_INLINE int igl::ReTwBar::TwTerminate()
   return r;
 }
 
-IGL_INLINE bool igl::ReTwBar::save(const char *file_name)
+IGL_INLINE bool igl::anttweakbar::ReTwBar::save(const char *file_name)
 {
   FILE * fp;
   if(file_name == NULL)
@@ -337,7 +344,7 @@ IGL_INLINE bool igl::ReTwBar::save(const char *file_name)
   return true;
 }
 
-IGL_INLINE std::string igl::ReTwBar::get_value_as_string(
+IGL_INLINE std::string igl::anttweakbar::ReTwBar::get_value_as_string(
   void * var, 
   TwType type)
 {
@@ -475,7 +482,7 @@ IGL_INLINE std::string igl::ReTwBar::get_value_as_string(
   return sstr.str();
 }
 
-IGL_INLINE bool igl::ReTwBar::load(const char *file_name)
+IGL_INLINE bool igl::anttweakbar::ReTwBar::load(const char *file_name)
 {
   FILE * fp;
   fp = fopen(file_name,"r");
@@ -536,7 +543,8 @@ IGL_INLINE bool igl::ReTwBar::load(const char *file_name)
   return true;
 }
 
-IGL_INLINE bool igl::ReTwBar::type_from_string(const char *type_str, TwType & type)
+IGL_INLINE bool igl::anttweakbar::ReTwBar::type_from_string(
+  const char *type_str, TwType & type)
 {
   // first check default types
   for(int j = 0; j < RETW_NUM_DEFAULT_TYPE_STRINGS; j++)
@@ -550,7 +558,9 @@ IGL_INLINE bool igl::ReTwBar::type_from_string(const char *type_str, TwType & ty
   }
 
   // then check custom types
-  std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::const_iterator iter = 
+  std::map<
+    TwType,std::pair<const char *,std::vector<TwEnumVal> > 
+    >::const_iterator iter = 
     ReTw_custom_types.begin();
   for(;iter != ReTw_custom_types.end(); iter++)
   {
@@ -563,7 +573,7 @@ IGL_INLINE bool igl::ReTwBar::type_from_string(const char *type_str, TwType & ty
   return false;
 }
 
-bool igl::ReTwBar::set_value_from_string(
+bool igl::anttweakbar::ReTwBar::set_value_from_string(
   const char * name, 
   TwType type, 
   const char * value_str)
@@ -911,12 +921,14 @@ bool igl::ReTwBar::set_value_from_string(
   return true;
 }
 
-IGL_INLINE const std::vector<igl::ReTwRWItem> & igl::ReTwBar::get_rw_items()
+IGL_INLINE const std::vector<igl::anttweakbar::ReTwRWItem> & 
+  igl::anttweakbar::ReTwBar::get_rw_items()
 {
   return rw_items;
 }
 
-IGL_INLINE const std::vector<igl::ReTwCBItem> & igl::ReTwBar::get_cb_items()
+IGL_INLINE const std::vector<igl::anttweakbar::ReTwCBItem> & 
+  igl::anttweakbar::ReTwBar::get_cb_items()
 {
   return cb_items;
 }

+ 185 - 182
include/igl/anttweakbar/ReAntTweakBar.h

@@ -60,196 +60,199 @@
 
 namespace igl
 {
-  TwType ReTwDefineEnum(
-    const char *name, 
-    const TwEnumVal *enumValues, 
-    unsigned int nbValues);
-  TwType ReTwDefineEnumFromString(const char * name,const char * enumString);
-  
-  struct ReTwRWItem
+  namespace anttweakbar
   {
-    //const char * name;
-    std::string name;
-    TwType type;
-    void * var;
-    // Default constructor
-    IGL_INLINE ReTwRWItem(
-      const std::string _name,
-      TwType _type, 
-      void *_var):
-      name(_name),
-      type(_type),
-      var(_var)
-    {
-    }
-    // Shallow copy constructor
-    // I solemnly swear it's OK to copy var this way
-    // Q: Is it really?
-    IGL_INLINE ReTwRWItem(const ReTwRWItem & that):
-      name(that.name),
-      type(that.type),
-      var(that.var)
-    {
-    }
-    // Shallow assignment 
-    // I solemnly swear it's OK to copy var this way
-    IGL_INLINE ReTwRWItem & operator=(const ReTwRWItem & that)
+    TwType ReTwDefineEnum(
+      const char *name, 
+      const TwEnumVal *enumValues, 
+      unsigned int nbValues);
+    TwType ReTwDefineEnumFromString(const char * name,const char * enumString);
+    
+    struct ReTwRWItem
     {
-      if(this != &that)
+      //const char * name;
+      std::string name;
+      TwType type;
+      void * var;
+      // Default constructor
+      IGL_INLINE ReTwRWItem(
+        const std::string _name,
+        TwType _type, 
+        void *_var):
+        name(_name),
+        type(_type),
+        var(_var)
       {
-        this->name = that.name;
-        this->type = that.type;
-        this->var = that.var;
       }
-      return *this;
-    }
-  };
-  
-  struct ReTwCBItem
-  {
-    //const char * name;
-    std::string name;
-    TwType type;
-    TwSetVarCallback setCallback;
-    TwGetVarCallback getCallback;
-    void * clientData;
-    // Default constructor
-    IGL_INLINE ReTwCBItem(
-      const std::string _name,
-      TwType _type, 
-      TwSetVarCallback _setCallback,
-      TwGetVarCallback _getCallback,
-      void * _clientData):
-      name(_name),
-      type(_type),
-      setCallback(_setCallback),
-      getCallback(_getCallback),
-      clientData(_clientData)
-    {
-    }
-    // Shallow copy
-    // I solemnly swear it's OK to copy clientData this way
-    IGL_INLINE ReTwCBItem(const ReTwCBItem & that):
-      name(that.name),
-      type(that.type),
-      setCallback(that.setCallback),
-      getCallback(that.getCallback),
-      clientData(that.clientData)
-    {
-    }
-    // Shallow assignment
-    // I solemnly swear it's OK to copy clientData this way
-    IGL_INLINE ReTwCBItem & operator=(const ReTwCBItem & that)
-    {
-      if(this != &that)
+      // Shallow copy constructor
+      // I solemnly swear it's OK to copy var this way
+      // Q: Is it really?
+      IGL_INLINE ReTwRWItem(const ReTwRWItem & that):
+        name(that.name),
+        type(that.type),
+        var(that.var)
       {
-        name = that.name;
-        type = that.type;
-        setCallback = that.setCallback;
-        getCallback = that.getCallback;
-        clientData = that.clientData;
       }
-      return *this;
-    }
-
-  };
-  
-  class ReTwBar
-  {
-    // VARIABLES
-    // Should be private, but seeing as I'm not going to implement all of the
-    // AntTweakBar public functions right away, I'll expose this so that at
-    // anytime AntTweakBar functions can be called directly on the bar
-    public:
-      TwBar * bar;
+      // Shallow assignment 
+      // I solemnly swear it's OK to copy var this way
+      IGL_INLINE ReTwRWItem & operator=(const ReTwRWItem & that)
+      {
+        if(this != &that)
+        {
+          this->name = that.name;
+          this->type = that.type;
+          this->var = that.var;
+        }
+        return *this;
+      }
+    };
+    
+    struct ReTwCBItem
+    {
+      //const char * name;
       std::string name;
-    protected:
-      std::vector<ReTwRWItem> rw_items;
-      std::vector<ReTwCBItem> cb_items;
-    public:
-      // Default constructor with explicit initialization
-      IGL_INLINE ReTwBar();
-    private:
-      // Copy constructor does shallow copy
-      IGL_INLINE ReTwBar(const ReTwBar & that);
-      // Assignment operator does shallow assignment
-      IGL_INLINE ReTwBar &operator=(const ReTwBar & that);
-  
-    // WRAPPERS FOR ANTTWEAKBAR FUNCTIONS 
-    public:
-      IGL_INLINE void TwNewBar(const char *_name);
-      IGL_INLINE int TwAddVarRW(
-        const char *name, 
-        TwType type, 
-        void *var, 
-        const char *def,
-        const bool record=true);
-      IGL_INLINE int TwAddVarCB(
-        const char *name, 
-        TwType type, 
-        TwSetVarCallback setCallback, 
-        TwGetVarCallback getCallback, 
-        void *clientData, 
-        const char *def,
-        const bool record=true);
-      // Wrappers for convenience (not recorded, just passed on)
-      IGL_INLINE int TwAddVarRO(const char *name, TwType type, void *var, const char *def);
-      IGL_INLINE int TwAddButton(
-        const char *name, 
-        TwButtonCallback buttonCallback, 
-        void *clientData, 
-        const char *def);
-      IGL_INLINE int TwSetParam(
-        const char *varName, 
-        const char *paramName, 
-        TwParamValueType paramValueType, 
-        unsigned int inValueCount, 
-        const void *inValues);
-      IGL_INLINE int TwGetParam(
-        const char *varName, 
-        const char *paramName, 
-        TwParamValueType paramValueType, 
-        unsigned int outValueMaxCount, 
-        void *outValues);
-      IGL_INLINE int TwRefreshBar();
-      IGL_INLINE int TwTerminate();
-  
+      TwType type;
+      TwSetVarCallback setCallback;
+      TwGetVarCallback getCallback;
+      void * clientData;
+      // Default constructor
+      IGL_INLINE ReTwCBItem(
+        const std::string _name,
+        TwType _type, 
+        TwSetVarCallback _setCallback,
+        TwGetVarCallback _getCallback,
+        void * _clientData):
+        name(_name),
+        type(_type),
+        setCallback(_setCallback),
+        getCallback(_getCallback),
+        clientData(_clientData)
+      {
+      }
+      // Shallow copy
+      // I solemnly swear it's OK to copy clientData this way
+      IGL_INLINE ReTwCBItem(const ReTwCBItem & that):
+        name(that.name),
+        type(that.type),
+        setCallback(that.setCallback),
+        getCallback(that.getCallback),
+        clientData(that.clientData)
+      {
+      }
+      // Shallow assignment
+      // I solemnly swear it's OK to copy clientData this way
+      IGL_INLINE ReTwCBItem & operator=(const ReTwCBItem & that)
+      {
+        if(this != &that)
+        {
+          name = that.name;
+          type = that.type;
+          setCallback = that.setCallback;
+          getCallback = that.getCallback;
+          clientData = that.clientData;
+        }
+        return *this;
+      }
   
-    // IO FUNCTIONS
-    public:
-      // Save current items to file
-      // Input:
-      //   file_name  name of file to save data to, can be null which means print
-      //   to stdout
-      // Return:
-      //   true only if there were no (fatal) errors
-      IGL_INLINE bool save(const char *file_name);
-      std::string get_value_as_string(
-        void * var, 
-        TwType type);
-      // Load into current items from file
-      // Input:
-      //   file_name  name of input file to load
-      // Return:
-      //   true only if there were no (fatal) errors
-      IGL_INLINE bool load(const char *file_name);
-      // Get TwType from string
-      // Input
-      //   type_str  string of type 
-      // Output
-      //   type  TwType converted from string
-      // Returns
-      //   true only if string matched a valid type
-      IGL_INLINE bool type_from_string(const char *type_str, TwType & type);
-      // I realize that I mix std::string and const char * all over the place.
-      // What can you do...
-      IGL_INLINE bool set_value_from_string(
-        const char * name, 
-        TwType type, 
-        const char * value_str);
-      IGL_INLINE const std::vector<ReTwRWItem> & get_rw_items();
-      IGL_INLINE const std::vector<ReTwCBItem> & get_cb_items();
-  };
+    };
+    
+    class ReTwBar
+    {
+      // VARIABLES
+      // Should be private, but seeing as I'm not going to implement all of the
+      // AntTweakBar public functions right away, I'll expose this so that at
+      // anytime AntTweakBar functions can be called directly on the bar
+      public:
+        TwBar * bar;
+        std::string name;
+      protected:
+        std::vector<ReTwRWItem> rw_items;
+        std::vector<ReTwCBItem> cb_items;
+      public:
+        // Default constructor with explicit initialization
+        IGL_INLINE ReTwBar();
+      private:
+        // Copy constructor does shallow copy
+        IGL_INLINE ReTwBar(const ReTwBar & that);
+        // Assignment operator does shallow assignment
+        IGL_INLINE ReTwBar &operator=(const ReTwBar & that);
+    
+      // WRAPPERS FOR ANTTWEAKBAR FUNCTIONS 
+      public:
+        IGL_INLINE void TwNewBar(const char *_name);
+        IGL_INLINE int TwAddVarRW(
+          const char *name, 
+          TwType type, 
+          void *var, 
+          const char *def,
+          const bool record=true);
+        IGL_INLINE int TwAddVarCB(
+          const char *name, 
+          TwType type, 
+          TwSetVarCallback setCallback, 
+          TwGetVarCallback getCallback, 
+          void *clientData, 
+          const char *def,
+          const bool record=true);
+        // Wrappers for convenience (not recorded, just passed on)
+        IGL_INLINE int TwAddVarRO(const char *name, TwType type, void *var, const char *def);
+        IGL_INLINE int TwAddButton(
+          const char *name, 
+          TwButtonCallback buttonCallback, 
+          void *clientData, 
+          const char *def);
+        IGL_INLINE int TwSetParam(
+          const char *varName, 
+          const char *paramName, 
+          TwParamValueType paramValueType, 
+          unsigned int inValueCount, 
+          const void *inValues);
+        IGL_INLINE int TwGetParam(
+          const char *varName, 
+          const char *paramName, 
+          TwParamValueType paramValueType, 
+          unsigned int outValueMaxCount, 
+          void *outValues);
+        IGL_INLINE int TwRefreshBar();
+        IGL_INLINE int TwTerminate();
+    
+    
+      // IO FUNCTIONS
+      public:
+        // Save current items to file
+        // Input:
+        //   file_name  name of file to save data to, can be null which means print
+        //   to stdout
+        // Return:
+        //   true only if there were no (fatal) errors
+        IGL_INLINE bool save(const char *file_name);
+        std::string get_value_as_string(
+          void * var, 
+          TwType type);
+        // Load into current items from file
+        // Input:
+        //   file_name  name of input file to load
+        // Return:
+        //   true only if there were no (fatal) errors
+        IGL_INLINE bool load(const char *file_name);
+        // Get TwType from string
+        // Input
+        //   type_str  string of type 
+        // Output
+        //   type  TwType converted from string
+        // Returns
+        //   true only if string matched a valid type
+        IGL_INLINE bool type_from_string(const char *type_str, TwType & type);
+        // I realize that I mix std::string and const char * all over the place.
+        // What can you do...
+        IGL_INLINE bool set_value_from_string(
+          const char * name, 
+          TwType type, 
+          const char * value_str);
+        IGL_INLINE const std::vector<ReTwRWItem> & get_rw_items();
+        IGL_INLINE const std::vector<ReTwCBItem> & get_cb_items();
+    };
+  }
 }
 
 // List of TwBar functions

+ 1 - 1
include/igl/anttweakbar/cocoa_key_to_anttweakbar_key.cpp

@@ -9,7 +9,7 @@
 
 #include <AntTweakBar.h>
 
-IGL_INLINE int igl::cocoa_key_to_anttweakbar_key(int key)
+IGL_INLINE int igl::anttweakbar::cocoa_key_to_anttweakbar_key(int key)
 {
   // I've left commented the AntTweakBar key codes that correspond to keys I
   // don't have on my keyboard. Please fill this in if you have those keys

+ 10 - 7
include/igl/anttweakbar/cocoa_key_to_anttweakbar_key.h

@@ -12,13 +12,16 @@
 
 namespace igl
 {
-  // Convert an unsigned char (like that from Cocoa apps) to AntTweakBar key
-  // code.
-  // See also: TranslateKey() in TwMgr.cpp in AntTweakBar source
-  // Inputs:
-  //   key  unsigned char key from keyboard
-  // Returns int of new key code 
-  IGL_INLINE int cocoa_key_to_anttweakbar_key(int key);
+  namespace anttweakbar
+  {
+    // Convert an unsigned char (like that from Cocoa apps) to AntTweakBar key
+    // code.
+    // See also: TranslateKey() in TwMgr.cpp in AntTweakBar source
+    // Inputs:
+    //   key  unsigned char key from keyboard
+    // Returns int of new key code 
+    IGL_INLINE int cocoa_key_to_anttweakbar_key(int key);
+  }
 }
 
 #ifndef IGL_STATIC_LIBRARY