From 08eef3ebf59a874d63946d7278bbf5dd87dd50ab Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Mon, 8 Nov 2010 09:31:36 -0800 Subject: [PATCH] Added Context2d::shadow{Start,Apply}() --- src/CanvasRenderingContext2d.cc | 42 +++++++++++++++++++++++---------- src/CanvasRenderingContext2d.h | 2 ++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index d4a44ff..b0c4db5 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1068,24 +1068,14 @@ Context2d::FillRect(const Arguments &args) { return Undefined(); } - cairo_save(ctx); - cairo_translate( - ctx - , context->state->shadowOffsetX - , context->state->shadowOffsetY); + context->shadowStart(); - cairo_push_group(ctx); cairo_rectangle(ctx, x, y, width, height); SET_SOURCE_RGBA(context->state->shadow); cairo_fill(ctx); - if (context->state->shadowBlur) { - Canvas::blur(cairo_get_group_target(ctx), context->state->shadowBlur); - } - cairo_pop_group_to_source(ctx); - cairo_paint(ctx); + context->shadowApply(); - cairo_restore(ctx); cairo_rectangle(ctx, x, y, width, height); cairo_fill(ctx); return Undefined(); @@ -1205,6 +1195,34 @@ Context2d::Arc(const Arguments &args) { return Undefined(); } +/* + * Start shadow context. + */ + +void +Context2d::shadowStart() { + cairo_save(_context); + cairo_translate( + _context + , state->shadowOffsetX + , state->shadowOffsetY); + cairo_push_group(_context); +} + +/* + * Apply shadow. + */ + +void +Context2d::shadowApply() { + if (state->shadowBlur) { + Canvas::blur(cairo_get_group_target(_context), state->shadowBlur); + } + cairo_pop_group_to_source(_context); + cairo_paint(_context); + cairo_restore(_context); +} + /* * Check if the context has a drawable shadow. */ diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 142fb65..2abcf2d 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -102,6 +102,8 @@ class Context2d: public node::ObjectWrap { inline Canvas *getCanvas(){ return _canvas; } inline bool hasShadow(); void setTextPath(const char *str, double x, double y); + void shadowStart(); + void shadowApply(); void savePath(); void restorePath(); void save();