*ScatterCtrl: Added limit checking

git-svn-id: svn://ultimatepp.org/upp/trunk@6284 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2013-08-28 20:18:58 +00:00
parent ca7e60660f
commit d0b5c2f074
3 changed files with 46 additions and 31 deletions

View file

@ -58,7 +58,16 @@ void ScatterCtrl::SaveToClipboard(bool)
void ScatterCtrl::Paint(Draw& w)
{
if (IsNull(highlight_0) && highlighting) {
highlighting = false;
KillTimeCallback();
}
if (!IsNull(highlight_0) && !highlighting) {
highlighting = true;
SetTimeCallback(-200, THISBACK(TimerCallback));
}
TimeStop t;
lastRefresh0_ms = GetTickCount();
if (mode == MD_DRAW) {
ScatterCtrl::SetDrawing(w, GetSize(), 1);
PlotTexts(w, GetSize(), 1);
@ -74,6 +83,10 @@ void ScatterCtrl::Paint(Draw& w)
lastRefresh_ms = t.Elapsed();
}
void ScatterCtrl::TimerCallback() {
Refresh();
}
void ScatterCtrl::ProcessPopUp(const Point & pt)
{
double _x = (popLT.x - hPlotLeft)*xRange/(GetSize().cx - (hPlotLeft + hPlotRight)-1) + xMin;
@ -288,35 +301,17 @@ void ScatterCtrl::MouseWheel(Point pt, int zdelta, dword keyFlags)
void ScatterCtrl::MouseMove(Point pt, dword)
{
if (isScrolling) {
double factorX = 0, factorY = 0;
int shiftX = pt.x - butDownX;
if (mouseHandlingX && shiftX != 0) {
double factorX = double(shiftX)/(GetSize().cx - (hPlotLeft + hPlotRight) - 1);
double deltaX = factorX*xRange;
xMin -= deltaX;
xMinUnit += deltaX;
AdjustMinUnitX();
butDownX = pt.x;
}
if (mouseHandlingX && shiftX != 0)
factorX = double(shiftX)/(GetSize().cx - (hPlotLeft + hPlotRight) - 1);
int shiftY = pt.y - butDownY;
if (mouseHandlingY && shiftY != 0) {
double factorY = double(shiftY)/(GetSize().cy - (vPlotTop + vPlotBottom) - 1);
double deltaY = -factorY*yRange;
yMin -= deltaY;
yMinUnit += deltaY;
AdjustMinUnitY();
if (drawY2Reticle) {
double deltaY2 = -factorY*yRange2;
yMin2 -= deltaY2;
yMinUnit2 += deltaY2;
AdjustMinUnitY2();
}
butDownY = pt.y;
}
if ((mouseHandlingX && shiftX != 0) || (mouseHandlingY && shiftY != 0)) {
WhenSetXYMin();
Refresh();
WhenZoomScroll();
}
if (mouseHandlingY && shiftY != 0)
factorY = double(shiftY)/(GetSize().cy - (vPlotTop + vPlotBottom) - 1);
butDownX = pt.x;
butDownY = pt.y;
if ((mouseHandlingX && shiftX != 0) || (mouseHandlingY && shiftY != 0))
ScatterDraw::Scroll(factorX, -factorY);
}
if(isLabelPopUp) {
if (paintInfo && hPlotLeft <= pt.x && pt.x <= GetSize().cx - hPlotRight &&
@ -341,7 +336,15 @@ void ScatterCtrl::MouseLeave()
void ScatterCtrl::MouseZoom(int zdelta, bool hor, bool ver)
{
double scale = zdelta > 0 ? zdelta/100. : -100./zdelta;
if (((lastxRange < xRange*scale) || (lastyRange < yRange*scale)) && (lastRefresh_ms > maxRefresh_ms))
// if (hor && (lastxRange < xRange*scale))
// return;
// if (ver && (lastyRange < yRange*scale))
// return;
if (lastRefresh_sign != ((scale >= 0) ? 1 : -1))
lastRefresh_ms = Null; // Change of scale sign resets lastRefresh check
if (GetTickCount() - lastRefresh0_ms > 1000)
lastRefresh_ms = Null; // 1 sec resets lastRefresh check
if (!IsNull(lastRefresh_ms) && (lastRefresh_ms > maxRefresh_ms))
return;
Zoom(scale, mouseHandlingX, mouseHandlingY);
}
@ -366,8 +369,8 @@ void ScatterCtrl::ContextMenu(Bar& bar)
bar.Add(t_("Fit to data"), ScatterImg::ShapeHandles(), THISBACK1(FitToData, mouseHandlingY));
bar.Add(t_("Zoom +"), ScatterImg::ZoomPlus(), THISBACK3(Zoom, 1/1.2, true, mouseHandlingY));
bar.Add(t_("Zoom -"), ScatterImg::ZoomMinus(), THISBACK3(Zoom, 1.2, true, mouseHandlingY));
bar.Add(t_("Scroll Left"), ScatterImg::LeftArrow(), THISBACK2(ScatterDraw::Scroll, -0.2, 0));
bar.Add(t_("Scroll Right"), ScatterImg::RightArrow(), THISBACK2(ScatterDraw::Scroll, 0.2, 0));
bar.Add(t_("Scroll Left"), ScatterImg::LeftArrow(), THISBACK2(ScatterDraw::Scroll, 0.2, 0));
bar.Add(t_("Scroll Right"), ScatterImg::RightArrow(), THISBACK2(ScatterDraw::Scroll, -0.2, 0));
if (mouseHandlingY) {
bar.Add(t_("Scroll Up"), ScatterImg::UpArrow(), THISBACK2(ScatterDraw::Scroll, 0, -0.2));
bar.Add(t_("Scroll Down"), ScatterImg::DownArrow(), THISBACK2(ScatterDraw::Scroll, 0, 0.2));
@ -435,6 +438,7 @@ ScatterCtrl::ScatterCtrl() : offset(10,12), copyRatio(1)
SetMouseBehavior(defaultMouse);
lastRefresh_ms = Null;
maxRefresh_ms = 500;
highlighting = false;
}
END_UPP_NAMESPACE

View file

@ -191,8 +191,11 @@ private:
bool showPropDlg;
int lastRefresh_ms;
dword lastRefresh0_ms;
int maxRefresh_ms;
bool highlighting;
MouseBehaviour *mouseBehavior;
void ProcessPopUp(const Point & pt);
@ -220,7 +223,8 @@ private:
virtual Image CursorImage(Point p, dword keyflags);
template <class T>
void SetDrawing(T& w, const Size &size, int scale);
void SetDrawing(T& w, const Size &size, int scale);
void TimerCallback();
};
template <class T>

View file

@ -1200,6 +1200,13 @@ in ScatterCtrl.&]
or].&]
[s1; &]
[s6;%- &]
[s5;:ScatterCtrl`:`:SetMouseHandling`(bool`,bool`):%- [_^ScatterCtrl^ ScatterCtrl][@(0.0.255) `&
]_[* SetMouseHandling]([@(0.0.255) bool]_[*@3 valx]_`=_[@(0.0.255) true],
[@(0.0.255) bool]_[*@3 valy]_`=_[@(0.0.255) false])&]
[s3; If [%-*@3 valx] mouse can scroll or zoom in X axis.&]
[s3; If [%-*@3 valy] mouse can scroll or zoom in Y axis.&]
[s1; &]
[s6;%- &]
[s5;:ScatterCtrl`:`:ShowContextMenu`(bool`):%- [_^ScatterCtrl^ ScatterCtrl][@(0.0.255) `&
]_[* ShowContextMenu]([@(0.0.255) bool]_[*@3 show]_`=_[@(0.0.255) true])&]
[s3; If [%-*@3 show] is true the context menu can be opened (right