Browse Source

Theme Switching

This supports the editors switching themes dynamically.
Peter Robinson 5 years ago
parent
commit
338b7aaf92

+ 5 - 0
editor/AssetAdmin/AssetAdmin.cs

@@ -45,6 +45,11 @@ function AssetAdmin::destroy(%this)
 
 }
 
+function AssetAdmin::onThemeChanged(%this, %theme)
+{
+	%this.comingSoon.setProfile(%theme.panelProfile);
+}
+
 function AssetAdmin::open(%this)
 {
 

+ 11 - 0
editor/EditorConsole/EditorConsole.cs

@@ -95,6 +95,17 @@ function EditorConsole::destroy(%this)
 
 }
 
+function EditorConsole::onThemeChanged(%this, %theme)
+{
+	%this.consoleEntry.setProfile(%theme.textEditProfile);
+	%this.hideLogButton.setProfile(%theme.buttonProfile);
+	%this.scroller.setProfile(%theme.scrollProfile);
+	%this.scroller.setThumbProfile(%theme.thumbProfile);
+	%this.scroller.setTrackProfile(%theme.trackProfile);
+	%this.scroller.setArrowProfile(%theme.scrollArrowProfile);
+	%this.consoleLog.setProfile(%theme.consoleProfile);
+}
+
 function EditorConsole::open(%this)
 {
 	%this.scroller.scrollToBottom();

+ 30 - 0
editor/EditorCore/EditorCore.cs

@@ -31,6 +31,7 @@ function EditorCore::create( %this )
 	{
 		class = "ThemeManager";
 	};
+	%this.startListening(%this.themes);
 
 	%this.initGui();
 
@@ -103,6 +104,8 @@ function EditorCore::RegisterEditor(%this, %name, %editor)
 		Text = %name;
 	};
 
+	%editor.startListening(%this.themes);
+
 	return %this.page[%name];
 }
 
@@ -110,3 +113,30 @@ function EditorCore::FinishRegistration(%this, %page)
 {
 	%this.tabBook.add(%page);
 }
+
+function EditorCore::onThemeChanged(%this, %theme)
+{
+	%this.tabBook.setProfile(%theme.tabBookProfileTop);
+	%this.tabBook.setTabProfile(%theme.tabProfileTop);
+
+	for(%i = 0; %i < %this.tabBook.getCount(); %i++)
+	{
+		%page = %this.tabBook.getObject(%i);
+		%page.setProfile(%theme.tabPageProfile);
+	}
+}
+
+function EditorCore::setTheme(%this, %i)
+{
+	%this.themes.setTheme(%i);
+}
+
+function EditorCore::nextTheme(%this)
+{
+	%this.themes.nextTheme();
+}
+
+function EditorCore::prevTheme(%this)
+{
+	%this.themes.prevTheme();
+}

+ 16 - 2
editor/EditorCore/Themes/ThemeManager.cs

@@ -24,7 +24,7 @@ function ThemeManager::onAdd(%this)
 {
 	%this.themeList = new SimSet();
 
-	%tuxedo = new ScriptObject()
+	%constructionVest = new ScriptObject()
 	{
 		class = "BaseTheme";
 	};
@@ -41,7 +41,7 @@ function ThemeManager::onAdd(%this)
 		class = "ForestRobeTheme";
 	};
 
-	%this.registerTheme(%tuxedo);
+	%this.registerTheme(%constructionVest);
 	%this.registerTheme(%labCoat);
 	%this.registerTheme(%forestRobe);
 	%this.setTheme(0);
@@ -49,10 +49,22 @@ function ThemeManager::onAdd(%this)
 
 function ThemeManager::setTheme(%this, %i)
 {
+	%i = mClamp(%i, 0, %this.themeList.getCount() - 1);
+	%this.curTheme = %i;
 	%theme = %this.themeList.getObject(%i);
 	%this.activateTheme(%theme);
 }
 
+function ThemeManager::nextTheme(%this)
+{
+	%this.setTheme(%this.curTheme+1);
+}
+
+function ThemeManager::prevTheme(%this)
+{
+	%this.setTheme(%this.curTheme-1);
+}
+
 function ThemeManager::registerTheme(%this, %theme)
 {
 	%this.themeList.add(%theme);
@@ -79,4 +91,6 @@ function ThemeManager::activateTheme(%this, %theme)
 	%this.thumbProfile = %theme.thumbProfile;
 	%this.trackProfile = %theme.trackProfile;
 	%this.scrollArrowProfile = %theme.scrollArrowProfile;
+
+	%this.postEvent("ThemeChanged", %this);
 }

+ 5 - 0
editor/ProjectManager/ProjectManager.cs

@@ -45,6 +45,11 @@ function ProjectManager::destroy(%this)
 
 }
 
+function ProjectManager::onThemeChanged(%this, %theme)
+{
+	%this.comingSoon.setProfile(%theme.panelProfile);
+}
+
 function ProjectManager::open(%this)
 {
 

+ 58 - 0
engine/source/gui/containers/guiScrollCtrl.cc

@@ -130,6 +130,16 @@ bool GuiScrollCtrl::onWake()
 	   mScrollBarThickness      = mBitmapBounds[BmpStates * BmpVPage].extent.x;
 	   computeSizes();
    }
+
+	if (mThumbProfile != NULL)
+		mThumbProfile->incRefCount();
+
+	if (mTrackProfile != NULL)
+		mTrackProfile->incRefCount();
+
+	if (mArrowProfile != NULL)
+		mArrowProfile->incRefCount();
+
    return true;
 }
 
@@ -137,6 +147,54 @@ void GuiScrollCtrl::onSleep()
 {
    Parent::onSleep();
    mTextureHandle = NULL;
+
+   if (mThumbProfile != NULL)
+	   mThumbProfile->decRefCount();
+
+   if (mTrackProfile != NULL)
+	   mTrackProfile->decRefCount();
+
+   if (mArrowProfile != NULL)
+	   mArrowProfile->decRefCount();
+}
+
+void GuiScrollCtrl::setControlThumbProfile(GuiControlProfile* prof)
+{
+	AssertFatal(prof, "GuiScrollCtrl::setControlThumbProfile: invalid thumb profile");
+	if (prof == mThumbProfile)
+		return;
+	if (mAwake)
+		mThumbProfile->decRefCount();
+	mThumbProfile = prof;
+	if (mAwake)
+		mThumbProfile->incRefCount();
+
+}
+
+void GuiScrollCtrl::setControlTrackProfile(GuiControlProfile* prof)
+{
+	AssertFatal(prof, "GuiScrollCtrl::setControlTrackProfile: invalid track profile");
+	if (prof == mTrackProfile)
+		return;
+	if (mAwake)
+		mTrackProfile->decRefCount();
+	mTrackProfile = prof;
+	if (mAwake)
+		mTrackProfile->incRefCount();
+
+}
+
+void GuiScrollCtrl::setControlArrowProfile(GuiControlProfile* prof)
+{
+	AssertFatal(prof, "GuiScrollCtrl::setControlArrowProfile: invalid Arrow profile");
+	if (prof == mArrowProfile)
+		return;
+	if (mAwake)
+		mArrowProfile->decRefCount();
+	mArrowProfile = prof;
+	if (mAwake)
+		mArrowProfile->incRefCount();
+
 }
 
 GuiControl* GuiScrollCtrl::findHitControl(const Point2I& pt, S32 initialLayer)

+ 3 - 0
engine/source/gui/containers/guiScrollCtrl.h

@@ -192,6 +192,9 @@ public:
 
    bool onWake();
    void onSleep();
+   void setControlThumbProfile(GuiControlProfile* prof);
+   void setControlTrackProfile(GuiControlProfile* prof);
+   void setControlArrowProfile(GuiControlProfile* prof);
 
    void onPreRender();
    void onRender(Point2I offset, const RectI &updateRect);

+ 36 - 0
engine/source/gui/containers/guiScrollCtrl_ScriptBinding.h

@@ -102,4 +102,40 @@ ConsoleMethod(GuiScrollCtrl, getScrollPositionY, S32, 2, 2, "()")
 ConsoleMethod(GuiScrollCtrl, computeSizes, void, 2, 2, "()")
 {
 	object->computeSizes();
+}
+
+/*! Sets the currently used ThumbProfile for the GuiControl
+	@param p The Thumbprofile you wish to set the control to use
+	@return No return value
+*/
+ConsoleMethodWithDocs(GuiScrollCtrl, setThumbProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
+{
+	GuiControlProfile* profile;
+
+	if (Sim::findObject(argv[2], profile))
+		object->setControlThumbProfile(profile);
+}
+
+/*! Sets the currently used TrackProfile for the GuiControl
+	@param p The Trackprofile you wish to set the control to use
+	@return No return value
+*/
+ConsoleMethodWithDocs(GuiScrollCtrl, setTrackProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
+{
+	GuiControlProfile* profile;
+
+	if (Sim::findObject(argv[2], profile))
+		object->setControlTrackProfile(profile);
+}
+
+/*! Sets the currently used ArrowProfile for the GuiControl
+	@param p The Arrowprofile you wish to set the control to use
+	@return No return value
+*/
+ConsoleMethodWithDocs(GuiScrollCtrl, setArrowProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
+{
+	GuiControlProfile* profile;
+
+	if (Sim::findObject(argv[2], profile))
+		object->setControlArrowProfile(profile);
 }

+ 19 - 0
engine/source/gui/containers/guiTabBookCtrl.cc

@@ -173,14 +173,33 @@ bool GuiTabBookCtrl::onWake()
    if( mHasTexture )
       mBitmapBounds = mProfile->mBitmapArrayRects.address();
 
+   //increment the tab profile
+   mTabProfile->incRefCount();
+
    return true;
 }
 
 void GuiTabBookCtrl::onSleep()
 {
    Parent::onSleep();
+
+   //decrement the tab profile referrence
+   if (mTabProfile != NULL)
+       mTabProfile->decRefCount();
 }
 
+void GuiTabBookCtrl::setControlTabProfile(GuiControlProfile* prof)
+{
+    AssertFatal(prof, "GuiTabBookCtrl::setControlTabProfile: invalid tab profile");
+    if (prof == mTabProfile)
+        return;
+    if (mAwake)
+        mTabProfile->decRefCount();
+    mTabProfile = prof;
+    if (mAwake)
+        mTabProfile->incRefCount();
+
+}
 
 void GuiTabBookCtrl::addNewPage()
 {

+ 1 - 0
engine/source/gui/containers/guiTabBookCtrl.h

@@ -122,6 +122,7 @@ private:
    void onRemove();
    bool onWake();
    void onSleep();
+   void setControlTabProfile(GuiControlProfile* prof);
    void onPreRender();
    void onRender( Point2I offset, const RectI &updateRect );
    /// @}

+ 12 - 0
engine/source/gui/containers/guiTabBookCtrl_ScriptBinding.h

@@ -38,4 +38,16 @@ ConsoleMethodWithDocs(GuiTabBookCtrl, selectPage, void, 3, 3, "(pageIndex)")
 ConsoleMethodWithDocs(GuiTabBookCtrl, selectPageName, void, 3, 3, "(pageName)")
 {
 	object->selectPage(argv[2]);
+}
+
+/*! Sets the currently used TabProfile for the GuiControl
+	@param p The tabprofile you wish to set the control to use
+	@return No return value
+*/
+ConsoleMethodWithDocs(GuiTabBookCtrl, setTabProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
+{
+	GuiControlProfile* profile;
+
+	if (Sim::findObject(argv[2], profile))
+		object->setControlTabProfile(profile);
 }