Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Several questions about Quartz, Carbon, Cocoa, and NSImages.

Several questions about Quartz, Carbon, Cocoa, and NSImages.
Thread Tools
Senior User
Join Date: Apr 2001
Location: Bolingbrook, IL, USA
Status: Offline
Reply With Quote
Jun 30, 2002, 04:19 PM
 
I'm trying to make a QuickTime movie play in my application's dock icon. So far, I've gotten it to each frame into a PicHandle. As it is, my code looks like this:

Controller.h
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> /* Controller */

#import &lt;Cocoa/Cocoa.h&gt;

@interface Controller : NSObject
{
IBOutlet id sourceField;
}
- (IBAction)startPlayingid)sender;
-(void)playThreadNSString*)string;
@end
</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Controller.m
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> #import &quot;Controller.h&quot;
#import &lt;QuickTime/QuickTime.h&gt;
#import &quot;DockHandler.h&quot;
@implementation Controller

- (IBAction)startPlayingid)sender
{
NSLog([sourceField stringValue]);
[NSThread detachNewThreadSelector:@selector(playThread
toTarget:self
withObject:[sourceField stringValue]];
}
-(void)playThreadNSString*)string {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
TimeValue x;
TimeValue duration;
PicHandle thePicture;
NSURL *url = [[NSURL alloc] initFileURLWithPath:@&quot;~/Movies/Xpalm.mp4&quot;];
NSMovie *movie=[[NSMovie alloc] initWithURL:url byReference:YES];
//[NSString stringWithFormat:@&quot;file://%@/%@&quot;,NSHomeDirectory,string] byReference:YES];
if(movie !=nil) {
Movie theMovie = [movie QTMovie];
NSLog(string);
[movie release];
EnterMovies();
duration = GetMovieDuration(theMovie);
while(x&lt;duration) {
thePicture = GetMoviePict( theMovie, x );
SetDockIcon( thePicture );
x++;
}
ExitMovies();
}
[pool release];
}
@end
</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">DockHandler.h
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> /*
* DockHandler.h
* WidgetTest
*
* Created by Chris Serino on Fri Jun 30 2000.
* Copyright (c) 2000 __MyCompanyName__. All rights reserved.
*
*/

#include &lt;Carbon/Carbon.h&gt;

void SetDockIcon( PicHandle theBadge ); </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">DockHandler.c
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">
#include &lt;Carbon/Carbon.h&gt;
#include &quot;DockHandler.h&quot;

void SetDockIcon( PicHandle theBadge )
{
OSStatus theErr;
PicHandle theBadgeMask;
GWorldPtr theBadgeWorld;
GWorldPtr theBadgeMaskWorld;

Rect theRect = { 0, 0, 128, 128 };
CGImageRef theBadgeImage;
GDHandle theSavedDevice;
GrafPtr theSavedPort;

// ***
//
// PITFALL!
//
// Rebadging the tile will composite over the old one!
// You might want to restore the tile before badging.
//
// ***

require( theBadge != NULL, CantLoadBadge );

// Make some GWorlds
theErr = NewGWorld( &amp;theBadgeWorld, 32, &amp;theRect, NULL, NULL, 0 );
require_noerr( theErr, CantMakeBadgeWorld );
theErr = NewGWorld( &amp;theBadgeMaskWorld, 32, &amp;theRect, NULL, NULL, 0 );
require_noerr( theErr, CantMakeBadgeMaskWorld );

// Draw the pictures into the GWorlds
GetGWorld( &amp;theSavedPort, &amp;theSavedDevice );
SetGWorld( theBadgeWorld, NULL );
DrawPicture( theBadge, &amp;theRect );
SetGWorld( theBadgeMaskWorld, NULL );
ForeColor( whiteColor );
PaintRect( &amp;theRect );
SetGWorld( theSavedPort, theSavedDevice );

// ***
//
// Make a CGImage from the GWorlds' pixmaps
//
// ***
theErr = CreateCGImageFromPixMaps( GetGWorldPixMap( theBadgeWorld ),
GetGWorldPixMap( theBadgeMaskWorld ), &amp;theBadgeImage );
if ( theErr != noErr )
SysBeep( 0 );
require_noerr( theErr, CantMakeBadgeImage );

// ***
//
// Badge the tile
//
// ***
theErr = OverlayApplicationDockTileImage( theBadgeImage );

if ( theBadgeImage != NULL )
CGImageRelease( theBadgeImage );
CantMakeBadgeMaskWorld:
;
CantMakeBadgeImage:
DisposeGWorld( theBadgeMaskWorld );

CantMakeBadgeWorld:
ReleaseResource( (Handle) theBadgeMask );

CantLoadBadgeMask:
ReleaseResource( (Handle) theBadge );

CantLoadBadge:
;
} </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I know my code is the ugliest thing since the OW icon (j/k I like it, but I couldn't think of anything else), but I'm somewhat of a n00b. Right now I get a linking error. Thanks for your help!

edit: Forgot about my NSImage question. Is there any way to put a PicHandle into an NSImage so I can just use NSApp's setApplicationDockTileImageBlahBlahBlah: method? Again, thanks for your help.

<small>[ 06-30-2002, 05:21 PM: Message edited by: oVeRmInD911 ]</small>
     
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Jun 30, 2002, 08:53 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by oVeRmInD911:
<strong>I know my code is the ugliest thing since the OW icon (j/k I like it, but I couldn't think of anything else), but I'm somewhat of a n00b. Right now I get a linking error. Thanks for your help!
</strong>
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Could you be more specific? A "linking error" could be about a million different things. What does it complain about in the build log?

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">
<strong>
edit: Forgot about my NSImage question. Is there any way to put a PicHandle into an NSImage so I can just use NSApp's setApplicationDockTileImageBlahBlahBlah: method? Again, thanks for your help.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Create an NSPictImageRep using the initWithData: method and pass it in the data stored by the handle. Then create a new NSImage using -initWithSize: and then call addRepresentation: to add your pict representation. You can then use the NSImage to draw your picture. Or, you could also skip making an NSImage altogether and just draw the NSPictImageRep directly using -draw, -drawAtPoint:, or -drawInRect: (all declared in NSImageRep).
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jul 1, 2002, 12:22 PM
 
Instead of faffing around creating an NSImage it might be easier to use QuickDraw and Dock Manager's BeginQDContextForApplicationDockTile() and EndQDContextForApplicationDockTile() functions. I don't really know, though.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:55 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2