Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#6 avoiding unintended zooming with [code][/code]

open
nobody
None
5
2010-03-30
2010-03-30
dlchnr
No

I've had a problem with unintended corrupted zooming described here:
http://wxforum.shadonet.com/viewtopic.php?t=27381
To avoid this problem, I've patched wxMathPlot.

- added lines in "mathplot.h":

[code]
#include <limits> // added (dlchnr)
// "Not a Number" for mouse position // added (dlchnr)
#define NaN_MOUSEPOS std::numeric_limits<int>::min() // added (dlchnr)
// square of minimum size of diagnal of zoom selection // added (dlchnr)
#define SQUARE_MIN_SIZE_ZOOM_SELECTION 256 // added (dlchnr)
[/code]

- added/changed lines in mathplot.cpp:

-- added in mpWindow::mpWindow(..) constructor:
[code]
m_mouseLClick_X = m_mouseLClick_Y = NaN_MOUSEPOS; // added (dlchnr)
[/code]

-- added/changed in mpWindow::OnMouseLeftRelease handler:
[code]
void mpWindow::OnMouseLeftRelease (wxMouseEvent &event)
{
wxPoint release(event.GetX(), event.GetY());
wxPoint press(m_mouseLClick_X, m_mouseLClick_Y);
wxPoint NaN_MPos(NaN_MOUSEPOS, NaN_MOUSEPOS); // added (dlchnr)
if (press != NaN_MPos) { // added (dlchnr)
// prevents unintentional zooming, when OnMouseLeftDown // added (dlchr)
// has been catched by another window // added (dlchnr)
if (m_movingInfoLayer != NULL) {
m_movingInfoLayer->UpdateReference();
m_movingInfoLayer = NULL;
} else {
if (release != press) { // added (dlchnr)
wxPoint diag(release - press); // added (dlchnr)
int sqdiag = diag.x * diag.x + diag.y * diag.y; // added (dlchnr)
if (sqdiag > SQUARE_MIN_SIZE_ZOOM_SELECTION) // added (dlchnr)
// prevents unintentional zooming // added (dlchnr)
ZoomRect(press, release);
} /*else {
if (m_coordTooltip) {
wxString toolTipContent;
toolTipContent.Printf(_("X = %f\nY = %f"), p2x(event.GetX()), p2y(event.GetY()));
SetToolTip(toolTipContent);
}
} */
}
} // added (dlchnr)
m_mouseLClick_X = m_mouseLClick_Y = NaN_MOUSEPOS; // added (dlchnr)
event.Skip();
}
[/code]

Discussion