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.
This commit is contained in:
parent
ecbca3feec
commit
e2d7e6c4be
@ -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();
|
||||
|
@ -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:
|
||||
|
@ -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.");
|
||||
|
@ -26,5 +26,4 @@ class StickItWindow : public BWindow {
|
||||
BListView* fListView1;
|
||||
BListView* fListView2;
|
||||
BJoystick* fJoystick;
|
||||
JoystickWindow* fJoystickWindow;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user