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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_DISPLAY_WIN_SCALING_UTIL_H_
#define UI_DISPLAY_WIN_SCALING_UTIL_H_
#include <stdint.h>
#include "ui/display/display_export.h"
#include "ui/display/display_layout.h"
#include "ui/display/win/display_info.h"
namespace gfx {
class Rect;
}
namespace display {
namespace win {
// Whether or not |a| shares an edge with |b|.
DISPLAY_EXPORT bool DisplayInfosTouch(const internal::DisplayInfo& a,
const internal::DisplayInfo& b);
// Returns a DisplayPlacement for |current| relative to |parent|.
// Note that DisplayPlacement's are always in DIPs, so this also performs the
// required scaling.
//
// Examples (The offset is indicated by the arrow.):
// Scaled and Unscaled Coordinates
// +--------------+ + Since both DisplayInfos are of the same scale
// | | | factor, relative positions remain the same.
// | Parent | V
// | 1x +----------+
// | | |
// +--------------+ Current |
// | 1x |
// +----------+
//
// Unscaled Coordinates
// +--------------+ The 2x DisplayInfo is offset to maintain a
// | | similar neighboring relationship with the 1x
// | Parent | parent. Current's position is based off of the
// | 1x +----------+ percentage position along its parent. This
// | | | percentage position is preserved in the scaled
// +--------------+ Current | coordinates.
// | 2x |
// +----------+
// Scaled Coordinates
// +--------------+ +
// | | |
// | Parent | V
// | 1x +-----+
// | + C 2x|
// +--------------+-----+
//
//
// Unscaled Coordinates
// +--------------+ The parent DisplayInfo has a 2x scale factor.
// | | The offset is adjusted to maintain the
// | | relative positioning of the 1x DisplayInfo in
// | Parent +----------+ the scaled coordinate space. Current's
// | 2x | | position is based off of the percentage
// | | Current | position along its parent. This percentage
// | | 1x | position is preserved in the scaled
// +--------------+ | coordinates.
// | |
// +----------+
// Scaled Coordinates
// +-------+ +
// | | V
// | Parent+----------+
// | 2x | |
// +-------+ Current |
// | 1x |
// | |
// | |
// +----------+
//
// Unscaled Coordinates
// +----------+ In this case, parent lies between the top and
// | | bottom of parent. The roles are reversed when
// +-------+ | this occurs, and current is placed to maintain
// | | Current | parent's relative position along current.
// | Parent| 1x |
// | 2x | |
// +-------+ |
// +----------+
// Scaled Coordinates
// ^ +----------+
// | | |
// + +----+ |
// |Prnt| Current |
// | 2x | 1x |
// +----+ |
// | |
// +----------+
//
// Scaled and Unscaled Coordinates
// +--------+ If the two DisplayInfos are bottom aligned or
// | | right aligned, the DisplayPlacement will
// | +--------+ have an offset of 0 relative to the
// | | | bottom-right of the DisplayInfo.
// | | |
// +--------+--------+
DISPLAY_EXPORT DisplayPlacement
CalculateDisplayPlacement(const internal::DisplayInfo& parent,
const internal::DisplayInfo& current);
// Returns the squared distance between two rects.
// The distance between two rects is the length of the shortest segment that can
// be drawn between two rectangles. This segment generally connects two opposing
// corners between rectangles like this...
//
// +----------+
// | |
// +----------+
// \ <--- Shortest Segment
// \
// +---+
// | |
// | |
// +---+
//
// For rectangles that share coordinates within the same axis, that generally
// means the segment is parallel to the axis and perpendicular to the edges.
//
// One of many shortest segments
// +----------+ / \ +--------+
// | | | \ | |
// | | V +---+ \ +--------+
// | |-----| | \-->|
// +----------+ | | +----+
// | | | |
// +---+ +----+
//
// For rectangles that intersect each other, the distance is the negative value
// of the overlapping area, so callers can distinguish different amounts of
// overlap.
//
// The squared distance is used to avoid taking the square root as the common
// usage is to compare distances greater than 1 unit.
DISPLAY_EXPORT int64_t SquaredDistanceBetweenRects(const gfx::Rect& ref,
const gfx::Rect& rect);
} // namespace win
} // namespace display
#endif // UI_DISPLAY_WIN_SCALING_UTIL_H_
|