OpenMW
apps/openmw/mwgui/widgets.hpp
Go to the documentation of this file.
00001 #ifndef MWGUI_WIDGETS_H
00002 #define MWGUI_WIDGETS_H
00003 
00004 #include "../mwworld/esmstore.hpp"
00005 #include "../mwmechanics/stat.hpp"
00006 #include "controllers.hpp"
00007 
00008 #include <MyGUI_Button.h>
00009 #include <MyGUI_EditBox.h>
00010 #include <MyGUI_ScrollBar.h>
00011 
00012 namespace MyGUI
00013 {
00014     class ImageBox;
00015 }
00016 
00017 namespace MWBase
00018 {
00019     class WindowManager;
00020 }
00021 
00022 /*
00023   This file contains various custom widgets used in OpenMW.
00024  */
00025 
00026 namespace MWGui
00027 {
00028     namespace Widgets
00029     {
00030         class MWEffectList;
00031 
00032         void fixTexturePath(std::string &path);
00033 
00034         struct SpellEffectParams
00035         {
00036             SpellEffectParams()
00037                 : mMagnMin(-1)
00038                 , mMagnMax(-1)
00039                 , mRange(-1)
00040                 , mDuration(-1)
00041                 , mSkill(-1)
00042                 , mArea(0)
00043                 , mAttribute(-1)
00044                 , mEffectID(-1)
00045                 , mNoTarget(false)
00046                 , mIsConstant(false)
00047                 , mKnown(true)
00048             {
00049             }
00050 
00051             bool mNoTarget; // potion effects for example have no target (target is always the player)
00052             bool mIsConstant; // constant effect means that duration will not be displayed
00053 
00054             bool mKnown; // is this effect known to the player? (If not, will display as a question mark instead)
00055 
00056             // value of -1 here means the effect is unknown to the player
00057             short mEffectID;
00058 
00059             // value of -1 here means there is no skill/attribute
00060             signed char mSkill, mAttribute;
00061 
00062             // value of -1 here means the value is unavailable
00063             int mMagnMin, mMagnMax, mRange, mDuration;
00064 
00065             // value of 0 -> no area effect
00066             int mArea;
00067 
00068             bool operator==(const SpellEffectParams& other) const
00069             {
00070                 if (mEffectID !=  other.mEffectID)
00071                     return false;
00072 
00073                 bool involvesAttribute = (mEffectID == 74 // restore attribute
00074                                         || mEffectID == 85 // absorb attribute
00075                                         || mEffectID == 17 // drain attribute
00076                                         || mEffectID == 79 // fortify attribute
00077                                         || mEffectID == 22); // damage attribute
00078                 bool involvesSkill = (mEffectID == 78 // restore skill
00079                                         || mEffectID == 89 // absorb skill
00080                                         || mEffectID == 21 // drain skill
00081                                         || mEffectID == 83 // fortify skill
00082                                         || mEffectID == 26); // damage skill
00083                 return ((other.mSkill == mSkill) || !involvesSkill) && ((other.mAttribute == mAttribute) && !involvesAttribute) && (other.mArea == mArea);
00084             }
00085         };
00086 
00087         typedef std::vector<SpellEffectParams> SpellEffectList;
00088 
00089         class MWSkill : public MyGUI::Widget
00090         {
00091             MYGUI_RTTI_DERIVED( MWSkill )
00092         public:
00093             MWSkill();
00094 
00095             typedef MWMechanics::Stat<float> SkillValue;
00096 
00097             void setSkillId(ESM::Skill::SkillEnum skillId);
00098             void setSkillNumber(int skillId);
00099             void setSkillValue(const SkillValue& value);
00100 
00101             ESM::Skill::SkillEnum getSkillId() const { return mSkillId; }
00102             const SkillValue& getSkillValue() const { return mValue; }
00103 
00104             // Events
00105             typedef MyGUI::delegates::CMultiDelegate1<MWSkill*> EventHandle_SkillVoid;
00106 
00110             EventHandle_SkillVoid eventClicked;
00111 
00112         protected:
00113             virtual ~MWSkill();
00114 
00115             virtual void initialiseOverride();
00116 
00117             void onClicked(MyGUI::Widget* _sender);
00118 
00119         private:
00120 
00121             void updateWidgets();
00122 
00123             ESM::Skill::SkillEnum mSkillId;
00124             SkillValue mValue;
00125             MyGUI::Widget* mSkillNameWidget;
00126             MyGUI::Widget* mSkillValueWidget;
00127         };
00128         typedef MWSkill* MWSkillPtr;
00129 
00130         class MWAttribute : public MyGUI::Widget
00131         {
00132             MYGUI_RTTI_DERIVED( MWAttribute )
00133         public:
00134             MWAttribute();
00135 
00136             typedef MWMechanics::Stat<int> AttributeValue;
00137 
00138             void setAttributeId(int attributeId);
00139             void setAttributeValue(const AttributeValue& value);
00140 
00141             int getAttributeId() const { return mId; }
00142             const AttributeValue& getAttributeValue() const { return mValue; }
00143 
00144             // Events
00145             typedef MyGUI::delegates::CMultiDelegate1<MWAttribute*> EventHandle_AttributeVoid;
00146 
00150             EventHandle_AttributeVoid eventClicked;
00151 
00152         protected:
00153             virtual ~MWAttribute();
00154 
00155             virtual void initialiseOverride();
00156 
00157             void onClicked(MyGUI::Widget* _sender);
00158 
00159         private:
00160 
00161             void updateWidgets();
00162 
00163             int mId;
00164             AttributeValue mValue;
00165             MyGUI::Widget* mAttributeNameWidget;
00166             MyGUI::Widget* mAttributeValueWidget;
00167         };
00168         typedef MWAttribute* MWAttributePtr;
00169 
00173         class MWSpellEffect;
00174         class MWSpell : public MyGUI::Widget
00175         {
00176             MYGUI_RTTI_DERIVED( MWSpell )
00177         public:
00178             MWSpell();
00179 
00180             typedef MWMechanics::Stat<int> SpellValue;
00181 
00182             void setSpellId(const std::string &id);
00183 
00191             void createEffectWidgets(std::vector<MyGUI::Widget*> &effects, MyGUI::Widget* creator, MyGUI::IntCoord &coord, int flags);
00192 
00193             const std::string &getSpellId() const { return mId; }
00194 
00195         protected:
00196             virtual ~MWSpell();
00197 
00198             virtual void initialiseOverride();
00199 
00200         private:
00201             void updateWidgets();
00202 
00203             std::string mId;
00204             MyGUI::TextBox* mSpellNameWidget;
00205         };
00206         typedef MWSpell* MWSpellPtr;
00207 
00208         class MWEffectList : public MyGUI::Widget
00209         {
00210             MYGUI_RTTI_DERIVED( MWEffectList )
00211         public:
00212             MWEffectList();
00213 
00214             typedef MWMechanics::Stat<int> EnchantmentValue;
00215 
00216             enum EffectFlags
00217             {
00218                 EF_NoTarget = 0x01, // potions have no target (target is always the player)
00219                 EF_Constant = 0x02 // constant effect means that duration will not be displayed
00220             };
00221 
00222             void setEffectList(const SpellEffectList& list);
00223 
00224             static SpellEffectList effectListFromESM(const ESM::EffectList* effects);
00225 
00233             void createEffectWidgets(std::vector<MyGUI::Widget*> &effects, MyGUI::Widget* creator, MyGUI::IntCoord &coord, bool center, int flags);
00234 
00235         protected:
00236             virtual ~MWEffectList();
00237 
00238             virtual void initialiseOverride();
00239 
00240         private:
00241             void updateWidgets();
00242 
00243             SpellEffectList mEffectList;
00244         };
00245         typedef MWEffectList* MWEffectListPtr;
00246 
00247         class MWSpellEffect : public MyGUI::Widget
00248         {
00249             MYGUI_RTTI_DERIVED( MWSpellEffect )
00250         public:
00251             MWSpellEffect();
00252 
00253             typedef ESM::ENAMstruct SpellEffectValue;
00254 
00255             void setSpellEffect(const SpellEffectParams& params);
00256 
00257             int getRequestedWidth() const { return mRequestedWidth; }
00258 
00259         protected:
00260             virtual ~MWSpellEffect();
00261 
00262             virtual void initialiseOverride();
00263 
00264         private:
00265 
00266             void updateWidgets();
00267 
00268             SpellEffectParams mEffectParams;
00269             MyGUI::ImageBox* mImageWidget;
00270             MyGUI::TextBox* mTextWidget;
00271             int mRequestedWidth;
00272         };
00273         typedef MWSpellEffect* MWSpellEffectPtr;
00274 
00275         class MWDynamicStat : public MyGUI::Widget
00276         {
00277             MYGUI_RTTI_DERIVED( MWDynamicStat )
00278         public:
00279             MWDynamicStat();
00280 
00281             void setValue(int value, int max);
00282             void setTitle(const std::string& text);
00283 
00284             int getValue() const { return mValue; }
00285             int getMax() const { return mMax; }
00286 
00287         protected:
00288             virtual ~MWDynamicStat();
00289 
00290             virtual void initialiseOverride();
00291 
00292         private:
00293 
00294             int mValue, mMax;
00295             MyGUI::TextBox* mTextWidget;
00296             MyGUI::ProgressPtr mBarWidget;
00297             MyGUI::TextBox* mBarTextWidget;
00298         };
00299         typedef MWDynamicStat* MWDynamicStatPtr;
00300 
00301 
00302 
00303 
00304 
00305         // ---------------------------------------------------------------------------------------------------------------------
00306 
00307 
00308 
00309         class AutoSizedWidget
00310         {
00311         public:
00312             virtual MyGUI::IntSize getRequestedSize() = 0;
00313 
00314         protected:
00315             void notifySizeChange(MyGUI::Widget* w);
00316 
00317             MyGUI::Align mExpandDirection;
00318         };
00319 
00320         class AutoSizedTextBox : public AutoSizedWidget, public MyGUI::TextBox
00321         {
00322             MYGUI_RTTI_DERIVED( AutoSizedTextBox )
00323 
00324         public:
00325             virtual MyGUI::IntSize getRequestedSize();
00326             virtual void setCaption(const MyGUI::UString& _value);
00327 
00328         protected:
00329             virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
00330         };
00331 
00332         class AutoSizedEditBox : public AutoSizedWidget, public MyGUI::EditBox
00333         {
00334             MYGUI_RTTI_DERIVED( AutoSizedEditBox )
00335 
00336         public:
00337             virtual MyGUI::IntSize getRequestedSize();
00338             virtual void setCaption(const MyGUI::UString& _value);
00339 
00340         protected:
00341             virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
00342         };
00343 
00344         class AutoSizedButton : public AutoSizedWidget, public MyGUI::Button
00345         {
00346             MYGUI_RTTI_DERIVED( AutoSizedButton )
00347 
00348         public:
00349             virtual MyGUI::IntSize getRequestedSize();
00350             virtual void setCaption(const MyGUI::UString& _value);
00351 
00352         protected:
00353             virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
00354         };
00355 
00360         class Box : public AutoSizedWidget
00361         {
00362         public:
00363             Box();
00364 
00365             void notifyChildrenSizeChanged();
00366 
00367         protected:
00368             virtual void align() = 0;
00369 
00370             virtual void _setPropertyImpl(const std::string& _key, const std::string& _value);
00371 
00372             int mSpacing; // how much space to put between elements
00373 
00374             int mPadding; // outer padding
00375 
00376             bool mAutoResize; // auto resize the box so that it exactly fits all elements
00377         };
00378 
00379         class HBox : public Box, public MyGUI::Widget
00380         {
00381             MYGUI_RTTI_DERIVED( HBox )
00382 
00383         public:
00384             virtual void setSize (const MyGUI::IntSize &_value);
00385             virtual void setCoord (const MyGUI::IntCoord &_value);
00386 
00387         protected:
00388             virtual void align();
00389             virtual MyGUI::IntSize getRequestedSize();
00390 
00391             virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
00392 
00393             virtual void onWidgetCreated(MyGUI::Widget* _widget);
00394         };
00395 
00396         class VBox : public Box, public MyGUI::Widget
00397         {
00398             MYGUI_RTTI_DERIVED( VBox)
00399 
00400         public:
00401             virtual void setSize (const MyGUI::IntSize &_value);
00402             virtual void setCoord (const MyGUI::IntCoord &_value);
00403 
00404         protected:
00405             virtual void align();
00406             virtual MyGUI::IntSize getRequestedSize();
00407 
00408             virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
00409 
00410             virtual void onWidgetCreated(MyGUI::Widget* _widget);
00411         };
00412 
00413         class MWScrollBar : public MyGUI::ScrollBar
00414         {
00415             MYGUI_RTTI_DERIVED(MWScrollBar)
00416 
00417         public:
00418             MWScrollBar();
00419             virtual ~MWScrollBar();
00420 
00421             void setEnableRepeat(bool enable);
00422             bool getEnableRepeat();
00423             void getRepeat(float &trigger, float &step);
00424             void setRepeat(float trigger, float step);
00425 
00426         protected:
00427             virtual void initialiseOverride();
00428             void repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller);
00429 
00430             bool mEnableRepeat;
00431             float mRepeatTriggerTime;
00432             float mRepeatStepTime;
00433             bool mIsIncreasing;
00434 
00435         private:
00436             void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
00437             void onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
00438             void onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
00439             void onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
00440         };
00441     }
00442 }
00443 
00444 #endif