From 0a5df778f0e6babd1fbe46838bdbb5c86aa5e397 Mon Sep 17 00:00:00 2001 From: koldo Date: Fri, 10 Feb 2017 22:02:26 +0000 Subject: [PATCH] ScatterCtrl: Added OnPaint git-svn-id: svn://ultimatepp.org/upp/trunk@10837 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h | 49 +++++++++++++++++++ .../ScatterCtrl_Demo/ScatterCtrl_Demo.lay | 6 ++- .../ScatterCtrl_Demo/ScatterCtrl_Demo.upp | 1 + examples/ScatterCtrl_Demo/tab10_User.cpp | 2 +- examples/ScatterCtrl_Demo/tab17_UserPaint.cpp | 30 ++++++++++++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 examples/ScatterCtrl_Demo/tab17_UserPaint.cpp diff --git a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h index 50ad93461..998945e78 100644 --- a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h +++ b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.h @@ -225,6 +225,55 @@ private: Vector idsBubble; }; +class Tab_UserPaint : public WithTabUserPaint { +public: + typedef Tab_UserPaint CLASSNAME; + + virtual void Init(); + virtual ScatterCtrl &Scatter() {return scatter;}; + + void OnPainter(Painter &w) {OnPaint(w);} + void OnDraw(Draw &w) {OnPaint(w);} + + template + void OnPaint(T& w) { + int plotW = scatter.GetPlotWidth(), plotH = scatter.GetPlotHeight(); + DrawLineOpa(w, 0, 0, plotW, plotH, 1, 1, 1, LtRed(), "2 2"); + DrawText(w, plotW/5, plotH/5, 0, "Fixed line", Arial(15), Black()); + + String text = "Fixed text"; + Font font = Arial(30); + Size sz = GetTextSize(text, font); + FillRectangleOpa(w, plotW - sz.cx - 10, 10, plotW - 10, 10 + sz.cy, 1, 0.3, Null, LtGreen()); + DrawText(w, plotW - sz.cx - 10, 10, 0, text, font, Black()); + + for (int i = 0; i < s1.GetCount(); ++i) { + if (s1[i].x >= 1) { + Pointf pos = scatter.GetPosPrimary(s1[i].x, s1[i].y); + double sizex = scatter.GetSizeX(0.2); + FillRectangleOpa(w, pos.x - sizex/2., pos.y - sizex/2., + pos.x + sizex/2., pos.y + sizex/2., + 1, 0.8, Null, LtGreen()); + Vector p; + p << Pointf(pos.x - sizex/2., pos.y - sizex/2.) + << Pointf(pos.x + sizex/2., pos.y - sizex/2.) + << Pointf(pos.x + sizex/2., pos.y + sizex/2.) + << Pointf(pos.x - sizex/2., pos.y + sizex/2.) + << Pointf(pos.x - sizex/2., pos.y - sizex/2.); + DrawPolylineOpa(w, p, 1, 1, 2, Green(), "", Null); + DrawText(w, pos.x + sizex/2., pos.y, 0, Format("Pos %.2f, %.2f fixed font", s1[i].x, s1[i].y), Arial(15), Black()); + double sizeT = scatter.GetSizeYPrimary(0.05); + Font font = Arial((int)sizeT); + DrawText(w, pos.x + sizex/2., pos.y + 15, 0, Format("Pos %.2f, %.2f scaled font", s1[i].x, s1[i].y), font, Black()); + break; + } + } + } + +private: + Vector s1; +}; + class TabPie : public WithTabPie { public: typedef TabPie CLASSNAME; diff --git a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay index 575c715ca..d3d63337f 100644 --- a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay +++ b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.lay @@ -15,7 +15,7 @@ LAYOUT(Tab1Basic, 428, 296) END_LAYOUT LAYOUT(Tab2Functions, 380, 292) - ITEM(ScatterCtrl, scatter, SetTitle(t_("Functions")).SetGridWidth(2).SetPlotAreaRightMargin(110).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).SetLegendAnchor(2).SetLegendPosX(-107).SetLegendPosY(0).HSizePosZ(16, 12).VSizePosZ(16, 16)) + ITEM(ScatterCtrl, scatter, SetTitle(t_("Functions")).SetPlotAreaRightMargin(110).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetGridWidth(2).SetTitleFont(SansSerifZ(14).Bold()).SetLegendAnchor(2).SetLegendPosX(-107).SetLegendPosY(0).HSizePosZ(16, 12).VSizePosZ(16, 16)) END_LAYOUT LAYOUT(Tab3ParametricFunctions, 384, 284) @@ -106,6 +106,10 @@ LAYOUT(TabBubblePlot, 420, 236) ITEM(ScatterCtrl, scatter, SetTitle(t_("Bubble Plot")).SetPlotAreaLeftMargin(40).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).HSizePosZ(4, 4).VSizePosZ(4, 4)) END_LAYOUT +LAYOUT(TabUserPaint, 428, 296) + ITEM(ScatterCtrl, scatter, SetTitle(t_("User paint")).SetPlotAreaRightMargin(20).SetPlotAreaTopMargin(20).SetLabelsFont(StdFontZ(11)).SetTitleFont(SansSerifZ(14).Bold()).SetLegendAnchor(2).HSizePosZ(4, 4).VSizePosZ(4, 4)) +END_LAYOUT + LAYOUT(TabPie, 536, 440) ITEM(PieCtrl, chart, SetLegendBackColor(Color(229, 229, 229)).SetLegendLeft(20).SetTitle(t_("Average Weather")).SetFrame(ThinInsetFrame()).HSizePosZ(8, 12).VSizePosZ(40, 12)) ITEM(Label, dv___1, SetLabel(t_(" EXPERIMENTAL")).SetFrame(ThinInsetFrame()).LeftPosZ(8, 84).TopPosZ(8, 24)) diff --git a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp index 5ecabc7e7..5fc0a2427 100644 --- a/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp +++ b/examples/ScatterCtrl_Demo/ScatterCtrl_Demo.upp @@ -26,6 +26,7 @@ file tab14_UserEquation.cpp, tab15_RangePlot.cpp, tab16_BubblePlot.cpp, + tab17_UserPaint.cpp, tab20_Pie.cpp, symbol.iml; diff --git a/examples/ScatterCtrl_Demo/tab10_User.cpp b/examples/ScatterCtrl_Demo/tab10_User.cpp index ea56506e7..0db0d4b24 100644 --- a/examples/ScatterCtrl_Demo/tab10_User.cpp +++ b/examples/ScatterCtrl_Demo/tab10_User.cpp @@ -10,7 +10,7 @@ private: void DoPaint(T& w, Vector &p, const int &scale, const double opacity, double thick, const Color &color, String pattern, const Color &background, const Color &fillColor, int y0) const { - Vector t; + Vector t; t.SetCount(3); for (int i = 0; i < p.GetCount(); ++i) { t[0].x = p[i].x + 80; diff --git a/examples/ScatterCtrl_Demo/tab17_UserPaint.cpp b/examples/ScatterCtrl_Demo/tab17_UserPaint.cpp new file mode 100644 index 000000000..1d992f82d --- /dev/null +++ b/examples/ScatterCtrl_Demo/tab17_UserPaint.cpp @@ -0,0 +1,30 @@ +#include "ScatterCtrl_Demo.h" + +void Tab_UserPaint::Init() +{ + CtrlLayout(*this); + SizePos(); + + double a = 1, b = 0, c = 1; + for (double x = -6; x < 6; x += 0.1) + s1 << Pointf(x, a*exp(-sqr(x - b)/(2*c*c))); + scatter.AddSeries(s1).Legend("Gauss").Opacity(0.3).Fill().NoMark(); + + scatter.ShowInfo().ShowContextMenu().ShowPropertiesDlg().ShowProcessDlg(). + SetMouseHandling(true, true); + scatter.SetLegendPos(Point(20, 20)).SetLegendAnchor(ScatterDraw::LEGEND_ANCHOR_RIGHT_BOTTOM); + scatter.ZoomToFit(true, true); + scatter.WhenPainter = THISBACK(OnPainter); + scatter.WhenDraw = THISBACK(OnDraw); +} + + +ScatterDemo *Construct17() +{ + static Tab_UserPaint tab; + return &tab; +} + +INITBLOCK { + RegisterExample("User paint", Construct17, __FILE__); +}