Add support for foreground and background colors to DoDrawText
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21878 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -110,6 +110,20 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
|
|||||||
[sm_cocoaNSTextStorage setAttributedString:attributedString];
|
[sm_cocoaNSTextStorage setAttributedString:attributedString];
|
||||||
[attributedString release];
|
[attributedString release];
|
||||||
|
|
||||||
|
// Set the color (and later font) attributes
|
||||||
|
NSColor *fgColor = m_textForegroundColour.GetNSColor();
|
||||||
|
NSColor *bgColor = m_textBackgroundColour.GetNSColor();
|
||||||
|
if(!fgColor)
|
||||||
|
fgColor = [NSColor clearColor];
|
||||||
|
if(!bgColor)
|
||||||
|
bgColor = [NSColor clearColor];
|
||||||
|
NSDictionary *attrDict = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||||
|
fgColor, NSForegroundColorAttributeName,
|
||||||
|
bgColor, NSBackgroundColorAttributeName,
|
||||||
|
nil];
|
||||||
|
[sm_cocoaNSTextStorage addAttributes: attrDict range:NSMakeRange(0,[sm_cocoaNSTextStorage length])];
|
||||||
|
[attrDict release];
|
||||||
|
|
||||||
NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer];
|
NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer];
|
||||||
NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer];
|
NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer];
|
||||||
// NOTE: We'll crash trying to get the location of glyphAtIndex:0 if
|
// NOTE: We'll crash trying to get the location of glyphAtIndex:0 if
|
||||||
@@ -150,8 +164,8 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
|
|||||||
layoutLocation.x = 0.0;
|
layoutLocation.x = 0.0;
|
||||||
layoutLocation.y *= -1.0;
|
layoutLocation.y *= -1.0;
|
||||||
layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0];
|
layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0];
|
||||||
// NOTE: That's NSMakePoint, not NSMakePint (working on that though)
|
if(m_backgroundMode==wxSOLID)
|
||||||
[m_textForegroundColour.GetNSColor() set];
|
[sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint];
|
||||||
[sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation];
|
[sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation];
|
||||||
|
|
||||||
[context restoreGraphicsState];
|
[context restoreGraphicsState];
|
||||||
|
Reference in New Issue
Block a user