Files
oboe/osx/tools/cursors.m
Celtic Minstrel 78cd213972 In no particular order:
- Added some of the most basic dialogs
- Changed C-style <xxx.h> headers to C++-style <cxxx> headers
- Switched graphics to load from the PNG files in graphics.exd rather than from Blades of Exile Graphics (NOTE: Some graphics still don't work, probably because of incorrect source rects)
- Switched cursors to load from GIF files in graphics.exd rather than from Blades of Exile Graphics
- Moved Niemand's tileImage functions from boe.graphics.cpp to graphtool.cpp, so they can be used by all three programs.
- Added some string lists in .txt files
- Made cursors into an enum
- Rewrote the code for displaying the Edit Terrain dialog to use the new engine (not tested yet)
- Fixed some __attribute__((deprecated)) stuff
- Most graphics are now loaded just after the custom graphics. This means they will be overridden by a file of the same name in the scenario's .exr folder.
- Altered modes a little so that when at the startup screen you are in MODE_STARTUP rather than MODE_OUTDOORS.
- Switched from function pointers to boost::function – the Boost libraries are now required.
- Finished off the new dialog engine and made gess necessary
- Added status icons as another type that can be drawn in dialogs
- C Wrappers for Cocoa cursors based on an Apple example. This is tested, and works perfectly.
- Added a switch in the program for using Windows graphics; however, there is no way as yet to set this flag, and in fact there aren't even any Windows graphics to use.
- Added include guards to graphtool.h
- Made separate mac and win directories within sounds.exa, since the Mac and Windows sounds are mostly subtly different (with two completely different!)

git-svn-id: http://openexile.googlecode.com/svn/trunk@90 4ebdad44-0ea0-11de-aab3-ff745001d230
2009-06-07 18:18:24 +00:00

80 lines
1.8 KiB
Objective-C

//
// cursors.m
// BoE
//
// Created by Celtic Minstrel on 03/06/09.
// Wrappers for NSCursor, based on an Apple example
//
#import <Cocoa/Cocoa.h>
#import "cursors.h"
NSAutoreleasePool *pool;
NSImage* ImageFromURL(CFURLRef url){
CGImageSourceRef imageSource = CGImageSourceCreateWithURL(url, NULL);
CGImageRef theImage = nil;
if(imageSource == nil) return nil;
theImage = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
if(theImage == nil) return nil;
CFRelease( imageSource );
NSRect imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
// Get the image dimensions.
imageRect.size.height = CGImageGetHeight(theImage);
imageRect.size.width = CGImageGetWidth(theImage);
// Create a new image to receive the Quartz image data.
NSImage *newImage = [[NSImage alloc] initWithSize:imageRect.size];
[newImage lockFocus];
// Get the Quartz context and draw.
CGContextRef imageContext = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextDrawImage(imageContext, *(CGRect*)&imageRect, theImage);
[newImage unlockFocus];
return newImage;
}
CursorRef CreateCursorFromFile(CFURLRef imgPath, float hotSpotX, float hotSpotY){
static BOOL inited = NO;
if(!inited){
NSApplicationLoad();
pool = [[NSAutoreleasePool alloc] init];
[[[NSWindow alloc] init] release];
inited = YES;
}
NSImage *img = ImageFromURL(imgPath);
NSCursor *cursor = [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(hotSpotX, hotSpotY)];
[img release];
CursorRef theCursor = malloc(sizeof(CocoaCursor));
theCursor->ptr = cursor;
return theCursor;
}
void DisposeNSCursor(CursorRef cursor){
[(NSCursor*)cursor->ptr release];
free(cursor);
}
void SetNSCursor(CursorRef cursor){
[(NSCursor*)cursor->ptr set];
}
void HideNSCursor(){
[NSCursor hide];
}
void ShowNSCursor(){
[NSCursor unhide];
}
void CleanUp(){
[pool release];
}