2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrRect_DEFINED
|
|
|
|
#define GrRect_DEFINED
|
|
|
|
|
2013-07-17 21:39:42 +00:00
|
|
|
#include "SkTypes.h"
|
2011-05-09 17:00:02 +00:00
|
|
|
#include "SkRect.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
struct GrIRect16 {
|
|
|
|
int16_t fLeft, fTop, fRight, fBottom;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-04-10 18:36:19 +00:00
|
|
|
static GrIRect16 SK_WARN_UNUSED_RESULT MakeEmpty() {
|
|
|
|
GrIRect16 r;
|
|
|
|
r.setEmpty();
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-06-30 15:26:50 +00:00
|
|
|
static GrIRect16 SK_WARN_UNUSED_RESULT MakeWH(int16_t w, int16_t h) {
|
|
|
|
GrIRect16 r;
|
|
|
|
r.set(0, 0, w, h);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GrIRect16 SK_WARN_UNUSED_RESULT MakeXYWH(int16_t x, int16_t y, int16_t w, int16_t h) {
|
|
|
|
GrIRect16 r;
|
|
|
|
r.set(x, y, x + w, y + h);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
int width() const { return fRight - fLeft; }
|
|
|
|
int height() const { return fBottom - fTop; }
|
|
|
|
int area() const { return this->width() * this->height(); }
|
|
|
|
bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-04-10 18:36:19 +00:00
|
|
|
void setEmpty() { memset(this, 0, sizeof(*this)); }
|
|
|
|
|
2014-06-30 15:26:50 +00:00
|
|
|
void set(int16_t left, int16_t top, int16_t right, int16_t bottom) {
|
|
|
|
fLeft = left;
|
|
|
|
fTop = top;
|
|
|
|
fRight = right;
|
|
|
|
fBottom = bottom;
|
|
|
|
}
|
|
|
|
|
2013-07-17 21:39:42 +00:00
|
|
|
void set(const SkIRect& r) {
|
2011-05-09 17:00:02 +00:00
|
|
|
fLeft = SkToS16(r.fLeft);
|
|
|
|
fTop = SkToS16(r.fTop);
|
|
|
|
fRight = SkToS16(r.fRight);
|
|
|
|
fBottom = SkToS16(r.fBottom);
|
2011-03-03 13:54:13 +00:00
|
|
|
}
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|