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

Side by Side Diff: mojo/examples/sample_app/gles2_client_impl.cc

Issue 413633003: Mojo: Introduces mojo::EventType and mojo::EventFlags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Landing Created 6 years, 4 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
« no previous file with comments | « mojo/examples/sample_app/DEPS ('k') | mojo/examples/window_manager/window_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/examples/sample_app/gles2_client_impl.h" 5 #include "mojo/examples/sample_app/gles2_client_impl.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 #include <math.h> 9 #include <math.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
11 11
12 #include "mojo/public/c/gles2/gles2.h" 12 #include "mojo/public/c/gles2/gles2.h"
13 #include "ui/events/event_constants.h"
14 13
15 namespace examples { 14 namespace examples {
16 namespace { 15 namespace {
17 16
18 float CalculateDragDistance(const mojo::Point& start, const mojo::Point& end) { 17 float CalculateDragDistance(const mojo::Point& start, const mojo::Point& end) {
19 return hypot(static_cast<float>(start.x - end.x), 18 return hypot(static_cast<float>(start.x - end.x),
20 static_cast<float>(start.y - end.y)); 19 static_cast<float>(start.y - end.y));
21 } 20 }
22 21
23 float GetRandomColor() { 22 float GetRandomColor() {
(...skipping 19 matching lines...) Expand all
43 void GLES2ClientImpl::SetSize(const mojo::Size& size) { 42 void GLES2ClientImpl::SetSize(const mojo::Size& size) {
44 size_ = size; 43 size_ = size;
45 if (size_.width == 0 || size_.height == 0) 44 if (size_.width == 0 || size_.height == 0)
46 return; 45 return;
47 cube_.Init(size_.width, size_.height); 46 cube_.Init(size_.width, size_.height);
48 RequestAnimationFrames(); 47 RequestAnimationFrames();
49 } 48 }
50 49
51 void GLES2ClientImpl::HandleInputEvent(const mojo::Event& event) { 50 void GLES2ClientImpl::HandleInputEvent(const mojo::Event& event) {
52 switch (event.action) { 51 switch (event.action) {
53 case ui::ET_MOUSE_PRESSED: 52 case mojo::EVENT_TYPE_MOUSE_PRESSED:
54 case ui::ET_TOUCH_PRESSED: 53 case mojo::EVENT_TYPE_TOUCH_PRESSED:
55 if (event.flags & ui::EF_RIGHT_MOUSE_BUTTON) 54 if (event.flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON)
56 break; 55 break;
57 CancelAnimationFrames(); 56 CancelAnimationFrames();
58 capture_point_ = *event.location; 57 capture_point_ = *event.location;
59 last_drag_point_ = capture_point_; 58 last_drag_point_ = capture_point_;
60 drag_start_time_ = mojo::GetTimeTicksNow(); 59 drag_start_time_ = mojo::GetTimeTicksNow();
61 break; 60 break;
62 case ui::ET_MOUSE_DRAGGED: 61 case mojo::EVENT_TYPE_MOUSE_DRAGGED:
63 case ui::ET_TOUCH_MOVED: 62 case mojo::EVENT_TYPE_TOUCH_MOVED:
64 if (event.flags & ui::EF_RIGHT_MOUSE_BUTTON) 63 if (event.flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON)
65 break; 64 break;
66 if (!getting_animation_frames_) { 65 if (!getting_animation_frames_) {
67 int direction = event.location->y < last_drag_point_.y || 66 int direction = event.location->y < last_drag_point_.y ||
68 event.location->x > last_drag_point_.x ? 1 : -1; 67 event.location->x > last_drag_point_.x ? 1 : -1;
69 cube_.set_direction(direction); 68 cube_.set_direction(direction);
70 cube_.UpdateForDragDistance( 69 cube_.UpdateForDragDistance(
71 CalculateDragDistance(last_drag_point_, *event.location)); 70 CalculateDragDistance(last_drag_point_, *event.location));
72 cube_.Draw(); 71 cube_.Draw();
73 MojoGLES2SwapBuffers(); 72 MojoGLES2SwapBuffers();
74 73
75 last_drag_point_ = *event.location; 74 last_drag_point_ = *event.location;
76 } 75 }
77 break; 76 break;
78 case ui::ET_MOUSE_RELEASED: 77 case mojo::EVENT_TYPE_MOUSE_RELEASED:
79 case ui::ET_TOUCH_RELEASED: { 78 case mojo::EVENT_TYPE_TOUCH_RELEASED: {
80 if (event.flags & ui::EF_RIGHT_MOUSE_BUTTON) { 79 if (event.flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON) {
81 cube_.set_color(GetRandomColor(), GetRandomColor(), GetRandomColor()); 80 cube_.set_color(GetRandomColor(), GetRandomColor(), GetRandomColor());
82 break; 81 break;
83 } 82 }
84 MojoTimeTicks offset = mojo::GetTimeTicksNow() - drag_start_time_; 83 MojoTimeTicks offset = mojo::GetTimeTicksNow() - drag_start_time_;
85 float delta = static_cast<float>(offset) / 1000000.; 84 float delta = static_cast<float>(offset) / 1000000.;
86 cube_.SetFlingMultiplier( 85 cube_.SetFlingMultiplier(
87 CalculateDragDistance(capture_point_, *event.location), 86 CalculateDragDistance(capture_point_, *event.location),
88 delta); 87 delta);
89 88
90 capture_point_ = last_drag_point_ = mojo::Point(); 89 capture_point_ = last_drag_point_ = mojo::Point();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 MojoGLES2RequestAnimationFrames(context_); 123 MojoGLES2RequestAnimationFrames(context_);
125 last_time_ = mojo::GetTimeTicksNow(); 124 last_time_ = mojo::GetTimeTicksNow();
126 } 125 }
127 126
128 void GLES2ClientImpl::CancelAnimationFrames() { 127 void GLES2ClientImpl::CancelAnimationFrames() {
129 getting_animation_frames_ = false; 128 getting_animation_frames_ = false;
130 MojoGLES2CancelAnimationFrames(context_); 129 MojoGLES2CancelAnimationFrames(context_);
131 } 130 }
132 131
133 } // namespace examples 132 } // namespace examples
OLDNEW
« no previous file with comments | « mojo/examples/sample_app/DEPS ('k') | mojo/examples/window_manager/window_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698