~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/dropper-context.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <gtkmm/clipboard.h>
23
23
#include <gdk/gdkkeysyms.h>
24
24
 
25
 
#include "libnr/n-art-bpath.h"
26
25
#include "macros.h"
27
26
#include "display/canvas-bpath.h"
28
27
#include "display/canvas-arena.h"
31
30
#include "color.h"
32
31
#include "color-rgba.h"
33
32
#include "desktop-style.h"
34
 
#include "prefs-utils.h"
 
33
#include "preferences.h"
35
34
#include "sp-namedview.h"
36
35
#include "desktop.h"
37
36
#include "desktop-handles.h"
42
41
 
43
42
#include "dropper-context.h"
44
43
#include "message-context.h"
45
 
#include "libnr/nr-scale-translate-ops.h"
46
 
 
47
 
#define C1 0.552
48
 
static NArtBpath const spdc_circle[] = {
49
 
    { NR_MOVETO, 0, 0, 0, 0, -1, 0 },
50
 
    { NR_CURVETO, -1, C1, -C1, 1, 0, 1 },
51
 
    { NR_CURVETO, C1, 1, 1, C1, 1, 0 },
52
 
    { NR_CURVETO, 1, -C1, C1, -1, 0, -1 },
53
 
    { NR_CURVETO, -C1, -1, -1, -C1, -1, 0 },
54
 
    { NR_END, 0, 0, 0, 0, 0, 0 }
55
 
};
56
 
#undef C1
 
44
//#include "libnr/nr-scale-translate-ops.h"
57
45
 
58
46
static void sp_dropper_context_class_init(SPDropperContextClass *klass);
59
47
static void sp_dropper_context_init(SPDropperContext *dc);
111
99
        ((SPEventContextClass *) parent_class)->setup(ec);
112
100
    }
113
101
 
114
 
    SPCurve *c = sp_curve_new_from_foreign_bpath(spdc_circle);
 
102
    /* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
 
103
    SPCurve *c = new SPCurve();
 
104
    const double C1 = 0.552;
 
105
    c->moveto(-1,0);
 
106
    c->curveto(-1, C1, -C1, 1, 0, 1 );
 
107
    c->curveto(C1, 1, 1, C1, 1, 0 );
 
108
    c->curveto(1, -C1, C1, -1, 0, -1 );
 
109
    c->curveto(-C1, -1, -1, -C1, -1, 0 );
 
110
    c->closepath();
115
111
    dc->area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c);
116
 
    sp_curve_unref(c);
 
112
    c->unref();
117
113
    sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(dc->area), 0x00000000,(SPWindRule)0);
118
114
    sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
119
115
    sp_canvas_item_hide(dc->area);
120
116
 
121
 
    if (prefs_get_int_attribute("tools.dropper", "selcue", 0) != 0) {
 
117
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
118
    if (prefs->getBool("/tools/dropper/selcue")) {
122
119
        ec->enableSelectionCue();
123
120
    }
124
121
 
125
 
    if (prefs_get_int_attribute("tools.dropper", "gradientdrag", 0) != 0) {
 
122
    if (prefs->getBool("/tools/dropper/gradientdrag")) {
126
123
        ec->enableGrDrag();
127
124
    }
128
125
}
141
138
 
142
139
 
143
140
/**
144
 
 * Copies the current context color to the clipboard.
 
141
 * Returns the current dropper context color.
145
142
 */
146
 
void sp_dropper_context_copy(SPEventContext *ec)
 
143
guint32 sp_dropper_context_get_color(SPEventContext *ec)
147
144
{
148
145
    SPDropperContext *dc = SP_DROPPER_CONTEXT(ec);
149
 
 
150
 
    guint32 const c32 = SP_RGBA32_F_COMPOSE(dc->R, dc->G, dc->B, dc->alpha);
151
 
 
152
 
    int pick = prefs_get_int_attribute("tools.dropper", "pick",
 
146
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
147
 
 
148
    int pick = prefs->getInt("/tools/dropper/pick",
153
149
                                       SP_DROPPER_PICK_VISIBLE);
154
 
 
155
 
    int setalpha = prefs_get_int_attribute("tools.dropper", "setalpha", 1);
156
 
 
157
 
    gchar c[64];
158
 
    g_snprintf(c, 64, "%06x%02x", c32 >> 8,
159
 
               (pick == SP_DROPPER_PICK_ACTUAL && setalpha)? SP_COLOR_F_TO_U(dc->alpha) : 255);
160
 
 
161
 
    Glib::ustring text;
162
 
    text += c;
163
 
    if (!text.empty())
164
 
    {
165
 
        Glib::RefPtr<Gtk::Clipboard> refClipboard =
166
 
            Gtk::Clipboard::get();
167
 
        refClipboard->set_text(text);
168
 
    }
169
 
}
170
 
 
171
 
/**
172
 
 * Makes a copy of the current desktop color to the clipboard.
173
 
 */
174
 
void sp_dropper_c32_color_copy(guint32 c32)
175
 
{
176
 
    int const pick = prefs_get_int_attribute("tools.dropper", "pick",
177
 
                                             SP_DROPPER_PICK_VISIBLE);
178
 
 
179
 
    gchar c[64];
180
 
    g_snprintf(c, 64, "%06x%02x", c32 >> 8,
181
 
        pick == SP_DROPPER_PICK_ACTUAL? SP_RGBA32_A_U(c32) : 255);
182
 
 
183
 
    Glib::ustring text;
184
 
    text += c;
185
 
    if (!text.empty()) {
186
 
            Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
187
 
            refClipboard->set_text(text);
188
 
    }
189
 
}
190
 
 
191
 
 
192
 
/**
193
 
 * Makes a copy of the current color as a hex value. This should always compute
194
 
 * the current color without alpha, but the on-screen representation.
195
 
 */
196
 
void sp_dropper_c32_color_copy_hex(guint32 c32)
197
 
{
198
 
    /*
199
 
    int pick = prefs_get_int_attribute ("tools.dropper", "pick",
200
 
                                    SP_DROPPER_PICK_VISIBLE);
201
 
 
202
 
    if ( pick == SP_DROPPER_PICK_ACTUAL )
203
 
        ; // process c32 so that it computes against page
204
 
    // else just can cut off that last 2 hex digits....
205
 
 
206
 
    */
207
 
 
208
 
    gchar c[48];
209
 
    g_snprintf(c, 48, "%06x", c32 >> 8);
210
 
 
211
 
    Glib::ustring text;
212
 
    text += c;
213
 
    if (!text.empty()) {
214
 
            Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
215
 
            refClipboard->set_text(text);
216
 
    }
 
150
    bool setalpha = prefs->getBool("/tools/dropper/setalpha", true);
 
151
 
 
152
    return SP_RGBA32_F_COMPOSE(dc->R, dc->G, dc->B,
 
153
        (pick == SP_DROPPER_PICK_ACTUAL && setalpha) ? dc->alpha : 1.0);
217
154
}
218
155
 
219
156
 
222
159
    SPDropperContext *dc = (SPDropperContext *) event_context;
223
160
    int ret = FALSE;
224
161
    SPDesktop *desktop = event_context->desktop;
 
162
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
225
163
 
226
 
    int pick = prefs_get_int_attribute("tools.dropper", "pick", SP_DROPPER_PICK_VISIBLE);
227
 
    int setalpha = prefs_get_int_attribute("tools.dropper", "setalpha", 1);
 
164
    int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE);
 
165
    bool setalpha = prefs->getBool("/tools/dropper/setalpha", true);
228
166
 
229
167
    switch (event->type) {
230
168
        case GDK_BUTTON_PRESS:
231
169
            if (event->button.button == 1 && !event_context->space_panning) {
232
 
                dc->centre = NR::Point(event->button.x, event->button.y);
 
170
                dc->centre = Geom::Point(event->button.x, event->button.y);
233
171
                dc->dragging = TRUE;
234
172
                ret = TRUE;
235
173
            }
249
187
                    // calculate average
250
188
 
251
189
                    // radius
252
 
                    rw = std::min(NR::L2(NR::Point(event->button.x, event->button.y) - dc->centre), 400.0);
 
190
                    rw = std::min(Geom::L2(Geom::Point(event->button.x, event->button.y) - dc->centre), 400.0);
253
191
 
254
192
                    if (rw == 0) { // happens sometimes, little idea why...
255
193
                        break;
256
194
                    }
257
195
 
258
 
                    NR::Point const cd = desktop->w2d(dc->centre);
259
 
                    NR::Matrix const w2dt = desktop->w2d();
260
 
                    const double scale = rw * NR_MATRIX_DF_EXPANSION(&w2dt);
261
 
                    NR::Matrix const sm( NR::scale(scale, scale) * NR::translate(cd) );
 
196
                    Geom::Point const cd = desktop->w2d(dc->centre);
 
197
                    Geom::Matrix const w2dt = desktop->w2d();
 
198
                    const double scale = rw * w2dt.descrim();
 
199
                    Geom::Matrix const sm( Geom::Scale(scale, scale) * Geom::Translate(cd) );
262
200
                    sp_canvas_item_affine_absolute(dc->area, sm);
263
201
                    sp_canvas_item_show(dc->area);
264
202
 
265
203
                    /* Get buffer */
266
 
                    const int x0 = (int) floor(dc->centre[NR::X] - rw);
267
 
                    const int y0 = (int) floor(dc->centre[NR::Y] - rw);
268
 
                    const int x1 = (int) ceil(dc->centre[NR::X] + rw);
269
 
                    const int y1 = (int) ceil(dc->centre[NR::Y] + rw);
 
204
                    const int x0 = (int) floor(dc->centre[Geom::X] - rw);
 
205
                    const int y0 = (int) floor(dc->centre[Geom::Y] - rw);
 
206
                    const int x1 = (int) ceil(dc->centre[Geom::X] + rw);
 
207
                    const int y1 = (int) ceil(dc->centre[Geom::Y] + rw);
270
208
 
271
209
                    if ((x1 > x0) && (y1 > y0)) {
272
210
                        NRPixBlock pb;
276
214
                        for (int y = y0; y < y1; y++) {
277
215
                            const unsigned char *s = NR_PIXBLOCK_PX(&pb) + (y - y0) * pb.rs;
278
216
                            for (int x = x0; x < x1; x++) {
279
 
                                const double dx = x - dc->centre[NR::X];
280
 
                                const double dy = y - dc->centre[NR::Y];
 
217
                                const double dx = x - dc->centre[Geom::X];
 
218
                                const double dy = y - dc->centre[Geom::Y];
281
219
                                const double w = exp(-((dx * dx) + (dy * dy)) / (rw * rw));
282
220
                                W += w;
283
221
                                R += w * s[0];
386
324
 
387
325
 
388
326
                if (!(sp_desktop_selection(desktop)->isEmpty())) {
389
 
                    sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_DROPPER, 
 
327
                    sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_DROPPER,
390
328
                                     _("Set picked color"));
391
329
                }
392
330