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

Side by Side Diff: examples/mouselock/mouselock.h

Issue 8510041: Add a mouselock example. (Closed) Base URL: http://nativeclient-sdk.googlecode.com/svn/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include <cmath>
6
7 #include "ppapi/c/ppb_fullscreen.h"
8 #include "ppapi/c/ppb_input_event.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/fullscreen.h"
11 #include "ppapi/cpp/mouse_lock.h"
12 #include "ppapi/cpp/graphics_2d.h"
13 #include "ppapi/cpp/image_data.h"
14 #include "ppapi/cpp/input_event.h"
15 #include "ppapi/cpp/instance.h"
16 #include "ppapi/cpp/module.h"
17 #include "ppapi/cpp/rect.h"
18 #include "ppapi/cpp/var.h"
19
20 namespace mouselock {
21
22 class MouseLockInstance : public pp::Instance, public pp::MouseLock {
23 public:
24 explicit MouseLockInstance(PP_Instance instance)
25 : pp::Instance(instance),
26 pp::MouseLock(this),
27 width_(0),
28 height_(0),
29 mouse_locked_(false),
30 waiting_for_flush_completion_(false),
31 callback_factory_(this),
32 fullscreen_(this) {
33 }
34 virtual ~MouseLockInstance() {}
35
36 // Called by the browser when the NaCl module is loaded and all ready to go.
37 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
38
39 // Called by the browser to handle incoming input events.
40 virtual bool HandleInputEvent(const pp::InputEvent& event);
41
42 // Called whenever the in-browser window changes size.
43 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip);
44
45 // Called by the browser when mouselock is lost. This happens when the NaCl
46 // module exits fullscreen mode.
47 virtual void MouseLockLost();
48
49 private:
50 // Return the Cartesian distance between two points.
51 double GetDistance(int point_1_x, int point_1_y,
52 int point_2_x, int point_2_y) {
53 return sqrt(pow(static_cast<double>(point_1_x - point_2_x), 2) +
54 pow(static_cast<double>(point_1_y - point_2_y), 2));
55 }
56
57 // Called when mouse lock has been acquired. Used as a callback to
58 // pp::MouseLock.LockMouse().
59 void DidLockMouse(int32_t result);
60
61 // Called when the 2D context has been flushed to the browser window. Used
62 // as a callback to pp::Graphics2D.Flush().
63 void DidFlush(int32_t result);
64
65 // Creates a new paint buffer, paints it then flush it to the 2D context. If
66 // a flush is pending, this does nothing.
67 void Paint();
68
69 // Create a new pp::ImageData and paint the graphics that represent the mouse
70 // movement in it. Return the new pp::ImageData.
71 pp::ImageData PaintImage(int width, int height);
72
73 // Print the printf-style format to the "console" via PostMessage.
74 void Log(const char* format, ...);
75
76 int width_;
77 int height_;
78
79 bool mouse_locked_;
80 pp::Point mouse_movement_;
81 bool waiting_for_flush_completion_;
82 bool saw_first_didchangeview_;
83 bool fullscreen_pending_;
84 pp::CompletionCallbackFactory<MouseLockInstance> callback_factory_;
85
86 pp::Fullscreen fullscreen_;
87 pp::Graphics2D device_context_;
88 };
89
90 } // namespace mouselock
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698