/* * Copyright 2014 Google Inc. * * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * */ #ifndef SkV8Example_BaseContext_DEFINED #define SkV8Example_BaseContext_DEFINED #include #include "SkPaint.h" using namespace v8; class SkCanvas; class Global; // BaseContext contains common functionality for both JsContext // and DisplayList. class BaseContext { public: BaseContext(Global* global) : fGlobal(global) { fFillStyle.setColor(SK_ColorBLACK); fFillStyle.setAntiAlias(true); fFillStyle.setStyle(SkPaint::kFill_Style); fStrokeStyle.setColor(SK_ColorBLACK); fStrokeStyle.setAntiAlias(true); fStrokeStyle.setStyle(SkPaint::kStroke_Style); } virtual ~BaseContext() {} // Retrieve the SkCanvas to draw on. May return NULL. virtual SkCanvas* getCanvas() = 0; // Add the Javascript attributes and methods that BaseContext implements to the ObjectTemplate. void addAttributesAndMethods(Handle tmpl); protected: // Get the pointer out of obj. static BaseContext* Unwrap(Handle obj); Global* fGlobal; SkPaint fFillStyle; SkPaint fStrokeStyle; private: static void GetStyle(Local name, const PropertyCallbackInfo& info, const SkPaint& style); static void SetStyle(Local name, Local value, const PropertyCallbackInfo& info, SkPaint& style); // JS Attributes static void GetFillStyle(Local name, const PropertyCallbackInfo& info); static void SetFillStyle(Local name, Local value, const PropertyCallbackInfo& info); static void GetStrokeStyle(Local name, const PropertyCallbackInfo& info); static void SetStrokeStyle(Local name, Local value, const PropertyCallbackInfo& info); static void GetWidth(Local name, const PropertyCallbackInfo& info); static void GetHeight(Local name, const PropertyCallbackInfo& info); // JS Methods static void FillRect(const v8::FunctionCallbackInfo& args); static void Stroke(const v8::FunctionCallbackInfo& args); static void Fill(const v8::FunctionCallbackInfo& args); static void Rotate(const v8::FunctionCallbackInfo& args); static void Save(const v8::FunctionCallbackInfo& args); static void Restore(const v8::FunctionCallbackInfo& args); static void Translate(const v8::FunctionCallbackInfo& args); static void ResetTransform(const v8::FunctionCallbackInfo& args); }; #endif