From b44956c073433c1e4d56bff4c1cd52792c9fa836 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 27 Oct 2010 10:14:52 -0700 Subject: [PATCH] Added restoreState() --- src/context2d.cc | 21 +++++++++++++++------ src/context2d.h | 3 ++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/context2d.cc b/src/context2d.cc index c881576..9bae2a6 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -134,7 +134,10 @@ Context2d::Context2d(Canvas *canvas): ObjectWrap() { cairo_set_line_width(_context, 1); shadowBlur = shadowOffsetX = shadowOffsetY = 0; globalAlpha = -1; - pushState(); + state = states[stateno = 0] = (canvas_state_t *) malloc(sizeof(canvas_state_t)); + state->fillPattern = state->strokePattern = NULL; + RGBA(state->fill,0,0,0,1); + RGBA(state->stroke,0,0,0,1); } /* @@ -146,11 +149,17 @@ Context2d::~Context2d() { } void -Context2d::pushState() { - states[stateno = 0] = state = (canvas_state_t *) malloc(sizeof(canvas_state_t)); - state->fillPattern = state->strokePattern = NULL; - RGBA(state->fill,0,0,0,1); - RGBA(state->stroke,0,0,0,1); +Context2d::saveState() { + printf("state %d -> %d\n", stateno, stateno + 1); + states[++stateno] = (canvas_state_t *) malloc(sizeof(canvas_state_t)); + memcpy(states[stateno], state, sizeof(canvas_state_t)); + state = states[stateno]; +} + +void +Context2d::restoreState() { + printf("state %d -> %d\n", stateno, stateno - 1); + state = states[--stateno]; } /* diff --git a/src/context2d.h b/src/context2d.h index 3f9374a..2c417c1 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -90,7 +90,8 @@ class Context2d: public node::ObjectWrap { static void SetShadowBlur(Local prop, Local val, const AccessorInfo &info); inline cairo_t *getContext(){ return _context; } inline Canvas *getCanvas(){ return _canvas; } - void pushState(); + void saveState(); + void restoreState(); protected: Context2d(Canvas *canvas);