blob: f2125eaa9edb01ef0d2fe3152c41ec489f484ddc [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/animator/SkBoundable.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "SkBoundable.h"
19#include "SkAnimateMaker.h"
20#include "SkCanvas.h"
21
22SkBoundable::SkBoundable() {
23 clearBounds();
24 fBounds.fTop = 0;
25 fBounds.fRight = 0;
26 fBounds.fBottom = 0;
27}
28
29void SkBoundable::clearBounder() {
30 fBounds.fLeft = 0x7fff;
31}
32
33void SkBoundable::getBounds(SkRect* rect) {
34 SkASSERT(rect);
35 if (fBounds.fLeft == (int16_t)0x8000U) {
36 INHERITED::getBounds(rect);
37 return;
38 }
39 rect->fLeft = SkIntToScalar(fBounds.fLeft);
40 rect->fTop = SkIntToScalar(fBounds.fTop);
41 rect->fRight = SkIntToScalar(fBounds.fRight);
42 rect->fBottom = SkIntToScalar(fBounds.fBottom);
43}
44
45void SkBoundable::enableBounder() {
46 fBounds.fLeft = 0;
47}
48
49
50SkBoundableAuto::SkBoundableAuto(SkBoundable* boundable,
51 SkAnimateMaker& maker) : fBoundable(boundable), fMaker(maker) {
52 if (fBoundable->hasBounds()) {
53 fMaker.fCanvas->setBounder(&maker.fDisplayList);
54 fMaker.fDisplayList.fBounds.setEmpty();
55 }
56}
57
58SkBoundableAuto::~SkBoundableAuto() {
59 if (fBoundable->hasBounds() == false)
60 return;
61 fMaker.fCanvas->setBounder(NULL);
62 fBoundable->setBounds(fMaker.fDisplayList.fBounds);
63}
64