-
Notifications
You must be signed in to change notification settings - Fork 38
/
lr_input_crosshair.c
92 lines (77 loc) · 1.79 KB
/
lr_input_crosshair.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "lr_input.h"
#include <stdint.h>
struct lr_crosshair_s
{
int32_t x;
int32_t y;
uint32_t c;
};
typedef struct lr_crosshair_s lr_crosshair_t;
static const uint32_t COLORS[LR_INPUT_MAX_DEVICES] =
{
0x000000FF,
0x00FF0000,
0x0000FF00,
0x00FFFFFF,
0x00FF00FF,
0x00FFFF00,
0x0000FFFF,
0x00000001
};
static lr_crosshair_t CROSSHAIRS[LR_INPUT_MAX_DEVICES] = {{0,0,0}};
static
void
lr_input_crosshair_draw(const lr_crosshair_t *crosshair_,
uint32_t *buf_,
const int32_t width_,
const int32_t height_)
{
int32_t x;
int32_t y;
uint32_t *p;
x = ((crosshair_->x + 32768) / (65535 / width_));
y = ((crosshair_->y + 32768) / (65535 / height_));
p = &buf_[x + (y * width_)];
*p = crosshair_->c;
if(x >= 1)
*(p -1) = crosshair_->c;
if(x < (width_ - 1))
*(p + 1) = crosshair_->c;
if(y >= 1)
*(p - width_) = crosshair_->c;
if(y < (height_ - 1))
*(p + width_) = crosshair_->c;
}
void
lr_input_crosshair_set(const uint32_t i_,
const int32_t x_,
const int32_t y_)
{
if(i_ >= LR_INPUT_MAX_DEVICES)
return;
CROSSHAIRS[i_].x = x_;
CROSSHAIRS[i_].y = y_;
CROSSHAIRS[i_].c = COLORS[i_];
}
void
lr_input_crosshair_reset(const uint32_t i_)
{
if(i_ >= LR_INPUT_MAX_DEVICES)
return;
CROSSHAIRS[i_].x = 0;
CROSSHAIRS[i_].y = 0;
CROSSHAIRS[i_].c = 0;
}
void
lr_input_crosshairs_draw(uint32_t *buf_,
const uint32_t width_,
const uint32_t height_)
{
int i;
for(i = 0; i < LR_INPUT_MAX_DEVICES; i++)
{
if(CROSSHAIRS[i].c == 0)
continue;
lr_input_crosshair_draw(&CROSSHAIRS[i],buf_,width_,height_);
}
}