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

Side by Side Diff: ppapi/examples/mouse_lock/mouse_lock.cc

Issue 9651002: Add C++ wrappers for output parameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: With swapping Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <cmath> 5 #include <cmath>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "ppapi/c/dev/ppb_console_dev.h" 9 #include "ppapi/c/dev/ppb_console_dev.h"
10 #include "ppapi/c/ppb_input_event.h" 10 #include "ppapi/c/ppb_input_event.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 PP_INPUTEVENT_CLASS_KEYBOARD); 44 PP_INPUTEVENT_CLASS_KEYBOARD);
45 return true; 45 return true;
46 } 46 }
47 47
48 virtual bool HandleInputEvent(const pp::InputEvent& event) { 48 virtual bool HandleInputEvent(const pp::InputEvent& event) {
49 switch (event.GetType()) { 49 switch (event.GetType()) {
50 case PP_INPUTEVENT_TYPE_MOUSEDOWN: { 50 case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
51 pp::MouseInputEvent mouse_event(event); 51 pp::MouseInputEvent mouse_event(event);
52 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT && 52 if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
53 !mouse_locked_) { 53 !mouse_locked_) {
54 LockMouse( 54 LockMouse(callback_factory_.NewCallback(&MyInstance::DidLockMouse));
55 callback_factory_.NewRequiredCallback(&MyInstance::DidLockMouse));
56 } 55 }
57 return true; 56 return true;
58 } 57 }
59 case PP_INPUTEVENT_TYPE_MOUSEMOVE: { 58 case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
60 pp::MouseInputEvent mouse_event(event); 59 pp::MouseInputEvent mouse_event(event);
61 mouse_movement_ = mouse_event.GetMovement(); 60 mouse_movement_ = mouse_event.GetMovement();
62 static unsigned int i = 0; 61 static unsigned int i = 0;
63 Log(PP_LOGLEVEL_LOG, "[%d] movementX: %d; movementY: %d\n", i++, 62 Log(PP_LOGLEVEL_LOG, "[%d] movementX: %d; movementY: %d\n", i++,
64 mouse_movement_.x(), mouse_movement_.y()); 63 mouse_movement_.x(), mouse_movement_.y());
65 Paint(); 64 Paint();
66 return true; 65 return true;
67 } 66 }
68 case PP_INPUTEVENT_TYPE_KEYDOWN: { 67 case PP_INPUTEVENT_TYPE_KEYDOWN: {
69 pp::KeyboardInputEvent key_event(event); 68 pp::KeyboardInputEvent key_event(event);
70 // Lock the mouse when the Enter key is pressed. 69 // Lock the mouse when the Enter key is pressed.
71 if (key_event.GetKeyCode() == 13) { 70 if (key_event.GetKeyCode() == 13) {
72 if (mouse_locked_) { 71 if (mouse_locked_)
73 UnlockMouse(); 72 UnlockMouse();
74 } else { 73 else
75 LockMouse(callback_factory_.NewRequiredCallback( 74 LockMouse(callback_factory_.NewCallback(&MyInstance::DidLockMouse));
76 &MyInstance::DidLockMouse));
77 }
78 return true; 75 return true;
79 } 76 }
80 return false; 77 return false;
81 } 78 }
82 default: 79 default:
83 return false; 80 return false;
84 } 81 }
85 } 82 }
86 83
87 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { 84 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (waiting_for_flush_completion_) { 125 if (waiting_for_flush_completion_) {
129 pending_paint_ = true; 126 pending_paint_ = true;
130 return; 127 return;
131 } 128 }
132 129
133 pp::ImageData image = PaintImage(width_, height_); 130 pp::ImageData image = PaintImage(width_, height_);
134 if (!image.is_null()) { 131 if (!image.is_null()) {
135 device_context_.ReplaceContents(&image); 132 device_context_.ReplaceContents(&image);
136 waiting_for_flush_completion_ = true; 133 waiting_for_flush_completion_ = true;
137 device_context_.Flush( 134 device_context_.Flush(
138 callback_factory_.NewRequiredCallback(&MyInstance::DidFlush)); 135 callback_factory_.NewCallback(&MyInstance::DidFlush));
139 } 136 }
140 } 137 }
141 138
142 pp::ImageData PaintImage(int width, int height) { 139 pp::ImageData PaintImage(int width, int height) {
143 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, 140 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
144 pp::Size(width, height), false); 141 pp::Size(width, height), false);
145 if (image.is_null()) 142 if (image.is_null())
146 return image; 143 return image;
147 144
148 const static int kCenteralSpotRadius = 5; 145 const static int kCenteralSpotRadius = 5;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 262
266 namespace pp { 263 namespace pp {
267 264
268 // Factory function for your specialization of the Module object. 265 // Factory function for your specialization of the Module object.
269 Module* CreateModule() { 266 Module* CreateModule() {
270 return new MyModule(); 267 return new MyModule();
271 } 268 }
272 269
273 } // namespace pp 270 } // namespace pp
274 271
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698