mirror of
https://github.com/glfw/glfw.git
synced 2026-08-27 17:05:54 +02:00
Fixed joysticks test segfault.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
int i;
|
||||
int axis_width, axis_height;
|
||||
int button_width, button_height;
|
||||
const int axis_height = 3 * height / 4;
|
||||
const int button_height = height / 4;
|
||||
|
||||
axis_width = width / j->axis_count;
|
||||
axis_height = 3 * height / 4;
|
||||
|
||||
button_width = width / j->button_count;
|
||||
button_height = height / 4;
|
||||
|
||||
for (i = 0; i < j->axis_count; i++)
|
||||
if (j->axis_count)
|
||||
{
|
||||
float value = j->axes[i] / 2.f + 0.5f;
|
||||
const int axis_width = width / j->axis_count;
|
||||
|
||||
glColor3f(0.3f, 0.3f, 0.3f);
|
||||
glRecti(x + i * axis_width,
|
||||
y,
|
||||
x + (i + 1) * axis_width,
|
||||
y + axis_height);
|
||||
for (i = 0; i < j->axis_count; i++)
|
||||
{
|
||||
float value = j->axes[i] / 2.f + 0.5f;
|
||||
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
glRecti(x + i * axis_width,
|
||||
y + (int) (value * (axis_height - 5)),
|
||||
x + (i + 1) * axis_width,
|
||||
y + 5 + (int) (value * (axis_height - 5)));
|
||||
glColor3f(0.3f, 0.3f, 0.3f);
|
||||
glRecti(x + i * axis_width,
|
||||
y,
|
||||
x + (i + 1) * axis_width,
|
||||
y + axis_height);
|
||||
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
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])
|
||||
glColor3f(1.f, 1.f, 1.f);
|
||||
else
|
||||
glColor3f(0.3f, 0.3f, 0.3f);
|
||||
const int button_width = width / j->button_count;
|
||||
|
||||
glRecti(x + i * button_width,
|
||||
y + axis_height,
|
||||
x + (i + 1) * button_width,
|
||||
y + axis_height + button_height);
|
||||
for (i = 0; i < j->button_count; i++)
|
||||
{
|
||||
if (j->buttons[i])
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user