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 #pragma once
6 
7 #include "flutter/fml/logging.h"
8 
9 #include <cstdint>
10 
11 namespace impeller {
12 
13 struct IPoint16 {
14  int16_t x() const { return x_; }
15  int16_t y() const { return y_; }
16 
17  int16_t x_;
18  int16_t y_;
19 };
20 
21 //------------------------------------------------------------------------------
22 /// @brief Packs rectangles into a specified area without rotating them.
23 ///
25  public:
26  //----------------------------------------------------------------------------
27  /// @brief Return an empty packer with area specified by width and height.
28  ///
29  static RectanglePacker* Factory(int width, int height);
30 
31  virtual ~RectanglePacker() {}
32 
33  //----------------------------------------------------------------------------
34  /// @brief Attempt to add a rect without moving already placed rectangles.
35  ///
36  /// @param[in] width The width of the rectangle to add.
37  /// @param[in] height The height of the rectangle to add.
38  /// @param[out] loc If successful, will be set to the position of the
39  /// upper-left corner of the rectangle.
40  ///
41  /// @return Return true on success; false on failure.
42  ///
43  virtual bool addRect(int width, int height, IPoint16* loc) = 0;
44 
45  //----------------------------------------------------------------------------
46  /// @brief Returns how much area has been filled with rectangles.
47  ///
48  /// @return Percentage as a decimal between 0.0 and 1.0
49  ///
50  virtual float percentFull() const = 0;
51 
52  //----------------------------------------------------------------------------
53  /// @brief Empty out all previously added rectangles.
54  ///
55  virtual void reset() = 0;
56 
57  protected:
58  RectanglePacker(int width, int height) : width_(width), height_(height) {
59  FML_DCHECK(width >= 0);
60  FML_DCHECK(height >= 0);
61  }
62 
63  int width() const { return width_; }
64  int height() const { return height_; }
65 
66  private:
67  const int width_;
68  const int height_;
69 };
70 
71 } // namespace impeller
impeller::RectanglePacker::width
int width() const
Definition: rectangle_packer.h:63
impeller::RectanglePacker::percentFull
virtual float percentFull() const =0
Returns how much area has been filled with rectangles.
impeller::IPoint16::x
int16_t x() const
Definition: rectangle_packer.h:14
impeller::IPoint16::y
int16_t y() const
Definition: rectangle_packer.h:15
impeller::RectanglePacker
Packs rectangles into a specified area without rotating them.
Definition: rectangle_packer.h:24
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::height
int height() const
Definition: rectangle_packer.h:64
impeller::IPoint16::x_
int16_t x_
Definition: rectangle_packer.h:17
impeller::RectanglePacker::RectanglePacker
RectanglePacker(int width, int height)
Definition: rectangle_packer.h:58
impeller::IPoint16::y_
int16_t y_
Definition: rectangle_packer.h:18
impeller::RectanglePacker::Factory
static RectanglePacker * Factory(int width, int height)
Return an empty packer with area specified by width and height.
Definition: rectangle_packer.cc:169
impeller::RectanglePacker::~RectanglePacker
virtual ~RectanglePacker()
Definition: rectangle_packer.h:31
impeller::IPoint16
Definition: rectangle_packer.h:13
impeller::RectanglePacker::reset
virtual void reset()=0
Empty out all previously added rectangles.
impeller
Definition: aiks_context.cc:10