summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4e5db1d)
raw | patch | inline | side by side (parent: 4e5db1d)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Tue, 1 Apr 2008 17:32:22 +0000 (17:32 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Tue, 1 Apr 2008 17:32:22 +0000 (17:32 +0000) |
src/ui/widget/selected-style.cpp | patch | blob | history | |
src/ui/widget/selected-style.h | patch | blob | history |
index 20838ee22ba8d0d12d2ba9ece042db14363b35cc..520d7f40402ddac306e3ceca4a3341ad2754a3d9 100644 (file)
static Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop);
SelectedStyle::SelectedStyle(bool /*layout*/)
- : _desktop (NULL),
+ :
+ current_stroke_width(0),
+
+ _desktop (NULL),
_table(2, 6),
_fill_label (_("Fill:")),
_opacity_sb (0.02, 0),
_stroke (),
+ _stroke_width_place(),
_stroke_width (""),
_opacity_blocked (false),
_fill_place.parent = this;
_stroke_place.parent = this;
+ _stroke_width_place.parent = this;
}
SelectedStyle::~SelectedStyle()
switch (result_sw) {
case QUERY_STYLE_NOTHING:
_stroke_width.set_markup("");
+ current_stroke_width = 0;
break;
case QUERY_STYLE_SINGLE:
case QUERY_STYLE_MULTIPLE_AVERAGED:
} else {
w = query->stroke_width.computed;
}
+ current_stroke_width = w;
+
{
gchar *str = g_strdup_printf(" %.3g", w);
_stroke_width.set_markup(str);
_opacity_blocked = false;
}
+/* ============================================= RotateableSwatch */
+
RotateableSwatch::RotateableSwatch(guint mode) {
fillstroke = mode;
startcolor_set = false;
diff = color_adjust(hsl, by, cc, modifier);
}
- if (modifier == 3) { // do nothing
+ if (modifier == 3) { // Alt, do nothing
} else if (modifier == 2) { // saturation
sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
cr_set = false;
}
- if (modifier == 3) { // nothing
+ if (modifier == 3) { // Alt, do nothing
} else if (modifier == 2) { // saturation
sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
SP_VERB_DIALOG_FILL_STROKE, ("Adjust saturation"));
startcolor_set = false;
}
+/* ============================================= RotateableStrokeWidth */
+
+RotateableStrokeWidth::RotateableStrokeWidth() {
+ undokey = "swrot1";
+ startvalue_set = false;
+ cr = NULL;
+ cr_set = false;
+}
+
+RotateableStrokeWidth::~RotateableStrokeWidth() {
+}
+
+double
+RotateableStrokeWidth::value_adjust(double current, double by, guint modifier, bool final)
+{
+ double newval;
+ // by is -1..1
+ if (by < 0) {
+ // map negative 0..-1 to current..0
+ newval = current * (1 + by);
+ } else {
+ // map positive 0..1 to current..4*current
+ newval = current * (1 + by) * (1 + by);
+ }
+
+ SPCSSAttr *css = sp_repr_css_attr_new ();
+ if (final && newval < 1e-6) {
+ // if dragged into zero and this is the final adjust on mouse release, delete stroke;
+ // if it's not final, leave it a chance to increase again (which is not possible with "none")
+ sp_repr_css_set_property (css, "stroke", "none");
+ } else {
+ Inkscape::CSSOStringStream os;
+ os << newval;
+ sp_repr_css_set_property (css, "stroke-width", os.str().c_str());
+ }
+
+ sp_desktop_set_style (parent->getDesktop(), css);
+ sp_repr_css_attr_unref (css);
+ return newval - current;
+}
+
+void
+RotateableStrokeWidth::do_motion(double by, guint modifier) {
+
+ // if this is the first motion after a mouse grab, remember the current width
+ if (!startvalue_set) {
+ startvalue = parent->current_stroke_width;
+ // if it's 0, adjusting (which uses multiplication) will not be able to change it, so we
+ // cheat and provide a non-zero value
+ if (startvalue == 0)
+ startvalue = 1;
+ startvalue_set = true;
+ }
+
+ if (modifier == 3) { // Alt, do nothing
+ } else {
+ double diff = value_adjust(startvalue, by, modifier, false);
+ sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
+ SP_VERB_DIALOG_FILL_STROKE, (_("Adjust stroke width")));
+ 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);
+ }
+}
+
+void
+RotateableStrokeWidth::do_release(double by, guint modifier) {
+
+ if (modifier == 3) { // do nothing
+
+ } else {
+ value_adjust(startvalue, by, modifier, true);
+ startvalue_set = false;
+ sp_document_maybe_done (sp_desktop_document(parent->getDesktop()), undokey,
+ SP_VERB_DIALOG_FILL_STROKE, (_("Adjust stroke width")));
+ }
+
+ if (!strcmp(undokey, "swrot1")) {
+ undokey = "swrot2";
+ } else {
+ undokey = "swrot1";
+ }
+ parent->getDesktop()->event_context->_message_context->clear();
+}
+
+
Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop)
{
if (Dialog::PanelDialogBase *panel_dialog =
index cd67abfc563e708adc3faf17efb2cfd2613fb1d9..4826281669cad5dda6f5a6b7f4bb388b523b13f1 100644 (file)
virtual void do_release (double by, guint state);
};
+class RotateableStrokeWidth: public Rotateable
+{
+public:
+ RotateableStrokeWidth();
+ ~RotateableStrokeWidth();
+
+ SelectedStyle *parent;
+
+ double startvalue;
+ bool startvalue_set;
+
+ gchar *undokey;
+
+ GdkCursor *cr;
+ bool cr_set;
+
+ double value_adjust(double current, double by, guint modifier, bool final);
+ virtual void do_motion (double by, guint state);
+ virtual void do_release (double by, guint state);
+};
+
class SelectedStyle : public Gtk::HBox
{
public:
guint _mode[2];
+ double current_stroke_width;
+
protected:
SPDesktop *_desktop;
Glib::ustring __multiple[2];
Gtk::HBox _stroke;
- Gtk::EventBox _stroke_width_place;
+ RotateableStrokeWidth _stroke_width_place;
Gtk::Label _stroke_width;
Glib::ustring _paintserver_id[2];