public EpgControl() { this.BackColor = Color.FromArgb(0xf5, 0xf5, 0xf5); _epgTimeControl = new EpgTimeControl(); _epgTimeControl.Location = new Point(107, 3); _epgTimeControl.Size = new Size(this.Width - _epgTimeControl.Left, 15); this.Controls.Add(_epgTimeControl); _epgChannelsControl = new EpgChannelsControl(); _epgChannelsControl.Location = new Point(3, _epgTimeControl.Height + 3); _epgChannelsControl.Size = new Size(100, this.Height - _epgChannelsControl.Top - 18); this.Controls.Add(_epgChannelsControl); _epgProgramsControl = new EpgProgramsControl(); _epgProgramsControl.Location = new Point(107, _epgTimeControl.Height + 3); _epgProgramsControl.Size = new Size(this.Width - _epgProgramsControl.Left, this.Height - _epgProgramsControl.Top); _epgProgramsControl.ScrollPositionChanged += _epgProgramsControl_ScrollPositionChanged; _epgProgramsControl.ProgramClicked += _epgProgramsControl_ProgramClicked; _epgProgramsControl.ProgramContextMenu += _epgProgramsControl_ProgramContextMenu; this.Controls.Add(_epgProgramsControl); _cursorTimer = new Timer(); _cursorTimer.Tick += _cursorTimer_Tick; _cursorTimer.Interval = 5000; _cursorTimer.Start(); }
public void GotoNowTime() { int pos = EpgTimeControl.GetTimeCursorPosition(DateTime.Now.TimeOfDay, -180); pos = Math.Min(pos, 5760 - _epgProgramsControl.Width); _epgProgramsControl.ScrollLeft = (int)(-pos * _widthFactor); SetTimeIndicator(); }
protected override void OnPaint(PaintEventArgs e) { Region clippingRegion = e.Graphics.Clip; TimeSpan time = TimeSpan.FromHours(EpgControl.EpgHoursOffset); int left = 0; const int step = 15; for (int count = 0; count < (24 * 60) / step; count++) { TimeSpan nextTime = time.Add(TimeSpan.FromMinutes(step)); int nextLeft = EpgTimeControl.GetTimeCursorPosition(nextTime, 0); Rectangle visibleRectangle = new Rectangle(left - 1, 0, nextLeft - left + 1, this.Height); visibleRectangle.Intersect(e.ClipRectangle); Region cellRegion = new Region(visibleRectangle); cellRegion.Intersect(clippingRegion); if (!cellRegion.IsEmpty(e.Graphics)) { int lineLeft = Math.Max(0, left - 1); e.Graphics.DrawLine(_epgBorderPen, lineLeft, 0, lineLeft, this.Height - 1); string timeText = EpgTimeControl.GetTimeString(time); e.Graphics.DrawString(timeText, _timeFont, _timeBrush, lineLeft + 1, 2); } left = nextLeft; time = nextTime; } if (this.CursorAtTime.HasValue) { int position = EpgTimeControl.GetTimeCursorPosition(_cursorAtTime.Value, -1); e.Graphics.DrawLine(_cursorPen, position, 0, position, this.Height - 1); e.Graphics.DrawLine(_cursorShadowPen, position + 1, 0, position + 1, this.Height - 1); string timeText = EpgTimeControl.GetTimeString(this.CursorAtTime.Value); SizeF size = e.Graphics.MeasureString(timeText, _cursorFont); e.Graphics.FillRectangle(_cursorBgBrush, position + 2, 1, size.Width, size.Height); e.Graphics.DrawString(timeText, _cursorFont, _cursorBrush, position + 2, 0); } base.OnPaint(e); }
protected override void OnPaint(PaintEventArgs e) { DateTime startDate = DateTime.Today; DateTime endDate = DateTime.Today.AddDays(1); Region clippingRegion = e.Graphics.Clip; foreach (GuideProgramCell cell in _guideProgramCells) { Rectangle visibleRectangle = new Rectangle(cell.Rectangle.Location, cell.Rectangle.Size); visibleRectangle.Intersect(e.ClipRectangle); Region cellRegion = new Region(visibleRectangle); cellRegion.Intersect(clippingRegion); if (cellRegion.IsEmpty(e.Graphics)) { continue; } bool clipLeft = (visibleRectangle.Left != cell.Rectangle.Left) || cell.ClipLeft; bool clipRight = (visibleRectangle.Right != cell.Rectangle.Right) || cell.ClipRight; Padding innerPadding = new Padding(2, 2, 2, 2); bool onNow = false; if (_cursorAtTime.HasValue) { DateTime cursorTime = DateTime.Today.Add(_cursorAtTime.Value); onNow = (cell.StartTime <= cursorTime) && (cell.StopTime > cursorTime); } bool isRecording = IsRecording(cell); e.Graphics.SetClip(visibleRectangle); if (cell.GuideProgram == null) { e.Graphics.FillRectangle(_unusedAreaBrush, visibleRectangle); } else if (!cell.IsBroadcasted) { e.Graphics.FillRectangle(_channelNotBroadcastedCellBrush, visibleRectangle); } else if (cell == _highlightedCell) { e.Graphics.FillRectangle(isRecording ? _highlightRecordingCellBrush : (onNow ? _highlightOnNowCellBrush : _highlightCellBrush), visibleRectangle); } else if (isRecording) { e.Graphics.FillRectangle(_recordingCellBrush, visibleRectangle); } else if (onNow) { e.Graphics.FillRectangle(_onNowCellBrush, visibleRectangle); } if (cell.IsTop) { e.Graphics.DrawLine(_epgBorderPen, visibleRectangle.Left, cell.Rectangle.Top, visibleRectangle.Right - 1, cell.Rectangle.Top); innerPadding.Top++; } if (clipLeft) { e.Graphics.DrawLine(_epgDashedBorderPen, visibleRectangle.Left, cell.Rectangle.Top, visibleRectangle.Left, cell.Rectangle.Bottom - 1); innerPadding.Left++; } else if (cell.Rectangle.Left == 0) { e.Graphics.DrawLine(_epgBorderPen, visibleRectangle.Left, cell.Rectangle.Top, visibleRectangle.Left, cell.Rectangle.Bottom - 1); innerPadding.Left++; } Pen rightBorderPen = _epgBorderPen; if (clipRight) { rightBorderPen = _epgDashedBorderPen; } e.Graphics.DrawLine(_epgBorderPen, visibleRectangle.Right - 1, cell.Rectangle.Bottom - 1, visibleRectangle.Left, cell.Rectangle.Bottom - 1); e.Graphics.DrawLine(rightBorderPen, visibleRectangle.Right - 1, cell.Rectangle.Top, visibleRectangle.Right - 1, cell.Rectangle.Bottom - 1); int innerWidth = visibleRectangle.Width - innerPadding.Horizontal; int innerHeight = cell.Rectangle.Height - innerPadding.Vertical; if (cell.GuideProgram != null && innerWidth > 0 && innerHeight > 0) { Rectangle innerRectangle = new Rectangle(visibleRectangle.Left + innerPadding.Left, cell.Rectangle.Top + innerPadding.Top, innerWidth, innerHeight); e.Graphics.SetClip(innerRectangle); TimeSpan time = cell.GuideProgram.StartTime.TimeOfDay; TimeSpan endTime = cell.GuideProgram.StopTime.TimeOfDay; string timeText = EpgTimeControl.GetTimeString(time); string endTimeText = EpgTimeControl.GetTimeString(endTime); string timeLabelText = timeText; if (clipLeft) { timeLabelText = "<" + timeText; } if (clipRight) { timeLabelText = timeText + "-" + endTimeText; } e.Graphics.DrawString(timeLabelText, _timeFont, _timeBrush, innerRectangle.Left, innerRectangle.Top); float titleTop = innerRectangle.Top + _timeFont.GetHeight(); int titleLeft = innerRectangle.Left; bool hasIcons = DrawScheduleIcon(cell, e, titleTop, ref titleLeft, _model.UpcomingRecordingsById); hasIcons = DrawScheduleIcon(cell, e, titleTop, ref titleLeft, _model.UpcomingAlertsById) || hasIcons; hasIcons = DrawScheduleIcon(cell, e, titleTop, ref titleLeft, _model.UpcomingSuggestionsById) || hasIcons; int titleWidth = innerRectangle.Width - (titleLeft - innerRectangle.Left); bool isHighlighted = (cell == _highlightedCell); string title = cell.GuideProgram.Title; Font titleFont = isHighlighted ? _titleHighlightFont : _titleFont; Brush titleBrush = isHighlighted ? _titleHighlightBrush : _titleBrush; int charsFitted; int linesFilled; SizeF titleSize = e.Graphics.MeasureString(title, titleFont, new SizeF(titleWidth, titleFont.Height), StringFormat.GenericDefault, out charsFitted, out linesFilled); if (charsFitted < title.Length) { while (charsFitted > 0 && title[charsFitted] != ' ') { charsFitted--; } if (charsFitted == 0) { while (charsFitted < title.Length && title[charsFitted] != ' ') { charsFitted++; } } } if (charsFitted > 0) { e.Graphics.DrawString(title.Substring(0, charsFitted), titleFont, titleBrush, new RectangleF(titleLeft, titleTop, titleWidth, titleFont.Height)); titleTop += titleFont.GetHeight(); if (charsFitted == title.Length) { title = String.Empty; } else { title = title.Substring(charsFitted).TrimStart(); } } if (hasIcons) { titleTop++; } if (!String.IsNullOrEmpty(title)) { titleSize = e.Graphics.MeasureString(title, titleFont, innerRectangle.Width); e.Graphics.DrawString(title, titleFont, titleBrush, new RectangleF(innerRectangle.Left, titleTop, titleSize.Width, titleSize.Height)); titleTop += titleSize.Height; } if (titleTop < innerRectangle.Bottom) { e.Graphics.DrawString(cell.GuideProgram.CreateEpisodeTitle(), _episodeFont, _episodeBrush, new RectangleF(innerRectangle.Left, titleTop, innerRectangle.Width, innerRectangle.Height)); } } } if (this.CursorAtTime.HasValue) { int position = EpgTimeControl.GetTimeCursorPosition(_cursorAtTime.Value, -1); Rectangle timeRectangle = new Rectangle(position, 0, 2, this.Height); e.Graphics.SetClip(timeRectangle); timeRectangle.Intersect(e.ClipRectangle); Region cellRegion = new Region(timeRectangle); cellRegion.Intersect(clippingRegion); if (!cellRegion.IsEmpty(e.Graphics)) { e.Graphics.DrawLine(_cursorPen, timeRectangle.Left, timeRectangle.Top, timeRectangle.Left, timeRectangle.Bottom - 1); e.Graphics.DrawLine(_cursorShadowPen, timeRectangle.Left + 1, timeRectangle.Top, timeRectangle.Left + 1, timeRectangle.Bottom - 1); } } base.OnPaint(e); }