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 » Developing U++ » U++ Developers corner » Optimizing DrawImage across platforms
Re: MILESTONE: gtk3 replaces gtk2 as default linux backend [message #53699 is a reply to message #53689] Wed, 22 April 2020 14:08 Go to previous messageGo to previous message
Tom1
Messages: 1303
Registered: March 2007
Ultimate Contributor
Hi,

Here's a completing feature for RectTracker for tracking line drawing (TrackLine) and free-hand polyline (TrackRoute):

class LineTracker: public RectTracker{
public:
	int mode;
	Vector<Point> route;

	Vector<Point> TrackLine(const Point& p){
		mode=1;
		route.Clear();
		route.Add(p);
		Track(Rect(p,p),0,0);
		return clone(route);
	}
	
	Vector<Point> TrackRoute(const Point& p){
		mode=2;
		route.Clear();
		route.Add(p);
		Track(Rect(p,p),0,0);
		return clone(route);
	}

	void MouseMove(Point p, dword){
		if(mode==2 || route.GetCount()<2){
			route.Add(p);
		}
		else route[1]=p;
		Refresh();
		sync(Rect(route[0],route[route.GetCount()-1]));
	}

	void Paint(Draw& w){
		w.DrawImage(0, 0, master_image);
		w.Clip(clip & GetMaster().GetSize());
		int style=width;
		if(pattern!=DRAWDRAGRECT_SOLID){
			Color color2 = IsDark(color) ? White() : Black();
			w.DrawPolyline(route,width,color2);
			switch(pattern){
				case DRAWDRAGRECT_NORMAL:
					style=PEN_DOT;
					break;
				case DRAWDRAGRECT_DASHED:
					style=PEN_DASHDOT;
					break;
			}
		}
		w.DrawPolyline(route,style,color);
		w.End();
	}
	
	LineTracker(Ctrl &master): RectTracker(master){
		MinSize(Size(-100000,-100000));
		mode=1;
	}
};


Feel free to include it in U++.

To test the functionality, you can try:
	void LeftDown(Point p, dword flags){
		LineTracker tracker(*this);
		tracker.Solid();
		tracker.Width(3);
		tracker.SetColor(Blue());

		Vector<Point> res;

		if(flags&K_CTRL) res = tracker.TrackRoute(p);
		else res = tracker.TrackLine(p);
		// ...
	}

It proved easy enough to inherit from RectTracker, so I made it a separate class after all.

Best regards,

Tom

[Updated on: Wed, 22 April 2020 21:11]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Rapsberry PI - cpu dilemma
Next Topic: U++ on Telegram
Goto Forum:
  


Current Time: Sat Jun 07 06:14:54 CEST 2025

Total time taken to generate the page: 0.06311 seconds