[vlc-commits] mac plugin: add support for the optional 'text' element
Felix Paul Kühne
git at videolan.org
Mon Feb 17 23:10:23 CET 2014
npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon Feb 17 23:10:26 2014 +0100| [535149194d230dcd653c6f534036ad9886233758] | committer: Felix Paul Kühne
mac plugin: add support for the optional 'text' element
> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=535149194d230dcd653c6f534036ad9886233758
---
npapi/vlcplugin_mac.mm | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/npapi/vlcplugin_mac.mm b/npapi/vlcplugin_mac.mm
index db6a8b1..0894825 100644
--- a/npapi/vlcplugin_mac.mm
+++ b/npapi/vlcplugin_mac.mm
@@ -565,11 +565,54 @@ bool VlcPluginMac::handle_event(void *event)
}
CGContextDrawImage(cgContext, CGRectMake((windowWidth - coneWidth) / 2., (windowHeight - coneHeight) / 2., coneWidth, coneHeight), cone);
CGImageRelease(cone);
+
+ // draw custom text
+ values[0] = CTFontCreateWithName(CFSTR("Helvetica"),14,NULL);
+ stylesDict = CFDictionaryCreate(kCFAllocatorDefault,
+ (const void **)&keys,
+ (const void **)&values,
+ 2, NULL, NULL);
+ const char *text = self.cppPlugin->get_options().get_bg_text().c_str();
+ if (text != NULL) {
+ attRef = CFAttributedStringCreate(kCFAllocatorDefault, CFStringCreateWithCString(kCFAllocatorDefault, text, kCFStringEncodingUTF8), stylesDict);
+ textLine = CTLineCreateWithAttributedString(attRef);
+ CGRect textRect = CTLineGetImageBounds(textLine, cgContext);
+ CGContextSetTextPosition(cgContext, ((windowWidth - textRect.size.width) / 2.), (windowHeight / 2.) + (coneHeight / 2.) + textRect.size.height + 50.);
+ CTLineDraw(textLine, cgContext);
+ CFRelease(textLine);
+ CFRelease(attRef);
+ }
+ CFRelease(stylesDict);
#else
// draw a background colored rect
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
CGContextSetFillColorWithColor(cgContext, backgroundColor);
CGContextDrawPath(cgContext, kCGPathFill);
+
+ const char *text = self.cppPlugin->get_options().get_bg_text().c_str();
+ if (text != NULL) {
+ CGContextSetGrayStrokeColor(cgContext, .95, 1.);
+ CGContextSetTextDrawingMode(cgContext, kCGTextFill);
+ CGContextSetGrayFillColor(cgContext, 1., 1.);
+ CFStringRef keys[2];
+ keys[0] = kCTFontAttributeName;
+ keys[1] = kCTForegroundColorFromContextAttributeName;
+ CFTypeRef values[2];
+ values[0] = CTFontCreateWithName(CFSTR("Helvetica Neue Light"),18,NULL);
+ values[1] = kCFBooleanTrue;
+ CFDictionaryRef stylesDict = CFDictionaryCreate(kCFAllocatorDefault,
+ (const void **)&keys,
+ (const void **)&values,
+ 2, NULL, NULL);
+ CFAttributedStringRef attRef = CFAttributedStringCreate(kCFAllocatorDefault, CFStringCreateWithCString(kCFAllocatorDefault, text, kCFStringEncodingUTF8), stylesDict);
+ CTLineRef textLine = CTLineCreateWithAttributedString(attRef);
+ CGRect textRect = CTLineGetImageBounds(textLine, cgContext);
+ CGContextSetTextPosition(cgContext, ((windowWidth - textRect.size.width) / 2.), (windowHeight / 2.));
+ CTLineDraw(textLine, cgContext);
+ CFRelease(textLine);
+ CFRelease(attRef);
+ CFRelease(stylesDict);
+ }
#endif
CGColorRelease(backgroundColor);
More information about the vlc-commits
mailing list