From e2d7e6c4be9142efe0d8964943d674a6a784c6de Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 14 Feb 2015 22:50:57 +0100 Subject: [PATCH] StickIt: Construct a new BJoystick object to pass to the window. Previously the same BJoystick object was reused when opening a new window, which caused all windows to show the data of the same device. --- .../kits/device/stickit_BJoystick/JoystickWindow.cpp | 10 ++++++++-- .../kits/device/stickit_BJoystick/JoystickWindow.h | 4 +++- .../kits/device/stickit_BJoystick/StickItWindow.cpp | 11 +++++++---- .../kits/device/stickit_BJoystick/StickItWindow.h | 1 - 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp b/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp index 35bc782453..624a1b7cb9 100644 --- a/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp +++ b/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp @@ -24,8 +24,9 @@ rgb_color rgb_grey = {216, 216, 216}; int32 hatX[9] = {10, 10, 20, 20, 20, 10, 0, 0, 0}; int32 hatY[9] = {10, 0, 0, 10, 20, 20, 20, 10, 0}; -JoystickWindow::JoystickWindow(BJoystick *stick, BRect rect) - : BWindow(rect, "StickIt", B_TITLED_WINDOW, +JoystickWindow::JoystickWindow(const char *deviceName, BJoystick *stick, + BRect rect) + : BWindow(rect, deviceName, B_TITLED_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE) { fView = new JoystickView(Bounds(), stick); @@ -64,6 +65,11 @@ JoystickView::JoystickView(BRect frame, BJoystick *stick) } +JoystickView::~JoystickView() { + delete fStick; +} + + void JoystickView::Pulse(void) { Window()->Lock(); diff --git a/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h b/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h index 6ffe7319f8..c796ae449d 100644 --- a/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h +++ b/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h @@ -13,6 +13,7 @@ class BJoystick; class JoystickView : public BView { public: JoystickView(BRect bounds, BJoystick *stick); + virtual ~JoystickView(); virtual void Draw(BRect updateRect); virtual void Pulse(void); @@ -29,7 +30,8 @@ class JoystickView : public BView { class JoystickWindow : public BWindow { public: - JoystickWindow(BJoystick *stick, BRect rect); + JoystickWindow(const char *deviceName, + BJoystick *stick, BRect rect); virtual bool QuitRequested(void); private: diff --git a/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp b/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp index 0f94731428..cc2db40925 100644 --- a/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp +++ b/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp @@ -103,19 +103,22 @@ StickItWindow::MessageReceived(BMessage *message) temp1 << "BJoystick::GetDeviceName(), id = " << id << ", name = " << devName; temp1 = AddToList(fListView1, temp1.String()); - err = fJoystick->Open(devName); + BJoystick *joystick = new BJoystick(); + err = joystick->Open(devName); if (err != B_ERROR) { temp1 = AddToList(fListView1, "BJoystick::Open()"); temp1 = AddToList(fListView1, "BJoystick::Open()"); - if(fJoystick->IsCalibrationEnabled()) + if (joystick->IsCalibrationEnabled()) temp1 = AddToList(fListView1, "BJoystick::IsCalibrationEnabled() - True"); else temp1 = AddToList(fListView1, "BJoystick::IsCalibrationEnabled() - False"); - fJoystickWindow = new JoystickWindow(fJoystick, + JoystickWindow *window = new(std::nothrow) + JoystickWindow(devName, joystick, BRect(50, 50, 405, 350)); - fJoystickWindow->Show(); + if (window != NULL) + window->Show(); } else AddToList(fListView1, "No controller connected on that port. Try again."); diff --git a/src/tests/kits/device/stickit_BJoystick/StickItWindow.h b/src/tests/kits/device/stickit_BJoystick/StickItWindow.h index 9d77005a9b..853e845826 100644 --- a/src/tests/kits/device/stickit_BJoystick/StickItWindow.h +++ b/src/tests/kits/device/stickit_BJoystick/StickItWindow.h @@ -26,5 +26,4 @@ class StickItWindow : public BWindow { BListView* fListView1; BListView* fListView2; BJoystick* fJoystick; - JoystickWindow* fJoystickWindow; };