* Make use of the new BJoystick::GetButtonValues() so any number of buttons can
be retrieved. I think the fixed layout will actually make it impossible to see anything beyond the 9th button however... The coding style of this app is, different, to say the least and I didn't really bother fixing it up right now, so the changes just mimic what's there. * Some automatic whitespace cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41883 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,4 +4,4 @@ SimpleTest stickit :
|
|||||||
JoystickWindow.cpp
|
JoystickWindow.cpp
|
||||||
StickItApp.cpp
|
StickItApp.cpp
|
||||||
StickItWindow.cpp
|
StickItWindow.cpp
|
||||||
: be device $(TARGET_LIBSTDC++) ;
|
: be libdevice.so $(TARGET_LIBSTDC++) ;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ int32 hatX[9] = {10, 10, 20, 20, 20, 10, 0, 0, 0};
|
|||||||
int32 hatY[9] = {10, 0, 0, 10, 20, 20, 20, 10, 0};
|
int32 hatY[9] = {10, 0, 0, 10, 20, 20, 20, 10, 0};
|
||||||
|
|
||||||
JoystickWindow::JoystickWindow(BJoystick *stick, BRect rect)
|
JoystickWindow::JoystickWindow(BJoystick *stick, BRect rect)
|
||||||
: BWindow(rect, "StickIt", B_TITLED_WINDOW,
|
: BWindow(rect, "StickIt", B_TITLED_WINDOW,
|
||||||
B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
|
B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
|
||||||
{
|
{
|
||||||
fView = new JoystickView(Bounds(), stick);
|
fView = new JoystickView(Bounds(), stick);
|
||||||
@@ -55,7 +55,7 @@ JoystickView::JoystickView(BRect frame, BJoystick *stick)
|
|||||||
BStringView *stickName = new BStringView(rect, "stickname", name.String());
|
BStringView *stickName = new BStringView(rect, "stickname", name.String());
|
||||||
stickName->SetFontSize(18);
|
stickName->SetFontSize(18);
|
||||||
AddChild(stickName);
|
AddChild(stickName);
|
||||||
|
|
||||||
rect = _BuildButtons(stick);
|
rect = _BuildButtons(stick);
|
||||||
rect.top += 15;
|
rect.top += 15;
|
||||||
rect.bottom += 15;
|
rect.bottom += 15;
|
||||||
@@ -78,15 +78,16 @@ JoystickView::Draw(BRect updateRect)
|
|||||||
int32 numButtons = fStick->CountButtons();
|
int32 numButtons = fStick->CountButtons();
|
||||||
int32 numHats = fStick->CountHats();
|
int32 numHats = fStick->CountHats();
|
||||||
int32 numAxes = fStick->CountAxes();
|
int32 numAxes = fStick->CountAxes();
|
||||||
|
bool *buttons = (bool *) malloc(sizeof(bool) * numButtons);
|
||||||
int16 *axes = (int16 *) malloc(sizeof(int16) * numAxes);
|
int16 *axes = (int16 *) malloc(sizeof(int16) * numAxes);
|
||||||
uint8 *hats = (uint8 *) malloc(numHats);
|
uint8 *hats = (uint8 *) malloc(numHats);
|
||||||
fStick->Update();
|
fStick->Update();
|
||||||
|
|
||||||
// Buttons first
|
// Buttons first
|
||||||
BRect r(105, 50, 115, 60);
|
BRect r(105, 50, 115, 60);
|
||||||
uint32 buttons = fStick->ButtonValues();
|
fStick->GetButtonValues(buttons);
|
||||||
for (int32 i = 0; i < numButtons; i++) {
|
for (int32 i = 0; i < numButtons; i++) {
|
||||||
if (buttons & (1 << i)) {
|
if (buttons[i]) {
|
||||||
FillRect(r, B_SOLID_HIGH);
|
FillRect(r, B_SOLID_HIGH);
|
||||||
} else {
|
} else {
|
||||||
r.InsetBy(1, 1);
|
r.InsetBy(1, 1);
|
||||||
@@ -111,13 +112,13 @@ JoystickView::Draw(BRect updateRect)
|
|||||||
AddLine(r.LeftTop(), r.LeftBottom(), rgb_black);
|
AddLine(r.LeftTop(), r.LeftBottom(), rgb_black);
|
||||||
AddLine(r.RightTop(), r.RightBottom(), rgb_black);
|
AddLine(r.RightTop(), r.RightBottom(), rgb_black);
|
||||||
AddLine(r.LeftBottom(), r.RightBottom(), rgb_black);
|
AddLine(r.LeftBottom(), r.RightBottom(), rgb_black);
|
||||||
AddLine(BPoint(r.left+10, r.top), BPoint(r.left+10, r.bottom),
|
AddLine(BPoint(r.left+10, r.top), BPoint(r.left+10, r.bottom),
|
||||||
rgb_black);
|
rgb_black);
|
||||||
AddLine(BPoint(r.left+20, r.top), BPoint(r.left+20, r.bottom),
|
AddLine(BPoint(r.left+20, r.top), BPoint(r.left+20, r.bottom),
|
||||||
rgb_black);
|
rgb_black);
|
||||||
AddLine(BPoint(r.left, r.top+10), BPoint(r.right, r.top+10),
|
AddLine(BPoint(r.left, r.top+10), BPoint(r.right, r.top+10),
|
||||||
rgb_black);
|
rgb_black);
|
||||||
AddLine(BPoint(r.left, r.top+20), BPoint(r.right, r.top+20),
|
AddLine(BPoint(r.left, r.top+20), BPoint(r.right, r.top+20),
|
||||||
rgb_black);
|
rgb_black);
|
||||||
EndLineArray();
|
EndLineArray();
|
||||||
curHatRect.Set(r.left, r.top, r.left+10, r.top+10);
|
curHatRect.Set(r.left, r.top, r.left+10, r.top+10);
|
||||||
@@ -131,8 +132,8 @@ JoystickView::Draw(BRect updateRect)
|
|||||||
r.top += 20;
|
r.top += 20;
|
||||||
r.bottom += 20;
|
r.bottom += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now the joystick
|
// Now the joystick
|
||||||
r.Set(200, 50, 350, 200);
|
r.Set(200, 50, 350, 200);
|
||||||
FillRect(r, B_SOLID_HIGH);
|
FillRect(r, B_SOLID_HIGH);
|
||||||
fStick->GetAxisValues(axes);
|
fStick->GetAxisValues(axes);
|
||||||
@@ -147,10 +148,10 @@ JoystickView::Draw(BRect updateRect)
|
|||||||
y += 195;
|
y += 195;
|
||||||
FillEllipse(BPoint(x,y), 5, 5);
|
FillEllipse(BPoint(x,y), 5, 5);
|
||||||
SetHighColor(rgb_black);
|
SetHighColor(rgb_black);
|
||||||
|
|
||||||
// Finally, other axes
|
// Finally, other axes
|
||||||
r.Set(200, 220, 350, 234);
|
r.Set(200, 220, 350, 234);
|
||||||
for (int32 i = 2; i < numAxes; i++) {
|
for (int32 i = 2; i < numAxes; i++) {
|
||||||
FillRect(r, B_SOLID_HIGH);
|
FillRect(r, B_SOLID_HIGH);
|
||||||
x = axes[i];
|
x = axes[i];
|
||||||
x += 32768;
|
x += 32768;
|
||||||
@@ -163,6 +164,7 @@ JoystickView::Draw(BRect updateRect)
|
|||||||
r.top += 20;
|
r.top += 20;
|
||||||
r.bottom += 20;
|
r.bottom += 20;
|
||||||
}
|
}
|
||||||
|
free(buttons);
|
||||||
free(axes);
|
free(axes);
|
||||||
free(hats);
|
free(hats);
|
||||||
}
|
}
|
||||||
@@ -197,7 +199,7 @@ JoystickView::_BuildHats(BJoystick *stick, BRect rect)
|
|||||||
|
|
||||||
|
|
||||||
BRect
|
BRect
|
||||||
JoystickView::_BuildString(BString name, const char* strName, int number,
|
JoystickView::_BuildString(BString name, const char* strName, int number,
|
||||||
BRect rect)
|
BRect rect)
|
||||||
{
|
{
|
||||||
name.Append(":");
|
name.Append(":");
|
||||||
@@ -215,17 +217,17 @@ void
|
|||||||
JoystickView::_BuildAxes(BJoystick *stick, BRect rect)
|
JoystickView::_BuildAxes(BJoystick *stick, BRect rect)
|
||||||
{
|
{
|
||||||
float col1bot = rect.bottom - 30;
|
float col1bot = rect.bottom - 30;
|
||||||
int32 numAxes = stick->CountAxes();
|
int32 numAxes = stick->CountAxes();
|
||||||
// We assume that the first two axes are the x and y axes.
|
// We assume that the first two axes are the x and y axes.
|
||||||
rect.Set(130, 50, 195, 64);
|
rect.Set(130, 50, 195, 64);
|
||||||
BStringView *sview = new BStringView(rect, "sticklabel", "Stick:");
|
BStringView *sview = new BStringView(rect, "sticklabel", "Stick:");
|
||||||
sview->SetFont(be_bold_font);
|
sview->SetFont(be_bold_font);
|
||||||
sview->SetAlignment(B_ALIGN_RIGHT);
|
sview->SetAlignment(B_ALIGN_RIGHT);
|
||||||
AddChild(sview);
|
AddChild(sview);
|
||||||
|
|
||||||
BString name;
|
BString name;
|
||||||
int32 i;
|
int32 i;
|
||||||
// Now make labels for all the solitary axes
|
// Now make labels for all the solitary axes
|
||||||
rect.Set(130, 200, 195, 234);
|
rect.Set(130, 200, 195, 234);
|
||||||
for (i = 2; i < numAxes; i++) {
|
for (i = 2; i < numAxes; i++) {
|
||||||
stick->GetAxisNameAt(i, &name);
|
stick->GetAxisNameAt(i, &name);
|
||||||
|
|||||||
Reference in New Issue
Block a user