// // CanvasRenderingContext2d.h // // Copyright (c) 2010 LearnBoost // #ifndef __NODE_CONTEXT2D_H__ #define __NODE_CONTEXT2D_H__ #include "Canvas.h" #include "CanvasGradient.h" /* * RGBA struct used to retain values of fill/stroke. */ typedef struct { double r, g, b, a; } rgba_t; /* * State struct. * * Used in conjunction with Save() / Restore() since * cairo's gstate maintains only a single source pattern at a time. */ typedef struct { rgba_t fill; rgba_t stroke; cairo_pattern_t *fillPattern; cairo_pattern_t *strokePattern; float globalAlpha; short textAlignment; short textBaseline; rgba_t shadow; int shadowBlur; double shadowOffsetX; double shadowOffsetY; } canvas_state_t; class Context2d: public node::ObjectWrap { public: short stateno; canvas_state_t *states[CANVAS_MAX_STATES]; canvas_state_t *state; static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle DrawImage(const Arguments &args); static Handle PutImageData(const Arguments &args); static Handle Save(const Arguments &args); static Handle Restore(const Arguments &args); static Handle Rotate(const Arguments &args); static Handle Translate(const Arguments &args); static Handle Scale(const Arguments &args); static Handle Transform(const Arguments &args); static Handle ResetTransform(const Arguments &args); static Handle IsPointInPath(const Arguments &args); static Handle BeginPath(const Arguments &args); static Handle ClosePath(const Arguments &args); static Handle Clip(const Arguments &args); static Handle Fill(const Arguments &args); static Handle Stroke(const Arguments &args); static Handle FillText(const Arguments &args); static Handle StrokeText(const Arguments &args); static Handle SetFont(const Arguments &args); static Handle SetFillRGBA(const Arguments &args); static Handle SetStrokeRGBA(const Arguments &args); static Handle SetShadowRGBA(const Arguments &args); static Handle SetFillPattern(const Arguments &args); static Handle SetStrokePattern(const Arguments &args); static Handle SetTextBaseline(const Arguments &args); static Handle SetTextAlignment(const Arguments &args); static Handle MeasureText(const Arguments &args); static Handle BezierCurveTo(const Arguments &args); static Handle QuadraticCurveTo(const Arguments &args); static Handle LineTo(const Arguments &args); static Handle MoveTo(const Arguments &args); static Handle FillRect(const Arguments &args); static Handle StrokeRect(const Arguments &args); static Handle ClearRect(const Arguments &args); static Handle Rect(const Arguments &args); static Handle Arc(const Arguments &args); static Handle GetGlobalCompositeOperation(Local prop, const AccessorInfo &info); static Handle GetGlobalAlpha(Local prop, const AccessorInfo &info); static Handle GetMiterLimit(Local prop, const AccessorInfo &info); static Handle GetLineCap(Local prop, const AccessorInfo &info); static Handle GetLineJoin(Local prop, const AccessorInfo &info); static Handle GetLineWidth(Local prop, const AccessorInfo &info); static Handle GetShadowOffsetX(Local prop, const AccessorInfo &info); static Handle GetShadowOffsetY(Local prop, const AccessorInfo &info); static Handle GetShadowBlur(Local prop, const AccessorInfo &info); static Handle GetAntiAlias(Local prop, const AccessorInfo &info); static void SetGlobalCompositeOperation(Local prop, Local val, const AccessorInfo &info); static void SetGlobalAlpha(Local prop, Local val, const AccessorInfo &info); static void SetMiterLimit(Local prop, Local val, const AccessorInfo &info); static void SetLineCap(Local prop, Local val, const AccessorInfo &info); static void SetLineJoin(Local prop, Local val, const AccessorInfo &info); static void SetLineWidth(Local prop, Local val, const AccessorInfo &info); static void SetShadowOffsetX(Local prop, Local val, const AccessorInfo &info); static void SetShadowOffsetY(Local prop, Local val, const AccessorInfo &info); static void SetShadowBlur(Local prop, Local val, const AccessorInfo &info); static void SetAntiAlias(Local prop, Local val, const AccessorInfo &info); inline cairo_t *context(){ return _context; } inline Canvas *canvas(){ return _canvas; } inline bool hasShadow(); void inline setSourceRGBA(rgba_t color); void setTextPath(const char *str, double x, double y); void blur(cairo_surface_t *surface, int radius); void shadow(void (fn)(cairo_t *cr)); void shadowStart(); void shadowApply(); void savePath(); void restorePath(); void saveState(); void restoreState(); void fill(bool preserve = false); void stroke(bool preserve = false); void save(); void restore(); protected: Context2d(Canvas *canvas); private: ~Context2d(); Canvas *_canvas; cairo_t *_context; cairo_path_t *_path; }; #endif