Author Topic: PCL: mouse is wiping out my line  (Read 5459 times)

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
PCL: mouse is wiping out my line
« on: 2009 May 06 07:11:15 »

Hi,

I'm drawing the profile line now as the mouse is being moved so that's pretty cool. Now the problem is that the line is being wiped out when I move the cursor over the line. Shouldn't I get draw events to tell me I need to redraw the line? Actually I'd rather have PI redraw the bitmap after the cursor wipes it but I imagine I have to do this myself, right?
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: mouse is wiping out my line
« Reply #1 on: 2009 May 08 08:30:47 »
Hi Juan, when you get a chance, can you look at this please?
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL: mouse is wiping out my line
« Reply #2 on: 2009 May 08 11:58:56 »
OK, here we go.

PixInsight doesn't update dynamically generated graphics automatically. That's the sole responsibility of the dynamic interface.

In your DynamicPaint routine, you must be prepared to update your line if the passed update rectangle intersects it. For example:

Code: [Select]
bool MyInterface::RequiresDynamicUpdate( const View& v, const DRect& updateRect ) const
{
   // myView is a View* that is the view where you're working (you normally
   // have fetched it upon a DynamicMousePress() call, when a new dynamic
   // session started. myView should be zero if no dynamic session is taking
   // place (for safety).
   // myRect is a DRect object that defines the current boundaries of your
   // drawing in image coordinates.

   return myView != 0 && v == *myView && myRect.Intersects( updateRect );
}

void MyInterface::DynamicPaint( const View& v, Graphics& g, const DRect& updateRect  ) const
{
   // Perform the drawing work. If possible, restrict and/or optimize your painting
   // routine to draw only into the updateRect rectangle.
}

Bear in mind that the passed updateRect objects are in image coordinates. Image coordinates are always real numbers (of double type). Take into account also that the updateRect can define coordinates outside the image in the passed view v. This may happen if for example the user has zoomed out the image so it doesn't cover the current v's viewport.

Also take into account that these functions will be called very frequently. For example, as soon as the user moves the cursor over a view, PI will call your routines. First it will call your RequiresDynamicUpdate(). If that routine returns false, your DynamicPaint() won't be called. This greatly improves efficiency.

Finally, as you see, in PixInsight *all* drawing must take place inside paint event handlers. No drawing is possible if it has not been solicited explicitly by the core application. This is essential to ensure portability across platforms.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PCL: mouse is wiping out my line
« Reply #3 on: 2009 May 08 12:25:18 »
Hi Juan,

ok then I'm probably close. Right now I have a very lenient RequiresDynamicUpdate routine:

Code: [Select]
bool ProfileInterface::RequiresDynamicUpdate( const View& v, const DRect& r ) const
{
return (pStart.x != 0 || pStart.y != 0 || pEnd.x != 0 || pEnd.y != 0);
}

So in effect my DynamicPaint routine gets called all the time as long as I have a start and end point for my profile line. I verified the DynamicPaint routine indeed gets called. It's just that somehow it's not redrawing the line correctly. It draws it fine when the entire window gets refreshed or when I'm dragging the line. So I'm probably mistranslating image coordinates to view port coordinates somewhere. Alright, I know where to look now. Thanks!
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PCL: mouse is wiping out my line
« Reply #4 on: 2009 May 08 12:48:57 »
Just an additional tip. Take into account that since image coordiantes are floating point numbers and viewport coordinates are integers, there can be some rounding errors that may affect your update rectangles after coordinate transformations. For example, this is part of DynamicCrop:

Code: [Select]
// Obtain the half-size of center marks in image coordinates
double dr = v.Window().ViewportScalarToImage( centerSz+1 ); // add 1 pixel to guard against roundoff errors

where centerSz is the radius in pixels of the cropping rectangle's center mark. Without adding 1 to centerSz, the transformation to image coordinates yields a too small dr value sometimes, and when that happens the center mark isn't updated correctly (it gets wiped out, as happens to your line :)).
Juan Conejero
PixInsight Development Team
http://pixinsight.com/