More work on AppKit

This commit is contained in:
Sergey Bugaev 2017-07-09 21:21:26 +03:00
parent f3a48d7aa3
commit 4b245db06f
5 changed files with 45 additions and 31 deletions

1
AppKit/CGEvent.h Normal file
View File

@ -0,0 +1 @@
#import <CoreGraphics/CGEvent.h>

View File

@ -12,7 +12,13 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-mmacosx-version-min=10.10"
)
find_package(X11 REQUIRED)
find_package(Freetype REQUIRED)
find_package(OpenGL REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_CAIRO cairo)
pkg_check_modules(PC_FONTCONFIG fontconfig)
include_directories(
${CMAKE_SOURCE_DIR}/src/external/foundation/include
@ -47,7 +53,11 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/NSToolbar.subproj
${CMAKE_CURRENT_SOURCE_DIR}/NSDrawer.subproj
${X11_INCLUDE_DIRS}
${FREETYPE_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIRS}
${PC_CAIRO_INCLUDE_DIRS}
${PC_FONTCONFIG_INCLUDE_DIRS}
)
set(AppKit_sources
@ -256,7 +266,7 @@ set(AppKit_sources
NSOpenGL/NSOpenGLPixelBuffer.m
NSOpenGL/NSOpenGLPixelFormat.m
NSOpenGL/NSOpenGLDrawable.m
NSOpenGL/NSOpenGLContext.m
# NSOpenGL/NSOpenGLContext.m
NSPopUpButtonCell.m
NSPredicateEditor.m
@ -377,5 +387,6 @@ add_framework(AppKit
Onyx2D
# native libraries
FreeType
fontconfig
jpeg png tiff
)

View File

@ -11,6 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSGraphicsContextFunctions.h>
#import <ApplicationServices/ApplicationServices.h>
#import <Foundation/NSDebug.h>
#import <AppKit/conversions.h>
@implementation NSColor_CGColor
@ -33,46 +35,46 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
+(NSColor *)colorWithGray:(float)gray alpha:(float)alpha spaceName:(NSString *)spaceName {
NSColor *result;
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceGray();
float components[2]={gray,alpha};
CGColorRef cgColor=CGColorCreate(colorSpace,components);
result=[self colorWithColorRef:cgColor spaceName:spaceName];
CGColorSpaceRelease(colorSpace);
CGColorRelease(cgColor);
return result;
}
+(NSColor *)colorWithCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha spaceName:(NSString *)spaceName {
NSColor *result;
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceCMYK();
float components[5]={cyan,magenta,yellow,black,alpha};
CGColorRef cgColor=CGColorCreate(colorSpace,components);
result=[self colorWithColorRef:cgColor spaceName:spaceName];
CGColorSpaceRelease(colorSpace);
CGColorRelease(cgColor);
return result;
}
+(NSColor *)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha spaceName:(NSString *)spaceName {
NSColor *result;
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
float components[4]={red,green,blue,alpha};
CGColorRef cgColor=CGColorCreate(colorSpace,components);
result=[self colorWithColorRef:cgColor spaceName:spaceName];
CGColorSpaceRelease(colorSpace);
CGColorRelease(cgColor);
return result;
}
@ -109,7 +111,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)getComponents:(CGFloat *)components {
NSInteger i,count=CGColorGetNumberOfComponents(_colorRef);
const CGFloat *comps=CGColorGetComponents(_colorRef);
for(i=0;i<count;i++)
components[i]=comps[i];
}
@ -121,10 +123,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(NSColor *)colorWithAlphaComponent:(CGFloat)alpha {
CGColorRef ref=CGColorCreateCopyWithAlpha(_colorRef,alpha);
NSColor *result=[[[isa alloc] initWithColorRef:ref spaceName:_colorSpaceName] autorelease];
CGColorRelease(ref);
return result;
}
}
#define REC601_LUMINANCE_R 0.299f
@ -153,7 +155,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
if([otherSpaceName isEqualToString:NSCalibratedRGBColorSpace] || colorSpace == nil)
return [NSColor colorWithCalibratedRed:white green:white blue:white alpha:alpha];
if([otherSpaceName isEqualToString:NSDeviceRGBColorSpace])
return [NSColor colorWithDeviceRed:white green:white blue:white alpha:alpha];
@ -184,19 +186,19 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
CGFloat yellow=components[2];
CGFloat black=components[3];
CGFloat alpha=components[4];
if([otherSpaceName isEqualToString:NSCalibratedRGBColorSpace]){
CGFloat white = 1 - black;
CGFloat red=(cyan > white ? 0 : white - cyan);
CGFloat green=(magenta > white ? 0 : white - magenta);
CGFloat blue=(yellow > white ? 0 : white - yellow);
return [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:alpha];
}
if([otherSpaceName isEqualToString:NSCalibratedWhiteColorSpace]){
CGFloat white = 1 - cyan - magenta - yellow - black;
return [NSColor colorWithCalibratedWhite:(white > 0 ? white : 0) alpha:alpha];
}
}
@ -208,7 +210,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
if([otherSpaceName isEqualToString:NSCalibratedRGBColorSpace] || colorSpace == nil)
return [NSColor colorWithCalibratedRed:white green:white blue:white alpha:alpha];
if([otherSpaceName isEqualToString:NSDeviceRGBColorSpace])
return [NSColor colorWithDeviceRed:white green:white blue:white alpha:alpha];
@ -233,7 +235,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
if([otherSpaceName isEqualToString:NSDeviceRGBColorSpace])
return [NSColor colorWithDeviceRed:red green:green blue:blue alpha:alpha];
}
if(NSDebugEnabled)
NSLog(@"Unable to convert color to space %@",otherSpaceName);
return nil;
@ -263,7 +265,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
CGColorSpaceRef colorSpace=CGColorGetColorSpace(_colorRef);
CGColorSpaceModel model=CGColorSpaceGetModel(colorSpace);
const CGFloat *components=CGColorGetComponents(_colorRef);
if(model==kCGColorSpaceModelRGB){
if(red!=NULL)
*red = components[0];
@ -275,7 +277,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
*alpha = components[3];
return;
}
if(model==kCGColorSpaceModelMonochrome){
if(red!=NULL)
*red = components[0];
@ -287,7 +289,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
*alpha = components[1];
return;
}
NSLog(@"-[%@ %s] failed, space=%@",isa,_cmd,_colorSpaceName);
}
@ -295,7 +297,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
CGColorSpaceRef colorSpace=CGColorGetColorSpace(_colorRef);
CGColorSpaceModel model=CGColorSpaceGetModel(colorSpace);
const CGFloat *components=CGColorGetComponents(_colorRef);
if(model==kCGColorSpaceModelRGB){
CGFloat red=components[0];
CGFloat green=components[1];
@ -306,7 +308,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
if(alphap!=NULL)
*alphap=alpha;
return;
}
@ -317,7 +319,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
CGColorSpaceRef colorSpace=CGColorGetColorSpace(_colorRef);
CGColorSpaceModel model=CGColorSpaceGetModel(colorSpace);
const CGFloat *components=CGColorGetComponents(_colorRef);
if(model==kCGColorSpaceModelCMYK){
if(cyan!=NULL)
*cyan = components[0];
@ -331,7 +333,7 @@ static inline CGFloat calibratedWhiteFromRGB(CGFloat r, CGFloat g, CGFloat b) {
*alpha = components[4];
return;
}
NSLog(@"-[%@ %s] failed",isa,_cmd);
}

View File

@ -1 +0,0 @@
../Foundation/NSException/NSRaise.h

1
AppKit/NSRaise.h Normal file
View File

@ -0,0 +1 @@
#import <Foundation/NSRaise.h>

View File

@ -4,7 +4,7 @@
#import <ft2build.h>
#import FT_FREETYPE_H
#import FT_RENDER_H
#import <fontconfig.h>
#import <fontconfig/fontconfig.h>
@interface O2Font_FT : O2Font {
FT_Face _face;