From 2c8b494c41e7258d1ae041fc28acc5f07816d5a4 Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Thu, 10 Jun 2010 18:06:51 +0200 Subject: [PATCH] Enable NSIS support for example module and rename it to mod_example --- synfig-core/configure.ac | 2 +- synfig-core/src/modules/Makefile.am | 18 +- synfig-core/src/modules/example/Makefile.am | 34 -- synfig-core/src/modules/example/filledrect.cpp | 586 --------------------- synfig-core/src/modules/example/filledrect.h | 81 --- synfig-core/src/modules/example/main.cpp | 61 --- synfig-core/src/modules/example/metaballs.cpp | 252 --------- synfig-core/src/modules/example/metaballs.h | 81 --- synfig-core/src/modules/example/simplecircle.cpp | 187 ------- synfig-core/src/modules/example/simplecircle.h | 73 --- synfig-core/src/modules/mod_example/Makefile.am | 38 ++ synfig-core/src/modules/mod_example/filledrect.cpp | 586 +++++++++++++++++++++ synfig-core/src/modules/mod_example/filledrect.h | 81 +++ synfig-core/src/modules/mod_example/main.cpp | 61 +++ synfig-core/src/modules/mod_example/metaballs.cpp | 252 +++++++++ synfig-core/src/modules/mod_example/metaballs.h | 81 +++ .../src/modules/mod_example/mod_example.nsh | 21 + .../src/modules/mod_example/simplecircle.cpp | 187 +++++++ synfig-core/src/modules/mod_example/simplecircle.h | 73 +++ .../src/modules/mod_example/unmod_example.nsh | 8 + synfig-core/src/modules/synfig_modules.cfg.in | 2 +- 21 files changed, 1399 insertions(+), 1366 deletions(-) delete mode 100644 synfig-core/src/modules/example/Makefile.am delete mode 100644 synfig-core/src/modules/example/filledrect.cpp delete mode 100644 synfig-core/src/modules/example/filledrect.h delete mode 100644 synfig-core/src/modules/example/main.cpp delete mode 100644 synfig-core/src/modules/example/metaballs.cpp delete mode 100644 synfig-core/src/modules/example/metaballs.h delete mode 100644 synfig-core/src/modules/example/simplecircle.cpp delete mode 100644 synfig-core/src/modules/example/simplecircle.h create mode 100644 synfig-core/src/modules/mod_example/Makefile.am create mode 100644 synfig-core/src/modules/mod_example/filledrect.cpp create mode 100644 synfig-core/src/modules/mod_example/filledrect.h create mode 100644 synfig-core/src/modules/mod_example/main.cpp create mode 100644 synfig-core/src/modules/mod_example/metaballs.cpp create mode 100644 synfig-core/src/modules/mod_example/metaballs.h create mode 100644 synfig-core/src/modules/mod_example/mod_example.nsh create mode 100644 synfig-core/src/modules/mod_example/simplecircle.cpp create mode 100644 synfig-core/src/modules/mod_example/simplecircle.h create mode 100644 synfig-core/src/modules/mod_example/unmod_example.nsh diff --git a/synfig-core/configure.ac b/synfig-core/configure.ac index 6907d20..1136ee5 100644 --- a/synfig-core/configure.ac +++ b/synfig-core/configure.ac @@ -683,7 +683,7 @@ src/modules/mod_png/Makefile src/modules/mod_ppm/Makefile src/modules/mod_yuv420p/Makefile src/modules/mod_svg/Makefile -src/modules/example/Makefile +src/modules/mod_example/Makefile src/tool/Makefile src/modules/synfig_modules.cfg examples/walk/Makefile diff --git a/synfig-core/src/modules/Makefile.am b/synfig-core/src/modules/Makefile.am index 4a40d3e..4d84b1e 100644 --- a/synfig-core/src/modules/Makefile.am +++ b/synfig-core/src/modules/Makefile.am @@ -27,19 +27,19 @@ SUBDIRS = \ mod_mng \ mod_svg \ mod_magickpp \ - example + mod_example EXTRA_DIST = \ untemplate.nsh \ template.nsh \ - example/simplecircle.h \ - example/simplecircle.cpp \ - example/filledrect.h \ - example/main.cpp \ - example/Makefile.am \ - example/filledrect.cpp \ - example/metaballs.cpp \ - example/metaballs.h \ + mod_example/simplecircle.h \ + mod_example/simplecircle.cpp \ + mod_example/filledrect.h \ + mod_example/main.cpp \ + mod_example/Makefile.am \ + mod_example/filledrect.cpp \ + mod_example/metaballs.cpp \ + mod_example/metaballs.h \ mod_mng/trgt_mng.h \ mod_mng/unmod_mng.nsh \ mod_mng/main.cpp \ diff --git a/synfig-core/src/modules/example/Makefile.am b/synfig-core/src/modules/example/Makefile.am deleted file mode 100644 index 1d38d74..0000000 --- a/synfig-core/src/modules/example/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -# $Id$ - -MAINTAINERCLEANFILES = \ - Makefile.in - -INCLUDES = \ - -I$(top_builddir) \ - -I$(top_srcdir)/src - - -moduledir = @MODULE_DIR@ - -module_LTLIBRARIES = libexample.la - -libexample_la_SOURCES = \ - main.cpp \ - simplecircle.cpp \ - simplecircle.h \ - filledrect.h \ - filledrect.cpp \ - metaballs.h \ - metaballs.cpp - -libexample_la_LIBADD = \ - ../../synfig/libsynfig.la \ - @SYNFIG_LIBS@ - -libexample_la_LDFLAGS = \ - -module \ - -no-undefined \ - -avoid-version - -libexample_la_CXXFLAGS = \ - @SYNFIG_CFLAGS@ diff --git a/synfig-core/src/modules/example/filledrect.cpp b/synfig-core/src/modules/example/filledrect.cpp deleted file mode 100644 index 329012f..0000000 --- a/synfig-core/src/modules/example/filledrect.cpp +++ /dev/null @@ -1,586 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file filledrect.cpp -** \brief Implementation of the "Rectangle" layer -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** Copyright (c) 2008 Chris Moore -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "filledrect.h" - -#endif - -/* === U S I N G =========================================================== */ - -using namespace etl; -using namespace std; -using namespace synfig; - -/* === G L O B A L S ======================================================= */ - -SYNFIG_LAYER_INIT(FilledRect); -SYNFIG_LAYER_SET_NAME(FilledRect,"filled_rectangle"); -SYNFIG_LAYER_SET_LOCAL_NAME(FilledRect,N_("Filled Rectangle")); -SYNFIG_LAYER_SET_CATEGORY(FilledRect,N_("Example")); -SYNFIG_LAYER_SET_VERSION(FilledRect,"0.1"); -SYNFIG_LAYER_SET_CVS_ID(FilledRect,"$Id$"); - -/* === P R O C E D U R E S ================================================= */ - -/* === M E T H O D S ======================================================= */ - -/* === E N T R Y P O I N T ================================================= */ - -FilledRect::FilledRect(): - Layer_Composite(1.0,Color::BLEND_STRAIGHT), - color(Color::black()), - point1(0,0), - point2(1,1), - feather_x(0), - feather_y(0), - bevel(0), - bevCircle(0) -{ -} - -bool -FilledRect::set_param(const String & param, const ValueBase &value) -{ - IMPORT(color); - IMPORT(point1); - IMPORT(point2); - IMPORT_PLUS(feather_x, if(feather_x<0)feather_x=0;); - IMPORT_PLUS(feather_y, if(feather_y<0)feather_y=0;); - IMPORT(bevel); - IMPORT(bevCircle); - - return Layer_Composite::set_param(param,value); -} - -ValueBase -FilledRect::get_param(const String ¶m)const -{ - EXPORT(color); - EXPORT(point1); - EXPORT(point2); - EXPORT(feather_x); - EXPORT(feather_y); - EXPORT(bevel); - EXPORT(bevCircle); - - EXPORT_NAME(); - EXPORT_VERSION(); - - return Layer_Composite::get_param(param); -} - -Layer::Vocab -FilledRect::get_param_vocab()const -{ - Layer::Vocab ret(Layer_Composite::get_param_vocab()); - - ret.push_back(ParamDesc("color") - .set_local_name(_("Color")) - ); - - ret.push_back(ParamDesc("point1") - .set_local_name(_("Point 1")) - .set_box("point2") - ); - - ret.push_back(ParamDesc("point2") - .set_local_name(_("Point 2")) - ); - - ret.push_back(ParamDesc("feather_x") - .set_local_name(_("Feather X")) - ); - - ret.push_back(ParamDesc("feather_y") - .set_local_name(_("Feather Y")) - ); - - ret.push_back(ParamDesc("bevel") - .set_local_name(_("Bevel")) - ); - - ret.push_back(ParamDesc("bevCircle") - .set_local_name(_("Keep Bevel Circular")) - ); - - return ret; -} - -synfig::Layer::Handle -FilledRect::hit_check(synfig::Context context, const synfig::Point &point)const -{ - Color clr; - Real amt; - - if (!get_color(point,clr,amt)) - return context.hit_check(point); - - synfig::Layer::Handle tmp; - - if (get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(point))) - return tmp; - - if (Color::is_onto(get_blend_method()) && !(context.hit_check(point))) - return 0; - - return const_cast(this); -} - -bool -FilledRect::get_color(const Point &pos, Color &out, Real &outamount) const -{ - Point p[2] = {point1,point2}; - Real swap; - - if(p[0][0] > p[1][0]) - { - swap = p[0][0]; - p[0][0] = p[1][0]; - p[1][0] = swap; - } - - if(p[0][1] > p[1][1]) - { - swap = p[0][1]; - p[0][1] = p[1][1]; - p[1][1] = swap; - } - - /* - p[0][0] -= feather_x; - p[1][0] += feather_x; - p[0][1] -= feather_y; - p[1][1] += feather_y;*/ - const Real w = p[1][0] - p[0][0]; - const Real h = p[1][1] - p[0][1]; - - if(pos[0] >= p[0][0] && pos[0] <= p[1][0] && pos[1] >= p[0][1] && pos[1] <= p[1][1]) - { - Real value = 1; - - if(feather_x > 0) - { - Real xdist = pos[0] - p[0][0]; - xdist = min(xdist,p[1][0]-pos[0]); - - if(xdist < feather_x) - { - value = xdist/feather_x; - } - } - - if(feather_y > 0) - { - Real ydist = pos[1]-p[0][1]; - ydist = min(ydist,p[1][1]-pos[1]); - - if(ydist < feather_y) - { - value = min(value,(ydist/feather_y)); - } - } - - //if we're beveled then check with ellipse code... - if(bevel > 0) - { - const Real bev = (bevel > 1) ? 1 : bevel; - const Real bevx = bevCircle ? min(w*bev/2,h*bev/2) : w*bev/2; - const Real bevy = bevCircle ? min(w*bev/2,h*bev/2) : h*bev/2;; - - Vector v(0,0); - bool in = false; - - //based on which quarter it is in (and because it's x/y symmetric) get a positive vector (x/y) - if(pos[0] < p[0][0] + bevx) - { - if(pos[1] < p[0][1] + bevy) - { - v[0] = p[0][0] + bevx - pos[0]; - v[1] = p[0][1] + bevy - pos[1]; - in = true; - }else if(pos[1] > p[1][1] - bevy) - { - v[0] = p[0][0] + bevx - pos[0]; - v[1] = pos[1] - (p[1][1] - bevy); - in = true; - } - } - else if(pos[0] > p[1][0] - bevx) - { - if(pos[1] < p[0][1] + bevy) - { - v[0] = pos[0] - (p[1][0] - bevx); - v[1] = p[0][1] + bevy - pos[1]; - in = true; - }else if(pos[1] > p[1][1] - bevy) - { - v[0] = pos[0] - (p[1][0] - bevx); - v[1] = pos[1] - (p[1][1] - bevy); - in = true; - } - } - - //if it's inside a bevelled block - if(in) - { - const Vector scale(bevx,bevy); - - Vector vc(v[0]/scale[0],v[1]/scale[1]); - Real d = vc.mag(); - - //if it's inside the ellipse - if(d < 1) - { - Real val = atan2(vc[1],vc[0]); - val /= (PI/2); //< will always be (0,pi/2) because both components are positive - - Real fthx=1,fthy=1; - - //change d into distance away from edge - d = 1 - d; - - if(feather_x > 0) - { - if(scale[0] < feather_x) - { - fthy = scale[0]/feather_x; - } - - if(d*scale[0] < feather_x) - { - fthx = d*scale[0]/feather_x; - } - } - - if(feather_y > 0) - { - if(scale[1] < feather_y) - { - fthx = min(fthx,scale[1]/feather_y); - } - - if(d*scale[1] < feather_y) - { - fthy = min(fthy,d*scale[1]/feather_y); - } - } - - //interpolate - outamount = min(value,((1-val)*fthx + val*fthy)) * get_amount(); - out = color; - return true; - - }else return false; - } - } - - outamount = value * get_amount(); - out = color; - - return true; - }else - return false; -} - -Color -FilledRect::get_color(Context context, const Point &pos)const -{ - Color clr; - Real amt; - - if(get_color(pos,clr,amt)) - { - if(amt==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - return clr; - else - return Color::blend(clr,context.get_color(pos),amt,get_blend_method()); - } - else - return context.get_color(pos); -} - -bool -FilledRect::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - // Width and Height of a pixel - const Point br(renddesc.get_br()), tl(renddesc.get_tl()); - const int w = renddesc.get_w(), h = renddesc.get_h(); - - Real wpp = (br[0]-tl[0])/w; - Real hpp = (br[1]-tl[1])/h; - //const Real xneg = wpp<0?-1:1; - //const Real yneg = hpp<0?-1:1; - - //the bounds of the rectangle - Point p[2] = {point1,point2}; - - if((p[0][0] > p[1][0]) ^ (wpp < 0)) - { - swap(p[0][0],p[1][0]); - } - - if((p[0][1] > p[1][1]) ^ (hpp < 0)) - { - swap(p[0][1],p[1][1]); - } - - /*p[0][0] -= xneg*feather_x; - p[1][0] += xneg*feather_x; - p[0][1] -= yneg*feather_y; - p[1][1] += yneg*feather_y;*/ - - //the integer coordinates - int y_start = (int)((p[0][1] - tl[1])/hpp +.5); //round start up - int x_start = (int)((p[0][0] - tl[0])/wpp +.5); - int y_end = (int)((p[1][1] - tl[1])/hpp +.5); //and ends up - int x_end = (int)((p[1][0] - tl[0])/wpp +.5); - - y_start = max(0,y_start); - x_start = max(0,x_start); - y_end = min(h,y_end); - x_end = min(w,x_end); - - SuperCallback supercb(cb,0,9000,10000); - - if(y_start >= h || x_start > w || x_end < 0 || y_end < 0) - { - if(!context.accelerated_render(surface,quality,renddesc,&supercb)) - { - if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__)); - return false; - } - - return true; - } - - Real xf_start = tl[0] + x_start*wpp; - Point pos(xf_start,tl[1] + y_start*hpp); - - Color clr = Color::black(); - Real amt; - - if(!context.accelerated_render(surface,quality,renddesc,&supercb)) - { - if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__)); - return false; - } - - for(int y = y_start; y < y_end; y++, pos[1] += hpp) - { - pos[0] = xf_start; - for(int x = x_start; x < x_end; x++, pos[0] += wpp) - { - if(get_color(pos,clr,amt)) - { - if(amt==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - (*surface)[y][x] = clr; - else - (*surface)[y][x] = Color::blend(clr,(*surface)[y][x],amt,get_blend_method()); - } - } - } - - return true; - -#if 0 - //faster version but much more complex - //the floating point - Real y1,y2,y3; - Real x1,x2,x3; - Real dx1,dx2; //reversed in 3rd y section, not used in 2nd - - //the transparent - Real fx = 0, fy = 0; - Real dfx,dfy; - - //Get the slopes of the lines we need to worry about - if(feather_x) - { - dfx = 1/(fxsize); - - if(fxsize*2 > xfw) - { - x1 = xfw/2; - x2 = 0; - x3 = xfw; - }else - { - x1 = fxsize; - x2 = xfw - fxsize; - x3 = xfw; - } - }else - { - fx = 1; - dfx = 0; - x1=0; - x2=xfw; - x3=0; - } - - if(feather_y) - { - dfy = 1/(fysize); - - if(fysize*2 > yfh) - { - y1 = yfh/2; - y2 = 0; - y3 = yfh; - }else - { - y1 = fysize; - y2 = yfh - fysize; - y3 = yfh; - } - - dx1 = ph*feather_x/feather_y; - dx2 = -2*dx1; - - }else - { - fy = 1; - dfy = 0; - y1=0; - y2=yfh; - y3=0; - } - - fy = yf*dfy; - - int x,y; - Real value = 0; - SuperCallback supercb(cb,0,9000,10000); - Surface::pen p; - - Real tx1 = 0,tx2 = - for(y = y_start;yf < y1; y++,yf++,fy+=dfy, tx1+=dx1) - { - fx = xf*dfx; - - p = surface->get_pen(x_start,y); - for(; xf < x1; xf++,p.inc_x(), fx+=dfx) - { - //we are in the x portion... use fx - value = fx*get_amount(); - if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - p.put_value(color); - else - p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); - } - - for(;xf < x2; xf++,p.inc_x()) - { - //we are now in y... use fy - value = fy*get_amount(); - if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - p.put_value(color); - else - p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); - } - - fx = xfw?(xfw - xf)/xfw:1; - for(;xf < x3 && ; xf++,p.inc_x(), fx-=dfx) - { - //we are in the x portion... use fx - value = max(0,fx*get_amount()); - if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - p.put_value(color); - else - p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); - } - } - - x1 = - for(;fy < 1.0; y++,yf++,fy+=dfy) - { - fx = xf*dfx; - - p = surface->get_pen(x_start,y); - for(; xf < x1; xf++,p.inc_x(), fx+=dfx) - { - //we are in the x portion... use fx - value = fx*get_amount(); - if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - p.put_value(color); - else - p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); - } - - for(;xf < x2; xf++,p.inc_x()) - { - //we are now in y... use fy - value = fy*get_amount(); - if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - p.put_value(color); - else - p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); - } - - fx = xfw?(xfw - xf)/xfw:1; - for(;xf < x3 && ; xf++,p.inc_x(), fx-=dfx) - { - //we are in the x portion... use fx - value = max(0,fx*get_amount()); - if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - p.put_value(color); - else - p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); - } - } - - for() - { - for(int x = x_start; x < x_end; x++) - { - - } - } - -#endif - - // Mark our progress as finished - if(cb && !cb->amount_complete(10000,10000)) - return false; - - return true; -} diff --git a/synfig-core/src/modules/example/filledrect.h b/synfig-core/src/modules/example/filledrect.h deleted file mode 100644 index b540105..0000000 --- a/synfig-core/src/modules/example/filledrect.h +++ /dev/null @@ -1,81 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file filledrect.h -** \brief Header file for implementation of the "Rectangle" layer -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_FILLEDRECT_H -#define __SYNFIG_FILLEDRECT_H - -/* === H E A D E R S ======================================================= */ - -#include -#include -#include -#include -#include - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -class FilledRect : public synfig::Layer_Composite -{ - SYNFIG_LAYER_MODULE_EXT - -private: - - synfig::Color color; - - synfig::Point point1; - synfig::Point point2; - - synfig::Real feather_x; - synfig::Real feather_y; - - synfig::Real bevel; - - bool bevCircle; - - bool get_color(const synfig::Point &pos, synfig::Color &out, synfig::Real &outamount)const; - -public: - - FilledRect(); - - virtual bool set_param(const synfig::String & param, const synfig::ValueBase &value); - - virtual synfig::ValueBase get_param(const synfig::String & param)const; - - virtual synfig::Color get_color(synfig::Context context, const synfig::Point &pos)const; - - virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; - - virtual Vocab get_param_vocab()const; - - virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; -}; // END of class FilledRect - -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-core/src/modules/example/main.cpp b/synfig-core/src/modules/example/main.cpp deleted file mode 100644 index 2a57384..0000000 --- a/synfig-core/src/modules/example/main.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file example/main.cpp -** \brief Template Header -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -** -** === N O T E S =========================================================== -** -** ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#define SYNFIG_MODULE - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include "simplecircle.h" -#include "filledrect.h" -#include "metaballs.h" - -#endif - -/* === E N T R Y P O I N T ================================================= */ - -MODULE_DESC_BEGIN(example) - MODULE_NAME("Example Module") - MODULE_DESCRIPTION("A dummy module that serves as a starting point for writing other modules.") - MODULE_AUTHOR("Robert B. Quattlebaum") - MODULE_VERSION("1.0") - MODULE_COPYRIGHT(SYNFIG_COPYRIGHT) -MODULE_DESC_END - -MODULE_INVENTORY_BEGIN(example) - BEGIN_LAYERS - LAYER(SimpleCircle) - LAYER(FilledRect) - LAYER(Metaballs) - END_LAYERS -MODULE_INVENTORY_END diff --git a/synfig-core/src/modules/example/metaballs.cpp b/synfig-core/src/modules/example/metaballs.cpp deleted file mode 100644 index 0cfa6c3..0000000 --- a/synfig-core/src/modules/example/metaballs.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file metaballs.cpp -** \brief Implementation of the "Metaballs" layer -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "metaballs.h" - -#endif - -/* === U S I N G =========================================================== */ - -using namespace etl; -using namespace std; -using namespace synfig; - -/* === G L O B A L S ======================================================= */ - -SYNFIG_LAYER_INIT(Metaballs); -SYNFIG_LAYER_SET_NAME(Metaballs,"metaballs"); -SYNFIG_LAYER_SET_LOCAL_NAME(Metaballs,N_("Metaballs")); -SYNFIG_LAYER_SET_CATEGORY(Metaballs,N_("Example")); -SYNFIG_LAYER_SET_VERSION(Metaballs,"0.1"); -SYNFIG_LAYER_SET_CVS_ID(Metaballs,"$Id$"); - -/* === P R O C E D U R E S ================================================= */ - -/* === M E T H O D S ======================================================= */ - -/* === E N T R Y P O I N T ================================================= */ - -Metaballs::Metaballs(): - Layer_Composite(1.0,Color::BLEND_STRAIGHT), - gradient(Color::black(), Color::white()), - threshold(0), - threshold2(1), - positive(false) -{ - centers.push_back(Point( 0, -1.5)); radii.push_back(2.5); weights.push_back(1); - centers.push_back(Point(-2, 1)); radii.push_back(2.5); weights.push_back(1); - centers.push_back(Point( 2, 1)); radii.push_back(2.5); weights.push_back(1); -} - -bool -Metaballs::set_param(const String & param, const ValueBase &value) -{ - if( param=="centers" && value.same_type_as(centers)) - { - centers = value; - return true; - } - - if( param=="weights" && value.same_type_as(weights)) - { - weights = value; - return true; - } - - if( param=="radii" && value.same_type_as(radii)) - { - radii = value; - return true; - } - - IMPORT(gradient); - IMPORT(threshold); - IMPORT(threshold2); - IMPORT(positive); - - return Layer_Composite::set_param(param,value); -} - -ValueBase -Metaballs::get_param(const String ¶m)const -{ - EXPORT(gradient); - - EXPORT(radii); - EXPORT(weights); - EXPORT(centers); - EXPORT(threshold); - EXPORT(threshold2); - EXPORT(positive); - - EXPORT_NAME(); - EXPORT_VERSION(); - - return Layer_Composite::get_param(param); -} - -Layer::Vocab -Metaballs::get_param_vocab()const -{ - Layer::Vocab ret(Layer_Composite::get_param_vocab()); - - ret.push_back(ParamDesc("gradient") - .set_local_name(_("Gradient")) - ); - - ret.push_back(ParamDesc("centers") - .set_local_name(_("Points")) - ); - - ret.push_back(ParamDesc("radii") - .set_local_name(_("Radii")) - ); - - ret.push_back(ParamDesc("weights") - .set_local_name(_("Weights")) - ); - - ret.push_back(ParamDesc("threshold") - .set_local_name(_("Gradient Left")) - ); - - ret.push_back(ParamDesc("threshold2") - .set_local_name(_("Gradient Right")) - ); - - ret.push_back(ParamDesc("positive") - .set_local_name(_("Positive Only")) - ); - - return ret; -} - -synfig::Layer::Handle -Metaballs::hit_check(synfig::Context context, const synfig::Point &point)const -{ - Real density(totaldensity(point)); - - if (density <= 0 || density > 1 || get_amount() == 0) - return context.hit_check(point); - - synfig::Layer::Handle tmp; - - if (get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(point))) - return tmp; - - if (Color::is_onto(get_blend_method()) && !(context.hit_check(point))) - return 0; - - return const_cast(this); -} - -Real -Metaballs::densityfunc(const synfig::Point &p, const synfig::Point &c, Real R)const -{ - const Real dx = p[0] - c[0]; - const Real dy = p[1] - c[1]; - - const Real n = (1 - (dx*dx + dy*dy)/(R*R)); - if (positive && n < 0) return 0; - return (n*n*n); - - /* - f(d) = (1 - d^2)^3 - f'(d) = -6d * (1 - d^2)^2 - - could use this too... - f(d) = (1 - d^2)^2 - f'(d) = -6d * (1 - d^2) - */ -} - -Real -Metaballs::totaldensity(const Point &pos)const -{ - Real density = 0; - - //sum up weighted functions - for(unsigned int i=0;ierror(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__)); - return false; - } - - for(int y = 0; y < h; y++, pos[1] += ph) - { - pos[0] = tl[0]; - for(int x = 0; x < w; x++, pos[0] += pw) - (*surface)[y][x] = Color::blend(gradient(totaldensity(pos)),(*surface)[y][x],get_amount(),get_blend_method()); - } - - // Mark our progress as finished - if(cb && !cb->amount_complete(10000,10000)) - return false; - - return true; -} diff --git a/synfig-core/src/modules/example/metaballs.h b/synfig-core/src/modules/example/metaballs.h deleted file mode 100644 index d9ae649..0000000 --- a/synfig-core/src/modules/example/metaballs.h +++ /dev/null @@ -1,81 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file metaballs.h -** \brief Header file for implementation of the "Metaballs" layer -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_METABALLS_H -#define __SYNFIG_METABALLS_H - -/* === H E A D E R S ======================================================= */ - -#include -#include -#include -#include -#include - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ -class Metaballs : public synfig::Layer_Composite -{ - SYNFIG_LAYER_MODULE_EXT - -private: - - synfig::Gradient gradient; - - std::vector centers; - std::vector radii; - std::vector weights; - - synfig::Real threshold; - synfig::Real threshold2; - - bool positive; - - synfig::Real densityfunc(const synfig::Point &p, const synfig::Point &c, synfig::Real R)const; - - synfig::Real totaldensity(const synfig::Point &pos)const; - -public: - - Metaballs(); - - virtual bool set_param(const synfig::String & param, const synfig::ValueBase &value); - - virtual synfig::ValueBase get_param(const synfig::String & param)const; - - virtual synfig::Color get_color(synfig::Context context, const synfig::Point &pos)const; - - virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; - - virtual Vocab get_param_vocab()const; - - virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; -}; // END of class Metaballs - -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-core/src/modules/example/simplecircle.cpp b/synfig-core/src/modules/example/simplecircle.cpp deleted file mode 100644 index e2eb896..0000000 --- a/synfig-core/src/modules/example/simplecircle.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file simplecircle.cpp -** \brief Implementation of the "Simple Circle" layer -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** Copyright (c) 2008 Chris Moore -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "simplecircle.h" - -#endif - -/* === U S I N G =========================================================== */ - -using namespace etl; -using namespace std; -using namespace synfig; - -/* === G L O B A L S ======================================================= */ - -SYNFIG_LAYER_INIT(SimpleCircle); -SYNFIG_LAYER_SET_NAME(SimpleCircle,"simple_circle"); -SYNFIG_LAYER_SET_LOCAL_NAME(SimpleCircle,N_("Simple Circle")); -SYNFIG_LAYER_SET_CATEGORY(SimpleCircle,N_("Example")); -SYNFIG_LAYER_SET_VERSION(SimpleCircle,"0.1"); -SYNFIG_LAYER_SET_CVS_ID(SimpleCircle,"$Id$"); - -/* === P R O C E D U R E S ================================================= */ - -/* === M E T H O D S ======================================================= */ - -/* === E N T R Y P O I N T ================================================= */ - -SimpleCircle::SimpleCircle(): - Layer_Composite(1.0,Color::BLEND_STRAIGHT), - color(Color::black()), - center(0,0), - radius(0.5) -{ -} - -bool -SimpleCircle::set_param(const String & param, const ValueBase &value) -{ - IMPORT(color); - IMPORT(center); - IMPORT(radius); - - return Layer_Composite::set_param(param,value); -} - -ValueBase -SimpleCircle::get_param(const String ¶m)const -{ - EXPORT(color); - EXPORT(center); - EXPORT(radius); - - EXPORT_NAME(); - EXPORT_VERSION(); - - return Layer_Composite::get_param(param); -} - -Layer::Vocab -SimpleCircle::get_param_vocab()const -{ - Layer::Vocab ret(Layer_Composite::get_param_vocab()); - - ret.push_back(ParamDesc("color") - .set_local_name(_("Color")) - ); - - ret.push_back(ParamDesc("center") - .set_local_name(_("Center")) - ); - - ret.push_back(ParamDesc("radius") - .set_local_name(_("Radius")) - .set_description(_("This is the radius of the circle")) - .set_origin("center") - ); - - return ret; -} - -Color -SimpleCircle::get_color(Context context, const Point &pos)const -{ - - if((pos-center).mag()(this); - else - return context.hit_check(pos); -} - -/* -bool -SimpleCircle::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - { - // Mark our progress as starting - if(cb && !cb->amount_complete(0,1000)) - return false; - - surface->set_wh(renddesc.get_w(),renddesc.get_h()); - surface->fill(color); - - // Mark our progress as finished - if(cb && !cb->amount_complete(1000,1000)) - return false; - - return true; - } - - SuperCallback supercb(cb,0,9500,10000); - - if(!context.accelerated_render(surface,quality,renddesc,&supercb)) - return false; - - int x,y; - - Surface::alpha_pen apen(surface->begin()); - - apen.set_value(color); - apen.set_alpha(get_amount()); - apen.set_blend_method(get_blend_method()); - - for(y=0;yamount_complete(10000,10000)) - return false; - - return true; -} -*/ diff --git a/synfig-core/src/modules/example/simplecircle.h b/synfig-core/src/modules/example/simplecircle.h deleted file mode 100644 index 48c555c..0000000 --- a/synfig-core/src/modules/example/simplecircle.h +++ /dev/null @@ -1,73 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file simplecircle.h -** \brief Header file for implementation of the "Simple Circle" layer -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_SIMPLECIRCLE_H -#define __SYNFIG_SIMPLECIRCLE_H - -/* === H E A D E R S ======================================================= */ - -#include -#include -#include -#include -#include - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -class SimpleCircle : public synfig::Layer_Composite -{ - SYNFIG_LAYER_MODULE_EXT - -private: - - synfig::Color color; - - synfig::Point center; - - synfig::Real radius; - -public: - - SimpleCircle(); - - virtual bool set_param(const synfig::String & param, const synfig::ValueBase &value); - - virtual synfig::ValueBase get_param(const synfig::String & param)const; - - virtual synfig::Color get_color(synfig::Context context, const synfig::Point &pos)const; - - //virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; - - synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; - - virtual Vocab get_param_vocab()const; -}; // END of class SimpleCircle - -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-core/src/modules/mod_example/Makefile.am b/synfig-core/src/modules/mod_example/Makefile.am new file mode 100644 index 0000000..bd4566f --- /dev/null +++ b/synfig-core/src/modules/mod_example/Makefile.am @@ -0,0 +1,38 @@ +# $Id$ + +MAINTAINERCLEANFILES = \ + Makefile.in + +INCLUDES = \ + -I$(top_builddir) \ + -I$(top_srcdir)/src + + +moduledir = @MODULE_DIR@ + +module_LTLIBRARIES = libmod_example.la + +libmod_example_la_SOURCES = \ + main.cpp \ + simplecircle.cpp \ + simplecircle.h \ + filledrect.h \ + filledrect.cpp \ + metaballs.h \ + metaballs.cpp + +libmod_example_la_LIBADD = \ + ../../synfig/libsynfig.la \ + @SYNFIG_LIBS@ + +libmod_example_la_LDFLAGS = \ + -module \ + -no-undefined \ + -avoid-version + +libmod_example_la_CXXFLAGS = \ + @SYNFIG_CFLAGS@ + +EXTRA_DIST = \ + mod_example.nsh \ + unmod_example.nsh diff --git a/synfig-core/src/modules/mod_example/filledrect.cpp b/synfig-core/src/modules/mod_example/filledrect.cpp new file mode 100644 index 0000000..329012f --- /dev/null +++ b/synfig-core/src/modules/mod_example/filledrect.cpp @@ -0,0 +1,586 @@ +/* === S Y N F I G ========================================================= */ +/*! \file filledrect.cpp +** \brief Implementation of the "Rectangle" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "filledrect.h" + +#endif + +/* === U S I N G =========================================================== */ + +using namespace etl; +using namespace std; +using namespace synfig; + +/* === G L O B A L S ======================================================= */ + +SYNFIG_LAYER_INIT(FilledRect); +SYNFIG_LAYER_SET_NAME(FilledRect,"filled_rectangle"); +SYNFIG_LAYER_SET_LOCAL_NAME(FilledRect,N_("Filled Rectangle")); +SYNFIG_LAYER_SET_CATEGORY(FilledRect,N_("Example")); +SYNFIG_LAYER_SET_VERSION(FilledRect,"0.1"); +SYNFIG_LAYER_SET_CVS_ID(FilledRect,"$Id$"); + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +/* === E N T R Y P O I N T ================================================= */ + +FilledRect::FilledRect(): + Layer_Composite(1.0,Color::BLEND_STRAIGHT), + color(Color::black()), + point1(0,0), + point2(1,1), + feather_x(0), + feather_y(0), + bevel(0), + bevCircle(0) +{ +} + +bool +FilledRect::set_param(const String & param, const ValueBase &value) +{ + IMPORT(color); + IMPORT(point1); + IMPORT(point2); + IMPORT_PLUS(feather_x, if(feather_x<0)feather_x=0;); + IMPORT_PLUS(feather_y, if(feather_y<0)feather_y=0;); + IMPORT(bevel); + IMPORT(bevCircle); + + return Layer_Composite::set_param(param,value); +} + +ValueBase +FilledRect::get_param(const String ¶m)const +{ + EXPORT(color); + EXPORT(point1); + EXPORT(point2); + EXPORT(feather_x); + EXPORT(feather_y); + EXPORT(bevel); + EXPORT(bevCircle); + + EXPORT_NAME(); + EXPORT_VERSION(); + + return Layer_Composite::get_param(param); +} + +Layer::Vocab +FilledRect::get_param_vocab()const +{ + Layer::Vocab ret(Layer_Composite::get_param_vocab()); + + ret.push_back(ParamDesc("color") + .set_local_name(_("Color")) + ); + + ret.push_back(ParamDesc("point1") + .set_local_name(_("Point 1")) + .set_box("point2") + ); + + ret.push_back(ParamDesc("point2") + .set_local_name(_("Point 2")) + ); + + ret.push_back(ParamDesc("feather_x") + .set_local_name(_("Feather X")) + ); + + ret.push_back(ParamDesc("feather_y") + .set_local_name(_("Feather Y")) + ); + + ret.push_back(ParamDesc("bevel") + .set_local_name(_("Bevel")) + ); + + ret.push_back(ParamDesc("bevCircle") + .set_local_name(_("Keep Bevel Circular")) + ); + + return ret; +} + +synfig::Layer::Handle +FilledRect::hit_check(synfig::Context context, const synfig::Point &point)const +{ + Color clr; + Real amt; + + if (!get_color(point,clr,amt)) + return context.hit_check(point); + + synfig::Layer::Handle tmp; + + if (get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(point))) + return tmp; + + if (Color::is_onto(get_blend_method()) && !(context.hit_check(point))) + return 0; + + return const_cast(this); +} + +bool +FilledRect::get_color(const Point &pos, Color &out, Real &outamount) const +{ + Point p[2] = {point1,point2}; + Real swap; + + if(p[0][0] > p[1][0]) + { + swap = p[0][0]; + p[0][0] = p[1][0]; + p[1][0] = swap; + } + + if(p[0][1] > p[1][1]) + { + swap = p[0][1]; + p[0][1] = p[1][1]; + p[1][1] = swap; + } + + /* + p[0][0] -= feather_x; + p[1][0] += feather_x; + p[0][1] -= feather_y; + p[1][1] += feather_y;*/ + const Real w = p[1][0] - p[0][0]; + const Real h = p[1][1] - p[0][1]; + + if(pos[0] >= p[0][0] && pos[0] <= p[1][0] && pos[1] >= p[0][1] && pos[1] <= p[1][1]) + { + Real value = 1; + + if(feather_x > 0) + { + Real xdist = pos[0] - p[0][0]; + xdist = min(xdist,p[1][0]-pos[0]); + + if(xdist < feather_x) + { + value = xdist/feather_x; + } + } + + if(feather_y > 0) + { + Real ydist = pos[1]-p[0][1]; + ydist = min(ydist,p[1][1]-pos[1]); + + if(ydist < feather_y) + { + value = min(value,(ydist/feather_y)); + } + } + + //if we're beveled then check with ellipse code... + if(bevel > 0) + { + const Real bev = (bevel > 1) ? 1 : bevel; + const Real bevx = bevCircle ? min(w*bev/2,h*bev/2) : w*bev/2; + const Real bevy = bevCircle ? min(w*bev/2,h*bev/2) : h*bev/2;; + + Vector v(0,0); + bool in = false; + + //based on which quarter it is in (and because it's x/y symmetric) get a positive vector (x/y) + if(pos[0] < p[0][0] + bevx) + { + if(pos[1] < p[0][1] + bevy) + { + v[0] = p[0][0] + bevx - pos[0]; + v[1] = p[0][1] + bevy - pos[1]; + in = true; + }else if(pos[1] > p[1][1] - bevy) + { + v[0] = p[0][0] + bevx - pos[0]; + v[1] = pos[1] - (p[1][1] - bevy); + in = true; + } + } + else if(pos[0] > p[1][0] - bevx) + { + if(pos[1] < p[0][1] + bevy) + { + v[0] = pos[0] - (p[1][0] - bevx); + v[1] = p[0][1] + bevy - pos[1]; + in = true; + }else if(pos[1] > p[1][1] - bevy) + { + v[0] = pos[0] - (p[1][0] - bevx); + v[1] = pos[1] - (p[1][1] - bevy); + in = true; + } + } + + //if it's inside a bevelled block + if(in) + { + const Vector scale(bevx,bevy); + + Vector vc(v[0]/scale[0],v[1]/scale[1]); + Real d = vc.mag(); + + //if it's inside the ellipse + if(d < 1) + { + Real val = atan2(vc[1],vc[0]); + val /= (PI/2); //< will always be (0,pi/2) because both components are positive + + Real fthx=1,fthy=1; + + //change d into distance away from edge + d = 1 - d; + + if(feather_x > 0) + { + if(scale[0] < feather_x) + { + fthy = scale[0]/feather_x; + } + + if(d*scale[0] < feather_x) + { + fthx = d*scale[0]/feather_x; + } + } + + if(feather_y > 0) + { + if(scale[1] < feather_y) + { + fthx = min(fthx,scale[1]/feather_y); + } + + if(d*scale[1] < feather_y) + { + fthy = min(fthy,d*scale[1]/feather_y); + } + } + + //interpolate + outamount = min(value,((1-val)*fthx + val*fthy)) * get_amount(); + out = color; + return true; + + }else return false; + } + } + + outamount = value * get_amount(); + out = color; + + return true; + }else + return false; +} + +Color +FilledRect::get_color(Context context, const Point &pos)const +{ + Color clr; + Real amt; + + if(get_color(pos,clr,amt)) + { + if(amt==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + return clr; + else + return Color::blend(clr,context.get_color(pos),amt,get_blend_method()); + } + else + return context.get_color(pos); +} + +bool +FilledRect::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const +{ + // Width and Height of a pixel + const Point br(renddesc.get_br()), tl(renddesc.get_tl()); + const int w = renddesc.get_w(), h = renddesc.get_h(); + + Real wpp = (br[0]-tl[0])/w; + Real hpp = (br[1]-tl[1])/h; + //const Real xneg = wpp<0?-1:1; + //const Real yneg = hpp<0?-1:1; + + //the bounds of the rectangle + Point p[2] = {point1,point2}; + + if((p[0][0] > p[1][0]) ^ (wpp < 0)) + { + swap(p[0][0],p[1][0]); + } + + if((p[0][1] > p[1][1]) ^ (hpp < 0)) + { + swap(p[0][1],p[1][1]); + } + + /*p[0][0] -= xneg*feather_x; + p[1][0] += xneg*feather_x; + p[0][1] -= yneg*feather_y; + p[1][1] += yneg*feather_y;*/ + + //the integer coordinates + int y_start = (int)((p[0][1] - tl[1])/hpp +.5); //round start up + int x_start = (int)((p[0][0] - tl[0])/wpp +.5); + int y_end = (int)((p[1][1] - tl[1])/hpp +.5); //and ends up + int x_end = (int)((p[1][0] - tl[0])/wpp +.5); + + y_start = max(0,y_start); + x_start = max(0,x_start); + y_end = min(h,y_end); + x_end = min(w,x_end); + + SuperCallback supercb(cb,0,9000,10000); + + if(y_start >= h || x_start > w || x_end < 0 || y_end < 0) + { + if(!context.accelerated_render(surface,quality,renddesc,&supercb)) + { + if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__)); + return false; + } + + return true; + } + + Real xf_start = tl[0] + x_start*wpp; + Point pos(xf_start,tl[1] + y_start*hpp); + + Color clr = Color::black(); + Real amt; + + if(!context.accelerated_render(surface,quality,renddesc,&supercb)) + { + if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__)); + return false; + } + + for(int y = y_start; y < y_end; y++, pos[1] += hpp) + { + pos[0] = xf_start; + for(int x = x_start; x < x_end; x++, pos[0] += wpp) + { + if(get_color(pos,clr,amt)) + { + if(amt==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + (*surface)[y][x] = clr; + else + (*surface)[y][x] = Color::blend(clr,(*surface)[y][x],amt,get_blend_method()); + } + } + } + + return true; + +#if 0 + //faster version but much more complex + //the floating point + Real y1,y2,y3; + Real x1,x2,x3; + Real dx1,dx2; //reversed in 3rd y section, not used in 2nd + + //the transparent + Real fx = 0, fy = 0; + Real dfx,dfy; + + //Get the slopes of the lines we need to worry about + if(feather_x) + { + dfx = 1/(fxsize); + + if(fxsize*2 > xfw) + { + x1 = xfw/2; + x2 = 0; + x3 = xfw; + }else + { + x1 = fxsize; + x2 = xfw - fxsize; + x3 = xfw; + } + }else + { + fx = 1; + dfx = 0; + x1=0; + x2=xfw; + x3=0; + } + + if(feather_y) + { + dfy = 1/(fysize); + + if(fysize*2 > yfh) + { + y1 = yfh/2; + y2 = 0; + y3 = yfh; + }else + { + y1 = fysize; + y2 = yfh - fysize; + y3 = yfh; + } + + dx1 = ph*feather_x/feather_y; + dx2 = -2*dx1; + + }else + { + fy = 1; + dfy = 0; + y1=0; + y2=yfh; + y3=0; + } + + fy = yf*dfy; + + int x,y; + Real value = 0; + SuperCallback supercb(cb,0,9000,10000); + Surface::pen p; + + Real tx1 = 0,tx2 = + for(y = y_start;yf < y1; y++,yf++,fy+=dfy, tx1+=dx1) + { + fx = xf*dfx; + + p = surface->get_pen(x_start,y); + for(; xf < x1; xf++,p.inc_x(), fx+=dfx) + { + //we are in the x portion... use fx + value = fx*get_amount(); + if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + p.put_value(color); + else + p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); + } + + for(;xf < x2; xf++,p.inc_x()) + { + //we are now in y... use fy + value = fy*get_amount(); + if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + p.put_value(color); + else + p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); + } + + fx = xfw?(xfw - xf)/xfw:1; + for(;xf < x3 && ; xf++,p.inc_x(), fx-=dfx) + { + //we are in the x portion... use fx + value = max(0,fx*get_amount()); + if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + p.put_value(color); + else + p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); + } + } + + x1 = + for(;fy < 1.0; y++,yf++,fy+=dfy) + { + fx = xf*dfx; + + p = surface->get_pen(x_start,y); + for(; xf < x1; xf++,p.inc_x(), fx+=dfx) + { + //we are in the x portion... use fx + value = fx*get_amount(); + if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + p.put_value(color); + else + p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); + } + + for(;xf < x2; xf++,p.inc_x()) + { + //we are now in y... use fy + value = fy*get_amount(); + if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + p.put_value(color); + else + p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); + } + + fx = xfw?(xfw - xf)/xfw:1; + for(;xf < x3 && ; xf++,p.inc_x(), fx-=dfx) + { + //we are in the x portion... use fx + value = max(0,fx*get_amount()); + if(value==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + p.put_value(color); + else + p.put_value(Color::blend(color,p.get_value(),value,get_blend_method())); + } + } + + for() + { + for(int x = x_start; x < x_end; x++) + { + + } + } + +#endif + + // Mark our progress as finished + if(cb && !cb->amount_complete(10000,10000)) + return false; + + return true; +} diff --git a/synfig-core/src/modules/mod_example/filledrect.h b/synfig-core/src/modules/mod_example/filledrect.h new file mode 100644 index 0000000..b540105 --- /dev/null +++ b/synfig-core/src/modules/mod_example/filledrect.h @@ -0,0 +1,81 @@ +/* === S Y N F I G ========================================================= */ +/*! \file filledrect.h +** \brief Header file for implementation of the "Rectangle" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_FILLEDRECT_H +#define __SYNFIG_FILLEDRECT_H + +/* === H E A D E R S ======================================================= */ + +#include +#include +#include +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +class FilledRect : public synfig::Layer_Composite +{ + SYNFIG_LAYER_MODULE_EXT + +private: + + synfig::Color color; + + synfig::Point point1; + synfig::Point point2; + + synfig::Real feather_x; + synfig::Real feather_y; + + synfig::Real bevel; + + bool bevCircle; + + bool get_color(const synfig::Point &pos, synfig::Color &out, synfig::Real &outamount)const; + +public: + + FilledRect(); + + virtual bool set_param(const synfig::String & param, const synfig::ValueBase &value); + + virtual synfig::ValueBase get_param(const synfig::String & param)const; + + virtual synfig::Color get_color(synfig::Context context, const synfig::Point &pos)const; + + virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; + + virtual Vocab get_param_vocab()const; + + virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; +}; // END of class FilledRect + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-core/src/modules/mod_example/main.cpp b/synfig-core/src/modules/mod_example/main.cpp new file mode 100644 index 0000000..614a078 --- /dev/null +++ b/synfig-core/src/modules/mod_example/main.cpp @@ -0,0 +1,61 @@ +/* === S Y N F I G ========================================================= */ +/*! \file example/main.cpp +** \brief Template Header +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +** +** === N O T E S =========================================================== +** +** ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#define SYNFIG_MODULE + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include "simplecircle.h" +#include "filledrect.h" +#include "metaballs.h" + +#endif + +/* === E N T R Y P O I N T ================================================= */ + +MODULE_DESC_BEGIN(libmod_example) + MODULE_NAME("Example Module") + MODULE_DESCRIPTION("A dummy module that serves as a starting point for writing other modules.") + MODULE_AUTHOR("Robert B. Quattlebaum") + MODULE_VERSION("1.0") + MODULE_COPYRIGHT(SYNFIG_COPYRIGHT) +MODULE_DESC_END + +MODULE_INVENTORY_BEGIN(libmod_example) + BEGIN_LAYERS + LAYER(SimpleCircle) + LAYER(FilledRect) + LAYER(Metaballs) + END_LAYERS +MODULE_INVENTORY_END diff --git a/synfig-core/src/modules/mod_example/metaballs.cpp b/synfig-core/src/modules/mod_example/metaballs.cpp new file mode 100644 index 0000000..0cfa6c3 --- /dev/null +++ b/synfig-core/src/modules/mod_example/metaballs.cpp @@ -0,0 +1,252 @@ +/* === S Y N F I G ========================================================= */ +/*! \file metaballs.cpp +** \brief Implementation of the "Metaballs" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "metaballs.h" + +#endif + +/* === U S I N G =========================================================== */ + +using namespace etl; +using namespace std; +using namespace synfig; + +/* === G L O B A L S ======================================================= */ + +SYNFIG_LAYER_INIT(Metaballs); +SYNFIG_LAYER_SET_NAME(Metaballs,"metaballs"); +SYNFIG_LAYER_SET_LOCAL_NAME(Metaballs,N_("Metaballs")); +SYNFIG_LAYER_SET_CATEGORY(Metaballs,N_("Example")); +SYNFIG_LAYER_SET_VERSION(Metaballs,"0.1"); +SYNFIG_LAYER_SET_CVS_ID(Metaballs,"$Id$"); + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +/* === E N T R Y P O I N T ================================================= */ + +Metaballs::Metaballs(): + Layer_Composite(1.0,Color::BLEND_STRAIGHT), + gradient(Color::black(), Color::white()), + threshold(0), + threshold2(1), + positive(false) +{ + centers.push_back(Point( 0, -1.5)); radii.push_back(2.5); weights.push_back(1); + centers.push_back(Point(-2, 1)); radii.push_back(2.5); weights.push_back(1); + centers.push_back(Point( 2, 1)); radii.push_back(2.5); weights.push_back(1); +} + +bool +Metaballs::set_param(const String & param, const ValueBase &value) +{ + if( param=="centers" && value.same_type_as(centers)) + { + centers = value; + return true; + } + + if( param=="weights" && value.same_type_as(weights)) + { + weights = value; + return true; + } + + if( param=="radii" && value.same_type_as(radii)) + { + radii = value; + return true; + } + + IMPORT(gradient); + IMPORT(threshold); + IMPORT(threshold2); + IMPORT(positive); + + return Layer_Composite::set_param(param,value); +} + +ValueBase +Metaballs::get_param(const String ¶m)const +{ + EXPORT(gradient); + + EXPORT(radii); + EXPORT(weights); + EXPORT(centers); + EXPORT(threshold); + EXPORT(threshold2); + EXPORT(positive); + + EXPORT_NAME(); + EXPORT_VERSION(); + + return Layer_Composite::get_param(param); +} + +Layer::Vocab +Metaballs::get_param_vocab()const +{ + Layer::Vocab ret(Layer_Composite::get_param_vocab()); + + ret.push_back(ParamDesc("gradient") + .set_local_name(_("Gradient")) + ); + + ret.push_back(ParamDesc("centers") + .set_local_name(_("Points")) + ); + + ret.push_back(ParamDesc("radii") + .set_local_name(_("Radii")) + ); + + ret.push_back(ParamDesc("weights") + .set_local_name(_("Weights")) + ); + + ret.push_back(ParamDesc("threshold") + .set_local_name(_("Gradient Left")) + ); + + ret.push_back(ParamDesc("threshold2") + .set_local_name(_("Gradient Right")) + ); + + ret.push_back(ParamDesc("positive") + .set_local_name(_("Positive Only")) + ); + + return ret; +} + +synfig::Layer::Handle +Metaballs::hit_check(synfig::Context context, const synfig::Point &point)const +{ + Real density(totaldensity(point)); + + if (density <= 0 || density > 1 || get_amount() == 0) + return context.hit_check(point); + + synfig::Layer::Handle tmp; + + if (get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(point))) + return tmp; + + if (Color::is_onto(get_blend_method()) && !(context.hit_check(point))) + return 0; + + return const_cast(this); +} + +Real +Metaballs::densityfunc(const synfig::Point &p, const synfig::Point &c, Real R)const +{ + const Real dx = p[0] - c[0]; + const Real dy = p[1] - c[1]; + + const Real n = (1 - (dx*dx + dy*dy)/(R*R)); + if (positive && n < 0) return 0; + return (n*n*n); + + /* + f(d) = (1 - d^2)^3 + f'(d) = -6d * (1 - d^2)^2 + + could use this too... + f(d) = (1 - d^2)^2 + f'(d) = -6d * (1 - d^2) + */ +} + +Real +Metaballs::totaldensity(const Point &pos)const +{ + Real density = 0; + + //sum up weighted functions + for(unsigned int i=0;ierror(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__)); + return false; + } + + for(int y = 0; y < h; y++, pos[1] += ph) + { + pos[0] = tl[0]; + for(int x = 0; x < w; x++, pos[0] += pw) + (*surface)[y][x] = Color::blend(gradient(totaldensity(pos)),(*surface)[y][x],get_amount(),get_blend_method()); + } + + // Mark our progress as finished + if(cb && !cb->amount_complete(10000,10000)) + return false; + + return true; +} diff --git a/synfig-core/src/modules/mod_example/metaballs.h b/synfig-core/src/modules/mod_example/metaballs.h new file mode 100644 index 0000000..d9ae649 --- /dev/null +++ b/synfig-core/src/modules/mod_example/metaballs.h @@ -0,0 +1,81 @@ +/* === S Y N F I G ========================================================= */ +/*! \file metaballs.h +** \brief Header file for implementation of the "Metaballs" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_METABALLS_H +#define __SYNFIG_METABALLS_H + +/* === H E A D E R S ======================================================= */ + +#include +#include +#include +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ +class Metaballs : public synfig::Layer_Composite +{ + SYNFIG_LAYER_MODULE_EXT + +private: + + synfig::Gradient gradient; + + std::vector centers; + std::vector radii; + std::vector weights; + + synfig::Real threshold; + synfig::Real threshold2; + + bool positive; + + synfig::Real densityfunc(const synfig::Point &p, const synfig::Point &c, synfig::Real R)const; + + synfig::Real totaldensity(const synfig::Point &pos)const; + +public: + + Metaballs(); + + virtual bool set_param(const synfig::String & param, const synfig::ValueBase &value); + + virtual synfig::ValueBase get_param(const synfig::String & param)const; + + virtual synfig::Color get_color(synfig::Context context, const synfig::Point &pos)const; + + virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; + + virtual Vocab get_param_vocab()const; + + virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; +}; // END of class Metaballs + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-core/src/modules/mod_example/mod_example.nsh b/synfig-core/src/modules/mod_example/mod_example.nsh new file mode 100644 index 0000000..c79179c --- /dev/null +++ b/synfig-core/src/modules/mod_example/mod_example.nsh @@ -0,0 +1,21 @@ +; The stuff to install +Section "mod_example" Sec_mod_example + +; SectionIn RO + + ; Set output path to the installation directory. + SetOutPath "$INSTDIR\lib\synfig\modules" + + ; Put file there + File /oname=mod_example.dll "src\modules\mod_example\.libs\libmod_example.dll" + + + FileOpen $0 $INSTDIR\etc\synfig_modules.cfg a + FileSeek $0 0 END + FileWrite $0 "mod_example" + FileWriteByte $0 "13" + FileWriteByte $0 "10" + FileClose $0 + +SectionEnd + diff --git a/synfig-core/src/modules/mod_example/simplecircle.cpp b/synfig-core/src/modules/mod_example/simplecircle.cpp new file mode 100644 index 0000000..e2eb896 --- /dev/null +++ b/synfig-core/src/modules/mod_example/simplecircle.cpp @@ -0,0 +1,187 @@ +/* === S Y N F I G ========================================================= */ +/*! \file simplecircle.cpp +** \brief Implementation of the "Simple Circle" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "simplecircle.h" + +#endif + +/* === U S I N G =========================================================== */ + +using namespace etl; +using namespace std; +using namespace synfig; + +/* === G L O B A L S ======================================================= */ + +SYNFIG_LAYER_INIT(SimpleCircle); +SYNFIG_LAYER_SET_NAME(SimpleCircle,"simple_circle"); +SYNFIG_LAYER_SET_LOCAL_NAME(SimpleCircle,N_("Simple Circle")); +SYNFIG_LAYER_SET_CATEGORY(SimpleCircle,N_("Example")); +SYNFIG_LAYER_SET_VERSION(SimpleCircle,"0.1"); +SYNFIG_LAYER_SET_CVS_ID(SimpleCircle,"$Id$"); + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +/* === E N T R Y P O I N T ================================================= */ + +SimpleCircle::SimpleCircle(): + Layer_Composite(1.0,Color::BLEND_STRAIGHT), + color(Color::black()), + center(0,0), + radius(0.5) +{ +} + +bool +SimpleCircle::set_param(const String & param, const ValueBase &value) +{ + IMPORT(color); + IMPORT(center); + IMPORT(radius); + + return Layer_Composite::set_param(param,value); +} + +ValueBase +SimpleCircle::get_param(const String ¶m)const +{ + EXPORT(color); + EXPORT(center); + EXPORT(radius); + + EXPORT_NAME(); + EXPORT_VERSION(); + + return Layer_Composite::get_param(param); +} + +Layer::Vocab +SimpleCircle::get_param_vocab()const +{ + Layer::Vocab ret(Layer_Composite::get_param_vocab()); + + ret.push_back(ParamDesc("color") + .set_local_name(_("Color")) + ); + + ret.push_back(ParamDesc("center") + .set_local_name(_("Center")) + ); + + ret.push_back(ParamDesc("radius") + .set_local_name(_("Radius")) + .set_description(_("This is the radius of the circle")) + .set_origin("center") + ); + + return ret; +} + +Color +SimpleCircle::get_color(Context context, const Point &pos)const +{ + + if((pos-center).mag()(this); + else + return context.hit_check(pos); +} + +/* +bool +SimpleCircle::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const +{ + if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) + { + // Mark our progress as starting + if(cb && !cb->amount_complete(0,1000)) + return false; + + surface->set_wh(renddesc.get_w(),renddesc.get_h()); + surface->fill(color); + + // Mark our progress as finished + if(cb && !cb->amount_complete(1000,1000)) + return false; + + return true; + } + + SuperCallback supercb(cb,0,9500,10000); + + if(!context.accelerated_render(surface,quality,renddesc,&supercb)) + return false; + + int x,y; + + Surface::alpha_pen apen(surface->begin()); + + apen.set_value(color); + apen.set_alpha(get_amount()); + apen.set_blend_method(get_blend_method()); + + for(y=0;yamount_complete(10000,10000)) + return false; + + return true; +} +*/ diff --git a/synfig-core/src/modules/mod_example/simplecircle.h b/synfig-core/src/modules/mod_example/simplecircle.h new file mode 100644 index 0000000..48c555c --- /dev/null +++ b/synfig-core/src/modules/mod_example/simplecircle.h @@ -0,0 +1,73 @@ +/* === S Y N F I G ========================================================= */ +/*! \file simplecircle.h +** \brief Header file for implementation of the "Simple Circle" layer +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_SIMPLECIRCLE_H +#define __SYNFIG_SIMPLECIRCLE_H + +/* === H E A D E R S ======================================================= */ + +#include +#include +#include +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +class SimpleCircle : public synfig::Layer_Composite +{ + SYNFIG_LAYER_MODULE_EXT + +private: + + synfig::Color color; + + synfig::Point center; + + synfig::Real radius; + +public: + + SimpleCircle(); + + virtual bool set_param(const synfig::String & param, const synfig::ValueBase &value); + + virtual synfig::ValueBase get_param(const synfig::String & param)const; + + virtual synfig::Color get_color(synfig::Context context, const synfig::Point &pos)const; + + //virtual bool accelerated_render(synfig::Context context,synfig::Surface *surface,int quality, const synfig::RendDesc &renddesc, synfig::ProgressCallback *cb)const; + + synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; + + virtual Vocab get_param_vocab()const; +}; // END of class SimpleCircle + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-core/src/modules/mod_example/unmod_example.nsh b/synfig-core/src/modules/mod_example/unmod_example.nsh new file mode 100644 index 0000000..ba88283 --- /dev/null +++ b/synfig-core/src/modules/mod_example/unmod_example.nsh @@ -0,0 +1,8 @@ +Section "un.mod_example" + Delete "$INSTDIR\lib\synfig\modules\mod_example.dll" + RMDir "$INSTDIR\lib\synfig\modules" + RMDir "$INSTDIR\lib\synfig" + RMDir "$INSTDIR\lib" + RMDir "$INSTDIR" +SectionEnd + diff --git a/synfig-core/src/modules/synfig_modules.cfg.in b/synfig-core/src/modules/synfig_modules.cfg.in index 899e295..529460e 100644 --- a/synfig-core/src/modules/synfig_modules.cfg.in +++ b/synfig-core/src/modules/synfig_modules.cfg.in @@ -1,4 +1,4 @@ -example +mod_example mod_gif mod_imagemagick mod_magickpp -- 2.7.4