mirror of https://github.com/odrling/Aegisub
Cut down on magic numbers in the drawing code for the x/y rotate grid
This commit is contained in:
parent
70440a8874
commit
41434ec5a1
|
@ -49,20 +49,30 @@ void VisualToolRotateXY::Draw() {
|
||||||
float g = colour[0].Green() / 255.f;
|
float g = colour[0].Green() / 255.f;
|
||||||
float b = colour[0].Blue() / 255.f;
|
float b = colour[0].Blue() / 255.f;
|
||||||
|
|
||||||
std::vector<float> colors(11 * 8 * 4);
|
// Number of lines on each side of each axis
|
||||||
for (int i = 0; i < 88; ++i) {
|
static const int radius = 5;
|
||||||
|
// Total number of lines, including center axis line
|
||||||
|
static const int line_count = radius * 2 + 1;
|
||||||
|
// Distance between each line in pixels
|
||||||
|
static const int spacing = 20;
|
||||||
|
// Length of each grid line in pixels from axis to one end
|
||||||
|
static const int half_line_length = spacing * (radius + 1);
|
||||||
|
static const float fade_factor = 0.9f / radius;
|
||||||
|
|
||||||
|
std::vector<float> colors(line_count * 8 * 4);
|
||||||
|
for (int i = 0; i < line_count * 8; ++i) {
|
||||||
colors[i * 4 + 0] = r;
|
colors[i * 4 + 0] = r;
|
||||||
colors[i * 4 + 1] = g;
|
colors[i * 4 + 1] = g;
|
||||||
colors[i * 4 + 2] = b;
|
colors[i * 4 + 2] = b;
|
||||||
colors[i * 4 + 3] = (i + 3) % 4 > 1 ? 0 : (1.f - abs(i / 8 - 5) * 0.18f);
|
colors[i * 4 + 3] = (i + 3) % 4 > 1 ? 0 : (1.f - abs(i / 8 - radius) * fade_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> points(11 * 8 * 2);
|
std::vector<float> points(line_count * 8 * 2);
|
||||||
for (int i = 0; i < 11; ++i) {
|
for (int i = 0; i < line_count; ++i) {
|
||||||
int pos = 20 * (i - 5);
|
int pos = spacing * (i - radius);
|
||||||
|
|
||||||
points[i * 16 + 0] = pos;
|
points[i * 16 + 0] = pos;
|
||||||
points[i * 16 + 1] = 120;
|
points[i * 16 + 1] = half_line_length;
|
||||||
|
|
||||||
points[i * 16 + 2] = pos;
|
points[i * 16 + 2] = pos;
|
||||||
points[i * 16 + 3] = 0;
|
points[i * 16 + 3] = 0;
|
||||||
|
@ -71,9 +81,9 @@ void VisualToolRotateXY::Draw() {
|
||||||
points[i * 16 + 5] = 0;
|
points[i * 16 + 5] = 0;
|
||||||
|
|
||||||
points[i * 16 + 6] = pos;
|
points[i * 16 + 6] = pos;
|
||||||
points[i * 16 + 7] = -120;
|
points[i * 16 + 7] = -half_line_length;
|
||||||
|
|
||||||
points[i * 16 + 8] = 120;
|
points[i * 16 + 8] = half_line_length;
|
||||||
points[i * 16 + 9] = pos;
|
points[i * 16 + 9] = pos;
|
||||||
|
|
||||||
points[i * 16 + 10] = 0;
|
points[i * 16 + 10] = 0;
|
||||||
|
@ -82,7 +92,7 @@ void VisualToolRotateXY::Draw() {
|
||||||
points[i * 16 + 12] = 0;
|
points[i * 16 + 12] = 0;
|
||||||
points[i * 16 + 13] = pos;
|
points[i * 16 + 13] = pos;
|
||||||
|
|
||||||
points[i * 16 + 14] = -120;
|
points[i * 16 + 14] = -half_line_length;
|
||||||
points[i * 16 + 15] = pos;
|
points[i * 16 + 15] = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue