Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ninepatch.h
Go to the documentation of this file.
1 
18 #ifndef ION_IMAGE_NINEPATCH_H_
19 #define ION_IMAGE_NINEPATCH_H_
20 
21 #include "base/integral_types.h"
22 #include "base/macros.h"
25 #include "ion/external/gtest/gunit_prod.h"
26 #include "ion/gfx/image.h"
27 #include "ion/math/range.h"
28 #include "ion/math/vector.h"
29 
30 namespace ion {
31 namespace image {
32 
40 class ION_API NinePatch : public base::Referent {
41  public:
46  explicit NinePatch(const gfx::ImagePtr& image);
47 
56  const gfx::ImagePtr BuildImage(uint32 width, uint32 height,
57  const base::AllocatorPtr& alloc) const;
58 
63  void SetBuildWipeable(bool wipable) { wipeable_ = wipable; }
64 
67  const math::Vector2ui GetMinimumSize() const;
68 
72  const math::Range2ui GetPaddingBox(uint32 width, uint32 height) const;
73 
77  const math::Vector2ui GetSizeToFitContent(
78  uint32 content_width, uint32 content_height) const;
79 
80  private:
82  struct Region;
83 
86  ~NinePatch() override;
87 
90  const base::AllocVector<Region> GetRegionsForSize(uint32 width,
91  uint32 height) const;
92 
97  math::Range2ui padding_;
99  gfx::ImagePtr image_;
101  bool wipeable_;
102 
103  FRIEND_TEST(NinePatch, StretchRegions);
104  FRIEND_TEST(NinePatch, PaddingBox);
105  DISALLOW_COPY_AND_ASSIGN(NinePatch);
106 };
107 
110 
111 } // namespace image
112 } // namespace ion
113 
114 #endif // ION_IMAGE_NINEPATCH_H_
Represents a nine-patch image as described in the Android SDK reference.
Definition: ninepatch.h:40
Thread-safe abstract base class.
Definition: referent.h:49
const Grid & image
The original monochrome image data, as doubles (0 - 1).
Definition: sdfutils.cc:90
int width
base::ReferentPtr< NinePatch >::Type NinePatchPtr
Convenience typedef.
Definition: ninepatch.h:109
void SetBuildWipeable(bool wipable)
Sets whether images returned by BuildImage() are wipeable (see base::DataContainer) or not...
Definition: ninepatch.h:63
Range< 2, uint32 > Range2ui
Definition: range.h:372
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
This class can be used in place of std::vector to allow an Ion Allocator to be used for memory alloca...
Definition: allocvector.h:50