Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » DrawLine bug
DrawLine bug [message #45595] Mon, 14 December 2015 05:32 Go to next message
pvictor is currently offline  pvictor
Messages: 67
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);
	}
}
Re: DrawLine bug [message #45598 is a reply to message #45595] Mon, 14 December 2015 14:36 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks, patch applied.
Previous Topic: Mismatched icon sizes
Next Topic: Method declared in iml_header.h but missing in iml_source.h
Goto Forum:
  


Current Time: Fri Apr 19 07:58:19 CEST 2024

Total time taken to generate the page: 0.03558 seconds