1#ifndef _WX_TIMELINE_CTRL_H
2#define _WX_TIMELINE_CTRL_H
5#include <wx/dcbuffer.h>
17template<
typename Tval>
18Tval
wxClip(Tval value, Tval min_val, Tval max_val)
20 if (value < min_val)
return min_val;
21 if (value > max_val)
return max_val;
25wxDECLARE_EVENT(wxEVT_TIMELINE_ZOOM, wxCommandEvent);
26wxDECLARE_EVENT(wxEVT_TIMELINE_SELECTION, wxCommandEvent);
27wxDECLARE_EVENT(wxEVT_TIMELINE_ITEM_DELETED, wxCommandEvent);
62 wxTimelineCtrl(wxWindow* parent, wxWindowID
id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize)
65 Create(parent,
id, pos, size);
75 bool Create(wxWindow* parent, wxWindowID
id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize)
77 if (!wxControl::Create(parent,
id, pos, size, wxWANTS_CHARS | wxNO_BORDER))
79 SetBackgroundStyle(wxBG_STYLE_PAINT);
95 if (startTime < 0) startTime = 0;
99 int newDuration = endTime - startTime;
101 wxLogDebug(
"ZoomToSelection: startTime=%d, endTime=%d, newDuration=%d",
102 startTime, endTime, newDuration);
106 int padding = newDuration / 20;
107 if (padding < 1) padding = 1;
109 startTime = wxMax(0, startTime - padding);
116 wxCommandEvent event(wxEVT_TIMELINE_ZOOM, GetId());
117 event.SetEventObject(
this);
119 ProcessWindowEvent(event);
121 wxLogDebug(
"Zoom applied: firstVisible=%d, duration=%d",
136 int halfZoom = zoomLevel / 2;
137 int startTime = wxMax(0, timePoint - halfZoom);
142 wxLogDebug(
"ZoomToTimePoint: timePoint=%d, zoomLevel=%d, visible=%d-%d",
143 timePoint, zoomLevel, startTime, endTime);
145 wxCommandEvent event(wxEVT_TIMELINE_ZOOM, GetId());
146 event.SetEventObject(
this);
148 ProcessWindowEvent(event);
186 wxLogDebug(
"SelectItem: index=%d, clearPrevious=%d", (
int)index, clearPrevious);
190 wxLogDebug(
"SelectItem: index %d out of range (size=%d)", (
int)index, (
int)
m_items.size());
196 wxLogDebug(
"SelectItem: clearing previous selection");
202 wxLogDebug(
"SelectItem: adding index %d to selection", (
int)index);
204 wxLogDebug(
"SelectItem: selection size now %d", (
int)
m_selectedItems.size());
207 wxLogDebug(
"Current selection after SelectItem:");
209 wxLogDebug(
" Selected item %d: index=%d", (
int)i, (
int)
m_selectedItems[i]);
234 wxCommandEvent event(wxEVT_TIMELINE_ZOOM, GetId());
235 event.SetEventObject(
this);
237 ProcessWindowEvent(event);
244 wxLogDebug(
"ShowAllTimeline: firstVisible=%d, duration=%d",
249 void AddItem(T* data,
const wxColour& colour = wxNullColour);
254 if (index >=
m_items.size() || !colour.IsOk())
257 m_items[index].SetColour(colour);
265 if (!data || !colour.IsOk())
271 it->SetColour(colour);
294 int itemEndTime = item.Data->GetEndTime();
295 if (itemEndTime > maxEndTime)
296 maxEndTime = itemEndTime;
300 int newDuration = maxEndTime;
312 if (it->Data == data)
342 std::swap(*it1, *it2);
349 wxImage::HSVValue hsv(0, 1, 1);
351 hsv.hue = modf(index * 0.07, &dummy);
353 wxImage::RGBValue rgb = wxImage::HSVtoRGB(hsv);
354 wxColour color(rgb.red, rgb.green, rgb.blue);
355 return color.ChangeLightness(90);
372 for (
const auto& item :
m_items)
374 if (item.Data == data)
397 if (startSeconds >= endSeconds)
400 int newDuration = endSeconds - startSeconds;
419 if (fixedTimePosition < 0)
422 double relativePos = 0.5;
432 int newFirstVisible = fixedTimePosition - wxRound(relativePos * newDuration);
436 if (newFirstVisible < 0)
448 wxCommandEvent event(wxEVT_TIMELINE_ZOOM, GetId());
449 event.SetEventObject(
this);
451 ProcessWindowEvent(event);
456 if (abs(deltaSeconds) == 1)
515 void OnPaint(wxPaintEvent& evt);
523 void OnMouse(wxMouseEvent& evt);
524 void OnSize(wxSizeEvent& evt);
525 void OnTimer(wxTimerEvent& evt);
567 typename TimelineItemVector::iterator
FindItem(T* data)
571 if (it->Data == data)
605 int minutes = seconds / 60;
606 int secs = seconds % 60;
607 return wxString::Format(
"%d:%02d", minutes, secs);
TimelineElementState
Definition TimelineItem.h:12
Definition TimelineArtProvider.h:15
void SetBackgroundColour(const wxColour &colour)
Definition TimelineArtProvider.h:205
Definition TimelineItem.h:22
Definition wxTimelineCtrl.h:38
void SetEventHandlers()
Definition wxTimelineCtrl_impl.h:66
int m_minVisibleDuration
Definition wxTimelineCtrl.h:625
int m_moveDirection
Definition wxTimelineCtrl.h:651
wxRect m_dropIndicatorRect
Definition wxTimelineCtrl.h:706
void ToggleItemSelection(size_t index)
Definition wxTimelineCtrl.h:173
void OnTimelineItemChangeRight(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1157
void CenterOnTime(int seconds)
Definition wxTimelineCtrl.h:489
bool m_isSelecting
Definition wxTimelineCtrl.h:598
wxVector< TimelineItem< T > > TimelineItemVector
Definition wxTimelineCtrl.h:40
void OnArrowDown(bool isLeft)
Definition wxTimelineCtrl_impl.h:1968
TimelineItem< T > m_detachedDragItemVisual
Definition wxTimelineCtrl.h:681
void SetFirstVisibleTime(int seconds)
Definition wxTimelineCtrl_impl.h:2029
int m_dragScrollerItemInitialClickTimeOffset
Definition wxTimelineCtrl.h:691
int GetLastVisibleTime() const
Definition wxTimelineCtrl.h:393
wxCursor GetCursorFromType(ElementType type)
Definition wxTimelineCtrl_impl.h:1786
wxSize m_floatingItemVisualSize
Definition wxTimelineCtrl.h:698
wxRect m_rectScroller
Definition wxTimelineCtrl.h:632
ElementType
Definition wxTimelineCtrl.h:44
@ ET_VISIBLE_FRAME
Definition wxTimelineCtrl.h:48
@ ET_MAX
Definition wxTimelineCtrl.h:57
@ ET_VISIBLE_FRAME_RIGHT
Definition wxTimelineCtrl.h:50
@ ET_NONE
Definition wxTimelineCtrl.h:45
@ ET_TIMELINE
Definition wxTimelineCtrl.h:46
@ ET_RIGHT_ARROW
Definition wxTimelineCtrl.h:52
@ ET_TIMELINE_ITEM_MAX
Definition wxTimelineCtrl.h:55
@ ET_LEFT_ARROW
Definition wxTimelineCtrl.h:51
@ ET_VISIBLE_FRAME_LEFT
Definition wxTimelineCtrl.h:49
@ ET_TIMELINE_SELECTION
Definition wxTimelineCtrl.h:56
@ ET_SCROLLER_ITEM_DRAG
Definition wxTimelineCtrl.h:53
@ ET_TIMELINE_ITEM
Definition wxTimelineCtrl.h:54
@ ET_SCROLLER
Definition wxTimelineCtrl.h:47
int ScrollerCoordToTime(int coord) const
Definition wxTimelineCtrl_impl.h:2118
void OnLeaveElement(ElementType type)
Definition wxTimelineCtrl_impl.h:946
int m_dragVisibleDuration
Definition wxTimelineCtrl.h:654
wxPoint m_selectionStart
Definition wxTimelineCtrl.h:599
wxRect m_originalPositionPlaceholderRectScroller
Definition wxTimelineCtrl.h:687
void OnVisibleFrameDrag(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1838
void OnTimelineUp(const wxPoint &pos, ElementType type)
Definition wxTimelineCtrl_impl.h:1030
int m_hoveredScrollerItemIndex
Definition wxTimelineCtrl.h:663
int m_dragPreviewTime
Definition wxTimelineCtrl.h:655
wxBitmap m_buffer
Definition wxTimelineCtrl.h:610
wxRect m_rectLeftArrowDraw
Definition wxTimelineCtrl.h:638
wxRect m_rectTimeline
Definition wxTimelineCtrl.h:631
void OnVisibleFrameUp(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1806
void OnTimer(wxTimerEvent &evt)
Definition wxTimelineCtrl_impl.h:1180
bool IsItemSelected(size_t index) const
Definition wxTimelineCtrl.h:167
int m_visibleDuration
Definition wxTimelineCtrl.h:621
void OnSize(wxSizeEvent &evt)
Definition wxTimelineCtrl_impl.h:345
void AddItem(T *data, const wxColour &colour=wxNullColour)
Definition wxTimelineCtrl_impl.h:2242
int m_maxVisibleDuration
Definition wxTimelineCtrl.h:626
void SetTotalDuration(int seconds)
Definition wxTimelineCtrl_impl.h:2141
void RemoveContextScrollerItem()
Definition wxTimelineCtrl_impl.h:2314
wxPoint m_cursorToDetachedVisualOffset
Definition wxTimelineCtrl.h:690
void OnVisibleFrameDown(const wxPoint &pos, ElementType type)
Definition wxTimelineCtrl_impl.h:1821
TimelineItemVector::iterator m_lastTask
Definition wxTimelineCtrl.h:586
void RemoveSelectedItems()
Definition wxTimelineCtrl_impl.h:2272
void OnMouseDown(ElementType type, const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1464
int m_contextMenuItemIndex
Definition wxTimelineCtrl.h:665
wxColour m_originalPositionPlaceholderColour
Definition wxTimelineCtrl.h:688
void AdjustMainViewToScrollerView()
Definition wxTimelineCtrl_impl.h:2207
void OnMouse(wxMouseEvent &evt)
Definition wxTimelineCtrl_impl.h:598
void OnEraseBackground(wxEraseEvent &evt)
Definition wxTimelineCtrl_impl.h:116
wxTimelineCtrl()
Definition wxTimelineCtrl.h:61
void RecalcVisibleFrame()
Definition wxTimelineCtrl_impl.h:386
bool m_mouseDown
Definition wxTimelineCtrl.h:649
int TimelineCoordToTime(int coord)
Definition wxTimelineCtrl.h:503
void SelectItem(size_t index, bool clearPrevious=true)
Definition wxTimelineCtrl.h:184
int m_colorCounter
Definition wxTimelineCtrl.h:646
wxRect m_rectScrollerTimeScale
Definition wxTimelineCtrl.h:641
wxColour GetItemColor(T *data) const
Definition wxTimelineCtrl.h:367
void OnTimelineItemChangeLeft(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1131
void TimeChanged()
Definition wxTimelineCtrl_impl.h:1381
bool m_isDraggingFloatingItem
Definition wxTimelineCtrl.h:693
static const int MAX_ITEMS
Definition wxTimelineCtrl.h:41
wxDateTime m_startTime
Definition wxTimelineCtrl.h:628
void DrawScroller(wxDC &dc)
Definition wxTimelineCtrl_impl.h:256
int m_resizeBorder
Definition wxTimelineCtrl.h:678
int TimelineTimeToCoord(int time)
Definition wxTimelineCtrl.h:496
wxRect m_rectRightArrow
Definition wxTimelineCtrl.h:637
ElementType m_selectedElement
Definition wxTimelineCtrl.h:643
int m_minScrollerVisibleDuration
Definition wxTimelineCtrl.h:619
void DrawTimeline(wxDC &dc)
Definition wxTimelineCtrl_impl.h:141
void OnArrowUp(bool isLeft)
Definition wxTimelineCtrl_impl.h:1989
wxRect m_rectTimelineMain
Definition wxTimelineCtrl.h:639
void ClearSelection()
Definition wxTimelineCtrl.h:151
int GetTotalDuration() const
Definition wxTimelineCtrl.h:387
wxRect m_rectTimelineTrack
Definition wxTimelineCtrl.h:634
TimelineItem< T > m_floatingItemVisualData
Definition wxTimelineCtrl.h:696
wxColour GetItemColor(size_t index) const
Definition wxTimelineCtrl.h:359
void Zoom(int deltaSeconds)
Definition wxTimelineCtrl.h:454
void SetVisibleDuration(int seconds)
Definition wxTimelineCtrl_impl.h:2072
void Init()
Definition wxTimelineCtrl_impl.h:4
wxRect m_rectBackground
Definition wxTimelineCtrl.h:630
wxRect m_dropTargetOnScrollerRect
Definition wxTimelineCtrl.h:704
void SetZoomLevel(int zoomLevelSeconds)
Definition wxTimelineCtrl.h:224
int m_ArrowDrawWidth
Definition wxTimelineCtrl.h:671
wxRect m_rectScrollerTrack
Definition wxTimelineCtrl.h:633
int ClampFirstVisibleTime(int first) const
Definition wxTimelineCtrl_impl.h:2262
void SwapItems(T *item1, T *item2)
Definition wxTimelineCtrl.h:337
wxSize m_detachedDragItemSize
Definition wxTimelineCtrl.h:684
void SetDefaultDuration(int seconds)
Definition wxTimelineCtrl.h:383
void SetVisibleTimeRange(int startSeconds, int endSeconds)
Definition wxTimelineCtrl.h:395
void OnKeyDown(wxKeyEvent &evt)
Definition wxTimelineCtrl_impl.h:1262
wxRect m_rectTimelineTimeScale
Definition wxTimelineCtrl.h:642
int m_scrollerFirstVisibleTime
Definition wxTimelineCtrl.h:617
virtual ~wxTimelineCtrl()
Definition wxTimelineCtrl.h:68
void RecalcRects()
Definition wxTimelineCtrl_impl.h:354
wxPoint m_selectionEnd
Definition wxTimelineCtrl.h:600
void ZoomToTimePoint(int timePoint, int zoomLevel=-1)
Definition wxTimelineCtrl.h:127
int m_dragFirstVisibleTime
Definition wxTimelineCtrl.h:653
int m_draggedScrollerItemIndex
Definition wxTimelineCtrl.h:664
wxPoint m_detachedDragItemScreenPos
Definition wxTimelineCtrl.h:683
void OnTimelineDrag(const wxPoint &pos, ElementType type)
Definition wxTimelineCtrl_impl.h:1041
wxRect m_dropIndicatorRectScroller
Definition wxTimelineCtrl.h:707
TimelineItemVector::iterator m_visibleItemBegin
Definition wxTimelineCtrl.h:587
void Draw(wxDC &dc)
Definition wxTimelineCtrl_impl.h:119
bool SetItemColor(T *data, const wxColour &colour)
Definition wxTimelineCtrl.h:263
int m_ArrowDrawHeight
Definition wxTimelineCtrl.h:672
wxRect m_selectionRect
Definition wxTimelineCtrl.h:601
int m_TimelineVMargin
Definition wxTimelineCtrl.h:676
void CalcMaxVisibleDuration()
Definition wxTimelineCtrl_impl.h:2012
wxPoint m_cursorToFloatingWinOffset
Definition wxTimelineCtrl.h:700
void OnScrollerDown(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1960
int GetFirstVisibleTime() const
Definition wxTimelineCtrl.h:392
int m_defaultDuration
Definition wxTimelineCtrl.h:622
void SetZoomPreset(ZoomPreset preset)
Definition wxTimelineCtrl.h:474
TimelineItemVector::iterator FindItem(T *data)
Definition wxTimelineCtrl.h:567
void RecalcItems()
Definition wxTimelineCtrl_impl.h:440
TimelineElementState m_stateLeftArrow
Definition wxTimelineCtrl.h:658
wxTimelineCtrl(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition wxTimelineCtrl.h:62
int m_GapHeight
Definition wxTimelineCtrl.h:669
void SendItemEvent(wxEventType evtType, int index)
Definition wxTimelineCtrl_impl.h:2002
void ChangeLastElement(ElementType type)
Definition wxTimelineCtrl_impl.h:1457
int GetDefaultDuration() const
Definition wxTimelineCtrl.h:384
bool m_isSnapping
Definition wxTimelineCtrl.h:656
TimelineArtProvider * m_artProvider
Definition wxTimelineCtrl.h:580
bool SetItemColor(size_t index, const wxColour &colour)
Definition wxTimelineCtrl.h:252
void UpdateTotalDurationForItems()
Definition wxTimelineCtrl.h:279
wxPoint m_dragCurrentPos
Definition wxTimelineCtrl.h:594
void OnEnterElement(ElementType type)
Definition wxTimelineCtrl_impl.h:903
wxTimer m_timerMove
Definition wxTimelineCtrl.h:612
int m_scrollerVisibleDuration
Definition wxTimelineCtrl.h:618
FloatingItemPopupWindow< T > * m_pFloatingItemWin
Definition wxTimelineCtrl.h:694
bool m_showOriginalPositionPlaceholder
Definition wxTimelineCtrl.h:686
int m_clickToItemTimeOffset
Definition wxTimelineCtrl.h:701
void OnTimelineDown(const wxPoint &pos, ElementType type)
Definition wxTimelineCtrl_impl.h:990
wxRect m_rectLeftArrow
Definition wxTimelineCtrl.h:637
int m_ArrowWidth
Definition wxTimelineCtrl.h:670
void ZoomAtPosition(int deltaSeconds, int fixedTimePosition=-1)
Definition wxTimelineCtrl.h:417
bool m_showDropTargetOnScroller
Definition wxTimelineCtrl.h:703
const wxVector< size_t > & GetSelectedItems() const
Definition wxTimelineCtrl.h:161
void OnPaint(wxPaintEvent &evt)
Definition wxTimelineCtrl_impl.h:108
wxVector< size_t > m_selectedItems
Definition wxTimelineCtrl.h:591
void OnMouseUp(ElementType type, const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1635
int m_totalDuration
Definition wxTimelineCtrl.h:614
void ShowContextMenu(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1215
int GetVisibleDuration() const
Definition wxTimelineCtrl.h:415
void OnMouseDrag(ElementType type, const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1507
wxRect m_rectVisibleFrameRight
Definition wxTimelineCtrl.h:636
ElementType m_lastElement
Definition wxTimelineCtrl.h:644
bool m_mouseCaptured
Definition wxTimelineCtrl.h:648
ElementType GetElementFromPos(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1390
TimelineItemVector m_items
Definition wxTimelineCtrl.h:582
TimelineElementState m_stateRightArrow
Definition wxTimelineCtrl.h:659
int m_ScrollerHeight
Definition wxTimelineCtrl.h:668
bool m_isDraggingDetachedItem
Definition wxTimelineCtrl.h:680
int m_ScrollerVMargin
Definition wxTimelineCtrl.h:677
wxColour GetItemColour(int index)
Definition wxTimelineCtrl.h:347
void RemoveItem(T *data)
Definition wxTimelineCtrl.h:308
int m_detachedDragItemOriginalIndex
Definition wxTimelineCtrl.h:682
wxRect m_rectScrollerMain
Definition wxTimelineCtrl.h:640
int m_ScrollerTimeScaleHeight
Definition wxTimelineCtrl.h:673
void SetStartTime(const wxDateTime &val)
Definition wxTimelineCtrl.h:380
int m_floatingItemOriginalIndex
Definition wxTimelineCtrl.h:697
void ClearItems()
Definition wxTimelineCtrl.h:330
void ZoomToSelection()
Definition wxTimelineCtrl.h:88
int m_TimelineTimeScaleHeight
Definition wxTimelineCtrl.h:674
TimelineElementState m_stateVisibleFrame
Definition wxTimelineCtrl.h:660
wxDateTime GetStartTime() const
Definition wxTimelineCtrl.h:381
void OnMouseCaptureLost(wxMouseCaptureLostEvent &evt)
Definition wxTimelineCtrl_impl.h:980
int m_firstVisibleTime
Definition wxTimelineCtrl.h:615
wxPoint m_dragStartPos
Definition wxTimelineCtrl.h:593
bool Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition wxTimelineCtrl.h:75
wxString FormatTime(int seconds) const
Definition wxTimelineCtrl.h:603
int GetZoomLevel() const
Definition wxTimelineCtrl.h:219
int m_totalTime
Definition wxTimelineCtrl.h:623
TimelineItemVector::iterator m_activeTask
Definition wxTimelineCtrl.h:585
void ShowAllTimeline()
Definition wxTimelineCtrl.h:240
void OnTimelineItemMove(const wxPoint &pos)
Definition wxTimelineCtrl_impl.h:1048
TimelineItemVector::iterator m_visibleItemEnd
Definition wxTimelineCtrl.h:588
int m_MinItemSize
Definition wxTimelineCtrl.h:675
wxRect m_rectRightArrowDraw
Definition wxTimelineCtrl.h:638
wxRect m_rectVisibleFrameLeft
Definition wxTimelineCtrl.h:636
wxRect m_rectVisibleFrame
Definition wxTimelineCtrl.h:635
wxPoint m_ptEndPos
Definition wxTimelineCtrl.h:596
int ScrollerTimeToCoord(int time)
Definition wxTimelineCtrl_impl.h:2129
ZoomPreset
Definition wxTimelineCtrl.h:464
@ ZOOM_MINUTES_10
Definition wxTimelineCtrl.h:470
@ ZOOM_ALL
Definition wxTimelineCtrl.h:471
@ ZOOM_MINUTES_2
Definition wxTimelineCtrl.h:468
@ ZOOM_MINUTE_1
Definition wxTimelineCtrl.h:467
@ ZOOM_SECONDS_30
Definition wxTimelineCtrl.h:466
@ ZOOM_SECONDS_10
Definition wxTimelineCtrl.h:465
@ ZOOM_MINUTES_5
Definition wxTimelineCtrl.h:469
void CalcArrowsState()
Definition wxTimelineCtrl_impl.h:1370
wxPoint m_ptStartPos
Definition wxTimelineCtrl.h:595
@ ID_TIMELINE_DELETE_SCROLLER_ITEM
Definition wxTimelineCtrl.h:32
@ ID_TIMELINE_DELETE
Definition wxTimelineCtrl.h:31
Tval wxClip(Tval value, Tval min_val, Tval max_val)
Definition wxTimelineCtrl.h:18