Maemopad+ 0.37 released
[maemopadplus.git] / src / ui / sketchwidget.h
blob2b338b867d8c479d3d868b97150511e86cb15e8b
2 /*
3 * This file is part of maemopad+
6 * This software is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * This software is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this software; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
23 #ifndef SKETCHWIDGET_H
24 #define SKETCHWIDGET_H
26 #include <math.h>
27 #include <gtk/gtk.h>
29 /*#define NOTIFY_STUPID */
30 /*#define NOTIFY_COORDS */
31 /*#define PRESSURECOLORS_DEBUG */
33 #define PRESSURE_MIN 0.1
34 #define PRESSURE_MAX 0.35
36 #define PRESSURE_COLOR_MAX 0.25
37 #define PRESSURE_COLORS 5
39 #define BACKGRAPH_LINE_HEIGHT 32
40 #define BACKGRAPH_LINE_MARGIN 40
41 #define BACKGRAPH_LINE_SIZE 1
42 #define BACKGRAPH_LINE_MARGIN_SIZE 2
44 #define BACKGRAPH_GRAPH_WIDTH 32
45 #define BACKGRAPH_GRAPH_SIZE 1
47 typedef enum
49 SKETCHBACK_UNSET = -1,
50 SKETCHBACK_NONE,
51 SKETCHBACK_LINES,
52 SKETCHBACK_GRAPH,
53 SKETCHBACK_COUNT
54 } sketchBack;
56 #define TILE_SIZE 32
59 * 800/TILE_SIZE
61 #define TILES_X 25
62 #define TILES_ROWSTRIDE TILES_X
65 * 480/TILE_SIZE
67 #define TILES_Y 15
69 #define UNDO_LEVELS 10
71 typedef enum
73 SKETCHSHAPE_FREEHAND = 0,
74 SKETCHSHAPE_LINE,
75 SKETCHSHAPE_RECT,
76 SKETCHSHAPE_ELLIPSE,
77 SKETCHSHAPE_COUNT
78 } sketchShape;
80 typedef struct _SketchWidgetTile SketchWidgetTile;
81 struct _SketchWidgetTile
83 guint tileid;
84 GdkPixmap *tiledata;
85 GdkPixmap *tiledata_new;
88 typedef struct _SketchWidgetUndo SketchWidgetUndo;
89 struct _SketchWidgetUndo
93 * keep a linked list for modified tiles with their data
95 GSList *tileList; /*list of SketchWidgetTile */
96 char saved_tiles[TILES_X * TILES_Y]; /*fast dupe check*/
99 typedef struct _SketchWidget SketchWidget;
100 struct _SketchWidget
102 GtkWidget *scrolledwindow;
103 GtkWidget *drawingarea;
104 GdkPixmap *pixmap;
105 GdkPixmap *backpixmap;
107 GdkPixmap *backpixmaps[SKETCHBACK_COUNT];
108 int backpixmapheights[SKETCHBACK_COUNT];
110 sketchBack backstyle;
111 sketchBack backstyle_currentimage;
113 sketchShape shape;
114 gboolean fillmode;
115 gboolean shiftmode;
117 guint brush_size;
118 guint brush_radius;
119 GdkColor brush_color;
120 gboolean border;
122 GdkColor brush_colors[PRESSURE_COLORS];
123 gdouble brush_colors_pressure_index[PRESSURE_COLORS];
125 gboolean pressuresensitivity;
127 GdkGC *gc;
128 GdkGC *backgc;
129 unsigned long lastevent_x, lastevent_y, start_x, start_y, cur_x, cur_y;
130 gboolean pressed;
131 gboolean coords_valid; /*if start_x/start_y valid*/
133 gboolean is_edited;
135 GList *undolist; /*list of SketchWidgetUndo, kept reverse */
136 guint undocurrent; /*current index on the undolist (=available redo steps) */
137 /*undocurrent = 0, no redo available*/
140 * current undo buffer, active when mouse pointer is held down
141 * when mouse pointer is released the new states of tiles will be saved again,
142 * then this will be prepended to *undolist and set to NULL
144 SketchWidgetUndo *undocurbuffer;
146 void (*callback_undotoggle) (SketchWidget * sk, gboolean st, gpointer data);
147 void (*callback_redotoggle) (SketchWidget * sk, gboolean st, gpointer data);
148 gpointer callback_undotoggle_data;
149 gpointer callback_redotoggle_data;
151 void (*callback_finger) (SketchWidget * sk, gint x, gint y, gdouble pressure, gpointer data);
152 gpointer callback_finger_data;
154 guint sizex, sizey;
155 guint stupidflag; /*1:ignore next motion_event 2:ignore next keypress 0:normal*/
158 SketchWidget *sketchwidget_new(gint sizex, gint sizey, gboolean border);
159 void sketchwidget_destroy(SketchWidget * sk);
160 gboolean sketch_configure(GtkWidget * widget, GdkEventConfigure * event, SketchWidget * sk);
162 void sketchwidget_set_fingercallback(SketchWidget * sk, void *func, gpointer data);
163 void sketchwidget_set_undocallback(SketchWidget * sk, void *func, gpointer data);
164 void sketchwidget_set_redocallback(SketchWidget * sk, void *func, gpointer data);
165 GtkWidget *sketchwidget_get_drawingarea(SketchWidget * sk);
166 GtkWidget *sketchwidget_get_mainwidget(SketchWidget * sk);
167 gboolean sketchwidget_get_edited(SketchWidget * sk);
168 void sketchwidget_set_edited(SketchWidget * sk, gboolean status);
169 void sketchwidget_clear_real(SketchWidget * sk);
170 void sketchwidget_clear(SketchWidget * sk);
171 void sketchwidget_set_fillmode(SketchWidget * sk, gboolean filled);
172 void sketchwidget_set_shift(SketchWidget * sk, gboolean shift);
173 gboolean sketchwidget_get_shift(SketchWidget * sk);
174 void sketchwidget_set_shape(SketchWidget * sk, sketchShape sp);
175 void sketchwidget_set_brushsize(SketchWidget * sk, guint bsize);
176 guint sketchwidget_get_brushsize(SketchWidget * sk);
177 void sketchwidget_set_brushcolor(SketchWidget * sk, GdkColor col);
178 GdkColor sketchwidget_get_brushcolor(SketchWidget * sk);
179 void sketchwidget_set_backstyle(SketchWidget * sk, sketchBack style);
181 GdkPixbuf *sketchwidget_trim_image(GdkPixbuf * pixbuf, guint totalw, guint totalh, double *w, double *h, gboolean doTopLeft);
183 gboolean sketchwidget_cut(SketchWidget * sk, GtkClipboard * clippy);
184 gboolean sketchwidget_copy(SketchWidget * sk, GtkClipboard * clippy);
185 gboolean sketchwidget_paste(SketchWidget * sk, GtkClipboard * clippy);
188 * unref the result afterwards
190 GdkPixmap *sketchwidget_get_Pixmap(SketchWidget * sk);
193 * undo/redo
195 gboolean sketchwidget_undo(SketchWidget * sk);
196 gboolean sketchwidget_redo(SketchWidget * sk);
197 void sketchwidget_wipe_undo(SketchWidget * sk);
199 #endif