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 » Paint dashed polyline
Paint dashed polyline [message #34656] Sun, 04 December 2011 00:39 Go to next message
koldo is currently offline  koldo
Messages: 3033
Registered: August 2008
Ultimate Member
Hello all

I wanted to paint a dashed polyline, but code like this does not work properly.

How could you do it?

void DrawPolyline(Painter& w, const Vector<Point> &p)
{
	for (int i = 1; i < p.GetCount(); ++i) 
		w.Move(p[i-1]).Line(p[i]).Stroke(2, Black()).Dash("5 2");
}


Best regards
Iñaki
Re: Paint dashed polyline [message #34660 is a reply to message #34656] Sun, 04 December 2011 11:40 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

koldo wrote on Sun, 04 December 2011 00:39

Hello all

I wanted to paint a dashed polyline, but code like this does not work properly.

How could you do it?

void DrawPolyline(Painter& w, const Vector<Point> &p)
{
	for (int i = 1; i < p.GetCount(); ++i) 
		w.Move(p[i-1]).Line(p[i]).Stroke(2, Black()).Dash("5 2");
}


Hi Koldo!
I think you should call Dash() before Stroke(). Also you don't have to call it after each segment - it will make nicer dashing at the vertices.

So I would write the code like this:
void DrawPolyline(Painter& w, const Vector<Point> &p)
{
	if(!p.GetCount()) return;
	w.Move(p[0]);
	for (int i = 1; i < p.GetCount(); ++i) 
		w.Line(p[i]);
	w.Dash("5 2").Stroke(2, Black());
}


Best regards,
Honza
Re: Paint dashed polyline [message #34661 is a reply to message #34660] Sun, 04 December 2011 13:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3033
Registered: August 2008
Ultimate Member
Thank you Honza Smile

You are right. The trick is that Stroke() has to be the last command. If not strange results are got.


Best regards
Iñaki
Re: Paint dashed polyline [message #34662 is a reply to message #34661] Sun, 04 December 2011 14:08 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

It kind of makes sense. In real life, you also have to first decide what kind of line will you draw and which pencil to use and drawing comes last Wink

Honza
Re: Paint dashed polyline [message #34666 is a reply to message #34662] Sun, 04 December 2011 17:29 Go to previous message
koldo is currently offline  koldo
Messages: 3033
Registered: August 2008
Ultimate Member
dolik.rce wrote on Sun, 04 December 2011 14:08

It kind of makes sense. In real life, you also have to first decide what kind of line will you draw and which pencil to use and drawing comes last Wink

Honza
Hello Honza

In real life first I take the pencil and after that I do paint. Very Happy


Best regards
Iñaki
Previous Topic: Problem with polygon inside polygon... in Painter
Next Topic: How to use the same .iml from multiple source files.
Goto Forum:
  


Current Time: Fri Nov 22 21:39:51 CET 2019

Total time taken to generate the page: 0.00821 seconds