OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkWidget.h" | 8 #include "SkWidget.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkMath.h" | 10 #include "SkMath.h" |
11 #include "SkShader.h" | 11 #include "SkShader.h" |
12 #include "SkInterpolator.h" | 12 #include "SkInterpolator.h" |
13 #include "SkTime.h" | 13 #include "SkTime.h" |
14 | 14 |
15 SkProgressView::SkProgressView(uint32_t flags) : SkView(flags), fOnShader(NULL),
fOffShader(NULL) | 15 SkProgressView::SkProgressView(uint32_t flags) : SkView(flags), fOnShader(nullpt
r), fOffShader(nullptr) |
16 { | 16 { |
17 fValue = 0; | 17 fValue = 0; |
18 fMax = 0; | 18 fMax = 0; |
19 fInterp = NULL; | 19 fInterp = nullptr; |
20 fDoInterp = false; | 20 fDoInterp = false; |
21 } | 21 } |
22 | 22 |
23 SkProgressView::~SkProgressView() | 23 SkProgressView::~SkProgressView() |
24 { | 24 { |
25 delete fInterp; | 25 delete fInterp; |
26 SkSafeUnref(fOnShader); | 26 SkSafeUnref(fOnShader); |
27 SkSafeUnref(fOffShader); | 27 SkSafeUnref(fOffShader); |
28 } | 28 } |
29 | 29 |
30 void SkProgressView::setMax(U16CPU max) | 30 void SkProgressView::setMax(U16CPU max) |
31 { | 31 { |
32 if (fMax != max) | 32 if (fMax != max) |
33 { | 33 { |
34 fMax = SkToU16(max); | 34 fMax = SkToU16(max); |
35 if (fValue > 0) | 35 if (fValue > 0) |
36 this->inval(NULL); | 36 this->inval(nullptr); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 void SkProgressView::setValue(U16CPU value) | 40 void SkProgressView::setValue(U16CPU value) |
41 { | 41 { |
42 if (fValue != value) | 42 if (fValue != value) |
43 { | 43 { |
44 if (fDoInterp) | 44 if (fDoInterp) |
45 { | 45 { |
46 if (fInterp) | 46 if (fInterp) |
47 delete fInterp; | 47 delete fInterp; |
48 fInterp = new SkInterpolator(1, 2); | 48 fInterp = new SkInterpolator(1, 2); |
49 SkScalar x = (SkScalar)(fValue << 8); | 49 SkScalar x = (SkScalar)(fValue << 8); |
50 fInterp->setKeyFrame(0, SkTime::GetMSecs(), &x, 0); | 50 fInterp->setKeyFrame(0, SkTime::GetMSecs(), &x, 0); |
51 x = (SkScalar)(value << 8); | 51 x = (SkScalar)(value << 8); |
52 fInterp->setKeyFrame(1, SkTime::GetMSecs() + 333, &x); | 52 fInterp->setKeyFrame(1, SkTime::GetMSecs() + 333, &x); |
53 } | 53 } |
54 fValue = SkToU16(value); | 54 fValue = SkToU16(value); |
55 this->inval(NULL); | 55 this->inval(nullptr); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void SkProgressView::onDraw(SkCanvas* canvas) | 59 void SkProgressView::onDraw(SkCanvas* canvas) |
60 { | 60 { |
61 if (fMax == 0) | 61 if (fMax == 0) |
62 return; | 62 return; |
63 | 63 |
64 SkFixed percent; | 64 SkFixed percent; |
65 | 65 |
66 if (fInterp) | 66 if (fInterp) |
67 { | 67 { |
68 SkScalar x; | 68 SkScalar x; |
69 if (fInterp->timeToValues(SkTime::GetMSecs(), &x) == SkInterpolator::kFr
eezeEnd_Result) | 69 if (fInterp->timeToValues(SkTime::GetMSecs(), &x) == SkInterpolator::kFr
eezeEnd_Result) |
70 { | 70 { |
71 delete fInterp; | 71 delete fInterp; |
72 fInterp = NULL; | 72 fInterp = nullptr; |
73 } | 73 } |
74 percent = (SkFixed)x; // now its 16.8 | 74 percent = (SkFixed)x; // now its 16.8 |
75 percent = SkMax32(0, SkMin32(percent, fMax << 8)); // now its pinned | 75 percent = SkMax32(0, SkMin32(percent, fMax << 8)); // now its pinned |
76 percent = SkFixedDiv(percent, fMax << 8); // now its 0.16 | 76 percent = SkFixedDiv(percent, fMax << 8); // now its 0.16 |
77 this->inval(NULL); | 77 this->inval(nullptr); |
78 } | 78 } |
79 else | 79 else |
80 { | 80 { |
81 U16CPU value = SkMax32(0, SkMin32(fValue, fMax)); | 81 U16CPU value = SkMax32(0, SkMin32(fValue, fMax)); |
82 percent = SkFixedDiv(value, fMax); | 82 percent = SkFixedDiv(value, fMax); |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 SkRect r; | 86 SkRect r; |
87 SkPaint p; | 87 SkPaint p; |
(...skipping 17 matching lines...) Expand all Loading... |
105 } | 105 } |
106 | 106 |
107 #include "SkImageDecoder.h" | 107 #include "SkImageDecoder.h" |
108 | 108 |
109 static SkShader* inflate_shader(const char file[]) | 109 static SkShader* inflate_shader(const char file[]) |
110 { | 110 { |
111 SkBitmap bm; | 111 SkBitmap bm; |
112 | 112 |
113 return SkImageDecoder::DecodeFile(file, &bm) ? | 113 return SkImageDecoder::DecodeFile(file, &bm) ? |
114 SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, SkShade
r::kRepeat_TileMode) : | 114 SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, SkShade
r::kRepeat_TileMode) : |
115 NULL; | 115 nullptr; |
116 } | 116 } |
117 | 117 |
118 void SkProgressView::onInflate(const SkDOM& dom, const SkDOM::Node* node) | 118 void SkProgressView::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
119 { | 119 { |
120 this->INHERITED::onInflate(dom, node); | 120 this->INHERITED::onInflate(dom, node); |
121 | 121 |
122 const char* s; | 122 const char* s; |
123 | 123 |
124 SkASSERT(fOnShader == NULL); | 124 SkASSERT(fOnShader == nullptr); |
125 SkASSERT(fOffShader == NULL); | 125 SkASSERT(fOffShader == nullptr); |
126 | 126 |
127 if ((s = dom.findAttr(node, "src-on")) != NULL) | 127 if ((s = dom.findAttr(node, "src-on")) != nullptr) |
128 fOnShader = inflate_shader(s); | 128 fOnShader = inflate_shader(s); |
129 if ((s = dom.findAttr(node, "src-off")) != NULL) | 129 if ((s = dom.findAttr(node, "src-off")) != nullptr) |
130 fOffShader = inflate_shader(s); | 130 fOffShader = inflate_shader(s); |
131 (void)dom.findBool(node, "do-interp", &fDoInterp); | 131 (void)dom.findBool(node, "do-interp", &fDoInterp); |
132 } | 132 } |
OLD | NEW |