System/Libraries/Graphics2D: Fix some line-drawing inaccuracies
This commit is contained in:
parent
a23a5ae844
commit
704c3962f5
2 changed files with 17 additions and 14 deletions
|
@ -713,8 +713,6 @@ U0 Plot2D(Context2D* ctx, I64 x, I64 y,
|
||||||
U0 VLine2D(Context2D* ctx, I64 x, I64 y, I64 y2,
|
U0 VLine2D(Context2D* ctx, I64 x, I64 y, I64 y2,
|
||||||
U32 color)
|
U32 color)
|
||||||
{ // Draw a vertical line.
|
{ // Draw a vertical line.
|
||||||
if (x > ctx->width || y > ctx->height)
|
|
||||||
return;
|
|
||||||
if (y2 < y)
|
if (y2 < y)
|
||||||
return;
|
return;
|
||||||
while (y < y2 + 1) {
|
while (y < y2 + 1) {
|
||||||
|
@ -726,22 +724,27 @@ U0 VLine2D(Context2D* ctx, I64 x, I64 y, I64 y2,
|
||||||
U0 HLine2D(Context2D* ctx, I64 x, I64 y, I64 x2,
|
U0 HLine2D(Context2D* ctx, I64 x, I64 y, I64 x2,
|
||||||
U32 color)
|
U32 color)
|
||||||
{ // Draw a horizontal line.
|
{ // Draw a horizontal line.
|
||||||
if (!ctx || !ctx->fb || x > ctx->width || y < 0 || y > ctx->height)
|
|
||||||
return;
|
|
||||||
if (x2 < x)
|
if (x2 < x)
|
||||||
return;
|
return;
|
||||||
I64 width = x2 - x;
|
if (y < 0 || y > ctx->height - 1)
|
||||||
MemSetU32(ctx->fb + (y * ctx->width) + x, color,
|
return;
|
||||||
T(x + width > ctx->width, ctx->width - x, width));
|
if (x > ctx->width - 1)
|
||||||
|
return;
|
||||||
|
if (x2 < 0)
|
||||||
|
return;
|
||||||
|
I64 min_x = MaxI64(0, x);
|
||||||
|
I64 max_x = MinI64(ctx->width - 1, x2);
|
||||||
|
I64 width = (max_x - min_x) + 1;
|
||||||
|
if (width == 1) {
|
||||||
|
Plot2D(ctx, x, y, color);
|
||||||
|
} else {
|
||||||
|
MemSetU32(ctx->fb + (y * ctx->width) + x, color, width);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
U0 Line2D(Context2D* ctx, I64 x1, I64 y1, I64 x2, I64 y2,
|
U0 Line2D(Context2D* ctx, I64 x1, I64 y1, I64 x2, I64 y2,
|
||||||
U32 color)
|
U32 color)
|
||||||
{ // Draw an arbitrary line using Bresenham's algorithm.
|
{ // Draw an arbitrary line using Bresenham's algorithm.
|
||||||
x1 = Max(0, x1);
|
|
||||||
y1 = Max(0, y1);
|
|
||||||
x2 = Min(ctx->width, x2);
|
|
||||||
y2 = Min(ctx->height, y2);
|
|
||||||
if (x1 == x2) {
|
if (x1 == x2) {
|
||||||
VLine2D(ctx, x1, y1, y2, color);
|
VLine2D(ctx, x1, y1, y2, color);
|
||||||
return;
|
return;
|
||||||
|
@ -977,7 +980,7 @@ U0 Rect2D(Context2D* ctx, I64 x, I64 y, I64 w, I64 h,
|
||||||
{ // Draw a rectangle fill.
|
{ // Draw a rectangle fill.
|
||||||
I64 i;
|
I64 i;
|
||||||
for (i = y; i < y + h; i++) {
|
for (i = y; i < y + h; i++) {
|
||||||
HLine2D(ctx, x, i, x + w, color);
|
HLine2D(ctx, x, i, x + w - 1, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1563,14 +1563,14 @@ U0 @render_node_text(@html_dom_node* node, HtmlRenderer* renderer)
|
||||||
fragment_widget->ctx = NewContext2D(text_width, ToI64(node->parentNode->fontSize * 1.2))->fill(node->parentNode->backgroundColor)->text(font_name, 0, 0, node->parentNode->fontSize, node->parentNode->color, fragments[i]);
|
fragment_widget->ctx = NewContext2D(text_width, ToI64(node->parentNode->fontSize * 1.2))->fill(node->parentNode->backgroundColor)->text(font_name, 0, 0, node->parentNode->fontSize, node->parentNode->color, fragments[i]);
|
||||||
|
|
||||||
if (node->parentNode->linethroughColor) {
|
if (node->parentNode->linethroughColor) {
|
||||||
fragment_widget->ctx->line(0, (fragment_widget->ctx->height / 2), fragment_widget->ctx->width, (fragment_widget->ctx->height / 2), node->parentNode->linethroughColor);
|
fragment_widget->ctx->line(0, (fragment_widget->ctx->height / 2), fragment_widget->ctx->width - 1, (fragment_widget->ctx->height / 2), node->parentNode->linethroughColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->parentNode->underlineColor) {
|
if (node->parentNode->underlineColor) {
|
||||||
if (underline_y_pos < 0)
|
if (underline_y_pos < 0)
|
||||||
underline_y_pos = @get_truetype_baseline(font_name, node->parentNode->fontSize) + 3;
|
underline_y_pos = @get_truetype_baseline(font_name, node->parentNode->fontSize) + 3;
|
||||||
if (!(underline_y_pos < 0)) {
|
if (!(underline_y_pos < 0)) {
|
||||||
fragment_widget->ctx->line(0, underline_y_pos, fragment_widget->ctx->width, underline_y_pos, node->parentNode->color);
|
fragment_widget->ctx->line(0, underline_y_pos, fragment_widget->ctx->width - 1, underline_y_pos, node->parentNode->color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue