Browse Source

FontColor Override

With this code, a user can override the fontColor in a profile with their own color. This works for nearly all controls, except for a handful of editor specific controls and the GuiTextEditCtrl. To override a font color, simply set the FontColor on the control and then set the OverrideFontColor flag to true. That same flag can be used to turn off the override as well.
Peter Robinson 3 năm trước cách đây
mục cha
commit
7af8bce456

+ 2 - 0
editor/EditorCore/scripts/EditorProjectSelector.cs

@@ -58,6 +58,8 @@ function EditorProjectSelector::onAdd(%this)
 		Visible = false;
 		FontSizeAdjust = 1.2;
 		Align = "right";
+		OverrideFontColor = true;
+		FontColor = ThemeManager.activeTheme.color5;
 	};
 	ThemeManager.setProfile(%this.versionText, "codeProfile");
 	%this.add(%this.versionText);

+ 1 - 1
engine/source/gui/buttons/guiButtonCtrl.cc

@@ -281,7 +281,7 @@ void GuiButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
 	renderUniversalRect(ctrlRect, mProfile, currentState, getFillColor(currentState), true);
 
 	//Render Text
-	dglSetBitmapModulation(mProfile->getFontColor(currentState));
+	dglSetBitmapModulation(getFontColor(mProfile, currentState));
 	RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mProfile);
 	RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mProfile);
 	renderText(contentRect.point, contentRect.extent, mText, mProfile);

+ 1 - 1
engine/source/gui/buttons/guiCheckBoxCtrl.cc

@@ -109,7 +109,7 @@ void GuiCheckBoxCtrl::onRender(Point2I offset, const RectI &updateRect)
 	}
 
 	//Render Text
-	dglSetBitmapModulation(mProfile->getFontColor(currentState));
+	dglSetBitmapModulation(getFontColor(mProfile, currentState));
 	renderText(textRect.point, textRect.extent, mText, mProfile);
 
 	//Render the childen

+ 2 - 2
engine/source/gui/buttons/guiDropDownCtrl.cc

@@ -175,7 +175,7 @@ void GuiDropDownCtrl::onRender(Point2I offset, const RectI& updateRect)
 	renderUniversalRect(ctrlRect, mProfile, currentState, getFillColor(currentState), true);
 
 	//Get the content area
-	dglSetBitmapModulation(mProfile->getFontColor(currentState));
+	dglSetBitmapModulation(getFontColor(mProfile, currentState));
 	RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mProfile);
 	RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mProfile);
 
@@ -183,7 +183,7 @@ void GuiDropDownCtrl::onRender(Point2I offset, const RectI& updateRect)
 	if(mProfile->usesDefaultRendering(currentState))
 	{
 		RectI drawArea = RectI(contentRect.point.x + contentRect.extent.x - contentRect.extent.y, contentRect.point.y, contentRect.extent.y, contentRect.extent.y);
-		ColorI color = ColorI(mProfile->getFontColor(currentState));
+		ColorI color = ColorI(getFontColor(mProfile, currentState));
 		renderTriangleIcon(drawArea, color, GuiDirection::Down, 8);
 		contentRect.extent.x -= contentRect.extent.y;
 	}

+ 1 - 1
engine/source/gui/containers/guiTabBookCtrl.cc

@@ -391,7 +391,7 @@ void GuiTabBookCtrl::renderTab( RectI tabRect, GuiTabPageCtrl *tab )
    renderUniversalRect(ctrlRect, mTabProfile, currentState);
 
    //Render Text
-   dglSetBitmapModulation(mTabProfile->getFontColor(currentState));
+   dglSetBitmapModulation(getFontColor(mTabProfile, currentState));
    RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mTabProfile);
    RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mTabProfile);
 

+ 1 - 1
engine/source/gui/containers/guiWindowCtrl.cc

@@ -656,7 +656,7 @@ void GuiWindowCtrl::onRender(Point2I offset, const RectI &updateRect)
 	renderUniversalRect(ctrlRectTitle, mProfile, currentState);
 
 	//Render Text and buttons
-	dglSetBitmapModulation(mProfile->mFontColor);
+	dglSetBitmapModulation(getFontColor(mProfile, currentState));
 	RectI fillRectTitle = applyBorders(ctrlRectTitle.point, ctrlRectTitle.extent, currentState, mProfile);
 	RectI contentRectTitle = applyPadding(fillRectTitle.point, fillRectTitle.extent, currentState, mProfile);
 

+ 1 - 1
engine/source/gui/editor/guiMenuBarCtrl.cc

@@ -815,7 +815,7 @@ void GuiMenuItemCtrl::onRender(Point2I offset, const RectI& updateRect)
 	renderUniversalRect(ctrlRect, mProfile, currentState);
 
 	//Render Text
-	dglSetBitmapModulation(mProfile->getFontColor(currentState));
+	dglSetBitmapModulation(getFontColor(mProfile, currentState));
 	RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mProfile);
 	RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mProfile);
 	renderText(contentRect.point, contentRect.extent, mText, mProfile);

+ 10 - 1
engine/source/gui/guiControl.cc

@@ -100,6 +100,8 @@ GuiControl::GuiControl()
    mAlignment           = AlignmentType::DefaultAlign;
    mVAlignment          = VertAlignmentType::DefaultVAlign;
    mFontSizeAdjust      = 1;
+   mFontColor.set(0, 0, 0, 255);
+   mOverrideFontColor   = false;
 
    mLangTable           = NULL;
    mFirstResponder      = NULL;
@@ -231,6 +233,8 @@ void GuiControl::initPersistFields()
    addField("align", TypeEnum, Offset(mAlignment, GuiControl), 1, &gAlignCtrlTable);
    addField("vAlign", TypeEnum, Offset(mVAlignment, GuiControl), 1, &gVAlignCtrlTable);
    addField("fontSizeAdjust", TypeF32, Offset(mFontSizeAdjust, GuiControl), "A decimal value that is multiplied with the profile's fontSize to determine the control's actual font size.");
+   addField("fontColor", TypeColorI, Offset(mFontColor, GuiControl), "A color to override the font color of the control's profile. OverrideFontColor must be set to true for this to work.");
+   addField("overrideFontColor", TypeBool, Offset(mOverrideFontColor, GuiControl), "If true, the control's fontColor will override the profile's font color.");
    endGroup("Text");
 }
 
@@ -559,7 +563,7 @@ void GuiControl::onRender(Point2I offset, const RectI &updateRect)
 	renderUniversalRect(ctrlRect, mProfile, NormalState);
 
 	//Render Text
-	dglSetBitmapModulation(mProfile->mFontColor);
+	dglSetBitmapModulation(getFontColor(mProfile));
 	RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, NormalState, mProfile);
 	RectI contentRect = applyPadding(fillRect.point, fillRect.extent, NormalState, mProfile);
 
@@ -2057,4 +2061,9 @@ VertAlignmentType GuiControl::getVertAlignmentType()
 VertAlignmentType GuiControl::getVertAlignmentType(GuiControlProfile* profile)
 {
     return mVAlignment == VertAlignmentType::DefaultVAlign ? profile->mVAlignment : mVAlignment;
+}
+
+const ColorI& GuiControl::getFontColor(GuiControlProfile* profile, const GuiControlState state)
+{
+    return mOverrideFontColor ? mFontColor : profile->getFontColor(state);
 }

+ 3 - 0
engine/source/gui/guiControl.h

@@ -213,6 +213,8 @@ protected:
     AlignmentType       mAlignment;
     VertAlignmentType   mVAlignment;
     F32                 mFontSizeAdjust;
+    ColorI              mFontColor;
+    bool                mOverrideFontColor;
 
     /// @}
 
@@ -776,6 +778,7 @@ protected:
     VertAlignmentType getVertAlignmentType();
     AlignmentType getAlignmentType(GuiControlProfile* profile);
     VertAlignmentType getVertAlignmentType(GuiControlProfile* profile);
+    const ColorI& getFontColor(GuiControlProfile* profile, const GuiControlState state = GuiControlState::NormalState);
 };
 /// @}
 

+ 1 - 1
engine/source/gui/guiListBoxCtrl.cc

@@ -679,7 +679,7 @@ void GuiListBoxCtrl::onRenderItem( RectI &itemRect, LBItem *item )
    renderUniversalRect(ctrlRect, mProfile, currentState);
 
    //Render Text
-   dglSetBitmapModulation(mProfile->getFontColor(currentState));
+   dglSetBitmapModulation(getFontColor(mProfile, currentState));
    RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mProfile);
    RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mProfile);
 

+ 1 - 1
engine/source/gui/guiProgressCtrl.cc

@@ -119,7 +119,7 @@ void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect)
 	renderUniversalRect(ctrlRect, mProfile, currentState);
 
 	//Render Text
-	dglSetBitmapModulation(mProfile->getFontColor(currentState));
+	dglSetBitmapModulation(getFontColor(mProfile, currentState));
 	RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState, mProfile);
 	RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState, mProfile);
 

+ 1 - 1
engine/source/gui/guiSliderCtrl.cc

@@ -460,7 +460,7 @@ void GuiSliderCtrl::onRender(Point2I offset, const RectI &updateRect)
         else if (textStart.x + txt_w > offset.x + mBounds.extent.x)
             textStart.x -= ((textStart.x + txt_w) - (offset.x + mBounds.extent.x));
 
-        dglSetBitmapModulation(mProfile->mFontColor);
+        dglSetBitmapModulation(getFontColor(mProfile));
         dglDrawText(mProfile->getFont(mFontSizeAdjust), textStart, buf, mProfile->mFontColors);
     }
     renderChildControls(offset, mBounds, updateRect);