 IN: ui.backend.windows
 
 SINGLETON: windows-ui-backend
+
+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
 
 <PRIVATE
 

    f class-name-ptr set-global
    f msg-obj set-global ;

: get-dc ( hWnd -- hDC ) GetDC dup win32-error=0/f ;

: get-rc ( hDC -- hRC )
    dup wglCreateContext dup win32-error=0/f
    [ wglMakeCurrent win32-error=0/f ] keep ;

: set-pixel-format ( pixel-format hdc -- )
    swap handle>> "PIXELFORMATDESCRIPTOR" <c-object> SetPixelFormat win32-error=0/f ;

: setup-gl ( world hwnd -- hDC hRC )
    get-dc
    [ [ drop ] 2dip [ set-pixel-format ] [ ] [ get-rc ] tri ]
    curry with-world-pixel-format ;

M: windows-ui-backend (open-window) ( world -- )
    [ dup create-window [ setup-gl ] keep ] keep
    [ f <win> ] keep
    [ swap hWnd>> register-window ] 2keep
    dupd (>>handle)
    hWnd>> show-window ;

M: win-base select-gl-context ( handle -- )
    [ hDC>> ] [ hRC>> ] bi wglMakeCurrent win32-error=0/f

: init-clipboard ( -- )
    <pasteboard> clipboard set-global
    <clipboard> selection set-global ;

SYMBOLS: msg-obj class-name-ptr mouse-captured ;

