Recent

Author Topic: NSView?  (Read 7784 times)

Hansaplast

  • Hero Member
  • *****
  • Posts: 674
  • Tweaking4All.com
    • Tweaking4All
NSView?
« on: August 01, 2012, 08:27:48 pm »
I'm not 100% sure if this is the correct place to ask, but does anyone have experience with using NSView?

I have the impression it's Cocoa specific and would need it to be able to embed VLClib on my LCL form.
(see my other post in the Carbon section - I apologize for potential cross posting)

This is the code where I get stuck by lack of experience and knowledge of NSView:

Code: [Select]
libvlc_media_player_set_nsobject_t =  procedure(
    p_mi: libvlc_media_player_t_ptr;
    drawable: Pointer
  );

The drawable pointer seems to be an NSView or something following the VLCOpenGLVideoViewEmbedding protocol (of which I know even less).

This is the "source" of my information (PasLibVlc source):

Code: [Select]
(**
 * Set the NSView handler where the media player should render its video output.
 *
 * Use the vout called "macosx".
 *
 * The drawable is an NSObject that follow the VLCOpenGLVideoViewEmbedding
 * protocol:
 *)

 // \@protocol VLCOpenGLVideoViewEmbedding <NSObject>
 // - (void)addVoutSubview:(NSView *)view;
 // - (void)removeVoutSubview:(NSView *)view;
 // \@end

 (*
 * Or it can be an NSView object.
 *
 * If you want to use it along with Qt4 see the QMacCocoaViewContainer. Then
 * the following code should work:
 * @begincode
 * {
 *     NSView *video = [[NSView alloc] init];
 *     QMacCocoaViewContainer *container = new QMacCocoaViewContainer(video, parent);
 *     libvlc_media_player_set_nsobject(mp, video);
 *     [video release];
 * }
 * @endcode
 *
 * You can find a live example in VLCVideoView in VLCKit.framework.
 *
 * \param p_mi the Media Player
 * \param drawable the drawable that is either an NSView or an object following
 * the VLCOpenGLVideoViewEmbedding protocol.
 *)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: NSView?
« Reply #1 on: April 23, 2014, 11:44:42 am »
hehhe, this is very old, but I will answer in case another person needs.

To get a NSView to place a control, you need to place in your form some kind of empty windowed control (which means a TWinControl descendent, which has a handle property). The best would be writing your own TCustomControl in code, and search the wiki for instructions for that. But if you are more lazy, just use a TPanel or TPaintBox or maybe TImage.

Then to obtain the NSView from a particular control:
1> Make sure you are using the LCL-Cocoa widgetset
2> use this function from unit CocoaUtils:

function GetNSObjectView(obj: NSObject): NSView;

Like this:

uses CocoaAll, CocoaUtils;

var
  MyControl: TCustomControl;
  MyControlNSView: NSView;
begin
  MyControlNSView := CocoaUtils.GetNSObjectView(NSObject(MyControl.Handle));

and ready to use the NSView! =D
« Last Edit: April 23, 2014, 11:59:29 am by felipemdc »

 

TinyPortal © 2005-2018