Code

Refactoring out common code
[inkscape.git] / src / common-context.cpp
2 #include "common-context.h"
4 #include <gtk/gtk.h>
6 #include "config.h"
8 #include "forward.h"
9 #include "message-context.h"
11 #define DRAG_DEFAULT 1.0
12 #define MIN_PRESSURE      0.0
13 #define MAX_PRESSURE      1.0
14 #define DEFAULT_PRESSURE  1.0
17 static void sp_common_context_class_init(SPCommonContextClass *klass);
18 static void sp_common_context_init(SPCommonContext *erc);
19 static void sp_common_context_dispose(GObject *object);
21 static void sp_common_context_setup(SPEventContext *ec);
22 static void sp_common_context_set(SPEventContext *ec, gchar const *key, gchar const *value);
24 static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event);
27 static SPEventContextClass *common_parent_class = 0;
29 GType sp_common_context_get_type(void)
30 {
31     static GType type = 0;
32     if (!type) {
33         GTypeInfo info = {
34             sizeof(SPCommonContextClass),
35             0, // base_init
36             0, // base_finalize
37             (GClassInitFunc)sp_common_context_class_init,
38             0, // class_finalize
39             0, // class_data
40             sizeof(SPCommonContext),
41             0, // n_preallocs
42             (GInstanceInitFunc)sp_common_context_init,
43             0 // value_table
44         };
45         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPCommonContext", &info, static_cast<GTypeFlags>(0));
46     }
47     return type;
48 }
51 static void sp_common_context_class_init(SPCommonContextClass *klass)
52 {
53     GObjectClass *object_class = (GObjectClass *) klass;
54     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
56     common_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
58     object_class->dispose = sp_common_context_dispose;
60     event_context_class->setup = sp_common_context_setup;
61     event_context_class->set = sp_common_context_set;
62     event_context_class->root_handler = sp_common_context_root_handler;
63 }
65 static void sp_common_context_init(SPCommonContext *ctx)
66 {
67 //     ctx->cursor_shape = cursor_eraser_xpm;
68 //     ctx->hot_x = 4;
69 //     ctx->hot_y = 4;
71     ctx->accumulated = 0;
72     ctx->segments = 0;
73     ctx->currentcurve = 0;
74     ctx->currentshape = 0;
75     ctx->npoints = 0;
76     ctx->cal1 = 0;
77     ctx->cal2 = 0;
78     ctx->repr = 0;
80     /* Common values */
81     ctx->cur = NR::Point(0,0);
82     ctx->last = NR::Point(0,0);
83     ctx->vel = NR::Point(0,0);
84     ctx->vel_max = 0;
85     ctx->acc = NR::Point(0,0);
86     ctx->ang = NR::Point(0,0);
87     ctx->del = NR::Point(0,0);
89     /* attributes */
90     ctx->dragging = FALSE;
92     ctx->mass = 0.3;
93     ctx->drag = DRAG_DEFAULT;
94     ctx->angle = 30.0;
95     ctx->width = 0.2;
96     ctx->pressure = DEFAULT_PRESSURE;
98     ctx->vel_thin = 0.1;
99     ctx->flatness = 0.9;
100     ctx->cap_rounding = 0.0;
102     ctx->abs_width = false;
105 static void sp_common_context_dispose(GObject *object)
107     SPCommonContext *ctx = SP_COMMON_CONTEXT(object);
109     if (ctx->accumulated) {
110         ctx->accumulated = ctx->accumulated->unref();
111         ctx->accumulated = 0;
112     }
114     while (ctx->segments) {
115         gtk_object_destroy(GTK_OBJECT(ctx->segments->data));
116         ctx->segments = g_slist_remove(ctx->segments, ctx->segments->data);
117     }
119     if (ctx->currentcurve) {
120         ctx->currentcurve = ctx->currentcurve->unref();
121         ctx->currentcurve = 0;
122     }
123     if (ctx->cal1) {
124         ctx->cal1 = ctx->cal1->unref();
125         ctx->cal1 = 0;
126     }
127     if (ctx->cal2) {
128         ctx->cal2 = ctx->cal2->unref();
129         ctx->cal2 = 0;
130     }
132     if (ctx->currentshape) {
133         gtk_object_destroy(GTK_OBJECT(ctx->currentshape));
134         ctx->currentshape = 0;
135     }
137     if (ctx->_message_context) {
138         delete ctx->_message_context;
139         ctx->_message_context = 0;
140     }
142     G_OBJECT_CLASS(common_parent_class)->dispose(object);
146 static void sp_common_context_setup(SPEventContext */*ec*/)
151 static void sp_common_context_set(SPEventContext */*ec*/, gchar const */*key*/, gchar const */*value*/)
155 static gint sp_common_context_root_handler(SPEventContext */*event_context*/, GdkEvent */*event*/)
157   return 0;
160 /*
161   Local Variables:
162   mode:c++
163   c-file-style:"stroustrup"
164   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
165   indent-tabs-mode:nil
166   fill-column:99
167   End:
168 */
169 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :