Re: GdkPixbuf and click events
- From: cecashon aol com
- To: ramirez ferdinand yahoo com, gtk-app-devel-list gnome org
- Subject: Re: GdkPixbuf and click events
- Date: Thu, 3 Aug 2017 19:56:37 -0400
Hi Ferdinand,
You can also try putting the pixbuf in an image widget and that into an event box.
Eric
//gcc -Wall right_click1.c -o right_click1 `pkg-config --cflags --libs gtk+-3.0`
#include<gtk/gtk.h>
static GdkPixbuf* draw_a_pixbuf()
{
cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 20, 20);
cairo_t *cr=cairo_create(surface);
cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
cairo_paint(cr);
GdkPixbuf *pixbuf=gdk_pixbuf_get_from_surface(surface, 0, 0, 20, 20);
cairo_destroy(cr);
cairo_surface_destroy(surface);
return pixbuf;
}
static gboolean start_press(GtkWidget *widget, GdkEvent *event, gpointer data)
{
if(event->button.button==3) g_print("Right Click\n");
return TRUE;
}
int main(int argc, char *argv[])
{
gtk_init (&argc, &argv);
GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Right Click");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
GdkPixbuf *pixbuf=draw_a_pixbuf();
GtkWidget *image=gtk_image_new_from_pixbuf(pixbuf);
GtkWidget *event=gtk_event_box_new();
g_signal_connect(event, "button-press-event", G_CALLBACK(start_press), NULL);
gtk_container_add(GTK_CONTAINER(event), image);
GtkWidget *textview=gtk_text_view_new();
gtk_text_view_add_child_in_window(GTK_TEXT_VIEW(textview), event, GTK_TEXT_WINDOW_TEXT, 40, 40);
gtk_widget_set_hexpand(textview, TRUE);
gtk_widget_set_vexpand(textview, TRUE);
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), textview, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);
gtk_main();
g_object_unref(pixbuf);
return 0;
}
-----Original Message-----
From: Ferdinand Ramirez via gtk-app-devel-list <gtk-app-devel-list gnome org>
To: gtk-app-devel-list <gtk-app-devel-list gnome org>
Sent: Thu, Aug 3, 2017 8:13 am
Subject: GdkPixbuf and click events
I have a program that adds a GdkPixbuf to a GtkTextView. I would like to right click on the image and capture
the mouse click event and execute a callback function. Is there any way of achieving this using GdkPixbuf?
Thanks,
Ferdinand
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]