Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » DrawLine bug
DrawLine bug [message #45595] |
Mon, 14 December 2015 05:32  |
pvictor
Messages: 75 Registered: December 2015
|
Member |
|
|
I was drawing a rotating line with width > 1. I discovered that the line doesn't move smoothly - when it goes strictly horizontal or vertical, it is drawn with an offset about half of its width. I found the source - GtkDrawOp.cpp. Here's the corrected function SystemDraw::DrawLineOp() (old lines are in comments). After correction the line rotates smoothly without any jumps.
void SystemDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
if(IsNull(width) || IsNull(color))
return;
if(width == 0)
width = 1;
FlushText();
SetColor(color);
if(width == PEN_SOLID)
width = 1;
if(y1 == y2 && width >= 0)
DrawRect(x1, y1-width/2, x2 - x1, width, color); // DrawRect(x1, y1, x2 - x1, width, color);
else
if(x1 == x2 && width >= 0)
DrawRect(x1-width/2, y1, width, y2 - y1, color); // DrawRect(x1, y1, width, y2 - y1, color);
else {
int w = width < 0 ? 1 : width;
double d = w / 2.0;
if(y1 == y2) {
cairo_move_to(cr, min(x1, x2) + 0.5, y1 + d); // cairo_move_to(cr, min(x1, x1) + 0.5, y1 + d);
cairo_line_to(cr, max(x1, x2) - 0.5, y1 + d);
}
else
if(x1 == x2) {
cairo_move_to(cr, x1 + d, min(y1, y2) + 0.5);
cairo_line_to(cr, x1 + d, max(y1, y2) - 0.5);
}
else {
cairo_move_to(cr, x1, y1);
cairo_line_to(cr, x2, y2);
}
sDrawLineStroke(cr, width);
}
}
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 05:46:12 CEST 2025
Total time taken to generate the page: 0.00465 seconds
|