Revision: 1413
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1413&view=rev
Author:   rorthomas
Date:     2010-06-23 02:30:18 +0000 (Wed, 23 Jun 2010)

Log Message:
-----------
added mygui baselayout to our svn

Added Paths:
-----------
    trunk/source/main/mygui/
    trunk/source/main/mygui/Attribute.h
    trunk/source/main/mygui/BaseLayout.h
    trunk/source/main/mygui/WrapsAttribute.h

Added: trunk/source/main/mygui/Attribute.h
===================================================================
--- trunk/source/main/mygui/Attribute.h                         (rev 0)
+++ trunk/source/main/mygui/Attribute.h 2010-06-23 02:30:18 UTC (rev 1413)
@@ -0,0 +1,118 @@
+/*!
+       @file
+       @author         Albert Semenov
+       @date           10/2009
+       @module
+*/
+
+#ifndef __ATTRIBUTE_H__
+#define __ATTRIBUTE_H__
+
+namespace attribute
+{
+
+       // \xEA\xEB\xE0\xF1\xF1 \xEE\xE1\xE5\xF0\xF2\xEA\xE0 \xE4\xEB\xFF 
\xF3\xE4\xE0\xEB\xE5\xED\xE8\xFF \xE4\xE0\xED\xED\xFB\xF5 \xE8\xE7 
\xF1\xF2\xE0\xF2\xE8\xF7\xE5\xF1\xEA\xEE\xE3\xEE \xE2\xE5\xEA\xF2\xEE\xF0\xE0
+       template <typename Type>
+       struct DataHolder
+       {
+               ~DataHolder()
+               {
+                       for (typename Type::iterator item=data.begin(); 
item!=data.end(); ++item)
+                               delete (*item).first;
+               }
+
+               Type data;
+       };
+
+       // \xE8\xED\xF2\xE5\xF0\xF4\xE5\xE9\xF1 \xE4\xEB\xFF 
\xEE\xE1\xE5\xF0\xF2\xEA\xE8 \xEF\xEE\xEB\xFF
+       template <typename OwnerType, typename SetterType>
+       struct Field
+       {
+               virtual void set(OwnerType* _target, typename 
SetterType::BaseValueType* _value) = 0;
+       };
+
+       // \xF8\xE0\xE1\xEB\xEE\xED \xE4\xEB\xFF \xEE\xE1\xE5\xF0\xF2\xEA\xE8 
\xEF\xEE\xEB\xFF
+       template <typename OwnerType, typename FieldType, typename SetterType>
+       struct FieldHolder : public Field<OwnerType, SetterType>
+       {
+               FieldHolder(FieldType* OwnerType::* offset) : m_offset(offset) 
{  }
+               FieldType* OwnerType::* const m_offset;
+
+               virtual void set(OwnerType* _target, typename 
SetterType::BaseValueType* _value)
+               {
+                  _target->*m_offset = SetterType::template 
convert<FieldType>(_value);
+                  //                  _target->*m_offset = (_value == 0 ? 0 : 
_value->castType<int>::template(false));//SetterType::convert<FieldType>(_value);
+               }
+       };
+
+       // \xF8\xE0\xE1\xEB\xEE\xED \xE4\xEB\xFF 
\xE0\xF2\xF0\xE8\xE1\xF3\xF2\xE0 \xEF\xEE\xEB\xFF
+       template <typename OwnerType, typename ValueType, typename SetterType>
+       struct AttributeField
+       {
+               typedef std::pair<Field<OwnerType, SetterType>*, ValueType> 
BindPair;
+               typedef std::vector<BindPair> VectorBindPair;
+
+               template <typename FieldType>
+               AttributeField(FieldType* OwnerType::* _offset, const 
ValueType& _value)
+               {
+                       getData().push_back(BindPair(new FieldHolder<OwnerType, 
FieldType, SetterType>(_offset), _value));
+               }
+               static VectorBindPair& getData()
+               {
+                       static DataHolder<VectorBindPair> data;
+                       return data.data;
+               }
+       };
+
+       // \xEC\xE0\xEA\xF0\xEE\xF1 \xE4\xEB\xFF 
\xE8\xED\xF1\xF2\xE0\xED\xF1\xE8\xF0\xEE\xE2\xE0\xED\xE8\xFF 
\xE0\xF2\xF0\xE8\xE1\xF3\xF2\xE0 \xEF\xEE\xEB\xFF
+#define DECLARE_ATTRIBUTE_FIELD(_name, _type, _setter) \
+       template <typename OwnerType, typename ValueType = _type, typename 
SetterType = _setter> \
+       struct _name : public attribute::AttributeField<OwnerType, ValueType, 
SetterType> \
+       { \
+               template <typename FieldType> \
+               _name(FieldType* OwnerType::* _offset, const ValueType& _value) 
: \
+                       AttributeField<OwnerType, ValueType, 
SetterType>(_offset, _value) { } \
+       }
+
+       // \xEC\xE0\xEA\xF0\xEE\xF1 \xE4\xEB\xFF 
\xE8\xED\xF1\xF2\xE0\xED\xF1\xE8\xF0\xEE\xE2\xE0\xED\xE8\xFF 
\xFD\xEA\xE7\xE5\xEC\xEF\xEB\xFF\xF0\xE0 \xE0\xF2\xF0\xE8\xE1\xF3\xF2\xE0
+#define ATTRIBUTE_FIELD(_attribute, _class, _field, _value) \
+       struct _attribute##_##_field \
+       { \
+               _attribute##_##_field() \
+               { \
+                       static attribute::_attribute<_class> 
bind(&_class::_field, _value); \
+               } \
+       } _attribute##_##_field
+
+
+       // \xF8\xE0\xE1\xEB\xEE\xED \xE4\xEB\xFF 
\xE0\xF2\xF0\xE8\xE1\xF3\xF2\xE0 \xEA\xEB\xE0\xF1\xF1\xE0
+       template <typename Type, typename ValueType>
+       struct ClassAttribute
+       {
+               ClassAttribute(const ValueType& _value)
+               {
+                       getData() = _value;
+               }
+               static ValueType& getData()
+               {
+                       static ValueType data;
+                       return data;
+               }
+       };
+
+       // \xEC\xE0\xEA\xF0\xEE\xF1 \xE4\xEB\xFF 
\xE8\xED\xF1\xF2\xE0\xED\xF1\xE8\xF0\xEE\xE2\xE0\xED\xE8\xFF 
\xE0\xF2\xF0\xE8\xE1\xF3\xF2\xE0 \xEA\xEB\xE0\xF1\xF1\xE0
+#define DECLARE_ATTRIBUTE_CLASS(_name, _type) \
+       template <typename Type, typename ValueType = _type> \
+       struct _name : public attribute::ClassAttribute<_name<Type>, ValueType> 
\
+       { \
+               _name(const ValueType& _value) : \
+                       ClassAttribute<_name<Type>, ValueType>(_value) { } \
+       }
+
+       // \xEC\xE0\xEA\xF0\xEE\xF1 \xE4\xEB\xFF 
\xE8\xED\xF1\xF2\xE0\xED\xF1\xE8\xF0\xEE\xE2\xE0\xED\xE8\xFF 
\xFD\xEA\xE7\xE5\xEC\xEF\xEB\xFF\xF0\xE0 \xEA\xEB\xE0\xF1\xF1\xE0
+#define ATTRIBUTE_CLASS(_attribute, _class, _value) \
+       class _class; \
+       static attribute::_attribute<_class> _attribute##_##_class(_value)
+}
+
+#endif // __ATTRIBUTE_H__

Added: trunk/source/main/mygui/BaseLayout.h
===================================================================
--- trunk/source/main/mygui/BaseLayout.h                                (rev 0)
+++ trunk/source/main/mygui/BaseLayout.h        2010-06-23 02:30:18 UTC (rev 
1413)
@@ -0,0 +1,150 @@
+/*!
+       @file
+       @author         Albert Semenov
+       @date           07/2008
+       @module
+*/
+
+#ifndef __BASE_LAYOUT_H__
+#define __BASE_LAYOUT_H__
+
+#include <MyGUI.h>
+#include "WrapsAttribute.h"
+
+namespace wraps
+{
+
+       class BaseLayout
+       {
+       protected:
+               BaseLayout() : mMainWidget(nullptr)
+               {
+               }
+
+               BaseLayout(const std::string& _layout, MyGUI::WidgetPtr _parent 
= nullptr) : mMainWidget(nullptr)
+               {
+                       initialise(_layout, _parent);
+               }
+
+               template <typename T>
+               void assignWidget(T * & _widget, const std::string& _name, bool 
_throw = true)
+               {
+                       _widget = nullptr;
+                       for (MyGUI::VectorWidgetPtr::iterator 
iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter)
+                       {
+                               MyGUI::WidgetPtr find = 
(*iter)->findWidget(mPrefix + _name);
+                               if (nullptr != find)
+                               {
+                                       T * cast = find->castType<T>(false);
+                                       if (nullptr != cast)
+                                       {
+                                               _widget = cast;
+                                       }
+                                       else if (_throw)
+                                       {
+                                                       MYGUI_EXCEPT("Error 
cast : dest type = '" << T::getClassTypeName()
+                                                       << "' source name = '" 
<< find->getName()
+                                                       << "' source type = '" 
<< find->getTypeName() << "' in layout '" << mLayoutName << "'");
+                                       }
+                                       return;
+
+                               }
+                       }
+                       MYGUI_ASSERT( ! _throw, "widget name '" << _name << "' 
in layout '" << mLayoutName << "' not found.");
+               }
+
+               template <typename T>
+               void assignBase(T * & _widget, const std::string& _name, bool 
_throw = true)
+               {
+                       _widget = nullptr;
+                       for (MyGUI::VectorWidgetPtr::iterator 
iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter)
+                       {
+                               MyGUI::WidgetPtr find = 
(*iter)->findWidget(mPrefix + _name);
+                               if (nullptr != find)
+                               {
+                                       _widget = new T(find);
+                                       mListBase.push_back(_widget);
+                                       return;
+                               }
+                       }
+                       MYGUI_ASSERT( ! _throw, "widget name '" << _name << "' 
in layout '" << mLayoutName << "' not found.");
+               }
+
+               void initialise(const std::string& _layout, MyGUI::WidgetPtr 
_parent = nullptr)
+               {
+                       const std::string MAIN_WINDOW = "_Main";
+                       mLayoutName = _layout;
+
+                       // \xEE\xE1\xEE\xF0\xE0\xF7\xE8\xE2\xE0\xE5\xEC
+                       if (mLayoutName.empty())
+                       {
+                               mMainWidget = _parent;
+                       }
+                       // \xE7\xE0\xE3\xF0\xF3\xE6\xE0\xE5\xEC 
\xEB\xE5\xE9\xE0\xF3\xF2 \xED\xE0 \xE2\xE8\xE4\xE6\xE5\xF2
+                       else
+                       {
+                               mPrefix = MyGUI::utility::toString(this, "_");
+                               mListWindowRoot = 
MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
+
+                               const std::string main_name = mPrefix + 
MAIN_WINDOW;
+                               for (MyGUI::VectorWidgetPtr::iterator 
iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter)
+                               {
+                                       if ((*iter)->getName() == main_name)
+                                       {
+                                               mMainWidget = (*iter);
+                                               break;
+                                       }
+                               }
+                               MYGUI_ASSERT(mMainWidget, "root widget name '" 
<< MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
+                       }
+               }
+
+               void shutdown()
+               {
+                       // \xF3\xE4\xE0\xEB\xFF\xE5\xEC \xE2\xF1\xE5 
\xEA\xEB\xE0\xF1\xF1\xFB
+                       for (VectorBasePtr::iterator iter=mListBase.begin(); 
iter!=mListBase.end(); ++iter)
+                       {
+                               delete (*iter);
+                       }
+                       mListBase.clear();
+
+                       // \xF3\xE4\xE0\xEB\xFF\xE5\xEC \xE2\xF1\xE5 
\xF0\xF3\xF2\xEE\xE2\xFB\xE5 \xE2\xE8\xE4\xE6\xE5\xF2\xFB
+                       
MyGUI::LayoutManager::getInstance().unloadLayout(mListWindowRoot);
+                       mListWindowRoot.clear();
+               }
+
+               template <typename Type>
+               void initialiseByAttributes(Type* _owner, MyGUI::WidgetPtr 
_parent = nullptr)
+               {
+                       initialise(attribute::AttributeLayout<Type>::getData(), 
_parent);
+
+                       typename 
attribute::AttributeFieldWidgetName<Type>::VectorBindPair& data = 
attribute::AttributeFieldWidgetName<Type>::getData();
+                       for (typename 
attribute::AttributeFieldWidgetName<Type>::VectorBindPair::iterator 
item=data.begin(); item!=data.end(); ++item)
+                       {
+                               MyGUI::Widget* value = 0;
+                               assignWidget(value, item->second, false);
+
+                               item->first->set(_owner, value);
+                       }
+               }
+
+       public:
+               virtual ~BaseLayout()
+               {
+                       shutdown();
+               }
+
+       protected:
+               MyGUI::WidgetPtr mMainWidget;
+
+       private:
+               std::string mPrefix;
+               std::string mLayoutName;
+               MyGUI::VectorWidgetPtr mListWindowRoot;
+               typedef std::vector<BaseLayout*> VectorBasePtr;
+               VectorBasePtr mListBase;
+       };
+
+} // namespace wraps
+
+#endif // __BASE_LAYOUT_H__

Added: trunk/source/main/mygui/WrapsAttribute.h
===================================================================
--- trunk/source/main/mygui/WrapsAttribute.h                            (rev 0)
+++ trunk/source/main/mygui/WrapsAttribute.h    2010-06-23 02:30:18 UTC (rev 
1413)
@@ -0,0 +1,48 @@
+/*!
+       @file
+       @author         Albert Semenov
+       @date           10/2009
+       @module
+*/
+
+#ifndef __WRAPS_ATTRIBUTE_H__
+#define __WRAPS_ATTRIBUTE_H__
+
+#include <MyGUI.h>
+#include "Attribute.h"
+
+namespace attribute
+{
+
+       struct FieldSetterWidget
+       {
+               typedef MyGUI::Widget BaseValueType;
+
+               template <typename Type>
+               static Type* convert(BaseValueType* _value)
+               {
+                       return _value == 0 ? 0 : _value->castType<Type>(false);
+               }
+       };
+
+       DECLARE_ATTRIBUTE_FIELD(AttributeFieldWidgetName, std::string, 
FieldSetterWidget);
+
+#define ATTRIBUTE_FIELD_WIDGET_NAME(_class, _field, _value) \
+       ATTRIBUTE_FIELD(AttributeFieldWidgetName, _class, _field, _value)
+
+
+
+       DECLARE_ATTRIBUTE_CLASS(AttributeSize, MyGUI::IntSize);
+
+#define ATTRIBUTE_CLASS_SIZE(_class, _value) \
+       ATTRIBUTE_CLASS(AttributeSize, _class, _value)
+
+
+       DECLARE_ATTRIBUTE_CLASS(AttributeLayout, std::string);
+
+#define ATTRIBUTE_CLASS_LAYOUT(_class, _value) \
+       ATTRIBUTE_CLASS(AttributeLayout, _class, _value)
+
+}
+
+#endif // __WRAPS_ATTRIBUTE_H__


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to