| Flutter Impeller |

rectangle_packer.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
6 #define FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
7
8 #include "flutter/fml/logging.h"
9 #include "impeller/geometry/scalar.h"
10
11 #include <cstdint>
12 #include <memory>
13
14 namespace impeller {
15
16 struct IPoint16 {
17 int16_t x() const { return x_; }
18 int16_t y() const { return y_; }
19
20 int16_t x_;
21 int16_t y_;
22 };
23
24 //------------------------------------------------------------------------------
25 /// @brief Packs rectangles into a specified area without rotating them.
26 ///
27 class RectanglePacker {
28 public:
29 //----------------------------------------------------------------------------
30 /// @brief Return an empty packer with area specified by width and height.
31 ///
32 static std::shared_ptr<RectanglePacker> Factory(int width, int height);
33
34 virtual ~RectanglePacker() {}
35
36 //----------------------------------------------------------------------------
37 /// @brief Attempt to add a rect without moving already placed rectangles.
38 ///
39 /// @param[in] width The width of the rectangle to add.
40 /// @param[in] height The height of the rectangle to add.
41 /// @param[out] loc If successful, will be set to the position of the
42 /// upper-left corner of the rectangle.
43 ///
44 /// @return Return true on success; false on failure.
45 ///
46 virtual bool AddRect(int width, int height, IPoint16* loc) = 0;
47
48 //----------------------------------------------------------------------------
49 /// @brief Returns how much area has been filled with rectangles.
50 ///
51 /// @return Percentage as a decimal between 0.0 and 1.0
52 ///
53 virtual Scalar PercentFull() const = 0;
54
55 //----------------------------------------------------------------------------
56 /// @brief Empty out all previously added rectangles.
57 ///
58 virtual void Reset() = 0;
59
60 protected:
61 RectanglePacker(int width, int height) : width_(width), height_(height) {
62 FML_DCHECK(width >= 0);
63 FML_DCHECK(height >= 0);
64 }
65
66 int width() const { return width_; }
67 int height() const { return height_; }
68
69 private:
70 const int width_;
71 const int height_;
72 };
73
74 } // namespace impeller
75
76 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
impeller::RectanglePacker
Packs rectangles into a specified area without rotating them.
Definition: rectangle_packer.h:27
impeller::RectanglePacker::width
int width() const
Definition: rectangle_packer.h:66
impeller::RectanglePacker::PercentFull
virtual Scalar PercentFull() const =0
Returns how much area has been filled with rectangles.
impeller::RectanglePacker::Reset
virtual void Reset()=0
Empty out all previously added rectangles.
impeller::RectanglePacker::AddRect
virtual bool AddRect(int width, int height, IPoint16 *loc)=0
Attempt to add a rect without moving already placed rectangles.
impeller::RectanglePacker::RectanglePacker
RectanglePacker(int width, int height)
Definition: rectangle_packer.h:61
impeller::RectanglePacker::~RectanglePacker
virtual ~RectanglePacker()
Definition: rectangle_packer.h:34
impeller::RectanglePacker::height
int height() const
Definition: rectangle_packer.h:67
impeller::RectanglePacker::Factory
static std::shared_ptr< RectanglePacker > Factory(int width, int height)
Return an empty packer with area specified by width and height.
Definition: rectangle_packer.cc:175
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:18
scalar.h
impeller::IPoint16
Definition: rectangle_packer.h:16
impeller::IPoint16::y_
int16_t y_
Definition: rectangle_packer.h:21
impeller::IPoint16::y
int16_t y() const
Definition: rectangle_packer.h:18
impeller::IPoint16::x
int16_t x() const
Definition: rectangle_packer.h:17
impeller::IPoint16::x_
int16_t x_
Definition: rectangle_packer.h:20