void initControls(bool checkFrame) { numEndSec.Minimum = numBeginSec.Minimum = new decimal[] { _timeController.BeginTime, _timeController.SelectBeginTime, 0 }.Min(); numEndSec.Maximum = numBeginSec.Maximum = new decimal[] { _timeController.EndTime, _timeController.SelectBeginTime }.Max(); var beginIndex = _timeController.GetIndexFromTime(_timeController.VisibleBeginTime); var endIndex = _timeController.GetIndexFromTime(_timeController.VisibleEndTime); numEndFrame.Minimum = numBeginFrame.Minimum = new decimal[] { 0, beginIndex }.Min(); numEndFrame.Maximum = numBeginFrame.Maximum = new decimal[] { _timeController.IndexCount, endIndex }.Max(); try { numBeginSec.Value = _timeController.SelectBeginTime; numEndSec.Value = _timeController.SelectEndTime; numBeginFrame.Value = beginIndex; numEndFrame.Value = endIndex; } catch (ArgumentOutOfRangeException) { } radioBeginSec.Checked = radioEndSec.Checked = !checkFrame; radioBeginFrame.Checked = radioEndFrame.Checked = checkFrame; setNumEnabled(); propagateValue(); }
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; }
//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; }