/src/wrappers/gtk/library/gtk_image.e
Specman e | 189 lines | 124 code | 32 blank | 33 comment | 8 complexity | 456732faead5d443f61001e50127259f MD5 | raw file
1indexing 2 description: "GtkImage: A widget displaying an image" 3 copyright: "[ 4 Copyright (C) 2006 Nicolas Fafchamps <nicolas.fafchamps@gmail.com> and others 5 Copyright (C) 2006 eiffel-libraries team, GTK+ team 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public License 9 as published by the Free Software Foundation; either version 2.1 of 10 the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20 02110-1301 USA 21 ]" 22 date: "$Date:$" 23 revision "$Revision:$" 24 25class GTK_IMAGE 26 27inherit GTK_MISC 28 29insert 30 GTK_IMAGE_EXTERNALS 31 GTK_IMAGE_TYPE 32 GTK_ICON_SIZE 33 34creation 35 make, from_file, from_external_pointer, from_pixbuf, from_pixmap, from_stock 36 37feature {} -- Initialization 38 39 make is 40 -- Create an empty gtk_image widget. 41 require gtk_initialized: gtk.is_initialized 42 do 43 from_external_pointer (gtk_image_new) 44 end 45 46 from_file (filename: STRING) is 47 -- Create a `gtk_image' displaying the file `filename'. 48 -- If the file isn't found or can't be loaded, the 49 -- resulting `gtk_image' will display a "broken image" icon. 50 require 51 gtk_initialized: gtk.is_initialized 52 filename_not_void: filename/=Void 53 do 54 from_external_pointer (gtk_image_new_from_file (filename.to_external)) 55 end 56 57 58 from_pixbuf (pic: GDK_PIXBUF) is 59 -- Creates a new GtkImage displaying `pic'. 60 require 61 gtk_initialized: gtk.is_initialized 62 pixbuf_not_void: pic /= Void 63 do 64 from_external_pointer (gtk_image_new_from_pixbuf (pic.handle)) 65 end 66 67 from_pixmap (a_pixmap: GDK_PIXMAP; a_mask: GDK_BITMAP) is 68 -- Creates a GtkImage widget displaying pixmap with a mask. 69 -- A GDK_PIXMAP is a server-side image buffer in the pixel 70 -- format of the current display. 71 require gtk_initialized: gtk.is_initialized 72 local 73 pixmap_ptr, mask_ptr: POINTER 74 do 75 if a_pixmap /= Void then pixmap_ptr := a_pixmap.handle end 76 if a_mask /= Void then mask_ptr := a_mask.handle end 77 from_external_pointer (gtk_image_new_from_pixmap (pixmap_ptr, mask_ptr)) 78 end 79 80 from_stock (a_stock_item: STRING; a_size: INTEGER) is 81 require 82 gtk.is_initialized 83 a_stock_item /= Void 84 is_valid_gtk_icon_size (a_size) 85 do 86 from_external_pointer (gtk_image_new_from_stock (a_stock_item.to_external, a_size)) 87 end 88 89 -- Todo : Write gdk_visual, gdk_pixmap, ... 90 -- Todo : gtk_icon_stock (?), gtk_icon_size (?), I am looking how to good implement. 91 92 93 -- Todo : GtkWidget* gtk_image_new_from_icon_set () 94 -- Todo : GtkWidget* gtk_image_new_from_image () 95 -- Todo : GtkWidget* gtk_image_new_from_animation () 96 -- Todo : GtkWidget* gtk_image_new_from_icon_name () 97 98feature -- Access 99 100 storage_type: INTEGER is 101 do 102 Result := gtk_image_get_storage_type (handle) 103 ensure 104 is_valid_gtk_image_type (Result) 105 end 106 107 pixbuf: GDK_PIXBUF is 108 require 109 storage_type = gtk_image_pixbuf or storage_type = gtk_image_empty 110 local 111 pixbuf_ptr: POINTER 112 factory: G_OBJECT_EXPANDED_FACTORY [GDK_PIXBUF] 113 do 114 pixbuf_ptr := gtk_image_get_pixbuf (handle) 115 if pixbuf_ptr.is_not_null then 116 Result := factory.wrapper (pixbuf_ptr) 117 if Result = Void then 118 -- We use from_external_pointer here because we *need* to 119 -- increase the pixbuf's refcount 120 create Result.from_external_pointer (pixbuf_ptr) 121 end 122 end 123 end 124 125feature -- Element change 126 set_file (filename: STRING) is 127 -- Set the `gtk_image' displaying the file `filename'. 128 -- If the file isn't found or can't be loaded, the 129 -- resulting gtk_image will display a "broken image" icon. 130 require 131 valid_filename: filename /= Void 132 do 133 gtk_image_set_from_file (handle,filename.to_external) 134 end 135 136 set_from_pixbuf (a_pixbuf: GDK_PIXBUF) is 137 -- See `from_pixbuf' for details. 138 require 139 valid_pixbuf: a_pixbuf /= Void 140 do 141 gtk_image_set_from_pixbuf (handle, a_pixbuf.handle) 142 end 143 144 set_from_pixmap (a_pixmap: GDK_PIXMAP; a_mask: GDK_BITMAP) is 145 -- See `from_pixmap' for details. 146 local 147 pixmap_ptr, mask_ptr: POINTER 148 do 149 if a_pixmap /= Void then pixmap_ptr := a_pixmap.handle end 150 if a_mask /= Void then mask_ptr := a_mask.handle end 151 gtk_image_set_from_pixmap (handle, pixmap_ptr, mask_ptr) 152 end 153 154feature -- Status setting 155 set_pixel_size (a_pixel_size : INTEGER) is 156 -- Sets the pixel size to use. 157 do 158 gtk_image_set_pixel_size (handle,a_pixel_size) 159 end 160 161 -- Todo : Write gdk_visual, gdk_pixmap, ... 162 -- Todo : gtk_icon_stock (?), gtk_icon_size (?), I am looking how to good implement. 163 164 -- Todo : void gtk_image_set_from_file () 165 -- Todo : void gtk_image_set_from_icon_set () 166 -- Todo : void gtk_image_set_from_image () 167 -- Todo : void gtk_image_set_from_pixbuf () 168 -- Todo : void gtk_image_set_from_pixmap () 169 -- Todo : void gtk_image_set_from_stock () 170 -- Todo : void gtk_image_set_from_animation () 171 -- Todo : void gtk_image_set_from_icon_name () 172 173 174feature -- Status report 175 176 pixel_size : INTEGER is 177 -- Pixel size used. 178 do 179 Result := gtk_image_get_pixel_size (handle) 180 end 181 182feature 183 184 struct_size: INTEGER is 185 external "C inline use <gtk/gtk.h>" 186 alias "sizeof(GtkImage)" 187 end 188 189end