Move core-graphics types from cocoa.types to core-graphics.types, clean up some code
parent
463599a931
commit
fd7a47613e
|
@ -44,7 +44,6 @@ $nl
|
||||||
{ $subsection "objc-calling" }
|
{ $subsection "objc-calling" }
|
||||||
{ $subsection "objc-subclassing" }
|
{ $subsection "objc-subclassing" }
|
||||||
"A utility library is built to faciliate the development of Cocoa applications in Factor:"
|
"A utility library is built to faciliate the development of Cocoa applications in Factor:"
|
||||||
{ $subsection "cocoa-types" }
|
|
||||||
{ $subsection "cocoa-application-utils" }
|
{ $subsection "cocoa-application-utils" }
|
||||||
{ $subsection "cocoa-dialogs" }
|
{ $subsection "cocoa-dialogs" }
|
||||||
{ $subsection "cocoa-pasteboard-utils" }
|
{ $subsection "cocoa-pasteboard-utils" }
|
||||||
|
|
|
@ -1,73 +1,20 @@
|
||||||
! Copyright (C) 2006, 2007 Slava Pestov
|
! Copyright (C) 2006, 2009 Slava Pestov
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types alien.syntax combinators kernel ;
|
USING: alien.c-types alien.syntax combinators kernel layouts
|
||||||
|
core-graphics.types ;
|
||||||
IN: cocoa.types
|
IN: cocoa.types
|
||||||
|
|
||||||
TYPEDEF: long NSInteger
|
TYPEDEF: long NSInteger
|
||||||
TYPEDEF: ulong NSUInteger
|
TYPEDEF: ulong NSUInteger
|
||||||
<< "ptrdiff_t" heap-size {
|
|
||||||
{ 4 [ "float" ] }
|
|
||||||
{ 8 [ "double" ] }
|
|
||||||
} case "CGFloat" typedef >>
|
|
||||||
|
|
||||||
C-STRUCT: NSPoint
|
|
||||||
{ "CGFloat" "x" }
|
|
||||||
{ "CGFloat" "y" } ;
|
|
||||||
|
|
||||||
|
TYPEDEF: CGPoint NSPoint
|
||||||
TYPEDEF: NSPoint _NSPoint
|
TYPEDEF: NSPoint _NSPoint
|
||||||
TYPEDEF: NSPoint CGPoint
|
|
||||||
|
|
||||||
: <NSPoint> ( x y -- point )
|
|
||||||
"NSPoint" <c-object>
|
|
||||||
[ set-NSPoint-y ] keep
|
|
||||||
[ set-NSPoint-x ] keep ;
|
|
||||||
|
|
||||||
C-STRUCT: NSSize
|
|
||||||
{ "CGFloat" "w" }
|
|
||||||
{ "CGFloat" "h" } ;
|
|
||||||
|
|
||||||
|
TYPEDEF: CGSize NSSize
|
||||||
TYPEDEF: NSSize _NSSize
|
TYPEDEF: NSSize _NSSize
|
||||||
TYPEDEF: NSSize CGSize
|
|
||||||
|
|
||||||
: <NSSize> ( w h -- size )
|
|
||||||
"NSSize" <c-object>
|
|
||||||
[ set-NSSize-h ] keep
|
|
||||||
[ set-NSSize-w ] keep ;
|
|
||||||
|
|
||||||
C-STRUCT: NSRect
|
|
||||||
{ "NSPoint" "origin" }
|
|
||||||
{ "NSSize" "size" } ;
|
|
||||||
|
|
||||||
|
TYPEDEF: CGRect NSRect
|
||||||
TYPEDEF: NSRect _NSRect
|
TYPEDEF: NSRect _NSRect
|
||||||
TYPEDEF: NSRect CGRect
|
|
||||||
|
|
||||||
: NSRect-x ( NSRect -- x )
|
|
||||||
NSRect-origin NSPoint-x ; inline
|
|
||||||
: NSRect-y ( NSRect -- y )
|
|
||||||
NSRect-origin NSPoint-y ; inline
|
|
||||||
: NSRect-w ( NSRect -- w )
|
|
||||||
NSRect-size NSSize-w ; inline
|
|
||||||
: NSRect-h ( NSRect -- h )
|
|
||||||
NSRect-size NSSize-h ; inline
|
|
||||||
|
|
||||||
: set-NSRect-x ( x NSRect -- )
|
|
||||||
NSRect-origin set-NSPoint-x ; inline
|
|
||||||
: set-NSRect-y ( y NSRect -- )
|
|
||||||
NSRect-origin set-NSPoint-y ; inline
|
|
||||||
: set-NSRect-w ( w NSRect -- )
|
|
||||||
NSRect-size set-NSSize-w ; inline
|
|
||||||
: set-NSRect-h ( h NSRect -- )
|
|
||||||
NSRect-size set-NSSize-h ; inline
|
|
||||||
|
|
||||||
: <NSRect> ( x y w h -- rect )
|
|
||||||
"NSRect" <c-object>
|
|
||||||
[ set-NSRect-h ] keep
|
|
||||||
[ set-NSRect-w ] keep
|
|
||||||
[ set-NSRect-y ] keep
|
|
||||||
[ set-NSRect-x ] keep ;
|
|
||||||
|
|
||||||
: NSRect-x-y ( alien -- origin-x origin-y )
|
|
||||||
[ NSRect-x ] keep NSRect-y ;
|
|
||||||
|
|
||||||
C-STRUCT: NSRange
|
C-STRUCT: NSRange
|
||||||
{ "NSUInteger" "location" }
|
{ "NSUInteger" "location" }
|
||||||
|
@ -85,14 +32,6 @@ TYPEDEF: void* unknown_type
|
||||||
[ set-NSRange-length ] keep
|
[ set-NSRange-length ] keep
|
||||||
[ set-NSRange-location ] keep ;
|
[ set-NSRange-location ] keep ;
|
||||||
|
|
||||||
C-STRUCT: CGAffineTransform
|
|
||||||
{ "CGFloat" "a" }
|
|
||||||
{ "CGFloat" "b" }
|
|
||||||
{ "CGFloat" "c" }
|
|
||||||
{ "CGFloat" "d" }
|
|
||||||
{ "CGFloat" "tx" }
|
|
||||||
{ "CGFloat" "ty" } ;
|
|
||||||
|
|
||||||
C-STRUCT: NSFastEnumerationState
|
C-STRUCT: NSFastEnumerationState
|
||||||
{ "ulong" "state" }
|
{ "ulong" "state" }
|
||||||
{ "id*" "itemsPtr" }
|
{ "id*" "itemsPtr" }
|
||||||
|
|
|
@ -1,68 +1,72 @@
|
||||||
! Copyright (C) 2006, 2008 Slava Pestov
|
! Copyright (C) 2006, 2009 Slava Pestov
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: specialized-arrays.int arrays kernel math namespaces make
|
USING: specialized-arrays.int arrays kernel math namespaces make
|
||||||
cocoa cocoa.messages cocoa.classes cocoa.types sequences
|
cocoa cocoa.messages cocoa.classes core-graphics.types sequences
|
||||||
continuations accessors ;
|
continuations accessors ;
|
||||||
IN: cocoa.views
|
IN: cocoa.views
|
||||||
|
|
||||||
: NSOpenGLPFAAllRenderers 1 ;
|
CONSTANT: NSOpenGLPFAAllRenderers 1
|
||||||
: NSOpenGLPFADoubleBuffer 5 ;
|
CONSTANT: NSOpenGLPFADoubleBuffer 5
|
||||||
: NSOpenGLPFAStereo 6 ;
|
CONSTANT: NSOpenGLPFAStereo 6
|
||||||
: NSOpenGLPFAAuxBuffers 7 ;
|
CONSTANT: NSOpenGLPFAAuxBuffers 7
|
||||||
: NSOpenGLPFAColorSize 8 ;
|
CONSTANT: NSOpenGLPFAColorSize 8
|
||||||
: NSOpenGLPFAAlphaSize 11 ;
|
CONSTANT: NSOpenGLPFAAlphaSize 11
|
||||||
: NSOpenGLPFADepthSize 12 ;
|
CONSTANT: NSOpenGLPFADepthSize 12
|
||||||
: NSOpenGLPFAStencilSize 13 ;
|
CONSTANT: NSOpenGLPFAStencilSize 13
|
||||||
: NSOpenGLPFAAccumSize 14 ;
|
CONSTANT: NSOpenGLPFAAccumSize 14
|
||||||
: NSOpenGLPFAMinimumPolicy 51 ;
|
CONSTANT: NSOpenGLPFAMinimumPolicy 51
|
||||||
: NSOpenGLPFAMaximumPolicy 52 ;
|
CONSTANT: NSOpenGLPFAMaximumPolicy 52
|
||||||
: NSOpenGLPFAOffScreen 53 ;
|
CONSTANT: NSOpenGLPFAOffScreen 53
|
||||||
: NSOpenGLPFAFullScreen 54 ;
|
CONSTANT: NSOpenGLPFAFullScreen 54
|
||||||
: NSOpenGLPFASampleBuffers 55 ;
|
CONSTANT: NSOpenGLPFASampleBuffers 55
|
||||||
: NSOpenGLPFASamples 56 ;
|
CONSTANT: NSOpenGLPFASamples 56
|
||||||
: NSOpenGLPFAAuxDepthStencil 57 ;
|
CONSTANT: NSOpenGLPFAAuxDepthStencil 57
|
||||||
: NSOpenGLPFAColorFloat 58 ;
|
CONSTANT: NSOpenGLPFAColorFloat 58
|
||||||
: NSOpenGLPFAMultisample 59 ;
|
CONSTANT: NSOpenGLPFAMultisample 59
|
||||||
: NSOpenGLPFASupersample 60 ;
|
CONSTANT: NSOpenGLPFASupersample 60
|
||||||
: NSOpenGLPFASampleAlpha 61 ;
|
CONSTANT: NSOpenGLPFASampleAlpha 61
|
||||||
: NSOpenGLPFARendererID 70 ;
|
CONSTANT: NSOpenGLPFARendererID 70
|
||||||
: NSOpenGLPFASingleRenderer 71 ;
|
CONSTANT: NSOpenGLPFASingleRenderer 71
|
||||||
: NSOpenGLPFANoRecovery 72 ;
|
CONSTANT: NSOpenGLPFANoRecovery 72
|
||||||
: NSOpenGLPFAAccelerated 73 ;
|
CONSTANT: NSOpenGLPFAAccelerated 73
|
||||||
: NSOpenGLPFAClosestPolicy 74 ;
|
CONSTANT: NSOpenGLPFAClosestPolicy 74
|
||||||
: NSOpenGLPFARobust 75 ;
|
CONSTANT: NSOpenGLPFARobust 75
|
||||||
: NSOpenGLPFABackingStore 76 ;
|
CONSTANT: NSOpenGLPFABackingStore 76
|
||||||
: NSOpenGLPFAMPSafe 78 ;
|
CONSTANT: NSOpenGLPFAMPSafe 78
|
||||||
: NSOpenGLPFAWindow 80 ;
|
CONSTANT: NSOpenGLPFAWindow 80
|
||||||
: NSOpenGLPFAMultiScreen 81 ;
|
CONSTANT: NSOpenGLPFAMultiScreen 81
|
||||||
: NSOpenGLPFACompliant 83 ;
|
CONSTANT: NSOpenGLPFACompliant 83
|
||||||
: NSOpenGLPFAScreenMask 84 ;
|
CONSTANT: NSOpenGLPFAScreenMask 84
|
||||||
: NSOpenGLPFAPixelBuffer 90 ;
|
CONSTANT: NSOpenGLPFAPixelBuffer 90
|
||||||
: NSOpenGLPFAAllowOfflineRenderers 96 ;
|
CONSTANT: NSOpenGLPFAAllowOfflineRenderers 96
|
||||||
: NSOpenGLPFAVirtualScreenCount 128 ;
|
CONSTANT: NSOpenGLPFAVirtualScreenCount 128
|
||||||
|
|
||||||
: kCGLRendererGenericFloatID HEX: 00020400 ;
|
CONSTANT: kCGLRendererGenericFloatID HEX: 00020400
|
||||||
|
|
||||||
|
|
||||||
|
CONSTANT: NSOpenGLCPSwapInterval 222
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
SYMBOL: +software-renderer+
|
SYMBOL: software-renderer?
|
||||||
SYMBOL: +multisample+
|
SYMBOL: multisample?
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: with-software-renderer ( quot -- )
|
: with-software-renderer ( quot -- )
|
||||||
t +software-renderer+ pick with-variable ; inline
|
[ t software-renderer? ] dip with-variable ; inline
|
||||||
|
|
||||||
: with-multisample ( quot -- )
|
: with-multisample ( quot -- )
|
||||||
t +multisample+ pick with-variable ; inline
|
[ t multisample? ] dip with-variable ; inline
|
||||||
|
|
||||||
: <PixelFormat> ( attributes -- pixelfmt )
|
: <PixelFormat> ( attributes -- pixelfmt )
|
||||||
NSOpenGLPixelFormat -> alloc swap [
|
NSOpenGLPixelFormat -> alloc swap [
|
||||||
%
|
%
|
||||||
NSOpenGLPFADepthSize , 16 ,
|
NSOpenGLPFADepthSize , 16 ,
|
||||||
+software-renderer+ get [
|
software-renderer? get [
|
||||||
NSOpenGLPFARendererID , kCGLRendererGenericFloatID ,
|
NSOpenGLPFARendererID , kCGLRendererGenericFloatID ,
|
||||||
] when
|
] when
|
||||||
+multisample+ get [
|
multisample? get [
|
||||||
NSOpenGLPFASupersample ,
|
NSOpenGLPFASupersample ,
|
||||||
NSOpenGLPFASampleBuffers , 1 ,
|
NSOpenGLPFASampleBuffers , 1 ,
|
||||||
NSOpenGLPFASamples , 8 ,
|
NSOpenGLPFASamples , 8 ,
|
||||||
|
@ -73,7 +77,7 @@ PRIVATE>
|
||||||
-> autorelease ;
|
-> autorelease ;
|
||||||
|
|
||||||
: <GLView> ( class dim -- view )
|
: <GLView> ( class dim -- view )
|
||||||
[ -> alloc 0 0 ] dip first2 <NSRect>
|
[ -> alloc 0 0 ] dip first2 <CGRect>
|
||||||
NSOpenGLPFAWindow NSOpenGLPFADoubleBuffer 2array <PixelFormat>
|
NSOpenGLPFAWindow NSOpenGLPFADoubleBuffer 2array <PixelFormat>
|
||||||
-> initWithFrame:pixelFormat:
|
-> initWithFrame:pixelFormat:
|
||||||
dup 1 -> setPostsBoundsChangedNotifications:
|
dup 1 -> setPostsBoundsChangedNotifications:
|
||||||
|
@ -81,26 +85,12 @@ PRIVATE>
|
||||||
|
|
||||||
: view-dim ( view -- dim )
|
: view-dim ( view -- dim )
|
||||||
-> bounds
|
-> bounds
|
||||||
dup NSRect-w >fixnum
|
[ CGRect-w >fixnum ] [ CGRect-h >fixnum ] bi
|
||||||
swap NSRect-h >fixnum 2array ;
|
2array ;
|
||||||
|
|
||||||
: mouse-location ( view event -- loc )
|
: mouse-location ( view event -- loc )
|
||||||
[
|
[
|
||||||
-> locationInWindow f -> convertPoint:fromView:
|
-> locationInWindow f -> convertPoint:fromView:
|
||||||
[ NSPoint-x ] [ NSPoint-y ] bi
|
[ CGPoint-x ] [ CGPoint-y ] bi
|
||||||
] [ drop -> frame NSRect-h ] 2bi
|
] [ drop -> frame CGRect-h ] 2bi
|
||||||
swap - 2array ;
|
swap - 2array ;
|
||||||
|
|
||||||
USE: opengl.gl
|
|
||||||
USE: alien.syntax
|
|
||||||
|
|
||||||
: NSOpenGLCPSwapInterval 222 ;
|
|
||||||
|
|
||||||
LIBRARY: OpenGL
|
|
||||||
|
|
||||||
TYPEDEF: int CGLError
|
|
||||||
TYPEDEF: void* CGLContextObj
|
|
||||||
TYPEDEF: int CGLContextParameter
|
|
||||||
|
|
||||||
FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ;
|
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.syntax alien.strings kernel sequences byte-arrays
|
USING: alien.syntax alien.strings kernel sequences byte-arrays
|
||||||
io.encodings.utf8 math core-foundation core-foundation.arrays ;
|
io.encodings.utf8 math core-foundation core-foundation.arrays
|
||||||
|
destructors ;
|
||||||
IN: core-foundation.strings
|
IN: core-foundation.strings
|
||||||
|
|
||||||
TYPEDEF: void* CFStringRef
|
TYPEDEF: void* CFStringRef
|
||||||
|
|
||||||
TYPEDEF: int CFStringEncoding
|
TYPEDEF: int CFStringEncoding
|
||||||
: kCFStringEncodingMacRoman HEX: 0 ;
|
CONSTANT: kCFStringEncodingMacRoman HEX: 0
|
||||||
: kCFStringEncodingWindowsLatin1 HEX: 0500 ;
|
CONSTANT: kCFStringEncodingWindowsLatin1 HEX: 0500
|
||||||
: kCFStringEncodingISOLatin1 HEX: 0201 ;
|
CONSTANT: kCFStringEncodingISOLatin1 HEX: 0201
|
||||||
: kCFStringEncodingNextStepLatin HEX: 0B01 ;
|
CONSTANT: kCFStringEncodingNextStepLatin HEX: 0B01
|
||||||
: kCFStringEncodingASCII HEX: 0600 ;
|
CONSTANT: kCFStringEncodingASCII HEX: 0600
|
||||||
: kCFStringEncodingUnicode HEX: 0100 ;
|
CONSTANT: kCFStringEncodingUnicode HEX: 0100
|
||||||
: kCFStringEncodingUTF8 HEX: 08000100 ;
|
CONSTANT: kCFStringEncodingUTF8 HEX: 08000100
|
||||||
: kCFStringEncodingNonLossyASCII HEX: 0BFF ;
|
CONSTANT: kCFStringEncodingNonLossyASCII HEX: 0BFF
|
||||||
: kCFStringEncodingUTF16 HEX: 0100 ;
|
CONSTANT: kCFStringEncodingUTF16 HEX: 0100
|
||||||
: kCFStringEncodingUTF16BE HEX: 10000100 ;
|
CONSTANT: kCFStringEncodingUTF16BE HEX: 10000100
|
||||||
: kCFStringEncodingUTF16LE HEX: 14000100 ;
|
CONSTANT: kCFStringEncodingUTF16LE HEX: 14000100
|
||||||
: kCFStringEncodingUTF32 HEX: 0c000100 ;
|
CONSTANT: kCFStringEncodingUTF32 HEX: 0c000100
|
||||||
: kCFStringEncodingUTF32BE HEX: 18000100 ;
|
CONSTANT: kCFStringEncodingUTF32BE HEX: 18000100
|
||||||
: kCFStringEncodingUTF32LE HEX: 1c000100 ;
|
CONSTANT: kCFStringEncodingUTF32LE HEX: 1c000100
|
||||||
|
|
||||||
FUNCTION: CFStringRef CFStringCreateWithBytes (
|
FUNCTION: CFStringRef CFStringCreateWithBytes (
|
||||||
CFAllocatorRef alloc,
|
CFAllocatorRef alloc,
|
||||||
|
@ -63,4 +64,4 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
|
||||||
CF>array [ CF>string ] map ;
|
CF>array [ CF>string ] map ;
|
||||||
|
|
||||||
: <CFStringArray> ( seq -- alien )
|
: <CFStringArray> ( seq -- alien )
|
||||||
[ <CFString> ] map [ <CFArray> ] [ [ CFRelease ] each ] bi ;
|
[ [ <CFString> &CFRelease ] map <CFArray> ] with-destructors ;
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
! Copyright (C) 2009 Slava Pestov.
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.syntax alien.c-types alien.destructors math
|
USING: alien.c-types alien.destructors alien.syntax
|
||||||
locals fry sequences destructors kernel ;
|
destructors fry kernel locals math sequences
|
||||||
|
core-graphics.types ;
|
||||||
IN: core-graphics
|
IN: core-graphics
|
||||||
|
|
||||||
TYPEDEF: void* CGColorSpaceRef
|
|
||||||
TYPEDEF: void* CGContextRef
|
|
||||||
|
|
||||||
! CGImageAlphaInfo
|
! CGImageAlphaInfo
|
||||||
C-ENUM:
|
C-ENUM:
|
||||||
kCGImageAlphaNone
|
kCGImageAlphaNone
|
||||||
|
@ -27,8 +25,6 @@ kCGImageAlphaNoneSkipFirst ;
|
||||||
: kCGBitmapByteOrder16Big ( -- n ) 3 12 shift ; inline
|
: kCGBitmapByteOrder16Big ( -- n ) 3 12 shift ; inline
|
||||||
: kCGBitmapByteOrder32Big ( -- n ) 4 12 shift ; inline
|
: kCGBitmapByteOrder32Big ( -- n ) 4 12 shift ; inline
|
||||||
|
|
||||||
TYPEDEF: uint CGBitmapInfo
|
|
||||||
|
|
||||||
FUNCTION: CGColorSpaceRef CGColorSpaceCreateDeviceRGB ( ) ;
|
FUNCTION: CGColorSpaceRef CGColorSpaceCreateDeviceRGB ( ) ;
|
||||||
|
|
||||||
FUNCTION: CGContextRef CGBitmapContextCreate (
|
FUNCTION: CGContextRef CGBitmapContextCreate (
|
||||||
|
@ -71,6 +67,8 @@ FUNCTION: void CGContextSetTextPosition (
|
||||||
CGFloat y
|
CGFloat y
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
|
FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ;
|
||||||
|
|
||||||
:: <CGBitmapContext> ( data w h -- context )
|
:: <CGBitmapContext> ( data w h -- context )
|
||||||
[
|
[
|
||||||
data w h 8 w 4 *
|
data w h 8 w 4 *
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Slava Pestov
|
|
@ -0,0 +1,29 @@
|
||||||
|
USING: math help.markup help.syntax ;
|
||||||
|
IN: core-graphics.types
|
||||||
|
|
||||||
|
HELP: <CGRect>
|
||||||
|
{ $values { "x" real } { "y" real } { "w" real } { "h" real } { "rect" "an " { $snippet "CGRect" } } }
|
||||||
|
{ $description "Allocates a new " { $snippet "CGRect" } " in the Factor heap." } ;
|
||||||
|
|
||||||
|
HELP: <CGPoint>
|
||||||
|
{ $values { "x" real } { "y" real } { "point" "an " { $snippet "CGPoint" } } }
|
||||||
|
{ $description "Allocates a new " { $snippet "CGPoint" } " in the Factor heap." } ;
|
||||||
|
|
||||||
|
HELP: <CGSize>
|
||||||
|
{ $values { "w" real } { "h" real } { "size" "an " { $snippet "CGSize" } } }
|
||||||
|
{ $description "Allocates a new " { $snippet "CGSize" } " in the Factor heap." } ;
|
||||||
|
|
||||||
|
ARTICLE: "core-graphics.types" "Core Graphics types"
|
||||||
|
"The Core Graphics binding defines some common C structs:"
|
||||||
|
{ $code
|
||||||
|
"CGRect"
|
||||||
|
"CGPoint"
|
||||||
|
"CGSize"
|
||||||
|
}
|
||||||
|
"Some words for working with the above:"
|
||||||
|
{ $subsection <CGRect> }
|
||||||
|
{ $subsection <CGPoint> }
|
||||||
|
{ $subsection <CGSize> } ;
|
||||||
|
|
||||||
|
IN: core-graphics.types
|
||||||
|
ABOUT: "core-graphics.types"
|
|
@ -0,0 +1,4 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: tools.test core-graphics.types ;
|
||||||
|
IN: core-graphics.types.tests
|
|
@ -0,0 +1,75 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: alien.c-types alien.syntax kernel layouts ;
|
||||||
|
IN: core-graphics.types
|
||||||
|
|
||||||
|
<< cell 4 = "float" "double" ? "CGFloat" typedef >>
|
||||||
|
|
||||||
|
: <CGFloat> ( x -- alien )
|
||||||
|
cell 4 = [ <float> ] [ <double> ] if ; inline
|
||||||
|
|
||||||
|
C-STRUCT: CGPoint
|
||||||
|
{ "CGFloat" "x" }
|
||||||
|
{ "CGFloat" "y" } ;
|
||||||
|
|
||||||
|
: <CGPoint> ( x y -- point )
|
||||||
|
"CGPoint" <c-object>
|
||||||
|
[ set-CGPoint-y ] keep
|
||||||
|
[ set-CGPoint-x ] keep ;
|
||||||
|
|
||||||
|
C-STRUCT: CGSize
|
||||||
|
{ "CGFloat" "w" }
|
||||||
|
{ "CGFloat" "h" } ;
|
||||||
|
|
||||||
|
: <CGSize> ( w h -- size )
|
||||||
|
"CGSize" <c-object>
|
||||||
|
[ set-CGSize-h ] keep
|
||||||
|
[ set-CGSize-w ] keep ;
|
||||||
|
|
||||||
|
C-STRUCT: CGRect
|
||||||
|
{ "CGPoint" "origin" }
|
||||||
|
{ "CGSize" "size" } ;
|
||||||
|
|
||||||
|
: CGRect-x ( CGRect -- x )
|
||||||
|
CGRect-origin CGPoint-x ; inline
|
||||||
|
: CGRect-y ( CGRect -- y )
|
||||||
|
CGRect-origin CGPoint-y ; inline
|
||||||
|
: CGRect-w ( CGRect -- w )
|
||||||
|
CGRect-size CGSize-w ; inline
|
||||||
|
: CGRect-h ( CGRect -- h )
|
||||||
|
CGRect-size CGSize-h ; inline
|
||||||
|
|
||||||
|
: set-CGRect-x ( x CGRect -- )
|
||||||
|
CGRect-origin set-CGPoint-x ; inline
|
||||||
|
: set-CGRect-y ( y CGRect -- )
|
||||||
|
CGRect-origin set-CGPoint-y ; inline
|
||||||
|
: set-CGRect-w ( w CGRect -- )
|
||||||
|
CGRect-size set-CGSize-w ; inline
|
||||||
|
: set-CGRect-h ( h CGRect -- )
|
||||||
|
CGRect-size set-CGSize-h ; inline
|
||||||
|
|
||||||
|
: <CGRect> ( x y w h -- rect )
|
||||||
|
"CGRect" <c-object>
|
||||||
|
[ set-CGRect-h ] keep
|
||||||
|
[ set-CGRect-w ] keep
|
||||||
|
[ set-CGRect-y ] keep
|
||||||
|
[ set-CGRect-x ] keep ;
|
||||||
|
|
||||||
|
: CGRect-x-y ( alien -- origin-x origin-y )
|
||||||
|
[ CGRect-x ] keep CGRect-y ;
|
||||||
|
|
||||||
|
C-STRUCT: CGAffineTransform
|
||||||
|
{ "CGFloat" "a" }
|
||||||
|
{ "CGFloat" "b" }
|
||||||
|
{ "CGFloat" "c" }
|
||||||
|
{ "CGFloat" "d" }
|
||||||
|
{ "CGFloat" "tx" }
|
||||||
|
{ "CGFloat" "ty" } ;
|
||||||
|
|
||||||
|
TYPEDEF: void* CGColorSpaceRef
|
||||||
|
TYPEDEF: void* CGContextRef
|
||||||
|
TYPEDEF: uint CGBitmapInfo
|
||||||
|
|
||||||
|
TYPEDEF: int CGLError
|
||||||
|
TYPEDEF: void* CGLContextObj
|
||||||
|
TYPEDEF: int CGLContextParameter
|
|
@ -41,3 +41,11 @@ C-GLOBAL: kCTGlyphInfoAttributeName
|
||||||
FUNCTION: CTLineRef CTLineCreateWithAttributedString ( CFAttributedStringRef string ) ;
|
FUNCTION: CTLineRef CTLineCreateWithAttributedString ( CFAttributedStringRef string ) ;
|
||||||
|
|
||||||
FUNCTION: void CTLineDraw ( CTLineRef line, CGContextRef context ) ;
|
FUNCTION: void CTLineDraw ( CTLineRef line, CGContextRef context ) ;
|
||||||
|
|
||||||
|
FUNCTION: CGFloat CTLineGetOffsetForStringIndex ( CTLineRef line, CFIndex charIndex, CGFloat* secondaryOffset ) ;
|
||||||
|
|
||||||
|
FUNCTION: CFIndex CTLineGetStringIndexForPosition ( CTLineRef line, CGPoint position ) ;
|
||||||
|
|
||||||
|
FUNCTION: double CTLineGetTypographicBounds ( CTLineRef line, CGFloat* ascent, CGFloat* descent, CGFloat* leading ) ;
|
||||||
|
|
||||||
|
FUNCTION: CGRect CTLineGetImageBounds ( CTLineRef line, CGContextRef context ) ;
|
||||||
|
|
|
@ -5,9 +5,10 @@ command-line kernel memory namespaces cocoa.messages
|
||||||
cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
|
cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
|
||||||
cocoa.windows cocoa.classes cocoa.nibs sequences system ui
|
cocoa.windows cocoa.classes cocoa.nibs sequences system ui
|
||||||
ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
|
ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
|
||||||
ui.cocoa.views core-foundation core-foundation.run-loop threads
|
ui.cocoa.views core-foundation core-foundation.run-loop
|
||||||
math.geometry.rect fry libc generalizations alien.c-types
|
core-graphics.types threads math.geometry.rect fry libc
|
||||||
cocoa.views combinators io.thread ;
|
generalizations alien.c-types cocoa.views combinators
|
||||||
|
io.thread ;
|
||||||
IN: ui.cocoa
|
IN: ui.cocoa
|
||||||
|
|
||||||
TUPLE: handle ;
|
TUPLE: handle ;
|
||||||
|
@ -35,7 +36,7 @@ M: pasteboard set-clipboard-contents
|
||||||
<clipboard> selection set-global ;
|
<clipboard> selection set-global ;
|
||||||
|
|
||||||
: world>NSRect ( world -- NSRect )
|
: world>NSRect ( world -- NSRect )
|
||||||
[ window-loc>> ] [ dim>> ] bi [ first2 ] bi@ <NSRect> ;
|
[ window-loc>> ] [ dim>> ] bi [ first2 ] bi@ <CGRect> ;
|
||||||
|
|
||||||
: gadget-window ( world -- )
|
: gadget-window ( world -- )
|
||||||
dup <FactorView>
|
dup <FactorView>
|
||||||
|
|
|
@ -4,7 +4,8 @@ USING: accessors alien alien.c-types arrays assocs cocoa kernel
|
||||||
math cocoa.messages cocoa.subclassing cocoa.classes cocoa.views
|
math cocoa.messages cocoa.subclassing cocoa.classes cocoa.views
|
||||||
cocoa.application cocoa.pasteboard cocoa.types cocoa.windows
|
cocoa.application cocoa.pasteboard cocoa.types cocoa.windows
|
||||||
sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
|
sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
|
||||||
core-foundation.strings threads combinators math.geometry.rect ;
|
core-foundation.strings core-graphics core-graphics.types
|
||||||
|
threads combinators math.geometry.rect ;
|
||||||
IN: ui.cocoa.views
|
IN: ui.cocoa.views
|
||||||
|
|
||||||
: send-mouse-moved ( view event -- )
|
: send-mouse-moved ( view event -- )
|
||||||
|
@ -14,15 +15,15 @@ IN: ui.cocoa.views
|
||||||
#! Cocoa -> Factor UI button mapping
|
#! Cocoa -> Factor UI button mapping
|
||||||
-> buttonNumber H{ { 0 1 } { 2 2 } { 1 3 } } at ;
|
-> buttonNumber H{ { 0 1 } { 2 2 } { 1 3 } } at ;
|
||||||
|
|
||||||
: modifiers
|
CONSTANT: modifiers
|
||||||
{
|
{
|
||||||
{ S+ HEX: 20000 }
|
{ S+ HEX: 20000 }
|
||||||
{ C+ HEX: 40000 }
|
{ C+ HEX: 40000 }
|
||||||
{ A+ HEX: 100000 }
|
{ A+ HEX: 100000 }
|
||||||
{ M+ HEX: 80000 }
|
{ M+ HEX: 80000 }
|
||||||
} ;
|
}
|
||||||
|
|
||||||
: key-codes
|
CONSTANT: key-codes
|
||||||
H{
|
H{
|
||||||
{ 71 "CLEAR" }
|
{ 71 "CLEAR" }
|
||||||
{ 36 "RET" }
|
{ 36 "RET" }
|
||||||
|
@ -47,7 +48,7 @@ IN: ui.cocoa.views
|
||||||
{ 126 "UP" }
|
{ 126 "UP" }
|
||||||
{ 116 "PAGE_UP" }
|
{ 116 "PAGE_UP" }
|
||||||
{ 121 "PAGE_DOWN" }
|
{ 121 "PAGE_DOWN" }
|
||||||
} ;
|
}
|
||||||
|
|
||||||
: key-code ( event -- string ? )
|
: key-code ( event -- string ? )
|
||||||
dup -> keyCode key-codes at
|
dup -> keyCode key-codes at
|
||||||
|
@ -57,7 +58,7 @@ IN: ui.cocoa.views
|
||||||
-> modifierFlags modifiers modifier ;
|
-> modifierFlags modifiers modifier ;
|
||||||
|
|
||||||
: key-event>gesture ( event -- modifiers keycode action? )
|
: key-event>gesture ( event -- modifiers keycode action? )
|
||||||
dup event-modifiers swap key-code ;
|
[ event-modifiers ] [ key-code ] bi ;
|
||||||
|
|
||||||
: send-key-event ( view gesture -- )
|
: send-key-event ( view gesture -- )
|
||||||
swap window propagate-key-gesture ;
|
swap window propagate-key-gesture ;
|
||||||
|
@ -74,7 +75,7 @@ IN: ui.cocoa.views
|
||||||
key-event>gesture <key-up> send-key-event ;
|
key-event>gesture <key-up> send-key-event ;
|
||||||
|
|
||||||
: mouse-event>gesture ( event -- modifiers button )
|
: mouse-event>gesture ( event -- modifiers button )
|
||||||
dup event-modifiers swap button ;
|
[ event-modifiers ] [ button ] bi ;
|
||||||
|
|
||||||
: send-button-down$ ( view event -- )
|
: send-button-down$ ( view event -- )
|
||||||
[ nip mouse-event>gesture <button-down> ]
|
[ nip mouse-event>gesture <button-down> ]
|
||||||
|
@ -107,18 +108,18 @@ IN: ui.cocoa.views
|
||||||
[ CF>string NSStringPboardType = ] [ t ] if* ;
|
[ CF>string NSStringPboardType = ] [ t ] if* ;
|
||||||
|
|
||||||
: valid-service? ( gadget send-type return-type -- ? )
|
: valid-service? ( gadget send-type return-type -- ? )
|
||||||
over string-or-nil? over string-or-nil? and
|
2dup [ string-or-nil? ] [ string-or-nil? ] bi* and
|
||||||
[ drop [ gadget-selection? ] [ drop t ] if ] [ 3drop f ] if ;
|
[ drop [ gadget-selection? ] [ drop t ] if ] [ 3drop f ] if ;
|
||||||
|
|
||||||
: NSRect>rect ( NSRect world -- rect )
|
: NSRect>rect ( NSRect world -- rect )
|
||||||
[ [ [ NSRect-x ] [ NSRect-y ] bi ] [ dim>> second ] bi* swap - 2array ]
|
[ [ [ CGRect-x ] [ CGRect-y ] bi ] [ dim>> second ] bi* swap - 2array ]
|
||||||
[ drop [ NSRect-w ] [ NSRect-h ] bi 2array ]
|
[ drop [ CGRect-w ] [ CGRect-h ] bi 2array ]
|
||||||
2bi <rect> ;
|
2bi <rect> ;
|
||||||
|
|
||||||
: rect>NSRect ( rect world -- NSRect )
|
: rect>NSRect ( rect world -- NSRect )
|
||||||
[ [ rect-loc first2 ] [ dim>> second ] bi* swap - ]
|
[ [ rect-loc first2 ] [ dim>> second ] bi* swap - ]
|
||||||
[ drop rect-dim first2 ]
|
[ drop rect-dim first2 ]
|
||||||
2bi <NSRect> ;
|
2bi <CGRect> ;
|
||||||
|
|
||||||
CLASS: {
|
CLASS: {
|
||||||
{ +superclass+ "NSOpenGLView" }
|
{ +superclass+ "NSOpenGLView" }
|
||||||
|
@ -318,7 +319,7 @@ CLASS: {
|
||||||
}
|
}
|
||||||
|
|
||||||
{ "firstRectForCharacterRange:" "NSRect" { "id" "SEL" "NSRange" }
|
{ "firstRectForCharacterRange:" "NSRect" { "id" "SEL" "NSRange" }
|
||||||
[ 3drop 0 0 0 0 <NSRect> ]
|
[ 3drop 0 0 0 0 <CGRect> ]
|
||||||
}
|
}
|
||||||
|
|
||||||
{ "conversationIdentifier" "NSInteger" { "id" "SEL" }
|
{ "conversationIdentifier" "NSInteger" { "id" "SEL" }
|
||||||
|
@ -369,8 +370,9 @@ CLASS: {
|
||||||
{ "windowDidMove:" "void" { "id" "SEL" "id" }
|
{ "windowDidMove:" "void" { "id" "SEL" "id" }
|
||||||
[
|
[
|
||||||
2nip -> object
|
2nip -> object
|
||||||
dup window-content-rect NSRect-x-y 2array
|
[ -> contentView window ]
|
||||||
swap -> contentView window (>>window-loc)
|
[ window-content-rect CGRect-x-y 2array ] bi
|
||||||
|
>>window-loc drop
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
USING: help.syntax help.markup strings kernel alien opengl
|
USING: help.syntax help.markup strings kernel alien opengl
|
||||||
quotations ui.render io.styles freetype ;
|
opengl.sprites quotations ui.render io.styles freetype ;
|
||||||
IN: ui.freetype
|
IN: ui.freetype
|
||||||
|
|
||||||
HELP: freetype
|
HELP: freetype
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
USING: ui.gadgets ui.render ui.gestures ui.backend help.markup
|
USING: ui.gadgets ui.render ui.gestures ui.backend help.markup
|
||||||
help.syntax models opengl strings ;
|
help.syntax models opengl opengl.sprites strings ;
|
||||||
IN: ui.gadgets.worlds
|
IN: ui.gadgets.worlds
|
||||||
|
|
||||||
HELP: user-input
|
HELP: user-input
|
||||||
|
|
|
@ -81,9 +81,9 @@ UNION: definition word method-spec link vocab vocab-link ;
|
||||||
[ definition? ] \ com-forget H{ } define-operation
|
[ definition? ] \ com-forget H{ } define-operation
|
||||||
|
|
||||||
! Words
|
! Words
|
||||||
[ word? ] \ insert-word H{
|
! [ word? ] \ insert-word H{
|
||||||
{ +secondary+ t }
|
! { +secondary+ t }
|
||||||
} define-operation
|
! } define-operation
|
||||||
|
|
||||||
[ topic? ] \ com-follow H{
|
[ topic? ] \ com-follow H{
|
||||||
{ +keyboard+ T{ key-down f { C+ } "h" } }
|
{ +keyboard+ T{ key-down f { C+ } "h" } }
|
||||||
|
|
Loading…
Reference in New Issue