Pebble Foundation Classes  0.2.0
C++ for Pebble
pebble_graphics_types.hpp
1 #pragma once
2 
3 namespace Pebble {
4 
5 struct GSize : public ::GSize
6 {
7  GSize() {}
8 
9  GSize(const ::GSize &size)
10  {
11  w = size.w;
12  h = size.h;
13  }
14 
15  GSize(int16_t w, int16_t h)
16  {
17  this->w = w;
18  this->h = h;
19  }
20 
21  inline operator const ::GSize*() const { return this; }
22  inline operator ::GSize*() { return this; }
23 
24  inline bool operator== (const ::GSize& size) const { return gsize_equal(this, &size); }
25 
26  inline bool operator!= (const ::GSize& size) const { return !(*this == size); }
27 };
28 
33 struct GPoint : public ::GPoint
34 {
36  GPoint() {}
37 
40  {
41  x = point.x;
42  y = point.y;
43  }
44 
48  GPoint(int16_t x, int16_t y)
49  {
50  this->x = x;
51  this->y = y;
52  }
53 
55  inline operator const ::GPoint*() const { return this; }
56  inline operator ::GPoint*() { return this; }
57 
61  inline bool operator== (const ::GPoint& point) const { return gpoint_equal(this, &point); }
62 
66  inline bool operator!= (const ::GPoint& point) const { return !(*this == point); }
67 };
68 
71 struct GRect
72 {
77 
79  GRect() {}
80 
83  {
84  origin.x = rect.origin.x;
85  origin.y = rect.origin.y;
86  size.w = rect.size.w;
87  size.h = rect.size.h;
88  }
89 
95  GRect(int16_t x, int16_t y, int16_t w, int16_t h) {
96  origin.x = x;
97  origin.y = y;
98  size.w = w;
99  size.h = h;
100  }
101 
106  {
107  this->origin = origin;
108  this->size = size;
109  }
110 
115  {
116  this->origin = origin;
117  this->size = size;
118  }
119 
121  inline operator ::GRect&() { return *(::GRect*)this; }
123  inline operator const ::GRect&() const { return *(::GRect*)this; }
125  inline operator ::GRect*() { return (::GRect*)this; }
127  inline operator const ::GRect*() const { return (::GRect*)this; }
128 
132  inline bool operator== (const ::GRect& rect) const { return grect_equal(*this, &rect); }
133 
137  inline bool operator!= (const ::GRect& rect) const { return !(*this == rect); }
138 
147  inline void Align(const ::GRect& inside_rect, const GAlign alignment, const bool clip) { grect_align(*this, &inside_rect, alignment, clip); }
148 
152  inline GPoint CenterPoint() const { return grect_center_point(*this); }
153 
160  inline GRect Inset(GEdgeInsets insets) const { return grect_inset(*this, insets); }
161 
166  inline bool IsEmpty() { return grect_is_empty(*this); }
167 
173  inline void Standardize() { grect_standardize(*this); }
174 
178  inline void Clip(const GRect& rect_clipper) { grect_clip(*this, rect_clipper); }
179 
183  inline bool ContainsPoint(const GPoint& point) { return grect_contains_point(*this, point); }
184 
192  inline GRect Crop(int32_t crop_size_px) { return grect_crop(*this, crop_size_px); }
193 
200  inline GPoint FromPolar(GOvalScaleMode scale_mode, int32_t angle)
201  {
202  return gpoint_from_polar(*this, scale_mode, angle);
203  }
204 
215  inline GRect CenterFromPolar(GOvalScaleMode scale_mode, int32_t angle, GSize size)
216  {
217  return grect_centered_from_polar(*this, scale_mode, angle, size);
218  }
219 };
220 
221 
223 {
224 public:
226  operator ::GBitmap*() const { return gbitmap_; }
227 
229  virtual ~GBitmapBase()
230  {
231  }
232 
241  inline uint16_t GetBytesPerRow() const { return gbitmap_get_bytes_per_row(gbitmap_); }
242 
245  inline GBitmapFormat GetFormat() const { return gbitmap_get_format(gbitmap_); }
246 
252  inline uint8_t* GetData() const { return gbitmap_get_data(gbitmap_); }
253 
258  inline GRect GetBounds() const { return gbitmap_get_bounds(gbitmap_); }
259 
263  inline GColor* GetPalette() const { return gbitmap_get_palette(gbitmap_); }
264 
265 protected:
267  GBitmapBase() : gbitmap_(nullptr)
268  {
269  }
270 
272  GBitmapBase(::GBitmap* gbitmap) : gbitmap_(gbitmap)
273  {
274  }
275 
276  // Private instance of window pebble Window pointer
277  ::GBitmap *gbitmap_;
278 
279  // Allow GBitmap to access the protected members of this class to provide
280  // the reference features.
281  friend class GBitmap;
282 }; // End Class
283 
284 
286 class GBitmap : public GBitmapBase
287 {
288 public:
290  GBitmap(::GBitmap* gbitmap) : GBitmapBase(gbitmap)
291  {
292  }
293 
295  GBitmap(const GBitmapBase& that) : GBitmapBase(that.gbitmap_)
296  {
297  }
298 
301  {
302  gbitmap_ = that.gbitmap_;
303  return *this;
304  }
305 
307  GBitmap& operator=(::GBitmap* gbitmap)
308  {
309  gbitmap_ = gbitmap;
310  return *this;
311  }
312 
314  inline bool IsValid() { return gbitmap_ != nullptr; }
315 }; // End Class
316 
317 
319 class GOwnedBitmap : public GBitmapBase
320 {
321 public:
322  GOwnedBitmap() : GBitmapBase() {}
323 
325  GOwnedBitmap(const GBitmap&) = delete;
326 
328  GOwnedBitmap(GOwnedBitmap&& that) : GBitmapBase(that.gbitmap_)
329  {
330  that.gbitmap_ = nullptr;
331  }
332 
335  {
336  std::swap(gbitmap_, that.gbitmap_);
337  return *this;
338  }
339 
342  {
343  std::swap(gbitmap_, that.gbitmap_);
344  return *this;
345  }
346 
348  virtual ~GOwnedBitmap()
349  {
350  if (gbitmap_) gbitmap_destroy(gbitmap_);
351  }
352 
360  inline void SetData(uint8_t * data, GBitmapFormat format, uint16_t row_size_bytes, bool free_on_destroy)
361  {
362  gbitmap_set_data(gbitmap_, data, format, row_size_bytes, free_on_destroy);
363  }
364 
368  inline void SetBounds(const GRect& bounds) { gbitmap_set_bounds(gbitmap_, bounds); }
369 
376  inline void SetPalette(GColor* palette, bool free_on_destroy) { gbitmap_set_palette(gbitmap_, palette, free_on_destroy); }
377 
385  static inline GOwnedBitmap CreateFromPngData(const uint8_t * png_data, size_t png_data_size)
386  {
387  return gbitmap_create_from_png_data(png_data, png_data_size);
388  }
389 
402  static inline GOwnedBitmap CreateSubBitmap(const ::GBitmap* base_bitmap, ::GRect sub_rect)
403  {
404  return gbitmap_create_as_sub_bitmap(base_bitmap, sub_rect);
405  }
406 
419  static inline GOwnedBitmap CreateWithData(const uint8_t* data)
420  {
421  return gbitmap_create_with_data(data);
422  }
423 
427  static inline GOwnedBitmap CreateWithResource(uint32_t resource_id)
428  {
429  return gbitmap_create_with_resource(resource_id);
430  }
431 
438  static inline GOwnedBitmap CreateBlank(GSize size, GBitmapFormat format)
439  {
440  return gbitmap_create_blank(size, format);
441  }
442 
456  static inline GOwnedBitmap CreateBlank(GSize size, GBitmapFormat format, GColor* palette, bool free_on_destroy)
457  {
458  return gbitmap_create_blank_with_palette(size, format, palette, free_on_destroy);
459  }
460 
468  static inline GOwnedBitmap CreatePalettizedFrom1bit(const ::GBitmap* src_bitmap)
469  {
470  return gbitmap_create_palettized_from_1bit(src_bitmap);
471  }
472 
473 protected:
475  GOwnedBitmap(::GBitmap* bitmap) : GBitmapBase(bitmap)
476  {
477  }
478 
479 }; // End Class
480 
481 
482 }
Pebble::GBitmap::GBitmap
GBitmap(::GBitmap *gbitmap)
Wrap a Pebble bitmap.
Definition: pebble_graphics_types.hpp:290
grect_clip
void grect_clip(GRect *const rect_to_clip, const GRect *const rect_clipper)
Pebble::GOwnedBitmap::CreateFromPngData
static GOwnedBitmap CreateFromPngData(const uint8_t *png_data, size_t png_data_size)
Definition: pebble_graphics_types.hpp:385
Pebble::GRect::GRect
GRect(GPoint origin, GSize size)
Definition: pebble_graphics_types.hpp:114
gbitmap_create_with_data
GBitmap * gbitmap_create_with_data(const uint8_t *data)
Pebble::GRect::GRect
GRect()
Constructs an empty GRect.
Definition: pebble_graphics_types.hpp:79
Pebble::GRect::GRect
GRect(int16_t x, int16_t y, int16_t w, int16_t h)
Definition: pebble_graphics_types.hpp:95
Pebble::GOwnedBitmap::GOwnedBitmap
GOwnedBitmap(::GBitmap *bitmap)
Create bitmap as sub bitmap.
Definition: pebble_graphics_types.hpp:475
Pebble::GRect::operator==
bool operator==(const ::GRect &rect) const
Definition: pebble_graphics_types.hpp:132
Pebble::GBitmapBase::GetBytesPerRow
uint16_t GetBytesPerRow() const
Definition: pebble_graphics_types.hpp:241
gbitmap_create_blank
GBitmap * gbitmap_create_blank(GSize size, GBitmapFormat format)
Pebble::GRect::CenterFromPolar
GRect CenterFromPolar(GOvalScaleMode scale_mode, int32_t angle, GSize size)
Definition: pebble_graphics_types.hpp:215
Pebble::GBitmapBase::GBitmapBase
GBitmapBase(::GBitmap *gbitmap)
Wrap a Pebble bitmap.
Definition: pebble_graphics_types.hpp:272
Pebble::GOwnedBitmap::CreateWithData
static GOwnedBitmap CreateWithData(const uint8_t *data)
Definition: pebble_graphics_types.hpp:419
Pebble::GOwnedBitmap::~GOwnedBitmap
virtual ~GOwnedBitmap()
Destroy the bitmap if pointer provided.
Definition: pebble_graphics_types.hpp:348
gsize_equal
bool gsize_equal(const GSize *size_a, const GSize *size_b)
grect_crop
GRect grect_crop(GRect rect, const int32_t crop_size_px)
Pebble::GRect::Clip
void Clip(const GRect &rect_clipper)
Definition: pebble_graphics_types.hpp:178
Pebble::GRect::Align
void Align(const ::GRect &inside_rect, const GAlign alignment, const bool clip)
Definition: pebble_graphics_types.hpp:147
Pebble::GOwnedBitmap::CreatePalettizedFrom1bit
static GOwnedBitmap CreatePalettizedFrom1bit(const ::GBitmap *src_bitmap)
Definition: pebble_graphics_types.hpp:468
Pebble::GRect::GRect
GRect(const ::GRect &rect)
Converts from Pebble GRect.
Definition: pebble_graphics_types.hpp:82
Pebble::GOwnedBitmap::SetData
void SetData(uint8_t *data, GBitmapFormat format, uint16_t row_size_bytes, bool free_on_destroy)
Definition: pebble_graphics_types.hpp:360
gbitmap_create_blank_with_palette
GBitmap * gbitmap_create_blank_with_palette(GSize size, GBitmapFormat format, GColor *palette, bool free_on_destroy)
Pebble::GRect::GRect
GRect(::GPoint origin, ::GSize size)
Definition: pebble_graphics_types.hpp:105
GEdgeInsets
Definition: pebble.h:3804
Pebble::GRect::ContainsPoint
bool ContainsPoint(const GPoint &point)
Definition: pebble_graphics_types.hpp:183
GOvalScaleMode
GOvalScaleMode
Definition: pebble.h:4099
Pebble::GBitmap::operator=
GBitmap & operator=(::GBitmap *gbitmap)
Assign the bitmap.
Definition: pebble_graphics_types.hpp:307
GAlign
GAlign
Definition: pebble.h:3713
Pebble::GBitmap
An unowned bitmap.
Definition: pebble_graphics_types.hpp:286
Pebble::GRect::CenterPoint
GPoint CenterPoint() const
Definition: pebble_graphics_types.hpp:152
Pebble::GOwnedBitmap::GOwnedBitmap
GOwnedBitmap(GOwnedBitmap &&that)
Move constructor.
Definition: pebble_graphics_types.hpp:328
Pebble::GPoint::GPoint
GPoint()
Constructs a new GPoint.
Definition: pebble_graphics_types.hpp:36
Pebble::GOwnedBitmap::operator=
GOwnedBitmap & operator=(GOwnedBitmap &that)
Swap assignment operator.
Definition: pebble_graphics_types.hpp:341
gbitmap_create_from_png_data
GBitmap * gbitmap_create_from_png_data(const uint8_t *png_data, size_t png_data_size)
gbitmap_get_data
uint8_t * gbitmap_get_data(const GBitmap *bitmap)
Pebble::GOwnedBitmap::SetPalette
void SetPalette(GColor *palette, bool free_on_destroy)
Definition: pebble_graphics_types.hpp:376
Pebble::GBitmap::GBitmap
GBitmap(const GBitmapBase &that)
Copy bitmap reference.
Definition: pebble_graphics_types.hpp:295
GPoint::y
int16_t y
The y-coordinate.
Definition: pebble.h:3320
grect_inset
GRect grect_inset(GRect rect, GEdgeInsets insets)
GSize
struct GSize GSize
Represents a 2-dimensional size.
GBitmapFormat
GBitmapFormat
The format of a GBitmap can either be 1-bit or 8-bit.
Definition: pebble.h:3428
Pebble::GPoint::GPoint
GPoint(int16_t x, int16_t y)
Definition: pebble_graphics_types.hpp:48
Pebble::GRect::FromPolar
GPoint FromPolar(GOvalScaleMode scale_mode, int32_t angle)
Definition: pebble_graphics_types.hpp:200
Pebble::GRect::IsEmpty
bool IsEmpty()
Definition: pebble_graphics_types.hpp:166
Pebble::GBitmapBase::GetBounds
GRect GetBounds() const
Definition: pebble_graphics_types.hpp:258
grect_centered_from_polar
GRect grect_centered_from_polar(GRect rect, GOvalScaleMode scale_mode, int32_t angle, GSize size)
grect_standardize
void grect_standardize(GRect *rect)
gbitmap_create_palettized_from_1bit
GBitmap * gbitmap_create_palettized_from_1bit(const GBitmap *src_bitmap)
Pebble::GRect::origin
GPoint origin
The coordinate of the upper-lefthand corner point of the rectangle.
Definition: pebble_graphics_types.hpp:74
Pebble::GOwnedBitmap::SetBounds
void SetBounds(const GRect &bounds)
Definition: pebble_graphics_types.hpp:368
gbitmap_get_bytes_per_row
uint16_t gbitmap_get_bytes_per_row(const GBitmap *bitmap)
gbitmap_destroy
void gbitmap_destroy(GBitmap *bitmap)
Pebble::GOwnedBitmap
A bitmap that destroys the underlying reference when destructed.
Definition: pebble_graphics_types.hpp:319
Pebble::GPoint::GPoint
GPoint(const ::GPoint &point)
Converts from a Pebble GPoint.
Definition: pebble_graphics_types.hpp:39
Pebble::GRect::size
GSize size
The size of the rectangle.
Definition: pebble_graphics_types.hpp:76
Pebble::GSize
Definition: pebble_graphics_types.hpp:5
Pebble::GBitmapBase::GetFormat
GBitmapFormat GetFormat() const
Definition: pebble_graphics_types.hpp:245
Pebble::GPoint::operator==
bool operator==(const ::GPoint &point) const
Definition: pebble_graphics_types.hpp:61
GPoint::x
int16_t x
The x-coordinate.
Definition: pebble.h:3318
GPoint
struct GPoint GPoint
Pebble::GBitmapBase
Definition: pebble_graphics_types.hpp:222
gbitmap_create_as_sub_bitmap
GBitmap * gbitmap_create_as_sub_bitmap(const GBitmap *base_bitmap, GRect sub_rect)
gbitmap_get_format
GBitmapFormat gbitmap_get_format(const GBitmap *bitmap)
GSize::w
int16_t w
The width.
Definition: pebble.h:3338
Pebble::GRect
Definition: pebble_graphics_types.hpp:71
grect_center_point
GPoint grect_center_point(const GRect *rect)
Pebble::GOwnedBitmap::CreateBlank
static GOwnedBitmap CreateBlank(GSize size, GBitmapFormat format, GColor *palette, bool free_on_destroy)
Definition: pebble_graphics_types.hpp:456
GRect
struct GRect GRect
gbitmap_set_palette
void gbitmap_set_palette(GBitmap *bitmap, GColor *palette, bool free_on_destroy)
gbitmap_set_data
void gbitmap_set_data(GBitmap *bitmap, uint8_t *data, GBitmapFormat format, uint16_t row_size_bytes, bool free_on_destroy)
Pebble::GBitmapBase::GetPalette
GColor * GetPalette() const
Definition: pebble_graphics_types.hpp:263
gbitmap_set_bounds
void gbitmap_set_bounds(GBitmap *bitmap, GRect bounds)
gbitmap_create_with_resource
GBitmap * gbitmap_create_with_resource(uint32_t resource_id)
gbitmap_get_bounds
GRect gbitmap_get_bounds(const GBitmap *bitmap)
Pebble::GOwnedBitmap::CreateWithResource
static GOwnedBitmap CreateWithResource(uint32_t resource_id)
Definition: pebble_graphics_types.hpp:427
GSize::h
int16_t h
The height.
Definition: pebble.h:3340
Pebble::GRect::operator!=
bool operator!=(const ::GRect &rect) const
Definition: pebble_graphics_types.hpp:137
grect_equal
bool grect_equal(const GRect *const rect_a, const GRect *const rect_b)
Pebble::GBitmapBase::~GBitmapBase
virtual ~GBitmapBase()
Destructor.
Definition: pebble_graphics_types.hpp:229
Pebble::GRect::Inset
GRect Inset(GEdgeInsets insets) const
Definition: pebble_graphics_types.hpp:160
gpoint_from_polar
GPoint gpoint_from_polar(GRect rect, GOvalScaleMode scale_mode, int32_t angle)
grect_is_empty
bool grect_is_empty(const GRect *const rect)
grect_align
void grect_align(GRect *rect, const GRect *inside_rect, const GAlign alignment, const bool clip)
gpoint_equal
bool gpoint_equal(const GPoint *const point_a, const GPoint *const point_b)
Pebble::GPoint
Definition: pebble_graphics_types.hpp:33
Pebble::GBitmapBase::GetData
uint8_t * GetData() const
Definition: pebble_graphics_types.hpp:252
Pebble::GRect::Crop
GRect Crop(int32_t crop_size_px)
Definition: pebble_graphics_types.hpp:192
Pebble::GOwnedBitmap::operator=
GOwnedBitmap & operator=(GOwnedBitmap that)
Swap assignment operator.
Definition: pebble_graphics_types.hpp:334
grect_contains_point
bool grect_contains_point(const GRect *rect, const GPoint *point)
Pebble::GRect::Standardize
void Standardize()
Definition: pebble_graphics_types.hpp:173
Pebble::GBitmap::IsValid
bool IsValid()
Returns true if the bitmap is valid and can be used.
Definition: pebble_graphics_types.hpp:314
GColor8
Definition: pebble.h:3268
Pebble::GOwnedBitmap::CreateBlank
static GOwnedBitmap CreateBlank(GSize size, GBitmapFormat format)
Definition: pebble_graphics_types.hpp:438
Pebble::GBitmapBase::GBitmapBase
GBitmapBase()
Cannot construct.
Definition: pebble_graphics_types.hpp:267
gbitmap_get_palette
GColor * gbitmap_get_palette(const GBitmap *bitmap)
Pebble::GPoint::operator!=
bool operator!=(const ::GPoint &point) const
Definition: pebble_graphics_types.hpp:66
Pebble::GBitmap::operator=
GBitmap & operator=(const GBitmapBase &that)
Assign the bitmap.
Definition: pebble_graphics_types.hpp:300
Pebble::GOwnedBitmap::CreateSubBitmap
static GOwnedBitmap CreateSubBitmap(const ::GBitmap *base_bitmap, ::GRect sub_rect)
Definition: pebble_graphics_types.hpp:402