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?
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 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 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

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: How can I select multiple directory/folders using FileSel?
Next Topic: Separate Database Access code
Goto Forum:
  


Current Time: Mon May 06 14:38:01 CEST 2024

Total time taken to generate the page: 0.01913 seconds