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 » DrawArc not working in GTK mode
DrawArc not working in GTK mode [message #50230] Fri, 31 August 2018 13:04 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior 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 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior 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 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior 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.
Re: DrawArc not working in GTK mode [message #50253 is a reply to message #50231] Tue, 04 September 2018 13:43 Go to previous message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
Thanks, frankly, this is weird way to draw ellipse, but fix should not hurt anything.

To draw ellipse without filling it, specify Null for the first color....

Mirek
Previous Topic: What is the best way to handle scaling icons?
Next Topic: JPEG Images do not get rotated correctly
Goto Forum:
  


Current Time: Fri Nov 15 13:42:29 CET 2019

Total time taken to generate the page: 0.02118 seconds