1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* Common drawing mode. Base class of Eraser and Calligraphic tools.
*//*
* Authors: see git history
*
* Copyright (C) 2018 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include "ui/tools/dynamic-base.h"
#include "message-context.h"
#include "desktop.h"
#include "display/curve.h"
#include "display/control/canvas-item-bpath.h"
#include "util/units.h"
using Inkscape::Util::Unit;
using Inkscape::Util::Quantity;
using Inkscape::Util::unit_table;
#define MIN_PRESSURE 0.0
#define MAX_PRESSURE 1.0
#define DEFAULT_PRESSURE 1.0
#define DRAG_MIN 0.0
#define DRAG_DEFAULT 1.0
#define DRAG_MAX 1.0
namespace Inkscape {
namespace UI {
namespace Tools {
DynamicBase::DynamicBase(SPDesktop *desktop, std::string prefs_path, const std::string &cursor_filename)
: ToolBase(desktop, prefs_path, cursor_filename)
, accumulated(nullptr)
, currentshape(nullptr)
, currentcurve(nullptr)
, cal1(nullptr)
, cal2(nullptr)
, point1()
, point2()
, npoints(0)
, repr(nullptr)
, cur(0, 0)
, vel(0, 0)
, vel_max(0)
, acc(0, 0)
, ang(0, 0)
, last(0, 0)
, del(0, 0)
, pressure(DEFAULT_PRESSURE)
, xtilt(0)
, ytilt(0)
, dragging(false)
, usepressure(false)
, usetilt(false)
, mass(0.3)
, drag(DRAG_DEFAULT)
, angle(30.0)
, width(0.2)
, vel_thin(0.1)
, flatness(0.9)
, tremor(0)
, cap_rounding(0)
, is_drawing(false)
, abs_width(false)
{
}
DynamicBase::~DynamicBase() {
for (auto segment : segments) {
delete segment;
}
segments.clear();
if (this->currentshape) {
delete currentshape;
}
}
void DynamicBase::set(const Inkscape::Preferences::Entry& value) {
Glib::ustring path = value.getEntryName();
// ignore preset modifications
static Glib::ustring const presets_path = getPrefsPath() + "/preset";
Glib::ustring const &full_path = value.getPath();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Unit const *unit = unit_table.getUnit(prefs->getString("/tools/calligraphic/unit"));
if (full_path.compare(0, presets_path.size(), presets_path) == 0) {
return;
}
if (path == "mass") {
this->mass = 0.01 * CLAMP(value.getInt(10), 0, 100);
} else if (path == "wiggle") {
this->drag = CLAMP((1 - 0.01 * value.getInt()), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle
} else if (path == "angle") {
this->angle = CLAMP(value.getDouble(), -90, 90);
} else if (path == "width") {
this->width = 0.01 * CLAMP(value.getDouble(), Quantity::convert(0.001, unit, "px"), Quantity::convert(100, unit, "px"));
} else if (path == "thinning") {
this->vel_thin = 0.01 * CLAMP(value.getInt(10), -100, 100);
} else if (path == "tremor") {
this->tremor = 0.01 * CLAMP(value.getInt(), 0, 100);
} else if (path == "flatness") {
this->flatness = 0.01 * CLAMP(value.getInt(), -100, 100);
} else if (path == "usepressure") {
this->usepressure = value.getBool();
} else if (path == "usetilt") {
this->usetilt = value.getBool();
} else if (path == "abs_width") {
this->abs_width = value.getBool();
} else if (path == "cap_rounding") {
this->cap_rounding = value.getDouble();
}
}
/* Get normalized point */
Geom::Point DynamicBase::getNormalizedPoint(Geom::Point v) const {
auto drect = _desktop->get_display_area();
double const max = drect.maxExtent();
return (v - drect.bounds().min()) / max;
}
/* Get view point */
Geom::Point DynamicBase::getViewPoint(Geom::Point n) const {
auto drect = _desktop->get_display_area();
double const max = drect.maxExtent();
return n * max + drect.bounds().min();
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|