| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
| 6 * | 6 * |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 Gamepad::Gamepad() : index_(0), timestamp_(0), display_id_(0) {} | 30 Gamepad::Gamepad() : index_(0), timestamp_(0), display_id_(0) {} |
| 31 | 31 |
| 32 Gamepad::~Gamepad() {} | 32 Gamepad::~Gamepad() {} |
| 33 | 33 |
| 34 void Gamepad::SetAxes(unsigned count, const double* data) { | 34 void Gamepad::SetAxes(unsigned count, const double* data) { |
| 35 axes_.Resize(count); | 35 axes_.Resize(count); |
| 36 if (count) | 36 if (count) |
| 37 std::copy(data, data + count, axes_.begin()); | 37 std::copy(data, data + count, axes_.begin()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void Gamepad::SetButtons(unsigned count, const WebGamepadButton* data) { | 40 void Gamepad::SetButtons(unsigned count, const device::GamepadButton* data) { |
| 41 if (buttons_.size() != count) { | 41 if (buttons_.size() != count) { |
| 42 buttons_.Resize(count); | 42 buttons_.Resize(count); |
| 43 for (unsigned i = 0; i < count; ++i) | 43 for (unsigned i = 0; i < count; ++i) |
| 44 buttons_[i] = GamepadButton::Create(); | 44 buttons_[i] = GamepadButton::Create(); |
| 45 } | 45 } |
| 46 for (unsigned i = 0; i < count; ++i) { | 46 for (unsigned i = 0; i < count; ++i) { |
| 47 buttons_[i]->SetValue(data[i].value); | 47 buttons_[i]->SetValue(data[i].value); |
| 48 buttons_[i]->SetPressed(data[i].pressed); | 48 buttons_[i]->SetPressed(data[i].pressed); |
| 49 buttons_[i]->SetTouched(data[i].touched || data[i].pressed || | 49 buttons_[i]->SetTouched(data[i].touched || data[i].pressed || |
| 50 (data[i].value > 0.0f)); | 50 (data[i].value > 0.0f)); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void Gamepad::SetPose(const WebGamepadPose& pose) { | 54 void Gamepad::SetPose(const device::GamepadPose& pose) { |
| 55 if (!pose.not_null) { | 55 if (!pose.not_null) { |
| 56 if (pose_) | 56 if (pose_) |
| 57 pose_ = nullptr; | 57 pose_ = nullptr; |
| 58 return; | 58 return; |
| 59 } | 59 } |
| 60 | 60 |
| 61 if (!pose_) | 61 if (!pose_) |
| 62 pose_ = GamepadPose::Create(); | 62 pose_ = GamepadPose::Create(); |
| 63 | 63 |
| 64 pose_->SetPose(pose); | 64 pose_->SetPose(pose); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void Gamepad::SetHand(const WebGamepadHand& hand) { | 67 void Gamepad::SetHand(const device::GamepadHand& hand) { |
| 68 switch (hand) { | 68 switch (hand) { |
| 69 case kGamepadHandNone: | 69 case device::kGamepadHandNone: |
| 70 hand_ = ""; | 70 hand_ = ""; |
| 71 break; | 71 break; |
| 72 case kGamepadHandLeft: | 72 case device::kGamepadHandLeft: |
| 73 hand_ = "left"; | 73 hand_ = "left"; |
| 74 break; | 74 break; |
| 75 case kGamepadHandRight: | 75 case device::kGamepadHandRight: |
| 76 hand_ = "right"; | 76 hand_ = "right"; |
| 77 break; | 77 break; |
| 78 default: | 78 default: |
| 79 NOTREACHED(); | 79 NOTREACHED(); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 DEFINE_TRACE(Gamepad) { | 83 DEFINE_TRACE(Gamepad) { |
| 84 visitor->Trace(buttons_); | 84 visitor->Trace(buttons_); |
| 85 visitor->Trace(pose_); | 85 visitor->Trace(pose_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |