summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-10-19 10:50:29 +0000
committerjabiertxof <info@marker.es>2016-10-19 10:50:29 +0000
commitf2d2c7740567dcf2452c41d8332380708f557157 (patch)
tree8ed1302a7cd2dc82f2621a5707ed0f19f4c83a20 /src
parentReposition widget and add degree symbol (diff)
downloadinkscape-f2d2c7740567dcf2452c41d8332380708f557157.tar.gz
inkscape-f2d2c7740567dcf2452c41d8332380708f557157.zip
Working with rotate preview
(bzr r15142.1.15)
Diffstat (limited to 'src')
-rw-r--r--src/display/sp-canvas.cpp169
-rw-r--r--src/display/sp-canvas.h4
-rw-r--r--src/ui/tools/tool-base.cpp2
-rw-r--r--src/widgets/desktop-widget.cpp24
4 files changed, 183 insertions, 16 deletions
diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp
index 9201168ef..36d0b7e7c 100644
--- a/src/display/sp-canvas.cpp
+++ b/src/display/sp-canvas.cpp
@@ -27,15 +27,19 @@
#include "helper/sp-marshal.h"
#include <2geom/rect.h>
#include <2geom/affine.h>
-#include "display/cairo-utils.h"
#include "display/sp-canvas.h"
#include "display/sp-canvas-group.h"
+#include "display/rendermode.h"
+#include "display/cairo-utils.h"
+#include "display/cairo-templates.h"
+#include "display/drawing-context.h"
+#include "display/drawing-item.h"
+#include "display/nr-filter-colormatrix.h"
+#include "display/canvas-arena.h"
#include "preferences.h"
#include "inkscape.h"
#include "sodipodi-ctrlrect.h"
#include "cms-system.h"
-#include "display/rendermode.h"
-#include "display/cairo-utils.h"
#include "debug/gdk-event-latency-tracker.h"
#include "desktop.h"
#include "color.h"
@@ -1945,6 +1949,165 @@ void SPCanvas::scrollTo(double cx, double cy, unsigned int clear, bool is_scroll
}
addIdle();
}
+gdouble grayscale_value_matrix[20] = {
+ 0.21, 0.72, 0.072, 0, 0,
+ 0.21, 0.72, 0.072, 0, 0,
+ 0.21, 0.72, 0.072, 0, 0,
+ 0 , 0 , 0 , 1, 0
+ };
+cairo_surface_t *surface_rotated;
+cairo_surface_t *surface_origin;
+cairo_surface_t *surface_measure;
+double start_angle = 0;
+bool started = false;
+void SPCanvas::startRotateTo(double angle)
+{
+ if (!_backing_store || started) {
+ return;
+ }
+ start_angle = angle;
+ started = true;
+ GtkAllocation allocation;
+ gtk_widget_get_allocation(&_widget, &allocation);
+ int half_w = allocation.width/2;
+ int half_h = allocation.height/2;
+ int half_min = std::min(half_w,half_h);
+ cairo_surface_t *new_backing_store = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height);
+ cairo_t *cr = cairo_create(new_backing_store);
+ cairo_arc(cr, half_w, half_h, half_min-15, 0, 2*M_PI);
+ cairo_fill(cr);
+ cairo_set_operator(cr, CAIRO_OPERATOR_IN);
+ cairo_set_source_surface(cr, _backing_store, 0, 0);
+ cairo_paint(cr);
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+ cairo_arc(cr, half_w, half_h, half_min-16, 0, 2*M_PI);
+ cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
+ cairo_stroke(cr);
+ cairo_destroy(cr);
+ surface_rotated = new_backing_store;
+
+ cairo_surface_t *new_backing_store_measure = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height);
+ cr = cairo_create(new_backing_store_measure);
+ cairo_arc(cr, half_w, half_h, half_min-15, 0, 2*M_PI);
+ cairo_set_source_rgba (cr, 1, 1, 1, 0.2);
+ cairo_fill(cr);
+ cairo_translate(cr, half_w, half_h);
+ for (gint x = 0; x < 360 ; x++){
+ gint ang = 360 - x ;//+ 90;
+ if (ang > 180) {
+ ang -= 360;
+ }
+ double rot = (-180.0 + x - start_angle)*(M_PI/180.);
+ double dist = half_min-9;
+ gint inverse = 1;
+ if((x- start_angle) < 91 || (x- start_angle) > 270) {
+ inverse = -1;
+ }
+ if(x%10 == 0) {
+ cairo_rotate(cr, -rot);
+ cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_set_font_size(cr, 10.0);
+ cairo_text_extents_t extents;
+ std::string s = std::to_string(ang) + "ยบ";
+ cairo_text_extents(cr, s.c_str(), &extents);
+ //std::cout << extents.width/2 << "extents.x_bearing\n";
+ cairo_translate(cr, (extents.width/2) * inverse * -1, (dist + ((extents.height/2)* inverse)));
+ if((x- start_angle) < 91 || (x- start_angle) > 270) {
+ cairo_rotate(cr, 180*(M_PI/180.0));
+ }
+ cairo_text_path(cr, s.c_str());
+ if((x- start_angle) < 91 || (x- start_angle) > 270) {
+ cairo_rotate(cr, -180*(M_PI/180.0));
+ }
+ cairo_translate(cr, (extents.width/2) * inverse , (dist + ((extents.height/2)* inverse)) * -1);
+ cairo_set_source_rgba (cr, 1, 1, 1, 1);
+ cairo_fill(cr);
+ cairo_rotate(cr, rot);
+ }
+ cairo_rotate(cr, x*(M_PI/180.));
+ if(x%5 == 0) {
+ cairo_move_to(cr, 0, half_min-30);
+ cairo_line_to(cr, 0, half_min-17);
+ } else {
+ cairo_move_to(cr, 0, half_min-20);
+ cairo_line_to(cr, 0, half_min-15);
+ }
+ cairo_line_to(cr, 0, half_min-15);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.4);
+ cairo_set_line_width (cr,1);
+ cairo_stroke(cr);
+ cairo_rotate(cr, -x*(M_PI/180.));
+ }
+ cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+ cairo_translate(cr, -half_w, -half_h);
+ cairo_arc(cr, half_w, half_h, half_min-30, 0, 2*M_PI);
+ cairo_set_source_rgba (cr, 1, 1, 1, 1);
+ cairo_fill(cr);
+ cairo_destroy(cr);
+ surface_measure = new_backing_store_measure;
+
+ cairo_surface_t *new_backing_store_grey = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height);
+ cr = cairo_create(new_backing_store_grey);
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+ cairo_set_source_surface(cr, _backing_store, 0, 0);
+ cairo_paint(cr);
+ Inkscape::Filters::FilterColorMatrix::ColorMatrixMatrix _grayscale_colormatrix = std::vector<gdouble> (grayscale_value_matrix, grayscale_value_matrix + 20);
+ cairo_surface_t *out = ink_cairo_surface_create_identical(new_backing_store_grey);
+ ink_cairo_surface_filter(new_backing_store_grey, out, _grayscale_colormatrix);
+ cairo_set_source_surface(cr, out, 0, 0);
+ cairo_surface_destroy(out);
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ surface_origin = new_backing_store_grey;
+
+}
+
+void SPCanvas::endRotateTo()
+{
+ if (!_backing_store) {
+ return;
+ }
+ started = false;
+ surface_rotated = NULL;
+ surface_origin = NULL;
+ gtk_widget_queue_draw(GTK_WIDGET(this));
+ dirtyAll();
+ addIdle();
+}
+
+void SPCanvas::rotateTo(SPCanvasItem * item, double angle)
+{
+ if (!_backing_store) {
+ return;
+ }
+ GtkAllocation allocation;
+ gtk_widget_get_allocation(&_widget, &allocation);
+ cairo_surface_t *new_backing_store = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height);
+ cairo_t *cr = cairo_create(new_backing_store);
+ cairo_set_source_surface(cr, surface_origin, 0, 0);
+ cairo_paint(cr);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
+ cairo_paint(cr);
+ cairo_pattern_t *source_pattern;
+ cairo_matrix_t matrix;
+ source_pattern = cairo_pattern_create_for_surface (surface_rotated);
+ cairo_matrix_init_identity (&matrix);
+ cairo_matrix_translate (&matrix, allocation.width/2.0, allocation.height/2.0);
+ cairo_matrix_rotate (&matrix, Geom::rad_from_deg(angle - start_angle) * -1);
+ cairo_matrix_translate (&matrix, -allocation.width/2.0, -allocation.height/2.0);
+ cairo_pattern_set_matrix (source_pattern, &matrix);
+ cairo_set_source(cr, source_pattern);
+ cairo_paint(cr);
+ cairo_set_source_surface(cr, surface_measure, 0, 0);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ cairo_surface_destroy(_backing_store);
+ _backing_store = new_backing_store;
+ cairo_pattern_destroy (source_pattern);
+ gtk_widget_queue_draw(GTK_WIDGET(this));
+ addIdle();
+}
void SPCanvas::updateNow()
{
diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h
index 78d96d728..b78cdcdd5 100644
--- a/src/display/sp-canvas.h
+++ b/src/display/sp-canvas.h
@@ -72,7 +72,9 @@ GType sp_canvas_get_type() G_GNUC_CONST;
struct SPCanvas {
/// Scrolls canvas to specific position (cx and cy are measured in screen pixels).
void scrollTo(double cx, double cy, unsigned int clear, bool is_scrolling = false);
-
+ void startRotateTo(double angle);
+ void rotateTo(SPCanvasItem * item, double angle);
+ void endRotateTo();
/// Synchronously updates the canvas if necessary.
void updateNow();
diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp
index 8a35882b9..128a09878 100644
--- a/src/ui/tools/tool-base.cpp
+++ b/src/ui/tools/tool-base.cpp
@@ -345,7 +345,6 @@ bool ToolBase::root_handler(GdkEvent* event) {
/* sp_desktop_dialog(); */
}
break;
-
case GDK_BUTTON_PRESS:
// save drag origin
xp = (gint) event->button.x;
@@ -446,7 +445,6 @@ bool ToolBase::root_handler(GdkEvent* event) {
// do not drag if we're within tolerance from origin
break;
}
-
// Once the user has moved farther than tolerance from
// the original location (indicating they intend to move
// the object, not click), then always process the motion
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index 16d71b4d2..e868dd2d6 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -62,7 +62,6 @@
#include "spw-utilities.h"
#include "toolbox.h"
#include "widget-sizes.h"
-
#include "verbs.h"
#include <gtkmm/cssprovider.h>
#include <gtkmm/paned.h>
@@ -1785,15 +1784,20 @@ sp_desktop_widget_rotate_document(GtkSpinButton *spin, SPDesktopWidget *dtw)
{
SPNamedView *nv = dtw->desktop->namedview;
double value = gtk_spin_button_get_value (spin);
- if (!dtw->desktop->getDocument()->getRoot()->rotated && value != nv->document_rotation) {
- nv->document_rotation = value;
- sp_repr_set_svg_double(nv->getRepr(), "inkscape:document-rotation", value);
- SPObject *updated = SP_OBJECT(nv);
- if (updated) {
- updated->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
- }
- }
- spinbutton_defocus (GTK_WIDGET(spin));
+// if (!dtw->desktop->getDocument()->getRoot()->rotated && value != nv->document_rotation) {
+// nv->document_rotation = value;
+// sp_repr_set_svg_double(nv->getRepr(), "inkscape:document-rotation", value);
+// SPObject *updated = SP_OBJECT(nv);
+// if (updated) {
+// updated->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+// }
+// //dtw->desktop->canvas->endRotateTo();
+// } else if( value != nv->document_rotation ) {
+ dtw->desktop->canvas->startRotateTo(0);
+ dtw->desktop->canvas->rotateTo(dtw->desktop->getDrawing(),value);
+ if (value == 180) { dtw->desktop->canvas->endRotateTo();}
+// }
+ spinbutton_defocus (GTK_WIDGET(spin));
}