OLD | NEW |
---|---|
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 <algorithm> | 5 #include <algorithm> |
6 #include <cmath> | 6 #include <cmath> |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include "ppapi/c/ppb_gamepad.h" | 10 #include "ppapi/c/ppb_gamepad.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 Paint(); | 72 Paint(); |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 void Paint() { | 76 void Paint() { |
77 pp::ImageData image = PaintImage(device_context_.size()); | 77 pp::ImageData image = PaintImage(device_context_.size()); |
78 if (!image.is_null()) { | 78 if (!image.is_null()) { |
79 device_context_.ReplaceContents(&image); | 79 device_context_.ReplaceContents(&image); |
80 device_context_.Flush( | 80 device_context_.Flush( |
81 callback_factory_.NewCallback(&MyInstance::OnFlush)); | 81 callback_factory_.NewCallback(&MyInstance::OnFlush)); |
82 } else { | |
83 printf("NullImage\n"); | |
arajp
2015/05/07 12:19:54
Removed this since the pre submit checks were givi
| |
84 } | 82 } |
85 } | 83 } |
86 | 84 |
87 pp::ImageData PaintImage(const pp::Size& size) { | 85 pp::ImageData PaintImage(const pp::Size& size) { |
88 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true); | 86 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true); |
89 if (image.is_null()) | 87 if (image.is_null()) |
90 return image; | 88 return image; |
91 | 89 |
92 PP_GamepadsSampleData gamepad_data; | 90 PP_GamepadsSampleData gamepad_data; |
93 gamepad_->Sample(pp_instance(), &gamepad_data); | 91 gamepad_->Sample(pp_instance(), &gamepad_data); |
94 | 92 |
95 if (gamepad_data.length > 1 && gamepad_data.items[0].connected) { | 93 if (gamepad_data.length > 0 && gamepad_data.items[0].connected) { |
96 int width2 = size.width() / 2; | 94 int width2 = size.width() / 2; |
97 int height2 = size.height() / 2; | 95 int height2 = size.height() / 2; |
98 // Draw 2 axes | 96 // Draw 2 axes |
99 for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) { | 97 for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) { |
100 int x = static_cast<int>( | 98 int x = static_cast<int>( |
101 gamepad_data.items[0].axes[i + 0] * width2 + width2); | 99 gamepad_data.items[0].axes[i + 0] * width2 + width2); |
102 int y = static_cast<int>( | 100 int y = static_cast<int>( |
103 gamepad_data.items[0].axes[i + 1] * height2 + height2); | 101 gamepad_data.items[0].axes[i + 1] * height2 + height2); |
104 uint32_t box_bgra = 0x80000000; // Alpha 50%. | 102 uint32_t box_bgra = 0x80000000; // Alpha 50%. |
105 FillRect(&image, x - 3, y - 3, 7, 7, box_bgra); | 103 FillRect(&image, x - 3, y - 3, 7, 7, box_bgra); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 139 |
142 namespace pp { | 140 namespace pp { |
143 | 141 |
144 // Factory function for your specialization of the Module object. | 142 // Factory function for your specialization of the Module object. |
145 Module* CreateModule() { | 143 Module* CreateModule() { |
146 return new MyModule(); | 144 return new MyModule(); |
147 } | 145 } |
148 | 146 |
149 } // namespace pp | 147 } // namespace pp |
150 | 148 |
OLD | NEW |