dip_util.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2014 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. #ifndef UI_GFX_GEOMETRY_DIP_UTIL_H_
  5. #define UI_GFX_GEOMETRY_DIP_UTIL_H_
  6. #include "ui/gfx/geometry/geometry_export.h"
  7. namespace gfx {
  8. class Insets;
  9. class InsetsF;
  10. class Point;
  11. class PointF;
  12. class Rect;
  13. class RectF;
  14. class Size;
  15. class SizeF;
  16. // This file contains helper functions to move between DIPs (device-independent
  17. // pixels) and physical pixels, by multiplying or dividing by device scale
  18. // factor. These help show the intent of the caller by naming the operation,
  19. // instead of directly performing a scale operation. More complicated
  20. // transformations between coordinate spaces than DIP<->physical pixels should
  21. // be done via more explicit means.
  22. //
  23. // Note that functions that receive integer values will convert them to floating
  24. // point values, which can itself be a lossy operation for large integers. The
  25. // intention of these methods is to be used for UI values which are relatively
  26. // small.
  27. GEOMETRY_EXPORT gfx::PointF ConvertPointToDips(
  28. const gfx::Point& point_in_pixels,
  29. float device_scale_factor);
  30. GEOMETRY_EXPORT gfx::PointF ConvertPointToDips(
  31. const gfx::PointF& point_in_pixels,
  32. float device_scale_factor);
  33. GEOMETRY_EXPORT gfx::PointF ConvertPointToPixels(
  34. const gfx::Point& point_in_dips,
  35. float device_scale_factor);
  36. GEOMETRY_EXPORT gfx::PointF ConvertPointToPixels(
  37. const gfx::PointF& point_in_dips,
  38. float device_scale_factor);
  39. GEOMETRY_EXPORT gfx::SizeF ConvertSizeToDips(const gfx::Size& size_in_pixels,
  40. float device_scale_factor);
  41. GEOMETRY_EXPORT gfx::SizeF ConvertSizeToDips(const gfx::SizeF& size_in_pixels,
  42. float device_scale_factor);
  43. GEOMETRY_EXPORT gfx::SizeF ConvertSizeToPixels(const gfx::Size& size_in_dips,
  44. float device_scale_factor);
  45. GEOMETRY_EXPORT gfx::SizeF ConvertSizeToPixels(const gfx::SizeF& size_in_dips,
  46. float device_scale_factor);
  47. GEOMETRY_EXPORT gfx::RectF ConvertRectToDips(const gfx::Rect& rect_in_pixels,
  48. float device_scale_factor);
  49. GEOMETRY_EXPORT gfx::RectF ConvertRectToDips(const gfx::RectF& rect_in_pixels,
  50. float device_scale_factor);
  51. GEOMETRY_EXPORT gfx::RectF ConvertRectToPixels(const gfx::Rect& rect_in_dips,
  52. float device_scale_factor);
  53. GEOMETRY_EXPORT gfx::RectF ConvertRectToPixels(const gfx::RectF& rect_in_dips,
  54. float device_scale_factor);
  55. GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToDips(
  56. const gfx::Insets& insets_in_pixels,
  57. float device_scale_factor);
  58. GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToDips(
  59. const gfx::InsetsF& insets_in_pixels,
  60. float device_scale_factor);
  61. GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToPixels(
  62. const gfx::Insets& insets_in_dips,
  63. float device_scale_factor);
  64. GEOMETRY_EXPORT gfx::InsetsF ConvertInsetsToPixels(
  65. const gfx::InsetsF& insets_in_dips,
  66. float device_scale_factor);
  67. } // namespace gfx
  68. #endif // UI_GFX_GEOMETRY_DIP_UTIL_H_