Fixed joysticks test segfault.

master
Camilla Berglund ago%!(EXTRA string=12 years)
parent 6c12ffc902
commit cc4c7167fd
  1. 1
      README.md
  2. 64
      tests/joysticks.c

@ -35,6 +35,7 @@ guide in the GLFW documentation.
documentation is built documentation is built
- Renamed configuration header to `glfw_config.h` to avoid conflicts - Renamed configuration header to `glfw_config.h` to avoid conflicts
- Bugfix: The `glfw3.pc` file did not respect the `LIB_SUFFIX` CMake option - Bugfix: The `glfw3.pc` file did not respect the `LIB_SUFFIX` CMake option
- Bugfix: The `joysticks` test would segfault if a controller had no axes
- [Win32] Bugfix: Removed joystick axis value negation left over from GLFW 2 - [Win32] Bugfix: Removed joystick axis value negation left over from GLFW 2
- [Win32] Bugfix: Restoring windows using the Win+D hot key did not trigger the - [Win32] Bugfix: Restoring windows using the Win+D hot key did not trigger the
focus callback focus callback

@ -64,43 +64,47 @@ static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
static void draw_joystick(Joystick* j, int x, int y, int width, int height) static void draw_joystick(Joystick* j, int x, int y, int width, int height)
{ {
int i; int i;
int axis_width, axis_height; const int axis_height = 3 * height / 4;
int button_width, button_height; const int button_height = height / 4;
axis_width = width / j->axis_count; if (j->axis_count)
axis_height = 3 * height / 4; {
const int axis_width = width / j->axis_count;
button_width = width / j->button_count; for (i = 0; i < j->axis_count; i++)
button_height = height / 4; {
float value = j->axes[i] / 2.f + 0.5f;
for (i = 0; i < j->axis_count; i++) glColor3f(0.3f, 0.3f, 0.3f);
{ glRecti(x + i * axis_width,
float value = j->axes[i] / 2.f + 0.5f; y,
x + (i + 1) * axis_width,
glColor3f(0.3f, 0.3f, 0.3f); y + axis_height);
glRecti(x + i * axis_width,
y, glColor3f(1.f, 1.f, 1.f);
x + (i + 1) * axis_width, glRecti(x + i * axis_width,
y + axis_height); y + (int) (value * (axis_height - 5)),
x + (i + 1) * axis_width,
glColor3f(1.f, 1.f, 1.f); y + 5 + (int) (value * (axis_height - 5)));
glRecti(x + i * axis_width, }
y + (int) (value * (axis_height - 5)),
x + (i + 1) * axis_width,
y + 5 + (int) (value * (axis_height - 5)));
} }
for (i = 0; i < j->button_count; i++) if (j->button_count)
{ {
if (j->buttons[i]) const int button_width = width / j->button_count;
glColor3f(1.f, 1.f, 1.f);
else
glColor3f(0.3f, 0.3f, 0.3f);
glRecti(x + i * button_width, for (i = 0; i < j->button_count; i++)
y + axis_height, {
x + (i + 1) * button_width, if (j->buttons[i])
y + axis_height + button_height); glColor3f(1.f, 1.f, 1.f);
else
glColor3f(0.3f, 0.3f, 0.3f);
glRecti(x + i * button_width,
y + axis_height,
x + (i + 1) * button_width,
y + axis_height + button_height);
}
} }
} }

Loading…
Cancel
Save