• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 package org.skia.androidkit;
9 
10 import android.support.annotation.Nullable;
11 
12 public class Paint {
13     private long mNativeInstance;
14 
Paint()15     public Paint() {
16         mNativeInstance = nCreate();
17     }
18 
setColor(Color c)19     public Paint setColor(Color c) {
20         nSetColor(mNativeInstance, c.r(), c.g(), c.b(), c.a());
21         return this;
22     }
23 
setColor(float r, float g, float b, float a)24     public Paint setColor(float r, float g, float b, float a) {
25         nSetColor(mNativeInstance, r, g, b, a);
26         return this;
27     }
28 
setColorFilter(@ullable ColorFilter filter)29     public Paint setColorFilter(@Nullable ColorFilter filter) {
30         nSetColorFilter(mNativeInstance, filter != null ? filter.getNativeInstance() : 0);
31         return this;
32     }
33 
setShader(@ullable Shader shader)34     public Paint setShader(@Nullable Shader shader) {
35         nSetShader(mNativeInstance, shader != null ? shader.getNativeInstance() : 0);
36         return this;
37     }
38 
setImageFilter(@ullable ImageFilter filter)39     public Paint setImageFilter(@Nullable ImageFilter filter) {
40         nSetImageFilter(mNativeInstance, filter != null ? filter.getNativeInstance() : 0);
41         return this;
42     }
43 
setStroke(boolean stroke)44     public Paint setStroke(boolean stroke) {
45         nSetStroke(mNativeInstance, stroke);
46         return this;
47     }
48 
setStrokeWidth(float w)49     public Paint setStrokeWidth(float w) {
50         nSetStrokeWidth(mNativeInstance, w);
51         return this;
52     }
53 
54     public enum Cap {
55         BUTT    (0),
56         ROUND   (1),
57         SQUARE  (2);
58 
Cap(int nativeInt)59         private Cap(int nativeInt) {
60             this.nativeInt = nativeInt;
61         }
62         final int nativeInt;
63     }
setStrokeCap(Cap cap)64     public Paint setStrokeCap(Cap cap) {
65         nSetStrokeCap(mNativeInstance, cap.nativeInt);
66         return this;
67     }
68 
69 
70     public enum Join {
71         MITER   (0),
72         ROUND   (1),
73         BEVEL   (2);
74 
Join(int nativeInt)75         private Join(int nativeInt) {
76             this.nativeInt = nativeInt;
77         }
78         final int nativeInt;
79     }
setStrokeJoin(Join join)80     public Paint setStrokeJoin(Join join) {
81         nSetStrokeJoin(mNativeInstance, join.nativeInt);
82         return this;
83     }
84 
setStrokeMiter(float limit)85     public Paint setStrokeMiter(float limit) {
86         nSetStrokeMiter(mNativeInstance, limit);
87         return this;
88     }
89 
90     /**
91      * Releases any resources associated with this Paint.
92      */
release()93     public void release() {
94         nRelease(mNativeInstance);
95         mNativeInstance = 0;
96     }
97 
98     @Override
finalize()99     protected void finalize() throws Throwable {
100         release();
101     }
102 
103     // package private
getNativeInstance()104     long getNativeInstance() { return mNativeInstance; }
105 
nCreate()106     private static native long nCreate();
nRelease(long nativeInstance)107     private static native void nRelease(long nativeInstance);
108 
nSetColor(long nativeInstance, float r, float g, float b, float a)109     private static native void nSetColor(long nativeInstance, float r, float g, float b, float a);
nSetStroke(long nativeInstance, boolean stroke)110     private static native void nSetStroke(long nativeInstance, boolean stroke);
nSetStrokeWidth(long nativeInstance, float w)111     private static native void nSetStrokeWidth(long nativeInstance, float w);
nSetStrokeCap(long nativeInstance, int native_cap)112     private static native void nSetStrokeCap(long nativeInstance, int native_cap);
nSetStrokeJoin(long nativeInstance, int native_join)113     private static native void nSetStrokeJoin(long nativeInstance, int native_join);
nSetStrokeMiter(long nativeInstance, float limit)114     private static native void nSetStrokeMiter(long nativeInstance, float limit);
nSetColorFilter(long nativeInstance, long nativeCF)115     private static native void nSetColorFilter(long nativeInstance, long nativeCF);
nSetShader(long nativeInstance, long nativeShader)116     private static native void nSetShader(long nativeInstance, long nativeShader);
nSetImageFilter(long nativeInstance, long nativeFilter)117     private static native void nSetImageFilter(long nativeInstance, long nativeFilter);
118 }
119