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

Unified Diff: ppapi/examples/gamepad/gamepad.cc

Issue 9405033: Revise gamepad interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/examples/gamepad/gamepad.cc
diff --git a/ppapi/examples/gamepad/gamepad.cc b/ppapi/examples/gamepad/gamepad.cc
index 60ef5895d2ab209fa59e8ffb9d56f08b93d54ab0..7006dd1796e8d14a269f9ae3063bb6306918dd6b 100644
--- a/ppapi/examples/gamepad/gamepad.cc
+++ b/ppapi/examples/gamepad/gamepad.cc
@@ -49,9 +49,6 @@ class MyInstance : public pp::Instance {
pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_DEV_INTERFACE));
if (!gamepad_)
return false;
-
- RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE |
- PP_INPUTEVENT_CLASS_KEYBOARD);
return true;
}
@@ -92,27 +89,29 @@ class MyInstance : public pp::Instance {
if (image.is_null())
return image;
- PP_GamepadsData_Dev gamepad_data;
- gamepad_->SampleGamepads(pp_instance(), &gamepad_data);
-
- int width2 = size.width() / 2;
- int height2 = size.height() / 2;
- // Draw 2 axes
- for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) {
- int x = static_cast<int>(
- gamepad_data.items[0].axes[i + 0] * width2 + width2);
- int y = static_cast<int>(
- gamepad_data.items[0].axes[i + 1] * height2 + height2);
- uint32_t box_bgra = 0x80000000; // Alpha 50%.
- FillRect(&image, x - 3, y - 3, 7, 7, box_bgra);
- }
-
- for (size_t i = 0; i < gamepad_data.items[0].buttons_length; ++i) {
- float button_val = gamepad_data.items[0].buttons[i];
- uint32_t colour = static_cast<uint32_t>((button_val * 192) + 63) << 24;
- int x = i * 8 + 10;
- int y = 10;
- FillRect(&image, x - 3, y - 3, 7, 7, colour);
+ PP_GamepadsSampleData_Dev gamepad_data;
+ gamepad_->Sample(pp_instance(), &gamepad_data);
+
+ if (gamepad_data.length > 1 && gamepad_data.items[0].connected) {
+ int width2 = size.width() / 2;
+ int height2 = size.height() / 2;
+ // Draw 2 axes
+ for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) {
+ int x = static_cast<int>(
+ gamepad_data.items[0].axes[i + 0] * width2 + width2);
+ int y = static_cast<int>(
+ gamepad_data.items[0].axes[i + 1] * height2 + height2);
+ uint32_t box_bgra = 0x80000000; // Alpha 50%.
+ FillRect(&image, x - 3, y - 3, 7, 7, box_bgra);
+ }
+
+ for (size_t i = 0; i < gamepad_data.items[0].buttons_length; ++i) {
+ float button_val = gamepad_data.items[0].buttons[i];
+ uint32_t colour = static_cast<uint32_t>((button_val * 192) + 63) << 24;
+ int x = i * 8 + 10;
+ int y = 10;
+ FillRect(&image, x - 3, y - 3, 7, 7, colour);
+ }
}
return image;
}
« no previous file with comments | « ppapi/c/dev/ppb_gamepad_dev.h ('k') | ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_gamepad_rpc_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698