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 » U++ Widgets - General questions or Mixed problems » How to implent a rubber band Class in u++
How to implent a rubber band Class in u++ [message #12330] Thu, 25 October 2007 14:01 Go to next message
westcity1973 is currently offline  westcity1973
Messages: 5
Registered: June 2007
Location: China
Promising Member
I am now studying CAD. And I need a class of rubber band like AutoCAD. RectTracker is good, but I need a tracker returning an array of points. I try to implent it in Scribble, but it is not very good. Is there any simple method to implement it.

I attach the my modified scribble code .
  • Attachment: scribble.rar
    (Size: 1.83KB, Downloaded 408 times)
Re: How to implent a rubber band Class in u++ [message #12340 is a reply to message #12330] Thu, 25 October 2007 16:44 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Easy Smile

RubberBand class:
class RubberBand : public LocalLoop
{
public:
	virtual void MouseMove(Point p, dword keyflags) 	{ points.Add(p); GetMaster().Refresh(); }
	virtual void LeftUp(Point p, dword keyflags)    	{ EndLoop(); }
	virtual void RightUp(Point p, dword keyflags)   	{ EndLoop(); }

	const Vector<Point> &	GetPoints()					{ return points; }
	void 					Clear()						{ points.Clear(); }
private:
	Vector<Point> points;
};

Test code (band is member variable of type RubberBand):
void AWindow::LeftDown(Point p, dword keyflags)
{
	band.Clear();
	band.SetMaster(*this);
	band.Run();
	Refresh();
}

void AWindow::Paint(Draw& w)
{
	const Vector<Point> &p = band.GetPoints();
	
	w.DrawRect(GetSize(), SColorFace);
	
	for (int i = 0; i < p.GetCount()-1; i++)
		w.DrawLine(p[i], p[i+1]);
	if (!band.InLoop() && p.GetCount() > 1)
		w.DrawLine(p[p.GetCount()-1], p[0]);
	w.DrawText(4, 4, AsString(p.GetCount()));
}

Hope that helps.

Btw, this is in the wrong forum. General widget forum would have been better.
Re: How to implent a rubber band Class in u++ [message #12353 is a reply to message #12340] Fri, 26 October 2007 04:49 Go to previous messageGo to next message
westcity1973 is currently offline  westcity1973
Messages: 5
Registered: June 2007
Location: China
Promising Member
Thanks, it is very helpful.
Re: How to implent a rubber band Class in u++ [message #16683 is a reply to message #12353] Mon, 07 July 2008 18:35 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Good example!

But how about to optimize this? When I move mouse and it is in loop, need to ADD only the last line draw but do not repaint all? This situation is when change form sizes too! I thing that a way is to set data in a Draw and every time when calls paint return from draw! Is the standard method about this?

Thank you!

[Updated on: Mon, 07 July 2008 18:54]

Report message to a moderator

Re: How to implent a rubber band Class in u++ [message #17030 is a reply to message #16683] Fri, 25 July 2008 20:02 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

How can i copy a draw data to another draw data with position?

for example
Thank you!
Re: How to implent a rubber band Class in u++ [message #17038 is a reply to message #17030] Sat, 26 July 2008 12:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
tojocky wrote on Fri, 25 July 2008 14:02

How can i copy a draw data to another draw data with position?

for example
Thank you!


What is "draw data"?
Re: How to implent a rubber band Class in u++ [message #17047 is a reply to message #17038] Sat, 26 July 2008 16:18 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Sat, 26 July 2008 13:03

tojocky wrote on Fri, 25 July 2008 14:02

How can i copy a draw data to another draw data with position?

for example
Thank you!


What is "draw data"?

Sorry for stupid question! In the documentation is this mechanism! I want to save in the variabile image data and on call Paint method to Draw saved Image! ImageMaker is perfect for me!

[Updated on: Sat, 26 July 2008 16:22]

Report message to a moderator

Re: How to implent a rubber band Class in u++ [message #17048 is a reply to message #17047] Sat, 26 July 2008 16:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Are we speaking about "Drawing"?

Mirek
Re: How to implent a rubber band Class in u++ [message #17062 is a reply to message #17048] Sat, 26 July 2008 22:45 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Sat, 26 July 2008 17:49

Are we speaking about "Drawing"?

Mirek


From Manual point number 6: Image cache
Re: How to implent a rubber band Class in u++ [message #17065 is a reply to message #17048] Sun, 27 July 2008 01:02 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

I tried to optimize this project, but i made this project more slowly and somewhere i have memory leak.
I added in RubberBandClass parameter

Quote:

Drawing resultpaint;

I Tried to buffering image on MouseMove and paste buffered image in method Paint method.

I attached the project!

Help!

[Updated on: Sun, 27 July 2008 01:03]

Report message to a moderator

Re: How to implent a rubber band Class in u++ [message #17162 is a reply to message #17065] Fri, 01 August 2008 08:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
tojocky wrote on Sat, 26 July 2008 19:02

I tried to optimize this project, but i made this project more slowly and somewhere i have memory leak.
I added in RubberBandClass parameter

Quote:

Drawing resultpaint;

I Tried to buffering image on MouseMove and paste buffered image in method Paint method.

I attached the project!

Help!


After fixing apparent bugs, I see no leak.

Anyway, Drawing will not speed this up. It would be more efficient to just add some "DrawRubber" method to your RubberBandClass.

Mirek
Re: How to implent a rubber band Class in u++ [message #17194 is a reply to message #17162] Fri, 01 August 2008 22:33 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

But i see that virtual memory increasing in example wich i modified... but in the preview original example the memory is constant!
Sorry for spent your time! but can you show me in this example?

Thanks!
Re: How to implent a rubber band Class in u++ [message #17202 is a reply to message #17162] Sat, 02 August 2008 09:49 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

I found corrected project in uppdev repository. but virtual memory increasing anyway and speed is slowly!
I uploaded the original project... the virtual memory is constant and faster.
Is the Method DrawingDraw so slowly?
Thanks!
Re: How to implent a rubber band Class in u++ [message #17249 is a reply to message #17162] Mon, 04 August 2008 18:56 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Fri, 01 August 2008 09:53

tojocky wrote on Sat, 26 July 2008 19:02

I tried to optimize this project, but i made this project more slowly and somewhere i have memory leak.
I added in RubberBandClass parameter

Quote:

Drawing resultpaint;

I Tried to buffering image on MouseMove and paste buffered image in method Paint method.

I attached the project!

Help!


After fixing apparent bugs, I see no leak.

Anyway, Drawing will not speed this up. It would be more efficient to just add some "DrawRubber" method to your RubberBandClass.

Mirek

How can I speed up if I will have a lot of points?
Re: How to implent a rubber band Class in u++ [message #17250 is a reply to message #17249] Mon, 04 August 2008 19:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
tojocky wrote on Mon, 04 August 2008 12:56

luzr wrote on Fri, 01 August 2008 09:53

tojocky wrote on Sat, 26 July 2008 19:02

I tried to optimize this project, but i made this project more slowly and somewhere i have memory leak.
I added in RubberBandClass parameter

Quote:

Drawing resultpaint;

I Tried to buffering image on MouseMove and paste buffered image in method Paint method.

I attached the project!

Help!


After fixing apparent bugs, I see no leak.

Anyway, Drawing will not speed this up. It would be more efficient to just add some "DrawRubber" method to your RubberBandClass.

Mirek

How can I speed up if I will have a lot of points?


Let us put it into perspective.

How much points? How slow? How much virtual memory? What computer?

I had patience to create 3000 points band, noticing NO slowdown, VM at 6MB (normal).

(But I must admit I have top-end rig now).

Mirek
Re: How to implent a rubber band Class in u++ [message #17252 is a reply to message #17250] Mon, 04 August 2008 22:33 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Mon, 04 August 2008 20:39



Let us put it into perspective.

How much points? How slow? How much virtual memory? What computer?

I had patience to create 3000 points band, noticing NO slowdown, VM at 6MB (normal).

(But I must admit I have top-end rig now).

Mirek


Sorry,
OS: Windows XP SP3;
Compiler: MSC8 Debug
UPP Version: SVN 318

1. RubberBand, 5000point: The virtual memory increase from 6.8Mb to 7Mb
2. RubberBandFast, 1500 points: The virtual memory increase from 6.8 to 85Mb

The RubberBandFast is more slowly!

[Updated on: Mon, 04 August 2008 22:35]

Report message to a moderator

Re: How to implent a rubber band Class in u++ [message #17281 is a reply to message #17252] Tue, 05 August 2008 15:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
The problem is

iw.DrawDrawing(0, 0, old_size.cx, old_size.cy, resultpaint);

creates very deep recursion in Drawing definition (other drawing within drawin is stored as operation). That results in slow speed and huge VM.

Mirek
Re: How to implent a rubber band Class in u++ [message #17286 is a reply to message #17281] Tue, 05 August 2008 17:37 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Tue, 05 August 2008 16:44

The problem is

iw.DrawDrawing(0, 0, old_size.cx, old_size.cy, resultpaint);

creates very deep recursion in Drawing definition (other drawing within drawin is stored as operation). That results in slow speed and huge VM.

Mirek


What another method will be more faster than DrawDrawing? May be DrawImage?
Re: How to implent a rubber band Class in u++ [message #17291 is a reply to message #17286] Tue, 05 August 2008 19:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
tojocky wrote on Tue, 05 August 2008 11:37

luzr wrote on Tue, 05 August 2008 16:44

The problem is

iw.DrawDrawing(0, 0, old_size.cx, old_size.cy, resultpaint);

creates very deep recursion in Drawing definition (other drawing within drawin is stored as operation). That results in slow speed and huge VM.

Mirek


What another method will be more faster than DrawDrawing? May be DrawImage?


You are limited here by the speed of DrawLine.

Anyway, 3000 points sounds like quite a lot for rubber-band. Maybe you could try to simplifify it a bit?

Mirek
Re: How to implent a rubber band Class in u++ [message #17296 is a reply to message #17291] Wed, 06 August 2008 00:29 Go to previous messageGo to previous message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

luzr wrote on Tue, 05 August 2008 20:54

tojocky wrote on Tue, 05 August 2008 11:37

luzr wrote on Tue, 05 August 2008 16:44

The problem is

iw.DrawDrawing(0, 0, old_size.cx, old_size.cy, resultpaint);

creates very deep recursion in Drawing definition (other drawing within drawin is stored as operation). That results in slow speed and huge VM.

Mirek


What another method will be more faster than DrawDrawing? May be DrawImage?


You are limited here by the speed of DrawLine.

Anyway, 3000 points sounds like quite a lot for rubber-band. Maybe you could try to simplifify it a bit?

Mirek


I want to understand how can I optimized in drawing and to use in future! In future I can have a control that Paint will have more operations and will be more optimized to save image and set it in Paint method.

[Updated on: Wed, 06 August 2008 00:31]

Report message to a moderator

Previous Topic: FileList problems with extensions and pop-ups
Next Topic: How to turn off special chars in RichEdit?
Goto Forum:
  


Current Time: Sun Apr 28 01:47:26 CEST 2024

Total time taken to generate the page: 2.93001 seconds