summaryrefslogtreecommitdiffstats
path: root/ui/gfx/size.h
blob: 4425207a18fa4b25b3a8bb433a4bd7b9da9940a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_SIZE_H_
#define UI_GFX_SIZE_H_

#include <string>

#include "build/build_config.h"
#include "ui/base/ui_export.h"
#include "ui/gfx/size_base.h"
#include "ui/gfx/size_f.h"

#if defined(OS_WIN)
typedef struct tagSIZE SIZE;
#elif defined(OS_IOS)
#include <CoreGraphics/CoreGraphics.h>
#elif defined(OS_MACOSX)
#include <ApplicationServices/ApplicationServices.h>
#endif

namespace gfx {

// A size has width and height values.
class UI_EXPORT Size : public SizeBase<Size, int> {
 public:
  Size();
  Size(int width, int height);
#if defined(OS_MACOSX)
  explicit Size(const CGSize& s);
#endif

  ~Size();

#if defined(OS_MACOSX)
  Size& operator=(const CGSize& s);
#endif

#if defined(OS_WIN)
  SIZE ToSIZE() const;
#elif defined(OS_MACOSX)
  CGSize ToCGSize() const;
#endif

  operator SizeF() const {
    return SizeF(width(), height());
  }

  SizeF Scale(float scale) const WARN_UNUSED_RESULT {
    return Scale(scale, scale);
  }

  SizeF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT {
    return SizeF(width() * x_scale, height() * y_scale);
  }

  std::string ToString() const;
};

inline bool operator==(const Size& lhs, const Size& rhs) {
  return lhs.width() == rhs.width() && lhs.height() == rhs.height();
}

inline bool operator!=(const Size& lhs, const Size& rhs) {
  return !(lhs == rhs);
}

#if !defined(COMPILER_MSVC)
extern template class SizeBase<Size, int>;
#endif

}  // namespace gfx

#endif  // UI_GFX_SIZE_H_