aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/SkV8Example/DrawingMethods.h
blob: d72a3df018e9b42d28c7271ba008bc9ae09f8ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * 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_DrawingMethods_DEFINED
#define SkV8Example_DrawingMethods_DEFINED

#include <v8.h>

class SkCanvas;
class Global;

// DrawingMethods contains common functionality for both Context, Image2Builder,
// and DisplayListBuiler.
class DrawingMethods {
public:
    DrawingMethods(Global* global)
            : fGlobal(global)
    {}
    virtual ~DrawingMethods() {}

    // Retrieve the SkCanvas to draw on. May return NULL.
    virtual SkCanvas* getCanvas() = 0;

    // Add the Javascript attributes and methods that DrawingMethods
    // implements to the ObjectTemplate.
    void addAttributesAndMethods(v8::Handle<v8::ObjectTemplate> tmpl);

protected:
    // Get the pointer out of obj.
    static DrawingMethods* Unwrap(v8::Handle<v8::Object> obj);

    Global* fGlobal;

private:
    // JS Attributes
    static void GetWidth(v8::Local<v8::String> name,
                         const v8::PropertyCallbackInfo<v8::Value>& info);
    static void GetHeight(v8::Local<v8::String> name,
                          const v8::PropertyCallbackInfo<v8::Value>& info);

    // JS Methods
    static void Save(const v8::FunctionCallbackInfo<v8::Value>& args);
    static void Restore(const v8::FunctionCallbackInfo<v8::Value>& args);
    static void Rotate(const v8::FunctionCallbackInfo<v8::Value>& args);
    static void Translate(const v8::FunctionCallbackInfo<v8::Value>& args);
    static void ResetTransform(const v8::FunctionCallbackInfo<v8::Value>& args);

    static void DrawPath(const v8::FunctionCallbackInfo<v8::Value>& args);
};

#endif