Ejemplo n.º 1
0
 public void SetProgramList(List <Tuple <double, List <ProgramViewItem> > > programGroupList, double height)
 {
     try
     {
         for (int i = 0; i < canvas.Children.Count; i++)
         {
             if (canvas.Children[i] is EpgViewPanel)
             {
                 canvas.Children.RemoveAt(i--);
             }
         }
         var itemFontNormal = new EpgViewPanel.ItemFont(EpgSetting.FontName, false, false);
         var itemFontTitle  = new EpgViewPanel.ItemFont(EpgSetting.FontNameTitle, EpgSetting.FontBoldTitle, false);
         var background     = new SolidColorBrush(Color.FromRgb(EpgSetting.EpgBackColorR, EpgSetting.EpgBackColorG, EpgSetting.EpgBackColorB));
         //フリーズしないとかなり重い
         background.Freeze();
         var   dictTitle   = CommonManager.CreateReplaceDictionary(EpgSetting.EpgReplacePatternTitle);
         var   dicNormal   = CommonManager.CreateReplaceDictionary(EpgSetting.EpgReplacePattern);
         Brush brushTitle  = ColorDef.CustColorBrush(EpgSetting.TitleColor1, EpgSetting.TitleCustColor1);
         Brush brushNormal = ColorDef.CustColorBrush(EpgSetting.TitleColor2, EpgSetting.TitleCustColor2);
         //ジャンル別の背景ブラシ
         var contentBrushList = new List <Brush>();
         for (int i = 0; i < EpgSetting.ContentColorList.Count; i++)
         {
             SolidColorBrush brush = ColorDef.CustColorBrush(EpgSetting.ContentColorList[i], EpgSetting.ContentCustColorList[i]);
             contentBrushList.Add(EpgSetting.EpgGradation ? (Brush)ColorDef.GradientBrush(brush.Color) : brush);
         }
         double totalWidth = 0;
         foreach (var programList in programGroupList)
         {
             EpgViewPanel item = new EpgViewPanel();
             item.Background = background;
             item.Height     = Math.Ceiling(height);
             item.Width      = programList.Item1;
             Canvas.SetLeft(item, totalWidth);
             item.Initialize(programList.Item2, EpgSetting.EpgBorderLeftSize, EpgSetting.EpgBorderTopSize,
                             false, EpgSetting.EpgTitleIndent, EpgSetting.EpgExtInfoTable,
                             dictTitle, dicNormal, itemFontTitle, itemFontNormal,
                             EpgSetting.FontSizeTitle, EpgSetting.FontSize, brushTitle, brushNormal,
                             EpgSetting.EpgBackColorA, contentBrushList);
             item.InvalidateVisual();
             canvas.Children.Add(item);
             totalWidth += programList.Item1;
         }
         //包含するCanvasにも直接適用する(Bindingは遅延するため)。GridやStackPanelで包含してもよいはずだが
         //非表示中にここを通るとなぜか包含側のActualHeight(Width)が正しく更新されず、結果スクロール不能になる
         canvasContainer.Height = canvas.Height = Math.Ceiling(height);
         canvasContainer.Width  = canvas.Width = totalWidth;
         itemFontNormal.ClearCache();
         itemFontTitle.ClearCache();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 2
0
 public void SetProgramList(List <Tuple <double, List <ProgramViewItem> > > programGroupList, double height)
 {
     try
     {
         for (int i = 0; i < canvas.Children.Count; i++)
         {
             if (canvas.Children[i] is EpgViewPanel)
             {
                 canvas.Children.RemoveAt(i--);
             }
         }
         var itemFontNormal = new EpgViewPanel.ItemFont(Settings.Instance.FontName, false, false);
         var itemFontTitle  = new EpgViewPanel.ItemFont(Settings.Instance.FontNameTitle, Settings.Instance.FontBoldTitle, false);
         epgViewPanel.Background = CommonManager.Instance.EpgBackColor;
         epgViewPanel.ReplaceDictionaryNormal = CommonManager.CreateReplaceDictionary(Settings.Instance.EpgReplacePattern);
         epgViewPanel.ReplaceDictionaryTitle  = CommonManager.CreateReplaceDictionary(Settings.Instance.EpgReplacePatternTitle);
         double totalWidth = 0;
         foreach (var programList in programGroupList)
         {
             EpgViewPanel item = new EpgViewPanel();
             item.Background              = epgViewPanel.Background;
             item.Height                  = Math.Ceiling(height);
             item.Width                   = programList.Item1;
             item.BorderLeftSize          = Settings.Instance.EpgBorderLeftSize;
             item.BorderTopSize           = Settings.Instance.EpgBorderTopSize;
             item.IsTitleIndent           = Settings.Instance.EpgTitleIndent;
             item.ReplaceDictionaryNormal = epgViewPanel.ReplaceDictionaryNormal;
             item.ReplaceDictionaryTitle  = epgViewPanel.ReplaceDictionaryTitle;
             item.ItemFontNormal          = itemFontNormal;
             item.ItemFontTitle           = itemFontTitle;
             Canvas.SetLeft(item, totalWidth);
             item.Items = programList.Item2;
             item.InvalidateVisual();
             canvas.Children.Add(item);
             totalWidth += programList.Item1;
         }
         canvas.Height = Math.Ceiling(height);
         canvas.Width  = totalWidth;
         itemFontNormal.ClearCache();
         itemFontTitle.ClearCache();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
     }
 }
Ejemplo n.º 3
0
        protected void PopupItem()
        {
            if (EpgSetting.EpgPopup == false)
            {
                return;
            }

            List <Brush>    contentBrushList = null;
            ProgramViewItem info             = null;

            Point cursorPos2 = Mouse.GetPosition(scrollViewer);

            if (cursorPos2.X < 0 || cursorPos2.Y < 0 ||
                scrollViewer.ViewportWidth < cursorPos2.X || scrollViewer.ViewportHeight < cursorPos2.Y)
            {
                return;
            }
            Point cursorPos = Mouse.GetPosition(canvas);

            foreach (UIElement child in canvas.Children)
            {
                EpgViewPanel childPanel = child as EpgViewPanel;
                if (childPanel != null && childPanel.Items != null && Canvas.GetLeft(child) <= cursorPos.X && cursorPos.X < Canvas.GetLeft(child) + childPanel.Width)
                {
                    foreach (ProgramViewItem item in childPanel.Items)
                    {
                        if (item.LeftPos <= cursorPos.X && cursorPos.X < item.LeftPos + item.Width &&
                            item.TopPos <= cursorPos.Y && cursorPos.Y < item.TopPos + item.Height)
                        {
                            if (item == lastPopupInfo)
                            {
                                return;
                            }

                            contentBrushList = childPanel.ContentBrushList;
                            info             = item;
                            lastPopupInfo    = info;
                            break;
                        }
                    }
                    break;
                }
            }

            if (info == null)
            {
                popupItem.Visibility = System.Windows.Visibility.Hidden;
                lastPopupInfo        = null;
                return;
            }

            //この番組だけのEpgViewPanelをつくる
            popupItemPanel.Background = new SolidColorBrush(Color.FromRgb(EpgSetting.EpgBackColorR, EpgSetting.EpgBackColorG, EpgSetting.EpgBackColorB));
            popupItemPanel.Background.Freeze();
            popupItemPanel.Width = info.Width;
            var   dictTitle      = CommonManager.CreateReplaceDictionary(EpgSetting.EpgReplacePatternTitle);
            var   dicNormal      = CommonManager.CreateReplaceDictionary(EpgSetting.EpgReplacePattern);
            var   itemFontTitle  = new EpgViewPanel.ItemFont(EpgSetting.FontNameTitle, EpgSetting.FontBoldTitle, true);
            var   itemFontNormal = new EpgViewPanel.ItemFont(EpgSetting.FontName, false, true);
            Brush brushTitle     = ColorDef.CustColorBrush(EpgSetting.TitleColor1, EpgSetting.TitleCustColor1);
            Brush brushNormal    = ColorDef.CustColorBrush(EpgSetting.TitleColor2, EpgSetting.TitleCustColor2);

            Canvas.SetLeft(popupItemPanel, 0);
            var items = new List <ProgramViewItem>()
            {
                new ProgramViewItem(info.EventInfo, info.Past, info.Filtered)
            };

            items[0].Width = info.Width;

            //テキスト全体を表示できる高さを求める
            items[0].Height = 4096;
            popupItemPanel.Initialize(items, EpgSetting.EpgBorderLeftSize, EpgSetting.EpgBorderTopSize,
                                      false, EpgSetting.EpgTitleIndent, EpgSetting.EpgExtInfoPopup,
                                      dictTitle, dicNormal, itemFontTitle, itemFontNormal,
                                      EpgSetting.FontSizeTitle, EpgSetting.FontSize, brushTitle, brushNormal,
                                      EpgSetting.EpgBackColorA, contentBrushList);
            double itemHeight = Math.Max(popupItemPanel.LastItemRenderTextHeight, info.Height);
            double topPos     = info.TopPos;

            if (EpgSetting.EpgAdjustPopup)
            {
                //下方にはみ出す部分をできるだけ縮める
                double trimmableHeight = Math.Max(info.Height - popupItemPanel.LastItemRenderTextHeight, 0);
                double trimHeight      = topPos + itemHeight - (scrollViewer.VerticalOffset + Math.Floor(scrollViewer.ViewportHeight));
                trimHeight       = Math.Min(Math.Max(trimHeight, 0), trimmableHeight);
                trimmableHeight -= trimHeight;
                itemHeight      -= trimHeight;
                //下方にはみ出すなら上げる
                topPos = Math.Min(topPos, scrollViewer.VerticalOffset + Math.Floor(scrollViewer.ViewportHeight) - itemHeight);
                //上方にはみ出すなら下げる
                topPos = Math.Max(topPos, scrollViewer.VerticalOffset);
                //ポップアップ前よりも下方に伸びる部分をできるだけ縮める
                trimHeight  = topPos + itemHeight - (info.TopPos + info.Height);
                trimHeight  = Math.Min(Math.Max(trimHeight, 0), trimmableHeight);
                itemHeight -= trimHeight;
            }

            items[0].Height       = itemHeight;
            popupItemPanel.Height = itemHeight;
            popupItemPanel.Initialize(items, EpgSetting.EpgBorderLeftSize, EpgSetting.EpgBorderTopSize,
                                      topPos != info.TopPos, EpgSetting.EpgTitleIndent, EpgSetting.EpgExtInfoPopup,
                                      dictTitle, dicNormal, itemFontTitle, itemFontNormal,
                                      EpgSetting.FontSizeTitle, EpgSetting.FontSize, brushTitle, brushNormal,
                                      EpgSetting.EpgBackColorA, contentBrushList);
            popupItemPanel.InvalidateVisual();

            Canvas.SetLeft(popupItem, info.LeftPos);
            Canvas.SetTop(popupItem, topPos);
            popupItem.Visibility = System.Windows.Visibility.Visible;
        }