示例#1
0
void wxChartArc::Draw(wxGraphicsContext &gc)
{
	wxGraphicsPath path = gc.CreatePath();

	if (m_innerRadius > 0)
	{
		path.AddArc(m_x, m_y, m_innerRadius, m_startAngle, m_endAngle, true);
		path.AddArc(m_x, m_y, m_outerRadius, m_endAngle, m_startAngle, false);
	}
	else
	{
		path.AddArc(m_x, m_y, m_outerRadius, m_endAngle, m_startAngle, false);
		path.AddLineToPoint(m_x, m_y);
	}

	path.CloseSubpath();

	wxBrush brush(m_options.GetFillColor());
	gc.SetBrush(brush);
	gc.FillPath(path);

	wxPen pen(*wxWHITE, m_options.GetOutlineWidth());
	gc.SetPen(pen);
	gc.StrokePath(path);
}
示例#2
0
void wxChartBackground::Draw(wxDouble x, 
                             wxDouble y, 
                             wxDouble width, 
                             wxDouble height,
                             wxGraphicsContext &gc)
{
    wxGraphicsPath path = gc.CreatePath();

    path.AddRoundedRectangle(x, y, width, height, m_options.GetCornerRadius());

    wxBrush brush(m_options.GetColor());
    gc.SetBrush(brush);
    gc.FillPath(path);
}
示例#3
0
void GCDCGraphs::DrawGraph(wxGraphicsContext &dc, Draw* d) {
	static const int ellipse_size = 5;

	if (d->GetEnable() == false)
		return;

	DrawInfo *di = d->GetDrawInfo();

	bool double_cursor = d->GetSelected() && d->GetDoubleCursor();

	wxGraphicsPath path1 = dc.CreatePath();
	wxGraphicsPath path2 = dc.CreatePath();

	wxGraphicsPath *path = &path1;

	const wxColour &wc = di->GetDrawColor();
	dc.SetPen(wxPen(wc, double_cursor ? 4 : 2, wxSOLID));

	int pc = d->GetValuesTable().size();

	bool prev_data = false;
	bool switched_to_alternate = false;
	bool switched_back = false;

	int dcs = -1, dce = -1;
	if (double_cursor) {
		dcs = d->GetValuesTable().m_stats.Start() - d->GetValuesTable().m_view.Start();
		dce = d->GetValuesTable().m_stats.End() - d->GetValuesTable().m_view.Start();
	}

	std::vector<std::pair<double,double> > p1circles;
	std::vector<std::pair<double,double> > p2circles;
	std::vector<std::pair<double,double> >* pcircles = &p1circles;

	bool draw_circle =
		d->GetPeriod() != PERIOD_T_DAY
		&& d->GetPeriod() != PERIOD_T_30MINUTE
		&& d->GetPeriod() != PERIOD_T_5MINUTE
		&& d->GetPeriod() != PERIOD_T_MINUTE
		&& d->GetPeriod() != PERIOD_T_30SEC;

	for (int i = 0; i < pc; i++) {
		if (!d->GetValuesTable().at(i).IsData()) {
			prev_data = false;
			continue;
		}

		double x = GetX(i);
		double y = GetY(d->GetValuesTable().at(i).val, di);

		bool drawn = false;

		if (i >= dcs && i <= dce && !switched_to_alternate) {
			if (prev_data)
				path->AddLineToPoint(x, y);

			path = &path2;
			pcircles = &p2circles;

			if (draw_circle || (!prev_data && ((i + 1) < pc) && !d->GetValuesTable().at(i + 1).IsData())) 
				pcircles->push_back(std::make_pair(x, y));

			path->MoveToPoint(x, y);
			switched_to_alternate = true;
			drawn = true;
		}

		if (i >= dce && switched_to_alternate && !switched_back) {
			if (prev_data)
				path->AddLineToPoint(x, y);

			std::vector<std::pair<double, double> > *p;
			if (i == dce)
				p = &p2circles;
			else
				p = &p1circles;

			if (draw_circle || (!prev_data && ((i + 1) < pc) && !d->GetValuesTable().at(i + 1).IsData())) 
				p->push_back(std::make_pair(x, y));

			path = &path1;
			pcircles = &p1circles;
			path->MoveToPoint(x, y);

			switched_back = true;

			drawn = true;
		}

		if (!drawn) {
			if (prev_data)
				path->AddLineToPoint(x, y);
			else
				path->MoveToPoint(x, y);

			if (draw_circle || (!prev_data && ((i + 1) < pc) && !d->GetValuesTable().at(i + 1).IsData())) 
				pcircles->push_back(std::make_pair(x, y));
		}
		
		prev_data = true;
	}

	for (std::vector<std::pair<double, double> >::iterator i = p1circles.begin();
			i != p1circles.end();
			i++)
		if (draw_circle)
			path1.AddEllipse(i->first - ellipse_size / 2, i->second - ellipse_size / 2, ellipse_size, ellipse_size);
		else
			path1.AddCircle(i->first, i->second, 1);

	dc.StrokePath(path1);

	if (double_cursor) {
		dc.SetPen(wxPen(*wxWHITE, 4, wxSOLID));
		for (std::vector<std::pair<double, double> >::iterator i = p2circles.begin();
				i != p2circles.end();
				i++)
			if (draw_circle)
				path2.AddEllipse(i->first - ellipse_size / 2, i->second - ellipse_size / 2, ellipse_size, ellipse_size);
			else
				path2.AddCircle(i->first, i->second, 1);
		dc.StrokePath(path2);
	}
}