Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » DrawArc not working in GTK mode 
	
		
		
			| DrawArc not working in GTK mode [message #50230] | 
			Fri, 31 August 2018 13:04   | 
		 
		
			
				
				
				
					
						  
						mdelfede
						 Messages: 1310 Registered: September 2007 
						
					 | 
					Ultimate Contributor  | 
					 | 
		 
		 
	 | 
 
	
		Hi, I've this code: 
 
iw.DrawArc(Rect(xc - r, yc - r, xc + r, yc + r), Point(xc + r, 0), Point(xc + r, 0), 0, c);
  
(iw is an ImageDraw) 
 
which should draw the outline of a circle. It works perfectly in X11 mode, it does nothing in GTK mode. 
I tried with DrawEllipse and this one DOES work, but fills the circle, which is not what I want. 
I tried also to draw half ellipse, to see if the problem is becuse of identical starting and ending points, 
but it also doesn't draw anything in GTK mode. 
 
It's a bug or am I missing something ? 
 
Ciao 
 
Massimo 
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
	
		
		
			| Re: DrawArc not working in GTK mode [message #50231 is a reply to message #50230] | 
			Fri, 31 August 2018 13:17    | 
		 
		
			
				
				
				
					
						  
						mdelfede
						 Messages: 1310 Registered: September 2007 
						
					 | 
					Ultimate Contributor  | 
					 | 
		 
		 
	 | 
 
	
		Found it... Cairo doesn't draw anything with ang1 == ang2. Modifying DrawArcOp like this works: 
 
void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color)
{
	if(rc.Width() <= 0 || rc.Height() <= 0)
		return;
	FlushText();
	Sizef radius = Sizef(rc.Size()) / 2.0;
	Pointf center = Pointf(rc.TopLeft()) + radius;
	double ang1 = Bearing((Pointf(start) - center) / radius);
	double ang2 = Bearing((Pointf(end) - center) / radius);
--->	if(ang1 == ang2)
--->		ang1 -= 0.000001;
	
	cairo_move_to(cr, center.x + radius.cx * cos(ang1), center.y + radius.cy * sin(ang1));
	cairo_save(cr);
	cairo_translate(cr, rc.left + radius.cx, rc.top + radius.cy);
	cairo_scale(cr, radius.cx, radius.cy);
	cairo_arc_negative(cr, 0, 0, 1, ang1, ang2);
	cairo_restore(cr);
	SetColor(color);
	sDrawLineStroke(cr, width);
}
 
 
BTW line thickness is much smaller in Cairo than in X11.
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
	
		
		
			| Re: DrawArc not working in GTK mode [message #50232 is a reply to message #50231] | 
			Fri, 31 August 2018 13:54    | 
		 
		
			
				
				
				
					
						  
						mdelfede
						 Messages: 1310 Registered: September 2007 
						
					 | 
					Ultimate Contributor  | 
					 | 
		 
		 
	 | 
 
	
		As a quick workaround without changing UPP code : 
 
static void _DrawCircle(ImageDraw &iw, int xc, int yc, int r, Color c)
{
#ifdef flagGTK
	iw.Alpha().DrawArc(Rect(xc - r, yc - r, xc + r, yc + r), Point(xc + r, 0), Point(xc - r, 0), 2, GrayColor(255));
	iw.        DrawArc(Rect(xc - r, yc - r, xc + r, yc + r), Point(xc + r, 0), Point(xc - r, 0), 2, c);
	iw.Alpha().DrawArc(Rect(xc - r, yc - r, xc + r, yc + r), Point(xc - r, 0), Point(xc + r, 0), 2, GrayColor(255));
	iw.        DrawArc(Rect(xc - r, yc - r, xc + r, yc + r), Point(xc - r, 0), Point(xc + r, 0), 2, c);
#else
	iw.Alpha().DrawArc(Rect(xc - r, yc - r, xc + r, yc + r), Point(xc + r, 0), Point(xc + r, 0), 0, GrayColor(255));
	iw.        DrawArc(Rect(xc - r, yc - r, xc + r, yc + r), Point(xc + r, 0), Point(xc + r, 0), 0, c);
#endif
}
 
 
Notice the thickness of 2 in GTK mode, using the default (0 or 1) draws an almost invisible arc. 
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
	| 
		
 |   
Goto Forum:
 
 Current Time: Tue Nov 04 02:18:15 CET 2025 
 Total time taken to generate the page: 0.04954 seconds 
 |