From 4b245db06f157e418e559f9ff426a8d3c5f615e9 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sun, 9 Jul 2017 21:21:26 +0300 Subject: [PATCH] More work on AppKit --- AppKit/CGEvent.h | 1 + AppKit/CMakeLists.txt | 13 +++++- AppKit/NSColor.subproj/NSColor_CGColor.m | 58 ++++++++++++------------ AppKit/NSRaise.h | 2 +- AppKit/X11.subproj/O2Font_FT.h | 2 +- 5 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 AppKit/CGEvent.h mode change 120000 => 100644 AppKit/NSRaise.h diff --git a/AppKit/CGEvent.h b/AppKit/CGEvent.h new file mode 100644 index 00000000..75968226 --- /dev/null +++ b/AppKit/CGEvent.h @@ -0,0 +1 @@ +#import diff --git a/AppKit/CMakeLists.txt b/AppKit/CMakeLists.txt index 6313a197..da9acfdb 100644 --- a/AppKit/CMakeLists.txt +++ b/AppKit/CMakeLists.txt @@ -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 ) diff --git a/AppKit/NSColor.subproj/NSColor_CGColor.m b/AppKit/NSColor.subproj/NSColor_CGColor.m index ad7be23d..8f726adf 100644 --- a/AppKit/NSColor.subproj/NSColor_CGColor.m +++ b/AppKit/NSColor.subproj/NSColor_CGColor.m @@ -11,6 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #import #import +#import + #import @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 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); } diff --git a/AppKit/NSRaise.h b/AppKit/NSRaise.h deleted file mode 120000 index fc815d5b..00000000 --- a/AppKit/NSRaise.h +++ /dev/null @@ -1 +0,0 @@ -../Foundation/NSException/NSRaise.h \ No newline at end of file diff --git a/AppKit/NSRaise.h b/AppKit/NSRaise.h new file mode 100644 index 00000000..2f09d40a --- /dev/null +++ b/AppKit/NSRaise.h @@ -0,0 +1 @@ +#import diff --git a/AppKit/X11.subproj/O2Font_FT.h b/AppKit/X11.subproj/O2Font_FT.h index c9188358..7d7e4140 100644 --- a/AppKit/X11.subproj/O2Font_FT.h +++ b/AppKit/X11.subproj/O2Font_FT.h @@ -4,7 +4,7 @@ #import #import FT_FREETYPE_H #import FT_RENDER_H -#import +#import @interface O2Font_FT : O2Font { FT_Face _face;