[vlc-commits] Windowed Mac Plugin: added a basic draft for a controller toolbar
Felix Paul Kühne
git at videolan.org
Tue Jan 1 21:27:41 CET 2013
npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Tue Jan 1 21:27:18 2013 +0100| [42d88288ffa90a38830b3e6e9d6b8436a2ae5ab1] | committer: Felix Paul Kühne
Windowed Mac Plugin: added a basic draft for a controller toolbar
> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=42d88288ffa90a38830b3e6e9d6b8436a2ae5ab1
---
npapi/Makefile.am | 1 +
npapi/vlcplugin_mac.mm | 163 +++++++++++++++++++++++++---
share/pixmaps/macosx/Knob.png | Bin 0 -> 1192 bytes
share/pixmaps/macosx/Pause.png | Bin 0 -> 2002 bytes
share/pixmaps/macosx/Play.png | Bin 0 -> 1975 bytes
share/pixmaps/macosx/SliderTrackCenter.png | Bin 0 -> 410 bytes
share/pixmaps/macosx/SliderTrackLeft.png | Bin 0 -> 493 bytes
share/pixmaps/macosx/SliderTrackRight.png | Bin 0 -> 490 bytes
8 files changed, 146 insertions(+), 18 deletions(-)
diff --git a/npapi/Makefile.am b/npapi/Makefile.am
index c891746..abd6597 100644
--- a/npapi/Makefile.am
+++ b/npapi/Makefile.am
@@ -175,6 +175,7 @@ VLC\ Plugin.plugin: $(lib_LTLIBRARIES)
rm -Rf "$@"
$(INSTALL) -d "VLC-Plugin.plugin/Contents/MacOS/lib"
$(INSTALL) -d "VLC-Plugin.plugin/Contents/Resources"
+ $(INSTALL) $(top_srcdir)/share/pixmaps/macosx/*.png "VLC-Plugin.plugin/Contents/Resources"
ACTION="release-makefile" PRODUCT="VLC-Plugin.plugin" libvlc_dir=$(LIBVLC_PREFIX) src_dir=$(srcdir) build_dir=$(top_builddir) sh "$(top_srcdir)/extras/macosx/build-package.sh"
$(INSTALL) "$(top_builddir)/extras/macosx/Info.plist" "VLC-Plugin.plugin/Contents/Info.plist"
mv "VLC-Plugin.plugin" "VLC Plugin.plugin"
diff --git a/npapi/vlcplugin_mac.mm b/npapi/vlcplugin_mac.mm
index 2d28821..390aa62 100644
--- a/npapi/vlcplugin_mac.mm
+++ b/npapi/vlcplugin_mac.mm
@@ -31,14 +31,26 @@
#include <QuartzCore/QuartzCore.h>
+ at interface VLCNoMediaLayer : CALayer {
+}
+
+ at end
+
@interface VLCControllerLayer : CALayer {
- BOOL b_nomedia;
+ CGImageRef _playImage;
+ CGImageRef _pauseImage;
+
+ CGImageRef _sliderTrackLeft;
+ CGImageRef _sliderTrackRight;
+ CGImageRef _sliderTrackCenter;
+
+ CGImageRef _knob;
}
- at property (readwrite) BOOL noMedia;
@end
static CALayer * rootLayer;
+static VLCNoMediaLayer * noMediaLayer;
static VLCControllerLayer * controllerLayer;
VlcPluginMac::VlcPluginMac(NPP instance, NPuint16_t mode) :
@@ -100,11 +112,12 @@ bool VlcPluginMac::destroy_windows()
NPError VlcPluginMac::get_root_layer(void *value)
{
+ noMediaLayer = [[VLCNoMediaLayer alloc] init];
+ noMediaLayer.opaque = 1.;
+ [rootLayer addSublayer: noMediaLayer];
+
controllerLayer = [[VLCControllerLayer alloc] init];
controllerLayer.opaque = 1.;
- controllerLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
- [controllerLayer setNoMedia:YES];
-
[rootLayer addSublayer: controllerLayer];
*(CALayer **)value = rootLayer;
@@ -175,21 +188,19 @@ bool VlcPluginMac::handle_event(void *event)
return VlcPluginBase::handle_event(event);
}
- at implementation VLCControllerLayer
- at synthesize noMedia=b_nomedia;
+ at implementation VLCNoMediaLayer
- (id)init
{
if (self = [super init]) {
self.needsDisplayOnBoundsChange = YES;
- self.frame = CGRectMake(0, 0, 0, 25);
- self.autoresizingMask = kCALayerWidthSizable;
+ self.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
}
return self;
}
-- (void)drawNoMedia:(CGContextRef)cgContext
+- (void)drawInContext:(CGContextRef)cgContext
{
float windowWidth = self.visibleRect.size.width;
float windowHeight = self.visibleRect.size.height;
@@ -254,16 +265,132 @@ bool VlcPluginMac::handle_event(void *event)
CGContextRestoreGState(cgContext);
}
-- (void)drawInContext:(CGContextRef)cgContext
+ at end
+
+ at implementation VLCControllerLayer
+
+static CGImageRef createImageNamed(NSString *name)
{
- if (self.noMedia)
- [self drawNoMedia:cgContext];
- else {
- CGContextSaveGState(cgContext);
- CGContextSetFillColorWithColor(cgContext, CGColorGetConstantColor(kCGColorBlack));
- CGContextFillRect(cgContext, self.bounds);
- CGContextRestoreGState(cgContext);
+ CFURLRef url = CFBundleCopyResourceURL(CFBundleGetBundleWithIdentifier(CFSTR("com.netscape.vlc")), (CFStringRef)name, CFSTR("png"), NULL);
+
+ if (!url)
+ return NULL;
+
+ CGImageSourceRef imageSource = CGImageSourceCreateWithURL(url, NULL);
+ if (!imageSource)
+ return NULL;
+
+ CGImageRef image = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
+ CFRelease(imageSource);
+
+ return image;
+}
+
+- (id)init
+{
+ if (self = [super init]) {
+ self.needsDisplayOnBoundsChange = YES;
+ self.frame = CGRectMake(0, 0, 0, 25);
+ self.autoresizingMask = kCALayerWidthSizable;
+
+ _playImage = createImageNamed(@"Play");
+ _pauseImage = createImageNamed(@"Pause");
+ _sliderTrackLeft = createImageNamed(@"SliderTrackLeft");
+ _sliderTrackRight = createImageNamed(@"SliderTrackRight");
+ _sliderTrackCenter = createImageNamed(@"SliderTrackCenter");
+
+ _knob = createImageNamed(@"Knob");
}
+
+ return self;
+}
+
+- (void)dealloc
+{
+ CGImageRelease(_playImage);
+ CGImageRelease(_pauseImage);
+
+ CGImageRelease(_sliderTrackLeft);
+ CGImageRelease(_sliderTrackRight);
+ CGImageRelease(_sliderTrackCenter);
+
+ CGImageRelease(_knob);
+
+ [super dealloc];
+}
+
+- (CGRect)_playPauseButtonRect
+{
+ return CGRectMake(0, 0, 25, 25);
+}
+
+- (CGRect)_sliderRect
+{
+ CGFloat sliderYPosition = (self.bounds.size.height - CGImageGetHeight(_sliderTrackLeft)) / 2.0;
+ CGFloat playPauseButtonWidth = [self _playPauseButtonRect].size.width;
+
+ return CGRectMake(playPauseButtonWidth, sliderYPosition,
+ self.bounds.size.width - playPauseButtonWidth - 7, CGImageGetHeight(_sliderTrackLeft));
+}
+
+- (CGRect)_sliderThumbRect
+{
+ CGRect sliderRect = [self _sliderRect];
+
+ CGFloat fraction = 0.0;
+/* if (_movie)
+ fraction = [self _currentTime] / [self _duration];*/
+
+ CGFloat x = fraction * (CGRectGetWidth(sliderRect) - CGImageGetWidth(_knob));
+
+ return CGRectMake(CGRectGetMinX(sliderRect) + x, CGRectGetMinY(sliderRect) - 1,
+ CGImageGetWidth(_knob), CGImageGetHeight(_knob));
+}
+
+- (CGRect)_innerSliderRect
+{
+ return CGRectInset([self _sliderRect], CGRectGetWidth([self _sliderThumbRect]) / 2, 0);
+}
+
+- (void)_drawPlayPauseButtonInContext:(CGContextRef)context
+{
+ CGContextDrawImage(context, [self _playPauseButtonRect], _playImage); //playlist_isplaying() ? _pauseImage;
+}
+
+- (void)_drawSliderInContext:(CGContextRef)context
+{
+ // Draw the thumb
+ CGRect sliderThumbRect = [self _sliderThumbRect];
+ CGContextDrawImage(context, sliderThumbRect, _knob);
+
+ CGRect sliderRect = [self _sliderRect];
+
+ // Draw left part
+ CGRect sliderLeftTrackRect = CGRectMake(CGRectGetMinX(sliderRect), CGRectGetMinY(sliderRect),
+ CGImageGetWidth(_sliderTrackLeft), CGImageGetHeight(_sliderTrackLeft));
+ CGContextDrawImage(context, sliderLeftTrackRect, _sliderTrackLeft);
+
+ // Draw center part
+ CGRect sliderCenterTrackRect = CGRectInset(sliderRect, CGImageGetWidth(_sliderTrackLeft), 0);
+ CGContextDrawImage(context, sliderCenterTrackRect, _sliderTrackCenter);
+
+ // Draw right part
+ CGRect sliderRightTrackRect = CGRectMake(CGRectGetMaxX(sliderCenterTrackRect), CGRectGetMinY(sliderRect),
+ CGImageGetWidth(_sliderTrackRight), CGImageGetHeight(_sliderTrackRight));
+ CGContextDrawImage(context, sliderRightTrackRect, _sliderTrackRight);
+
+}
+
+- (void)drawInContext:(CGContextRef)cgContext
+{
+ CGContextSaveGState(cgContext);
+ CGContextSetFillColorWithColor(cgContext, CGColorGetConstantColor(kCGColorBlack));
+ CGContextFillRect(cgContext, self.bounds);
+ CGContextRestoreGState(cgContext);
+
+ [self _drawPlayPauseButtonInContext:cgContext];
+ [self _drawSliderInContext:cgContext];
}
@end
+
diff --git a/share/pixmaps/macosx/Knob.png b/share/pixmaps/macosx/Knob.png
new file mode 100644
index 0000000..0ec2ab6
Binary files /dev/null and b/share/pixmaps/macosx/Knob.png differ
diff --git a/share/pixmaps/macosx/Pause.png b/share/pixmaps/macosx/Pause.png
new file mode 100644
index 0000000..ad06f06
Binary files /dev/null and b/share/pixmaps/macosx/Pause.png differ
diff --git a/share/pixmaps/macosx/Play.png b/share/pixmaps/macosx/Play.png
new file mode 100644
index 0000000..0b28903
Binary files /dev/null and b/share/pixmaps/macosx/Play.png differ
diff --git a/share/pixmaps/macosx/SliderTrackCenter.png b/share/pixmaps/macosx/SliderTrackCenter.png
new file mode 100644
index 0000000..02b9711
Binary files /dev/null and b/share/pixmaps/macosx/SliderTrackCenter.png differ
diff --git a/share/pixmaps/macosx/SliderTrackLeft.png b/share/pixmaps/macosx/SliderTrackLeft.png
new file mode 100644
index 0000000..2c3669c
Binary files /dev/null and b/share/pixmaps/macosx/SliderTrackLeft.png differ
diff --git a/share/pixmaps/macosx/SliderTrackRight.png b/share/pixmaps/macosx/SliderTrackRight.png
new file mode 100644
index 0000000..acd6f70
Binary files /dev/null and b/share/pixmaps/macosx/SliderTrackRight.png differ
More information about the vlc-commits
mailing list