"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "uppsrc/ScatterCtrl/ScatterCtrl.cpp" between
upp-x11-src-13648.tar.gz and upp-x11-src-13659.tar.gz

About: Ultimate++ is a C++ cross-platform rapid application development framework. Stable release.

ScatterCtrl.cpp  (upp-x11-src-13648):ScatterCtrl.cpp  (upp-x11-src-13659)
#include "ScatterCtrl.h" #include "ScatterCtrl.h"
#define IMAGECLASS ScatterImg #define IMAGECLASS ScatterImg
#define IMAGEFILE <ScatterCtrl/ScatterCtrl.iml> #define IMAGEFILE <ScatterCtrl/ScatterCtrl.iml>
#include <Draw/iml.h> #include <Draw/iml.h>
#define TFILE <ScatterCtrl/ScatterCtrl.t> #define TFILE <ScatterCtrl/ScatterCtrl.t>
#include <Core/t.h> #include <Core/t.h>
Vector<ScatterCtrl *> ScatterCtrl::instances;
#ifdef PLATFORM_WIN32 #ifdef PLATFORM_WIN32
void ScatterCtrl::SaveAsMetafile(const char* file) void ScatterCtrl::SaveAsMetafile(const char* file)
{ {
GuiLock __; GuiLock __;
WinMetaFileDraw wmfd; WinMetaFileDraw wmfd;
wmfd.Create(saveSize.cx, saveSize.cy, "ScatterCtrl", "chart", file); wmfd.Create(saveSize.cx, saveSize.cy, "ScatterCtrl", "chart", file);
ScatterDraw::SetSize(saveSize); ScatterDraw::SetSize(saveSize);
ScatterDraw::SetDrawing<Draw>(wmfd); ScatterDraw::SetDrawing<Draw>(wmfd);
wmfd.Close(); wmfd.Close();
skipping to change at line 196 skipping to change at line 198
if (!StoreAsXMLFile(*this, fileName)) if (!StoreAsXMLFile(*this, fileName))
Exclamation(t_("Plot has not been saved")); Exclamation(t_("Plot has not been saved"));
} else if (GetFileExt(fileName) == ".bin") { } else if (GetFileExt(fileName) == ".bin") {
if (!StoreToFile(*this, fileName)) if (!StoreToFile(*this, fileName))
Exclamation(t_("Plot has not been saved")); Exclamation(t_("Plot has not been saved"));
} else } else
Exclamation(Format(t_("File format \"%s\" not found"), GetFileExt (fileName))); Exclamation(Format(t_("File format \"%s\" not found"), GetFileExt (fileName)));
} }
void ScatterCtrl::Paint0(Draw& w, const Size &sz) { void ScatterCtrl::Paint0(Draw& w, const Size &sz) {
GuiLock __;
if (IsNull(highlight_0) && highlighting) { if (IsNull(highlight_0) && highlighting) {
highlighting = false; highlighting = false;
KillTimeCallback(); KillTimeCallback();
} }
if (!IsNull(highlight_0) && !highlighting) { if (!IsNull(highlight_0) && !highlighting) {
highlighting = true; highlighting = true;
SetTimeCallback(-200, THISBACK(TimerCallback)); SetTimeCallback(-200, THISBACK(TimerCallback));
} }
TimeStop t; TimeStop t;
lastRefresh0_ms = GetTickCount(); lastRefresh0_ms = GetTickCount();
skipping to change at line 235 skipping to change at line 236
delta = 0; delta = 0;
#endif #endif
w.DrawLine(sz.cx+delta, 0, sz.cx+delta, sz.cy, 2, LtGray( )); w.DrawLine(sz.cx+delta, 0, sz.cx+delta, sz.cy, 2, LtGray( ));
w.DrawLine(0, sz.cy+delta, sz.cx, sz.cy+delta, 2, LtGray( )); w.DrawLine(0, sz.cy+delta, sz.cx, sz.cy+delta, 2, LtGray( ));
} }
} }
lastRefresh_ms = t.Elapsed(); lastRefresh_ms = t.Elapsed();
} }
void ScatterCtrl::Paint(Draw& w) { void ScatterCtrl::Paint(Draw& w) {
GuiLock __;
if (rotate == Angle_0) if (rotate == Angle_0)
Paint0(w, GetSize()); Paint0(w, GetSize());
else if (rotate == Angle_90) { else if (rotate == Angle_90) {
Size sz(GetSize().cy, GetSize().cx); Size sz(GetSize().cy, GetSize().cx);
ImageDraw dw(sz); ImageDraw dw(sz);
Paint0(dw, sz); Paint0(dw, sz);
w.DrawImage(0, 0, GetSize().cx, GetSize().cy, RotateClockwise(dw) ); w.DrawImage(0, 0, GetSize().cx, GetSize().cy, RotateClockwise(dw) );
} else if (rotate == Angle_270) { } else if (rotate == Angle_270) {
Size sz(GetSize().cy, GetSize().cx); Size sz(GetSize().cy, GetSize().cx);
ImageDraw dw(sz); ImageDraw dw(sz);
skipping to change at line 259 skipping to change at line 262
ImageDraw dw(sz); ImageDraw dw(sz);
Paint0(dw, sz); Paint0(dw, sz);
w.DrawImage(0, 0, GetSize().cx, GetSize().cy, Rotate180(dw)); w.DrawImage(0, 0, GetSize().cx, GetSize().cy, Rotate180(dw));
} }
} }
void ScatterCtrl::TimerCallback() { void ScatterCtrl::TimerCallback() {
Refresh(); Refresh();
} }
void ScatterCtrl::ProcessPopUp(const Point &pt) void ScatterCtrl::Closest(double &x, double &y, double &y2) {
{ double minD = DBL_MAX;
double retx, rety, rety2;
for (int i = 0; i < series.GetCount(); ++i) {
ScatterSeries &serie = series[i];
if (serie.IsDeleted() || serie.opacity == 0 || serie.Data().IsExp
licit())
continue;
DataSource &data = serie.Data();
double d;
int64 id;
if (serie.primaryY) {
id = data.Closest(x, y);
d = GetScatterDistance(x - data.x(id), y - data.y(id));
} else {
id = data.Closest(x, y);
d = GetScatterDistance2(x - data.x(id), y - data.y(id));
}
if (minD > d) {
minD = d;
retx = data.x(id);
if (serie.primaryY) {
rety = data.y(id);
rety2 = GetRealPosY2(GetScatterPosY(data.y(id)));
} else {
rety2 = data.y(id);
rety = GetRealPosY(GetScatterPosY2(data.y(id)));
}
}
}
if (minD == DBL_MAX)
x = y = y2 = Null;
else {
x = retx;
y = rety;
y2 = rety2;
}
}
void ScatterCtrl::ProcessPopUp(Point &pt) {
double _x = GetRealPosX(popLT.x); double _x = GetRealPosX(popLT.x);
double _y = GetRealPosY(popLT.y); double _y = GetRealPosY(popLT.y);
double _y2 = GetRealPosY2(popLT.y); double _y2 = GetRealPosY2(popLT.y);
double x = GetRealPosX(pt.x); double x = GetRealPosX(pt.x);
double y = GetRealPosY(pt.y); double y = GetRealPosY(pt.y);
double y2 = GetRealPosY2(pt.y); double y2 = GetRealPosY2(pt.y);
if (IsNull(popLT))
popLT = pt;
popRB = pt;
double dx = fabs(x - _x); double dx = fabs(x - _x);
double dy = fabs(y - _y); double dy = fabs(y - _y);
double dy2 = fabs(y2 - _y2); double dy2 = fabs(y2 - _y2);
String strx, _strx, dstrx, stry, _stry, dstry; String strx, _strx, dstrx, stry, _stry, dstry;
if (cbModifFormatX) { if (cbModifFormatX) {
cbModifFormatX(strx, 0, x); cbModifFormatX(strx, 0, x);
strx.Replace("\n", " "); strx.Replace("\n", " ");
cbModifFormatX(_strx, 0, _x); cbModifFormatX(_strx, 0, _x);
_strx.Replace("\n", " "); _strx.Replace("\n", " ");
skipping to change at line 382 skipping to change at line 427
popTextVert.Move(this, MousePointUnrot(p3)); popTextVert.Move(this, MousePointUnrot(p3));
} else } else
popTextVert.Hide(); popTextVert.Hide();
if (!str.IsEmpty()) { if (!str.IsEmpty()) {
popTextEnd.Show(); popTextEnd.Show();
popTextEnd.SetText(str).Move(this, MousePointUnrot(popPoint)); popTextEnd.SetText(str).Move(this, MousePointUnrot(popPoint));
} else } else
popTextEnd.Hide(); popTextEnd.Hide();
} }
/*void ScatterCtrl::ProcessClickSeries(const Point &pt)
{
double posx = GetRealPosX(pt.x);
double posy = GetRealPosY(pt.y);
double dx = 2*GetPixelThickX();
double dy = 2*GetPixelThickY();
}*/
void ScatterCtrl::DoMouseAction(bool down, Point pt, ScatterAction action, int w heel) void ScatterCtrl::DoMouseAction(bool down, Point pt, ScatterAction action, int w heel)
{ {
if (!down) { if (!down) {
Scrolling(false, pt); Scrolling(false, pt);
LabelPopUp(false, pt); LabelPopUp(false, pt);
ZoomWindow(false, pt); ZoomWindow(false, pt);
} }
switch (action) { switch (action) {
case SCROLL: Scrolling(down, pt); case SCROLL: Scrolling(down, pt);
break; break;
skipping to change at line 522 skipping to change at line 559
bool processed = false; bool processed = false;
for (int i = 0; i < keyBehavior.GetCount(); ++i) { for (int i = 0; i < keyBehavior.GetCount(); ++i) {
if (keyBehavior[i].ctrl == ctrl && keyBehavior[i].alt == alt && keyBehavior[i].shift == shift && keyBehavior[i].key == key) { if (keyBehavior[i].ctrl == ctrl && keyBehavior[i].alt == alt && keyBehavior[i].shift == shift && keyBehavior[i].key == key) {
processed = true; processed = true;
DoKeyAction(keyBehavior[i].action); DoKeyAction(keyBehavior[i].action);
} }
} }
return processed; return processed;
} }
void ScatterCtrl::LabelPopUp(bool down, Point &pt) void ScatterCtrl::LabelPopUp(bool down, Point &pt) {
{ GuiLock __;
if (down) { if (down) {
if(showInfo && PointInPlot(pt)) { if(showInfo && PointInPlot(pt)) {
popTextBegin.AppearOnly(this); popTextBegin.AppearOnly(this);
popTextVert.AppearOnly(this); popTextVert.AppearOnly(this);
popTextHoriz.AppearOnly(this); popTextHoriz.AppearOnly(this);
popTextEnd.AppearOnly(this); popTextEnd.AppearOnly(this);
isLabelPopUp = true; isLabelPopUp = true;
if (IsNull(popLT))
popLT = pt;
popRB = pt;
/*Rect wa = GetWorkArea();
Rect rc = GetScreenRect();
if (wa.right - (rc.left + pt.x) < 200)
pt.x -= 200;
if (wa.bottom - (rc.top + pt.y) < 200)
pt.y -= 200;*/
//ProcessClickSeries(pt); TBD
ProcessPopUp(pt); ProcessPopUp(pt);
} }
} else { } else {
if(showInfo && isLabelPopUp) { if(showInfo && isLabelPopUp) {
popTextBegin.Close(); popTextBegin.Close();
popTextVert.Close(); popTextVert.Close();
popTextHoriz.Close(); popTextHoriz.Close();
popTextEnd.Close(); popTextEnd.Close();
isLabelPopUp = isZoomWindow = false; isLabelPopUp = isZoomWindow = false;
popLT = popRB = Null; popLT = popRB = Null;
Refresh(); Refresh();
} }
} }
} }
void ScatterCtrl::ZoomWindow(bool down, Point &pt) void ScatterCtrl::ZoomWindow(bool down, Point &pt) {
{
if (down) { if (down) {
if (PointInPlot(pt)) { if (PointInPlot(pt)) {
isZoomWindow = true; isZoomWindow = true;
if (IsNull(popLT)) if (IsNull(popLT))
popLT = pt; popLT = pt;
popRB = pt; popRB = pt;
} }
} else { } else {
if(isZoomWindow) { if (isZoomWindow) {
isLabelPopUp = isZoomWindow = false; isLabelPopUp = isZoomWindow = false;
if (popLT.x > popRB.x) if (popLT.x > popRB.x)
::Swap(popLT, popRB); ::Swap(popLT, popRB);
double LTx, LTy, LTy2, RBx, RBy, RBy2; double LTx, LTy, LTy2, RBx, RBy, RBy2;
LTx = (popLT.x - hPlotLeft)*xRange/(GetSize().cx - (hPlot Left + hPlotRight)-1) + xMin; LTx = (popLT.x - hPlotLeft)*xRange/(GetSize().cx - (hPlot Left + hPlotRight)-1) + xMin;
LTy = -(popLT.y - vPlotTop - titleHeight)*yRange/(GetSize ().cy - (vPlotTop + vPlotBottom + titleHeight)+1) + yMin + yRange; LTy = -(popLT.y - vPlotTop - titleHeight)*yRange/(GetSize ().cy - (vPlotTop + vPlotBottom + titleHeight)+1) + yMin + yRange;
LTy2 = -(popLT.y - vPlotTop - titleHeight)*yRange2/(GetSi ze().cy - (vPlotTop + vPlotBottom + titleHeight)+1) + yMin2 + yRange2; LTy2 = -(popLT.y - vPlotTop - titleHeight)*yRange2/(GetSi ze().cy - (vPlotTop + vPlotBottom + titleHeight)+1) + yMin2 + yRange2;
RBx = (popRB.x - hPlotLeft)*xRange/(GetSize().cx - (hPlot Left + hPlotRight)-1) + xMin; RBx = (popRB.x - hPlotLeft)*xRange/(GetSize().cx - (hPlot Left + hPlotRight)-1) + xMin;
RBy = -(popRB.y - vPlotTop - titleHeight)*yRange/(GetSize ().cy - (vPlotTop + vPlotBottom + titleHeight)+1) + yMin + yRange; RBy = -(popRB.y - vPlotTop - titleHeight)*yRange/(GetSize ().cy - (vPlotTop + vPlotBottom + titleHeight)+1) + yMin + yRange;
skipping to change at line 627 skipping to change at line 654
} }
bool ScatterCtrl::Key(dword key, int ) bool ScatterCtrl::Key(dword key, int )
{ {
if (!ProcessKey(key)) { if (!ProcessKey(key)) {
if (key == K_CTRL_P) if (key == K_CTRL_P)
DoShowEditDlg(0); DoShowEditDlg(0);
else if (key == K_CTRL_D) else if (key == K_CTRL_D)
DoShowData(); DoShowData();
else if (key == K_CTRL_C) else if (key == K_CTRL_C)
SaveToClipboard(true); SaveToClipboard(false);
else if (key == K_CTRL_S) else if (key == K_CTRL_S)
SaveToFile(Null); SaveToFile(Null);
else else
return false; return false;
} }
return true; return true;
} }
void ScatterCtrl::GotFocus() void ScatterCtrl::GotFocus()
{ {
skipping to change at line 724 skipping to change at line 751
MousePointRot(pt); MousePointRot(pt);
if (zdelta == 0) if (zdelta == 0)
return; return;
if(!HasFocus()) if(!HasFocus())
SetFocus(); SetFocus();
ProcessMouse(true, pt, keyFlags & K_CTRL, keyFlags & K_ALT, keyFlags & K_ SHIFT, false, false, zdelta, false); ProcessMouse(true, pt, keyFlags & K_CTRL, keyFlags & K_ALT, keyFlags & K_ SHIFT, false, false, zdelta, false);
} }
void ScatterCtrl::MouseMove(Point pt, dword keyFlags) void ScatterCtrl::MouseMove(Point pt, dword keyFlags)
{ {
GuiLock __;
MousePointRot(pt); MousePointRot(pt);
if (isScrolling) { if (isScrolling) {
double factorX = 0, factorY = 0; double factorX = 0, factorY = 0;
int shiftX = pt.x - butDownX; int shiftX = pt.x - butDownX;
if (mouseHandlingX && shiftX != 0) if (mouseHandlingX && shiftX != 0)
factorX = double(shiftX)/(GetSize().cx - (hPlotLeft + hPl otRight) - 1); factorX = double(shiftX)/(GetSize().cx - (hPlotLeft + hPl otRight) - 1);
int shiftY = pt.y - butDownY; int shiftY = pt.y - butDownY;
if (mouseHandlingY && shiftY != 0) if (mouseHandlingY && shiftY != 0)
factorY = double(shiftY)/(GetSize().cy - (vPlotTop + vPlo tBottom) - 1); factorY = double(shiftY)/(GetSize().cy - (vPlotTop + vPlo tBottom) - 1);
butDownX = pt.x; butDownX = pt.x;
butDownY = pt.y; butDownY = pt.y;
if ((mouseHandlingX && shiftX != 0) || (mouseHandlingY && shiftY != 0)) if ((mouseHandlingX && shiftX != 0) || (mouseHandlingY && shiftY != 0))
ScatterDraw::Scroll(factorX, -factorY); ScatterDraw::Scroll(factorX, -factorY);
} }
if(isLabelPopUp) { if(isLabelPopUp) {
if (showInfo && PointInPlot(pt)) { if (showInfo && PointInPlot(pt)) {
if (IsNull(popLT))
popLT = pt;
popRB = pt;
ProcessPopUp(pt); ProcessPopUp(pt);
popTextBegin.AppearOnlyOpen(this); popTextBegin.AppearOnlyOpen(this);
popTextHoriz.AppearOnlyOpen(this); popTextHoriz.AppearOnlyOpen(this);
popTextVert.AppearOnlyOpen(this); popTextVert.AppearOnlyOpen(this);
popTextEnd.AppearOnlyOpen(this); popTextEnd.AppearOnlyOpen(this);
Refresh(); Refresh();
} }
} else if (isZoomWindow) { } else if (isZoomWindow) {
if (PointInPlot(pt)) { if (PointInPlot(pt)) {
if (IsNull(popLT)) if (IsNull(popLT))
skipping to change at line 888 skipping to change at line 914
fs.file = ForceExt(GetFileName(~fs), ".jpg"); fs.file = ForceExt(GetFileName(~fs), ".jpg");
else if (id == 1) else if (id == 1)
fs.file = ForceExt(GetFileName(~fs), ".png"); fs.file = ForceExt(GetFileName(~fs), ".png");
else if (id == 2) else if (id == 2)
fs.file = ForceExt(GetFileName(~fs), ".pdf"); fs.file = ForceExt(GetFileName(~fs), ".pdf");
} }
void ScatterCtrl::SaveToFile(String fileName) void ScatterCtrl::SaveToFile(String fileName)
{ {
GuiLock __; GuiLock __;
if (IsNull(fileName)) { if (IsNull(fileName)) {
FileSel fs; FileSel fs;
fs.Type(Format(t_("%s bitmap file"), "jpeg"), "*.jpg"); fs.Type(Format(t_("%s bitmap file"), "jpeg"), "*.jpg");
fs.Type(Format(t_("%s bitmap file"), "png"), "*.png"); fs.Type(Format(t_("%s bitmap file"), "png"), "*.png");
fs.Type(Format(t_("%s vector file"), "pdf"), "*.pdf"); fs.Type(Format(t_("%s vector file"), "pdf"), "*.pdf");
fs.AllFilesType(); fs.AllFilesType();
if (!defaultFileNamePlot.IsEmpty()) if (!defaultFileNamePlot.IsEmpty())
fs = defaultFileNamePlot; fs = defaultFileNamePlot;
else if (!GetTitle().IsEmpty()) else if (!GetTitle().IsEmpty())
fs = FixPathName(GetTitle()) + ".jpg"; fs = FixPathName(GetTitle()) + ".jpg";
skipping to change at line 1069 skipping to change at line 1096
AddKeyBehavior(true, false, false, K_ADD, true, ScatterCt rl::ZOOM_V_ENL); AddKeyBehavior(true, false, false, K_ADD, true, ScatterCt rl::ZOOM_V_ENL);
AddKeyBehavior(true, false, false, '-', false, ScatterCt rl::ZOOM_H_RED); AddKeyBehavior(true, false, false, '-', false, ScatterCt rl::ZOOM_H_RED);
AddKeyBehavior(true, false, false, K_SUBTRACT, true, ScatterCtrl::ZOOM _H_RED); AddKeyBehavior(true, false, false, K_SUBTRACT, true, ScatterCtrl::ZOOM _H_RED);
AddKeyBehavior(true, false, false, '-', false, ScatterCt rl::ZOOM_V_RED); AddKeyBehavior(true, false, false, '-', false, ScatterCt rl::ZOOM_V_RED);
AddKeyBehavior(true, false, false, K_SUBTRACT, true, ScatterCtrl::ZOOM _V_RED); AddKeyBehavior(true, false, false, K_SUBTRACT, true, ScatterCtrl::ZOOM _V_RED);
AddKeyBehavior(true, false, false, K_LEFT, true, ScatterCtrl::SCRO LL_LEFT); AddKeyBehavior(true, false, false, K_LEFT, true, ScatterCtrl::SCRO LL_LEFT);
AddKeyBehavior(true, false, false, K_RIGHT, true, ScatterCtrl::SCRO LL_RIGHT); AddKeyBehavior(true, false, false, K_RIGHT, true, ScatterCtrl::SCRO LL_RIGHT);
AddKeyBehavior(true, false, false, K_UP, true, ScatterCtrl::SCRO LL_UP); AddKeyBehavior(true, false, false, K_UP, true, ScatterCtrl::SCRO LL_UP);
AddKeyBehavior(true, false, false, K_DOWN, true, ScatterCtrl::SCRO LL_DOWN); AddKeyBehavior(true, false, false, K_DOWN, true, ScatterCtrl::SCRO LL_DOWN);
AddKeyBehavior(true, false, false, K_F, true, ScatterCt rl::ZOOM_FIT); AddKeyBehavior(true, false, false, K_F, true, ScatterCt rl::ZOOM_FIT);
AddInstance(this);
} }
 End of changes. 15 change blocks. 
30 lines changed or deleted 60 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)