ui.backend.gtk: load icon data directly into factor.image when deploying, no io is needed
							parent
							
								
									ab29ed3892
								
							
						
					
					
						commit
						8c61b874b7
					
				| 
						 | 
				
			
			@ -1,7 +1,8 @@
 | 
			
		|||
! Copyright (C) 2009 Anton Gorenko.
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: alien alien.libraries combinators kernel system
 | 
			
		||||
gobject-introspection gio.ffi glib.ffi gmodule.ffi gobject.ffi ;
 | 
			
		||||
USING: alien alien.data alien.libraries alien.syntax
 | 
			
		||||
combinators gio.ffi glib.ffi gmodule.ffi gobject-introspection
 | 
			
		||||
gobject.ffi kernel libc sequences system ;
 | 
			
		||||
EXCLUDE: alien.c-types => pointer ;
 | 
			
		||||
IN: gdk.pixbuf.ffi
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -15,3 +16,11 @@ IN: gdk.pixbuf.ffi
 | 
			
		|||
 | 
			
		||||
GIR: vocab:gdk/pixbuf/GdkPixbuf-2.0.gir
 | 
			
		||||
 | 
			
		||||
: data>GInputStream ( data -- GInputStream )
 | 
			
		||||
    [ malloc-byte-array &free ] [ length ] bi
 | 
			
		||||
    f g_memory_input_stream_new_from_data ;
 | 
			
		||||
 | 
			
		||||
: GInputStream>GdkPixbuf ( GInputStream -- GdkPixbuf )
 | 
			
		||||
    f { { pointer: GError initial: f } }
 | 
			
		||||
    [ gdk_pixbuf_new_from_stream ] with-out-parameters
 | 
			
		||||
    handle-GError ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,9 @@
 | 
			
		|||
! Copyright (C) 2010 Philipp Brüschweiler.
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: accessors alien.c-types alien.data alien.strings
 | 
			
		||||
alien.syntax arrays classes.struct combinators destructors
 | 
			
		||||
gdk.pixbuf.ffi gio.ffi glib.ffi gobject.ffi grouping images
 | 
			
		||||
images.loader io io.encodings.utf8
 | 
			
		||||
kernel libc locals math sequences specialized-arrays ;
 | 
			
		||||
USING: accessors alien.c-types alien.data arrays combinators
 | 
			
		||||
destructors gdk.pixbuf.ffi gobject.ffi grouping images
 | 
			
		||||
images.loader io kernel locals math sequences
 | 
			
		||||
specialized-arrays ;
 | 
			
		||||
IN: images.gtk
 | 
			
		||||
SPECIALIZED-ARRAY: uchar
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -20,15 +19,6 @@ SINGLETON: gtk-image
 | 
			
		|||
 | 
			
		||||
<PRIVATE
 | 
			
		||||
 | 
			
		||||
: data>GInputStream ( data -- GInputStream )
 | 
			
		||||
    [ malloc-byte-array &free ] [ length ] bi
 | 
			
		||||
    f g_memory_input_stream_new_from_data &g_object_unref ;
 | 
			
		||||
 | 
			
		||||
: GInputStream>GdkPixbuf ( GInputStream -- GdkPixbuf )
 | 
			
		||||
    f { { pointer: GError initial: f } }
 | 
			
		||||
    [ gdk_pixbuf_new_from_stream ] with-out-parameters
 | 
			
		||||
    handle-GError &g_object_unref ;
 | 
			
		||||
 | 
			
		||||
: image-data ( GdkPixbuf -- data )
 | 
			
		||||
    {
 | 
			
		||||
        [ gdk_pixbuf_get_pixels ]
 | 
			
		||||
| 
						 | 
				
			
			@ -72,6 +62,7 @@ PRIVATE>
 | 
			
		|||
 | 
			
		||||
M: gtk-image stream>image
 | 
			
		||||
    drop [
 | 
			
		||||
        stream-contents data>GInputStream
 | 
			
		||||
        GInputStream>GdkPixbuf GdkPixbuf>image
 | 
			
		||||
        stream-contents data>GInputStream &g_object_unref
 | 
			
		||||
        GInputStream>GdkPixbuf &g_object_unref
 | 
			
		||||
        GdkPixbuf>image
 | 
			
		||||
    ] with-destructors ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -93,6 +93,13 @@ IN: tools.deploy.shaker
 | 
			
		|||
        run-file
 | 
			
		||||
    ] when ;
 | 
			
		||||
 | 
			
		||||
: strip-gtk-icon ( -- )
 | 
			
		||||
    "ui.backend.gtk" vocab [
 | 
			
		||||
        "Stripping GTK icon loading code" show
 | 
			
		||||
        "vocab:tools/deploy/shaker/strip-gtk-icon.factor"
 | 
			
		||||
        run-file
 | 
			
		||||
    ] when ;
 | 
			
		||||
 | 
			
		||||
: strip-specialized-arrays ( -- )
 | 
			
		||||
    strip-dictionary? "specialized-arrays" vocab and [
 | 
			
		||||
        "Stripping specialized arrays" show
 | 
			
		||||
| 
						 | 
				
			
			@ -534,6 +541,7 @@ SYMBOL: deploy-vocab
 | 
			
		|||
    strip-destructors
 | 
			
		||||
    strip-call
 | 
			
		||||
    strip-cocoa
 | 
			
		||||
    strip-gtk-icon
 | 
			
		||||
    strip-debugger
 | 
			
		||||
    strip-ui-error-hook
 | 
			
		||||
    strip-specialized-arrays
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
! Copyright (C) 2010 Philipp Brüschweiler
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: kernel tools.deploy.shaker literals namespaces
 | 
			
		||||
vocabs.loader io.pathnames io.files io.encodings.binary ;
 | 
			
		||||
IN: ui.backend.gtk
 | 
			
		||||
 | 
			
		||||
CONSTANT: get-icon-data
 | 
			
		||||
    $[
 | 
			
		||||
        deploy-vocab get
 | 
			
		||||
        dup vocab-dir "icon.png" append-path vocab-append-path
 | 
			
		||||
        [ exists? ] keep "resource:misc/icons/Factor_48x48.png" ?
 | 
			
		||||
        binary file-contents
 | 
			
		||||
    ]
 | 
			
		||||
| 
						 | 
				
			
			@ -1,22 +1,12 @@
 | 
			
		|||
! Copyright (C) 2008 James Cash
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: io io.backend io.directories io.files io.files.info.unix
 | 
			
		||||
io.pathnames kernel namespaces sequences system
 | 
			
		||||
tools.deploy.backend tools.deploy.config
 | 
			
		||||
tools.deploy.config.editor vocabs.loader vocabs.metadata ;
 | 
			
		||||
USING: io io.backend io.directories io.files.info.unix kernel
 | 
			
		||||
namespaces sequences system tools.deploy.backend
 | 
			
		||||
tools.deploy.config tools.deploy.config.editor ;
 | 
			
		||||
IN: tools.deploy.unix
 | 
			
		||||
 | 
			
		||||
: used-icon ( vocab -- ico )
 | 
			
		||||
    dup vocab-dir "icon.png" append-path vocab-append-path
 | 
			
		||||
    [ exists? ] keep "vocab:ui/backend/gtk/icon.png" ? ;
 | 
			
		||||
 | 
			
		||||
: copy-icon ( vocab bundle-name -- )
 | 
			
		||||
    [ used-icon ]
 | 
			
		||||
    [ "ui/backend/gtk/icon.png" append-path ] bi*
 | 
			
		||||
    copy-file ;
 | 
			
		||||
 | 
			
		||||
: create-app-dir ( vocab bundle-name -- vm )
 | 
			
		||||
    [ copy-vm ] [ copy-icon ] 2bi
 | 
			
		||||
    copy-vm
 | 
			
		||||
    dup OCT: 755 set-file-permissions ;
 | 
			
		||||
 | 
			
		||||
: bundle-name ( -- str )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,16 +1,17 @@
 | 
			
		|||
! Copyright (C) 2010 Anton Gorenko, Philipp Brüschweiler.
 | 
			
		||||
! See http://factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: accessors alien.accessors alien.c-types alien.data
 | 
			
		||||
alien.strings alien.syntax arrays assocs classes.struct
 | 
			
		||||
command-line destructors gdk.ffi gdk.gl.ffi glib.ffi
 | 
			
		||||
alien.strings arrays assocs classes.struct command-line
 | 
			
		||||
destructors gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi
 | 
			
		||||
gobject.ffi gtk.ffi gtk.gl.ffi io.backend
 | 
			
		||||
io.backend.unix.multiplexers io.encodings.utf8 io.thread kernel
 | 
			
		||||
libc literals locals math math.bitwise math.order math.vectors
 | 
			
		||||
namespaces sequences strings system threads ui ui.backend
 | 
			
		||||
ui.clipboards ui.commands ui.event-loop ui.gadgets
 | 
			
		||||
ui.gadgets.editors ui.gadgets.menus ui.gadgets.private
 | 
			
		||||
ui.gadgets.worlds ui.gestures ui.pixel-formats
 | 
			
		||||
ui.pixel-formats.private ui.private ;
 | 
			
		||||
io.backend.unix.multiplexers io.encodings.binary
 | 
			
		||||
io.encodings.utf8 io.files io.thread kernel libc literals
 | 
			
		||||
locals math math.bitwise math.order math.vectors namespaces
 | 
			
		||||
sequences strings system threads ui ui.backend ui.clipboards
 | 
			
		||||
ui.commands ui.event-loop ui.gadgets ui.gadgets.editors
 | 
			
		||||
ui.gadgets.menus ui.gadgets.private ui.gadgets.worlds
 | 
			
		||||
ui.gestures ui.pixel-formats ui.pixel-formats.private
 | 
			
		||||
ui.private ;
 | 
			
		||||
IN: ui.backend.gtk
 | 
			
		||||
 | 
			
		||||
SINGLETON: gtk-ui-backend
 | 
			
		||||
| 
						 | 
				
			
			@ -268,15 +269,16 @@ SYMBOL: next-timeout
 | 
			
		|||
    f g_source_attach drop
 | 
			
		||||
    nano-count next-timeout set-global ;
 | 
			
		||||
 | 
			
		||||
! This word gets replaced when deploying. See 'Vocabulary icons'
 | 
			
		||||
! in the docs and tools.deploy.shaker.gtk-icon
 | 
			
		||||
: get-icon-data ( -- byte-array )
 | 
			
		||||
    "resource:misc/icons/Factor_48x48.png" binary file-contents ;
 | 
			
		||||
 | 
			
		||||
: load-icon ( -- )
 | 
			
		||||
    ! This file is not in a resource.txt because it can be
 | 
			
		||||
    ! overwritten when deploying. See 'Vocabulary icons'
 | 
			
		||||
    ! in the docs.
 | 
			
		||||
    "vocab:ui/backend/gtk/icon.png"
 | 
			
		||||
    normalize-path utf8 string>alien
 | 
			
		||||
    { { pointer: GError initial: f } }
 | 
			
		||||
    [ gtk_window_set_default_icon_from_file ] with-out-parameters
 | 
			
		||||
    handle-GError drop ;
 | 
			
		||||
    get-icon-data [
 | 
			
		||||
        data>GInputStream &g_object_unref
 | 
			
		||||
        GInputStream>GdkPixbuf gtk_window_set_default_icon
 | 
			
		||||
    ] with-destructors ;
 | 
			
		||||
 | 
			
		||||
M: gtk-ui-backend (with-ui)
 | 
			
		||||
    [
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 7.1 KiB  | 
		Loading…
	
		Reference in New Issue