root/gtkimageview/tests/ex-cairo-drawing.c

Revision 700, 4.1 kB (checked in by bjourne, 4 years ago)

Make the demo show a window.

Line 
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*-
2  *
3  * Copyright © 2007-2008 Björn Lindqvist <bjourne@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; either version 2, or
8  * (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #include <src/gtkimagescrollwin.h>
21 #include <src/gtkimagetoolcairo.h>
22
23 /*************************************************************/
24 /***** LineShaper class **************************************/
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 /***** Stuff that deals with the type ************************/
47 /*************************************************************/
48 static void
49 gtk_iimage_cairo_shaper_interface_init (gpointer g_iface,
50                                         gpointer iface_data)
51 {
52     //GtkIImageCairoShaper *klass (GtkIImageCairoShaper *) g_iface;
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
Note: See TracBrowser for help on using the browser.