Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #ifndef REVEALCLIP_H |
| 17 | #define REVEALCLIP_H |
| 18 | |
| 19 | #include <SkPath.h> |
| 20 | |
| 21 | #include "Rect.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
| 26 | class RevealClip { |
| 27 | public: |
| 28 | RevealClip() |
| 29 | : mShouldClip(false) |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 30 | , mX(0) |
| 31 | , mY(0) |
| 32 | , mRadius(0) {} |
| 33 | |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 34 | void set(bool shouldClip, float x, float y, float radius) { |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 35 | mShouldClip = shouldClip; |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 36 | mX = x; |
| 37 | mY = y; |
| 38 | mRadius = radius; |
| 39 | |
| 40 | mPath.rewind(); |
| 41 | if (mShouldClip) { |
| 42 | mPath.addCircle(x, y, radius); |
| 43 | } |
| 44 | } |
| 45 | |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 46 | bool willClip() const { |
| 47 | return mShouldClip; |
| 48 | } |
| 49 | |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 50 | void getBounds(Rect* outBounds) const { |
| 51 | outBounds->set(mX - mRadius, mY - mRadius, |
| 52 | mX + mRadius, mY + mRadius); |
John Reck | d3de42c | 2014-07-15 14:29:33 -0700 | [diff] [blame] | 53 | } |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 54 | |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 55 | float getRadius() const { return mRadius; } |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 56 | float getX() const { return mX; } |
| 57 | float getY() const { return mY; } |
John Reck | d3de42c | 2014-07-15 14:29:33 -0700 | [diff] [blame] | 58 | |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 59 | const SkPath* getPath() const { |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 60 | if (!mShouldClip) return nullptr; |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 61 | |
| 62 | return &mPath; |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | bool mShouldClip; |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 67 | float mX; |
| 68 | float mY; |
| 69 | float mRadius; |
| 70 | SkPath mPath; |
| 71 | }; |
| 72 | |
| 73 | } /* namespace uirenderer */ |
| 74 | } /* namespace android */ |
| 75 | |
| 76 | #endif /* REVEALCLIP_H */ |