Jelajahi Sumber

GuiBorder in GuiTypes

-GuiBorder Left Top Bottom Right now expected as names of GuiBorderProfiles
-GuiBorder default expected as TypeGuiBorderProfile
marauder2k7 4 tahun lalu
induk
melakukan
c335a9b7f9
2 mengubah file dengan 212 tambahan dan 18 penghapusan
  1. 186 13
      engine/source/gui/guiTypes.cc
  2. 26 5
      engine/source/gui/guiTypes.h

+ 186 - 13
engine/source/gui/guiTypes.cc

@@ -280,9 +280,14 @@ GuiControlProfile::GuiControlProfile(void) :
 	mUseInput      = true;
 
 	mBorderDefault = NULL;
+
+   mLeftProfileName = NULL;
 	mBorderLeft = NULL;
+   mRightProfileName = NULL;
 	mBorderRight = NULL;
+   mTopProfileName = NULL;
 	mBorderTop = NULL;
+   mBottomProfileName = NULL;
 	mBorderBottom = NULL;
 	
 	// default font
@@ -323,10 +328,10 @@ GuiControlProfile::GuiControlProfile(void) :
       mFillColorNA = def->mFillColorNA;
 
       mBorderDefault = def->mBorderDefault;
-      mBorderLeft = def->mBorderDefault;
-      mBorderRight = def->mBorderDefault;
-      mBorderTop = def->mBorderDefault;
-      mBorderBottom = def->mBorderDefault;
+      mLeftProfileName = def->mLeftProfileName;
+      mRightProfileName = def->mRightProfileName;
+      mTopProfileName = def->mTopProfileName;
+      mBottomProfileName = def->mBottomProfileName;
 
       // default font
       mFontType = def->mFontType;
@@ -345,6 +350,8 @@ GuiControlProfile::GuiControlProfile(void) :
       mReturnTab = def->mReturnTab;
       mNumbersOnly = def->mNumbersOnly;
       mCursorColor = def->mCursorColor;
+
+      // Child profile
       mProfileForChildrenName = def->mProfileForChildrenName;
       setChildrenProfile(def->mProfileForChildren);
    }
@@ -358,11 +365,12 @@ GuiControlProfile::~GuiControlProfile()
 void GuiControlProfile::initPersistFields()
 {
    Parent::initPersistFields();
-
-   addField("tab",           TypeBool,       Offset(mTabable, GuiControlProfile));
-   addField("canKeyFocus",   TypeBool,       Offset(mCanKeyFocus, GuiControlProfile));
-   addField("useInput",      TypeBool,       Offset(mUseInput, GuiControlProfile));
-   addField("mouseOverSelected", TypeBool,   Offset(mMouseOverSelected, GuiControlProfile));
+   addGroup("Behavior");
+      addField("tab",           TypeBool,       Offset(mTabable, GuiControlProfile));
+      addField("canKeyFocus",   TypeBool,       Offset(mCanKeyFocus, GuiControlProfile));
+      addField("useInput",      TypeBool,       Offset(mUseInput, GuiControlProfile));
+      addField("mouseOverSelected", TypeBool,   Offset(mMouseOverSelected, GuiControlProfile));
+   endGroup("Behavior");
 
    addField("fillColor",     TypeColorI,     Offset(mFillColor, GuiControlProfile));
    addField("fillColorHL",   TypeColorI,     Offset(mFillColorHL, GuiControlProfile));
@@ -370,10 +378,10 @@ void GuiControlProfile::initPersistFields()
    addField("fillColorNA",   TypeColorI,     Offset(mFillColorNA, GuiControlProfile));
 
    addField("borderDefault", TypeGuiBorderProfile, Offset(mBorderDefault, GuiControlProfile));
-   addField("borderLeft",    TypeGuiBorderProfile, Offset(mBorderLeft, GuiControlProfile));
-   addField("borderRight",   TypeGuiBorderProfile, Offset(mBorderRight, GuiControlProfile));
-   addField("borderTop",     TypeGuiBorderProfile, Offset(mBorderTop, GuiControlProfile));
-   addField("borderBottom",  TypeGuiBorderProfile, Offset(mBorderBottom, GuiControlProfile));
+   addField("borderLeft",    TypeString, Offset(mLeftProfileName, GuiControlProfile));
+   addField("borderRight",   TypeString, Offset(mRightProfileName, GuiControlProfile));
+   addField("borderTop",     TypeString, Offset(mTopProfileName, GuiControlProfile));
+   addField("borderBottom",  TypeString, Offset(mBottomProfileName, GuiControlProfile));
 
    addField("fontType",      TypeString,     Offset(mFontType, GuiControlProfile));
    addField("fontSize",      TypeS32,        Offset(mFontSize, GuiControlProfile));
@@ -410,11 +418,176 @@ bool GuiControlProfile::onAdd()
 
    Sim::getGuiDataGroup()->addObject(this);
 
+   getLeftProfile();
+   getRightProfile();
+   getTopProfile();
+   getBottomProfile();
+
    getChildrenProfile();
 
    return true;
 }
 
+GuiBorderProfile * GuiControlProfile::getLeftProfile()
+{
+   // We can early out if we still have a valid profile
+   if (mBorderLeft)
+      return mBorderLeft;
+
+   // Attempt to find the profile specified
+   if (mLeftProfileName)
+   {
+      GuiBorderProfile *profile = dynamic_cast<GuiBorderProfile*> (Sim::findObject(mLeftProfileName));
+
+      if (profile)
+      {
+         setLeftProfile(profile);
+      }
+   }
+   else
+   {
+      setLeftProfile(mBorderDefault);
+   }
+
+   return mBorderLeft;
+}
+
+void GuiControlProfile::setLeftProfile(GuiBorderProfile * prof)
+{
+   if (prof == mBorderLeft)
+      return;
+
+   // Clear the delete notification we previously set up
+   if (mBorderLeft)
+      clearNotify(mBorderLeft);
+
+   mBorderLeft = prof;
+
+   // Make sure that the new profile will notify us when it is deleted
+   if (mBorderLeft)
+      deleteNotify(mBorderLeft);
+}
+
+GuiBorderProfile * GuiControlProfile::getRightProfile()
+{
+   // We can early out if we still have a valid profile
+   if (mBorderRight)
+      return mBorderRight;
+
+   // Attempt to find the profile specified
+   if (mRightProfileName)
+   {
+      GuiBorderProfile *profile = dynamic_cast<GuiBorderProfile*> (Sim::findObject(mLeftProfileName));
+
+      if (profile)
+      {
+         setRightProfile(profile);
+      }
+   }
+   else
+   {
+      setLeftProfile(mBorderDefault);
+   }
+
+   return mBorderRight;
+}
+
+void GuiControlProfile::setRightProfile(GuiBorderProfile * prof)
+{
+   if (prof == mBorderRight)
+      return;
+
+   // Clear the delete notification we previously set up
+   if (mBorderRight)
+      clearNotify(mBorderRight);
+
+   mBorderRight = prof;
+
+   // Make sure that the new profile will notify us when it is deleted
+   if (mBorderRight)
+      deleteNotify(mBorderRight);
+}
+
+GuiBorderProfile * GuiControlProfile::getTopProfile()
+{
+   // We can early out if we still have a valid profile
+   if (mBorderTop)
+      return mBorderTop;
+
+   // Attempt to find the profile specified
+   if (mTopProfileName)
+   {
+      GuiBorderProfile *profile = dynamic_cast<GuiBorderProfile*> (Sim::findObject(mLeftProfileName));
+
+      if (profile)
+      {
+         setTopProfile(profile);
+      }
+   }
+   else
+   {
+      setTopProfile(mBorderDefault);
+   }
+
+   return mBorderTop;
+}
+
+void GuiControlProfile::setTopProfile(GuiBorderProfile * prof)
+{
+   if (prof == mBorderTop)
+      return;
+
+   // Clear the delete notification we previously set up
+   if (mBorderTop)
+      clearNotify(mBorderTop);
+
+   mBorderTop = prof;
+
+   // Make sure that the new profile will notify us when it is deleted
+   if (mBorderTop)
+      deleteNotify(mBorderTop);
+}
+
+GuiBorderProfile * GuiControlProfile::getBottomProfile()
+{
+   // We can early out if we still have a valid profile
+   if (mBorderBottom)
+      return mBorderBottom;
+
+   // Attempt to find the profile specified
+   if (mBottomProfileName)
+   {
+      GuiBorderProfile *profile = dynamic_cast<GuiBorderProfile*> (Sim::findObject(mLeftProfileName));
+
+      if (profile)
+      {
+         setBottomProfile(profile);
+      }
+   }
+   else
+   {
+      setBottomProfile(mBorderDefault);
+   }
+
+   return mBorderBottom;
+}
+
+void GuiControlProfile::setBottomProfile(GuiBorderProfile * prof)
+{
+   if (prof == mBorderBottom)
+      return;
+
+   // Clear the delete notification we previously set up
+   if (mBorderBottom)
+      clearNotify(mBorderBottom);
+
+   mBorderBottom = prof;
+
+   // Make sure that the new profile will notify us when it is deleted
+   if (mBorderBottom)
+      deleteNotify(mBorderBottom);
+}
+
 GuiControlProfile* GuiControlProfile::getChildrenProfile()
 {
    // We can early out if we still have a valid profile

+ 26 - 5
engine/source/gui/guiTypes.h

@@ -175,9 +175,17 @@ public:
    ColorI mFillColorNA; //Used if the object is not active or disabled.
 
    GuiBorderProfile* mBorderDefault;					//The default border settings.
+   // top profile
+   StringTableEntry mTopProfileName;
    GuiBorderProfile* mBorderTop;
+   // Bottom profile
+   StringTableEntry mBottomProfileName;
    GuiBorderProfile* mBorderBottom;
+   // Left profile
+   StringTableEntry mLeftProfileName;
    GuiBorderProfile* mBorderLeft;
+   // Left profile
+   StringTableEntry mRightProfileName;
    GuiBorderProfile* mBorderRight;
 
    // font members
@@ -255,8 +263,21 @@ public:
    static void initPersistFields();
    bool onAdd();
 
-   GuiControlProfile * getChildrenProfile();
 
+   GuiBorderProfile* getLeftProfile();
+   void setLeftProfile(GuiBorderProfile* prof);
+
+   GuiBorderProfile* getRightProfile();
+   void setRightProfile(GuiBorderProfile* prof);
+
+   GuiBorderProfile* getTopProfile();
+   void setTopProfile(GuiBorderProfile* prof);
+
+   GuiBorderProfile* getBottomProfile();
+   void setBottomProfile(GuiBorderProfile* prof);
+
+   // Get and Set child profile
+   GuiControlProfile * getChildrenProfile();
    void setChildrenProfile(GuiControlProfile * prof);
 
    /// This method creates an array of bitmaps from one single bitmap with
@@ -272,10 +293,10 @@ public:
    const ColorI& getFillColor(const GuiControlState state); //Returns the fill color based on the state.
    const ColorI& getFontColor(const GuiControlState state); //Returns the font color based on the state.
 
-   GuiBorderProfile* getLeftBorder() { return ((mBorderLeft) ? mBorderLeft : mBorderDefault); };
-   GuiBorderProfile* getRightBorder() { return ((mBorderRight) ? mBorderRight : mBorderDefault); };
-   GuiBorderProfile* getTopBorder() { return ((mBorderTop) ? mBorderTop : mBorderDefault); };
-   GuiBorderProfile* getBottomBorder() { return ((mBorderBottom) ? mBorderBottom : mBorderDefault); };
+   GuiBorderProfile* getLeftBorder() { return mBorderLeft; }
+   GuiBorderProfile* getRightBorder() { return mBorderRight; }
+   GuiBorderProfile* getTopBorder() { return mBorderTop; }
+   GuiBorderProfile* getBottomBorder() { return mBorderBottom; }
 };
 DefineConsoleType( TypeGuiProfile)