Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
size.cc
Go to the documentation of this file.
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
3// found in the LICENSE file.
4
5#include "size.h"
6
7#if defined(OS_WIN)
8#include <windows.h>
9#elif defined(OS_IOS)
10#include <CoreGraphics/CoreGraphics.h>
11#elif defined(OS_APPLE)
12#include <ApplicationServices/ApplicationServices.h>
13#endif
14
18#include "base/string_utils.h"
19#include "size_conversions.h"
20
21namespace gfx {
22
23#if defined(OS_APPLE)
24Size::Size(const CGSize& s)
25 : width_(s.width < 0 ? 0 : s.width), height_(s.height < 0 ? 0 : s.height) {}
26
27Size& Size::operator=(const CGSize& s) {
28 set_width(s.width);
29 set_height(s.height);
30 return *this;
31}
32#endif
33
34void Size::operator+=(const Size& size) {
35 Enlarge(size.width(), size.height());
36}
37
38void Size::operator-=(const Size& size) {
39 Enlarge(-size.width(), -size.height());
40}
41
42#if defined(OS_WIN)
43SIZE Size::ToSIZE() const {
44 SIZE s;
45 s.cx = width();
46 s.cy = height();
47 return s;
48}
49#elif defined(OS_APPLE)
50CGSize Size::ToCGSize() const {
51 return CGSizeMake(width(), height());
52}
53#endif
54
55int Size::GetArea() const {
56 return GetCheckedArea().ValueOrDie();
57}
58
59base::CheckedNumeric<int> Size::GetCheckedArea() const {
60 base::CheckedNumeric<int> checked_area = width();
61 checked_area *= height();
62 return checked_area;
63}
64
65void Size::Enlarge(int grow_width, int grow_height) {
66 SetSize(base::ClampAdd(width(), grow_width),
67 base::ClampAdd(height(), grow_height));
68}
69
70void Size::SetToMin(const Size& other) {
71 width_ = width() <= other.width() ? width() : other.width();
72 height_ = height() <= other.height() ? height() : other.height();
73}
74
75void Size::SetToMax(const Size& other) {
76 width_ = width() >= other.width() ? width() : other.width();
77 height_ = height() >= other.height() ? height() : other.height();
78}
79
80std::string Size::ToString() const {
81 return base::StringPrintf("%dx%d", width(), height());
82}
83
84Size ScaleToCeiledSize(const Size& size, float x_scale, float y_scale) {
85 if (x_scale == 1.f && y_scale == 1.f)
86 return size;
87 return ToCeiledSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
88}
89
90Size ScaleToCeiledSize(const Size& size, float scale) {
91 if (scale == 1.f)
92 return size;
94}
95
96Size ScaleToFlooredSize(const Size& size, float x_scale, float y_scale) {
97 if (x_scale == 1.f && y_scale == 1.f)
98 return size;
99 return ToFlooredSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
100}
101
102Size ScaleToFlooredSize(const Size& size, float scale) {
103 if (scale == 1.f)
104 return size;
106}
107
108Size ScaleToRoundedSize(const Size& size, float x_scale, float y_scale) {
109 if (x_scale == 1.f && y_scale == 1.f)
110 return size;
111 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
112}
113
114Size ScaleToRoundedSize(const Size& size, float scale) {
115 if (scale == 1.f)
116 return size;
118}
119
120} // namespace gfx
constexpr Size()
Definition size.h:28
constexpr int height() const
Definition size.h:50
constexpr int width() const
Definition size.h:49
struct MyStruct s
std::string StringPrintf(const std::string &format, Args... args)
Definition insets.cc:10
Size ToFlooredSize(const SizeF &size)
SizeF ScaleSize(const SizeF &s, float x_scale, float y_scale)
Definition size_f.cc:33
Size ToCeiledSize(const SizeF &size)
Size ScaleToCeiledSize(const Size &size, float x_scale, float y_scale)
Definition size.cc:84
Size ScaleToFlooredSize(const Size &size, float x_scale, float y_scale)
Definition size.cc:96
Size ToRoundedSize(const SizeF &size)
Size ScaleToRoundedSize(const Size &size, float x_scale, float y_scale)
Definition size.cc:108
TSize< Scalar > Size
Definition size.h:137
#define SIZE
int32_t height
int32_t width
const Scalar scale