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 » Community » Newbie corner » How to Draw without overriding Paint?
How to Draw without overriding Paint? [message #38810] Sun, 20 January 2013 00:01 Go to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Is it possible to call functions like DrawLine outside of the Paint method?

For example after the TopWindow is already running, I want to call DrawLine at the click of a button.

Thanks
Re: How to Draw without overriding Paint? [message #38817 is a reply to message #38810] Sun, 20 January 2013 10:25 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

lectus wrote on Sun, 20 January 2013 00:01

Is it possible to call functions like DrawLine outside of the Paint method?

For example after the TopWindow is already running, I want to call DrawLine at the click of a button.

Thanks

Hi lectus,
Simplest way to do this is to have Image member in your class and draw in it using ImageDraw on the user action. Then, when Painting, just paint the image on the screen. Simple example for this:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct App : TopWindow {
	Image img;

	virtual void Paint(Draw& w) {
		w.DrawImage(0, 0, img);
	}

	virtual void LeftDown(Point p, dword keyflags){
		//draw a circle on mouse click
		int r = Random(200);
		RGBA c = Color(Random(255),Random(255),Random(255));
		ImageDraw w(GetSize());
		w.DrawRect(GetSize(), SBlack());
		w.DrawEllipse(p.x-r/2, p.y-r/2, r, r, c);
		img = w;
		Refresh();
	}

	App() {
		Size sz(400,400);
		SetRect(0,0,sz.cx,sz.cy);
		ImageDraw w(sz);
		w.DrawRect(sz, SBlack());
		img = w;
	}
};

GUI_APP_MAIN
{
	App().Run();
}



Another way to do this is to store the info of the user action and than paint do the drawing i Paint based on this info. For example of this have a look a examples/Scribble.


Best regards,
Honza

Re: How to Draw without overriding Paint? [message #38819 is a reply to message #38817] Sun, 20 January 2013 14:15 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Thank you!
It works!

Let's see if I got the logic right:

1) You create a Image object as member of the class so it lasts while TopWindow lasts.

2) You draw this Image object on Paint reserving its position.

3) On any event, like the click of the button you use ImageDraw to draw anything and finally you assign it to the Image object to show it on the screen, and finally call Refresh() to update the window.
Re: How to Draw without overriding Paint? [message #38820 is a reply to message #38819] Sun, 20 January 2013 15:37 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

lectus wrote on Sun, 20 January 2013 14:15

Thank you!
It works!

Let's see if I got the logic right:

1) You create a Image object as member of the class so it lasts while TopWindow lasts.

2) You draw this Image object on Paint reserving its position.

3) On any event, like the click of the button you use ImageDraw to draw anything and finally you assign it to the Image object to show it on the screen, and finally call Refresh() to update the window.

Yes, just like that Smile
Previous Topic: How can I select multiple directory/folders using FileSel?
Next Topic: Separate Database Access code
Goto Forum:
  


Current Time: Thu Mar 28 12:24:51 CET 2024

Total time taken to generate the page: 0.01022 seconds