void GraphView::GetDistance(int x, int y, double &d, wxDateTime &time) const { d = INFINITY; time = wxInvalidDateTime; /* this defines search radius for 'direct hit' */ int w,h; m_dc->GetSize(&w, &h); /* forget about top and bottom margins */ h -= m_bottommargin + m_topmargin; /* get X coordinate */ int index = GetIndex(x); const Draw::VT& vt = m_draw->GetValuesTable(); int i, j; for (i = j = index; i >= 0 || j < (int)vt.size(); --i, ++j) { double d1 = INFINITY; double d2 = INFINITY; if (i >= 0 && i < (int)vt.size() && vt.at(i).IsData()) { int xi, yi; GetPointPosition(m_dc, i, &xi, &yi); d1 = (x - xi) * (x - xi) + (y - yi) * (y - yi); } if (j >= 0 && j < (int)vt.size() && vt.at(j).IsData()) { int xj, yj; GetPointPosition(m_dc, j, &xj, &yj); d1 = (x - xj) * (x - xj) + (y - yj) * (y - yj); } if (!std::isfinite(d1) && !std::isfinite(d1)) continue; if (!std::isfinite(d2) || d1 < d2) { d = d1; time = m_draw->GetTimeOfIndex(i); wxLogInfo(_T("Nearest index %d, time: %s"), i, time.Format().c_str()); } else { d = d2; time = m_draw->GetTimeOfIndex(j); wxLogInfo(_T("Nearest index %d, time: %s"), j, time.Format().c_str()); } break; } }
void GraphView::DrawCursor(int index, bool clear, wxRegion *region) { if (index < 0) return; int x, y; wxDC* dc = m_dc; const Draw::VT& vt = m_draw->GetValuesTable(); if (!vt.at(index).IsData()) return; GetPointPosition(dc, index, &x, &y); wxRect rect(x - cursorrectanglesize / 2, y - cursorrectanglesize / 2, cursorrectanglesize, cursorrectanglesize ); dc->SetBrush(wxBrush(wxColour(0,0,0), wxTRANSPARENT)); if (!clear) { dc->SetPen(wxPen(*wxWHITE, 1, wxSOLID)); wxLogInfo(_T("Drawing cursor at position %d , %d"), x, y); m_sdc.SetWhiteForeground(); dc->DrawRectangle(rect); m_sdc.DrawRectangle(rect); } else { dc->SetPen(wxPen(*wxBLACK, 1, wxSOLID)); wxLogInfo(_T("Clearing cursor at position %d , %d"), x, y); m_sdc.SetBlackForeground(); dc->DrawRectangle(rect); m_sdc.DrawRectangle(rect); //repaint points damaged by cursor int x1, x2; x1 = GetIndex(x - cursorrectanglesize / 2); x2 = GetIndex(x + cursorrectanglesize / 2); for (int i = x1; i <= x2; i++) if (i > 0 && i < (int)vt.size()) DrawPoint(i, region, false); } if (region) region->Union(rect); dc->SetPen(wxNullPen); dc->SetBrush(wxNullBrush); }
AnimatePoint AnimateCompile::GetEndingPosition(const ContToken* token) const { auto sheet = curr_sheet + 1; while (1) { if (sheet == mShow.GetSheetEnd()) { RegisterError(ANIMERR_UNDEFINED, token); return GetPointPosition(); } if (sheet->IsInAnimation()) { return sheet->GetPosition(GetCurrentPoint()); } ++sheet; } }
void GraphDrawer::DrawAllPoints(wxDC *dc, SDC *sdc, int point_width) { if (!dc->Ok()) return; if (m_draw->GetDrawInfo() == NULL) return; bool prev_no_data = true; wxPen pen1; wxPen pen2; pen1.SetStyle(wxSOLID); pen2.SetStyle(wxSOLID); pen1.SetWidth(point_width); pen2.SetWidth(point_width); pen1.SetColour(m_draw->GetDrawInfo()->GetDrawColor()); pen2.SetColour(alt_color); dc->SetPen(pen1); if (sdc) { sdc->SetWhiteForeground(); sdc->SetLineWidth(point_width); } const Draw::VT& vt = m_draw->GetValuesTable(); bool is_alt = false; for (size_t i = 0; i < vt.size(); i++) { if (!vt.at(i).IsData()) { prev_no_data = true; continue; } int x, y; GetPointPosition(dc, i, &x, &y); bool pa = AlternateColor(i); if (!prev_no_data) { int x1, y1; if (is_alt && pa) dc->SetPen(pen2); else dc->SetPen(pen1); GetPointPosition(dc, i - 1, &x1, &y1); dc->DrawLine(x1, y1, x, y); if (sdc) sdc->DrawLine(x1, y1, x, y); if (is_alt) dc->SetPen(pen2); else dc->SetPen(pen1); dc->DrawPoint(x1, y1); if (sdc) sdc->DrawPoint(x1, y1); if (m_draw->GetPeriod() != PERIOD_T_DAY && m_draw->GetPeriod() != PERIOD_T_30MINUTE) { dc->DrawCircle(x1, y1, m_circle_radius); if (sdc) sdc->DrawCircle(x1, y1, m_circle_radius); } } if ((i + 1) >= vt.size() || !vt.at(i + 1).IsData()) { if (pa) dc->SetPen(pen2); else dc->SetPen(pen1); dc->DrawPoint(x, y); if (sdc) sdc->DrawPoint(x, y); if (m_draw->GetPeriod() != PERIOD_T_DAY && m_draw->GetPeriod() != PERIOD_T_30MINUTE) { dc->DrawCircle(x, y, m_circle_radius); if (sdc) sdc->DrawCircle(x, y, m_circle_radius); } } is_alt = pa; prev_no_data = false; } dc->SetBrush(wxNullBrush); dc->SetPen(wxNullPen); if (sdc) sdc->SetLineWidth(1); }
void GraphView::DrawPoint(int index, wxRegion *region, bool maybe_repaint_cursor) { bool repaint_cursor = false; int current_index = 0; if (index < 0) return; if (!m_draw->GetValuesTable().at(index).IsData()) return; wxDC* dc = m_dc; if (!dc->Ok()) return; int x, y; GetPointPosition(dc, index, &x , &y); bool wide = m_draw->GetSelected() && m_draw->GetDoubleCursor(); int line_width = wide ? 3 : 1; m_sdc.SetLineWidth(wide ? 3 : 1); m_sdc.SetWhiteForeground(); wxPen pen1(m_draw->GetDrawInfo()->GetDrawColor(), line_width, wxSOLID); wxPen pen2(alt_color, line_width, wxSOLID); dc->SetPen(pen1); dc->SetBrush(wxBrush(wxColour(0,0,0), wxTRANSPARENT)); int i = index; const Draw::VT& vt = m_draw->GetValuesTable(); bool is_alternate = AlternateColor(index); if (i - 1 >= 0 && vt.at(i-1).IsData()) { int x1, y1; GetPointPosition(dc, i - 1, &x1, &y1); bool ac = AlternateColor(i - 1); if (ac && is_alternate) { dc->SetPen(pen2); } else { dc->SetPen(pen1); } dc->DrawLine(x1, y1, x, y); m_sdc.DrawLine(x1, y1, x, y); if (ac) dc->SetPen(pen2); else dc->SetPen(pen1); DrawDot(x1, y1, dc, &m_sdc, region); if (region) region->Union(x1 , std::min(y, y1) - line_width, abs(x - x1) + 2 * line_width, abs(y - y1) + 2 * line_width); if (maybe_repaint_cursor && m_draw->GetCurrentIndex() != -1 && m_draw->GetCurrentIndex() == i) { repaint_cursor = true; current_index = i - 1; } } if ((i + 1) < (int)vt.size() && vt.at(i + 1).IsData()) { int x2, y2; bool ac = AlternateColor(i + 1); if (ac && is_alternate) { dc->SetPen(pen2); } else { dc->SetPen(pen1); } GetPointPosition(dc, i + 1, &x2 , &y2); dc->DrawLine(x, y, x2, y2); m_sdc.DrawLine(x, y, x2, y2); if (ac) dc->SetPen(pen2); else dc->SetPen(pen1); DrawDot(x2, y2, dc, &m_sdc, region); if (region) region->Union(x, std::min(y, y2) - line_width, abs(x - x2) + 2 * line_width, abs(y - y2) + 2 * line_width); if (maybe_repaint_cursor && m_draw->GetCurrentIndex() != -1 && m_draw->GetCurrentIndex() == i) { repaint_cursor = true; current_index = i + 1; } } if (is_alternate) dc->SetPen(pen2); else dc->SetPen(pen1); DrawDot(x, y, dc, &m_sdc, region); m_sdc.SetLineWidth(1); pen1.SetWidth(1); pen2.SetWidth(1); if (repaint_cursor) DrawCursor(current_index, region); dc->SetPen(wxNullPen); dc->SetBrush(wxNullBrush); }