summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2012-12-14 00:02:58 +0000
committerJabiertxo Arraiza Cenoz <jtx@jtx.marker.es>2012-12-14 00:02:58 +0000
commit6e8af542d7247bce3e9d03210170febd28a4ef54 (patch)
tree37d9d885550aef067b6b8ba11a51bfb3054dc3ef /src
parentbzr history lost by a killed merge (diff)
parentre-add Grayscale color mode (diff)
downloadinkscape-6e8af542d7247bce3e9d03210170febd28a4ef54.tar.gz
inkscape-6e8af542d7247bce3e9d03210170febd28a4ef54.zip
merge from brach
(bzr r11950.1.2)
Diffstat (limited to 'src')
-rw-r--r--src/display/drawing.cpp34
-rw-r--r--src/display/nr-filter-colormatrix.cpp77
-rw-r--r--src/display/nr-filter-colormatrix.h9
-rw-r--r--src/ui/dialog/document-metadata.cpp112
-rw-r--r--src/ui/dialog/document-metadata.h21
-rw-r--r--src/widgets/spinbutton-events.cpp48
6 files changed, 187 insertions, 114 deletions
diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp
index 77f24caf3..171cc014f 100644
--- a/src/display/drawing.cpp
+++ b/src/display/drawing.cpp
@@ -4,8 +4,9 @@
*//*
* Authors:
* Krzysztof KosiƄski <tweenk.pl@gmail.com>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) 2011 Authors
+ * Copyright (C) 2011-2012 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -14,6 +15,12 @@
#include "nr-filter-gaussian.h"
#include "nr-filter-types.h"
+//grayscale colormode:
+#include "nr-filter-colormatrix.h"
+#include "cairo-templates.h"
+#include "drawing-context.h"
+
+
namespace Inkscape {
Drawing::Drawing(SPCanvasArena *arena)
@@ -145,12 +152,37 @@ Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned fl
_pickItemsForCaching();
}
+// hardcoded grayscale color matrix values. could be turned into preference settings in future.
+static const gdouble grayscale_value_matrix[] = {
+ 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
+};
+static Filters::FilterColorMatrix::ColorMatrixMatrix grayscale_colormatrix(
+ std::vector<gdouble> (grayscale_value_matrix, grayscale_value_matrix + sizeof(grayscale_value_matrix) / sizeof(grayscale_value_matrix[0]) )
+);
+
void
Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags)
{
if (_root) {
_root->render(ct, area, flags);
}
+
+ if (colorMode() == COLORMODE_GRAYSCALE) {
+ // apply grayscale filter on top of everything
+ cairo_surface_t *input = ct.rawTarget();
+ cairo_surface_t *out = ink_cairo_surface_create_identical(input);
+ ink_cairo_surface_filter(input, out, grayscale_colormatrix);
+ Geom::Point origin = ct.targetLogicalBounds().min();
+ ct.setSource(out, origin[Geom::X], origin[Geom::Y]);
+ ct.setOperator(CAIRO_OPERATOR_SOURCE);
+ ct.paint();
+ ct.setOperator(CAIRO_OPERATOR_OVER);
+
+ cairo_surface_destroy(out);
+ }
}
DrawingItem *
diff --git a/src/display/nr-filter-colormatrix.cpp b/src/display/nr-filter-colormatrix.cpp
index 33718ed68..fad6215ff 100644
--- a/src/display/nr-filter-colormatrix.cpp
+++ b/src/display/nr-filter-colormatrix.cpp
@@ -32,50 +32,47 @@ FilterPrimitive * FilterColorMatrix::create() {
FilterColorMatrix::~FilterColorMatrix()
{}
-struct ColorMatrixMatrix {
- ColorMatrixMatrix(std::vector<double> const &values) {
- unsigned limit = std::min(static_cast<size_t>(20), values.size());
- for (unsigned i = 0; i < limit; ++i) {
- if (i % 5 == 4) {
- _v[i] = round(values[i]*255*255);
- } else {
- _v[i] = round(values[i]*255);
- }
- }
- for (unsigned i = limit; i < 20; ++i) {
- _v[i] = 0;
+FilterColorMatrix::ColorMatrixMatrix::ColorMatrixMatrix(std::vector<double> const &values) {
+ unsigned limit = std::min(static_cast<size_t>(20), values.size());
+ for (unsigned i = 0; i < limit; ++i) {
+ if (i % 5 == 4) {
+ _v[i] = round(values[i]*255*255);
+ } else {
+ _v[i] = round(values[i]*255);
}
}
+ for (unsigned i = limit; i < 20; ++i) {
+ _v[i] = 0;
+ }
+}
- guint32 operator()(guint32 in) {
- EXTRACT_ARGB32(in, a, r, g, b)
- // we need to un-premultiply alpha values for this type of matrix
- // TODO: unpremul can be ignored if there is an identity mapping on the alpha channel
- if (a != 0) {
- r = unpremul_alpha(r, a);
- g = unpremul_alpha(g, a);
- b = unpremul_alpha(b, a);
- }
-
- gint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + a*_v[3] + _v[4];
- gint32 go = r*_v[5] + g*_v[6] + b*_v[7] + a*_v[8] + _v[9];
- gint32 bo = r*_v[10] + g*_v[11] + b*_v[12] + a*_v[13] + _v[14];
- gint32 ao = r*_v[15] + g*_v[16] + b*_v[17] + a*_v[18] + _v[19];
- ro = (pxclamp(ro, 0, 255*255) + 127) / 255;
- go = (pxclamp(go, 0, 255*255) + 127) / 255;
- bo = (pxclamp(bo, 0, 255*255) + 127) / 255;
- ao = (pxclamp(ao, 0, 255*255) + 127) / 255;
+guint32 FilterColorMatrix::ColorMatrixMatrix::operator()(guint32 in) {
+ EXTRACT_ARGB32(in, a, r, g, b)
+ // we need to un-premultiply alpha values for this type of matrix
+ // TODO: unpremul can be ignored if there is an identity mapping on the alpha channel
+ if (a != 0) {
+ r = unpremul_alpha(r, a);
+ g = unpremul_alpha(g, a);
+ b = unpremul_alpha(b, a);
+ }
- ro = premul_alpha(ro, ao);
- go = premul_alpha(go, ao);
- bo = premul_alpha(bo, ao);
+ gint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + a*_v[3] + _v[4];
+ gint32 go = r*_v[5] + g*_v[6] + b*_v[7] + a*_v[8] + _v[9];
+ gint32 bo = r*_v[10] + g*_v[11] + b*_v[12] + a*_v[13] + _v[14];
+ gint32 ao = r*_v[15] + g*_v[16] + b*_v[17] + a*_v[18] + _v[19];
+ ro = (pxclamp(ro, 0, 255*255) + 127) / 255;
+ go = (pxclamp(go, 0, 255*255) + 127) / 255;
+ bo = (pxclamp(bo, 0, 255*255) + 127) / 255;
+ ao = (pxclamp(ao, 0, 255*255) + 127) / 255;
+
+ ro = premul_alpha(ro, ao);
+ go = premul_alpha(go, ao);
+ bo = premul_alpha(bo, ao);
+
+ ASSEMBLE_ARGB32(pxout, ao, ro, go, bo)
+ return pxout;
+}
- ASSEMBLE_ARGB32(pxout, ao, ro, go, bo)
- return pxout;
- }
-private:
- gint32 _v[20];
-};
struct ColorMatrixSaturate {
ColorMatrixSaturate(double v_in) {
@@ -163,7 +160,7 @@ void FilterColorMatrix::render_cairo(FilterSlot &slot)
switch (type) {
case COLORMATRIX_MATRIX:
- ink_cairo_surface_filter(input, out, ColorMatrixMatrix(values));
+ ink_cairo_surface_filter(input, out, FilterColorMatrix::ColorMatrixMatrix(values));
break;
case COLORMATRIX_SATURATE:
ink_cairo_surface_filter(input, out, ColorMatrixSaturate(value));
diff --git a/src/display/nr-filter-colormatrix.h b/src/display/nr-filter-colormatrix.h
index 5f21a4210..c7e5e91d9 100644
--- a/src/display/nr-filter-colormatrix.h
+++ b/src/display/nr-filter-colormatrix.h
@@ -42,6 +42,15 @@ public:
virtual void set_type(FilterColorMatrixType type);
virtual void set_value(gdouble value);
virtual void set_values(std::vector<gdouble> const &values);
+
+public:
+ struct ColorMatrixMatrix {
+ ColorMatrixMatrix(std::vector<double> const &values);
+ guint32 operator()(guint32 in);
+ private:
+ gint32 _v[20];
+ };
+
private:
std::vector<gdouble> values;
gdouble value;
diff --git a/src/ui/dialog/document-metadata.cpp b/src/ui/dialog/document-metadata.cpp
index 6318ffbbb..efe25d843 100644
--- a/src/ui/dialog/document-metadata.cpp
+++ b/src/ui/dialog/document-metadata.cpp
@@ -61,13 +61,30 @@ DocumentMetadata::getInstance()
DocumentMetadata::DocumentMetadata()
+#if WITH_GTKMM_3_0
+ : UI::Widget::Panel ("", "/dialogs/documentmetadata", SP_VERB_DIALOG_METADATA)
+#else
: UI::Widget::Panel ("", "/dialogs/documentmetadata", SP_VERB_DIALOG_METADATA),
_page_metadata1(1, 1), _page_metadata2(1, 1)
+#endif
{
hide();
_getContents()->set_spacing (4);
_getContents()->pack_start(_notebook, true, true);
+ _page_metadata1.set_border_width(2);
+ _page_metadata2.set_border_width(2);
+
+#if WITH_GTKMM_3_0
+ _page_metadata1.set_column_spacing(2);
+ _page_metadata2.set_column_spacing(2);
+ _page_metadata1.set_row_spacing(2);
+ _page_metadata2.set_row_spacing(2);
+#else
+ _page_metadata1.set_spacings(2);
+ _page_metadata2.set_spacings(2);
+#endif
+
_notebook.append_page(_page_metadata1, _("Metadata"));
_notebook.append_page(_page_metadata2, _("License"));
@@ -98,50 +115,6 @@ DocumentMetadata::~DocumentMetadata()
delete (*it);
}
-//========================================================================
-
-/**
- * Helper function that attachs widgets in a 3xn table. The widgets come in an
- * array that has two entries per table row. The two entries code for four
- * possible cases: (0,0) means insert space in first column; (0, non-0) means
- * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
- * (non-0, non-0) means two widgets in columns 2 and 3.
- */
-inline void attach_all(Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int start = 0)
-{
- for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2)
- {
- if (arr[i] && arr[i+1])
- {
- table.attach (const_cast<Gtk::Widget&>(*arr[i]), 1, 2, r, r+1,
- Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
- table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
- Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
- }
- else
- {
- if (arr[i+1])
- table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
- Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
- else if (arr[i])
- {
- Gtk::Label& label = static_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
- label.set_alignment (0.0);
- table.attach (label, 0, 3, r, r+1,
- Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
- }
- else
- {
- Gtk::HBox *space = manage (new Gtk::HBox);
- space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
- table.attach (*space, 0, 1, r, r+1,
- (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
- }
- }
- ++r;
- }
-}
-
void
DocumentMetadata::build_metadata()
{
@@ -152,7 +125,14 @@ DocumentMetadata::build_metadata()
Gtk::Label *label = manage (new Gtk::Label);
label->set_markup (_("<b>Dublin Core Entities</b>"));
label->set_alignment (0.0);
- _page_metadata1.table().attach (*label, 0,3,0,1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+
+#if WITH_GTKMM_3_0
+ label->set_valign(Gtk::ALIGN_CENTER);
+ _page_metadata1.attach(*label, 0, 0, 3, 1);
+#else
+ _page_metadata1.attach(*label, 0,3,0,1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+#endif
+
/* add generic metadata entry areas */
struct rdf_work_entity_t * entity;
int row = 1;
@@ -162,9 +142,22 @@ DocumentMetadata::build_metadata()
_rdflist.push_back (w);
Gtk::HBox *space = manage (new Gtk::HBox);
space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
- _page_metadata1.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
- _page_metadata1.table().attach (w->_label, 1,2, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
- _page_metadata1.table().attach (*w->_packable, 2,3, row, row+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
+
+#if WITH_GTKMM_3_0
+ space->set_valign(Gtk::ALIGN_CENTER);
+ _page_metadata1.attach(*space, 0, row, 1, 1);
+
+ w->_label.set_valign(Gtk::ALIGN_CENTER);
+ _page_metadata1.attach(w->_label, 1, row, 1, 1);
+
+ w->_packable->set_hexpand();
+ w->_packable->set_valign(Gtk::ALIGN_CENTER);
+ _page_metadata1.attach(*w->_packable, 2, row, 1, 1);
+#else
+ _page_metadata1.attach(*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+ _page_metadata1.attach(w->_label, 1,2, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+ _page_metadata1.attach(*w->_packable, 2,3, row, row+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
+#endif
}
}
@@ -174,14 +167,31 @@ DocumentMetadata::build_metadata()
Gtk::Label *llabel = manage (new Gtk::Label);
llabel->set_markup (_("<b>License</b>"));
llabel->set_alignment (0.0);
- _page_metadata2.table().attach (*llabel, 0,3, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+
+#if WITH_GTKMM_3_0
+ llabel->set_valign(Gtk::ALIGN_CENTER);
+ _page_metadata2.attach(*llabel, 0, row, 3, 1);
+#else
+ _page_metadata2.attach(*llabel, 0,3, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+#endif
+
/* add license selector pull-down and URI */
++row;
_licensor.init (_wr);
Gtk::HBox *space = manage (new Gtk::HBox);
space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
- _page_metadata2.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
- _page_metadata2.table().attach (_licensor, 1,3, row, row+1, Gtk::EXPAND|Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+
+#if WITH_GTKMM_3_0
+ space->set_valign(Gtk::ALIGN_CENTER);
+ _page_metadata2.attach(*space, 0, row, 1, 1);
+
+ _licensor.set_hexpand();
+ _licensor.set_valign(Gtk::ALIGN_CENTER);
+ _page_metadata2.attach(_licensor, 1, row, 2, 1);
+#else
+ _page_metadata2.attach(*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+ _page_metadata2.attach(_licensor, 1,3, row, row+1, Gtk::EXPAND|Gtk::FILL, (Gtk::AttachOptions)0,0,0);
+#endif
}
/**
diff --git a/src/ui/dialog/document-metadata.h b/src/ui/dialog/document-metadata.h
index f201679b5..3b7ed1ec8 100644
--- a/src/ui/dialog/document-metadata.h
+++ b/src/ui/dialog/document-metadata.h
@@ -13,12 +13,22 @@
#ifndef INKSCAPE_UI_DIALOG_DOCUMENT_METADATA_H
#define INKSCAPE_UI_DIALOG_DOCUMENT_METADATA_H
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <list>
#include <stddef.h>
#include "ui/widget/panel.h"
#include <gtkmm/notebook.h>
+
+#if WITH_GTKMM_3_0
+# include <gtkmm/grid.h>
+#else
+# include <gtkmm/table.h>
+#endif
+
#include "ui/widget/licensor.h"
-#include "ui/widget/notebook-page.h"
#include "ui/widget/registry.h"
namespace Inkscape {
@@ -51,8 +61,13 @@ protected:
Gtk::Notebook _notebook;
- UI::Widget::NotebookPage _page_metadata1;
- UI::Widget::NotebookPage _page_metadata2;
+#if WITH_GTKMM_3_0
+ Gtk::Grid _page_metadata1;
+ Gtk::Grid _page_metadata2;
+#else
+ Gtk::Table _page_metadata1;
+ Gtk::Table _page_metadata2;
+#endif
//---------------------------------------------------------------
RDElist _rdflist;
diff --git a/src/widgets/spinbutton-events.cpp b/src/widgets/spinbutton-events.cpp
index c718b6712..1d44b9190 100644
--- a/src/widgets/spinbutton-events.cpp
+++ b/src/widgets/spinbutton-events.cpp
@@ -66,26 +66,25 @@ spinbutton_defocus (GtkWidget *container)
gboolean spinbutton_keypress(GtkWidget *w, GdkEventKey *event, gpointer data)
{
- SPWidget *spw = SP_WIDGET(data);
gdouble v;
gdouble step;
gdouble page;
switch (get_group0_keyval (event)) {
case GDK_KEY_Escape: // defocus
- spinbutton_undo (w);
- spinbutton_defocus(GTK_WIDGET(spw));
+ spinbutton_undo(w);
+ spinbutton_defocus(w);
return TRUE; // I consumed the event
break;
case GDK_KEY_Return: // defocus
case GDK_KEY_KP_Enter:
- spinbutton_defocus (GTK_WIDGET(spw));
+ spinbutton_defocus(w);
return TRUE; // I consumed the event
break;
case GDK_KEY_Tab:
case GDK_KEY_ISO_Left_Tab:
// set the flag meaning "do not leave toolbar when changing value"
- g_object_set_data (G_OBJECT (spw), "stay", GINT_TO_POINTER(TRUE));
+ g_object_set_data(G_OBJECT(w), "stay", GINT_TO_POINTER(TRUE));
return FALSE; // I didn't consume the event
break;
@@ -94,45 +93,45 @@ gboolean spinbutton_keypress(GtkWidget *w, GdkEventKey *event, gpointer data)
case GDK_KEY_Up:
case GDK_KEY_KP_Up:
- g_object_set_data (G_OBJECT (spw), "stay", GINT_TO_POINTER(TRUE));
- v = gtk_spin_button_get_value(GTK_SPIN_BUTTON (w));
- gtk_spin_button_get_increments(GTK_SPIN_BUTTON (w), &step, &page);
+ g_object_set_data(G_OBJECT(w), "stay", GINT_TO_POINTER(TRUE));
+ v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
+ gtk_spin_button_get_increments(GTK_SPIN_BUTTON(w), &step, &page);
v += step;
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), v);
return TRUE; // I consumed the event
break;
case GDK_KEY_Down:
case GDK_KEY_KP_Down:
- g_object_set_data (G_OBJECT (spw), "stay", GINT_TO_POINTER(TRUE));
- v = gtk_spin_button_get_value(GTK_SPIN_BUTTON (w));
- gtk_spin_button_get_increments(GTK_SPIN_BUTTON (w), &step, &page);
+ g_object_set_data(G_OBJECT(w), "stay", GINT_TO_POINTER(TRUE));
+ v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
+ gtk_spin_button_get_increments(GTK_SPIN_BUTTON(w), &step, &page);
v -= step;
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), v);
return TRUE; // I consumed the event
break;
case GDK_KEY_Page_Up:
case GDK_KEY_KP_Page_Up:
- g_object_set_data (G_OBJECT (spw), "stay", GINT_TO_POINTER(TRUE));
- v = gtk_spin_button_get_value(GTK_SPIN_BUTTON (w));
- gtk_spin_button_get_increments(GTK_SPIN_BUTTON (w), &step, &page);
+ g_object_set_data(G_OBJECT(w), "stay", GINT_TO_POINTER(TRUE));
+ v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
+ gtk_spin_button_get_increments(GTK_SPIN_BUTTON(w), &step, &page);
v += page;
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), v);
return TRUE; // I consumed the event
break;
case GDK_KEY_Page_Down:
case GDK_KEY_KP_Page_Down:
- g_object_set_data (G_OBJECT (spw), "stay", GINT_TO_POINTER(TRUE));
- v = gtk_spin_button_get_value(GTK_SPIN_BUTTON (w));
- gtk_spin_button_get_increments(GTK_SPIN_BUTTON (w), &step, &page);
+ g_object_set_data(G_OBJECT(w), "stay", GINT_TO_POINTER(TRUE));
+ v = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w));
+ gtk_spin_button_get_increments(GTK_SPIN_BUTTON(w), &step, &page);
v -= page;
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), v);
return TRUE; // I consumed the event
break;
case GDK_KEY_z:
case GDK_KEY_Z:
- g_object_set_data (G_OBJECT (spw), "stay", GINT_TO_POINTER(TRUE));
+ g_object_set_data(G_OBJECT(w), "stay", GINT_TO_POINTER(TRUE));
if (event->state & GDK_CONTROL_MASK) {
- spinbutton_undo (w);
+ spinbutton_undo(w);
return TRUE; // I consumed the event
}
break;
@@ -142,3 +141,14 @@ gboolean spinbutton_keypress(GtkWidget *w, GdkEventKey *event, gpointer data)
}
return FALSE; // I didn't consume the event
}
+
+/*
+ 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 :