OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "remoting/client/view_matrix.h" | 5 #include "remoting/client/view_matrix.h" |
6 | 6 |
7 namespace remoting { | 7 namespace remoting { |
8 | 8 |
9 ViewMatrix::ViewMatrix() : ViewMatrix(0.f, {0.f, 0.f}) {} | 9 ViewMatrix::ViewMatrix() : ViewMatrix(0.f, {0.f, 0.f}) {} |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 void ViewMatrix::SetScale(float scale) { | 28 void ViewMatrix::SetScale(float scale) { |
29 scale_ = scale; | 29 scale_ = scale; |
30 } | 30 } |
31 | 31 |
32 float ViewMatrix::GetScale() const { | 32 float ViewMatrix::GetScale() const { |
33 return scale_; | 33 return scale_; |
34 } | 34 } |
35 | 35 |
36 void ViewMatrix::PostScale(const Point& pivot, float scale) { | 36 void ViewMatrix::PostScale(const Point& pivot, float scale) { |
37 scale_ *= scale; | 37 scale_ *= scale; |
| 38 offset_.x *= scale; |
38 offset_.x += (1.f - scale) * pivot.x; | 39 offset_.x += (1.f - scale) * pivot.x; |
| 40 offset_.y *= scale; |
39 offset_.y += (1.f - scale) * pivot.y; | 41 offset_.y += (1.f - scale) * pivot.y; |
40 } | 42 } |
41 | 43 |
42 void ViewMatrix::PostTranslate(const Vector2D& delta) { | 44 void ViewMatrix::PostTranslate(const Vector2D& delta) { |
43 offset_.x += delta.x; | 45 offset_.x += delta.x; |
44 offset_.y += delta.y; | 46 offset_.y += delta.y; |
45 } | 47 } |
46 | 48 |
47 ViewMatrix ViewMatrix::Invert() const { | 49 ViewMatrix ViewMatrix::Invert() const { |
48 return ViewMatrix(1.f / scale_, {-offset_.x / scale_, -offset_.y / scale_}); | 50 return ViewMatrix(1.f / scale_, {-offset_.x / scale_, -offset_.y / scale_}); |
49 } | 51 } |
50 | 52 |
51 std::array<float, 9> ViewMatrix::ToMatrixArray() const { | 53 std::array<float, 9> ViewMatrix::ToMatrixArray() const { |
52 return {{scale_, 0, offset_.x, // Row 1 | 54 return {{scale_, 0, offset_.x, // Row 1 |
53 0, scale_, offset_.y, // Row 2 | 55 0, scale_, offset_.y, // Row 2 |
54 0, 0, 1}}; | 56 0, 0, 1}}; |
55 } | 57 } |
56 | 58 |
57 bool ViewMatrix::IsEmpty() const { | 59 bool ViewMatrix::IsEmpty() const { |
58 return scale_ == 0.f && offset_.x == 0.f && offset_.y == 0.f; | 60 return scale_ == 0.f && offset_.x == 0.f && offset_.y == 0.f; |
59 } | 61 } |
60 | 62 |
61 } // namespace remoting | 63 } // namespace remoting |
OLD | NEW |