Ver Fonte

TextEdit Support for FontColor Override

When the ability to override font colors was introduced, it did not apply to text boxes. This update causes it to apply to text boxes.
Peter Robinson há 3 anos atrás
pai
commit
dd6db8cdff

+ 15 - 8
engine/source/gui/guiTextEditCtrl.cc

@@ -45,7 +45,7 @@ GuiTextEditTextBlock::GuiTextEditTextBlock()
     mLineStartIbeamValue = 0;
     mLineStartIbeamValue = 0;
 }
 }
 
 
-void GuiTextEditTextBlock::render(const RectI& bounds, string line, U32 ibeamStartValue, GuiControlProfile* profile, GuiControlState currentState, GuiTextEditSelection& selector, AlignmentType align, GFont* font)
+void GuiTextEditTextBlock::render(const RectI& bounds, string line, U32 ibeamStartValue, GuiControlProfile* profile, GuiControlState currentState, GuiTextEditSelection& selector, AlignmentType align, GFont* font, bool overrideFontColor)
 {
 {
     mGlobalBounds.set(bounds.point, bounds.extent);
     mGlobalBounds.set(bounds.point, bounds.extent);
     mText.assign(line);
     mText.assign(line);
@@ -63,9 +63,9 @@ void GuiTextEditTextBlock::render(const RectI& bounds, string line, U32 ibeamSta
 
 
         processTextAlignment(line, font, align);
         processTextAlignment(line, font, align);
         Point2I movingStartPoint = getGlobalTextStart();
         Point2I movingStartPoint = getGlobalTextStart();
-        movingStartPoint.x += renderTextSection(movingStartPoint, 0, lengthOfPreBlockText, profile, currentState, font);
-        movingStartPoint.x += renderTextSection(movingStartPoint, lengthOfPreBlockText, lengthOfHighlightBlockText, profile, currentState, font, true);
-        movingStartPoint.x += renderTextSection(movingStartPoint, lengthOfPreBlockText + lengthOfHighlightBlockText, lengthOfPostBlockText, profile, currentState, font);
+        movingStartPoint.x += renderTextSection(movingStartPoint, 0, lengthOfPreBlockText, profile, currentState, font, false, overrideFontColor);
+        movingStartPoint.x += renderTextSection(movingStartPoint, lengthOfPreBlockText, lengthOfHighlightBlockText, profile, currentState, font, true, overrideFontColor);
+        movingStartPoint.x += renderTextSection(movingStartPoint, lengthOfPreBlockText + lengthOfHighlightBlockText, lengthOfPostBlockText, profile, currentState, font, false, overrideFontColor);
     }
     }
 
 
     Point2I textStartPoint = getGlobalTextStart();
     Point2I textStartPoint = getGlobalTextStart();
@@ -76,7 +76,7 @@ void GuiTextEditTextBlock::render(const RectI& bounds, string line, U32 ibeamSta
     }
     }
 }
 }
 
 
-U32 GuiTextEditTextBlock::renderTextSection(const Point2I& startPoint, const U32 subStrStart, const U32 subStrLen, GuiControlProfile* profile, const GuiControlState currentState, GFont* font, bool isSelectedText)
+U32 GuiTextEditTextBlock::renderTextSection(const Point2I& startPoint, const U32 subStrStart, const U32 subStrLen, GuiControlProfile* profile, const GuiControlState currentState, GFont* font, bool isSelectedText, bool overrideFontColor)
 {
 {
     if (subStrLen != 0)
     if (subStrLen != 0)
     {
     {
@@ -85,11 +85,14 @@ U32 GuiTextEditTextBlock::renderTextSection(const Point2I& startPoint, const U32
         Point2I pointToDraw = Point2I(startPoint.x, startPoint.y);
         Point2I pointToDraw = Point2I(startPoint.x, startPoint.y);
         if (isSelectedText)
         if (isSelectedText)
         {
         {
-            dglSetBitmapModulation(profile->mFontColorTextSL);
+            if (!overrideFontColor)
+            {
+                dglSetBitmapModulation(profile->mFontColorTextSL);
+            }
             RectI highlightRect = RectI(pointToDraw.x, pointToDraw.y, blockStrWidth, mGlobalBounds.extent.y);
             RectI highlightRect = RectI(pointToDraw.x, pointToDraw.y, blockStrWidth, mGlobalBounds.extent.y);
             dglDrawRectFill(highlightRect, profile->mFillColorTextSL);
             dglDrawRectFill(highlightRect, profile->mFillColorTextSL);
         }
         }
-        else
+        else if(!overrideFontColor)
         {
         {
             const ColorI& fontColor = profile->getFontColor(currentState);
             const ColorI& fontColor = profile->getFontColor(currentState);
             dglSetBitmapModulation(fontColor);
             dglSetBitmapModulation(fontColor);
@@ -1060,7 +1063,11 @@ void GuiTextEditCtrl::renderLineList(const Point2I& offset, const Point2I& exten
         Point2I start = Point2I(0, offsetY);
         Point2I start = Point2I(0, offsetY);
         Point2I blockExtent = Point2I(extent.x, textHeight);
         Point2I blockExtent = Point2I(extent.x, textHeight);
         RectI blockBounds = RectI(start + offset + profile->mTextOffset, blockExtent);
         RectI blockBounds = RectI(start + offset + profile->mTextOffset, blockExtent);
-        mTextBlockList[i].render(blockBounds, lineList[i], ibeamPos, mProfile, getCurrentState(), mSelector, getAlignmentType(), font);
+        if (mOverrideFontColor)
+        {
+            dglSetBitmapModulation(getFontColor(profile, NormalState));
+        }
+        mTextBlockList[i].render(blockBounds, lineList[i], ibeamPos, mProfile, getCurrentState(), mSelector, getAlignmentType(), font, mOverrideFontColor);
 
 
         offsetY += textHeight;
         offsetY += textHeight;
         ibeamPos += lineList[i].length();
         ibeamPos += lineList[i].length();

+ 2 - 2
engine/source/gui/guiTextEditCtrl.h

@@ -85,8 +85,8 @@ public:
 	inline const U32 getStartValue() const { return mLineStartIbeamValue; }
 	inline const U32 getStartValue() const { return mLineStartIbeamValue; }
 	inline RectI getGlobalBounds() const { return mGlobalBounds; }
 	inline RectI getGlobalBounds() const { return mGlobalBounds; }
 	inline Point2I getGlobalTextStart() { return Point2I(mGlobalBounds.point.x + mTextOffsetX - mTextScrollX, mGlobalBounds.point.y); }
 	inline Point2I getGlobalTextStart() { return Point2I(mGlobalBounds.point.x + mTextOffsetX - mTextScrollX, mGlobalBounds.point.y); }
-	void render(const RectI& bounds, string line, U32 ibeamStartValue, GuiControlProfile* profile, GuiControlState currentState, GuiTextEditSelection& selector, AlignmentType align, GFont* font);
-	U32 renderTextSection(const Point2I& startPoint, const U32 subStrStart, const U32 subStrLen, GuiControlProfile* profile, const GuiControlState currentState, GFont* font, bool isSelectedText = false);
+	void render(const RectI& bounds, string line, U32 ibeamStartValue, GuiControlProfile* profile, GuiControlState currentState, GuiTextEditSelection& selector, AlignmentType align, GFont* font, bool overrideFontColor = false);
+	U32 renderTextSection(const Point2I& startPoint, const U32 subStrStart, const U32 subStrLen, GuiControlProfile* profile, const GuiControlState currentState, GFont* font, bool isSelectedText = false, bool overrideFontColor = false);
 	void performScrollJumpX(const S32 targetX, const S32 areaStart, const S32 areaEnd);
 	void performScrollJumpX(const S32 targetX, const S32 areaStart, const S32 areaEnd);
 	U32 calculateIbeamPositionInLine(const S32 targetX, GFont* font);
 	U32 calculateIbeamPositionInLine(const S32 targetX, GFont* font);
 	inline bool calculateCursorAtEOL(const U32 cursorPos) { return cursorPos == mText.length(); }
 	inline bool calculateCursorAtEOL(const U32 cursorPos) { return cursorPos == mText.length(); }