]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Fri, 12 Dec 2008 01:16:12 +0000 (17:16 -0800)
committerJoe Groff <arcata@gmail.com>
Fri, 12 Dec 2008 01:16:12 +0000 (17:16 -0800)
1  2 
basis/ui/ui.factor
basis/ui/windows/windows.factor
basis/ui/x11/x11.factor

diff --combined basis/ui/ui.factor
index e3401cdb332bf340fd1284532030fb22bfb6d3cc,d9ff2870144127200cb377a7a3fb4b6044ebd140..1ee860c9748d0ea6316fd7e92f44331ff9748add
@@@ -60,26 -60,23 +60,26 @@@ SYMBOL: stop-after-last-window
      focus-path f swap focus-gestures ;
  
  M: world graft*
 -    dup (open-window)
 -    dup title>> over set-title
 -    request-focus ;
 +    [ (open-window) ]
 +    [ [ title>> ] keep set-title ]
 +    [ request-focus ] tri ;
  
  : reset-world ( world -- )
      #! This is used when a window is being closed, but also
      #! when restoring saved worlds on image startup.
 -    dup fonts>> clear-assoc
 -    dup unfocus-world
 -    f >>handle drop ;
 +    [ fonts>> clear-assoc ]
 +    [ unfocus-world ]
 +    [ f >>handle drop ] tri ;
 +
 +: (ungraft-world) ( world -- )
 +    [ free-fonts ]
 +    [ hand-clicked close-global ]
 +    [ hand-gadget close-global ] tri ;
  
  M: world ungraft*
 -    dup free-fonts
 -    dup hand-clicked close-global
 -    dup hand-gadget close-global
 -    dup handle>> (close-window)
 -    reset-world ;
 +    [ (ungraft-world) ]
 +    [ handle>> (close-window) ]
 +    [ reset-world ] tri ;
  
  : find-window ( quot -- world )
      windows get values
@@@ -143,7 -140,7 +143,7 @@@ SYMBOL: ui-hoo
      graft-queue [ notify ] slurp-deque ;
  
  : send-queued-gestures ( -- )
-     gesture-queue [ send-queued-gesture ] slurp-deque ;
+     gesture-queue [ send-queued-gesture notify-queued ] slurp-deque ;
  
  : update-ui ( -- )
      [
index 8e60ad1bc583f9aed52a78c7a4660816d12d96cc,10539df8e7d837e4937f55c797b717a6fc6181a8..35ee9f9a600ca2ef67021c3887404487c112af05
@@@ -6,7 -6,7 +6,7 @@@ ui.gadgets ui.backend ui.clipboards ui.
  ui.gestures io kernel math math.vectors namespaces make
  sequences strings vectors words windows.kernel32 windows.gdi32
  windows.user32 windows.opengl32 windows.messages windows.types
 -windows.nt windows threads libc combinators
 +windows.nt windows threads libc combinators fry
  combinators.short-circuit continuations command-line shuffle
  opengl ui.render ascii math.bitwise locals symbols accessors
  math.geometry.rect math.order ascii calendar
@@@ -70,11 -70,9 +70,11 @@@ M: pasteboard set-clipboard-contents dr
      <pasteboard> clipboard set-global
      <clipboard> selection set-global ;
  
 -! world-handle is a <win>
 -TUPLE: win hWnd hDC hRC world title ;
 +TUPLE: win-base hDC hRC ;
 +TUPLE: win < win-base hWnd world title ;
 +TUPLE: win-offscreen < win-base hBitmap bits ;
  C: <win> win
 +C: <win-offscreen> win-offscreen
  
  SYMBOLS: msg-obj class-name-ptr mouse-captured ;
  
  
  : send-key-gesture ( sym action? quot hWnd -- )
      [ [ key-modifiers ] 3dip call ] dip
-     window-focus propagate-gesture ; inline
+     window propagate-key-gesture ; inline
  
  : send-key-down ( sym action? hWnd -- )
      [ [ <key-down> ] ] dip send-key-gesture ;
          ctrl? alt? xor [
              wParam 1string
              [ f hWnd send-key-down ]
-             [ hWnd window-focus user-input ] bi
+             [ hWnd window user-input ] bi
          ] unless
      ] unless ;
  
@@@ -481,8 -479,8 +481,8 @@@ M: windows-ui-backend do-event
      f class-name-ptr set-global
      f msg-obj set-global ;
  
 -: setup-pixel-format ( hdc -- )
 -    16 make-pfd [ ChoosePixelFormat dup win32-error=0/f ] 2keep
 +: setup-pixel-format ( hdc flags -- )
 +    32 make-pfd [ ChoosePixelFormat dup win32-error=0/f ] 2keep
      swapd SetPixelFormat win32-error=0/f ;
  
  : get-dc ( hWnd -- hDC ) GetDC dup win32-error=0/f ;
      [ wglMakeCurrent win32-error=0/f ] keep ;
  
  : setup-gl ( hwnd -- hDC hRC )
 -    get-dc dup setup-pixel-format dup get-rc ;
 +    get-dc dup windowed-pfd-dwFlags setup-pixel-format dup get-rc ;
  
  M: windows-ui-backend (open-window) ( world -- )
 -    [ create-window dup setup-gl ] keep
 +    [ create-window [ setup-gl ] keep ] keep
      [ f <win> ] keep
      [ swap hWnd>> register-window ] 2keep
      dupd (>>handle)
      hWnd>> show-window ;
  
 -M: windows-ui-backend select-gl-context ( handle -- )
 -    [ hDC>> ] keep hRC>> wglMakeCurrent win32-error=0/f ;
 +M: win-base select-gl-context ( handle -- )
 +    [ hDC>> ] keep hRC>> wglMakeCurrent win32-error=0/f
 +    GdiFlush drop ;
  
 -M: windows-ui-backend flush-gl-context ( handle -- )
 +M: win-base flush-gl-context ( handle -- )
      hDC>> SwapBuffers win32-error=0/f ;
  
 -! Move window to front
 +: (bitmap-info) ( dim -- BITMAPINFO )
 +    "BITMAPINFO" <c-object> [
 +        BITMAPINFO-bmiHeader {
 +            [ nip "BITMAPINFOHEADER" heap-size swap set-BITMAPINFOHEADER-biSize ]
 +            [ [ first ] dip set-BITMAPINFOHEADER-biWidth ]
 +            [ [ second ] dip set-BITMAPINFOHEADER-biHeight ]
 +            [ nip 1 swap set-BITMAPINFOHEADER-biPlanes ]
 +            [ nip 32 swap set-BITMAPINFOHEADER-biBitCount ]
 +            [ nip BI_RGB swap set-BITMAPINFOHEADER-biCompression ]
 +            [ [ first2 * 4 * ] dip set-BITMAPINFOHEADER-biSizeImage ]
 +            [ nip 72 swap set-BITMAPINFOHEADER-biXPelsPerMeter ]
 +            [ nip 72 swap set-BITMAPINFOHEADER-biYPelsPerMeter ]
 +            [ nip 0 swap set-BITMAPINFOHEADER-biClrUsed ]
 +            [ nip 0 swap set-BITMAPINFOHEADER-biClrImportant ]
 +        } 2cleave
 +    ] keep ;
 +
 +: make-offscreen-dc-and-bitmap ( dim -- hDC hBitmap bits )
 +    f CreateCompatibleDC
 +    dup rot (bitmap-info) DIB_RGB_COLORS f <void*>
 +    [ f 0 CreateDIBSection ] keep *void*
 +    [ 2dup SelectObject drop ] dip ;
 +
 +: setup-offscreen-gl ( dim -- hDC hRC hBitmap bits )
 +    make-offscreen-dc-and-bitmap [
 +        [ dup offscreen-pfd-dwFlags setup-pixel-format ]
 +        [ get-rc ] bi
 +    ] 2dip ;
 +
 +M: windows-ui-backend (open-offscreen-buffer) ( world -- )
 +    dup dim>> setup-offscreen-gl <win-offscreen>
 +    >>handle drop ;
 +M: windows-ui-backend (close-offscreen-buffer) ( handle -- )
 +    [ hDC>> DeleteDC drop ]
 +    [ hBitmap>> DeleteObject drop ] bi ;
 +
 +! Windows 32-bit bitmaps don't actually use the alpha byte of
 +! each pixel; it's left as zero
 +
 +: (make-opaque) ( byte-array -- byte-array' )
 +    [ length 4 / ]
 +    [ '[ 255 swap 4 * 3 + _ set-nth ] each ]
 +    [ ] tri ;
 +
 +: (opaque-pixels) ( world -- pixels )
 +    [ handle>> bits>> ] [ dim>> first2 * 4 * ] bi
 +    memory>byte-array (make-opaque) ;
 +
 +M: windows-ui-backend offscreen-pixels ( world -- alien w h )
 +    [ (opaque-pixels) ] [ dim>> first2 ] bi ;
 +
  M: windows-ui-backend raise-window* ( world -- )
      handle>> [
          hWnd>> SetFocus drop
diff --combined basis/ui/x11/x11.factor
index b65185967a17878d583797c0579b15968bd02202,563b98aa34048a6611c697a5e81d37a606ed0d64..817e356712505d2100b7b021f40ee1cfcd6290b0
@@@ -14,12 -14,9 +14,12 @@@ SINGLETON: x11-ui-backen
  
  : XA_NET_WM_NAME ( -- atom ) "_NET_WM_NAME" x-atom ;
  
 -TUPLE: x11-handle window glx xic ;
 +TUPLE: x11-handle-base glx ;
 +TUPLE: x11-handle < x11-handle-base xic window ;
 +TUPLE: x11-pixmap-handle < x11-handle-base pixmap glx-pixmap ;
  
  C: <x11-handle> x11-handle
 +C: <x11-pixmap-handle> x11-pixmap-handle
  
  M: world expose-event nip relayout ;
  
@@@ -86,8 -83,7 +86,7 @@@ M: world configure-even
  
  M: world key-down-event
      [ key-down-event>gesture ] keep
-     world-focus
-     [ propagate-gesture drop ]
+     [ propagate-key-gesture drop ]
      [ 2over valid-input? [ nip user-input ] [ 3drop ] if ]
      3bi ;
  
@@@ -95,7 -91,7 +94,7 @@@
      dup event-modifiers swap 0 XLookupKeysym key-code <key-up> ;
  
  M: world key-up-event
-     [ key-up-event>gesture ] dip world-focus propagate-gesture ;
+     [ key-up-event>gesture ] dip propagate-key-gesture ;
  
  : mouse-event>gesture ( event -- modifiers button loc )
      [ event-modifiers ]
@@@ -141,7 -137,7 +140,7 @@@ M: world focus-out-even
  
  M: world selection-notify-event
      [ handle>> window>> selection-from-event ] keep
-     world-focus user-input ;
+     user-input ;
  
  : supported-type? ( atom -- ? )
      { "UTF8_STRING" "STRING" "TEXT" }
@@@ -188,7 -184,7 +187,7 @@@ M: world client-even
  
  : gadget-window ( world -- )
      dup window-loc>> over rect-dim glx-window
 -    over "Factor" create-xic <x11-handle>
 +    over "Factor" create-xic rot <x11-handle>
      2dup window>> register-window
      >>handle drop ;
  
@@@ -251,33 -247,14 +250,33 @@@ M: x11-ui-backend raise-window* ( worl
          dpy get swap window>> XRaiseWindow drop
      ] when* ;
  
 -M: x11-ui-backend select-gl-context ( handle -- )
 +M: x11-handle select-gl-context ( handle -- )
      dpy get swap
 -    dup window>> swap glx>> glXMakeCurrent
 +    [ window>> ] [ glx>> ] bi glXMakeCurrent
      [ "Failed to set current GLX context" throw ] unless ;
  
 -M: x11-ui-backend flush-gl-context ( handle -- )
 +M: x11-handle flush-gl-context ( handle -- )
      dpy get swap window>> glXSwapBuffers ;
  
 +M: x11-pixmap-handle select-gl-context ( handle -- )
 +    dpy get swap
 +    [ glx-pixmap>> ] [ glx>> ] bi glXMakeCurrent
 +    [ "Failed to set current GLX context" throw ] unless ;
 +
 +M: x11-pixmap-handle flush-gl-context ( handle -- )
 +    drop ;
 +
 +M: x11-ui-backend (open-offscreen-buffer) ( world -- )
 +    dup dim>> glx-pixmap <x11-pixmap-handle> >>handle drop ;
 +M: x11-ui-backend (close-offscreen-buffer) ( handle -- )
 +    dpy get swap
 +    [ glx-pixmap>> glXDestroyGLXPixmap ]
 +    [ pixmap>> XFreePixmap drop ]
 +    [ glx>> glXDestroyContext ] 2tri ;
 +
 +M: x11-ui-backend offscreen-pixels ( world -- alien w h )
 +    [ [ dim>> ] [ handle>> pixmap>> ] bi pixmap-bits ] [ dim>> first2 ] bi ;
 +
  M: x11-ui-backend ui ( -- )
      [
          f [