Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

ControlGroup.H

Go to the documentation of this file.
00001 
00015 #ifndef _CONTROLS_H
00016 #define _CONTROLS_H
00017 
00018 #include <map>
00019 #include <string>
00020 #include <algorithm>
00021 #include <KeyBoard.H>
00022 #include <xstl.H>
00023 #include <gluifVectorSpinner.H>
00024 
00025 
00026 namespace xchen
00027 {
00028   class UI :: ControlGroup
00029   {
00030       struct ctrl_vec_info 
00031       {
00032           ctrl_vec_info() { }
00033           ctrl_vec_info(KeyValue k, const fVector& v, const fVector& m, const fVector& M);
00034           KeyValue hotkey; 
00035           CtrlVector val, min, max;         
00036           CtrlVector* normalized_val;
00037           int actual_vec_sz; 
00038       };
00039       enum { max_ctrls_per_grp = 10000 };
00040       static vector<ControlGroup*> ctrlgrps;
00041 
00042   public:
00043       static  void ctrl_keyboard_cb(ConvertedKeyValue ctrl_id, int, int);        
00044       static  void bctrl_keyboard_cb(ConvertedKeyValue ctrl_id, int, int);  
00045       
00046   public:
00047       ControlGroup() : grp_id(ctrlgrps.size()) { ctrlgrps.push_back(this); }
00048       ~ControlGroup();
00049       
00050       ControlID AddControl(const string& name, const string& ext_name, KeyValue k, const fVector& val, const fVector& min , const fVector& max);
00051       
00052       CtrlVector& Control(const string& nm);
00053 
00054   private:
00055       int grp_id;
00056       vector<string> names;
00057       vector<string> ext_names;   // more detail of the name, not used for indexing.
00058       map< string, ctrl_vec_info, less<string> > ctrls;
00059       bool hasControl(const string& name) const                  { return findInVector(name, names) != names.end(); }
00060 
00061       static ControlGroup* GetControlGroup(ControlID id)         { return ctrlgrps[id / max_ctrls_per_grp]; }
00062   };
00063 
00064 
00065 
00066   inline void UI :: ControlGroup :: ctrl_keyboard_cb(ConvertedKeyValue ctrl_id, int x, int y)    
00067   { 
00068     ControlGroup* ctrlgrp = GetControlGroup(ctrl_id);
00069     const string& name = ctrlgrp->names[ ctrl_id % max_ctrls_per_grp ];
00070     ctrl_vec_info & info = ctrlgrp->ctrls[ ctrlgrp->names[ ctrl_id % max_ctrls_per_grp ] ];
00071     sp->Bind( name + ctrlgrp->ext_names[ ctrl_id % max_ctrls_per_grp ], 
00072               info.normalized_val? info.normalized_val->GetData() : info.val.GetData(), info.actual_vec_sz ); 
00073   }
00074 
00075   inline void UI :: ControlGroup::bctrl_keyboard_cb(ConvertedKeyValue ctrl_id, int x, int y)
00076   {
00077     ControlGroup* ctrlgrp = (ControlGroup*) ControlGroup::GetControlGroup( ctrl_id );
00078     CtrlVector& v = ctrlgrp->ctrls[ctrlgrp->names[ ctrl_id % max_ctrls_per_grp ]].val;
00079     v[0] = 1 - v[0];
00080   }
00081 
00082 }
00083 
00084 #endif
00085 
00086                                                                             

Generated on Wed Apr 7 21:40:49 2004 by doxygen1.2.18