// Called by the DataStream when new data is available. public void UpdateData(AppSpecificationDescriptor description) { // if the existing description is not null, make it null if (null != _description) { _description = null; } // set the description to this new value _description = description; // Now make sure that the current selectionX/Y are valid for this page. ChannelBox current = _description.Nearest(_selectionX, _selectionY); if (current != null) { _selectionX = current.Column; _selectionY = current.Row; } // we got data from the receiver. Make ourselves visible if (!_overlaySurface.Visible) { _overlaySurface.Visible = true; } UpdateDisplayAndAudio(); }
// Called after UI _description available private void Render() { AspectRatios ar = FromSize(_overlaySurface.RenderingMode.PlayerViewportSize.Width, _overlaySurface.RenderingMode.PlayerViewportSize.Height); if (ar == AspectRatios.AspectRatio_16x10) { _videoSurface.ZoomMode = ZoomMode.Stretched; } else { _videoSurface.ZoomMode = ZoomMode.Normal; } Microsoft.MediaCenter.UI.Point startPoint = new Microsoft.MediaCenter.UI.Point(0, 0); Bitmap image = new Bitmap(1200, 800, PixelFormat.Format32bppArgb); using (Graphics dc = Graphics.FromImage(image)) { ChannelBox current = _description.Lookup(_selectionX, _selectionY); if (current == null) { return; } int index = 0; foreach (InfoTextFormat icb in _description.InfoTexts) { SolidBrush brush = new SolidBrush(System.Drawing.Color.FromName(icb.infoColor)); Font font = new Font(icb.infoFont, icb.infoFontSize); dc.DrawString(current._infoText[index], font, brush, icb.left, icb.top); index++; } // Draw the lines around the chosen cell. SolidBrush brushText = new SolidBrush(System.Drawing.Color.FromName(_description.InfoTexts[0].infoColor)); Pen pen = new System.Drawing.Pen(brushText, 6); dc.DrawLine(pen, current.Left, current.Top, current.Left + _description.CellWidth, current.Top); dc.DrawLine(pen, current.Left, current.Top, current.Left, current.Top + _description.CellHeight); dc.DrawLine(pen, current.Left, current.Top + _description.CellHeight, current.Left + _description.CellWidth, current.Top + _description.CellHeight); dc.DrawLine(pen, current.Left + _description.CellWidth, current.Top, current.Left + _description.CellWidth, current.Top + _description.CellHeight); } _overlaySurface.BeginRegionUpdates(); _overlaySurface.UpdateRegion(startPoint, image); _overlaySurface.EndRegionUpdates(); }
// Get the channel box which is closes to the location detailed in the [arameters. public ChannelBox Nearest(int column, int row) { ChannelBox bestBox = _channelBoxes[0]; foreach (ChannelBox channelBox in _channelBoxes) { int x1 = Math.Abs(bestBox.Column - column); int y1 = Math.Abs(bestBox.Row - row); int x2 = Math.Abs(channelBox.Column - column); int y2 = Math.Abs(channelBox.Row - row); if ((x2 < x1 && y2 <= y1) || (x2 <= x1 && y2 < y1)) { bestBox = channelBox; } } return(bestBox); }
// Receive data for each Mosaic Cell. public void ReceiveCellData(int iRowIndex, int iColIndex, int iAudioPid, int iLeft, int iTop, string tuneString, string programInfo1, string programInfo2, string programInfo3) { // if we have all the info we need, just ignore. if ((null != _description) && (_description.Channels.Count != _iNumberOfCells)) { // create a channel box and populate the data ChannelBox box = new ChannelBox(iRowIndex, iColIndex, iAudioPid, iLeft, iTop, (string)tuneString); box.AddInfoText(programInfo1); box.AddInfoText(programInfo2); box.AddInfoText(programInfo3); // add this to _description _description.Channels.Add(box); // we have all our data, so set the UI. if (_description.Channels.Count == _iNumberOfCells) { _userInterface.UpdateData(_description); } } }
// Return the Audio PID for this channel box public int GetAudioPid(ChannelBox channelBox) { return(channelBox.AudioPID); }
// Moving to a different cell results only in the audio stream switch. Pressing Enter/Ok causes the tune to happen. public void ProcessKeyboardEvent(KeyCommandEventArgs args) { try { switch (args.Key) { // Move Left case Microsoft.MediaCenter.TVVM.KeyHandlerKey.Left: if (_selectionX > 0) { _selectionX--; } break; // Move Right case Microsoft.MediaCenter.TVVM.KeyHandlerKey.Right: if (_selectionX < (_description.Columns - 1)) { _selectionX++; } break; // Move Up case Microsoft.MediaCenter.TVVM.KeyHandlerKey.Up: if (_selectionY > 0) { _selectionY--; } break; // Move Down case Microsoft.MediaCenter.TVVM.KeyHandlerKey.Down: if (_selectionY < (_description.Rows - 1)) { _selectionY++; } break; // User hit OK/Enter. Tune to the channel and exit the Addin. case Microsoft.MediaCenter.TVVM.KeyHandlerKey.Return: // get the channel box ChannelBox channelBox = _description.Lookup(_selectionX, _selectionY); if (null != channelBox) { // check if this has a valid tune string if (channelBox.TuneString != string.Empty) { // Start tuning request _tuning.Tune(channelBox.TuneString, true); // Call exit. _addin.Exit(); return; } } break; } UpdateDisplayAndAudio(); } catch (Exception) { } }