mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
ScatterCtrl: Added OnPaint
git-svn-id: svn://ultimatepp.org/upp/trunk@10837 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
87f1b7acd9
commit
0a5df778f0
5 changed files with 86 additions and 2 deletions
|
|
@ -225,6 +225,55 @@ private:
|
|||
Vector<int> idsBubble;
|
||||
};
|
||||
|
||||
class Tab_UserPaint : public WithTabUserPaint<ScatterDemo> {
|
||||
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 <class T>
|
||||
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<Pointf> 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<Pointf> s1;
|
||||
};
|
||||
|
||||
class TabPie : public WithTabPie<StaticRect> {
|
||||
public:
|
||||
typedef TabPie CLASSNAME;
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ file
|
|||
tab14_UserEquation.cpp,
|
||||
tab15_RangePlot.cpp,
|
||||
tab16_BubblePlot.cpp,
|
||||
tab17_UserPaint.cpp,
|
||||
tab20_Pie.cpp,
|
||||
symbol.iml;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ private:
|
|||
void DoPaint(T& w, Vector<Point> &p, const int &scale, const double opacity,
|
||||
double thick, const Color &color, String pattern, const Color &background,
|
||||
const Color &fillColor, int y0) const {
|
||||
Vector<Point> t;
|
||||
Vector<Pointf> t;
|
||||
t.SetCount(3);
|
||||
for (int i = 0; i < p.GetCount(); ++i) {
|
||||
t[0].x = p[i].x + 80;
|
||||
|
|
|
|||
30
examples/ScatterCtrl_Demo/tab17_UserPaint.cpp
Normal file
30
examples/ScatterCtrl_Demo/tab17_UserPaint.cpp
Normal file
|
|
@ -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__);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue