| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 | |
| 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ | |
| 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "device/vr/vr_types.h" | |
| 14 | |
| 15 namespace base { | |
| 16 class TimeTicks; | |
| 17 } | |
| 18 | |
| 19 namespace vr_shell { | |
| 20 | |
| 21 class Animation; | |
| 22 | |
| 23 enum XAnchoring { | |
| 24 XNONE = 0, | |
| 25 XLEFT, | |
| 26 XRIGHT, | |
| 27 }; | |
| 28 | |
| 29 enum YAnchoring { | |
| 30 YNONE = 0, | |
| 31 YTOP, | |
| 32 YBOTTOM, | |
| 33 }; | |
| 34 | |
| 35 enum Fill { | |
| 36 NONE = 0, | |
| 37 // The element is filled with part of the HTML UI as specified by the copy | |
| 38 // rect. | |
| 39 SPRITE = 1, | |
| 40 // The element is filled with a radial gradient as specified by the edge and | |
| 41 // center color. | |
| 42 OPAQUE_GRADIENT = 2, | |
| 43 // Same as OPAQUE_GRADIENT but the element is drawn as a grid. | |
| 44 GRID_GRADIENT = 3, | |
| 45 // The element is filled with the content web site. Only one content element | |
| 46 // may be added to the | |
| 47 // scene. | |
| 48 CONTENT = 4, | |
| 49 }; | |
| 50 | |
| 51 struct Transform { | |
| 52 Transform(); | |
| 53 | |
| 54 void MakeIdentity(); | |
| 55 void Rotate(const vr::Quatf& quat); | |
| 56 void Rotate(const vr::RotationAxisAngle& axis_angle); | |
| 57 void Translate(const gfx::Vector3dF& translation); | |
| 58 void Scale(const gfx::Vector3dF& scale); | |
| 59 | |
| 60 vr::Mat4f to_world; | |
| 61 }; | |
| 62 | |
| 63 class WorldRectangle { | |
| 64 public: | |
| 65 const vr::Mat4f& TransformMatrix() const; | |
| 66 Transform* mutable_transform() { return &transform_; } | |
| 67 | |
| 68 gfx::Point3F GetCenter() const; | |
| 69 gfx::Vector3dF GetNormal() const; | |
| 70 | |
| 71 // Computes the distance from |ray_origin| to this rectangles's plane, along | |
| 72 // |ray_vector|. Returns true and populates |distance| if the calculation is | |
| 73 // possible, and false if the ray is parallel to the plane. | |
| 74 bool GetRayDistance(const gfx::Point3F& ray_origin, | |
| 75 const gfx::Vector3dF& ray_vector, | |
| 76 float* distance) const; | |
| 77 | |
| 78 // Projects a 3D world point onto the X and Y axes of the transformed | |
| 79 // rectangle, returning 2D coordinates relative to the un-transformed unit | |
| 80 // rectangle. This allows beam intersection points to be mapped to sprite | |
| 81 // pixel coordinates. Points that fall onto the rectangle will generate X and | |
| 82 // Y values on the interval [-0.5, 0.5]. | |
| 83 gfx::PointF GetUnitRectangleCoordinates(const gfx::Point3F& world_point); | |
| 84 | |
| 85 private: | |
| 86 Transform transform_; | |
| 87 }; | |
| 88 | |
| 89 struct ContentRectangle : public WorldRectangle { | |
| 90 ContentRectangle(); | |
| 91 ~ContentRectangle(); | |
| 92 | |
| 93 void Animate(const base::TimeTicks& time); | |
| 94 | |
| 95 // Indicates whether the element should be visually rendered. | |
| 96 bool IsVisible() const; | |
| 97 | |
| 98 // Indicates whether the element should be tested for cursor input. | |
| 99 bool IsHitTestable() const; | |
| 100 | |
| 101 // Valid IDs are non-negative. | |
| 102 int id = -1; | |
| 103 | |
| 104 // Name string for debugging and testing purposes. | |
| 105 std::string name; | |
| 106 | |
| 107 // If a non-negative parent ID is specified, applicable transformations | |
| 108 // are applied relative to the parent, rather than absolutely. | |
| 109 int parent_id = -1; | |
| 110 | |
| 111 // If true, this object will be visible. | |
| 112 bool visible = true; | |
| 113 | |
| 114 // If false, the reticle will not hit the element, even if visible. | |
| 115 bool hit_testable = true; | |
| 116 | |
| 117 // If true, transformations will be applied relative to the field of view, | |
| 118 // rather than the world. | |
| 119 bool lock_to_fov = false; | |
| 120 | |
| 121 // Specifies the region (in pixels) of a texture to render. | |
| 122 gfx::Rect copy_rect = {0, 0, 0, 0}; | |
| 123 | |
| 124 // The size of the object. This does not affect children. | |
| 125 gfx::Vector3dF size = {1.0f, 1.0f, 1.0f}; | |
| 126 | |
| 127 // The scale of the object, and its children. | |
| 128 gfx::Vector3dF scale = {1.0f, 1.0f, 1.0f}; | |
| 129 | |
| 130 // The rotation of the object, and its children. | |
| 131 vr::RotationAxisAngle rotation = {1.0f, 0.0f, 0.0f, 0.0f}; | |
| 132 | |
| 133 // The translation of the object, and its children. Translation is applied | |
| 134 // after rotation and scaling. | |
| 135 gfx::Vector3dF translation = {0.0f, 0.0f, 0.0f}; | |
| 136 | |
| 137 // The opacity of the object (between 0.0 and 1.0). | |
| 138 float opacity = 1.0f; | |
| 139 | |
| 140 // The computed opacity, incorporating opacity of parent objects. | |
| 141 float computed_opacity; | |
| 142 | |
| 143 // The computed lock to the FoV, incorporating lock of parent objects. | |
| 144 bool computed_lock_to_fov; | |
| 145 | |
| 146 // If anchoring is specified, the translation will be relative to the | |
| 147 // specified edge(s) of the parent, rather than the center. A parent object | |
| 148 // must be specified when using anchoring. | |
| 149 XAnchoring x_anchoring = XAnchoring::XNONE; | |
| 150 YAnchoring y_anchoring = YAnchoring::YNONE; | |
| 151 | |
| 152 // Animations that affect the properties of the object over time. | |
| 153 std::vector<std::unique_ptr<Animation>> animations; | |
| 154 | |
| 155 Fill fill = Fill::NONE; | |
| 156 | |
| 157 vr::Colorf edge_color = {1.0f, 1.0f, 1.0f, 1.0f}; | |
| 158 vr::Colorf center_color = {1.0f, 1.0f, 1.0f, 1.0f}; | |
| 159 | |
| 160 int gridline_count = 1; | |
| 161 | |
| 162 int draw_phase = 1; | |
| 163 | |
| 164 // This transform can be used by children to derive position of its parent. | |
| 165 Transform inheritable_transform; | |
| 166 | |
| 167 // A flag usable during transformation calculates to avoid duplicate work. | |
| 168 bool dirty; | |
| 169 | |
| 170 private: | |
| 171 DISALLOW_COPY_AND_ASSIGN(ContentRectangle); | |
| 172 }; | |
| 173 | |
| 174 } // namespace vr_shell | |
| 175 | |
| 176 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ | |
| OLD | NEW |