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

« back to all changes in this revision

Viewing changes to src/ui/widget/selected-style.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:
86
86
    APP_X_COLOR
87
87
} ui_drop_target_info;
88
88
 
 
89
//TODO: warning: deprecated conversion from string constant to ‘gchar*’
 
90
//
 
91
//Turn out to be warnings that we should probably leave in place. The
 
92
// pointers/types used need to be read-only. So until we correct the using
 
93
// code, those warnings are actually desired. They say "Hey! Fix this". We
 
94
// definitely don't want to hide/ignore them. --JonCruz
89
95
static GtkTargetEntry ui_drop_target_entries [] = {
90
96
    {"application/x-color", 0, APP_X_COLOR}
91
97
};
97
103
static Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop);
98
104
 
99
105
SelectedStyle::SelectedStyle(bool /*layout*/)
100
 
    : _desktop (NULL),
 
106
    : 
 
107
      current_stroke_width(0),
 
108
 
 
109
      _desktop (NULL),
101
110
 
102
111
      _table(2, 6),
103
112
      _fill_label (_("Fill:")),
104
113
      _stroke_label (_("Stroke:")),
105
114
      _opacity_label (_("O:")),
106
115
 
107
 
      _fill_place (SS_FILL),
108
 
      _stroke_place (SS_STROKE),
 
116
      _fill_place(this, SS_FILL),
 
117
      _stroke_place(this, SS_STROKE),
109
118
 
110
119
      _fill_flag_place (),
111
120
      _stroke_flag_place (),
115
124
      _opacity_sb (0.02, 0),
116
125
 
117
126
      _stroke (),
 
127
      _stroke_width_place(this),
118
128
      _stroke_width (""),
119
129
 
120
130
      _opacity_blocked (false),
375
385
                     "drag_data_received",
376
386
                     G_CALLBACK(dragDataReceived),
377
387
                     _drop[SS_FILL]);
378
 
 
379
 
    _fill_place.parent = this;
380
 
    _stroke_place.parent = this;
381
388
}
382
389
 
383
390
SelectedStyle::~SelectedStyle()
1038
1045
    switch (result_sw) {
1039
1046
    case QUERY_STYLE_NOTHING:
1040
1047
        _stroke_width.set_markup("");
 
1048
        current_stroke_width = 0;
1041
1049
        break;
1042
1050
    case QUERY_STYLE_SINGLE:
1043
1051
    case QUERY_STYLE_MULTIPLE_AVERAGED:
1049
1057
        } else {
1050
1058
            w = query->stroke_width.computed;
1051
1059
        }
 
1060
        current_stroke_width = w;
 
1061
 
1052
1062
        {
1053
1063
            gchar *str = g_strdup_printf(" %.3g", w);
1054
1064
            _stroke_width.set_markup(str);
1145
1155
    _opacity_blocked = false;
1146
1156
}
1147
1157
 
1148
 
RotateableSwatch::RotateableSwatch(guint mode) {
1149
 
    fillstroke = mode;
1150
 
    startcolor_set = false;
1151
 
    undokey = "ssrot1";
1152
 
    cr = NULL;
1153
 
    cr_set = false;
 
1158
/* =============================================  RotateableSwatch  */
 
1159
 
 
1160
RotateableSwatch::RotateableSwatch(SelectedStyle *parent, guint mode) :
 
1161
    fillstroke(mode),
 
1162
    parent(parent),
 
1163
    startcolor(0),
 
1164
    startcolor_set(false),
 
1165
    undokey("ssrot1"),
 
1166
    cr(0),
 
1167
    cr_set(false)
 
1168
    
 
1169
{
1154
1170
}
1155
1171
 
1156
1172
RotateableSwatch::~RotateableSwatch() {
1254
1270
        diff = color_adjust(hsl, by, cc, modifier);
1255
1271
    }
1256
1272
 
1257
 
    if (modifier == 3) { // do nothing
 
1273
    if (modifier == 3) { // Alt, do nothing
1258
1274
 
1259
1275
    } else if (modifier == 2) { // saturation
1260
1276
        sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
1296
1312
        cr_set = false;
1297
1313
    }
1298
1314
 
1299
 
    if (modifier == 3) { // nothing
 
1315
    if (modifier == 3) { // Alt, do nothing
1300
1316
    } else if (modifier == 2) { // saturation
1301
1317
        sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
1302
1318
                                SP_VERB_DIALOG_FILL_STROKE, ("Adjust saturation"));
1320
1336
    startcolor_set = false;
1321
1337
}
1322
1338
 
 
1339
/* =============================================  RotateableStrokeWidth  */
 
1340
 
 
1341
RotateableStrokeWidth::RotateableStrokeWidth(SelectedStyle *parent) :
 
1342
    parent(parent),
 
1343
    startvalue(0),
 
1344
    startvalue_set(false),
 
1345
    undokey("swrot1"),
 
1346
    cr(0),
 
1347
    cr_set(false)
 
1348
{
 
1349
}
 
1350
 
 
1351
RotateableStrokeWidth::~RotateableStrokeWidth() {
 
1352
}
 
1353
 
 
1354
double
 
1355
RotateableStrokeWidth::value_adjust(double current, double by, guint /*modifier*/, bool final)
 
1356
{
 
1357
    double newval;
 
1358
    // by is -1..1
 
1359
    if (by < 0) {
 
1360
        // map negative 0..-1 to current..0
 
1361
        newval = current * (1  +  by);
 
1362
    } else {
 
1363
        // map positive 0..1 to current..4*current
 
1364
        newval = current * (1  +  by) * (1  +  by);
 
1365
    }
 
1366
 
 
1367
    SPCSSAttr *css = sp_repr_css_attr_new ();
 
1368
    if (final && newval < 1e-6) {
 
1369
        // if dragged into zero and this is the final adjust on mouse release, delete stroke;
 
1370
        // if it's not final, leave it a chance to increase again (which is not possible with "none")
 
1371
        sp_repr_css_set_property (css, "stroke", "none");
 
1372
    } else {
 
1373
        Inkscape::CSSOStringStream os;
 
1374
        os << newval;
 
1375
        sp_repr_css_set_property (css, "stroke-width", os.str().c_str());
 
1376
    }
 
1377
 
 
1378
    sp_desktop_set_style (parent->getDesktop(), css);
 
1379
    sp_repr_css_attr_unref (css);
 
1380
    return newval - current;
 
1381
}
 
1382
 
 
1383
void
 
1384
RotateableStrokeWidth::do_motion(double by, guint modifier) {
 
1385
 
 
1386
    // if this is the first motion after a mouse grab, remember the current width
 
1387
    if (!startvalue_set) {
 
1388
        startvalue = parent->current_stroke_width;
 
1389
        // if it's 0, adjusting (which uses multiplication) will not be able to change it, so we
 
1390
        // cheat and provide a non-zero value
 
1391
        if (startvalue == 0)
 
1392
            startvalue = 1;
 
1393
        startvalue_set = true;
 
1394
    }
 
1395
 
 
1396
    if (modifier == 3) { // Alt, do nothing
 
1397
    } else {
 
1398
        double diff = value_adjust(startvalue, by, modifier, false);
 
1399
        sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
 
1400
                                SP_VERB_DIALOG_FILL_STROKE, (_("Adjust stroke width")));
 
1401
        parent->getDesktop()->event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Adjusting <b>stroke width</b>: was %.3g, now <b>%.3g</b> (diff %.3g)"), startvalue, startvalue + diff, diff);
 
1402
    }
 
1403
}
 
1404
 
 
1405
void
 
1406
RotateableStrokeWidth::do_release(double by, guint modifier) {
 
1407
 
 
1408
    if (modifier == 3) { // do nothing
 
1409
 
 
1410
    } else {
 
1411
        value_adjust(startvalue, by, modifier, true);
 
1412
        startvalue_set = false;
 
1413
        sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
 
1414
                                SP_VERB_DIALOG_FILL_STROKE, (_("Adjust stroke width")));
 
1415
    }
 
1416
 
 
1417
    if (!strcmp(undokey, "swrot1")) {
 
1418
        undokey = "swrot2";
 
1419
    } else {
 
1420
        undokey = "swrot1";
 
1421
    }
 
1422
    parent->getDesktop()->event_context->_message_context->clear();
 
1423
}
 
1424
 
 
1425
 
1323
1426
Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop)
1324
1427
{
1325
1428
    if (Dialog::PanelDialogBase *panel_dialog =