OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrRect_DEFINED | 8 #ifndef GrRect_DEFINED |
9 #define GrRect_DEFINED | 9 #define GrRect_DEFINED |
10 | 10 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 #include "SkRect.h" | 12 #include "SkRect.h" |
13 | 13 |
14 struct GrIRect16 { | 14 struct GrIRect16 { |
15 int16_t fLeft, fTop, fRight, fBottom; | 15 int16_t fLeft, fTop, fRight, fBottom; |
16 | 16 |
17 static GrIRect16 SK_WARN_UNUSED_RESULT MakeEmpty() { | 17 static GrIRect16 SK_WARN_UNUSED_RESULT MakeEmpty() { |
18 GrIRect16 r; | 18 GrIRect16 r; |
19 r.setEmpty(); | 19 r.setEmpty(); |
20 return r; | 20 return r; |
21 } | 21 } |
22 | 22 |
| 23 static GrIRect16 SK_WARN_UNUSED_RESULT MakeWH(int16_t w, int16_t h) { |
| 24 GrIRect16 r; |
| 25 r.set(0, 0, w, h); |
| 26 return r; |
| 27 } |
| 28 |
| 29 static GrIRect16 SK_WARN_UNUSED_RESULT MakeXYWH(int16_t x, int16_t y, int16_
t w, int16_t h) { |
| 30 GrIRect16 r; |
| 31 r.set(x, y, x + w, y + h); |
| 32 return r; |
| 33 } |
| 34 |
23 int width() const { return fRight - fLeft; } | 35 int width() const { return fRight - fLeft; } |
24 int height() const { return fBottom - fTop; } | 36 int height() const { return fBottom - fTop; } |
25 int area() const { return this->width() * this->height(); } | 37 int area() const { return this->width() * this->height(); } |
26 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } | 38 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } |
27 | 39 |
28 void setEmpty() { memset(this, 0, sizeof(*this)); } | 40 void setEmpty() { memset(this, 0, sizeof(*this)); } |
29 | 41 |
| 42 void set(int16_t left, int16_t top, int16_t right, int16_t bottom) { |
| 43 fLeft = left; |
| 44 fTop = top; |
| 45 fRight = right; |
| 46 fBottom = bottom; |
| 47 } |
| 48 |
30 void set(const SkIRect& r) { | 49 void set(const SkIRect& r) { |
31 fLeft = SkToS16(r.fLeft); | 50 fLeft = SkToS16(r.fLeft); |
32 fTop = SkToS16(r.fTop); | 51 fTop = SkToS16(r.fTop); |
33 fRight = SkToS16(r.fRight); | 52 fRight = SkToS16(r.fRight); |
34 fBottom = SkToS16(r.fBottom); | 53 fBottom = SkToS16(r.fBottom); |
35 } | 54 } |
36 }; | 55 }; |
37 | 56 |
38 #endif | 57 #endif |
OLD | NEW |