| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_GEOMETRY_INSETS_H_ | 5 #ifndef UI_GFX_GEOMETRY_INSETS_H_ |
| 6 #define UI_GFX_GEOMETRY_INSETS_H_ | 6 #define UI_GFX_GEOMETRY_INSETS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ui/gfx/geometry/insets_f.h" | 10 #include "ui/gfx/geometry/insets_f.h" |
| 11 #include "ui/gfx/gfx_export.h" | 11 #include "ui/gfx/gfx_export.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 | 14 |
| 15 class Vector2d; |
| 16 |
| 15 // Represents the widths of the four borders or margins of an unspecified | 17 // Represents the widths of the four borders or margins of an unspecified |
| 16 // rectangle. An Insets stores the thickness of the top, left, bottom and right | 18 // rectangle. An Insets stores the thickness of the top, left, bottom and right |
| 17 // edges, without storing the actual size and position of the rectangle itself. | 19 // edges, without storing the actual size and position of the rectangle itself. |
| 18 // | 20 // |
| 19 // This can be used to represent a space within a rectangle, by "shrinking" the | 21 // This can be used to represent a space within a rectangle, by "shrinking" the |
| 20 // rectangle by the inset amount on all four sides. Alternatively, it can | 22 // rectangle by the inset amount on all four sides. Alternatively, it can |
| 21 // represent a border that has a different thickness on each side. | 23 // represent a border that has a different thickness on each side. |
| 22 class GFX_EXPORT Insets { | 24 class GFX_EXPORT Insets { |
| 23 public: | 25 public: |
| 24 constexpr Insets() : top_(0), left_(0), bottom_(0), right_(0) {} | 26 constexpr Insets() : top_(0), left_(0), bottom_(0), right_(0) {} |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return Scale(scale, scale); | 88 return Scale(scale, scale); |
| 87 } | 89 } |
| 88 | 90 |
| 89 Insets Scale(float x_scale, float y_scale) const { | 91 Insets Scale(float x_scale, float y_scale) const { |
| 90 return Insets(static_cast<int>(top() * y_scale), | 92 return Insets(static_cast<int>(top() * y_scale), |
| 91 static_cast<int>(left() * x_scale), | 93 static_cast<int>(left() * x_scale), |
| 92 static_cast<int>(bottom() * y_scale), | 94 static_cast<int>(bottom() * y_scale), |
| 93 static_cast<int>(right() * x_scale)); | 95 static_cast<int>(right() * x_scale)); |
| 94 } | 96 } |
| 95 | 97 |
| 98 // Adjusts the vertical and horizontal dimensions by the values described in |
| 99 // |vector|. Offsetting insets before applying to a rectangle would be |
| 100 // equivalent to offseting the rectangle then applying the insets. |
| 101 Insets Offset(const gfx::Vector2d& vector) const; |
| 102 |
| 96 operator InsetsF() const { | 103 operator InsetsF() const { |
| 97 return InsetsF(static_cast<float>(top()), static_cast<float>(left()), | 104 return InsetsF(static_cast<float>(top()), static_cast<float>(left()), |
| 98 static_cast<float>(bottom()), static_cast<float>(right())); | 105 static_cast<float>(bottom()), static_cast<float>(right())); |
| 99 } | 106 } |
| 100 | 107 |
| 101 // Returns a string representation of the insets. | 108 // Returns a string representation of the insets. |
| 102 std::string ToString() const; | 109 std::string ToString() const; |
| 103 | 110 |
| 104 private: | 111 private: |
| 105 int top_; | 112 int top_; |
| 106 int left_; | 113 int left_; |
| 107 int bottom_; | 114 int bottom_; |
| 108 int right_; | 115 int right_; |
| 109 }; | 116 }; |
| 110 | 117 |
| 111 inline Insets operator+(Insets lhs, const Insets& rhs) { | 118 inline Insets operator+(Insets lhs, const Insets& rhs) { |
| 112 lhs += rhs; | 119 lhs += rhs; |
| 113 return lhs; | 120 return lhs; |
| 114 } | 121 } |
| 115 | 122 |
| 116 inline Insets operator-(Insets lhs, const Insets& rhs) { | 123 inline Insets operator-(Insets lhs, const Insets& rhs) { |
| 117 lhs -= rhs; | 124 lhs -= rhs; |
| 118 return lhs; | 125 return lhs; |
| 119 } | 126 } |
| 120 | 127 |
| 121 } // namespace gfx | 128 } // namespace gfx |
| 122 | 129 |
| 123 #endif // UI_GFX_GEOMETRY_INSETS_H_ | 130 #endif // UI_GFX_GEOMETRY_INSETS_H_ |
| OLD | NEW |