| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#include <src/gtkimagescrollwin.h> |
|---|
| 21 |
#include <src/gtkimagetoolcairo.h> |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
#define TYPE_LINE_SHAPER (line_shaper_get_type ()) |
|---|
| 27 |
#define LINE_SHAPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LINE_SHAPER, LineShaper)) |
|---|
| 28 |
#define LINE_SHAPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LINE_SHAPER, LineShaperClass)) |
|---|
| 29 |
|
|---|
| 30 |
typedef struct _LineShaper LineShaper; |
|---|
| 31 |
typedef struct _LineShaperClass LineShaperClass; |
|---|
| 32 |
|
|---|
| 33 |
struct _LineShaper |
|---|
| 34 |
{ |
|---|
| 35 |
GObject parent; |
|---|
| 36 |
}; |
|---|
| 37 |
|
|---|
| 38 |
struct _LineShaperClass |
|---|
| 39 |
{ |
|---|
| 40 |
GObjectClass parent; |
|---|
| 41 |
}; |
|---|
| 42 |
|
|---|
| 43 |
GType line_shaper_get_type (void); |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
static void |
|---|
| 49 |
gtk_iimage_cairo_shaper_interface_init (gpointer g_iface, |
|---|
| 50 |
gpointer iface_data) |
|---|
| 51 |
{ |
|---|
| 52 |
|
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
G_DEFINE_TYPE_EXTENDED (LineShaper, |
|---|
| 56 |
line_shaper, |
|---|
| 57 |
G_TYPE_OBJECT, |
|---|
| 58 |
0, |
|---|
| 59 |
G_IMPLEMENT_INTERFACE (GTK_TYPE_IIMAGE_CAIRO_SHAPER, |
|---|
| 60 |
gtk_iimage_cairo_shaper_interface_init)); |
|---|
| 61 |
|
|---|
| 62 |
static void |
|---|
| 63 |
line_shaper_class_init (LineShaperClass *klass) |
|---|
| 64 |
{ |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
static void |
|---|
| 68 |
line_shaper_init (LineShaper *shaper) |
|---|
| 69 |
{ |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
static GtkIImageCairoShaper* |
|---|
| 73 |
line_shaper_new () |
|---|
| 74 |
{ |
|---|
| 75 |
gpointer data = g_object_new (TYPE_LINE_SHAPER, NULL); |
|---|
| 76 |
return GTK_IIMAGE_CAIRO_SHAPER (data); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
int |
|---|
| 80 |
main (int argc, char *argv[]) |
|---|
| 81 |
{ |
|---|
| 82 |
printf ("This program demonstrates how to draw stuff using cairo\n" |
|---|
| 83 |
"on the pixbuf GtkImageView shows.\n"); |
|---|
| 84 |
|
|---|
| 85 |
char **filenames = NULL; |
|---|
| 86 |
GOptionEntry options[] = { |
|---|
| 87 |
{ |
|---|
| 88 |
G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, |
|---|
| 89 |
&filenames, NULL, "[FILE...]" |
|---|
| 90 |
}, |
|---|
| 91 |
{NULL} |
|---|
| 92 |
}; |
|---|
| 93 |
GOptionContext *ctx = g_option_context_new ("ex-abssize"); |
|---|
| 94 |
g_option_context_add_main_entries (ctx, options, "moo"); |
|---|
| 95 |
g_option_context_parse (ctx, &argc, &argv, NULL); |
|---|
| 96 |
g_option_context_free (ctx); |
|---|
| 97 |
|
|---|
| 98 |
gtk_init (&argc, &argv); |
|---|
| 99 |
if (!filenames) |
|---|
| 100 |
{ |
|---|
| 101 |
printf ("Supply name of image.\n"); |
|---|
| 102 |
return 1; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
GtkWidget *view = gtk_image_view_new (); |
|---|
| 106 |
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (filenames[0], NULL); |
|---|
| 107 |
gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (view), pixbuf, TRUE); |
|---|
| 108 |
GtkIImageCairoShaper *shaper = line_shaper_new (); |
|---|
| 109 |
GtkIImageTool *cairo = |
|---|
| 110 |
gtk_image_tool_cairo_new (GTK_IMAGE_VIEW (view), shaper); |
|---|
| 111 |
gtk_image_view_set_tool (GTK_IMAGE_VIEW (view), cairo); |
|---|
| 112 |
|
|---|
| 113 |
GtkWidget *scroll_win = gtk_image_scroll_win_new (GTK_IMAGE_VIEW(view)); |
|---|
| 114 |
|
|---|
| 115 |
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
|---|
| 116 |
gtk_window_set_default_size (GTK_WINDOW (window), 500, 300); |
|---|
| 117 |
gtk_container_add (GTK_CONTAINER (window), scroll_win); |
|---|
| 118 |
g_signal_connect (G_OBJECT (window), "delete_event", |
|---|
| 119 |
G_CALLBACK (gtk_main_quit), NULL); |
|---|
| 120 |
|
|---|
| 121 |
gtk_widget_show_all (window); |
|---|
| 122 |
gtk_main (); |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|