private void inputSelectRangeToolStripMenuItem_Click(object sender, EventArgs e) { TimeController timeController = _timeController; if (timeController == null) { return; } Misc.DialogSetSelectRange dialog = new MotionDataHandler.Misc.DialogSetSelectRange(timeController, this.ShowsFrameIndex); dialog.ShowDialog(); }
void setSelectTimeRange() { TimeController timeController = _timeController; if (timeController == null) { return; } _beginSelectTime = timeController.SelectBeginTime; _endSelectTime = timeController.SelectEndTime; }
private void pictDisplay_MouseDoubleClick(object sender, MouseEventArgs e) { decimal time = getTimeFromPosition(e.X); TimeController timeController = _timeController; if (timeController == null) { return; } timeController.CurrentTime = time; }
private void TimeSelectionControl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { TimeController timeController = _timeController; if (timeController != null) { int addend = 1; if (e.Control) { addend = 8; } switch (e.KeyCode) { case Keys.Right: timeController.CurrentIndex += addend; timeController.CursorTime = timeController.CurrentTime; if (e.Shift) { timeController.AdjustSelectedRange(timeController.CurrentTime); } else { timeController.SelectRange(timeController.CurrentTime, timeController.CurrentTime); } e.IsInputKey = true; break; case Keys.Left: timeController.CurrentIndex -= addend; timeController.CursorTime = timeController.CurrentTime; if (e.Shift) { timeController.AdjustSelectedRange(timeController.CurrentTime); } else { timeController.SelectRange(timeController.CurrentTime, timeController.CurrentTime); } e.IsInputKey = true; break; case Keys.Down: this.CurrentTimeTabSize = Math.Min(this.Height / 2, this.CurrentTimeTabSize + addend); e.IsInputKey = true; break; case Keys.Up: this.CurrentTimeTabSize -= addend; e.IsInputKey = true; break; } } }
void _timeController_SelectedRangeChanged(object sender, EventArgs e) { TimeController timeController = _timeController; if (timeController == null) { return; } _beginSelectTime = timeController.SelectBeginTime; _endSelectTime = timeController.SelectEndTime; displayTimeBar(); }
public void DetachTimeController() { if (_timeController != null) { lock (_timeController) { _timeController.CurrentTimeChanged -= onTimeChanged; _timeController.IsPlayingChanged -= onPlayingChanged; _timeController.SettingsChanged -= onTimeControllerSettingsChanged; _timeController = null; } } }
private decimal getRuleInterval(decimal timeInterval, int minimumDisplayInterval) { TimeController timeController = _timeController; if (timeController == null) { return(0); } if (timeInterval <= 0) { return(0); } decimal ret; if (this.ShowsFrameIndex) { ret = 1M / timeController.FPS; while (ret < 5000000M) { if ((decimal)pictDisplay.Width * ret / timeInterval >= minimumDisplayInterval) { return(ret); } ret *= 5M; if (ret >= 5000000M) { break; } if ((decimal)pictDisplay.Width * ret / timeInterval >= minimumDisplayInterval) { return(ret); } ret *= 2M; } return(ret); } else { for (decimal candid = 0.0000001M; candid < 100000000M; candid *= 10M) { if ((decimal)pictDisplay.Width * candid / timeInterval >= minimumDisplayInterval) { return(candid); } if ((decimal)pictDisplay.Width * candid * 5M / timeInterval >= minimumDisplayInterval) { return(candid * 5M); } } return(timeController.Duration / 5M); } }
private void contextMenuMain_Opening(object sender, CancelEventArgs e) { resetScaleToolStripMenuItem.Visible = !this.IsGlobalTimeLineMode; selectVisibleRangeToolStripMenuItem.Visible = !this.IsGlobalTimeLineMode; menuUnzoom.Visible = !this.IsGlobalTimeLineMode; TimeController timeController = _timeController; if (timeController == null) { return; } menuZoom.Enabled = menuUnzoom.Enabled = timeController.IsSelecting && (timeController.SelectEndTime - timeController.SelectBeginTime) > 0; }
void _timeController_CursorTimeChanged(object sender, EventArgs e) { if (this.InvokeRequired) { this.BeginInvoke(new EventHandler(_timeController_CursorTimeChanged), sender, e); return; } TimeController timeController = _timeController; if (timeController == null) { return; } decimal?cursor = timeController.CursorTime; if (_prevCursor != cursor) { if (cursor.HasValue) { pictCursor.Location = new Point((int)Math.Round(getDisplayPosition(cursor.Value)), 0); pictCursor.Size = new Size(1, pictDisplay.Height); pictCursor.Visible = true; if (this.ShowsCursorTimeLabel) { labelCursor.Visible = true; if (this.ShowsFrameIndex) { labelCursor.Text = "[" + timeController.GetIndexFromTime(cursor.Value) + "]"; } else { labelCursor.Text = cursor.Value.ToString("0.000"); } if (pictCursor.Location.X + 5 + labelCursor.Width >= pictDisplay.Width) { labelCursor.Location = new Point(pictCursor.Location.X - 5 - labelCursor.Width, (pictDisplay.Height - labelCursor.Height) / 2); } else { labelCursor.Location = new Point(pictCursor.Location.X + 5, (pictDisplay.Height - labelCursor.Height) / 2); } } } else { pictCursor.Visible = false; labelCursor.Visible = false; } } _prevCursor = cursor; }
public void AttachTimeController(TimeController timeController) { DetachTimeController(); if (timeController != null) { lock (_timeController = timeController) { _timeController.CurrentTimeChanged += onTimeChanged; _timeController.IsPlayingChanged += onPlayingChanged; _timeController.SettingsChanged += onTimeControllerSettingsChanged; onTimeControllerSettingsChanged(this, new EventArgs()); } } enableControls(_timeController != null); }
private void JumpHereToolStripMenuItem_Click(object sender, EventArgs e) { TimeController timeController = _timeController; if (timeController == null) { return; } decimal?cursor = timeController.CursorTime; if (cursor.HasValue) { timeController.CurrentTime = cursor.Value; } }
private void pictDisplay_MouseMove(object sender, MouseEventArgs e) { TimeController timeController = _timeController; if (timeController == null) { return; } decimal cursorTime = getTimeFromPosition(e.X); //cursorTime = Math.Min(timeController.VisibleEndTime, Math.Max(timeController.VisibleBeginTime, cursorTime)); timeController.CursorTime = cursorTime; RegulatedMouseInfo info = _mouse.MouseMove(e); decimal timeDelta = getTimeSpanFromDelta(_mouse.MoveDelta.X); switch (info.Button) { case RegulatedMouseButton.Left: timeController.CursorTime = cursorTime; timeController.SelectRange(Math.Min(cursorTime, _selectingTime), Math.Max(cursorTime, _selectingTime)); break; case RegulatedMouseButton.CtrlLeft: timeController.CurrentTime = cursorTime; timeController.SelectRange(Math.Min(cursorTime, _selectingTime), Math.Max(cursorTime, _selectingTime)); break; case RegulatedMouseButton.AltLeft: decimal timeOffset = timeDelta; if (!this.IsGlobalTimeLineMode) { timeOffset = -timeOffset; } timeController.SetVisibleTime(timeController.VisibleBeginTime + timeOffset, timeController.VisibleEndTime + timeOffset); break; case RegulatedMouseButton.ShiftLeft: timeController.AdjustSelectedRange(cursorTime); break; case RegulatedMouseButton.ShiftCtrlLeft: timeController.CurrentTime = cursorTime; timeController.AdjustSelectedRange(cursorTime); break; } }
private void pictCurrentTab_MouseMove(object sender, MouseEventArgs e) { TimeController timeController = _timeController; if (timeController == null) { return; } if (_leftDownTab && !_rightDownTab) { timeController.CurrentTime = getTimeFromPosition(e.X + pictCurrentTab.Location.X); if ((Control.ModifierKeys & Keys.Shift) != 0) { timeController.AdjustSelectedRange(timeController.CurrentTime); } } }
void setTimeRange() { TimeController timeController = _timeController; if (timeController == null) { return; } if (this.IsGlobalTimeLineMode) { _beginTime = timeController.BeginTime; _endTime = timeController.EndTime; } else { _beginTime = timeController.VisibleBeginTime; _endTime = timeController.VisibleEndTime; } }
void setCurrentTimeBar() { if (this.InvokeRequired) { this.BeginInvoke(new Action(setCurrentTimeBar)); return; } TimeController timeController = _timeController; if (timeController == null) { return; } pictCurrent.Width = 1; pictCurrent.Height = this.Height; pictCurrent.Location = new Point((int)Math.Round(getDisplayPosition(timeController.CurrentTime)), 0); pictCurrentTab.Size = new Size(CurrentTimeTabSize, CurrentTimeTabSize); pictCurrentTab.Location = new Point(pictCurrent.Location.X - CurrentTimeTabSize / 2, 0); }
private void pictCurrentTab_MouseUp(object sender, MouseEventArgs e) { TimeController timeController = _timeController; if (timeController == null) { return; } switch (e.Button) { case MouseButtons.Left: _leftDownTab = false; setPictCurrentTab(); break; case MouseButtons.Right: _rightDownTab = false; setPictCurrentTab(); break; } }
public void AttachTimeController(TimeController timeController) { if (_timeController != null) { _timeController.CurrentTimeChanged -= new EventHandler(_timeController_TimeChanged); _timeController.VisibleRangeChanged -= new EventHandler(_timeController_SelectTimeChanged); _timeController.SelectedRangeChanged -= new EventHandler(_timeController_SelectedRangeChanged); _timeController.SettingsChanged -= new EventHandler(_timeController_SettingsChanged); _timeController.CursorTimeChanged -= new EventHandler(_timeController_CursorTimeChanged); } _timeController = timeController; if (_timeController != null) { _timeController.CurrentTimeChanged += new EventHandler(_timeController_TimeChanged); _timeController.VisibleRangeChanged += new EventHandler(_timeController_SelectTimeChanged); _timeController.SelectedRangeChanged += new EventHandler(_timeController_SelectedRangeChanged); _timeController.SettingsChanged += new EventHandler(_timeController_SettingsChanged); _timeController.CursorTimeChanged += new EventHandler(_timeController_CursorTimeChanged); setTimeRange(); setSelectTimeRange(); setCurrentTimeBar(); displayTimeBar(); } }
private void pictDisplay_MouseDown(object sender, MouseEventArgs e) { TimeController timeController = _timeController; if (timeController == null) { return; } RegulatedMouseButton button = _mouse.MouseDown(e); decimal cursorTime = getTimeFromPosition(e.X); //cursorTime = Math.Min(timeController.VisibleEndTime, Math.Max(timeController.VisibleBeginTime, cursorTime)); _selectingTime = cursorTime; switch (button) { case RegulatedMouseButton.Left: timeController.CursorTime = cursorTime; timeController.SelectRange(Math.Min(cursorTime, _selectingTime), Math.Max(cursorTime, _selectingTime)); break; case RegulatedMouseButton.CtrlLeft: timeController.CurrentTime = cursorTime; timeController.SelectRange(Math.Min(cursorTime, _selectingTime), Math.Max(cursorTime, _selectingTime)); break; case RegulatedMouseButton.ShiftCtrlLeft: timeController.AdjustSelectedRange(cursorTime); timeController.CurrentTime = cursorTime; break; case RegulatedMouseButton.ShiftLeft: timeController.AdjustSelectedRange(cursorTime); break; } }
//private float _resizeGripLength = 2f; //EnumResizeArea testResizeArea(MouseEventArgs e) { // TimeController timeController = _timeController; // if(timeController == null) // return EnumResizeArea.None; // try { // if(timeController.IsSelecting) { // float leftIndex = getDisplayPosition(_beginSelectTime); // float rightIndex = getDisplayPosition(_endSelectTime); // if(leftIndex + _resizeGripLength <= e.X && e.X <= rightIndex - _resizeGripLength) { // return EnumResizeArea.Move; // } else if(leftIndex - _resizeGripLength <= e.X && e.X <= leftIndex + _resizeGripLength) { // // 左 // return EnumResizeArea.ResizeBegin; // } else if(rightIndex - _resizeGripLength <= e.X && e.X <= rightIndex + _resizeGripLength) { // // 右 // return EnumResizeArea.ResizeEnd; // } else { // // 外 // return EnumResizeArea.None; // } // } else { // return EnumResizeArea.None; // } // } catch(OverflowException) { // return EnumResizeArea.None; // } //} //void setCursorShape(EnumResizeArea resizeMode) { // if((Control.ModifierKeys & Keys.Control) != 0) { // switch(resizeMode) { // case EnumResizeArea.None: // pictDisplay.Cursor = Cursor.Current = Cursors.Default; // break; // case EnumResizeArea.ResizeBegin: // case EnumResizeArea.ResizeEnd: // pictDisplay.Cursor = Cursor.Current = Cursors.VSplit; // break; // case EnumResizeArea.Move: // pictDisplay.Cursor = Cursor.Current = Cursors.SizeAll; // break; // } // } else { // pictDisplay.Cursor = Cursor.Current = Cursors.Default; // } //} private void displayTimeBar() { if (this.InvokeRequired) { this.BeginInvoke(new Action(displayTimeBar)); return; } int width, height; TimeController timeController = _timeController; if (timeController == null) { return; } width = pictDisplay.Width; height = pictDisplay.Height; if (width <= 0 || height <= 0) { return; } Image img = new Bitmap(width, height); using (Graphics gfx = Graphics.FromImage(img)) { gfx.Clear(getColorFocused(this.TimeLineBackColor)); Pen pen = new Pen(getColorFocused(this.TimeLineRulerColor)); Font font = new Font("UI Gothic", 10); Brush strBrush = new SolidBrush(getColorFocused(this.TimeLineRulerColor)); decimal ruleInterval = getRuleInterval(_endTime - _beginTime, 4); if (ruleInterval > 0) { int digit = (int)Math.Floor(Math.Log10((double)ruleInterval * 10)); string formatForSec = "0"; string formatForSec2 = "0.00"; if (digit < 0) { formatForSec += "."; for (int i = 0; i < -digit; i++) { formatForSec += "0"; formatForSec2 += "0"; } } decimal visibleBeginIndex = getTimeFromPosition(0) / ruleInterval; decimal visibleEndIndex = getTimeFromPosition(width) / ruleInterval; decimal beginIndex = Math.Max(timeController.BeginTime / ruleInterval, visibleBeginIndex - 10); decimal endIndex = Math.Min(timeController.EndTime / ruleInterval, visibleEndIndex + 10); for (decimal index = decimal.Ceiling(beginIndex); index < endIndex; index++) { decimal ruleTime = index * ruleInterval; float rulePos = getDisplayPosition(ruleTime); int ruleHeight = this.MinorRuleHeight; if (decimal.Round(decimal.Remainder(index, 5M)) == 0) { if (decimal.Round(decimal.Remainder(index, 10M)) == 0) { // 主目盛 ruleHeight = this.MajorRuleHeight; string ruleText; if (this.ShowsFrameIndex) { ruleText = "[" + timeController.GetIndexFromTime(ruleTime) + "]"; } else { ruleText = decimal.Round(ruleTime, Math.Max(0, -digit)).ToString(formatForSec); } var timeTextSize = gfx.MeasureString(ruleText, font); gfx.DrawString(ruleText, font, strBrush, new PointF(rulePos - timeTextSize.Width / 2f, _invertY ? (height - _subMajorRuleHeight - timeTextSize.Height) : _subMajorRuleHeight + 1)); } else { // 副目盛 ruleHeight = this.SubMajorRuleHeight; } } gfx.DrawLine(pen, new PointF(rulePos, _invertY ? height - 1 : 0), new PointF(rulePos, _invertY ? (height - ruleHeight - 1) : ruleHeight)); } string beginStr = _beginTime.ToString(formatForSec2); string endStr = _endTime.ToString(formatForSec2); var beginSize = gfx.MeasureString(beginStr, font); gfx.DrawString(beginStr, font, new SolidBrush(Color.Red), new PointF(0, _invertY ? (height - 1 - beginSize.Height) : 0)); var endSize = gfx.MeasureString(endStr, font); gfx.DrawString(endStr, font, new SolidBrush(Color.Red), new PointF(width - endSize.Width, _invertY ? (height - 1 - beginSize.Height) : 0)); } float beginVisiblePos = getDisplayPosition(timeController.VisibleBeginTime); float endVisiblePos = getDisplayPosition(timeController.VisibleEndTime); Brush invisibleBrush = new SolidBrush(Color.FromArgb(64, Color.Black)); gfx.FillRectangle(invisibleBrush, new RectangleF(0, 0, beginVisiblePos, height)); gfx.FillRectangle(invisibleBrush, new RectangleF(endVisiblePos, 0, width - endVisiblePos, height)); if (timeController.IsSelecting) { float beginSelectPos = getDisplayPosition(_beginSelectTime); float endSelectPos = getDisplayPosition(_endSelectTime); float markerheight = 5; float markerWidth = markerheight * (float)Math.Sqrt(3) / 2; float topY = this.InvertY ? height - 1 : 0; float middleY = this.InvertY ? height - markerheight - 1 : markerheight; float lineY = this.InvertY ? (height - markerheight) * 0.8f - 1 : markerheight + (height - markerheight) * 0.2f; float bottomY = this.InvertY ? 0 : height - 1; Color color = getColorFocused(this.TimeLineSelectColor); Brush fillBgBrush = new SolidBrush(Color.FromArgb(64, color)); Brush fillBrush = new SolidBrush(color); Pen fillPen = new Pen(color); RectangleF fillRect = new RectangleF(beginSelectPos, 0, endSelectPos - beginSelectPos, height); gfx.FillRectangle(fillBgBrush, fillRect); foreach (float pos in new float[] { beginSelectPos, endSelectPos }) { PointF[] triangle = new PointF[] { new PointF(pos, middleY), new PointF(pos + markerWidth, topY), new PointF(pos - markerWidth, topY) }; gfx.FillPolygon(fillBrush, triangle); gfx.DrawPolygon(fillPen, triangle); gfx.DrawLine(fillPen, new PointF(pos, middleY), new PointF(pos, bottomY)); } gfx.DrawLine(fillPen, new PointF(beginSelectPos, lineY), new PointF(endSelectPos, lineY)); } } pictDisplay.Image = img; }