Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/browser/android/vr_shell/ui_elements/ui_element.h

Issue 2856023003: Make UiElement a class (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 30 matching lines...) Expand all
41 CONTENT = 1, 41 CONTENT = 1,
42 // The element is filled with a radial gradient as specified by the edge and 42 // The element is filled with a radial gradient as specified by the edge and
43 // center color. 43 // center color.
44 OPAQUE_GRADIENT = 2, 44 OPAQUE_GRADIENT = 2,
45 // Same as OPAQUE_GRADIENT but the element is drawn as a grid. 45 // Same as OPAQUE_GRADIENT but the element is drawn as a grid.
46 GRID_GRADIENT = 3, 46 GRID_GRADIENT = 3,
47 // The element draws itself. 47 // The element draws itself.
48 SELF = 4, 48 SELF = 4,
49 }; 49 };
50 50
51 // TODO(vollick): use gfx::Transform crbug.com/718004
51 struct Transform { 52 struct Transform {
52 Transform(); 53 Transform();
54 explicit Transform(const Transform& other);
53 55
54 void MakeIdentity(); 56 void MakeIdentity();
55 void Rotate(const vr::Quatf& quat); 57 void Rotate(const vr::Quatf& quat);
56 void Rotate(const vr::RotationAxisAngle& axis_angle); 58 void Rotate(const vr::RotationAxisAngle& axis_angle);
57 void Translate(const gfx::Vector3dF& translation); 59 void Translate(const gfx::Vector3dF& translation);
58 void Scale(const gfx::Vector3dF& scale); 60 void Scale(const gfx::Vector3dF& scale);
59 61
60 vr::Mat4f to_world; 62 vr::Mat4f to_world;
61 }; 63 };
62 64
(...skipping 16 matching lines...) Expand all
79 // rectangle, returning 2D coordinates relative to the un-transformed unit 81 // rectangle, returning 2D coordinates relative to the un-transformed unit
80 // rectangle. This allows beam intersection points to be mapped to sprite 82 // rectangle. This allows beam intersection points to be mapped to sprite
81 // pixel coordinates. Points that fall onto the rectangle will generate X and 83 // pixel coordinates. Points that fall onto the rectangle will generate X and
82 // Y values on the interval [-0.5, 0.5]. 84 // Y values on the interval [-0.5, 0.5].
83 gfx::PointF GetUnitRectangleCoordinates(const gfx::Point3F& world_point); 85 gfx::PointF GetUnitRectangleCoordinates(const gfx::Point3F& world_point);
84 86
85 private: 87 private:
86 Transform transform_; 88 Transform transform_;
87 }; 89 };
88 90
89 // TODO(mthiesse): Make this a class - we derive classes from this struct. 91 class UiElement : public WorldRectangle {
90 struct UiElement : public WorldRectangle { 92 public:
91 UiElement(); 93 UiElement();
92 virtual ~UiElement(); 94 virtual ~UiElement();
93 95
94 void Animate(const base::TimeTicks& time); 96 void Animate(const base::TimeTicks& time);
95 97
96 // Indicates whether the element should be visually rendered. 98 // Indicates whether the element should be visually rendered.
97 bool IsVisible() const; 99 bool IsVisible() const;
98 100
99 // Indicates whether the element should be tested for cursor input. 101 // Indicates whether the element should be tested for cursor input.
100 bool IsHitTestable() const; 102 bool IsHitTestable() const;
101 103
102 virtual void Render(VrShellRenderer* renderer, 104 virtual void Render(VrShellRenderer* renderer,
103 vr::Mat4f view_proj_matrix) const; 105 vr::Mat4f view_proj_matrix) const;
104 106
105 virtual void Initialize(); 107 virtual void Initialize();
106 108
107 // Controller interaction methods. 109 // Controller interaction methods.
108 virtual void OnHoverEnter(); 110 virtual void OnHoverEnter();
109 virtual void OnHoverLeave(); 111 virtual void OnHoverLeave();
110 virtual void OnButtonDown(); 112 virtual void OnButtonDown();
111 virtual void OnButtonUp(); 113 virtual void OnButtonUp();
112 114
113 // Valid IDs are non-negative. 115 int id() const { return id_; }
114 int id = -1; 116 void set_id(int id) { id_ = id; }
115 117
116 // If a non-negative parent ID is specified, applicable transformations 118 // If a non-negative parent ID is specified, applicable transformations
117 // are applied relative to the parent, rather than absolutely. 119 // are applied relative to the parent, rather than absolutely.
118 int parent_id = -1; 120 int parent_id() const { return parent_id_; }
121 void set_parent_id(int id) { parent_id_ = id; }
119 122
120 // If true, this object will be visible. 123 // If true, this object will be visible.
121 bool visible = true; 124 bool visible() const { return visible_; }
125 void set_visible(bool visible) { visible_ = visible; }
122 126
123 // If false, the reticle will not hit the element, even if visible. 127 // If false, the reticle will not hit the element, even if visible.
124 bool hit_testable = true; 128 bool hit_testable() const { return hit_testable_; }
129 void set_hit_testable(bool hit_testable) { hit_testable_ = hit_testable; }
125 130
126 // If true, transformations will be applied relative to the field of view, 131 // If true, transformations will be applied relative to the field of view,
127 // rather than the world. 132 // rather than the world.
128 bool lock_to_fov = false; 133 bool lock_to_fov() const { return lock_to_fov_; }
134 void set_lock_to_fov(bool lock) { lock_to_fov_ = lock; }
135
136 // The computed lock to the FoV, incorporating lock of parent objects.
137 bool computed_lock_to_fov() const { return computed_lock_to_fov_; }
138 void set_computed_lock_to_fov(bool computed_lock) {
139 computed_lock_to_fov_ = computed_lock;
140 }
129 141
130 // The size of the object. This does not affect children. 142 // The size of the object. This does not affect children.
131 gfx::Vector3dF size = {1.0f, 1.0f, 1.0f}; 143 gfx::Vector3dF size() const { return size_; }
144 void set_size(const gfx::Vector3dF& size) { size_ = size; }
132 145
133 // The scale of the object, and its children. 146 // The scale of the object, and its children.
134 gfx::Vector3dF scale = {1.0f, 1.0f, 1.0f}; 147 gfx::Vector3dF scale() const { return scale_; }
148 void set_scale(const gfx::Vector3dF& scale) { scale_ = scale; }
135 149
136 // The rotation of the object, and its children. 150 // The rotation of the object, and its children.
137 vr::RotationAxisAngle rotation = {1.0f, 0.0f, 0.0f, 0.0f}; 151 vr::RotationAxisAngle rotation() const { return rotation_; }
152 void set_rotation(const vr::RotationAxisAngle& rotation) {
153 rotation_ = rotation;
154 }
138 155
139 // The translation of the object, and its children. Translation is applied 156 // The translation of the object, and its children. Translation is applied
140 // after rotation and scaling. 157 // after rotation and scaling.
141 gfx::Vector3dF translation = {0.0f, 0.0f, 0.0f}; 158 gfx::Vector3dF translation() const { return translation_; }
159 void set_translation(const gfx::Vector3dF& translation) {
160 translation_ = translation;
161 }
142 162
143 // The opacity of the object (between 0.0 and 1.0). 163 // The opacity of the object (between 0.0 and 1.0).
144 float opacity = 1.0f; 164 float opacity() const { return opacity_; }
165 void set_opacity(float opacity) { opacity_ = opacity; }
145 166
146 // The computed opacity, incorporating opacity of parent objects. 167 // The computed opacity, incorporating opacity of parent objects.
147 float computed_opacity; 168 float computed_opacity() const { return computed_opacity_; }
148 169 void set_computed_opacity(float computed_opacity) {
149 // The computed lock to the FoV, incorporating lock of parent objects. 170 computed_opacity_ = computed_opacity;
150 bool computed_lock_to_fov; 171 }
151 172
152 // If anchoring is specified, the translation will be relative to the 173 // If anchoring is specified, the translation will be relative to the
153 // specified edge(s) of the parent, rather than the center. A parent object 174 // specified edge(s) of the parent, rather than the center. A parent object
154 // must be specified when using anchoring. 175 // must be specified when using anchoring.
155 XAnchoring x_anchoring = XAnchoring::XNONE; 176 XAnchoring x_anchoring() const { return x_anchoring_; }
156 YAnchoring y_anchoring = YAnchoring::YNONE; 177 void set_x_anchoring(XAnchoring x_anchoring) { x_anchoring_ = x_anchoring; }
178
179 YAnchoring y_anchoring() const { return y_anchoring_; }
180 void set_y_anchoring(YAnchoring y_anchoring) { y_anchoring_ = y_anchoring; }
157 181
158 // Animations that affect the properties of the object over time. 182 // Animations that affect the properties of the object over time.
159 std::vector<std::unique_ptr<Animation>> animations; 183 std::vector<std::unique_ptr<Animation>>& animations() { return animations_; }
184 const std::vector<std::unique_ptr<Animation>>& animations() const {
185 return animations_;
186 }
160 187
161 Fill fill = Fill::NONE; 188 Fill fill() const { return fill_; }
189 void set_fill(Fill fill) { fill_ = fill; }
162 190
163 vr::Colorf edge_color = {1.0f, 1.0f, 1.0f, 1.0f}; 191 vr::Colorf edge_color() const { return edge_color_; }
164 vr::Colorf center_color = {1.0f, 1.0f, 1.0f, 1.0f}; 192 void set_edge_color(const vr::Colorf& edge_color) {
193 edge_color_ = edge_color;
194 }
165 195
166 int gridline_count = 1; 196 vr::Colorf center_color() const { return center_color_; }
197 void set_center_color(const vr::Colorf& center_color) {
198 center_color_ = center_color;
199 }
167 200
168 int draw_phase = 1; 201 int gridline_count() const { return gridline_count_; }
202 void set_gridline_count(int gridline_count) {
203 gridline_count_ = gridline_count;
204 }
205
206 int draw_phase() const { return draw_phase_; }
207 void set_draw_phase(int draw_phase) { draw_phase_ = draw_phase; }
169 208
170 // This transform can be used by children to derive position of its parent. 209 // This transform can be used by children to derive position of its parent.
171 Transform inheritable_transform; 210 Transform& inheritable_transform() { return inheritable_transform_; }
211 const Transform& inheritable_transform() const {
212 return inheritable_transform_;
213 }
214 void set_inheritable_transform(const Transform& transform) {
215 inheritable_transform_ = transform;
216 }
172 217
173 // A flag usable during transformation calculates to avoid duplicate work. 218 // A flag usable during transformation calculates to avoid duplicate work.
174 bool dirty; 219 bool dirty() const { return dirty_; }
220 void set_dirty(bool dirty) { dirty_ = dirty; }
175 221
176 private: 222 private:
223 // Valid IDs are non-negative.
224 int id_ = -1;
225
226 // If a non-negative parent ID is specified, applicable transformations
227 // are applied relative to the parent, rather than absolutely.
228 int parent_id_ = -1;
229
230 // If true, this object will be visible.
231 bool visible_ = true;
232
233 // If false, the reticle will not hit the element, even if visible.
234 bool hit_testable_ = true;
235
236 // If true, transformations will be applied relative to the field of view,
237 // rather than the world.
238 bool lock_to_fov_ = false;
239
240 // The computed lock to the FoV, incorporating lock of parent objects.
241 bool computed_lock_to_fov_;
242
243 // The size of the object. This does not affect children.
244 gfx::Vector3dF size_ = {1.0f, 1.0f, 1.0f};
245
246 // The scale of the object, and its children.
247 gfx::Vector3dF scale_ = {1.0f, 1.0f, 1.0f};
248
249 // The rotation of the object, and its children.
250 vr::RotationAxisAngle rotation_ = {1.0f, 0.0f, 0.0f, 0.0f};
251
252 // The translation of the object, and its children. Translation is applied
253 // after rotation and scaling.
254 gfx::Vector3dF translation_ = {0.0f, 0.0f, 0.0f};
255
256 // The opacity of the object (between 0.0 and 1.0).
257 float opacity_ = 1.0f;
258
259 // The computed opacity, incorporating opacity of parent objects.
260 float computed_opacity_;
261
262 // If anchoring is specified, the translation will be relative to the
263 // specified edge(s) of the parent, rather than the center. A parent object
264 // must be specified when using anchoring.
265 XAnchoring x_anchoring_ = XAnchoring::XNONE;
266 YAnchoring y_anchoring_ = YAnchoring::YNONE;
267
268 // Animations that affect the properties of the object over time.
269 std::vector<std::unique_ptr<Animation>> animations_;
270
271 Fill fill_ = Fill::NONE;
272
273 vr::Colorf edge_color_ = {1.0f, 1.0f, 1.0f, 1.0f};
274 vr::Colorf center_color_ = {1.0f, 1.0f, 1.0f, 1.0f};
275
276 int gridline_count_ = 1;
277
278 int draw_phase_ = 1;
279
280 // This transform can be used by children to derive position of its parent.
281 Transform inheritable_transform_;
282
283 // A flag usable during transformation calculates to avoid duplicate work.
284 bool dirty_;
285
286 Transform transform_;
287
177 DISALLOW_COPY_AND_ASSIGN(UiElement); 288 DISALLOW_COPY_AND_ASSIGN(UiElement);
178 }; 289 };
179 290
180 } // namespace vr_shell 291 } // namespace vr_shell
181 292
182 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ 293 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698