Browse Source

Added restoreState()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
b44956c073
  1. 21
      src/context2d.cc
  2. 3
      src/context2d.h

21
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];
}
/*

3
src/context2d.h

@ -90,7 +90,8 @@ class Context2d: public node::ObjectWrap {
static void SetShadowBlur(Local<String> prop, Local<Value> 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);

Loading…
Cancel
Save