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

Side by Side Diff: native_client_sdk/src/examples/api/mouse_lock/mouselock.h

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
(Empty)
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
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/size.h"
19 #include "ppapi/cpp/var.h"
20 #include "ppapi/utility/completion_callback_factory.h"
21
22 #ifdef _MSC_VER
23 // Allow 'this' in initializer list
24 #pragma warning(disable : 4355)
25 #endif
26
27 namespace mouselock {
28
29 class MouseLockInstance : public pp::Instance, public pp::MouseLock {
30 public:
31 explicit MouseLockInstance(PP_Instance instance)
32 : pp::Instance(instance),
33 pp::MouseLock(this),
34 mouse_locked_(false),
35 waiting_for_flush_completion_(false),
36 callback_factory_(this),
37 fullscreen_(this),
38 is_context_bound_(false),
39 was_fullscreen_(false),
40 background_scanline_(NULL) {}
41 virtual ~MouseLockInstance();
42
43 // Called by the browser when the NaCl module is loaded and all ready to go.
44 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
45
46 // Called by the browser to handle incoming input events.
47 virtual bool HandleInputEvent(const pp::InputEvent& event);
48
49 // Called whenever the in-browser window changes size.
50 virtual void DidChangeView(const pp::View& view);
51
52 // Called by the browser when mouselock is lost. This happens when the NaCl
53 // module exits fullscreen mode.
54 virtual void MouseLockLost();
55
56 private:
57 // Return the Cartesian distance between two points.
58 double GetDistance(int point_1_x,
59 int point_1_y,
60 int point_2_x,
61 int point_2_y) {
62 return sqrt(pow(static_cast<double>(point_1_x - point_2_x), 2) +
63 pow(static_cast<double>(point_1_y - point_2_y), 2));
64 }
65
66 // Called when mouse lock has been acquired. Used as a callback to
67 // pp::MouseLock.LockMouse().
68 void DidLockMouse(int32_t result);
69
70 // Called when the 2D context has been flushed to the browser window. Used
71 // as a callback to pp::Graphics2D.Flush().
72 void DidFlush(int32_t result);
73
74 // Creates a new paint buffer, paints it then flush it to the 2D context. If
75 // a flush is pending, this does nothing.
76 void Paint();
77
78 // Create a new pp::ImageData and paint the graphics that represent the mouse
79 // movement in it. Return the new pp::ImageData.
80 pp::ImageData PaintImage(const pp::Size& size);
81
82 // Fill the image with the background color.
83 void ClearToBackground(pp::ImageData* image);
84
85 void DrawCenterSpot(pp::ImageData* image, uint32_t spot_color);
86
87 void DrawNeedle(pp::ImageData* image, uint32_t needle_color);
88
89 // Print the printf-style format to the "console" via PostMessage.
90 void Log(const char* format, ...);
91
92 pp::Size size_;
93
94 bool mouse_locked_;
95 pp::Point mouse_movement_;
96 bool waiting_for_flush_completion_;
97 pp::CompletionCallbackFactory<MouseLockInstance> callback_factory_;
98
99 pp::Fullscreen fullscreen_;
100 pp::Graphics2D device_context_;
101 bool is_context_bound_;
102 bool was_fullscreen_;
103 uint32_t* background_scanline_;
104 };
105
106 } // namespace mouselock
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698