18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkDashPathEffect_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkDashPathEffect_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathEffect.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkDashPathEffect 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDashPathEffect is a subclass of SkPathEffect that implements dashing 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 177ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkDashPathEffect : public SkPathEffect { 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 1920bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com /** intervals: array containing an even number of entries (>=2), with 2020bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com the even indices specifying the length of "on" intervals, and the odd 2120bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com indices specifying the length of "off" intervals. 22fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com count: number of elements in the intervals array 2320bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com phase: offset into the intervals array (mod the sum of all of the 2420bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com intervals). 2520bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 2620bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com For example: if intervals[] = {10, 20}, count = 2, and phase = 25, 2720bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com this will set up a dashed path like so: 2820bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 5 pixels off 2920bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 10 pixels on 3020bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 20 pixels off 3120bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 10 pixels on 3220bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 20 pixels off 3320bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com ... 3420bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com A phase of -5, 25, 55, 85, etc. would all result in the same path, 3520bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com because the sum of all the intervals is 30. 3620bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 3720bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com Note: only affects stroked paths. 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 390a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org static SkDashPathEffect* Create(const SkScalar intervals[], int count, 4035c03fbf101306e8e82141853de4c664cbafedbbcommit-bot@chromium.org SkScalar phase) { 4135c03fbf101306e8e82141853de4c664cbafedbbcommit-bot@chromium.org return SkNEW_ARGS(SkDashPathEffect, (intervals, count, phase)); 420a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org } 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkDashPathEffect(); 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 45548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com virtual bool filterPath(SkPath* dst, const SkPath& src, 4636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein SkStrokeRec*, const SkRect*) const override; 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 48687c57c7d5a17549f63e0b15208db18b220e2a91skia.committer@gmail.com virtual bool asPoints(PointData* results, const SkPath& src, 494bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com const SkStrokeRec&, const SkMatrix&, 5036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein const SkRect*) const override; 51629ab540667422d3edcb97c51e9628b7051e1ba4robertphillips@google.com 5236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein DashType asADash(DashInfo* info) const override; 53aec143824c9be4e4af6e2cb7cce3d2d2268c0b15commit-bot@chromium.org 5442dbfa8651861f2f686879c996aab9f9f82277ddrobertphillips SK_TO_STRING_OVERRIDE() 559fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDashPathEffect) 566bac947cd5bc460dd9166ada6310d678fd2e39f8reed@google.com 5764de1e179012302d5f3b805d0736a583ad91c6a2tomhudson#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 5836352bf5e38f45a70ee4f4fc132a38048d38206dmtklein bool exposedInAndroidJavaAPI() const override { return true; } 5964de1e179012302d5f3b805d0736a583ad91c6a2tomhudson#endif 6064de1e179012302d5f3b805d0736a583ad91c6a2tomhudson 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 6235c03fbf101306e8e82141853de4c664cbafedbbcommit-bot@chromium.org SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase); 6336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void flatten(SkWriteBuffer&) const override; 640a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar* fIntervals; 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int32_t fCount; 68aec143824c9be4e4af6e2cb7cce3d2d2268c0b15commit-bot@chromium.org SkScalar fPhase; 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // computed from phase 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fInitialDashLength; 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int32_t fInitialDashIndex; 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fIntervalLength; 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkPathEffect INHERITED; 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 78