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

Side by Side Diff: native_client_sdk/src/examples/api/mouse_lock/mouse_lock.cc

Issue 14607005: [NaCl SDK] Cleanup examples. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 7 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 | 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>
6 #include <cstdlib>
7 #include <stdarg.h> 5 #include <stdarg.h>
8 #include <stdio.h> 6 #include <stdio.h>
9 #include <string.h> 7 #include <string.h>
8 #include <cmath>
9 #include <cstdlib>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "mouselock.h" 13 #include "mouse_lock.h"
14 14
15 #ifdef WIN32 15 #ifdef WIN32
16 #undef min 16 #undef min
17 #undef max 17 #undef max
18 #undef PostMessage 18 #undef PostMessage
19 #endif 19 #endif
20 20
21 // Indicate the direction of the mouse location relative to the center of the 21 // Indicate the direction of the mouse location relative to the center of the
22 // view. These values are used to determine which 2D quadrant the needle lies 22 // view. These values are used to determine which 2D quadrant the needle lies
23 // in. 23 // in.
24 typedef enum { 24 typedef enum {
25 kLeft = 0, 25 kLeft = 0,
26 kRight = 1, 26 kRight = 1,
27 kUp = 2, 27 kUp = 2,
28 kDown = 3 28 kDown = 3
29 } MouseDirection; 29 } MouseDirection;
30 30
31 namespace { 31 namespace {
32 const int kCentralSpotRadius = 5; 32 const int kCentralSpotRadius = 5;
33 const uint32_t kReturnKeyCode = 13; 33 const uint32_t kReturnKeyCode = 13;
34 const uint32_t kBackgroundColor = 0xff606060; 34 const uint32_t kBackgroundColor = 0xff606060;
35 const uint32_t kForegroundColor = 0xfff08080; 35 const uint32_t kForegroundColor = 0xfff08080;
36 } // namespace 36 } // namespace
37 37
38 namespace mouselock {
39
40 MouseLockInstance::~MouseLockInstance() { 38 MouseLockInstance::~MouseLockInstance() {
41 free(background_scanline_); 39 free(background_scanline_);
42 background_scanline_ = NULL; 40 background_scanline_ = NULL;
43 } 41 }
44 42
45 bool MouseLockInstance::Init(uint32_t argc, 43 bool MouseLockInstance::Init(uint32_t argc,
46 const char* argn[], 44 const char* argn[],
47 const char* argv[]) { 45 const char* argv[]) {
48 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_KEYBOARD); 46 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_KEYBOARD);
49 return true; 47 return true;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 va_start(args, format); 336 va_start(args, format);
339 char buf[512]; 337 char buf[512];
340 vsnprintf(buf, sizeof(buf) - 1, format, args); 338 vsnprintf(buf, sizeof(buf) - 1, format, args);
341 buf[sizeof(buf) - 1] = '\0'; 339 buf[sizeof(buf) - 1] = '\0';
342 va_end(args); 340 va_end(args);
343 341
344 pp::Var value(buf); 342 pp::Var value(buf);
345 console->Log(pp_instance(), PP_LOGLEVEL_ERROR, value.pp_var()); 343 console->Log(pp_instance(), PP_LOGLEVEL_ERROR, value.pp_var());
346 } 344 }
347 345
348 } // namespace mouselock
349
350 // This object is the global object representing this plugin library as long 346 // This object is the global object representing this plugin library as long
351 // as it is loaded. 347 // as it is loaded.
352 class MouseLockModule : public pp::Module { 348 class MouseLockModule : public pp::Module {
353 public: 349 public:
354 MouseLockModule() : pp::Module() {} 350 MouseLockModule() : pp::Module() {}
355 virtual ~MouseLockModule() {} 351 virtual ~MouseLockModule() {}
356 352
357 // Override CreateInstance to create your customized Instance object. 353 // Override CreateInstance to create your customized Instance object.
358 virtual pp::Instance* CreateInstance(PP_Instance instance) { 354 virtual pp::Instance* CreateInstance(PP_Instance instance) {
359 return new mouselock::MouseLockInstance(instance); 355 return new MouseLockInstance(instance);
360 } 356 }
361 }; 357 };
362 358
363 namespace pp { 359 namespace pp {
364 360
365 // Factory function for your specialization of the Module object. 361 // Factory function for your specialization of the Module object.
366 Module* CreateModule() { return new MouseLockModule(); } 362 Module* CreateModule() { return new MouseLockModule(); }
367 363
368 } // namespace pp 364 } // namespace pp
OLDNEW
« no previous file with comments | « native_client_sdk/src/examples/api/mouse_lock/mouse_lock.h ('k') | native_client_sdk/src/examples/api/mouse_lock/mouselock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698