]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.backend.gtk: use a global variable to store the icon data
authorBjörn Lindqvist <bjourne@gmail.com>
Fri, 17 Jun 2016 14:35:15 +0000 (16:35 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Fri, 17 Jun 2016 14:39:11 +0000 (16:39 +0200)
It's easier than the previous code that replaced the get-icon-data word
during deployment. Also GTK support for icon.ico icons.

basis/tools/deploy/shaker/strip-gtk-icon.factor
basis/ui/backend/gtk/gtk-docs.factor
basis/ui/backend/gtk/gtk-tests.factor
basis/ui/backend/gtk/gtk.factor
core/vocabs/loader/loader-docs.factor

index e444d9a390c4d8793f6d7cb7c32fc1f1691c3491..23c9b32a5a45ca3910d2e4267618260e7eb14b30 100644 (file)
@@ -1,13 +1,6 @@
 ! 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 ;
+USING: namespaces tools.deploy.shaker ;
 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_128x128.png" ?
-        binary file-contents
-    ]
+deploy-vocab get vocab-icon-data icon-data set-global
index de069ee1e3d62f62b1dac6bed8b8ee1461cc5150..958259b686a2caadeda37519a1d5abeb9786d7ae 100644 (file)
@@ -1,4 +1,5 @@
-USING: alien gdk.ffi gtk.ffi help.markup help.syntax kernel ;
+USING: alien byte-arrays gdk.ffi gtk.ffi help.markup help.syntax
+kernel ;
 IN: ui.backend.gtk
 
 HELP: configure-im
@@ -6,6 +7,9 @@ HELP: configure-im
 { $description "Configures the input methods of the window. Must only be run after the window has been realized." }
 { $see-also gtk_widget_realize } ;
 
+HELP: icon-data
+{ $var-description "Contains a " { $link byte-array } " or " { $link f } " which is the data for the icon to be used for gtk windows. The variable is updated to contain a vocab-specific icon when deploying. See " { $link "vocabs.icons" } " and 'tools.deploy.shaker.strip-gtk-icon'." } ;
+
 HELP: on-configure
 { $values
   { "win" alien }
index 69ea1806daf1524cc52d703ca9890cabca3692d9..a3a285a4777d7da7e0e6f785433c69ab11790229 100644 (file)
@@ -1,5 +1,5 @@
-USING: alien.syntax classes.struct gdk.ffi kernel system tools.test
-ui.backend.gtk ui.gestures ;
+USING: alien.syntax classes.struct gdk.ffi kernel sequences system
+tools.test ui.backend.gtk ui.gestures ;
 IN: ui.backend.gtk.tests
 
 : gdk-key-release-event ( -- event )
@@ -59,3 +59,7 @@ os linux? [
         gdk-space-key-press-event key-event>gesture
     ] unit-test
 ] when
+
+{ 9854 } [
+    "gpu.demos.bunny" vocab-icon-data length
+] unit-test
index f693893e3fb8701390fe0b9fc464a13a7e2bb7b0..e1616b5f34664fe5c3844861739b159326d39422 100644 (file)
@@ -1,16 +1,15 @@
 ! Copyright (C) 2010, 2011 Anton Gorenko, Philipp Bruschweiler.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.accessors alien.c-types alien.data
-alien.strings arrays assocs classes.struct combinators
-continuations destructors environment gdk.ffi gdk.gl.ffi
-gdk.pixbuf.ffi glib.ffi gobject-introspection.standard-types
-gobject.ffi gtk.ffi gtk.gl.ffi io.encodings.binary
-io.encodings.utf8 io.files kernel libc literals locals math
-math.bitwise math.vectors namespaces sequences strings system
-threads ui ui.backend ui.backend.gtk.input-methods
-ui.backend.gtk.io ui.clipboards ui.event-loop ui.gadgets
-ui.gadgets.private ui.gadgets.worlds ui.gestures
-ui.pixel-formats ui.pixel-formats.private ui.private
+alien.strings arrays assocs classes.struct combinators continuations
+destructors environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi
+gobject-introspection.standard-types gobject.ffi gtk.ffi gtk.gl.ffi
+io.encodings.binary io.encodings.utf8 io.files io.pathnames kernel
+libc literals locals math math.bitwise math.vectors namespaces
+sequences strings system threads ui ui.backend
+ui.backend.gtk.input-methods ui.backend.gtk.io ui.clipboards
+ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds
+ui.gestures ui.pixel-formats ui.pixel-formats.private ui.private
 vocabs.loader ;
 IN: ui.backend.gtk
 
@@ -215,15 +214,25 @@ CONSTANT: action-key-codes
 : on-focus-out ( win event user-data -- ? )
     2drop window unfocus-world t ;
 
-! This word gets replaced when deploying. See 'Vocabulary icons'
-! in the docs and tools.deploy.shaker.gtk-icon
-: get-icon-data ( -- byte-array/f )
+CONSTANT: default-icon-path "resource:misc/icons/Factor_128x128.png"
+
+: default-icon-data ( -- byte-array/f )
     [
-        "resource:misc/icons/Factor_128x128.png" binary file-contents
+        default-icon-path binary file-contents
     ] [ drop f ] recover ;
 
+SYMBOL: icon-data
+
+icon-data [ default-icon-data ] initialize
+
+: vocab-icon-data ( vocab-name -- byte-array )
+    dup vocab-dir { "icon.png" "icon.ico" } [
+        append-path vocab-append-path
+    ] 2with map default-icon-path suffix
+    [ exists? ] find nip binary file-contents ;
+
 : load-icon ( -- )
-    get-icon-data [
+    icon-data get [
         [
             data>GInputStream &g_object_unref
             GInputStream>GdkPixbuf gtk_window_set_default_icon
index b1f1796e1495d2a409fa0c9e24894356322e5be3..6d8bad2536bf19c24f2606a14d7f985a6e4b6e2e 100755 (executable)
@@ -30,10 +30,11 @@ ARTICLE: "vocabs.roots" "Vocabulary roots"
 ARTICLE: "vocabs.icons" "Vocabulary icons"
 "An icon file representing the vocabulary can be provided for use by " { $link "tools.deploy" } ". If any of the following files exist inside the vocabulary directory, they will be used as icons when the application is deployed."
 { $list
-    { { $snippet "icon.ico" } " on Windows" }
+    { { $snippet "icon.ico" } " on Windows and Linux" }
     { { $snippet "icon.icns" } " on MacOS X" }
-    { { $snippet "icon.png" } " on Linux and *BSD" }
-} ;
+    { { $snippet "icon.png" } " on Linux" }
+}
+"The icon file will be embedded in the vocab's image file." ;
 
 ARTICLE: "vocabs.loader" "Vocabulary loader"
 "The " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " words load vocabularies using the vocabulary loader. The vocabulary loader is implemented in the " { $vocab-link "vocabs.loader" } " vocabulary."