]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Tue, 9 Dec 2008 03:32:49 +0000 (19:32 -0800)
committerJoe Groff <arcata@gmail.com>
Tue, 9 Dec 2008 03:32:49 +0000 (19:32 -0800)
1  2 
basis/ui/cocoa/cocoa.factor

index 8861f8ffa21af92838736f0a6491586a0e158d35,42063fbf7326b21adede23677ff24484b886ebb6..811d35a8a12aa97019765850a0f61762d1c00ddc
@@@ -1,23 -1,16 +1,23 @@@
  ! Copyright (C) 2006, 2008 Slava Pestov.
  ! See http://factorcode.org/license.txt for BSD license.
- USING: accessors math arrays cocoa cocoa.application
+ USING: accessors math arrays assocs cocoa cocoa.application
  command-line kernel memory namespaces cocoa.messages
  cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
  cocoa.windows cocoa.classes cocoa.application sequences system
  ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
 -ui.cocoa.views core-foundation threads math.geometry.rect fry ;
 +ui.cocoa.views core-foundation threads math.geometry.rect fry
 +libc generalizations ;
  IN: ui.cocoa
  
 -TUPLE: handle view window ;
 +TUPLE: handle ;
 +TUPLE: window-handle < handle view window ;
 +TUPLE: offscreen-handle < handle context buffer ;
  
 -C: <handle> handle
 +C: <window-handle> window-handle
 +C: <offscreen-handle> offscreen-handle
 +
 +M: offscreen-handle window>> f ;
 +M: offscreen-handle view>>   f ;
  
  SINGLETON: cocoa-ui-backend
  
@@@ -45,8 -38,7 +45,8 @@@ M: pasteboard set-clipboard-content
  : gadget-window ( world -- )
      dup <FactorView>
      2dup swap world>NSRect <ViewWindow>
 -    [ [ -> release ] [ install-window-delegate ] bi* ] [ <handle> ] 2bi
 +    [ [ -> release ] [ install-window-delegate ] bi* ]
 +    [ <window-handle> ] 2bi
      >>handle drop ;
  
  M: cocoa-ui-backend set-title ( string world -- )
@@@ -95,50 -87,38 +95,63 @@@ M: cocoa-ui-backend raise-window* ( wor
          NSApp 1 -> activateIgnoringOtherApps:
      ] when* ;
  
 -M: cocoa-ui-backend select-gl-context ( handle -- )
 -    view>> -> openGLContext -> makeCurrentContext ;
 +: pixel-size ( pixel-format -- size )
 +    0 <int> [ NSOpenGLPFAColorSize 0 -> getValues:forAttribute:forVirtualScreen: ]
 +    keep *int -3 shift ;
 +
 +: offscreen-buffer ( world pixel-format -- alien w h pitch )
 +    [ dim>> first2 ] [ pixel-size ] bi*
 +    { [ * * malloc ] [ 2drop ] [ drop nip ] [ nip * ] } cleave ;
 +
 +: gadget-offscreen-context ( world -- context buffer )
 +    { NSOpenGLPFAOffscreen } <PixelFormat>
 +    [ NSOpenGLContext -> alloc swap f -> initWithFormat:shareContext: ]
 +    [ offscreen-buffer ] bi
 +    4 npick [ setOffScreen:width:height:rowbytes: ] dip ;
 +
 +M: cocoa-ui-backend (open-offscreen-buffer) ( world -- )
 +    dup gadget-offscreen-context <offscreen-handle> >>handle drop ;
 +
 +M: cocoa-ui-backend (close-offscreen-buffer) ( handle -- )
 +    [ context>> -> release ]
 +    [ buffer>> free ] bi ;
 +
 +GENERIC: gl-context ( handle -- context )
 +M: window-handle gl-context view>> -> openGLContext ;
 +M: offscreen-handle gl-context context>> ;
 +
 +M: handle select-gl-context ( handle -- )
 +    gl-context -> makeCurrentContext ;
  
 -M: cocoa-ui-backend flush-gl-context ( handle -- )
 -    view>> -> openGLContext -> flushBuffer ;
 +M: handle flush-gl-context ( handle -- )
 +    gl-context -> flushBuffer ;
  
  M: cocoa-ui-backend beep ( -- )
      NSBeep ;
  
+ CLASS: {
+     { +superclass+ "NSObject" }
+     { +name+ "FactorApplicationDelegate" }
+ }
+ { "applicationDidFinishLaunching:" "void" { "id" "SEL" "id" }
+     [ 3drop event-loop ]
+ } ;
+ : install-app-delegate ( -- )
+     NSApp FactorApplicationDelegate install-delegate ;
  SYMBOL: cocoa-init-hook
  
+ cocoa-init-hook global [ [ install-app-delegate ] or ] change-at
  M: cocoa-ui-backend ui
      "UI" assert.app [
          [
              init-clipboard
-             cocoa-init-hook get [ call ] when*
+             cocoa-init-hook get call
              start-ui
-             finish-launching
-             event-loop
+             NSApp -> run
          ] ui-running
      ] with-cocoa ;