1 /* $Id: canvas.h,v 1.4 2005/01/07 02:50:52 meffie Exp $
2  *
3  * GNU Paint
4  * Copyright 2000-2003, 2007  Li-Cheng (Andy) Tai
5  *
6  * Authors: Li-Cheng (Andy) Tai <atai@gnu.org>
7  *          Michael A. Meffie III <meffiem@neo.rr.com>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 3
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be
15  * useful, but WITHOUT ANY WARRANTY; without even the implied
16  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  * PURPOSE. See the GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef __CANVAS_H__
24 #define __CANVAS_H__
25 
26 #include <gtk/gtk.h>
27 #include "image.h"
28 #include "drawing.h"
29 #include "selection.h"
30 
31 #define DEFAULT_WIDTH  640
32 #define DEFAULT_HEIGHT 480
33 
34 typedef struct _gpaint_canvas    gpaint_canvas;
35 typedef struct _gpaint_canvas_class    gpaint_canvas_class;
36 typedef struct _gpaint_tool      gpaint_tool;
37 
38 typedef enum _gpaint_attribute
39 {
40     GpaintForegroundColor,
41     GpaintBackgroundColor,
42     GpaintFillShape,
43     GpaintFont
44 } gpaint_attribute;
45 
46 typedef enum _gpaint_change
47 {
48     GpaintFocusIn,
49     GpaintFocusOut
50 } gpaint_change;
51 
52 /*
53  * Drawing Tool
54  */
55 typedef gpaint_tool* (*ToolCreate)       (const char*);
56 typedef void         (*ToolDestroy)      (gpaint_tool*);
57 typedef void         (*ToolSelect)       (gpaint_tool*);
58 typedef void         (*ToolDeselect)     (gpaint_tool*);
59 typedef gboolean     (*ToolAttribute)    (gpaint_tool*, gpaint_attribute, gpointer);
60 typedef void         (*ToolChange)       (gpaint_tool*, gpaint_change, gpointer);
61 typedef void         (*ToolButtonPress)  (gpaint_tool*, int, int);
62 typedef void         (*ToolMotion)       (gpaint_tool*, int, int);
63 typedef void         (*ToolButtonRelease)(gpaint_tool*, int, int);
64 typedef void         (*ToolKeyRelease)   (gpaint_tool*, GdkEventKey*);
65 typedef void         (*ToolCurrentDraw)  (gpaint_tool *);
66 typedef void         (*ToolCommitChange) (gpaint_tool *);
67 
68 struct _gpaint_tool
69 {
70     const char       *name;
71     gpaint_drawing   *drawing;
72     gpaint_canvas    *canvas;
73     GdkCursor        *cursor;
74     ToolDestroy       destroy;
75     ToolSelect        select;
76     ToolDeselect      deselect;
77     ToolAttribute     attribute;
78     ToolChange        change;
79     ToolButtonPress   button_press;
80     ToolMotion        motion;
81     ToolButtonRelease button_release;
82     ToolKeyRelease    key_release;
83     ToolCurrentDraw   current_draw;
84     ToolCommitChange  commit_change;
85 };
86 
87 /* cast macro */
88 #define GPAINT_TOOL(object)  ((gpaint_tool*)object)
89 
90 typedef struct _gpaint_clipboard
91 {
92     gpaint_image       *image;
93     gpaint_point_array *points;
94 
95     GSList	       *pixbuf_formats;
96 
97     GtkTargetEntry     *target_entries;
98     gint		n_target_entries;
99     gchar	      **savers;
100 } gpaint_clipboard;
101 
102 struct _gpaint_canvas_class
103 {
104     GObjectClass      parent;
105 };
106 
107 struct _gpaint_canvas
108 {
109     GObject	      parent;
110 
111     /* public */
112     GtkWidget        *top_level;
113     GtkDrawingArea   *drawing_area;
114     GdkGC            *gc;
115     gpaint_tool      *active_tool;
116     gpaint_drawing   *drawing;
117     gboolean          has_focus;
118     gpaint_selection *selection;
119 
120     /* private */
121     GdkCursor        *cursor;
122     GdkCursor        *busy_cursor;
123     GdkCursor        *arrow_cursor;
124     gpaint_tool      *paste_tool;
125     gpaint_tool      *saved_tool;
126 };
127 
128 void canvas_init_arg(int argc, char *argv[]);
129 void canvas_destroy(gpaint_canvas *canvas);
130 gpaint_canvas* canvas_lookup(GtkWidget *widget);
131 
132 void canvas_set_drawing(gpaint_canvas *canvas, gpaint_drawing *drawing);
133 void canvas_resize(gpaint_canvas *canvas);
134 void canvas_set_tool(gpaint_canvas *canvas, gpaint_tool *new_tool);
135 
136 void canvas_commit_change(gpaint_canvas *canvas);
137 void canvas_begin_busy_cursor(gpaint_canvas *canvas);
138 void canvas_end_busy_cursor(gpaint_canvas *canvas);
139 void canvas_focus_gained(gpaint_canvas *canvas);
140 void canvas_focus_lost(gpaint_canvas *canvas);
141 void canvas_redraw(gpaint_canvas *canvas);
142 
143 void canvas_begin_paste_mode(gpaint_canvas *canvas);
144 void canvas_end_paste_mode(gpaint_canvas *canvas);
145 void canvas_cut(gpaint_canvas *canvas);
146 void canvas_copy(gpaint_canvas *canvas);
147 void canvas_clear(gpaint_canvas *canvas);
148 void canvas_select_all(gpaint_canvas *canvas);
149 gboolean canvas_has_selection(gpaint_canvas *canvas);
150 gpaint_clipboard *canvas_clipboard(gpaint_canvas *canvas);
151 
152 #endif
153