Example #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());
     }
 }
Example #2
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;
        }
Example #3
0
        public void SetReserveList(List <ReserveViewItem> reserveList)
        {
            try
            {
                for (int i = 0; i < canvas.Children.Count; i++)
                {
                    if (canvas.Children[i] is Rectangle)
                    {
                        canvas.Children.RemoveAt(i--);
                    }
                }

                //0→50で塗りつぶしの不透明度が上がる
                int fillOpacity = Math.Min(EpgSetting.ReserveRectFillOpacity, 50) * 2;
                //50→100で枠の不透明度が下がる
                int strokeOpacity = Math.Min(100 - EpgSetting.ReserveRectFillOpacity, 50) * 2;
                //予約枠が色名指定のときは少し透過(0xA0)する
                Brush strokeNormal  = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorNormal, EpgSetting.ContentCustColorList[17], 0xA0, strokeOpacity);
                Brush strokeNo      = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorNo, EpgSetting.ContentCustColorList[18], 0xA0, strokeOpacity);
                Brush strokeNoTuner = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorNoTuner, EpgSetting.ContentCustColorList[19], 0xA0, strokeOpacity);
                Brush strokeWarning = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorWarning, EpgSetting.ContentCustColorList[20], 0xA0, strokeOpacity);
                Brush fillNormal    = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorNormal, EpgSetting.ContentCustColorList[17], 0xA0, fillOpacity);
                Brush fillNo        = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorNo, EpgSetting.ContentCustColorList[18], 0xA0, fillOpacity);
                Brush fillNoTuner   = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorNoTuner, EpgSetting.ContentCustColorList[19], 0xA0, fillOpacity);
                Brush fillWarning   = ColorDef.CustColorBrush(EpgSetting.ReserveRectColorWarning, EpgSetting.ContentCustColorList[20], 0xA0, fillOpacity);
                var   blurEffect    = new System.Windows.Media.Effects.DropShadowEffect()
                {
                    BlurRadius = 10
                };
                blurEffect.Freeze();
                var dashArray = new DoubleCollection()
                {
                    2.5, 1.5
                };
                dashArray.Freeze();

                foreach (ReserveViewItem info in reserveList)
                {
                    Rectangle rect         = new Rectangle();
                    Rectangle fillOnlyRect = EpgSetting.ReserveRectFillWithShadow ? null : new Rectangle();
                    Rectangle fillRect     = fillOnlyRect ?? rect;

                    if (info.ReserveInfo.RecSetting.IsNoRec())
                    {
                        rect.Stroke   = strokeNo;
                        fillRect.Fill = fillNo;
                    }
                    else if (info.ReserveInfo.OverlapMode == 2)
                    {
                        rect.Stroke   = strokeNoTuner;
                        fillRect.Fill = fillNoTuner;
                    }
                    else if (info.ReserveInfo.OverlapMode == 1)
                    {
                        rect.Stroke   = strokeWarning;
                        fillRect.Fill = fillWarning;
                    }
                    else
                    {
                        rect.Stroke   = strokeNormal;
                        fillRect.Fill = fillNormal;
                    }

                    rect.Effect          = blurEffect;
                    rect.StrokeThickness = 3;
                    if (info.ReserveInfo.RecSetting.GetRecMode() == 4)
                    {
                        rect.StrokeDashArray = dashArray;
                        rect.StrokeDashCap   = PenLineCap.Round;
                    }
                    rect.Width                = info.Width;
                    rect.Height               = info.Height;
                    rect.IsHitTestVisible     = false;
                    fillRect.Width            = info.Width;
                    fillRect.Height           = info.Height;
                    fillRect.IsHitTestVisible = false;

                    Canvas.SetLeft(rect, info.LeftPos);
                    Canvas.SetTop(rect, info.TopPos);
                    Canvas.SetZIndex(rect, 10);
                    canvas.Children.Add(rect);

                    if (fillOnlyRect != null)
                    {
                        Canvas.SetLeft(fillOnlyRect, info.LeftPos);
                        Canvas.SetTop(fillOnlyRect, info.TopPos);
                        Canvas.SetZIndex(fillOnlyRect, 9);
                        canvas.Children.Add(fillOnlyRect);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #4
0
        protected override void OnRender(DrawingContext dc)
        {
            dc.DrawRectangle(Background, null, new Rect(RenderSize));

            var ps = PresentationSource.FromVisual(this);

            if (ps == null || Items == null)
            {
                return;
            }
            Matrix m = ps.CompositionTarget.TransformToDevice;

            var itemFontTitle  = new EpgView.EpgViewPanel.ItemFont(Settings.Instance.EpgSettingList[0].FontNameTitle, Settings.Instance.EpgSettingList[0].FontBoldTitle, true);
            var itemFontNormal = new EpgView.EpgViewPanel.ItemFont(Settings.Instance.EpgSettingList[0].FontName, false, true);

            if (itemFontTitle.GlyphType == null || itemFontNormal.GlyphType == null)
            {
                return;
            }

            {
                double          sizeTitle    = Math.Max(Settings.Instance.EpgSettingList[0].FontSizeTitle, 1);
                double          sizeNormal   = Math.Max(Settings.Instance.EpgSettingList[0].FontSize, 1);
                double          indentTitle  = sizeTitle * 1.7;
                double          indentNormal = 2;
                SolidColorBrush colorTitle   = ColorDef.CustColorBrush(Settings.Instance.EpgSettingList[0].TitleColor1,
                                                                       Settings.Instance.EpgSettingList[0].TitleCustColor1);
                SolidColorBrush colorNormal = ColorDef.CustColorBrush(Settings.Instance.EpgSettingList[0].TitleColor2,
                                                                      Settings.Instance.EpgSettingList[0].TitleCustColor2);

                foreach (ReserveViewItem info in Items)
                {
                    var textDrawList = new List <Tuple <Brush, GlyphRun> >();

                    double innerLeft   = info.LeftPos + 1;
                    double innerTop    = info.TopPos + 1;
                    double innerWidth  = info.Width - 2;
                    double innerHeight = info.Height - 2;
                    double useHeight;

                    info.TitleDrawErr = true;

                    //分
                    string min = info.ReserveInfo.StartTime.Minute.ToString("d02");
                    //設計的にやや微妙だがやる事が同じなのでEpgViewPanelのメソッドを流用する
                    if (EpgView.EpgViewPanel.RenderText(min, textDrawList, itemFontTitle, sizeTitle * 0.95,
                                                        innerWidth - 1, innerHeight,
                                                        innerLeft + 1, innerTop, out useHeight, colorTitle, m, 0))
                    {
                        //サービス名
                        string serviceName = info.ReserveInfo.StationName;
                        serviceName += " (" + CommonManager.ConvertNetworkNameText(info.ReserveInfo.OriginalNetworkID) + ")";
                        if (EpgView.EpgViewPanel.RenderText(serviceName, textDrawList, itemFontTitle, sizeTitle,
                                                            innerWidth - sizeTitle * 0.5 - indentTitle, innerHeight,
                                                            innerLeft + indentTitle, innerTop, out useHeight, colorTitle, m, 0))
                        {
                            double renderTextHeight = useHeight + sizeNormal * 0.5;
                            //番組名
                            if (EpgView.EpgViewPanel.RenderText(info.ReserveInfo.Title, textDrawList, itemFontNormal, sizeNormal,
                                                                innerWidth - sizeTitle * 0.5 - indentNormal, innerHeight - renderTextHeight,
                                                                innerLeft + indentNormal, innerTop + renderTextHeight, out useHeight, colorNormal, m, 0))
                            {
                                info.TitleDrawErr = innerHeight < renderTextHeight + useHeight;
                            }
                        }
                    }

                    if (info.Width > 0 && info.Height > 0)
                    {
                        dc.DrawRectangle(Brushes.LightGray, null, new Rect(info.LeftPos, info.TopPos, info.Width, info.Height));
                    }
                    if (innerWidth > 0 && innerHeight > 0)
                    {
                        var textArea = new Rect(innerLeft, innerTop, innerWidth, innerHeight);
                        dc.DrawRectangle(info.ReserveInfo.OverlapMode == 1 ? Brushes.Yellow : Brushes.White, null, textArea);
                        dc.PushClip(new RectangleGeometry(textArea));
                        foreach (Tuple <Brush, GlyphRun> txtinfo in textDrawList)
                        {
                            dc.DrawGlyphRun(txtinfo.Item1, txtinfo.Item2);
                        }
                        dc.Pop();
                    }
                }
            }
        }