mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-27 05:50:27 +00:00
- Issue #135 fix, use OBJCModulePathForProcess() instead of __argv[0]
- Some NSGraphicsContext work to support drawing in NSBitmapImageRep's, probably not functional
This commit is contained in:
parent
83b3c3dec1
commit
8890d71158
@ -47,10 +47,12 @@ void KGPaintRadialGradient(KGPaint_radialGradient *self,CGFloat *g, CGFloat *rho
|
||||
|
||||
CGPoint fp = Vector2Subtract(f,c);
|
||||
|
||||
#if 0
|
||||
//clamp the focal point inside the gradient circle
|
||||
CGFloat fpLen = Vector2Length(fp);
|
||||
if( fpLen > 0.999f * r )
|
||||
fp = Vector2MultiplyByFloat(fp, (0.999f * r / fpLen));
|
||||
#endif
|
||||
|
||||
CGFloat D = -1.0f / (Vector2Dot(fp,fp) - r*r);
|
||||
CGPoint p=CGPointMake(x, y);
|
||||
|
@ -8,6 +8,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKitExport.h>
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
@class NSColor;
|
||||
|
||||
|
@ -8,8 +8,24 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
|
||||
@class NSWindow, NSCachedImageRep;
|
||||
@class NSWindow,NSBitmapImageRep;
|
||||
|
||||
typedef enum {
|
||||
NSImageInterpolationDefault=kCGInterpolationDefault,
|
||||
NSImageInterpolationNone=kCGInterpolationNone,
|
||||
NSImageInterpolationLow=kCGInterpolationLow,
|
||||
NSImageInterpolationHigh=kCGInterpolationHigh,
|
||||
} NSImageInterpolation;
|
||||
|
||||
typedef enum {
|
||||
NSColorRenderingIntentDefault=kCGRenderingIntentDefault,
|
||||
NSColorRenderingIntentAbsoluteColorimetric=kCGRenderingIntentAbsoluteColorimetric,
|
||||
NSColorRenderingIntentRelativeColorimetric=kCGRenderingIntentRelativeColorimetric,
|
||||
NSColorRenderingIntentPerceptual=kCGRenderingIntentPerceptual,
|
||||
NSColorRenderingIntentSaturation=kCGRenderingIntentSaturation,
|
||||
} NSColorRenderingIntent;
|
||||
|
||||
@interface NSGraphicsContext : NSObject {
|
||||
KGContext *_graphicsPort;
|
||||
@ -20,6 +36,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
+(NSGraphicsContext *)graphicsContextWithWindow:(NSWindow *)window;
|
||||
+(NSGraphicsContext *)graphicsContextWithGraphicsPort:(KGContext *)context flipped:(BOOL)flipped;
|
||||
+(NSGraphicsContext *)graphicsContextWithBitmapImageRep:(NSBitmapImageRep *)imageRep;
|
||||
|
||||
+(NSGraphicsContext *)currentContext;
|
||||
+(void)setCurrentContext:(NSGraphicsContext *)context;
|
||||
@ -33,8 +50,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
-(NSMutableArray *)focusStack;
|
||||
|
||||
-(BOOL)isDrawingToScreen;
|
||||
-(BOOL)isFlipped;
|
||||
|
||||
-(void)setShouldAntialias:(BOOL)flag;
|
||||
-(void)setShouldAntialias:(BOOL)value;
|
||||
-(void)setImageInterpolation:(NSImageInterpolation)value;
|
||||
-(void)setColorRenderingIntent:(NSColorRenderingIntent)value;
|
||||
-(void)setCompositingOperation:(NSCompositingOperation)value;
|
||||
|
||||
-(void)saveGraphicsState;
|
||||
-(void)restoreGraphicsState;
|
||||
|
@ -5,11 +5,10 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
// Original - Christopher Lloyd <cjwl@objc.net>
|
||||
#import <AppKit/NSGraphicsContext.h>
|
||||
#import <AppKit/NSWindow-Private.h>
|
||||
#import <AppKit/NSCachedImageRep.h>
|
||||
#import <AppKit/NSBitmapImageRep.h>
|
||||
#import <ApplicationServices/CGContext.h>
|
||||
|
||||
@class NSColor;
|
||||
@ -32,8 +31,61 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return self;
|
||||
}
|
||||
|
||||
static CGColorSpaceRef colorSpaceWithName(NSString *name){
|
||||
if([name isEqualToString:NSDeviceRGBColorSpace])
|
||||
return CGColorSpaceCreateDeviceRGB();
|
||||
if([name isEqualToString:NSCalibratedRGBColorSpace])
|
||||
return CGColorSpaceCreateDeviceRGB();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static CGBitmapInfo bitmapInfoForBitmapFormat(NSBitmapFormat bitmapFormat){
|
||||
CGBitmapInfo result=kCGBitmapByteOrderDefault;
|
||||
|
||||
if(bitmapFormat&NSAlphaFirstBitmapFormat){
|
||||
if(bitmapFormat&NSAlphaNonpremultipliedBitmapFormat)
|
||||
result|=kCGImageAlphaFirst;
|
||||
else
|
||||
result|=kCGImageAlphaPremultipliedFirst;
|
||||
}
|
||||
else {
|
||||
if(bitmapFormat&NSAlphaNonpremultipliedBitmapFormat)
|
||||
result|=kCGImageAlphaLast;
|
||||
else
|
||||
result|=kCGImageAlphaPremultipliedLast;
|
||||
}
|
||||
if(bitmapFormat&NSFloatingPointSamplesBitmapFormat)
|
||||
result|=kCGBitmapFloatComponents;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-initWithBitmapImageRep:(NSBitmapImageRep *)imageRep {
|
||||
CGColorSpaceRef colorSpace=colorSpaceWithName([imageRep colorSpaceName]);
|
||||
|
||||
if(colorSpace==nil){
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
_graphicsPort=CGBitmapContextCreate([imageRep bitmapData],[imageRep pixelsWide],[imageRep pixelsHigh],[imageRep bitsPerSample],[imageRep bytesPerRow],colorSpace,bitmapInfoForBitmapFormat([imageRep bitmapFormat]));
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
|
||||
if(_graphicsPort==nil){
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
_focusStack=[NSMutableArray new];
|
||||
_isDrawingToScreen=YES;
|
||||
_isFlipped=NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
CGContextRelease(_graphicsPort);
|
||||
if(_graphicsPort!=NULL)
|
||||
CGContextRelease(_graphicsPort);
|
||||
[_focusStack release];
|
||||
[super dealloc];
|
||||
}
|
||||
@ -46,6 +98,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return [[[self alloc] initWithGraphicsPort:context flipped:flipped] autorelease];
|
||||
}
|
||||
|
||||
+(NSGraphicsContext *)graphicsContextWithBitmapImageRep:(NSBitmapImageRep *)imageRep {
|
||||
return [[[self alloc] initWithBitmapImageRep:imageRep] autorelease];
|
||||
}
|
||||
|
||||
+(NSMutableArray *)_contextStack {
|
||||
NSMutableDictionary *shared=[NSCurrentThread() sharedDictionary];
|
||||
NSMutableArray *stack=[shared objectForKey:@"NSGraphicsContext.stack"];
|
||||
@ -115,7 +171,48 @@ NSMutableArray *NSCurrentFocusStack() {
|
||||
return _isDrawingToScreen;
|
||||
}
|
||||
|
||||
-(BOOL)isFlipped {
|
||||
NSView *focusView=[_focusStack lastObject];
|
||||
|
||||
if(focusView!=nil)
|
||||
return [focusView isFlipped];
|
||||
|
||||
return _isFlipped;
|
||||
}
|
||||
|
||||
-(void)setShouldAntialias:(BOOL)flag {
|
||||
CGContextSetShouldAntialias(_graphicsPort,flag);
|
||||
}
|
||||
|
||||
-(void)setImageInterpolation:(NSImageInterpolation)value {
|
||||
CGContextSetInterpolationQuality(_graphicsPort,value);
|
||||
}
|
||||
|
||||
-(void)setColorRenderingIntent:(NSColorRenderingIntent)value {
|
||||
CGContextSetRenderingIntent(_graphicsPort,value);
|
||||
}
|
||||
|
||||
-(void)setCompositingOperation:(NSCompositingOperation)value {
|
||||
CGBlendMode blendMode[]={
|
||||
kCGBlendModeClear,
|
||||
kCGBlendModeCopy,
|
||||
kCGBlendModeNormal,
|
||||
kCGBlendModeSourceIn,
|
||||
kCGBlendModeSourceOut,
|
||||
kCGBlendModeSourceAtop,
|
||||
kCGBlendModeDestinationOver,
|
||||
kCGBlendModeDestinationIn,
|
||||
kCGBlendModeDestinationOut,
|
||||
kCGBlendModeDestinationAtop,
|
||||
kCGBlendModeXOR,
|
||||
kCGBlendModePlusDarker,
|
||||
kCGBlendModeNormal,
|
||||
kCGBlendModePlusLighter,
|
||||
};
|
||||
if(value<NSCompositeClear || value>NSCompositePlusLighter)
|
||||
return;
|
||||
|
||||
CGContextSetBlendMode(_graphicsPort,blendMode[value]);
|
||||
}
|
||||
|
||||
-(void)saveGraphicsState {
|
||||
@ -127,6 +224,7 @@ NSMutableArray *NSCurrentFocusStack() {
|
||||
}
|
||||
|
||||
-(void)flushGraphics {
|
||||
CGContextFlush(_graphicsPort);
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -35,6 +35,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <Foundation/NSSelectInputSourceSet.h>
|
||||
|
||||
#import <Foundation/ObjectiveC.h>
|
||||
#import <Foundation/ObjCModule.h>
|
||||
|
||||
NSString *NSPlatformClassName=@"NSPlatform_win32";
|
||||
|
||||
@ -51,8 +52,7 @@ NSString *NSPlatformClassName=@"NSPlatform_win32";
|
||||
|
||||
[NSSocket_windows class]; // initialize winsock
|
||||
|
||||
_processName=[[[[NSString stringWithCString:__argv[0]] lastPathComponent] stringByDeletingPathExtension] copy];
|
||||
|
||||
_processName=[[[[NSString stringWithCString:OBJCModulePathForProcess()] lastPathComponent] stringByDeletingPathExtension] copy];
|
||||
entry=[@"SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\" stringByAppendingString:_processName];
|
||||
|
||||
if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,[entry cString],0,NULL,
|
||||
|
Loading…
Reference in New Issue
Block a user