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 » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Canvas widget created (Callbacks are great:-)
Canvas widget created (Callbacks are great:-) [message #4762] Mon, 21 August 2006 21:38 Go to next message
ren42 is currently offline  ren42
Messages: 12
Registered: July 2006
Promising Member
Hi everybody,
while I'm coding my private app, I missed an useful way to paint
in a rectangular area. So I decided to develop a canvas class
derived from Ctrl to get what i want. I worked since 7 weeks with
UPP and I think it's time to give something back, because UPP is
the best c++IDE I've ever seen. And I try a lot of IDE's Smile
The Attachment include a complete Example. Simply copy it to your
MyApps Nest, create a new Package "uppCanvas" and hit Ctrl-F5.

And now some more Infos:

Canvas provides an easy way to draw on rectangular
area embedded in a parentcontrol of your choice e.g. a StaticRect(so far I tested). But how is it possible to receive mouseclicks or to
paint on Canvas without altering or override the virtual methods in a child class of Canvas? The solution are Callbacks.
Consider a callback as a pointer to a method of Canvas called from another place (the parent window).
In order to draw on the Canvas the parent window must provide and assign methods with matching signaturs to the Callbacks of
Canvas. e.g.:
//Declaration
struct App : public TopWindow{
	typedef App CLASSNAME; //Needed by THISBACK macro
	Canvas canvas;	       //Prepair your brushes
	
	App();
	//Same signatur as canvas.paint(Draw& w)
	void OnCanvasPaint(Draw& w); //Want to paint on canvas
	//Paint on Click see below
	void OnCanvasMouseLeft(Point p, dword keyflags);
};

//Definition
App::App(){
	.
	.
	// The magic assignment:-)
	canvas.OnCanvasPaint=THISBACK(OnCanvasPaint);
	// The left mousebutton click is now routed to the canvas 
	canvas.OnMouseLeft=THISBACK(OnCanvasMouseLeft);
}  

void App::OnCanvasPaint(Draw& w)
{// Your paintings on Canvas goes here:
  Rect r=canvas.GetSize();
 // Draw a Line
  w.DrawLine(0,0,r.Width(),r.height(),1,Black());
}
/*
And not still enough, Canvas offers a way to paint not only
in a Paint Callback. For this purpose you can use the DrawSheet()
function. To make it short here is an Example:
*/
void App::OnCanvasMouseLeft(Point p, dword keyflags)
{ //Paint an ugly ellipse:-)
  Rect r=canvas.GetSize();
  DrawingDraw& ds=canvas.DrawSheet(); 
  ds.DrawEllipse(p.x,p.y,20,20,Red(),5,Green());
  canvas.EndSheet();//draw it now
}

Consider the Drawsheet as an additional paintlayer you can paint at.
Look at main.cpp to see it all together:-)
Happy coding...

  • Attachment: uppCanvas.rar
    (Size: 4.59KB, Downloaded 6061 times)
Re: Canvas widget created (Callbacks are great:-) [message #4764 is a reply to message #4762] Mon, 21 August 2006 22:11 Go to previous messageGo to next message
ren42 is currently offline  ren42
Messages: 12
Registered: July 2006
Promising Member
Hi, I made a mistake, sorry

Quote:


Simply copy it to your
MyApps Nest, create a new Package "uppCanvas" and hit Ctrl-F5.


Simply copy it to your MyApps Nest is ok.
You need not to create a new Package. If you Select main Package
click the option "All Packages" and the Package uppCanvas will
appear.

ren
Re: Canvas widget created (Callbacks are great:-) [message #4766 is a reply to message #4764] Tue, 22 August 2006 00:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
Nice Drawing/DrawingDraw example Smile

Mirek
Re: Canvas widget created (Callbacks are great:-) [message #4786 is a reply to message #4762] Tue, 22 August 2006 12:05 Go to previous message
ren42 is currently offline  ren42
Messages: 12
Registered: July 2006
Promising Member

Quote:

Nice Drawing/DrawingDraw example Smile


Thanks a lot Smile

I will develop it further in the next 1 or 2 weeks. I think of
scrollbars, more callbacks of course, and maybe multiple Layers.

Happy coding, ren
Previous Topic: LinkCtrl
Next Topic: ParentCtrl
Goto Forum:
  


Current Time: Sat Feb 16 16:35:47 CET 2019

Total time taken to generate the page: 0.00551 seconds