Fix dirty pixels problem on window's right side

The last column of pixel on the window's right side isn't correctly
drawn and pixels appear dirty and more noticeably when the a NagView
message was previously shown, a stripe of red pixels remains on the right.

We use now a more souding roundig scheme. Now the rectangles to clip or to
draw are passed around as Lua numbers without any rounding. In turns, when
the rect coordinates are passed to the renderer we ensure the border of the
rect are correctly snapped to the pixel's grid. It works by computing the
coordinates of the edges, round them to integers and then compute the rect's
width based on the rounded coordinates values.
This commit is contained in:
Francesco Abbate 2021-10-10 14:52:55 +02:00
parent c179f909e2
commit cb08c5cbb7
3 changed files with 19 additions and 12 deletions

View File

@ -602,7 +602,7 @@ function Node:draw()
self:draw_tabs()
end
local pos, size = self.active_view.position, self.active_view.size
core.push_clip_rect(pos.x, pos.y, size.x + pos.x % 1, size.y + pos.y % 1)
core.push_clip_rect(pos.x, pos.y, pos.x + size.x, pos.y + size.y)
self.active_view:draw()
core.pop_clip_rect()
else

View File

@ -140,7 +140,7 @@ end
function View:draw_background(color)
local x, y = self.position.x, self.position.y
local w, h = self.size.x, self.size.y
renderer.draw_rect(x, y, w + x % 1, h + y % 1, color)
renderer.draw_rect(x, y, w, h, color)
end

View File

@ -49,23 +49,30 @@ static int f_end_frame(lua_State *L) {
}
static RenRect rect_to_grid(lua_Number x, lua_Number y, lua_Number w, lua_Number h) {
int x1 = (int) (x + 0.5), y1 = (int) (y + 0.5);
int x2 = (int) (x + w + 0.5), y2 = (int) (y + h + 0.5);
return (RenRect) {x1, y1, x2 - x1, y2 - y1};
}
static int f_set_clip_rect(lua_State *L) {
RenRect rect;
rect.x = luaL_checknumber(L, 1);
rect.y = luaL_checknumber(L, 2);
rect.width = luaL_checknumber(L, 3);
rect.height = luaL_checknumber(L, 4);
lua_Number x = luaL_checknumber(L, 1);
lua_Number y = luaL_checknumber(L, 2);
lua_Number w = luaL_checknumber(L, 3);
lua_Number h = luaL_checknumber(L, 4);
RenRect rect = rect_to_grid(x, y, w, h);
rencache_set_clip_rect(rect);
return 0;
}
static int f_draw_rect(lua_State *L) {
RenRect rect;
rect.x = luaL_checknumber(L, 1);
rect.y = luaL_checknumber(L, 2);
rect.width = luaL_checknumber(L, 3);
rect.height = luaL_checknumber(L, 4);
lua_Number x = luaL_checknumber(L, 1);
lua_Number y = luaL_checknumber(L, 2);
lua_Number w = luaL_checknumber(L, 3);
lua_Number h = luaL_checknumber(L, 4);
RenRect rect = rect_to_grid(x, y, w, h);
RenColor color = checkcolor(L, 5, 255);
rencache_draw_rect(rect, color);
return 0;