1#ifndef _TIMELINEARTPROVIDER_H
2#define _TIMELINEARTPROVIDER_H
12class wxGraphicsGradientStops;
25 m_TimeScaleFont.Create(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
false,
"Arial");
26 m_ItemNameFont.Create(9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
false,
"Arial");
32 m_PenGap = wxPen(*wxRED, 1, wxPENSTYLE_SHORT_DASH);
40 dc.GradientFillLinear(rect, wxColour(83, 83, 83), wxColour(163, 163, 163), wxDOWN);
54 virtual void DrawGap(wxDC& dc,
const wxRect& rTimeline,
const wxRect& rVisibleFrame) {
56 wxUnusedVar(rTimeline);
57 wxUnusedVar(rVisibleFrame);
62 wxPoint t = rect.GetTopRight();
63 wxPoint b = rect.GetBottomRight();
64 wxPoint c = rect.GetTopLeft();
65 c.y += rect.height / 2;
71 wxPoint t = rect.GetTopLeft();
72 wxPoint b = rect.GetBottomLeft();
73 wxPoint c = rect.GetTopRight();
74 c.y += rect.height / 2;
85 int desiredRadius = 11;
87 int maxPossibleRadiusForRect = (wxMin(rect.width, rect.height) - 2) / 2;
88 int actualRadius =
wxClip(desiredRadius, 0, maxPossibleRadiusForRect);
90 dc.SetPen(wxColour(255, 255, 255, 255 * (koef + 0.1)));
92 wxGraphicsGradientStops stops(wxColour(255, 255, 255, 192 * koef), wxColour(255, 255, 255, 128 * koef));
93 stops.Add(wxColour(255, 255, 255, 128 * koef), 0.6f);
94 stops.Add(wxColour(255, 255, 255, 76 * koef), 0.61f);
99 const wxDateTime& startTime,
const wxDateTime& endTime)
101 if (rect.width <= 0 || rect.height <= 0)
104 wxTimeSpan duration = endTime - startTime;
105 long totalSeconds = duration.GetSeconds().ToLong();
107 if (totalSeconds <= 0)
110 dc.SetTextForeground(wxColour(80, 80, 80));
112 dc.SetPen(wxPen(wxColour(80, 80, 80), 1));
114 wxString sampleText =
"00:00:00";
115 wxSize textSize = dc.GetTextExtent(sampleText);
116 int textWidth = textSize.GetWidth();
117 int textHeight = textSize.GetHeight();
119 int minSpacing = textWidth + 20;
121 int maxLabels = wxMax(2, rect.width / minSpacing);
125 int numMarks = (totalSeconds / interval) + 1;
127 for (
int i = 0; i <= numMarks && i * interval <= totalSeconds; ++i)
129 long offsetSeconds = i * interval;
130 if (offsetSeconds > totalSeconds)
131 offsetSeconds = totalSeconds;
133 double progress = double(offsetSeconds) / double(totalSeconds);
134 int x = rect.x + int(progress * rect.width);
136 wxDateTime markTime = startTime + wxTimeSpan::Seconds(offsetSeconds);
141 dc.DrawLine(tickX, rect.y, tickX, rect.y + tickHeight);
143 wxSize currentTextSize = dc.GetTextExtent(timeText);
150 else if (offsetSeconds >= totalSeconds)
152 textX = x - currentTextSize.GetWidth() - 2;
156 textX = x - currentTextSize.GetWidth() / 2;
159 textY = rect.y + (rect.height - textHeight) / 2;
161 textX = wxMax(rect.x, wxMin(textX, rect.GetRight() - currentTextSize.GetWidth()));
163 dc.SetClippingRegion(rect);
164 dc.DrawText(timeText, textX, textY);
165 dc.DestroyClippingRegion();
174 double roughInterval = double(totalSeconds) / double(maxLabels - 1);
176 const int niceIntervals[] = {
178 60, 120, 300, 600, 900, 1800,
179 3600, 7200, 10800, 21600, 43200,
180 86400, 172800, 432000, 864000, 2592000
182 const int numIntervals =
sizeof(niceIntervals) /
sizeof(niceIntervals[0]);
184 for (
int i = 0; i < numIntervals; ++i)
186 if (niceIntervals[i] >= roughInterval)
188 return niceIntervals[i];
192 int largestNice = niceIntervals[numIntervals - 1];
193 int multiplier = (int(roughInterval) + largestNice - 1) / largestNice;
194 return largestNice * multiplier;
199 return time.Format(
"%H:%M:%S");
203 void DrawItem(wxDC& dc,
const wxRect& rect,
const wxRect& parentRect,
const TimelineItem<T>& item,
bool isScrollerContext =
false,
bool makeTransparentDueToOverlap =
false);
214 dc.SetBackground(*wxWHITE_BRUSH);
216 dc.SetPen(*wxBLACK_PEN);
217 dc.SetBrush(*wxBLACK_BRUSH);
232 wxRegion region(rect);
235 round.Offset(rect.x, rect.y);
236 region.Subtract(round);
239 round.Offset(rect.x, rect.y + rect.height -
m_Radius);
240 region.Subtract(round);
243 round.Offset(rect.x + rect.width -
m_Radius, rect.y);
244 region.Subtract(round);
247 round.Offset(rect.x + rect.width -
m_Radius, rect.y + rect.height -
m_Radius);
248 region.Subtract(round);
253 void DrawGradientRoundedRect(wxDC& dc,
const wxRect& rect,
double radius,
const wxGraphicsGradientStops& stops, wxDirection direction = wxEAST)
255 wxGCDC* gdc = wxDynamicCast(&dc, wxGCDC);
259 dc.GradientFillLinear(rect, stops.GetStartColour(), stops.GetEndColour(), direction);
260 dc.SetBrush(*wxTRANSPARENT_BRUSH);
261 dc.DrawRoundedRectangle(rect, radius);
262 dc.DestroyClippingRegion();
269 if (w == 0 || h == 0)
273 radius = -radius * ((w < h) ? w : h);
280 start = rect.GetRightBottom();
282 end = rect.GetLeftBottom();
285 start = rect.GetLeftBottom();
286 end = rect.GetRightBottom();
290 start = rect.GetLeftBottom();
292 end = rect.GetLeftTop();
295 start = rect.GetLeftTop();
296 end = rect.GetLeftBottom();
303 wxGraphicsContext* gc = gdc->GetGraphicsContext();
305 if (gc->ShouldOffset())
311 gc->SetBrush(gc->CreateLinearGradientBrush(start.x, start.y, end.x, end.y, stops));
312 gc->DrawRoundedRectangle(rect.x, rect.y, w, h, radius);
317 wxColour penColor, brushColor, shadowColor;
322 penColor = wxColour(60, 60, 60);
323 brushColor = wxColour(180, 180, 180, 220);
324 shadowColor = wxColour(0, 0, 0, 80);
327 penColor = wxColour(40, 40, 40);
328 brushColor = wxColour(240, 240, 240, 240);
329 shadowColor = wxColour(0, 0, 0, 120);
332 penColor = wxColour(20, 20, 20);
333 brushColor = wxColour(255, 255, 255, 255);
334 shadowColor = wxColour(0, 0, 0, 150);
337 penColor = wxColour(120, 120, 120);
338 brushColor = wxColour(160, 160, 160, 160);
339 shadowColor = wxColour(0, 0, 0, 40);
342 penColor = wxColour(60, 60, 60);
343 brushColor = wxColour(180, 180, 180, 220);
344 shadowColor = wxColour(0, 0, 0, 80);
348 wxPoint expandedTop = top;
349 wxPoint expandedBottom = bottom;
350 wxPoint expandedCenter = center;
352 int deltaY = (bottom.y - top.y) / 6;
353 expandedTop.y -= deltaY;
354 expandedBottom.y += deltaY;
356 int deltaX = abs(center.x - top.x) / 4;
357 if (center.x > top.x)
358 expandedCenter.x += deltaX;
360 expandedCenter.x -= deltaX;
362 wxPoint arrowPoints[] = { expandedTop, expandedCenter, expandedBottom };
366 wxPoint shadowPoints[] = {
367 wxPoint(expandedTop.x + 1, expandedTop.y + 1),
368 wxPoint(expandedCenter.x + 1, expandedCenter.y + 1),
369 wxPoint(expandedBottom.x + 1, expandedBottom.y + 1)
372 dc.SetBrush(wxBrush(shadowColor));
373 dc.SetPen(wxPen(shadowColor));
374 dc.DrawPolygon(WXSIZEOF(shadowPoints), shadowPoints);
377 dc.SetBrush(wxBrush(brushColor));
378 dc.SetPen(wxPen(brushColor));
379 dc.DrawPolygon(WXSIZEOF(arrowPoints), arrowPoints);
382 dc.DrawLines(WXSIZEOF(arrowPoints), arrowPoints);
386 wxColour highlightColor = wxColour(255, 255, 255, 100);
387 dc.SetPen(wxPen(highlightColor, 1));
389 if (center.x > top.x)
391 dc.DrawLine(expandedTop.x - 1, expandedTop.y + 1,
392 expandedCenter.x - 1, expandedCenter.y);
396 dc.DrawLine(expandedTop.x + 1, expandedTop.y + 1,
397 expandedCenter.x + 1, expandedCenter.y);
429 wxRect r(rect.Intersect(parentRect));
433 wxColour currentItemColor = item.
Colour;
438 currentItemColor = currentItemColor.ChangeLightness(130);
441 currentItemColor = currentItemColor.ChangeLightness(150);
444 currentItemColor = currentItemColor.ChangeLightness(90);
450 unsigned char finalAlpha = currentItemColor.Alpha();
451 if (makeTransparentDueToOverlap)
453 if (isScrollerContext)
463 wxColour baseColor(currentItemColor.Red(), currentItemColor.Green(), currentItemColor.Blue(), finalAlpha);
465 wxColour gradColor = baseColor.ChangeLightness(133);
466 gradColor.Set(gradColor.Red(), gradColor.Green(), gradColor.Blue(), finalAlpha);
470 wxGCDC* gdc = wxDynamicCast(&dc, wxGCDC);
473 wxGraphicsContext* gc = gdc->GetGraphicsContext();
476 wxGraphicsGradientStops stops(baseColor, gradColor);
477 wxGraphicsBrush brush = gc->CreateLinearGradientBrush(
478 r.x, r.GetBottom(), r.GetRight(), r.GetBottom(), stops);
480 gc->DrawRoundedRectangle(r.x, r.y, r.width, r.height, radius);
486 dc.GradientFillLinear(r, gradColor, baseColor, wxDOWN);
487 dc.SetBrush(*wxTRANSPARENT_BRUSH);
488 dc.DrawRoundedRectangle(r, radius);
489 dc.DestroyClippingRegion();
496 textRect.Deflate(isScrollerContext ? 2 : 5, 0);
499 if (isScrollerContext)
501 fontToUse = wxFont(wxFontInfo(9).Family(wxFONTFAMILY_SWISS).Weight(wxFONTWEIGHT_NORMAL));
505 fontToUse = wxFont(wxFontInfo(12)
512 dc.SetFont(fontToUse);
514 dc.SetTextForeground(*wxBLACK);
516 wxSize textSize = dc.GetTextExtent(name);
518 bool canDrawText = (textRect.width >= textSize.x && textRect.height >= textSize.y);
519 if (isScrollerContext && r.width < 10)
526 textRect = textRect.Intersect(r);
527 if (!textRect.IsEmpty())
529 wxDCClipper clip(dc, textRect);
530 dc.DrawLabel(name, textRect, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
TimelineElementState
Definition TimelineItem.h:12
Definition TimelineArtProvider.h:15
wxFont m_ItemNameFont
Definition TimelineArtProvider.h:407
wxRegion m_RoundRegionTR
Definition TimelineArtProvider.h:417
virtual void DrawTimelineTrack(wxDC &dc, const wxRect &rect)
Definition TimelineArtProvider.h:43
virtual ~TimelineArtProvider()
Definition TimelineArtProvider.h:36
wxPen m_PenVisibleFramePressed
Definition TimelineArtProvider.h:413
virtual void DrawScrollerTrack(wxDC &dc, const wxRect &rect)
Definition TimelineArtProvider.h:49
wxPen m_PenScrollerMain
Definition TimelineArtProvider.h:410
double m_MinScaleStep
Definition TimelineArtProvider.h:420
virtual void DrawGap(wxDC &dc, const wxRect &rTimeline, const wxRect &rVisibleFrame)
Definition TimelineArtProvider.h:54
wxPen m_PenGap
Definition TimelineArtProvider.h:414
virtual void DrawScrollerBackground(wxDC &dc, const wxRect &rect)
Definition TimelineArtProvider.h:48
virtual void DrawRightArrow(wxDC &dc, const wxRect &rect, TimelineElementState state)
Definition TimelineArtProvider.h:69
int CalculateNiceInterval(long totalSeconds, int maxLabels)
Definition TimelineArtProvider.h:169
void DrawArrow(wxDC &dc, wxPoint &top, wxPoint &bottom, wxPoint ¢er, TimelineElementState state)
Definition TimelineArtProvider.h:315
wxRegion m_RoundRegionBR
Definition TimelineArtProvider.h:417
wxRegion m_RoundRegionBL
Definition TimelineArtProvider.h:417
wxRegion m_RoundRegionTL
Definition TimelineArtProvider.h:417
virtual void DrawVisibleFrame(wxDC &dc, const wxRect &rect, TimelineElementState state)
Definition TimelineArtProvider.h:78
wxPen m_PenTimelineMain
Definition TimelineArtProvider.h:409
virtual void DrawTimelineBackground(wxDC &dc, const wxRect &rect)
Definition TimelineArtProvider.h:42
virtual void DrawBackground(wxDC &dc, const wxRect &rect)
Definition TimelineArtProvider.h:38
wxString FormatTimeForScale(const wxDateTime &time)
Definition TimelineArtProvider.h:197
wxPen m_PenVisibleFrameNormal
Definition TimelineArtProvider.h:411
wxFont m_TimeScaleFont
Definition TimelineArtProvider.h:406
void SetBackgroundColour(const wxColour &colour)
Definition TimelineArtProvider.h:205
int m_Radius
Definition TimelineArtProvider.h:419
void DrawGradientRoundedRect(wxDC &dc, const wxRect &rect, double radius, const wxGraphicsGradientStops &stops, wxDirection direction=wxEAST)
Definition TimelineArtProvider.h:253
void CreateRoundRegions()
Definition TimelineArtProvider.h:209
wxPen m_PenVisibleFrameHover
Definition TimelineArtProvider.h:412
virtual void DrawLeftArrow(wxDC &dc, const wxRect &rect, TimelineElementState state)
Definition TimelineArtProvider.h:60
void DrawItem(wxDC &dc, const wxRect &rect, const wxRect &parentRect, const TimelineItem< T > &item, bool isScrollerContext=false, bool makeTransparentDueToOverlap=false)
Definition TimelineArtProvider.h:424
void DrawTimeScale(wxDC &dc, const wxRect &rect, const wxDateTime &startTime, const wxDateTime &endTime)
Definition TimelineArtProvider.h:98
wxColour m_LimitTimeColour
Definition TimelineArtProvider.h:404
wxColour GetBackgroundColour() const
Definition TimelineArtProvider.h:206
TimelineArtProvider()
Definition TimelineArtProvider.h:19
wxBitmap m_BmpRound
Definition TimelineArtProvider.h:416
wxRegion GetRoundRegion(const wxRect &rect)
Definition TimelineArtProvider.h:230
wxColour m_BackgroundColour
Definition TimelineArtProvider.h:403
Definition TimelineItem.h:22
wxColour Colour
Definition TimelineItem.h:57
wxString GetItemName() const
Definition TimelineItem.h:47
T * Data
Definition TimelineItem.h:55
TimelineElementState State
Definition TimelineItem.h:56
Tval wxClip(Tval value, Tval min_val, Tval max_val)
Definition wxTimelineCtrl.h:18