blob: 89008f66940064d4a39f9efba69f10d3ab475a6f [file] [log] [blame]
Dominik Laskowski718f9602019-11-09 20:01:35 -08001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <type_traits>
20
21namespace android::ui {
22
23enum class Rotation { Rotation0 = 0, Rotation90 = 1, Rotation180 = 2, Rotation270 = 3 };
24
25// Equivalent to Surface.java constants.
26constexpr auto ROTATION_0 = Rotation::Rotation0;
27constexpr auto ROTATION_90 = Rotation::Rotation90;
28constexpr auto ROTATION_180 = Rotation::Rotation180;
29constexpr auto ROTATION_270 = Rotation::Rotation270;
30
31constexpr auto toRotation(std::underlying_type_t<Rotation> rotation) {
32 return static_cast<Rotation>(rotation);
33}
34
35constexpr auto toRotationInt(Rotation rotation) {
36 return static_cast<std::underlying_type_t<Rotation>>(rotation);
37}
38
39constexpr Rotation operator+(Rotation lhs, Rotation rhs) {
40 constexpr auto N = toRotationInt(ROTATION_270) + 1;
41 return toRotation((toRotationInt(lhs) + toRotationInt(rhs)) % N);
42}
43
44constexpr const char* toCString(Rotation rotation) {
45 switch (rotation) {
46 case ROTATION_0:
47 return "ROTATION_0";
48 case ROTATION_90:
49 return "ROTATION_90";
50 case ROTATION_180:
51 return "ROTATION_180";
52 case ROTATION_270:
53 return "ROTATION_270";
54 }
55}
56
57} // namespace android::ui