From: gouldtj Date: Fri, 10 Aug 2007 17:38:51 +0000 (+0000) Subject: r16217@tres: ted | 2007-08-10 10:36:27 -0700 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=273e421813f295d65aab512f508e8fb575d997d4;p=inkscape.git r16217@tres: ted | 2007-08-10 10:36:27 -0700 ImageMagick effects patch from Chris Brown. Google Summer of Code project. --- diff --git a/configure.ac b/configure.ac index 47466a30a..b776663dc 100644 --- a/configure.ac +++ b/configure.ac @@ -560,6 +560,23 @@ AM_CONDITIONAL(WITH_INKBOARD, test "x$with_inkboard" = "xyes") AC_SUBST(INKBOARD_LIBS) AC_SUBST(INKBOARD_CFLAGS) +dnl ****************************** +dnl Check for ImageMagick Magick++ +dnl ****************************** + +AC_CHECK_LIB(Magick++, InitializeMagick, [AC_CHECK_HEADER(Magick++.h, magick_ok=yes, magick_ok=no)], magick_ok=no, -llcms -lfreetype -ljpeg -lfontconfig -lXext -lSM -lICE -lX11 -lz -lpthread -lm -lpthread) + +if test "x$magick_ok" = "xyes"; then + AC_CHECK_PROG(MAGICKPP_CONFIG, Magick++-config, yes, no) + if test "x$MAGICKPP_CONFIG" = "xyes"; then + IMAGEMAGICK_LIBS=`Magick++-config --libs` + AC_SUBST(IMAGEMAGICK_LIBS) + AC_DEFINE(WITH_IMAGE_MAGICK,1,[Image Magick++ support for bitmap effects]) + fi +fi + +AM_CONDITIONAL(USE_IMAGE_MAGICK, test "x$magick_ok" = "xyes") + dnl ****************************** dnl Unconditional dependencies dnl ****************************** @@ -927,4 +944,5 @@ Configuration: Enable LittleCms: ${enable_lcms} Enable Inkboard: ${with_inkboard} Enable SSL in Inkboard: ${with_inkboard_ssl} + ImageMagick Magick++: ${magick_ok} " diff --git a/po/POTFILES.in b/po/POTFILES.in index 26a9b616d..d3d40f4ea 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -68,33 +68,129 @@ src/event-context.cpp src/event-log.cpp src/extension/db.cpp src/extension/dependency.cpp +src/extension/dxf2svg/aci2rgb.cpp +src/extension/dxf2svg/blocks.cpp +src/extension/dxf2svg/dxf2svg.cpp +src/extension/dxf2svg/entities2elements.cpp +src/extension/dxf2svg/entities.cpp +src/extension/dxf2svg/read_dxf.cpp +src/extension/dxf2svg/tables2svg_info.cpp +src/extension/dxf2svg/tables.cpp +src/extension/dxf2svg/test_dxf.cpp src/extension/effect.cpp +src/extension/error-file.cpp src/extension/execution-env.cpp src/extension/extension.cpp -src/extension/error-file.cpp src/extension/implementation/implementation.cpp src/extension/implementation/script.cpp +src/extension/implementation/xslt.cpp src/extension/init.cpp +src/extension/input.cpp +src/extension/internal/bitmap/adaptiveThreshold.cpp +src/extension/internal/bitmap/addNoise.cpp +src/extension/internal/bitmap/blur.cpp +src/extension/internal/bitmap/channel.cpp +src/extension/internal/bitmap/charcoal.cpp +src/extension/internal/bitmap/colorize.cpp +src/extension/internal/bitmap/contrast.cpp +src/extension/internal/bitmap/convolve.cpp +src/extension/internal/bitmap/cycleColormap.cpp +src/extension/internal/bitmap/despeckle.cpp +src/extension/internal/bitmap/edge.cpp +src/extension/internal/bitmap/emboss.cpp +src/extension/internal/bitmap/enhance.cpp +src/extension/internal/bitmap/equalize.cpp +src/extension/internal/bitmap/flop.cpp +src/extension/internal/bitmap/gaussianBlur.cpp +src/extension/internal/bitmap/imagemagick.cpp +src/extension/internal/bitmap/implode.cpp +src/extension/internal/bitmap/levelChannel.cpp +src/extension/internal/bitmap/level.cpp +src/extension/internal/bitmap/medianFilter.cpp +src/extension/internal/bitmap/modulate.cpp +src/extension/internal/bitmap/negate.cpp +src/extension/internal/bitmap/normalize.cpp +src/extension/internal/bitmap/oilPaint.cpp +src/extension/internal/bitmap/opacity.cpp +src/extension/internal/bitmap/raise.cpp +src/extension/internal/bitmap/reduceNoise.cpp +src/extension/internal/bitmap/shade.cpp +src/extension/internal/bitmap/sharpen.cpp +src/extension/internal/bitmap/solarize.cpp +src/extension/internal/bitmap/spread.cpp +src/extension/internal/bitmap/swirl.cpp +src/extension/internal/bitmap/threshold.cpp +src/extension/internal/bitmap/unsharpmask.cpp +src/extension/internal/bitmap/wave.cpp src/extension/internal/bluredge.cpp -src/extension/internal/eps-out.cpp +src/extension/internal/cairo-pdf-out.cpp +src/extension/internal/cairo-png-out.cpp +src/extension/internal/cairo-ps-out.cpp +src/extension/internal/cairo-render-context.cpp +src/extension/internal/cairo-renderer.cpp +src/extension/internal/cairo-renderer-pdf-out.cpp src/extension/internal/emf-win32-inout.cpp +src/extension/internal/emf-win32-print.cpp +src/extension/internal/eps-out.cpp src/extension/internal/gdkpixbuf-input.cpp src/extension/internal/gimpgrad.cpp src/extension/internal/gnome.cpp src/extension/internal/grid.cpp -src/extension/internal/latex-pstricks-out.cpp src/extension/internal/latex-pstricks.cpp +src/extension/internal/latex-pstricks-out.cpp +src/extension/internal/libwpg/WPG1Parser.cpp +src/extension/internal/libwpg/WPG2Parser.cpp +src/extension/internal/libwpg/WPGBrush.cpp +src/extension/internal/libwpg/WPGColor.cpp +src/extension/internal/libwpg/WPGGradient.cpp +src/extension/internal/libwpg/WPGHeader.cpp +src/extension/internal/libwpg/WPGOLEStream.cpp +src/extension/internal/libwpg/WPGPath.cpp +src/extension/internal/libwpg/WPGPen.cpp +src/extension/internal/libwpg/WPGPoint.cpp +src/extension/internal/libwpg/WPGraphics.cpp +src/extension/internal/libwpg/WPGRect.cpp +src/extension/internal/libwpg/WPGStreamImplementation.cpp +src/extension/internal/libwpg/WPGString.cpp +src/extension/internal/libwpg/WPGSVGGenerator.cpp +src/extension/internal/libwpg/WPGXParser.cpp src/extension/internal/odf.cpp src/extension/internal/pdf-cairo.cpp +src/extension/internal/pdf-input-cairo.cpp +src/extension/internal/pdfinput/pdf-input.cpp +src/extension/internal/pdfinput/pdf-parser.cpp +src/extension/internal/pdfinput/svg-builder.cpp src/extension/internal/pov-out.cpp -src/extension/internal/ps-out.cpp src/extension/internal/ps.cpp +src/extension/internal/ps-out.cpp src/extension/internal/svg.cpp src/extension/internal/svgz.cpp src/extension/internal/win32.cpp src/extension/internal/wpg-input.cpp +src/extension/output.cpp +src/extension/parambool.cpp +src/extension/paramcolor.cpp +src/extension/paramdescription.cpp +src/extension/paramenum.cpp +src/extension/parameter.cpp +src/extension/paramfloat.cpp +src/extension/paramint.cpp +src/extension/paramnotebook.cpp +src/extension/paramradiobutton.cpp +src/extension/paramstring.cpp +src/extension/patheffect.cpp src/extension/prefdialog.cpp +src/extension/print.cpp +src/extension/script/bindtest.cpp +src/extension/script/cpptest.cpp +src/extension/script/InkscapeBinding.cpp +src/extension/script/InkscapeInterpreter.cpp +src/extension/script/InkscapePerl.cpp +src/extension/script/inkscape_perl_wrap.cpp +src/extension/script/InkscapePython.cpp +src/extension/script/InkscapeScript.cpp src/extension/system.cpp +src/extension/timer.cpp src/extract-uri.cpp src/file.cpp src/fixes.cpp diff --git a/src/Makefile_insert b/src/Makefile_insert index 946e3b1ff..89fa9cb11 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -365,7 +365,8 @@ all_libs = \ $(win32ldflags) \ $(PERL_LIBS) \ $(PYTHON_LIBS) \ - $(INKBOARD_LIBS) + $(INKBOARD_LIBS) \ + $(IMAGEMAGICK_LIBS) desktop.$(OBJEXT): helper/sp-marshal.h document.$(OBJEXT): helper/sp-marshal.h inkscape_version.h diff --git a/src/extension/Makefile_insert b/src/extension/Makefile_insert index 3df936cd9..9c6cdd61f 100644 --- a/src/extension/Makefile_insert +++ b/src/extension/Makefile_insert @@ -23,10 +23,22 @@ extension_libextension_a_SOURCES = \ extension/parameter.cpp \ extension/paramnotebook.h \ extension/paramnotebook.cpp \ + extension/parambool.h \ + extension/parambool.cpp \ + extension/paramcolor.h \ + extension/paramcolor.cpp \ + extension/paramdescription.h \ + extension/paramdescription.cpp \ extension/paramenum.h \ extension/paramenum.cpp \ + extension/paramfloat.h \ + extension/paramfloat.cpp \ + extension/paramint.h \ + extension/paramint.cpp \ extension/paramradiobutton.h \ extension/paramradiobutton.cpp \ + extension/paramstring.h \ + extension/paramstring.cpp \ extension/prefdialog.cpp \ extension/prefdialog.h \ extension/system.cpp \ diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 5082ba08e..b56a1d6f2 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -428,6 +428,13 @@ Extension::get_param_string (const gchar * name, const SPDocument * doc, const I return param->get_string(doc, node); } +const gchar * +Extension::get_param_enum (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) +{ + Parameter* param = param_shared(name, parameters); + return param->get_enum(doc, node); +} + /** \return The value of the parameter identified by the name \brief Gets a parameter identified by name with the bool placed @@ -487,6 +494,24 @@ Extension::get_param_float (const gchar * name, const SPDocument * doc, const In return param->get_float(doc, node); } +/** + \return The string value for the parameter specified + \brief Gets a parameter identified by name with the float placed + in value. + \param name The name of the parameter to get + \param doc The document to look in for document specific parameters + \param node The node to look in for a specific parameter + + Look up in the parameters list, then execute the function on that + found parameter. +*/ +SPColor* +Extension::get_param_color (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) +{ + Parameter* param = param_shared(name, parameters); + return param->get_color(doc, node); +} + /** \return The passed in value \brief Sets a parameter identified by name with the boolean @@ -567,6 +592,25 @@ Extension::set_param_string (const gchar * name, const gchar * value, SPDocument return param->set_string(value, doc, node); } +/** + \return The passed in value + \brief Sets a parameter identified by name with the string + in the parameter value. + \param name The name of the parameter to set + \param value The value to set the parameter to + \param doc The document to look in for document specific parameters + \param node The node to look in for a specific parameter + + Look up in the parameters list, then execute the function on that + found parameter. +*/ +SPColor* +Extension::set_param_color (const gchar * name, SPColor* color, SPDocument * doc, Inkscape::XML::Node * node) +{ + Parameter* param = param_shared(name, parameters); + return param->set_color(color, doc, node); +} + /** \brief A function to open the error log file. */ void Extension::error_file_open (void) diff --git a/src/extension/extension.h b/src/extension/extension.h index a1993f941..967dda2cf 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -131,6 +131,12 @@ private: public: /** An error class for when a parameter is called on a type it is not */ class param_wrong_type {}; + class param_not_color_param {}; + class param_not_enum_param {}; + class param_not_string_param {}; + class param_not_float_param {}; + class param_not_int_param {}; + class param_not_bool_param {}; /** An error class for when a parameter is looked for that just * simply doesn't exist */ @@ -159,6 +165,12 @@ public: const gchar * get_param_string (const gchar * name, const SPDocument * doc = NULL, const Inkscape::XML::Node * node = NULL); + SPColor* get_param_color (const gchar * name, + const SPDocument * doc = NULL, + const Inkscape::XML::Node * node = NULL); + const gchar * get_param_enum (const gchar * name, + const SPDocument * doc = NULL, + const Inkscape::XML::Node * node = NULL); bool set_param_bool (const gchar * name, bool value, SPDocument * doc = NULL, @@ -175,6 +187,10 @@ public: const gchar * value, SPDocument * doc = NULL, Inkscape::XML::Node * node = NULL); + SPColor* set_param_color (const gchar * name, + SPColor* color, + SPDocument * doc = NULL, + Inkscape::XML::Node * node = NULL); /* Error file handling */ public: diff --git a/src/extension/init.cpp b/src/extension/init.cpp index 239a5bb26..fca5a7e5d 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -62,6 +62,44 @@ #include "prefs-utils.h" #include "io/sys.h" +#ifdef WITH_IMAGE_MAGICK +#include "internal/bitmap/adaptiveThreshold.h" +#include "internal/bitmap/addNoise.h" +#include "internal/bitmap/blur.h" +#include "internal/bitmap/channel.h" +#include "internal/bitmap/charcoal.h" +#include "internal/bitmap/colorize.h" +#include "internal/bitmap/contrast.h" +#include "internal/bitmap/convolve.h" +#include "internal/bitmap/cycleColormap.h" +#include "internal/bitmap/despeckle.h" +#include "internal/bitmap/edge.h" +#include "internal/bitmap/emboss.h" +#include "internal/bitmap/enhance.h" +#include "internal/bitmap/equalize.h" +#include "internal/bitmap/flop.h" +#include "internal/bitmap/gaussianBlur.h" +#include "internal/bitmap/implode.h" +#include "internal/bitmap/level.h" +#include "internal/bitmap/levelChannel.h" +#include "internal/bitmap/medianFilter.h" +#include "internal/bitmap/modulate.h" +#include "internal/bitmap/negate.h" +#include "internal/bitmap/normalize.h" +#include "internal/bitmap/oilPaint.h" +#include "internal/bitmap/opacity.h" +#include "internal/bitmap/raise.h" +#include "internal/bitmap/reduceNoise.h" +#include "internal/bitmap/shade.h" +#include "internal/bitmap/sharpen.h" +#include "internal/bitmap/solarize.h" +#include "internal/bitmap/spread.h" +#include "internal/bitmap/swirl.h" +#include "internal/bitmap/threshold.h" +#include "internal/bitmap/unsharpmask.h" +#include "internal/bitmap/wave.h" +#endif /* WITH_IMAGE_MAGICK */ + extern gboolean inkscape_app_use_gui( Inkscape::Application const *app ); namespace Inkscape { @@ -156,6 +194,45 @@ init() Internal::BlurEdge::init(); Internal::GimpGrad::init(); Internal::Grid::init(); + + /* Raster Effects */ +#ifdef WITH_IMAGE_MAGICK + Internal::Bitmap::AdaptiveThreshold::init(); + Internal::Bitmap::AddNoise::init(); + Internal::Bitmap::Blur::init(); + Internal::Bitmap::Channel::init(); + Internal::Bitmap::Charcoal::init(); + Internal::Bitmap::Colorize::init(); + Internal::Bitmap::Contrast::init(); + Internal::Bitmap::Convolve::init(); + Internal::Bitmap::CycleColormap::init(); + Internal::Bitmap::Edge::init(); + Internal::Bitmap::Despeckle::init(); + Internal::Bitmap::Emboss::init(); + Internal::Bitmap::Enhance::init(); + Internal::Bitmap::Equalize::init(); + Internal::Bitmap::Flop::init(); + Internal::Bitmap::GaussianBlur::init(); + Internal::Bitmap::Implode::init(); + Internal::Bitmap::Level::init(); + Internal::Bitmap::LevelChannel::init(); + Internal::Bitmap::MedianFilter::init(); + Internal::Bitmap::Modulate::init(); + Internal::Bitmap::Negate::init(); + Internal::Bitmap::Normalize::init(); + Internal::Bitmap::OilPaint::init(); + Internal::Bitmap::Opacity::init(); + Internal::Bitmap::Raise::init(); + Internal::Bitmap::ReduceNoise::init(); + Internal::Bitmap::Shade::init(); + Internal::Bitmap::Sharpen::init(); + Internal::Bitmap::Solarize::init(); + Internal::Bitmap::Spread::init(); + Internal::Bitmap::Swirl::init(); + Internal::Bitmap::Threshold::init(); + Internal::Bitmap::Unsharpmask::init(); + Internal::Bitmap::Wave::init(); +#endif /* WITH_IMAGE_MAGICK */ /* Load search path for extensions */ if (Inkscape::Extension::Extension::search_path.size() == 0) diff --git a/src/extension/internal/Makefile_insert b/src/extension/internal/Makefile_insert index f615e02fd..418498efd 100644 --- a/src/extension/internal/Makefile_insert +++ b/src/extension/internal/Makefile_insert @@ -11,6 +11,82 @@ extension_internal_gnome_print_sources = \ extension/internal/gnome.h endif +if USE_IMAGE_MAGICK +extension_internal_image_magick_sources = \ + extension/internal/bitmap/imagemagick.cpp \ + extension/internal/bitmap/imagemagick.h \ + extension/internal/bitmap/adaptiveThreshold.cpp \ + extension/internal/bitmap/adaptiveThreshold.h \ + extension/internal/bitmap/addNoise.cpp \ + extension/internal/bitmap/addNoise.h \ + extension/internal/bitmap/blur.cpp \ + extension/internal/bitmap/blur.h \ + extension/internal/bitmap/channel.cpp \ + extension/internal/bitmap/channel.h \ + extension/internal/bitmap/charcoal.cpp \ + extension/internal/bitmap/charcoal.h \ + extension/internal/bitmap/colorize.cpp \ + extension/internal/bitmap/colorize.h \ + extension/internal/bitmap/contrast.cpp \ + extension/internal/bitmap/contrast.h \ + extension/internal/bitmap/convolve.cpp \ + extension/internal/bitmap/convolve.h \ + extension/internal/bitmap/cycleColormap.cpp \ + extension/internal/bitmap/cycleColormap.h \ + extension/internal/bitmap/despeckle.cpp \ + extension/internal/bitmap/despeckle.h \ + extension/internal/bitmap/edge.cpp \ + extension/internal/bitmap/edge.h \ + extension/internal/bitmap/emboss.cpp \ + extension/internal/bitmap/emboss.h \ + extension/internal/bitmap/enhance.cpp \ + extension/internal/bitmap/enhance.h \ + extension/internal/bitmap/equalize.cpp \ + extension/internal/bitmap/equalize.h \ + extension/internal/bitmap/flop.cpp \ + extension/internal/bitmap/flop.h \ + extension/internal/bitmap/gaussianBlur.cpp \ + extension/internal/bitmap/gaussianBlur.h \ + extension/internal/bitmap/implode.cpp \ + extension/internal/bitmap/implode.h \ + extension/internal/bitmap/level.cpp \ + extension/internal/bitmap/level.h \ + extension/internal/bitmap/levelChannel.cpp \ + extension/internal/bitmap/levelChannel.h \ + extension/internal/bitmap/medianFilter.cpp \ + extension/internal/bitmap/medianFilter.h \ + extension/internal/bitmap/modulate.cpp \ + extension/internal/bitmap/modulate.h \ + extension/internal/bitmap/negate.cpp \ + extension/internal/bitmap/negate.h \ + extension/internal/bitmap/normalize.cpp \ + extension/internal/bitmap/normalize.h \ + extension/internal/bitmap/oilPaint.cpp \ + extension/internal/bitmap/oilPaint.h \ + extension/internal/bitmap/opacity.cpp \ + extension/internal/bitmap/opacity.h \ + extension/internal/bitmap/raise.cpp \ + extension/internal/bitmap/raise.h \ + extension/internal/bitmap/reduceNoise.cpp \ + extension/internal/bitmap/reduceNoise.h \ + extension/internal/bitmap/shade.cpp \ + extension/internal/bitmap/shade.h \ + extension/internal/bitmap/sharpen.cpp \ + extension/internal/bitmap/sharpen.h \ + extension/internal/bitmap/solarize.cpp \ + extension/internal/bitmap/solarize.h \ + extension/internal/bitmap/spread.cpp \ + extension/internal/bitmap/spread.h \ + extension/internal/bitmap/swirl.cpp \ + extension/internal/bitmap/swirl.h \ + extension/internal/bitmap/threshold.cpp \ + extension/internal/bitmap/threshold.h \ + extension/internal/bitmap/unsharpmask.cpp \ + extension/internal/bitmap/unsharpmask.h \ + extension/internal/bitmap/wave.cpp \ + extension/internal/bitmap/wave.h +endif + extension_internal_libinternal_a_SOURCES = \ extension/internal/bluredge.h \ extension/internal/bluredge.cpp \ @@ -63,4 +139,6 @@ extension_internal_libinternal_a_SOURCES = \ extension/internal/latex-pstricks-out.h \ extension/internal/wpg-input.cpp \ extension/internal/wpg-input.h \ - $(extension_internal_gnome_print_sources) + $(extension_internal_gnome_print_sources) \ + $(extension_internal_image_magick_sources) + diff --git a/src/extension/internal/bitmap/adaptiveThreshold.cpp b/src/extension/internal/bitmap/adaptiveThreshold.cpp new file mode 100644 index 000000000..5a2db5dc0 --- /dev/null +++ b/src/extension/internal/bitmap/adaptiveThreshold.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "adaptiveThreshold.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +AdaptiveThreshold::applyEffect(Magick::Image *image) { + image->adaptiveThreshold(_width, _height); +} + +void +AdaptiveThreshold::refreshParameters(Inkscape::Extension::Effect *module) { + _width = module->get_param_int("width"); + _height = module->get_param_int("height"); +} + +#include "../clear-n_.h" + +void +AdaptiveThreshold::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Adaptive Threshold") "\n" + "org.inkscape.effect.bitmap.adaptiveThreshold\n" + "5\n" + "1\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Adaptive Threshold Effect") "\n" + "\n" + "\n", new AdaptiveThreshold()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/adaptiveThreshold.h b/src/extension/internal/bitmap/adaptiveThreshold.h new file mode 100644 index 000000000..e7b5e753f --- /dev/null +++ b/src/extension/internal/bitmap/adaptiveThreshold.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class AdaptiveThreshold : public ImageMagick +{ +private: + int _width; + int _height; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/addNoise.cpp b/src/extension/internal/bitmap/addNoise.cpp new file mode 100644 index 000000000..11e3835cf --- /dev/null +++ b/src/extension/internal/bitmap/addNoise.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "addNoise.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +AddNoise::applyEffect(Magick::Image *image) { + Magick::NoiseType noiseType = Magick::UniformNoise; + if (!strcmp(_noiseTypeName, "Uniform Noise")) noiseType = Magick::UniformNoise; + else if (!strcmp(_noiseTypeName, "Gaussian Noise")) noiseType = Magick::GaussianNoise; + else if (!strcmp(_noiseTypeName, "Multiplicative Gaussian Noise")) noiseType = Magick::MultiplicativeGaussianNoise; + else if (!strcmp(_noiseTypeName, "Impulse Noise")) noiseType = Magick::ImpulseNoise; + else if (!strcmp(_noiseTypeName, "Laplacian Noise")) noiseType = Magick::LaplacianNoise; + else if (!strcmp(_noiseTypeName, "Poisson Noise")) noiseType = Magick::PoissonNoise; + + image->addNoise(noiseType); +} + +void +AddNoise::refreshParameters(Inkscape::Extension::Effect *module) { + _noiseTypeName = module->get_param_enum("noiseType"); +} + +#include "../clear-n_.h" + +void +AddNoise::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Add Noise") "\n" + "org.inkscape.effect.bitmap.addNoise\n" + "\n" + "Uniform Noise\n" + "Gaussian Noise\n" + "Multiplicative Gaussian Noise\n" + "Impulse Noise\n" + "Laplacian Noise\n" + "Poisson Noise\n" + "\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Add Noise Effect") "\n" + "\n" + "\n", new AddNoise()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/addNoise.h b/src/extension/internal/bitmap/addNoise.h new file mode 100644 index 000000000..b1ac6a9f5 --- /dev/null +++ b/src/extension/internal/bitmap/addNoise.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class AddNoise : public ImageMagick +{ +private: + const gchar* _noiseTypeName; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/blur.cpp b/src/extension/internal/bitmap/blur.cpp new file mode 100644 index 000000000..ad2b5a837 --- /dev/null +++ b/src/extension/internal/bitmap/blur.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "blur.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Blur::applyEffect(Magick::Image *image) { + image->blur(_radius, _sigma); +} + +void +Blur::refreshParameters(Inkscape::Extension::Effect *module) { + _radius = module->get_param_float("radius"); + _sigma = module->get_param_float("sigma"); +} + +#include "../clear-n_.h" + +void +Blur::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Blur") "\n" + "org.inkscape.effect.bitmap.blur\n" + "5.0\n" + "1.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Blur Effect") "\n" + "\n" + "\n", new Blur()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/blur.h b/src/extension/internal/bitmap/blur.h new file mode 100644 index 000000000..be58ba5ba --- /dev/null +++ b/src/extension/internal/bitmap/blur.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Blur : public ImageMagick +{ +private: + float _radius; + float _sigma; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/channel.cpp b/src/extension/internal/bitmap/channel.cpp new file mode 100644 index 000000000..708638371 --- /dev/null +++ b/src/extension/internal/bitmap/channel.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "channel.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Channel::applyEffect(Magick::Image *image) { + Magick::ChannelType layer = Magick::UndefinedChannel; + if (!strcmp(_layerName, "Red Channel")) layer = Magick::RedChannel; + else if (!strcmp(_layerName, "Green Channel")) layer = Magick::GreenChannel; + else if (!strcmp(_layerName, "Blue Channel")) layer = Magick::BlueChannel; + else if (!strcmp(_layerName, "Cyan Channel")) layer = Magick::CyanChannel; + else if (!strcmp(_layerName, "Magenta Channel")) layer = Magick::MagentaChannel; + else if (!strcmp(_layerName, "Yellow Channel")) layer = Magick::YellowChannel; + else if (!strcmp(_layerName, "Black Channel")) layer = Magick::BlackChannel; + else if (!strcmp(_layerName, "Opacity Channel")) layer = Magick::OpacityChannel; + else if (!strcmp(_layerName, "Matte Channel")) layer = Magick::MatteChannel; + + image->channel(layer); +} + +void +Channel::refreshParameters(Inkscape::Extension::Effect *module) { + _layerName = module->get_param_enum("layer"); +} + +#include "../clear-n_.h" + +void +Channel::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Channel") "\n" + "org.inkscape.effect.bitmap.channel\n" + "\n" + "Red Channel\n" + "Green Channel\n" + "Blue Channel\n" + "Cyan Channel\n" + "Magenta Channel\n" + "Yellow Channel\n" + "Black Channel\n" + "Opacity Channel\n" + "Matte Channel\n" + "\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Channel Effect") "\n" + "\n" + "\n", new Channel()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/channel.h b/src/extension/internal/bitmap/channel.h new file mode 100644 index 000000000..898d3af46 --- /dev/null +++ b/src/extension/internal/bitmap/channel.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Channel : public ImageMagick { + +private: + const gchar * _layerName; + +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/charcoal.cpp b/src/extension/internal/bitmap/charcoal.cpp new file mode 100644 index 000000000..6f3244b8d --- /dev/null +++ b/src/extension/internal/bitmap/charcoal.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "charcoal.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Charcoal::applyEffect(Magick::Image* image) { + image->charcoal(_radius, _sigma); +} + +void +Charcoal::refreshParameters(Inkscape::Extension::Effect* module) { + _radius = module->get_param_float("radius"); + _sigma = module->get_param_float("sigma"); +} + +#include "../clear-n_.h" + +void +Charcoal::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Charcoal") "\n" + "org.inkscape.effect.bitmap.charcoal\n" + "5.0\n" + "1.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Charcoal Effect") "\n" + "\n" + "\n", new Charcoal()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/charcoal.h b/src/extension/internal/bitmap/charcoal.h new file mode 100644 index 000000000..2bedba76e --- /dev/null +++ b/src/extension/internal/bitmap/charcoal.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Charcoal : public ImageMagick +{ +private: + float _radius; + float _sigma; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/colorize.cpp b/src/extension/internal/bitmap/colorize.cpp new file mode 100644 index 000000000..cf8ff5dd3 --- /dev/null +++ b/src/extension/internal/bitmap/colorize.cpp @@ -0,0 +1,76 @@ +/* + * Authors: + * Christopher Brown + * Ted Gould + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "colorize.h" + +#include "color.h" + +#include + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Colorize::applyEffect(Magick::Image *image) { + float rgb[3]; + sp_color_get_rgb_floatv(_color, rgb); + int red = (int)(rgb[0] * 255); + int green = (int)(rgb[1] * 255); + int blue = (int)(rgb[2] * 255); + + + printf("(2fk) applying colorize\n"); + printf("(2fl) rgb: %i,%i,%i\n", red, green, blue); + printf("(2fm) opacity: %i\n", _opacity); + + Magick::ColorRGB mc(red, green, blue); + + image->colorize(_opacity, mc); +} + +void +Colorize::refreshParameters(Inkscape::Extension::Effect *module) { + _opacity = module->get_param_int("opacity"); + _color = module->get_param_color("color"); + + printf("(2ga) refreshing colorize\n"); + printf("(2gb) _color: %f,%f,%f,%f\n", _color->v.c[0], _color->v.c[1], _color->v.c[2], _color->v.c[3]); +} + +#include "../clear-n_.h" + +void +Colorize::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Colorize") "\n" + "org.inkscape.effect.bitmap.colorize\n" + "#FF0000\n" + "1\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Colorize Effect") "\n" + "\n" + "\n", new Colorize()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/colorize.h b/src/extension/internal/bitmap/colorize.h new file mode 100644 index 000000000..e82ef88a4 --- /dev/null +++ b/src/extension/internal/bitmap/colorize.h @@ -0,0 +1,33 @@ +/* + * Authors: + * Christopher Brown + * Ted Gould + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Colorize : public ImageMagick { +private: + SPColor* _color; + int _opacity; + +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/contrast.cpp b/src/extension/internal/bitmap/contrast.cpp new file mode 100644 index 000000000..1728c325f --- /dev/null +++ b/src/extension/internal/bitmap/contrast.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "contrast.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Contrast::applyEffect(Magick::Image *image) { + printf("(o0x) Sharpening at: %i\n", _sharpen); + image->contrast(_sharpen); +} + +void +Contrast::refreshParameters(Inkscape::Extension::Effect *module) { + _sharpen = module->get_param_bool("sharpen"); +} + +#include "../clear-n_.h" + +void +Contrast::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Contrast") "\n" + "org.inkscape.effect.bitmap.contrast\n" + "1\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Contrast Effect") "\n" + "\n" + "\n", new Contrast()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/contrast.h b/src/extension/internal/bitmap/contrast.h new file mode 100644 index 000000000..acb5982a3 --- /dev/null +++ b/src/extension/internal/bitmap/contrast.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Contrast : public ImageMagick +{ +private: + bool _sharpen; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/convolve.cpp b/src/extension/internal/bitmap/convolve.cpp new file mode 100644 index 000000000..008cd4390 --- /dev/null +++ b/src/extension/internal/bitmap/convolve.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "convolve.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Convolve::applyEffect(Magick::Image *image) { + image->convolve(_order, _kernel); +} + +void +Convolve::refreshParameters(Inkscape::Extension::Effect *module) { + _order = module->get_param_int("order"); + *_kernel = 0; +} + +#include "../clear-n_.h" + +void +Convolve::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Convolve") "\n" + "org.inkscape.effect.bitmap.convolve\n" + "1\n" + "1,1,1,0,0,0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Convolve Effect") "\n" + "\n" + "\n", new Convolve()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/convolve.h b/src/extension/internal/bitmap/convolve.h new file mode 100644 index 000000000..3cfdc7fd3 --- /dev/null +++ b/src/extension/internal/bitmap/convolve.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Convolve : public ImageMagick { +private: + int _order; + double* _kernel; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/cycleColormap.cpp b/src/extension/internal/bitmap/cycleColormap.cpp new file mode 100644 index 000000000..309837abe --- /dev/null +++ b/src/extension/internal/bitmap/cycleColormap.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "cycleColormap.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +CycleColormap::applyEffect(Magick::Image *image) { + image->cycleColormap(_amount); +} + +void +CycleColormap::refreshParameters(Inkscape::Extension::Effect *module) { + _amount = module->get_param_int("amount"); +} + +#include "../clear-n_.h" + +void +CycleColormap::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Cycle Colormap") "\n" + "org.inkscape.effect.bitmap.cycleColormap\n" + "1\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Cycle Colormap Effect") "\n" + "\n" + "\n", new CycleColormap()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/cycleColormap.h b/src/extension/internal/bitmap/cycleColormap.h new file mode 100644 index 000000000..7d8f49504 --- /dev/null +++ b/src/extension/internal/bitmap/cycleColormap.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class CycleColormap : public ImageMagick { +private: + int _amount; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/despeckle.cpp b/src/extension/internal/bitmap/despeckle.cpp new file mode 100644 index 000000000..75a1ca35a --- /dev/null +++ b/src/extension/internal/bitmap/despeckle.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "despeckle.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Despeckle::applyEffect(Magick::Image *image) { + image->despeckle(); +} + +void +Despeckle::refreshParameters(Inkscape::Extension::Effect *module) { + +} + +#include "../clear-n_.h" + +void +Despeckle::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Despeckle") "\n" + "org.inkscape.effect.bitmap.despeckle\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Despeckle Effect") "\n" + "\n" + "\n", new Despeckle()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/despeckle.h b/src/extension/internal/bitmap/despeckle.h new file mode 100644 index 000000000..7a9be90a3 --- /dev/null +++ b/src/extension/internal/bitmap/despeckle.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Despeckle : public ImageMagick { +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/edge.cpp b/src/extension/internal/bitmap/edge.cpp new file mode 100644 index 000000000..f9b14b246 --- /dev/null +++ b/src/extension/internal/bitmap/edge.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "edge.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Edge::applyEffect(Magick::Image *image) { + image->edge(_radius); +} + +void +Edge::refreshParameters(Inkscape::Extension::Effect *module) { + _radius = module->get_param_int("radius"); +} + +#include "../clear-n_.h" + +void +Edge::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Edge") "\n" + "org.inkscape.effect.bitmap.edge\n" + "5\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Edge Effect") "\n" + "\n" + "\n", new Edge()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/edge.h b/src/extension/internal/bitmap/edge.h new file mode 100644 index 000000000..4585648f2 --- /dev/null +++ b/src/extension/internal/bitmap/edge.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Edge : public ImageMagick { +private: + int _radius; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/emboss.cpp b/src/extension/internal/bitmap/emboss.cpp new file mode 100644 index 000000000..8d7f72459 --- /dev/null +++ b/src/extension/internal/bitmap/emboss.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "emboss.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Emboss::applyEffect(Magick::Image *image) { + image->emboss(_radius, _sigma); +} + +void +Emboss::refreshParameters(Inkscape::Extension::Effect *module) { + _radius = module->get_param_float("radius"); + _sigma = module->get_param_float("sigma"); +} + +#include "../clear-n_.h" + +void +Emboss::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Emboss") "\n" + "org.inkscape.effect.bitmap.emboss\n" + "5.0\n" + "1.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Emboss Effect") "\n" + "\n" + "\n", new Emboss()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/emboss.h b/src/extension/internal/bitmap/emboss.h new file mode 100644 index 000000000..4dcfc89d4 --- /dev/null +++ b/src/extension/internal/bitmap/emboss.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Emboss : public ImageMagick +{ +private: + float _radius; + float _sigma; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/enhance.cpp b/src/extension/internal/bitmap/enhance.cpp new file mode 100644 index 000000000..dae90776b --- /dev/null +++ b/src/extension/internal/bitmap/enhance.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "enhance.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Enhance::applyEffect(Magick::Image *image) { + image->enhance(); +} + +void +Enhance::refreshParameters(Inkscape::Extension::Effect *module) { + +} + +#include "../clear-n_.h" + +void +Enhance::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Enhance") "\n" + "org.inkscape.effect.bitmap.enhance\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Enhance Effect") "\n" + "\n" + "\n", new Enhance()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/enhance.h b/src/extension/internal/bitmap/enhance.h new file mode 100644 index 000000000..3f5df47f6 --- /dev/null +++ b/src/extension/internal/bitmap/enhance.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Enhance : public ImageMagick +{ +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/equalize.cpp b/src/extension/internal/bitmap/equalize.cpp new file mode 100644 index 000000000..1b0911ac3 --- /dev/null +++ b/src/extension/internal/bitmap/equalize.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "equalize.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Equalize::applyEffect(Magick::Image *image) { + image->equalize(); +} + +void +Equalize::refreshParameters(Inkscape::Extension::Effect *module) { + +} + +#include "../clear-n_.h" + +void +Equalize::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Equalize") "\n" + "org.inkscape.effect.bitmap.equalize\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Equalize Effect") "\n" + "\n" + "\n", new Equalize()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/equalize.h b/src/extension/internal/bitmap/equalize.h new file mode 100644 index 000000000..22cadf554 --- /dev/null +++ b/src/extension/internal/bitmap/equalize.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Equalize : public ImageMagick +{ +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/flop.cpp b/src/extension/internal/bitmap/flop.cpp new file mode 100644 index 000000000..437c8afbd --- /dev/null +++ b/src/extension/internal/bitmap/flop.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "flop.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Flop::applyEffect(Magick::Image *image) { + image->flop(); +} + +void +Flop::refreshParameters(Inkscape::Extension::Effect *module) { + +} + +#include "../clear-n_.h" + +void +Flop::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Flop") "\n" + "org.inkscape.effect.bitmap.flop\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Flop Effect") "\n" + "\n" + "\n", new Flop()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/flop.h b/src/extension/internal/bitmap/flop.h new file mode 100644 index 000000000..d996396ea --- /dev/null +++ b/src/extension/internal/bitmap/flop.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Flop : public ImageMagick +{ +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init (void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/gaussianBlur.cpp b/src/extension/internal/bitmap/gaussianBlur.cpp new file mode 100644 index 000000000..36087c525 --- /dev/null +++ b/src/extension/internal/bitmap/gaussianBlur.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "gaussianBlur.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +GaussianBlur::applyEffect(Magick::Image* image) { + image->gaussianBlur(_width, _sigma); +} + +void +GaussianBlur::refreshParameters(Inkscape::Extension::Effect* module) { + _width = module->get_param_float("width"); + _sigma = module->get_param_float("sigma"); +} + +#include "../clear-n_.h" + +void +GaussianBlur::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Gaussian Blur") "\n" + "org.inkscape.effect.bitmap.gaussianBlur\n" + "5.0\n" + "5.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Gaussian Blur Effect") "\n" + "\n" + "\n", new GaussianBlur()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/gaussianBlur.h b/src/extension/internal/bitmap/gaussianBlur.h new file mode 100644 index 000000000..3b6ca2137 --- /dev/null +++ b/src/extension/internal/bitmap/gaussianBlur.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class GaussianBlur : public ImageMagick +{ +private: + float _width; + float _sigma; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp new file mode 100644 index 000000000..83650aaa7 --- /dev/null +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -0,0 +1,175 @@ +/* + * Authors: + * Christopher Brown + * Ted Gould + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include + +#include + +#include "desktop.h" +#include "desktop-handles.h" +#include "selection.h" +#include "sp-object.h" +#include "util/glib-list-iterators.h" + +#include "extension/effect.h" +#include "extension/system.h" + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +bool +ImageMagick::load(Inkscape::Extension::Extension *module) +{ + _loaded = FALSE; + return TRUE; +} + +void +ImageMagick::commitDocument(void) { + _loaded = FALSE; +} + +void +ImageMagick::cancelDocument(void) { + for (int i = 0; i < _imageCount; i++) { + _nodes[i]->setAttribute("xlink:href", _originals[i], true); + } + + _loaded = FALSE; +} + +void +ImageMagick::readImage(const char *xlink, Magick::Image *image) +{ + // Find if the xlink:href is base64 data, i.e. if the image is embedded + char *search = strndup(xlink, 30); + if (strstr(search, "base64") != (char*)NULL) { + // 7 = strlen("base64") + strlen(",") + char* pureBase64 = strstr(xlink, "base64") + 7; + Magick::Blob blob; + blob.base64(pureBase64); + image->read(blob); + } + else { + image->read(xlink); + } +} + +void +ImageMagick::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document) +{ + refreshParameters(module); + + if (!_loaded) + { + SPDesktop *desktop = (SPDesktop*)document; + const GSList *selectedReprList = desktop->selection->reprList(); + int selectCount = g_slist_length((GSList *)selectedReprList); + + // Init the data-holders + _nodes = new Inkscape::XML::Node*[selectCount]; + _originals = new const char*[selectCount]; + _images = new Magick::Image[selectCount]; + _imageCount = 0; + + // Loop through selected nodes + for (; selectedReprList != NULL; selectedReprList = g_slist_next(selectedReprList)) + { + Inkscape::XML::Node *node = reinterpret_cast(selectedReprList->data); + if (!strcmp(node->name(), "image") || !strcmp(node->name(), "svg:image")) + { + _nodes[_imageCount] = node; + char const *xlink = node->attribute("xlink:href"); + + _originals[_imageCount] = xlink; + + readImage(xlink, &_images[_imageCount]); + + _imageCount++; + } + } + + _loaded = 1; + } + + for (int i = 0; i < _imageCount; i++) + { + try + { + Magick::Image effectedImage = _images[i]; + applyEffect(&effectedImage); + + Magick::Blob blob; + effectedImage.write(&blob); + + std::string raw_string = blob.base64(); + const int raw_len = raw_string.length(); + const char *raw = raw_string.c_str(); + const char *raw_i = raw; + + int formatted_len = (int)(raw_len / 76.0 * 78.0) + 100; + char *formatted = new char[formatted_len]; + char *formatted_i = formatted; + // data:image/png;base64, + formatted_i = stpcpy(formatted_i, "data:image/"); + formatted_i = stpcpy(formatted_i, effectedImage.magick().c_str()); + formatted_i = stpcpy(formatted_i, ";base64, \n"); + while (strnlen(raw_i, 80) > 76) + { + formatted_i = stpncpy(formatted_i, raw_i, 76); + formatted_i = stpcpy(formatted_i, "\n"); + raw_i += 76; + } + if (strlen(raw_i) > 0) + { + formatted_i = stpcpy(formatted_i, raw_i); + formatted_i = stpcpy(formatted_i, "\n"); + } + + formatted_i = stpcpy(formatted_i, "\0"); + + _nodes[i]->setAttribute("xlink:href", formatted, true); + } + catch (Magick::Exception &error_) { + printf("Caught exception: %s \n", error_.what()); + } + } +} + +/** \brief A function to get the prefences for the grid + \param moudule Module which holds the params + \param view Unused today - may get style information in the future. + + Uses AutoGUI for creating the GUI. +*/ +Gtk::Widget * +ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view, sigc::signal * changeSignal) +{ + SPDocument * current_document = view->doc(); + + using Inkscape::Util::GSListConstIterator; + GSListConstIterator selected = sp_desktop_selection((SPDesktop *)view)->itemList(); + Inkscape::XML::Node * first_select = NULL; + if (selected != NULL) + first_select = SP_OBJECT_REPR(*selected); + + return module->autogui(current_document, first_select, changeSignal); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/imagemagick.h b/src/extension/internal/bitmap/imagemagick.h new file mode 100644 index 000000000..36536bb69 --- /dev/null +++ b/src/extension/internal/bitmap/imagemagick.h @@ -0,0 +1,51 @@ +#ifndef __INKSCAPE_EXTENSION_INTERNAL_BITMAP_IMAGEMAGICK_H__ +#define __INKSCAPE_EXTENSION_INTERNAL_BITMAP_IMAGEMAGICK_H__ + +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/implementation/implementation.h" +#include "extension/extension-forward.h" +#include + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class ImageMagick : public Inkscape::Extension::Implementation::Implementation { + +private: + bool _loaded; + + Inkscape::XML::Node **_nodes; + + Magick::Image *_images; + int _imageCount; + + const char **_originals; +public: + virtual void applyEffect(Magick::Image *image) { }; + virtual void refreshParameters(Inkscape::Extension::Effect *module) { }; + bool load(Inkscape::Extension::Extension *module); + + void commitDocument(void); + void cancelDocument(void); + + void readImage(char const *xlink, Magick::Image *image); + void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document); + + Gtk::Widget* prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view, sigc::signal * changeSignal); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ + +#endif /* __INKSCAPE_EXTENSION_INTERNAL_BITMAP_IMAGEMAGICK_H__ */ diff --git a/src/extension/internal/bitmap/implode.cpp b/src/extension/internal/bitmap/implode.cpp new file mode 100644 index 000000000..74dc81e4e --- /dev/null +++ b/src/extension/internal/bitmap/implode.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "implode.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Implode::applyEffect(Magick::Image* image) { + image->implode(_factor); +} + +void +Implode::refreshParameters(Inkscape::Extension::Effect* module) { + _factor = module->get_param_float("factor"); +} + +#include "../clear-n_.h" + +void +Implode::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Implode") "\n" + "org.inkscape.effect.bitmap.implode\n" + "5.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Implode Effect") "\n" + "\n" + "\n", new Implode()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/implode.h b/src/extension/internal/bitmap/implode.h new file mode 100644 index 000000000..b25b35412 --- /dev/null +++ b/src/extension/internal/bitmap/implode.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Implode : public ImageMagick +{ +private: + float _factor; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/level.cpp b/src/extension/internal/bitmap/level.cpp new file mode 100644 index 000000000..f48be32a2 --- /dev/null +++ b/src/extension/internal/bitmap/level.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "level.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Level::applyEffect(Magick::Image* image) { + Magick::Quantum black_point = Magick::Color::scaleDoubleToQuantum(_black_point / 100.0); + Magick::Quantum white_point = Magick::Color::scaleDoubleToQuantum(_white_point / 100.0); + image->level(black_point, white_point, _mid_point); +} + +void +Level::refreshParameters(Inkscape::Extension::Effect* module) { + _black_point = module->get_param_float("blackPoint"); + _white_point = module->get_param_float("whitePoint"); + _mid_point = module->get_param_float("midPoint"); +} + +#include "../clear-n_.h" + +void +Level::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Level") "\n" + "org.inkscape.effect.bitmap.level\n" + "0.0\n" + "100.0\n" + "1.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Level Effect") "\n" + "\n" + "\n", new Level()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/level.h b/src/extension/internal/bitmap/level.h new file mode 100644 index 000000000..111e83af7 --- /dev/null +++ b/src/extension/internal/bitmap/level.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Level : public ImageMagick +{ +private: + float _black_point; + float _white_point; + float _mid_point; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/levelChannel.cpp b/src/extension/internal/bitmap/levelChannel.cpp new file mode 100644 index 000000000..90372aa84 --- /dev/null +++ b/src/extension/internal/bitmap/levelChannel.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "levelChannel.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +LevelChannel::applyEffect(Magick::Image* image) { + Magick::ChannelType channel = Magick::UndefinedChannel; + if (!strcmp(_channelName, "Red Channel")) channel = Magick::RedChannel; + else if (!strcmp(_channelName, "Green Channel")) channel = Magick::GreenChannel; + else if (!strcmp(_channelName, "Blue Channel")) channel = Magick::BlueChannel; + else if (!strcmp(_channelName, "Cyan Channel")) channel = Magick::CyanChannel; + else if (!strcmp(_channelName, "Magenta Channel")) channel = Magick::MagentaChannel; + else if (!strcmp(_channelName, "Yellow Channel")) channel = Magick::YellowChannel; + else if (!strcmp(_channelName, "Black Channel")) channel = Magick::BlackChannel; + else if (!strcmp(_channelName, "Opacity Channel")) channel = Magick::OpacityChannel; + else if (!strcmp(_channelName, "Matte Channel")) channel = Magick::MatteChannel; + Magick::Quantum black_point = Magick::Color::scaleDoubleToQuantum(_black_point / 100.0); + Magick::Quantum white_point = Magick::Color::scaleDoubleToQuantum(_white_point / 100.0); + image->levelChannel(channel, black_point, white_point, _mid_point); +} + +void +LevelChannel::refreshParameters(Inkscape::Extension::Effect* module) { + _channelName = module->get_param_enum("channel"); + _black_point = module->get_param_float("blackPoint"); + _white_point = module->get_param_float("whitePoint"); + _mid_point = module->get_param_float("midPoint"); +} + +#include "../clear-n_.h" + +void +LevelChannel::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Level (with Channel)") "\n" + "org.inkscape.effect.bitmap.levelChannel\n" + "\n" + "Red Channel\n" + "Green Channel\n" + "Blue Channel\n" + "Cyan Channel\n" + "Magenta Channel\n" + "Yellow Channel\n" + "Black Channel\n" + "Opacity Channel\n" + "Matte Channel\n" + "\n" + "0.0\n" + "100.0\n" + "1.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Level (with Channel) Effect") "\n" + "\n" + "\n", new LevelChannel()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/levelChannel.h b/src/extension/internal/bitmap/levelChannel.h new file mode 100644 index 000000000..832619d5f --- /dev/null +++ b/src/extension/internal/bitmap/levelChannel.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class LevelChannel : public ImageMagick +{ +private: + float _black_point; + float _white_point; + float _mid_point; + const gchar * _channelName; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/medianFilter.cpp b/src/extension/internal/bitmap/medianFilter.cpp new file mode 100644 index 000000000..4ba14fd70 --- /dev/null +++ b/src/extension/internal/bitmap/medianFilter.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "medianFilter.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +MedianFilter::applyEffect(Magick::Image* image) { + image->medianFilter(_radius); +} + +void +MedianFilter::refreshParameters(Inkscape::Extension::Effect* module) { + _radius = module->get_param_float("radius"); +} + +#include "../clear-n_.h" + +void +MedianFilter::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Median Filter") "\n" + "org.inkscape.effect.bitmap.medianFilter\n" + "5.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Median Filter Effect") "\n" + "\n" + "\n", new MedianFilter()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/medianFilter.h b/src/extension/internal/bitmap/medianFilter.h new file mode 100644 index 000000000..befc57001 --- /dev/null +++ b/src/extension/internal/bitmap/medianFilter.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class MedianFilter : public ImageMagick +{ +private: + float _radius; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/modulate.cpp b/src/extension/internal/bitmap/modulate.cpp new file mode 100644 index 000000000..97a4d5a47 --- /dev/null +++ b/src/extension/internal/bitmap/modulate.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "modulate.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Modulate::applyEffect(Magick::Image* image) { + float hue = (_hue + 180.0) / 180.0; + image->modulate(_brightness, _saturation, hue); +} + +void +Modulate::refreshParameters(Inkscape::Extension::Effect* module) { + _brightness = module->get_param_float("brightness"); + _saturation = module->get_param_float("saturation"); + _hue = module->get_param_float("hue"); +} + +#include "../clear-n_.h" + +void +Modulate::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Modulate") "\n" + "org.inkscape.effect.bitmap.modulate\n" + "1.0\n" + "1.0\n" + "0.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Modulate Effect") "\n" + "\n" + "\n", new Modulate()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/modulate.h b/src/extension/internal/bitmap/modulate.h new file mode 100644 index 000000000..f7c6fe9a5 --- /dev/null +++ b/src/extension/internal/bitmap/modulate.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Modulate : public ImageMagick +{ +private: + float _brightness; + float _saturation; + float _hue; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/negate.cpp b/src/extension/internal/bitmap/negate.cpp new file mode 100644 index 000000000..19e72e8dd --- /dev/null +++ b/src/extension/internal/bitmap/negate.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "negate.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Negate::applyEffect(Magick::Image* image) { + image->negate(); +} + +void +Negate::refreshParameters(Inkscape::Extension::Effect* module) { +} + +#include "../clear-n_.h" + +void +Negate::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Negate") "\n" + "org.inkscape.effect.bitmap.negate\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Negate Effect") "\n" + "\n" + "\n", new Negate()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/negate.h b/src/extension/internal/bitmap/negate.h new file mode 100644 index 000000000..7ebe3b79e --- /dev/null +++ b/src/extension/internal/bitmap/negate.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Negate : public ImageMagick +{ +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/normalize.cpp b/src/extension/internal/bitmap/normalize.cpp new file mode 100644 index 000000000..6d8b4330b --- /dev/null +++ b/src/extension/internal/bitmap/normalize.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "normalize.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Normalize::applyEffect(Magick::Image* image) { + image->normalize(); +} + +void +Normalize::refreshParameters(Inkscape::Extension::Effect* module) { +} + +#include "../clear-n_.h" + +void +Normalize::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Normalize") "\n" + "org.inkscape.effect.bitmap.normalize\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Normalize Effect") "\n" + "\n" + "\n", new Normalize()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/normalize.h b/src/extension/internal/bitmap/normalize.h new file mode 100644 index 000000000..0637dbf44 --- /dev/null +++ b/src/extension/internal/bitmap/normalize.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Normalize : public ImageMagick +{ +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/oilPaint.cpp b/src/extension/internal/bitmap/oilPaint.cpp new file mode 100644 index 000000000..7b95fe160 --- /dev/null +++ b/src/extension/internal/bitmap/oilPaint.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "oilPaint.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +OilPaint::applyEffect(Magick::Image* image) { + image->oilPaint(_radius); +} + +void +OilPaint::refreshParameters(Inkscape::Extension::Effect* module) { + _radius = module->get_param_int("radius"); +} + +#include "../clear-n_.h" + +void +OilPaint::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Oil Paint") "\n" + "org.inkscape.effect.bitmap.oilPaint\n" + "3\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply OilPaint Effect") "\n" + "\n" + "\n", new OilPaint()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/oilPaint.h b/src/extension/internal/bitmap/oilPaint.h new file mode 100644 index 000000000..822119d00 --- /dev/null +++ b/src/extension/internal/bitmap/oilPaint.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class OilPaint : public ImageMagick +{ +private: + float _radius; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/opacity.cpp b/src/extension/internal/bitmap/opacity.cpp new file mode 100644 index 000000000..af2c3fe26 --- /dev/null +++ b/src/extension/internal/bitmap/opacity.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "opacity.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Opacity::applyEffect(Magick::Image* image) { + Magick::Quantum opacity = Magick::Color::scaleDoubleToQuantum(_opacity / 100.0); + image->opacity(opacity); +} + +void +Opacity::refreshParameters(Inkscape::Extension::Effect* module) { + _opacity = module->get_param_float("opacity"); +} + +#include "../clear-n_.h" + +void +Opacity::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Opacity") "\n" + "org.inkscape.effect.bitmap.opacity\n" + "80.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Opacity Effect") "\n" + "\n" + "\n", new Opacity()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/opacity.h b/src/extension/internal/bitmap/opacity.h new file mode 100644 index 000000000..2c3a4ecb3 --- /dev/null +++ b/src/extension/internal/bitmap/opacity.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Opacity : public ImageMagick +{ +private: + float _opacity; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/raise.cpp b/src/extension/internal/bitmap/raise.cpp new file mode 100644 index 000000000..6f050fcef --- /dev/null +++ b/src/extension/internal/bitmap/raise.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "raise.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Raise::applyEffect(Magick::Image* image) { + Magick::Geometry geometry(_width, _height, _x, _y); + image->raise(geometry, _raisedFlag); +} + +void +Raise::refreshParameters(Inkscape::Extension::Effect* module) { + _width = module->get_param_int("width"); + _height = module->get_param_int("height"); + _x = module->get_param_int("x"); + _y = module->get_param_int("y"); + _raisedFlag = module->get_param_bool("raisedFlag"); +} + +#include "../clear-n_.h" + +void +Raise::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Raise") "\n" + "org.inkscape.effect.bitmap.raise\n" + "6\n" + "6\n" + "0\n" + "0\n" + "0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Raise Effect") "\n" + "\n" + "\n", new Raise()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/raise.h b/src/extension/internal/bitmap/raise.h new file mode 100644 index 000000000..7ceb08867 --- /dev/null +++ b/src/extension/internal/bitmap/raise.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Raise : public ImageMagick +{ +private: + int _x; + int _y; + int _width; + int _height; + bool _raisedFlag; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/reduceNoise.cpp b/src/extension/internal/bitmap/reduceNoise.cpp new file mode 100644 index 000000000..689a97361 --- /dev/null +++ b/src/extension/internal/bitmap/reduceNoise.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "reduceNoise.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +ReduceNoise::applyEffect(Magick::Image* image) { + if (_order > -1) + image->reduceNoise(_order); + else + image->reduceNoise(); +} + +void +ReduceNoise::refreshParameters(Inkscape::Extension::Effect* module) { + _order = module->get_param_int("order"); +} + +#include "../clear-n_.h" + +void +ReduceNoise::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Reduce Noise") "\n" + "org.inkscape.effect.bitmap.reduceNoise\n" + "-1\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply ReduceNoise Effect") "\n" + "\n" + "\n", new ReduceNoise()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/reduceNoise.h b/src/extension/internal/bitmap/reduceNoise.h new file mode 100644 index 000000000..0a4847d63 --- /dev/null +++ b/src/extension/internal/bitmap/reduceNoise.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class ReduceNoise : public ImageMagick +{ +private: + int _order; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/shade.cpp b/src/extension/internal/bitmap/shade.cpp new file mode 100644 index 000000000..a9bb5a266 --- /dev/null +++ b/src/extension/internal/bitmap/shade.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "shade.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Shade::applyEffect(Magick::Image* image) { + image->shade(_azimuth, _elevation, _colorShading); +} + +void +Shade::refreshParameters(Inkscape::Extension::Effect* module) { + _azimuth = module->get_param_float("azimuth"); + _elevation = module->get_param_float("elevation"); + _colorShading = module->get_param_bool("colorShading"); +} + +#include "../clear-n_.h" + +void +Shade::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Shade") "\n" + "org.inkscape.effect.bitmap.shade\n" + "30\n" + "30\n" + "0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Shade Effect") "\n" + "\n" + "\n", new Shade()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/shade.h b/src/extension/internal/bitmap/shade.h new file mode 100644 index 000000000..2f8349265 --- /dev/null +++ b/src/extension/internal/bitmap/shade.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Shade : public ImageMagick +{ +private: + float _azimuth; + float _elevation; + bool _colorShading; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/sharpen.cpp b/src/extension/internal/bitmap/sharpen.cpp new file mode 100644 index 000000000..cf0bf519e --- /dev/null +++ b/src/extension/internal/bitmap/sharpen.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "sharpen.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Sharpen::applyEffect(Magick::Image* image) { + image->sharpen(_radius, _sigma); +} + +void +Sharpen::refreshParameters(Inkscape::Extension::Effect* module) { + _radius = module->get_param_float("radius"); + _sigma = module->get_param_float("sigma"); +} + +#include "../clear-n_.h" + +void +Sharpen::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Sharpen") "\n" + "org.inkscape.effect.bitmap.sharpen\n" + "1.0\n" + "0.5\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Sharpen Effect") "\n" + "\n" + "\n", new Sharpen()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/sharpen.h b/src/extension/internal/bitmap/sharpen.h new file mode 100644 index 000000000..b8f92ddb3 --- /dev/null +++ b/src/extension/internal/bitmap/sharpen.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Sharpen : public ImageMagick +{ +private: + float _radius; + float _sigma; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/solarize.cpp b/src/extension/internal/bitmap/solarize.cpp new file mode 100644 index 000000000..1de9bf9da --- /dev/null +++ b/src/extension/internal/bitmap/solarize.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "solarize.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Solarize::applyEffect(Magick::Image* image) { + image->solarize(_factor); +} + +void +Solarize::refreshParameters(Inkscape::Extension::Effect* module) { + _factor = module->get_param_float("factor"); +} + +#include "../clear-n_.h" + +void +Solarize::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Solarize") "\n" + "org.inkscape.effect.bitmap.solarize\n" + "50.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Solarize Effect") "\n" + "\n" + "\n", new Solarize()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/solarize.h b/src/extension/internal/bitmap/solarize.h new file mode 100644 index 000000000..4acdf3c5c --- /dev/null +++ b/src/extension/internal/bitmap/solarize.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Solarize : public ImageMagick +{ +private: + float _factor; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/spread.cpp b/src/extension/internal/bitmap/spread.cpp new file mode 100644 index 000000000..dfc9b8bf5 --- /dev/null +++ b/src/extension/internal/bitmap/spread.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "spread.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Spread::applyEffect(Magick::Image* image) { + image->spread(_amount); +} + +void +Spread::refreshParameters(Inkscape::Extension::Effect* module) { + _amount = module->get_param_int("amount"); +} + +#include "../clear-n_.h" + +void +Spread::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Spread") "\n" + "org.inkscape.effect.bitmap.spread\n" + "3\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Spread Effect") "\n" + "\n" + "\n", new Spread()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/spread.h b/src/extension/internal/bitmap/spread.h new file mode 100644 index 000000000..82d955890 --- /dev/null +++ b/src/extension/internal/bitmap/spread.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Spread : public ImageMagick +{ +private: + int _amount; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/swirl.cpp b/src/extension/internal/bitmap/swirl.cpp new file mode 100644 index 000000000..a880552c6 --- /dev/null +++ b/src/extension/internal/bitmap/swirl.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "swirl.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Swirl::applyEffect(Magick::Image* image) { + image->swirl(_degrees); +} + +void +Swirl::refreshParameters(Inkscape::Extension::Effect* module) { + _degrees = module->get_param_float("degrees"); +} + +#include "../clear-n_.h" + +void +Swirl::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Swirl") "\n" + "org.inkscape.effect.bitmap.swirl\n" + "30\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Swirl Effect") "\n" + "\n" + "\n", new Swirl()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/swirl.h b/src/extension/internal/bitmap/swirl.h new file mode 100644 index 000000000..cea1850ea --- /dev/null +++ b/src/extension/internal/bitmap/swirl.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Swirl : public ImageMagick +{ +private: + double _degrees; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/threshold.cpp b/src/extension/internal/bitmap/threshold.cpp new file mode 100644 index 000000000..6f21e61d1 --- /dev/null +++ b/src/extension/internal/bitmap/threshold.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "threshold.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Threshold::applyEffect(Magick::Image* image) { + image->threshold(_threshold); +} + +void +Threshold::refreshParameters(Inkscape::Extension::Effect* module) { + _threshold = module->get_param_float("threshold"); +} + +#include "../clear-n_.h" + +void +Threshold::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Threshold") "\n" + "org.inkscape.effect.bitmap.threshold\n" + "\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Threshold Effect") "\n" + "\n" + "\n", new Threshold()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/threshold.h b/src/extension/internal/bitmap/threshold.h new file mode 100644 index 000000000..2e65a7a6f --- /dev/null +++ b/src/extension/internal/bitmap/threshold.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Threshold : public ImageMagick +{ +private: + double _threshold; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/unsharpmask.cpp b/src/extension/internal/bitmap/unsharpmask.cpp new file mode 100644 index 000000000..6e4a1759a --- /dev/null +++ b/src/extension/internal/bitmap/unsharpmask.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "unsharpmask.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Unsharpmask::applyEffect(Magick::Image* image) { + float amount = _amount / 100.0; + image->unsharpmask(_radius, _sigma, amount, _threshold); +} + +void +Unsharpmask::refreshParameters(Inkscape::Extension::Effect* module) { + _radius = module->get_param_float("radius"); + _sigma = module->get_param_float("sigma"); + _amount = module->get_param_float("amount"); + _threshold = module->get_param_float("threshold"); +} + +#include "../clear-n_.h" + +void +Unsharpmask::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Unsharp Mask") "\n" + "org.inkscape.effect.bitmap.unsharpmask\n" + "5.0\n" + "5.0\n" + "50.0\n" + "5.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Unsharp Mask Effect") "\n" + "\n" + "\n", new Unsharpmask()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/unsharpmask.h b/src/extension/internal/bitmap/unsharpmask.h new file mode 100644 index 000000000..5d3a47ecf --- /dev/null +++ b/src/extension/internal/bitmap/unsharpmask.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Unsharpmask : public ImageMagick +{ +private: + float _radius; + float _sigma; + float _amount; + float _threshold; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/wave.cpp b/src/extension/internal/bitmap/wave.cpp new file mode 100644 index 000000000..c1a2994c0 --- /dev/null +++ b/src/extension/internal/bitmap/wave.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "extension/effect.h" +#include "extension/system.h" + +#include "wave.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +void +Wave::applyEffect(Magick::Image* image) { + image->wave(_amplitude, _wavelength); +} + +void +Wave::refreshParameters(Inkscape::Extension::Effect* module) { + _amplitude = module->get_param_float("amplitude"); + _wavelength = module->get_param_int("wavelength"); +} + +#include "../clear-n_.h" + +void +Wave::init(void) +{ + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Wave") "\n" + "org.inkscape.effect.bitmap.wave\n" + "25.0\n" + "150.0\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "" N_("Apply Wave Effect") "\n" + "\n" + "\n", new Wave()); +} + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/internal/bitmap/wave.h b/src/extension/internal/bitmap/wave.h new file mode 100644 index 000000000..8ee1fc7f5 --- /dev/null +++ b/src/extension/internal/bitmap/wave.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007 Authors: + * Christopher Brown + * Ted Gould + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "imagemagick.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { +namespace Bitmap { + +class Wave : public ImageMagick +{ +private: + float _amplitude; + int _wavelength; +public: + void applyEffect(Magick::Image *image); + void refreshParameters(Inkscape::Extension::Effect *module); + static void init(void); +}; + +}; /* namespace Bitmap */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/parambool.cpp b/src/extension/parambool.cpp new file mode 100644 index 000000000..2aa480688 --- /dev/null +++ b/src/extension/parambool.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include + +#include "extension.h" +#include "parambool.h" + +namespace Inkscape { +namespace Extension { + +/** \brief Use the superclass' allocator and set the \c _value */ +ParamBool::ParamBool (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, ext), _value(false) +{ + const char * defaultval = NULL; + if (sp_repr_children(xml) != NULL) + defaultval = sp_repr_children(xml)->content(); + + if (defaultval != NULL && (!strcmp(defaultval, "TRUE") || !strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { + _value = true; + } else { + _value = false; + } + + gchar * pref_name = this->pref_name(); + _value = (bool)prefs_get_int_attribute(PREF_DIR, pref_name, _value); + g_free(pref_name); + + return; +} + +/** \brief A function to set the \c _value + \param in The value to set to + \param doc A document that should be used to set the value. + \param node The node where the value may be placed + + This function sets the internal value, but it also sets the value + in the preferences structure. To put it in the right place, \c PREF_DIR + and \c pref_name() are used. +*/ +bool +ParamBool::set (bool in, SPDocument * doc, Inkscape::XML::Node * node) +{ + _value = in; + + gchar * prefname = this->pref_name(); + prefs_set_int_attribute(PREF_DIR, prefname, _value == true ? 1 : 0); + g_free(prefname); + + return _value; +} + +/** \brief A check button which is Param aware. It works with the + parameter to change it's value as the check button changes + value. */ +class ParamBoolCheckButton : public Gtk::CheckButton { +private: + /** \brief Param to change */ + ParamBool * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +public: + /** \brief Initialize the check button + \param param Which parameter to adjust on changing the check button + + This function sets the value of the checkbox to be that of the + parameter, and then sets up a callback to \c on_toggle. + */ + ParamBoolCheckButton (ParamBool * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + Gtk::CheckButton(), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { + this->set_active(_pref->get(NULL, NULL) /**\todo fix */); + this->signal_toggled().connect(sigc::mem_fun(this, &ParamBoolCheckButton::on_toggle)); + return; + } + void on_toggle (void); +}; + +/** + \brief A function to respond to the check box changing + + Adjusts the value of the preference to match that in the check box. +*/ +void +ParamBoolCheckButton::on_toggle (void) +{ + _pref->set(this->get_active(), NULL /**\todo fix this */, NULL); + if (_changeSignal != NULL) { + _changeSignal->emit(); + } + return; +} + +/** \brief Return 'true' or 'false' */ +Glib::ustring * +ParamBool::string (void) +{ + Glib::ustring * mystring; + + if (_value) + mystring = new Glib::ustring("true"); + else + mystring = new Glib::ustring("false"); + + return mystring; +} + +/** + \brief Creates a bool check button for a bool parameter + + Builds a hbox with a label and a check button in it. +*/ +Gtk::Widget * +ParamBool::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); + label->show(); + hbox->pack_start(*label, true, true); + + ParamBoolCheckButton * checkbox = new ParamBoolCheckButton(this, doc, node, changeSignal); + checkbox->show(); + hbox->pack_start(*checkbox, false, false); + + hbox->show(); + + return dynamic_cast(hbox); +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/parambool.h b/src/extension/parambool.h new file mode 100644 index 000000000..56edc70a7 --- /dev/null +++ b/src/extension/parambool.h @@ -0,0 +1,46 @@ +#ifndef __INK_EXTENSION_PARAMBOOL_H__ +#define __INK_EXTENSION_PARAMBOOL_H__ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +/** \brief A boolean parameter */ +class ParamBool : public Parameter { +private: + /** \brief Internal value. */ + bool _value; +public: + ParamBool(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + /** \brief Returns \c _value */ + bool get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } + bool set (bool in, SPDocument * doc, Inkscape::XML::Node * node); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + Glib::ustring * string (void); +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMBOOL_H__ */ + +/* + 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 : diff --git a/src/extension/paramcolor.cpp b/src/extension/paramcolor.cpp new file mode 100644 index 000000000..83dba1b2b --- /dev/null +++ b/src/extension/paramcolor.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen + * Christopher Brown + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include +#include +#include + +#include + +#include "extension.h" +#include "paramcolor.h" + +#include "color.h" +#include "widgets/sp-color-selector.h" +#include "widgets/sp-color-notebook.h" + + +namespace Inkscape { +namespace Extension { + +void sp_color_param_changed(SPColorSelector *csel, GObject *cp); + + +/** \brief Free the allocated data. */ +ParamColor::~ParamColor(void) +{ + g_free(_value); +} + +SPColor* +ParamColor::set (SPColor* in, SPDocument * doc, Inkscape::XML::Node * node) +{ + _value = in; + + gchar * prefname = this->pref_name(); + prefs_set_string_attribute(PREF_DIR, prefname, this->string()->c_str()); + g_free(prefname); + + return _value; +} + +/** \brief Initialize the object, to do that, copy the data. */ +ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, ext), _value(NULL) +{ + const char * defaulthex = NULL; + if (sp_repr_children(xml) != NULL) + defaulthex = sp_repr_children(xml)->content(); + + gchar * pref_name = this->pref_name(); + const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name); + g_free(pref_name); + + if (paramval != NULL) + defaulthex = paramval; + + const char* hexMark = strchr(defaulthex, '#'); + if (hexMark != NULL) + defaulthex++;// = hexMark; + + if (strlen(defaulthex) == 6) { + int r = 0, g = 0, b = 0; + std::stringstream ss; + ss << strndup(defaulthex, 2); + ss >> std::hex >> r; + ss << strndup(defaulthex + 2, 2); + ss >> std::hex >> g; + ss << defaulthex + 4; + ss >> std::hex >> b; + g_free(ss); + + SPColor defaultColor; + sp_color_set_rgb_float(&defaultColor, r / 255.0, g / 255.0, b / 255.0); + _value = &defaultColor; + } + + return; +} + +/** \brief Return the value as a string */ +Glib::ustring * +ParamColor::string (void) +{ + float rgb[3]; + sp_color_get_rgb_floatv(_value, rgb); + char hex[8]; + snprintf(hex, 8, "#%02X%02X%02X", (int)(rgb[0] * 255), (int)(rgb[1] * 255), (int)(rgb[2] * 255)); + + Glib::ustring* ret = new Glib::ustring(hex); + + printf("ParamColor::string = '%s'\n", hex); + + return ret; +} + +Gtk::Widget * +ParamColor::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + _changeSignal = new sigc::signal(*changeSignal); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK, SP_COLORSPACE_TYPE_RGB); + + ColorSelector* colorSelector = spColorSelector->base; + if (_value == NULL) { + _value = new SPColor(); + sp_color_set_rgb_float(_value, 1.0, 0.0, 0.0); + } + colorSelector->setColor(*_value); + + hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0); + g_signal_connect(G_OBJECT(spColorSelector), "dragged", G_CALLBACK(sp_color_param_changed), (void*)this); + g_signal_connect(G_OBJECT(spColorSelector), "released", G_CALLBACK(sp_color_param_changed), (void*)this); + g_signal_connect(G_OBJECT(spColorSelector), "changed", G_CALLBACK(sp_color_param_changed), (void*)this); + + gtk_widget_show(GTK_WIDGET(spColorSelector)); + hbox->show(); + + return dynamic_cast(hbox); +} + +void +sp_color_param_changed(SPColorSelector *csel, GObject *obj) +{ + SPColor color; + float alpha; + csel->base->getColorAlpha(color, &alpha); + guint32 rgba = sp_color_get_rgba32_falpha(&color, alpha); + + + ParamColor* ptr = (ParamColor* )obj; + ptr->set(&color, NULL, NULL); + + ptr->_changeSignal->emit(); +} + +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/paramcolor.h b/src/extension/paramcolor.h new file mode 100644 index 000000000..c109df04f --- /dev/null +++ b/src/extension/paramcolor.h @@ -0,0 +1,47 @@ +#ifndef __INK_EXTENSION_PARAMCOLOR_H__ +#define __INK_EXTENSION_PARAMCOLOR_H__ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include +#include "color.h" +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +class ParamColor : public Parameter { +private: + SPColor* _value; +public: + ParamColor(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ~ParamColor(void); + /** \brief Returns \c _value, with a \i const to protect it. */ + SPColor* get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } + SPColor* set (SPColor* in, SPDocument * doc, Inkscape::XML::Node * node); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + Glib::ustring * string (void); + sigc::signal * _changeSignal; +}; /* class ParamColor */ + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMCOLOR_H__ */ + +/* + 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 : diff --git a/src/extension/paramdescription.cpp b/src/extension/paramdescription.cpp new file mode 100644 index 000000000..40cbba8c6 --- /dev/null +++ b/src/extension/paramdescription.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef linux // does the dollar sign need escaping when passed as string parameter? +# define ESCAPE_DOLLAR_COMMANDLINE +#endif + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + + +#include "paramdescription.h" + +#include +#include +#include +#include + + +#include + +#include + +#include "extension.h" +#include "prefs-utils.h" + +namespace Inkscape { +namespace Extension { + + +/** \brief Initialize the object, to do that, copy the data. */ +ParamDescription::ParamDescription (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, ext), _value(NULL) +{ + // printf("Building Description\n"); + const char * defaultval = NULL; + if (sp_repr_children(xml) != NULL) + defaultval = sp_repr_children(xml)->content(); + + if (defaultval != NULL) + _value = g_strdup(defaultval); + + return; +} + +/** \brief Create a label for the description */ +Gtk::Widget * +ParamDescription::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_value))); + label->set_line_wrap(); + label->show(); + + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + hbox->pack_start(*label, true, true, 5); + hbox->show(); + + return hbox; +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/paramdescription.h b/src/extension/paramdescription.h new file mode 100644 index 000000000..13b4e5eae --- /dev/null +++ b/src/extension/paramdescription.h @@ -0,0 +1,43 @@ +#ifndef __INK_EXTENSION_PARAMDESCRIPTION_H__ +#define __INK_EXTENSION_PARAMDESCRIPTION_H__ + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +/** \brief A description parameter */ +class ParamDescription : public Parameter { +private: + /** \brief Internal value. */ + gchar * _value; +public: + ParamDescription(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMDESCRIPTION_H__ */ + +/* + 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 : diff --git a/src/extension/paramenum.cpp b/src/extension/paramenum.cpp index 8aea1daeb..8d779d1c2 100644 --- a/src/extension/paramenum.cpp +++ b/src/extension/paramenum.cpp @@ -155,6 +155,11 @@ ParamComboBox::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * no return _value; } +void +ParamComboBox::changed (void) { + +} + /** \brief A function to get the value of the parameter in string form @@ -168,19 +173,23 @@ ParamComboBox::string (void) return param_string; } + + + /** \brief A special category of Gtk::Entry to handle string parameteres */ class ParamComboBoxEntry : public Gtk::ComboBoxText { private: ParamComboBox * _pref; SPDocument * _doc; Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; public: /** \brief Build a string preference for the given parameter \param pref Where to get the string from, and where to put it when it changes. */ - ParamComboBoxEntry (ParamComboBox * pref, SPDocument * doc, Inkscape::XML::Node * node) : - Gtk::ComboBoxText(), _pref(pref), _doc(doc), _node(node) { + ParamComboBoxEntry (ParamComboBox * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + Gtk::ComboBoxText(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { this->signal_changed().connect(sigc::mem_fun(this, &ParamComboBoxEntry::changed)); }; void changed (void); @@ -196,11 +205,11 @@ ParamComboBoxEntry::changed (void) { Glib::ustring data = this->get_active_text(); _pref->set(data.c_str(), _doc, _node); - return; + if (_changeSignal != NULL) { + _changeSignal->emit(); + } } - - /** \brief Creates a combobox widget for an enumeration parameter */ @@ -213,7 +222,7 @@ ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s label->show(); hbox->pack_start(*label, false, false); - ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node)); + ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); // add choice strings: Glib::ustring * settext = 0; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { @@ -237,4 +246,3 @@ ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s } /* namespace Extension */ } /* namespace Inkscape */ - diff --git a/src/extension/paramenum.h b/src/extension/paramenum.h index b5eaeded7..7f36742aa 100644 --- a/src/extension/paramenum.h +++ b/src/extension/paramenum.h @@ -44,6 +44,8 @@ public: const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + + void changed (void); }; /* class ParamComboBox */ diff --git a/src/extension/parameter.cpp b/src/extension/parameter.cpp index f59a5cc3d..52c67267f 100644 --- a/src/extension/parameter.cpp +++ b/src/extension/parameter.cpp @@ -24,195 +24,29 @@ #include #include -#include - #include #include "extension.h" -#include "prefs-utils.h" #include "document-private.h" #include "sp-object.h" +#include "color.h" +#include "widgets/sp-color-selector.h" +#include "widgets/sp-color-notebook.h" #include "parameter.h" -#include "paramnotebook.h" +#include "parambool.h" +#include "paramcolor.h" +#include "paramdescription.h" #include "paramenum.h" +#include "paramfloat.h" +#include "paramint.h" +#include "paramnotebook.h" #include "paramradiobutton.h" - -/** \brief The root directory in the preferences database for extension - related parameters. */ -#define PREF_DIR "extensions" +#include "paramstring.h" namespace Inkscape { namespace Extension { -/** \brief A description parameter */ -class ParamDescription : public Parameter { -private: - /** \brief Internal value. */ - gchar * _value; -public: - ParamDescription(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); -}; - -/** \brief A boolean parameter */ -class ParamBool : public Parameter { -private: - /** \brief Internal value. */ - bool _value; -public: - ParamBool(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - bool get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } - bool set (bool in, SPDocument * doc, Inkscape::XML::Node * node); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - Glib::ustring * string (void); -}; - -/** \brief Use the superclass' allocator and set the \c _value */ -ParamBool::ParamBool (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(false) -{ - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - - if (defaultval != NULL && (!strcmp(defaultval, "TRUE") || !strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { - _value = true; - } else { - _value = false; - } - - gchar * pref_name = this->pref_name(); - _value = (bool)prefs_get_int_attribute(PREF_DIR, pref_name, _value); - g_free(pref_name); - - return; -} - -class ParamInt : public Parameter { -private: - /** \brief Internal value. */ - int _value; - int _min; - int _max; -public: - ParamInt (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - int get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } - int set (int in, SPDocument * doc, Inkscape::XML::Node * node); - int max (void) { return _max; } - int min (void) { return _min; } - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - Glib::ustring * string (void); -}; - -/** \brief Use the superclass' allocator and set the \c _value */ -ParamInt::ParamInt (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(0), _min(0), _max(10) -{ - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - if (defaultval != NULL) { - _value = atoi(defaultval); - } - - const char * maxval = xml->attribute("max"); - if (maxval != NULL) - _max = atoi(maxval); - - const char * minval = xml->attribute("min"); - if (minval != NULL) - _min = atoi(minval); - - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10; - _min = 0; - } - - gchar * pref_name = this->pref_name(); - _value = prefs_get_int_attribute(PREF_DIR, pref_name, _value); - g_free(pref_name); - - // std::cout << "New Int:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; - - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - return; -} - -class ParamFloat : public Parameter { -private: - /** \brief Internal value. */ - float _value; - float _min; - float _max; -public: - ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - float get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } - float set (float in, SPDocument * doc, Inkscape::XML::Node * node); - float max (void) { return _max; } - float min (void) { return _min; } - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - Glib::ustring * string (void); -}; - -/** \brief Use the superclass' allocator and set the \c _value */ -ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(0.0), _min(0.0), _max(10.0) -{ - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - if (defaultval != NULL) { - _value = atof(defaultval); - } - - const char * maxval = xml->attribute("max"); - if (maxval != NULL) - _max = atof(maxval); - - const char * minval = xml->attribute("min"); - if (minval != NULL) - _min = atof(minval); - - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10.0; - _min = 0.0; - } - - gchar * pref_name = this->pref_name(); - _value = prefs_get_double_attribute(PREF_DIR, pref_name, _value); - g_free(pref_name); - - // std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; - - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - return; -} - -class ParamString : public Parameter { -private: - /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. */ - gchar * _value; -public: - ParamString(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - ~ParamString(void); - /** \brief Returns \c _value, with a \i const to protect it. */ - const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } - const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - Glib::ustring * string (void); -}; - class ParamEnum : public Parameter { private: class Choice { @@ -245,8 +79,7 @@ public: Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); Glib::ustring * string (void); }; /* class ParamEnum */ - - + /** \return None \brief This function creates a parameter that can be used later. This @@ -322,116 +155,23 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * param = new ParamNotebook(name, guitext, desc, scope, in_ext, in_repr); } else if (!strcmp(type, "optiongroup")) { param = new ParamRadioButton(name, guitext, desc, scope, in_ext, in_repr); + } else if (!strcmp(type, "color")) { + param = new ParamColor(name, guitext, desc, scope, in_ext, in_repr); } /* Note: param could equal NULL */ return param; } -/** \brief A function to set the \c _value - \param in The value to set to - \param doc A document that should be used to set the value. - \param node The node where the value may be placed - - This function sets the internal value, but it also sets the value - in the preferences structure. To put it in the right place, \c PREF_DIR - and \c pref_name() are used. -*/ -bool -ParamBool::set (bool in, SPDocument * doc, Inkscape::XML::Node * node) -{ - _value = in; - - gchar * prefname = this->pref_name(); - prefs_set_int_attribute(PREF_DIR, prefname, _value == true ? 1 : 0); - g_free(prefname); - - return _value; -} - -/** \brief A function to set the \c _value - \param in The value to set to - \param doc A document that should be used to set the value. - \param node The node where the value may be placed - - This function sets the internal value, but it also sets the value - in the preferences structure. To put it in the right place, \c PREF_DIR - and \c pref_name() are used. -*/ -int -ParamInt::set (int in, SPDocument * doc, Inkscape::XML::Node * node) -{ - _value = in; - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - gchar * prefname = this->pref_name(); - prefs_set_int_attribute(PREF_DIR, prefname, _value); - g_free(prefname); - - return _value; -} - -/** \brief A function to set the \c _value - \param in The value to set to - \param doc A document that should be used to set the value. - \param node The node where the value may be placed - - This function sets the internal value, but it also sets the value - in the preferences structure. To put it in the right place, \c PREF_DIR - and \c pref_name() are used. -*/ -float -ParamFloat::set (float in, SPDocument * doc, Inkscape::XML::Node * node) -{ - _value = in; - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - gchar * prefname = this->pref_name(); - prefs_set_double_attribute(PREF_DIR, prefname, _value); - g_free(prefname); - - return _value; -} - -/** \brief A function to set the \c _value - \param in The value to set to - \param doc A document that should be used to set the value. - \param node The node where the value may be placed - - This function sets the internal value, but it also sets the value - in the preferences structure. To put it in the right place, \c PREF_DIR - and \c pref_name() are used. - - To copy the data into _value the old memory must be free'd first. - It is important to note that \c g_free handles \c NULL just fine. Then - the passed in value is duplicated using \c g_strdup(). -*/ -const gchar * -ParamString::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node) -{ - if (in == NULL) return NULL; /* Can't have NULL string */ - if (_value != NULL) - g_free(_value); - _value = g_strdup(in); - - gchar * prefname = this->pref_name(); - prefs_set_string_attribute(PREF_DIR, prefname, _value); - g_free(prefname); - - return _value; -} /** \brief Wrapper to cast to the object and use it's function. */ bool Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamBool * boolpntr; - boolpntr = dynamic_cast(this); + ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_bool_param(); return boolpntr->get(doc, node); } @@ -439,10 +179,9 @@ Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node) int Parameter::get_int (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamInt * intpntr; - intpntr = dynamic_cast(this); + ParamInt * intpntr = dynamic_cast(this); if (intpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_int_param(); return intpntr->get(doc, node); } @@ -450,10 +189,9 @@ Parameter::get_int (const SPDocument * doc, const Inkscape::XML::Node * node) float Parameter::get_float (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamFloat * floatpntr; - floatpntr = dynamic_cast(this); + ParamFloat * floatpntr = dynamic_cast(this); if (floatpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_float_param(); return floatpntr->get(doc, node); } @@ -461,21 +199,38 @@ Parameter::get_float (const SPDocument * doc, const Inkscape::XML::Node * node) const gchar * Parameter::get_string (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamString * stringpntr; - stringpntr = dynamic_cast(this); + ParamString * stringpntr = dynamic_cast(this); if (stringpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_string_param(); return stringpntr->get(doc, node); } +/** \brief Wrapper to cast to the object and use it's function. */ +const gchar * +Parameter::get_enum (const SPDocument * doc, const Inkscape::XML::Node * node) +{ + ParamComboBox * param = dynamic_cast(this); + if (param == NULL) + throw Extension::param_not_enum_param(); + return param->get(doc, node); +} + +SPColor* +Parameter::get_color(const SPDocument* doc, const Inkscape::XML::Node* node) +{ + ParamColor* param = dynamic_cast(this); + if (param == NULL) + throw Extension::param_not_color_param(); + return param->get(doc, node); +} + /** \brief Wrapper to cast to the object and use it's function. */ bool Parameter::set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node) { - ParamBool * boolpntr; - boolpntr = dynamic_cast(this); + ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_bool_param(); return boolpntr->set(in, doc, node); } @@ -483,10 +238,9 @@ Parameter::set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node) int Parameter::set_int (int in, SPDocument * doc, Inkscape::XML::Node * node) { - ParamInt * intpntr; - intpntr = dynamic_cast(this); + ParamInt * intpntr = dynamic_cast(this); if (intpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_int_param(); return intpntr->set(in, doc, node); } @@ -497,7 +251,7 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) ParamFloat * floatpntr; floatpntr = dynamic_cast(this); if (floatpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_float_param(); return floatpntr->set(in, doc, node); } @@ -505,38 +259,21 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) const gchar * Parameter::set_string (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node) { - ParamString * stringpntr; - stringpntr = dynamic_cast(this); + ParamString * stringpntr = dynamic_cast(this); if (stringpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_string_param(); return stringpntr->set(in, doc, node); } - -/** \brief Initialize the object, to do that, copy the data. */ -ParamString::ParamString (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(NULL) +/** \brief Wrapper to cast to the object and use it's function. */ +SPColor* +Parameter::set_color (SPColor* in, SPDocument * doc, Inkscape::XML::Node * node) { - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - - gchar * pref_name = this->pref_name(); - const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name); - g_free(pref_name); - - if (paramval != NULL) - defaultval = paramval; - if (defaultval != NULL) - _value = g_strdup(defaultval); - - return; + ParamColor* param = dynamic_cast(this); + if (param == NULL) + throw Extension::param_not_color_param(); + return param->set(in, doc, node); } -/** \brief Free the allocated data. */ -ParamString::~ParamString(void) -{ - g_free(_value); -} /** \brief Oop, now that we need a parameter, we need it's name. */ Parameter::Parameter (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext) : @@ -633,346 +370,9 @@ Parameter::string (void) return mystring; } -/** \brief A class to make an adjustment that uses Extension params */ -class ParamFloatAdjustment : public Gtk::Adjustment { - /** The parameter to adjust */ - ParamFloat * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** \brief Make the adjustment using an extension and the string - describing the parameter. */ - ParamFloatAdjustment (ParamFloat * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Adjustment(0.0, param->min(), param->max(), 0.1), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { - this->set_value(_pref->get(NULL, NULL) /* \todo fix */); - this->signal_value_changed().connect(sigc::mem_fun(this, &ParamFloatAdjustment::val_changed)); - return; - }; - - void val_changed (void); -}; /* class ParamFloatAdjustment */ - -/** \brief A function to respond to the value_changed signal from the - adjustment. - - This function just grabs the value from the adjustment and writes - it to the parameter. Very simple, but yet beautiful. -*/ -void -ParamFloatAdjustment::val_changed (void) -{ - //std::cout << "Value Changed to: " << this->get_value() << std::endl; - _pref->set(this->get_value(), _doc, _node); - if (_changeSignal != NULL) { - _changeSignal->emit(); - } - return; -} - -/** \brief A class to make an adjustment that uses Extension params */ -class ParamIntAdjustment : public Gtk::Adjustment { - /** The parameter to adjust */ - ParamInt * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** \brief Make the adjustment using an extension and the string - describing the parameter. */ - ParamIntAdjustment (ParamInt * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Adjustment(0.0, param->min(), param->max(), 1.0), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { - this->set_value(_pref->get(NULL, NULL) /* \todo fix */); - this->signal_value_changed().connect(sigc::mem_fun(this, &ParamIntAdjustment::val_changed)); - return; - }; - - void val_changed (void); -}; /* class ParamIntAdjustment */ - -/** \brief A function to respond to the value_changed signal from the - adjustment. - - This function just grabs the value from the adjustment and writes - it to the parameter. Very simple, but yet beautiful. -*/ -void -ParamIntAdjustment::val_changed (void) -{ - //std::cout << "Value Changed to: " << this->get_value() << std::endl; - _pref->set((int)this->get_value(), _doc, _node); - if (_changeSignal != NULL) { - _changeSignal->emit(); - } - return; -} - -/** - \brief Creates a Float Adjustment for a float parameter - - Builds a hbox with a label and a float adjustment in it. -*/ -Gtk::Widget * -ParamFloat::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - - Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); - label->show(); - hbox->pack_start(*label, true, true); - - ParamFloatAdjustment * fadjust = Gtk::manage(new ParamFloatAdjustment(this, doc, node, changeSignal)); - Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 0.1, 1)); - spin->show(); - hbox->pack_start(*spin, false, false); - - hbox->show(); - - return dynamic_cast(hbox); -} - -/** - \brief Creates a Int Adjustment for a int parameter - - Builds a hbox with a label and a int adjustment in it. -*/ -Gtk::Widget * -ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); - label->show(); - hbox->pack_start(*label, true, true); - ParamIntAdjustment * fadjust = Gtk::manage(new ParamIntAdjustment(this, doc, node, changeSignal)); - Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 1.0, 0)); - spin->show(); - hbox->pack_start(*spin, false, false); - hbox->show(); - - return dynamic_cast(hbox); -} - -/** \brief A check button which is Param aware. It works with the - parameter to change it's value as the check button changes - value. */ -class ParamBoolCheckButton : public Gtk::CheckButton { -private: - /** \brief Param to change */ - ParamBool * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** \brief Initialize the check button - \param param Which parameter to adjust on changing the check button - - This function sets the value of the checkbox to be that of the - parameter, and then sets up a callback to \c on_toggle. - */ - ParamBoolCheckButton (ParamBool * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::CheckButton(), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { - this->set_active(_pref->get(NULL, NULL) /**\todo fix */); - this->signal_toggled().connect(sigc::mem_fun(this, &ParamBoolCheckButton::on_toggle)); - return; - } - void on_toggle (void); -}; - -/** - \brief A function to respond to the check box changing - - Adjusts the value of the preference to match that in the check box. -*/ -void -ParamBoolCheckButton::on_toggle (void) -{ - _pref->set(this->get_active(), NULL /**\todo fix this */, NULL); - if (_changeSignal != NULL) { - _changeSignal->emit(); - } - return; -} - -/** - \brief Creates a bool check button for a bool parameter - - Builds a hbox with a label and a check button in it. -*/ -Gtk::Widget * -ParamBool::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - - Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); - label->show(); - hbox->pack_start(*label, true, true); - - ParamBoolCheckButton * checkbox = new ParamBoolCheckButton(this, doc, node, changeSignal); - checkbox->show(); - hbox->pack_start(*checkbox, false, false); - - hbox->show(); - - return dynamic_cast(hbox); -} - -/** \brief A special category of Gtk::Entry to handle string parameteres */ -class ParamStringEntry : public Gtk::Entry { -private: - ParamString * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** \brief Build a string preference for the given parameter - \param pref Where to get the string from, and where to put it - when it changes. - */ - ParamStringEntry (ParamString * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - if (_pref->get(NULL, NULL) != NULL) - this->set_text(Glib::ustring(_pref->get(NULL, NULL))); - this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); - }; - void changed_text (void); -}; - -/** \brief Respond to the text box changing - - This function responds to the box changing by grabbing the value - from the text box and putting it in the parameter. -*/ -void -ParamStringEntry::changed_text (void) -{ - Glib::ustring data = this->get_text(); - _pref->set(data.c_str(), _doc, _node); - if (_changeSignal != NULL) { - _changeSignal->emit(); - } - return; -} - -/** - \brief Creates a text box for the string parameter - - Builds a hbox with a label and a text box in it. -*/ -Gtk::Widget * -ParamString::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - - Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); - label->show(); - hbox->pack_start(*label, false, false); - - ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); - textbox->show(); - hbox->pack_start(*textbox, true, true); - - hbox->show(); - - return dynamic_cast(hbox); -} - -/** \brief Return 'true' or 'false' */ -Glib::ustring * -ParamBool::string (void) -{ - Glib::ustring * mystring; - - if (_value) - mystring = new Glib::ustring("true"); - else - mystring = new Glib::ustring("false"); - - return mystring; -} - -/** \brief Return the value as a string */ -Glib::ustring * -ParamInt::string (void) -{ - char startstring[32]; - sprintf(startstring, "%d", _value); - Glib::ustring * mystring = new Glib::ustring(startstring); - return mystring; -} - -/** \brief Return the value as a string */ -Glib::ustring * -ParamFloat::string (void) -{ - char startstring[G_ASCII_DTOSTR_BUF_SIZE]; - g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); - Glib::ustring * mystring = new Glib::ustring(startstring); - return mystring; -} - -/** \brief Return the value as a string */ -Glib::ustring * -ParamString::string (void) -{ - if (_value == NULL) - return new Glib::ustring(""); - - // FIXME: I think the string should NOT be escaped. Just put between "..." - // Otherwise \frac{1}{2} will become \\frac{1}{2} and then the LaTeX effect won't work.... - //gchar * esc = g_strescape(_value, NULL); - Glib::ustring escaped(_value); - //g_free(esc); - -#ifdef ESCAPE_DOLLAR_COMMANDLINE // escape the dollar sign - Glib::ustring::iterator i; - for (i = escaped.begin(); i != escaped.end(); ++i) { - if ( *i == '$') { - i = escaped.insert(i, '\\'); - i++; - } - } -#endif - - Glib::ustring * mystring = new Glib::ustring(""); - *mystring += "\""; - *mystring += escaped; - *mystring += "\""; - - return mystring; -} - -/** \brief Create a label for the description */ -Gtk::Widget * -ParamDescription::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_value))); - label->set_line_wrap(); - label->show(); - - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - hbox->pack_start(*label, true, true, 5); - hbox->show(); - - return hbox; -} - -/** \brief Initialize the object, to do that, copy the data. */ -ParamDescription::ParamDescription (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(NULL) -{ - // printf("Building Description\n"); - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - - if (defaultval != NULL) - _value = g_strdup(defaultval); - - return; -} ParamEnum::ParamEnum (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : Parameter(name, guitext, desc, scope, ext), _current_choice(NULL) diff --git a/src/extension/parameter.h b/src/extension/parameter.h index 5ac1c9f5c..0c799a1c2 100644 --- a/src/extension/parameter.h +++ b/src/extension/parameter.h @@ -13,10 +13,21 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + +/** \brief The root directory in the preferences database for extension-related parameters. */ +#define PREF_DIR "extensions" + #include #include "xml/document.h" +#include "xml/node.h" +#include "document.h" #include "extension-forward.h" +#include "prefs-utils.h" + +#include + +#include "color.h" namespace Inkscape { namespace Extension { @@ -76,11 +87,16 @@ public: const Inkscape::XML::Node * node); const gchar * get_string (const SPDocument * doc, const Inkscape::XML::Node * node); + SPColor* get_color (const SPDocument * doc, + const Inkscape::XML::Node * node); + const gchar * get_enum (const SPDocument * doc, + const Inkscape::XML::Node * node); bool set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node); int set_int (int in, SPDocument * doc, Inkscape::XML::Node * node); float set_float (float in, SPDocument * doc, Inkscape::XML::Node * node); const gchar * set_string (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + SPColor* set_color (SPColor* in, SPDocument * doc, Inkscape::XML::Node * node); const gchar * name (void) {return _name;} @@ -90,7 +106,6 @@ public: gchar const * get_tooltip (void) { return _desc; } }; - } /* namespace Extension */ } /* namespace Inkscape */ diff --git a/src/extension/paramfloat.cpp b/src/extension/paramfloat.cpp new file mode 100644 index 000000000..85a0bc4b9 --- /dev/null +++ b/src/extension/paramfloat.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include + +#include "extension.h" +#include "paramfloat.h" + +namespace Inkscape { +namespace Extension { + + +/** \brief Use the superclass' allocator and set the \c _value */ +ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, ext), _value(0.0), _min(0.0), _max(10.0) +{ + const char * defaultval = NULL; + if (sp_repr_children(xml) != NULL) + defaultval = sp_repr_children(xml)->content(); + if (defaultval != NULL) { + _value = atof(defaultval); + } + + const char * maxval = xml->attribute("max"); + if (maxval != NULL) + _max = atof(maxval); + + const char * minval = xml->attribute("min"); + if (minval != NULL) + _min = atof(minval); + + /* We're handling this by just killing both values */ + if (_max < _min) { + _max = 10.0; + _min = 0.0; + } + + gchar * pref_name = this->pref_name(); + _value = prefs_get_double_attribute(PREF_DIR, pref_name, _value); + g_free(pref_name); + + // std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; + + if (_value > _max) _value = _max; + if (_value < _min) _value = _min; + + return; +} + +/** \brief A function to set the \c _value + \param in The value to set to + \param doc A document that should be used to set the value. + \param node The node where the value may be placed + + This function sets the internal value, but it also sets the value + in the preferences structure. To put it in the right place, \c PREF_DIR + and \c pref_name() are used. +*/ +float +ParamFloat::set (float in, SPDocument * doc, Inkscape::XML::Node * node) +{ + _value = in; + if (_value > _max) _value = _max; + if (_value < _min) _value = _min; + + gchar * prefname = this->pref_name(); + prefs_set_double_attribute(PREF_DIR, prefname, _value); + g_free(prefname); + + return _value; +} + +/** \brief Return the value as a string */ +Glib::ustring * +ParamFloat::string (void) +{ + char startstring[G_ASCII_DTOSTR_BUF_SIZE]; + g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); + Glib::ustring * mystring = new Glib::ustring(startstring); + return mystring; +} + +/** \brief A class to make an adjustment that uses Extension params */ +class ParamFloatAdjustment : public Gtk::Adjustment { + /** The parameter to adjust */ + ParamFloat * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +public: + /** \brief Make the adjustment using an extension and the string + describing the parameter. */ + ParamFloatAdjustment (ParamFloat * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + Gtk::Adjustment(0.0, param->min(), param->max(), 0.1), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { + this->set_value(_pref->get(NULL, NULL) /* \todo fix */); + this->signal_value_changed().connect(sigc::mem_fun(this, &ParamFloatAdjustment::val_changed)); + return; + }; + + void val_changed (void); +}; /* class ParamFloatAdjustment */ + +/** \brief A function to respond to the value_changed signal from the + adjustment. + + This function just grabs the value from the adjustment and writes + it to the parameter. Very simple, but yet beautiful. +*/ +void +ParamFloatAdjustment::val_changed (void) +{ + //std::cout << "Value Changed to: " << this->get_value() << std::endl; + _pref->set(this->get_value(), _doc, _node); + if (_changeSignal != NULL) { + _changeSignal->emit(); + } + return; +} + +/** + \brief Creates a Float Adjustment for a float parameter + + Builds a hbox with a label and a float adjustment in it. +*/ +Gtk::Widget * +ParamFloat::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); + label->show(); + hbox->pack_start(*label, true, true); + + ParamFloatAdjustment * fadjust = Gtk::manage(new ParamFloatAdjustment(this, doc, node, changeSignal)); + Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 0.1, 1)); + spin->show(); + hbox->pack_start(*spin, false, false); + + hbox->show(); + + return dynamic_cast(hbox); +} + + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/paramfloat.h b/src/extension/paramfloat.h new file mode 100644 index 000000000..ab9d61177 --- /dev/null +++ b/src/extension/paramfloat.h @@ -0,0 +1,50 @@ +#ifndef __INK_EXTENSION_PARAMFLOAT_H +#define __INK_EXTENSION_PARAMFLOAT_H + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +class ParamFloat : public Parameter { +private: + /** \brief Internal value. */ + float _value; + float _min; + float _max; +public: + ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + /** \brief Returns \c _value */ + float get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } + float set (float in, SPDocument * doc, Inkscape::XML::Node * node); + float max (void) { return _max; } + float min (void) { return _min; } + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + Glib::ustring * string (void); +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMFLOAT_H */ + +/* + 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 : diff --git a/src/extension/paramint.cpp b/src/extension/paramint.cpp new file mode 100644 index 000000000..316d104ed --- /dev/null +++ b/src/extension/paramint.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include + +#include "extension.h" +#include "paramint.h" + +namespace Inkscape { +namespace Extension { + + +/** \brief Use the superclass' allocator and set the \c _value */ +ParamInt::ParamInt (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, ext), _value(0), _min(0), _max(10) +{ + const char * defaultval = NULL; + if (sp_repr_children(xml) != NULL) + defaultval = sp_repr_children(xml)->content(); + if (defaultval != NULL) { + _value = atoi(defaultval); + } + + const char * maxval = xml->attribute("max"); + if (maxval != NULL) + _max = atoi(maxval); + + const char * minval = xml->attribute("min"); + if (minval != NULL) + _min = atoi(minval); + + /* We're handling this by just killing both values */ + if (_max < _min) { + _max = 10; + _min = 0; + } + + gchar * pref_name = this->pref_name(); + _value = prefs_get_int_attribute(PREF_DIR, pref_name, _value); + g_free(pref_name); + + // std::cout << "New Int:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; + + if (_value > _max) _value = _max; + if (_value < _min) _value = _min; + + return; +} + +/** \brief A function to set the \c _value + \param in The value to set to + \param doc A document that should be used to set the value. + \param node The node where the value may be placed + + This function sets the internal value, but it also sets the value + in the preferences structure. To put it in the right place, \c PREF_DIR + and \c pref_name() are used. +*/ +int +ParamInt::set (int in, SPDocument * doc, Inkscape::XML::Node * node) +{ + _value = in; + if (_value > _max) _value = _max; + if (_value < _min) _value = _min; + + gchar * prefname = this->pref_name(); + prefs_set_int_attribute(PREF_DIR, prefname, _value); + g_free(prefname); + + return _value; +} + +/** \brief A class to make an adjustment that uses Extension params */ +class ParamIntAdjustment : public Gtk::Adjustment { + /** The parameter to adjust */ + ParamInt * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +public: + /** \brief Make the adjustment using an extension and the string + describing the parameter. */ + ParamIntAdjustment (ParamInt * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + Gtk::Adjustment(0.0, param->min(), param->max(), 1.0), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { + this->set_value(_pref->get(NULL, NULL) /* \todo fix */); + this->signal_value_changed().connect(sigc::mem_fun(this, &ParamIntAdjustment::val_changed)); + return; + }; + + void val_changed (void); +}; /* class ParamIntAdjustment */ + +/** \brief A function to respond to the value_changed signal from the + adjustment. + + This function just grabs the value from the adjustment and writes + it to the parameter. Very simple, but yet beautiful. +*/ +void +ParamIntAdjustment::val_changed (void) +{ + //std::cout << "Value Changed to: " << this->get_value() << std::endl; + _pref->set((int)this->get_value(), _doc, _node); + if (_changeSignal != NULL) { + _changeSignal->emit(); + } + return; +} + +/** + \brief Creates a Int Adjustment for a int parameter + + Builds a hbox with a label and a int adjustment in it. +*/ +Gtk::Widget * +ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); + label->show(); + hbox->pack_start(*label, true, true); + + ParamIntAdjustment * fadjust = Gtk::manage(new ParamIntAdjustment(this, doc, node, changeSignal)); + Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 1.0, 0)); + spin->show(); + hbox->pack_start(*spin, false, false); + + hbox->show(); + + return dynamic_cast(hbox); +} + +/** \brief Return the value as a string */ +Glib::ustring * +ParamInt::string (void) +{ + char startstring[32]; + sprintf(startstring, "%d", _value); + Glib::ustring * mystring = new Glib::ustring(startstring); + return mystring; +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/paramint.h b/src/extension/paramint.h new file mode 100644 index 000000000..2496b722f --- /dev/null +++ b/src/extension/paramint.h @@ -0,0 +1,50 @@ +#ifndef __INK_EXTENSION_PARAMINT_H +#define __INK_EXTENSION_PARAMINT_H + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +class ParamInt : public Parameter { +private: + /** \brief Internal value. */ + int _value; + int _min; + int _max; +public: + ParamInt (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + /** \brief Returns \c _value */ + int get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } + int set (int in, SPDocument * doc, Inkscape::XML::Node * node); + int max (void) { return _max; } + int min (void) { return _min; } + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + Glib::ustring * string (void); +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMINT_H */ + +/* + 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 : diff --git a/src/extension/paramstring.cpp b/src/extension/paramstring.cpp new file mode 100644 index 000000000..1b5b09ade --- /dev/null +++ b/src/extension/paramstring.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include + +#include "extension.h" +#include "paramstring.h" + +namespace Inkscape { +namespace Extension { + + +/** \brief Free the allocated data. */ +ParamString::~ParamString(void) +{ + g_free(_value); +} + +/** \brief A function to set the \c _value + \param in The value to set to + \param doc A document that should be used to set the value. + \param node The node where the value may be placed + + This function sets the internal value, but it also sets the value + in the preferences structure. To put it in the right place, \c PREF_DIR + and \c pref_name() are used. + + To copy the data into _value the old memory must be free'd first. + It is important to note that \c g_free handles \c NULL just fine. Then + the passed in value is duplicated using \c g_strdup(). +*/ +const gchar * +ParamString::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node) +{ + if (in == NULL) return NULL; /* Can't have NULL string */ + + if (_value != NULL) + g_free(_value); + _value = g_strdup(in); + + gchar * prefname = this->pref_name(); + prefs_set_string_attribute(PREF_DIR, prefname, _value); + g_free(prefname); + + return _value; +} + +/** \brief Return the value as a string */ +Glib::ustring * +ParamString::string (void) +{ + if (_value == NULL) + return new Glib::ustring(""); + + // FIXME: I think the string should NOT be escaped. Just put between "..." + // Otherwise \frac{1}{2} will become \\frac{1}{2} and then the LaTeX effect won't work.... + //gchar * esc = g_strescape(_value, NULL); + Glib::ustring escaped(_value); + //g_free(esc); + +#ifdef ESCAPE_DOLLAR_COMMANDLINE // escape the dollar sign + Glib::ustring::iterator i; + for (i = escaped.begin(); i != escaped.end(); ++i) { + if ( *i == '$') { + i = escaped.insert(i, '\\'); + i++; + } + } +#endif + + Glib::ustring * mystring = new Glib::ustring(""); + *mystring += "\""; + *mystring += escaped; + *mystring += "\""; + + return mystring; +} + +/** \brief Initialize the object, to do that, copy the data. */ +ParamString::ParamString (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, ext), _value(NULL) +{ + const char * defaultval = NULL; + if (sp_repr_children(xml) != NULL) + defaultval = sp_repr_children(xml)->content(); + + gchar * pref_name = this->pref_name(); + const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name); + g_free(pref_name); + + if (paramval != NULL) + defaultval = paramval; + if (defaultval != NULL) + _value = g_strdup(defaultval); + + return; +} + +/** \brief A special category of Gtk::Entry to handle string parameteres */ +class ParamStringEntry : public Gtk::Entry { +private: + ParamString * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +public: + /** \brief Build a string preference for the given parameter + \param pref Where to get the string from, and where to put it + when it changes. + */ + ParamStringEntry (ParamString * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { + if (_pref->get(NULL, NULL) != NULL) + this->set_text(Glib::ustring(_pref->get(NULL, NULL))); + this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); + }; + void changed_text (void); +}; + + +/** \brief Respond to the text box changing + + This function responds to the box changing by grabbing the value + from the text box and putting it in the parameter. +*/ +void +ParamStringEntry::changed_text (void) +{ + Glib::ustring data = this->get_text(); + _pref->set(data.c_str(), _doc, _node); + if (_changeSignal != NULL) { + _changeSignal->emit(); + } + return; +} + +/** + \brief Creates a text box for the string parameter + + Builds a hbox with a label and a text box in it. +*/ +Gtk::Widget * +ParamString::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); + label->show(); + hbox->pack_start(*label, false, false); + + ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); + textbox->show(); + hbox->pack_start(*textbox, true, true); + + hbox->show(); + + return dynamic_cast(hbox); +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/paramstring.h b/src/extension/paramstring.h new file mode 100644 index 000000000..c36d7ba6c --- /dev/null +++ b/src/extension/paramstring.h @@ -0,0 +1,49 @@ +#ifndef __INK_EXTENSION_PARAMSTRING_H +#define __INK_EXTENSION_PARAMSTRING_H + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +class ParamString : public Parameter { +private: + /** \brief Internal value. This should point to a string that has + been allocated in memory. And should be free'd. */ + gchar * _value; +public: + ParamString(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ~ParamString(void); + /** \brief Returns \c _value, with a \i const to protect it. */ + const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } + const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + Glib::ustring * string (void); +}; + + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMSTRING_H */ + +/* + 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 :