Libraries:Gtk:Gtk:Image
Types
T
Inherits from:The T widget displays an image. Various kinds of object can be displayed as an image; most typically, you would load a Gtk.Gdk.Pixbuf.T ("pixel buffer") from a file, and then display that. There's a convenience function to do this, gtk_image_new_from_file(), used as follows:
1 2 |
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_new_from_file(), then create the T with gtk_image_new_from_pixbuf().
The image file may contain an animation, if so the T will display an animation (Gtk.Gdk.PixbufAnimation.T) instead of a static image.
T is a subclass of Gtk.Gtk.Misc.T, which implies that you can align it (center, left, right) and add padding to it, using Gtk.Gtk.Misc.T methods.
T is a "no window" widget (has no Gtk.Gdk.Window.T 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.Gtk.EventBox.T, then connect to the event signals on the event box.
Example 12. Handling button press events on a GtkImage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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.Gtk.Misc.T). 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 gdk-pixbuf-csource. This program allows you to convert an image into a C variable declaration, which can then be loaded into a Gtk.Gdk.Pixbuf.T using gdk_pixbuf_new_from_inline().
Constants
Nil : T
Functions
GetType() : Gtk.GObject.Type.T
New() : Gtk.Gtk.Image.T
NewFromAnimation(animation @ Gtk.Gdk.PixbufAnimation.T) : Gtk.Gtk.Image.T
Creates a T displaying the given animation. The T does not assume a reference to the animation; you still need to unref it if you own references. T will add its own reference rather than adopting yours.
Note that the animation frames are shown using a timeout with G_PRIORITY_DEFAULT. When using animations to indicate busyness, keep in mind that the animation will only be shown if the main loop is not busy with something that has a higher priority.
animation | an animation |
Returns | a new T widget |
NewFromFile(filename @ Std.String.T) : Gtk.Gtk.Image.T
NewFromGicon(icon @ Gtk.Gio.GIcon.T, size @ Gtk.Gtk.IconSize.T) : Gtk.Gtk.Image.T
Creates a T displaying an icon from the current icon theme. If the icon name isn't known, a "broken image" icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
icon | an icon |
size | a stock icon size. [type int] |
Returns | a new T displaying the themed icon |
NewFromIconName(icon_name @ Std.String.T, size @ Gtk.Gtk.IconSize.T) : Gtk.Gtk.Image.T
Creates a T displaying an icon from the current icon theme. If the icon name isn't known, a "broken image" icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
icon_name | an icon name |
size | a stock icon size. [type int] |
Returns | a new T displaying the themed icon |
NewFromIconSet(icon_set @ Gtk.Gtk.IconSet.T, size @ Gtk.Gtk.IconSize.T) : Gtk.Gtk.Image.T
Creates a T displaying an icon set. Sample stock sizes are GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using this function, usually it's better to create a Gtk.Gtk.IconFactory.T, put your icon sets in the icon factory, add the icon factory to the list of default factories with Gtk.Gtk.IconFactory.AddDefault, and then use gtk_image_new_from_stock(). This will allow themes to override the icon you ship with your application.
The T does not assume a reference to the icon set; you still need to unref it if you own references. T will add its own reference rather than adopting yours.
icon_set | a Gtk.Gtk.IconSet.T |
size | a stock icon size. [type int] |
Returns | a new T |
NewFromImage(image @ Gtk.Gdk.Image.T, mask @ Gtk.Gdk.Bitmap.T) : Gtk.Gtk.Image.T
Creates a T widget displaying a image with a mask. A Gtk.Gdk.Image.T is a client-side image buffer in the pixel format of the current display. The T does not assume a reference to the image or mask; you still need to unref them if you own references. T will add its own reference rather than adopting yours.
image | a Gtk.Gdk.Image.T, or NULL. [allow-none] |
mask | a Gtk.Gdk.Bitmap.T, or NULL. [allow-none] |
Returns | a new T |
NewFromPixbuf(pixbuf @ Gtk.Gdk.Pixbuf.T) : Gtk.Gtk.Image.T
Creates a new T displaying pixbuf. The T does not assume a reference to the pixbuf; you still need to unref it if you own references. T will add its own reference rather than adopting yours.
Note that this function just creates an T from the pixbuf. The T created will not react to state changes. Should you want that, you should use gtk_image_new_from_icon_set().
pixbuf | a Gtk.Gdk.Pixbuf.T, or NULL. [allow-none] |
Returns | a new T |
NewFromPixmap(pixmap @ Gtk.Gdk.Pixmap.T, mask @ Gtk.Gdk.Bitmap.T) : Gtk.Gtk.Image.T
Creates a T widget displaying pixmap with a mask. A Gtk.Gdk.Pixmap.T is a server-side image buffer in the pixel format of the current display. The T does not assume a reference to the pixmap or mask; you still need to unref them if you own references. T will add its own reference rather than adopting yours.
pixmap | a Gtk.Gdk.Pixmap.T, or NULL. [allow-none] |
mask | a Gtk.Gdk.Bitmap.T, or NULL. [allow-none] |
Returns | a new T |
NewFromStock(stock_id @ Std.String.T, size @ Gtk.Gtk.IconSize.T) : Gtk.Gtk.Image.T
Creates a T displaying a stock icon. Sample stock icon names are GTK_STOCK_OPEN, GTK_STOCK_QUIT. Sample stock sizes are GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock icon name isn't known, the image will be empty. You can register your own stock icon names, see Gtk.Gtk.IconFactory.AddDefault and Gtk.Gtk.IconFactory.Add.
stock_id | a stock icon name |
size | a stock icon size. [type int] |
Returns | a new T displaying the stock icon |
Methods
:Anim(self @ T) : Gtk.Gtk.ImageAnimationData.T
:Clear(self @ T) : Std.Object.T
:Get(self @ T, val @ Std.Object.T, mask @ Std.Object.T) : Std.Object.T
Warning
Get has been deprecated since version 2.0 and should not be used in newly-written code. Use GetImage instead.
:GetAnimation(self @ T) : Gtk.Gdk.PixbufAnimation.T
Gets the Gtk.Gdk.PixbufAnimation.T being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.Animation (see GetStorageType). The caller of this function does not own a reference to the returned animation.
:GetGicon(self @ T, gicon @ Std.Object.T, size @ Std.Object.T) : Std.Object.T
Gets the GIcon and size being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.Gicon (see GetStorageType). The caller of this function does not own a reference to the returned GIcon.
image | a T |
gicon | place to store a GIcon, or NULL. [out][transfer none][allow-none] |
size | place to store an icon size, or NULL. [out][allow-none][type int] |
:GetIconName(self @ T, icon_name @ Agg.List.T, size @ Std.Object.T) : Std.Object.T
Gets the icon name and size being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.IconName (see GetStorageType). The returned string is owned by the T and should not be freed.
image | a T |
icon_name | place to store an icon name, or NULL. [out][transfer none][allow-none] |
size | place to store an icon size, or NULL. [out][allow-none][type int] |
:GetIconSet(self @ T, icon_set @ Std.Object.T, size @ Std.Object.T) : Std.Object.T
Gets the icon set and size being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.IconSet (see GetStorageType).
image | a T |
icon_set | location to store a Gtk.Gtk.IconSet.T, or NULL. [out][transfer none][allow-none] |
size | location to store a stock icon size, or NULL. [out][allow-none][type int] |
:GetImage(self @ T, gdk_image @ Std.Object.T, mask @ Std.Object.T) : Std.Object.T
Gets the Gtk.Gdk.Image.T and mask being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.Image (see GetStorageType). The caller of this function does not own a reference to the returned image and mask.
image | a T |
gdk_image | return location for a T, or NULL. [out][transfer none][allow-none] |
mask | return location for a Gtk.Gdk.Bitmap.T, or NULL. [out][transfer none][allow-none] |
:GetPixbuf(self @ T) : Gtk.Gdk.Pixbuf.T
Gets the Gtk.Gdk.Pixbuf.T being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.Pixbuf (see GetStorageType). The caller of this function does not own a reference to the returned pixbuf.
:GetPixelSize(self @ T) : Std.Integer.SmallT
:GetPixmap(self @ T, pixmap @ Std.Object.T, mask @ Std.Object.T) : Std.Object.T
Gets the pixmap and mask being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.Pixmap (see GetStorageType). The caller of this function does not own a reference to the returned pixmap and mask.
image | a T |
pixmap | location to store the pixmap, or NULL. [out][transfer none][allow-none] |
mask | location to store the mask, or NULL. [out][transfer none][allow-none] |
:GetStock(self @ T, stock_id @ Agg.List.T, size @ Std.Object.T) : Std.Object.T
Gets the stock icon name and size being displayed by the T. The storage type of the image must be Gtk.Gtk.ImageType.Empty or Gtk.Gtk.ImageType.Stock (see GetStorageType). The returned string is owned by the T and should not be freed.
image | a T |
stock_id | place to store a stock icon name, or NULL. [out][transfer none][allow-none] |
size | place to store a stock icon size, or NULL. [out][allow-none][type int] |
:GetStorageType(self @ T) : Gtk.Gtk.ImageType.T
Gets the type of representation being used by the T to store image data. If the T has no image data, the return value will be Gtk.Gtk.ImageType.Empty.
image | a T |
Returns | image representation being used |
:Gicon(self @ T) : Gtk.Gtk.ImageGIconData.T
:IconSet(self @ T) : Gtk.Gtk.ImageIconSetData.T
:Image(self @ T) : Gtk.Gtk.ImageImageData.T
:Name(self @ T) : Gtk.Gtk.ImageIconNameData.T
:Pixbuf(self @ T) : Gtk.Gtk.ImagePixbufData.T
:Pixmap(self @ T) : Gtk.Gtk.ImagePixmapData.T
:Set(self @ T, val @ Gtk.Gdk.Image.T, mask @ Gtk.Gdk.Bitmap.T) : Std.Object.T
Warning
Set has been deprecated since version 2.0 and should not be used in newly-written code. Use SetFromImage instead.
:SetFromAnimation(self @ T, animation @ Gtk.Gdk.PixbufAnimation.T) : Std.Object.T
Causes the T to display the given animation (or display nothing, if you set the animation to NULL).
image | a T |
animation | the Gtk.Gdk.PixbufAnimation.T |
:SetFromFile(self @ T, filename @ Std.String.T) : Std.Object.T
:SetFromGicon(self @ T, icon @ Gtk.Gio.GIcon.T, size @ Gtk.Gtk.IconSize.T) : Std.Object.T
:SetFromIconName(self @ T, icon_name @ Std.String.T, size @ Gtk.Gtk.IconSize.T) : Std.Object.T
See gtk_image_new_from_icon_name() for details.
image | a T |
icon_name | an icon name |
size | an icon size. [type int] |
:SetFromIconSet(self @ T, icon_set @ Gtk.Gtk.IconSet.T, size @ Gtk.Gtk.IconSize.T) : Std.Object.T
See gtk_image_new_from_icon_set() for details.
image | a T |
icon_set | a Gtk.Gtk.IconSet.T |
size | a stock icon size. [type int] |
:SetFromImage(self @ T, gdk_image @ Gtk.Gdk.Image.T, mask @ Gtk.Gdk.Bitmap.T) : Std.Object.T
See gtk_image_new_from_image() for details.
image | a T |
gdk_image | a Gtk.Gdk.Image.T or NULL. [allow-none] |
mask | a Gtk.Gdk.Bitmap.T or NULL. [allow-none] |
:SetFromPixbuf(self @ T, pixbuf @ Gtk.Gdk.Pixbuf.T) : Std.Object.T
See gtk_image_new_from_pixbuf() for details.
image | a T |
pixbuf | a Gtk.Gdk.Pixbuf.T or NULL. [allow-none] |
:SetFromPixmap(self @ T, pixmap @ Gtk.Gdk.Pixmap.T, mask @ Gtk.Gdk.Bitmap.T) : Std.Object.T
See gtk_image_new_from_pixmap() for details.
image | a T |
pixmap | a Gtk.Gdk.Pixmap.T or NULL. [allow-none] |
mask | a Gtk.Gdk.Bitmap.T or NULL. [allow-none] |
:SetFromStock(self @ T, stock_id @ Std.String.T, size @ Gtk.Gtk.IconSize.T) : Std.Object.T
See gtk_image_new_from_stock() for details.
image | a T |
stock_id | a stock icon name |
size | a stock icon size. [type int] |
:SetPixelSize(self @ T, pixel_size @ Std.Integer.SmallT) : Std.Object.T
Sets the pixel size to use for named icons. If the pixel size is set to a value != -1, it is used instead of the icon size set by SetFromIconName.
image | a T |
pixel_size | the new pixel size |