package Gtk_Image_Type_Properties is new Generic_Internal_Discrete_Property (Gtk_Image_Type);
package Implements_Gtk_Buildable is new Glib.Types.Implements (Gtk.Buildable.Gtk_Buildable, Gtk_Image_Record, Gtk_Image);
type Gtk_Image_Record is new Gtk_Misc_Record with null record;
type Gtk_Image is access all Gtk_Image_Record'Class;
type Gtk_Image_Type is ( Image_Empty, Image_Pixbuf, Image_Stock, Image_Icon_Set, Image_Animation, Image_Icon_Name, Image_Gicon);
type Property_Gtk_Image_Type is new Gtk_Image_Type_Properties.Property;
File_Property : constant Glib.Properties.Property_String;
G_Icon_Property : constant Glib.Properties.Property_Boxed;
Icon_Name_Property : constant Glib.Properties.Property_String;
Icon_Set_Property : constant Glib.Properties.Property_Object;
Icon_Size_Property : constant Glib.Properties.Property_Int;
Pixbuf_Property : constant Glib.Properties.Property_Object;
Pixbuf_Animation_Property : constant Glib.Properties.Property_Boxed;
Pixel_Size_Property : constant Glib.Properties.Property_Int;
Resource_Property : constant Glib.Properties.Property_String;
Stock_Property : constant Glib.Properties.Property_String;
Storage_Type_Property : constant Gtk.Image.Property_Gtk_Image_Type;
Use_Fallback_Property : constant Glib.Properties.Property_Boolean;
procedure Gtk_New
( | Image | : out Gtk_Image); |
procedure Initialize
( | Image | : not null access Gtk_Image_Record'Class); |
function Gtk_Image_New return Gtk_Image;
procedure Gtk_New
( | Image | : out Gtk_Image; |
Animation | : Gdk.Pixbuf.Gdk_Pixbuf_Animation); |
procedure Initialize
( | Image | : not null access Gtk_Image_Record'Class; |
Animation | : Gdk.Pixbuf.Gdk_Pixbuf_Animation); |
function Gtk_Image_New_From_Animation
( | Animation | : Gdk.Pixbuf.Gdk_Pixbuf_Animation) return Gtk_Image; |
procedure Gtk_New
( | Image | : out Gtk_Image; |
Filename | : UTF8_String); |
procedure Initialize
( | Image | : not null access Gtk_Image_Record'Class; |
Filename | : UTF8_String); |
function Gtk_Image_New_From_File
( | Filename | : UTF8_String) return Gtk_Image; |
procedure Gtk_New_From_Gicon
( | Image | : out Gtk_Image; |
Icon | : Glib.G_Icon.G_Icon; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Initialize_From_Gicon
( | Image | : not null access Gtk_Image_Record'Class; |
Icon | : Glib.G_Icon.G_Icon; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
function Gtk_Image_New_From_Gicon
( | Icon | : Glib.G_Icon.G_Icon; |
Size | : Gtk.Enums.Gtk_Icon_Size) return Gtk_Image; |
procedure Gtk_New_From_Icon_Name
( | Image | : out Gtk_Image; |
Icon_Name | : UTF8_String; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Initialize_From_Icon_Name
( | Image | : not null access Gtk_Image_Record'Class; |
Icon_Name | : UTF8_String; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
function Gtk_Image_New_From_Icon_Name
( | Icon_Name | : UTF8_String; |
Size | : Gtk.Enums.Gtk_Icon_Size) return Gtk_Image; |
procedure Gtk_New
( | Image | : out Gtk_Image; |
Icon_Set | : Gtk.Icon_Set.Gtk_Icon_Set; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Initialize
( | Image | : not null access Gtk_Image_Record'Class; |
Icon_Set | : Gtk.Icon_Set.Gtk_Icon_Set; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
function Gtk_Image_New_From_Icon_Set
( | Icon_Set | : Gtk.Icon_Set.Gtk_Icon_Set; |
Size | : Gtk.Enums.Gtk_Icon_Size) return Gtk_Image; |
procedure Gtk_New
( | Image | : out Gtk_Image; |
Pixbuf | : access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class); |
procedure Initialize
( | Image | : not null access Gtk_Image_Record'Class; |
Pixbuf | : access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class); |
function Gtk_Image_New_From_Pixbuf
( | Pixbuf | : access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class) return Gtk_Image; |
procedure Gtk_New_From_Resource
( | Image | : out Gtk_Image; |
Resource_Path | : UTF8_String); |
procedure Initialize_From_Resource
( | Image | : not null access Gtk_Image_Record'Class; |
Resource_Path | : UTF8_String); |
function Gtk_Image_New_From_Resource
( | Resource_Path | : UTF8_String) return Gtk_Image; |
procedure Gtk_New
( | Image | : out Gtk_Image; |
Stock_Id | : UTF8_String; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Initialize
( | Image | : not null access Gtk_Image_Record'Class; |
Stock_Id | : UTF8_String; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
function Gtk_Image_New_From_Stock
( | Stock_Id | : UTF8_String; |
Size | : Gtk.Enums.Gtk_Icon_Size) return Gtk_Image; |
function Get_Type return Glib.GType;
procedure Clear
( | Image | : not null access Gtk_Image_Record); |
function Get
( | Image | : not null access Gtk_Image_Record) return Gdk.Pixbuf.Gdk_Pixbuf_Animation; |
procedure Get
( | Image | : not null access Gtk_Image_Record; |
G_Icon | : out Glib.G_Icon.G_Icon; | |
Size | : out Gtk.Enums.Gtk_Icon_Size); |
procedure Get
( | Image | : not null access Gtk_Image_Record; |
Icon_Set | : out Gtk.Icon_Set.Gtk_Icon_Set; | |
Size | : out Gtk.Enums.Gtk_Icon_Size); |
function Get
( | Image | : not null access Gtk_Image_Record) return Gdk.Pixbuf.Gdk_Pixbuf; |
function Get_Pixel_Size
( | Image | : not null access Gtk_Image_Record) return Gint; |
procedure Set_Pixel_Size
( | Image | : not null access Gtk_Image_Record; |
Pixel_Size | : Gint); |
function Get_Storage_Type
( | Image | : not null access Gtk_Image_Record) return Gtk_Image_Type; |
procedure Set
( | Image | : not null access Gtk_Image_Record; |
Animation | : Gdk.Pixbuf.Gdk_Pixbuf_Animation); |
procedure Set
( | Image | : not null access Gtk_Image_Record; |
Filename | : UTF8_String := ""); |
procedure Set
( | Image | : not null access Gtk_Image_Record; |
Icon | : Glib.G_Icon.G_Icon; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Set
( | Image | : not null access Gtk_Image_Record; |
Icon_Set | : Gtk.Icon_Set.Gtk_Icon_Set; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Set
( | Image | : not null access Gtk_Image_Record; |
Pixbuf | : access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class); |
procedure Set
( | Image | : not null access Gtk_Image_Record; |
Stock_Id | : UTF8_String; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Set_From_Icon_Name
( | Image | : not null access Gtk_Image_Record; |
Icon_Name | : UTF8_String; | |
Size | : Gtk.Enums.Gtk_Icon_Size); |
procedure Set_From_Resource
( | Image | : not null access Gtk_Image_Record; |
Resource_Path | : UTF8_String := ""); |
function Get
( | Image | : access Gtk_Image_Record; |
Size | : access Gtk.Enums.Gtk_Icon_Size) return String; |
procedure Get_Icon_Name
( | Image | : access Gtk_Image_Record; |
Name | : out GNAT.Strings.String_Access; | |
Size | : out Gtk.Enums.Gtk_Icon_Size); |
function "+"
( | Widget | : access Gtk_Image_Record'Class) return Gtk.Buildable.Gtk_Buildable renames Implements_Gtk_Buildable.To_Interface; |
function "-"
( | Interf | : Gtk.Buildable.Gtk_Buildable) return Gtk_Image renames Implements_Gtk_Buildable.To_Object; |
The Gtk.Image.Gtk_Image widget displays an image. Various kinds of object can be displayed as an image; most typically, you would load a Gdk.Pixbuf.Gdk_Pixbuf ("pixel buffer") from a file, and then display that.
There's a convenience function to do this, Gtk.Image.Gtk_New, used as follows: GtkWidget *image; image = gtk_image_new_from_file ("myfile.png"); If the file isn't loaded successfully, the image will contain a "broken image" icon similar to that used in many web browsers. If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with Gdk.Pixbuf.Gdk_New_From_File, then create the Gtk.Image.Gtk_Image with Gtk.Image.Gtk_New.
The image file may contain an animation, if so the Gtk.Image.Gtk_Image will display an animation (Gdk_Pixbuf_Animation) instead of a static image.
Gtk.Image.Gtk_Image is a subclass of Gtk.Misc.Gtk_Misc, which implies that you can align it (center, left, right) and add padding to it, using Gtk.Misc.Gtk_Misc methods.
Gtk.Image.Gtk_Image is a "no window" widget (has no Gdk.Gdk_Window of its own), so by default does not receive events. If you want to receive events on the image, such as button clicks, place the image inside a Gtk.Event_Box.Gtk_Event_Box, then connect to the event signals on the event box. <title>Handling button press events on a <structname>GtkImage</structname>.</title> static gboolean button_press_callback (GtkWidget *event_box, GdkEventButton *event, gpointer data) { g_print ("Event box clicked at coordinates %f,%f\n", event->x, event->y); /<!---->* Returning TRUE means we handled the event, so the signal * emission should be stopped (don't call any further * callbacks that may be connected). Return FALSE * to continue invoking callbacks. *<!---->/ return TRUE; } static GtkWidget* create_image (void) { GtkWidget *image; GtkWidget *event_box; image = gtk_image_new_from_file ("myfile.png"); event_box = gtk_event_box_new (<!-- -->); gtk_container_add (GTK_CONTAINER (event_box), image); g_signal_connect (G_OBJECT (event_box), "button_press_event", G_CALLBACK (button_press_callback), image); return image; } When handling events on the event box, keep in mind that coordinates in the image may be different from event box coordinates due to the alignment and padding settings on the image (see Gtk.Misc.Gtk_Misc). The simplest way to solve this is to set the alignment to 0.0 (left/top), and set the padding to zero. Then the origin of the image will be the same as the origin of the event box.
Sometimes an application will want to avoid depending on external data files, such as image files. GTK+ comes with a program to avoid this, called <application>gdk-pixbuf-csource</application>. This library allows you to convert an image into a C variable declaration, which can then be loaded into a Gdk.Pixbuf.Gdk_Pixbuf using gdk_pixbuf_new_from_inline.