mirror of https://github.com/aseprite/aseprite.git
Add pixel-precise grid for any grid size
This commit is contained in:
parent
0a18e5ffc6
commit
14b64f341e
|
@ -58,6 +58,7 @@
|
|||
#include "base/chrono.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/pi.h"
|
||||
#include "doc/algo.h"
|
||||
#include "doc/doc.h"
|
||||
#include "doc/mask_boundaries.h"
|
||||
#include "doc/slice.h"
|
||||
|
@ -1186,7 +1187,7 @@ void Editor::drawGrid(Graphics* g,
|
|||
y1 -= dy;
|
||||
|
||||
// Draw pixel-precise isometric grid when zoomed in
|
||||
if (m_proj.zoom().scale() > 8.00) {
|
||||
if (m_proj.zoom().scale() > 6.00) {
|
||||
ui::Paint paint;
|
||||
paint.style(ui::Paint::Stroke);
|
||||
paint.antialias(false);
|
||||
|
@ -1249,6 +1250,11 @@ void Editor::drawGrid(Graphics* g,
|
|||
}
|
||||
}
|
||||
|
||||
static void push_line_pixel(const int x, const int y, std::vector<Point>* const data)
|
||||
{
|
||||
data->push_back(Point(x, y));
|
||||
};
|
||||
|
||||
gfx::Path& Editor::getIsometricGridPath(Rect& grid)
|
||||
{
|
||||
static Path path;
|
||||
|
@ -1269,65 +1275,27 @@ gfx::Path& Editor::getIsometricGridPath(Rect& grid)
|
|||
|
||||
// Prepare bitmap
|
||||
im->clear(0x00);
|
||||
int x = 0;
|
||||
int y = int(std::round(grid.h * 0.5));
|
||||
const int lx = grid.w;
|
||||
int ly = y - 1;
|
||||
const Point a(0, std::round(grid.h * 0.5));
|
||||
const Point b(std::floor(grid.w * 0.5), grid.h);
|
||||
std::vector<Point> line;
|
||||
|
||||
im->fillRect(0, std::round(y * pix.h), std::round(lx * pix.w), std::round(y * pix.h), 0x01);
|
||||
// We use the line drawing algorithm to find the points
|
||||
// for a single pixel-precise line
|
||||
doc::algo_line_continuous_with_fix_for_line_brush(a.x,
|
||||
a.y,
|
||||
b.x,
|
||||
b.y,
|
||||
&line,
|
||||
(doc::AlgoPixel)&push_line_pixel);
|
||||
|
||||
y++;
|
||||
x++;
|
||||
|
||||
// 2:1
|
||||
if (grid.w == grid.h * 2) {
|
||||
for (; y < grid.h; y++, x += 2)
|
||||
im->fillRect(std::round(x * pix.w),
|
||||
std::round((y - (x + 1)) * pix.h),
|
||||
std::round((lx - x) * pix.w),
|
||||
std::round(y * pix.h),
|
||||
0x01);
|
||||
|
||||
im->fillRect(std::round(x * pix.w),
|
||||
0,
|
||||
std::round((x + 2) * pix.w),
|
||||
std::round(y * pix.h),
|
||||
// Iterating on said points, we fill in the bitmap
|
||||
// for a single cell grid
|
||||
for (auto p : line)
|
||||
im->fillRect(std::round(p.x * pix.w),
|
||||
std::round((grid.h - p.y) * pix.h),
|
||||
std::floor((grid.w - p.x) * pix.w),
|
||||
std::floor(p.y * pix.h),
|
||||
0x01);
|
||||
}
|
||||
// 1:1
|
||||
else if (grid.w == grid.h) {
|
||||
for (; y < grid.h; y++, x++, ly--)
|
||||
im->fillRect(std::round(x * pix.w),
|
||||
std::round(ly * pix.h),
|
||||
std::round((lx - x) * pix.w),
|
||||
std::round(y * pix.h),
|
||||
0x01);
|
||||
|
||||
im->fillRect(std::round(x * pix.w), 0, std::round(x * pix.w), std::round(y * pix.h), 0x01);
|
||||
}
|
||||
// Quick test for other ratios
|
||||
else if (grid.w > grid.h * 2) {
|
||||
float step = 0.00;
|
||||
float rem = 0.00;
|
||||
const float len = float(grid.w) / (grid.h + 1);
|
||||
|
||||
for (; y < grid.h; y++, x += step, ly--) {
|
||||
step = len + rem;
|
||||
rem = (step - int(step)) * int(std::round(step) > std::floor(step));
|
||||
step = std::round(step);
|
||||
im->fillRect(std::round(x * pix.w),
|
||||
std::round(ly * pix.h),
|
||||
std::round((lx - x) * pix.w),
|
||||
std::round(y * pix.h),
|
||||
0x01);
|
||||
}
|
||||
|
||||
im->fillRect(std::round((grid.w * 0.5 - 1) * pix.w),
|
||||
0,
|
||||
std::round((grid.w * 0.5 + 1) * pix.w),
|
||||
std::round(y * pix.h),
|
||||
0x01);
|
||||
}
|
||||
|
||||
doc::MaskBoundaries immask;
|
||||
immask.regen(im);
|
||||
|
|
Loading…
Reference in New Issue