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 » Draw, Display, Images, Bitmaps, Icons » Painter and viewports
Painter and viewports [message #43961] Sat, 29 November 2014 12:30 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hi, I'm using painter to draw inside a big working area, let's say of 20'000 (millimeters)
size, given by a rectangle from (-10000, -10000) to (10000, 10000).
To do this, I write:

PaintingPainter sw(20000, 20000);
sw.Translate(-10000, -10000);


I guess it's correct.
Now I want to take a viewport of my big area and display it inside a control, like
following picture:

index.php?t=getfile&id=4673&private=0

Viewport is given by its origin and a zoom/scale factor.
I can't find a way to do it....
Re: Painter and viewports [message #43964 is a reply to message #43961] Mon, 01 December 2014 20:07 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Massimo,

I think Painter and Drawing has all you need.
You don't need to create PaintingPainter sw(20000, 20000); with such a big size.
All you need to do is:

PaintingPainter sw(viewPortXsize, viewPortYsize);
sw.Offset(viewportOrigin);
.... paint you're data
sw.end();

Ideally you may not even need to allocate a PaintingPainter ==> if Draw interface is sufficient you can reuse the draw instance of the control passed to ViewportCtrl::Paint()

If you really need to use painter, I use the following code (or something close to it), look at GraphDraw::Paint() method (in svn repo).
ViewportCtrl::Paint(Draw& w) {
	ImageBuffer ib( Size() ); // Ctrl size
	Upp::Fill( ib.Begin(), bckgColor, ib.GetLength() ); // if you use transparent colors, you will need this
	BufferPainter bp(ib, drawMode);
	bp.Offset(viewportOrigin);
	.... paint you're data
	sw.end();
	DrawImage(0, 0, bp);
}


In fact, the data is first drawn to an image (using painter) and then the image is draw to the Ctrl
Not very efficient, but I don't know a better way to achieve this when you use Painter.

Re: Painter and viewports [message #43965 is a reply to message #43964] Mon, 01 December 2014 22:03 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hi Didier,

thank you for answer.

I use Painter because I need to work in floating point units, scale and so on,
and I don't want to replicate all that stuff Wink
Btw, I use a big painting area because I just do drawing regens when I modify it,
then I "move" the viewport over it to pan/zoom, so I spare some graphic calculations.

I found a solution, anyways.
Now I've got the problem of transparency.

I need to paint 2 transparent drawings over a background, i.e.:

	// create an imagebuffer to paint inside
	ImageBuffer ib(sz);
	
	// place it on requested viewport
	BufferPainter bp(ib);
	bp.Scale(scale, scale);
	bp.Translate(-x1 - WORK_AREA / 2, -y1 + WORK_AREA / 2);
	
	// paint work area
	INTERLOCKED_(doc->RegenMutex()) {
		One<PaintingPainter> &workArea = doc->GetWorkArea();
		if(!workArea.IsEmpty())
			bp.Paint(*workArea);
	}

	// paint overlayer
	bp.Paint(*doc->GetOverlayArea());
	
	// display it
	w.DrawImage(0, 0, ib);


workArea and overlayArea are both cleared with RGBAZero() color.
But when I paint on bp object (which has a white background...) I get garbage.
If I clear the painters with a color, all is ok, but I loose the overlay stuff.
Re: Painter and viewports [message #43966 is a reply to message #43965] Mon, 01 December 2014 23:34 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
I think what is missing is :
// create an imagebuffer to paint inside
	ImageBuffer ib(sz);
	Upp::Fill( ib.Begin(), bckgColor, ib.GetLength() );   // ************ if the ImageBuffer is not filled, transparency gives garbage
	// place it on requested viewport
	BufferPainter bp(ib);


I stumbled accross the same problems when trying to use transparency in background with GraphCtrl (took me some time to figure it out ... and also needed an Upp bug correction)
Re: Painter and viewports [message #43971 is a reply to message #43966] Tue, 02 December 2014 08:27 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hi,

I solved (ugly) painting on bp an empty, non-transparent painter filled with background color just before
painting the 2 layers on it. It works.... but I don't like very much that solution.
Re: Painter and viewports [message #43972 is a reply to message #43971] Tue, 02 December 2014 19:13 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Massimo,

backgroundColor can be transparent.
The need for this is that the BP memory contains random data if you don't initialize it.
So when using transparency ... problems start appearing since then the random data gets involved in final result Sad

I don't see any other solution
Previous Topic: Should RGBA have got 4 arguments constructor?
Next Topic: Simplest way to add jpg or png to a layout, for logos, image visble off/on for status, etc.
Goto Forum:
  


Current Time: Fri Mar 29 01:40:53 CET 2024

Total time taken to generate the page: 0.01531 seconds