コード例 #1
0
        /// <summary>
        /// Creates a square image and attaches an event handler to the layout changed event that
        /// adds the the square in the upper right-hand corner of the TextView via the adornment layer
        /// </summary>
        /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
        public LyricalEditor(IWpfTextView view, IEnumerable<Detail> details)
        {
            this.view = view;
            var doc =
                view.TextDataModel.DocumentBuffer.Properties.GetProperty<ITextDocument>(typeof(ITextDocument));
            var file = doc.FilePath;

            detail = details.FirstOrDefault(d => Regex.IsMatch(file, d.RuleRegex));
            imageFile = SelectFile(detail, 0);

            //Grab a reference to the adornment layer that this adornment should be added to
            this.adornmentLayer = view.GetAdornmentLayer("LyricalEditor");

            view.ViewportHeightChanged += delegate { this.onSizeChange(); };
            view.ViewportWidthChanged += delegate { this.onSizeChange(); };

            if (detail.IsSlideShow)
            {
                timer.Interval = TimeSpan.FromSeconds((double)detail.SlideShowTiming);
                timer.Tick += delegate
                {
                    crntImageIndex++;
                    if (crntImageIndex >= detail.Images.Count)
                        crntImageIndex = 0;
                    imageFile = SelectFile(detail, crntImageIndex);
                    SetImage();
                };
                timer.Start();
            }
            view.Closed += delegate { timer.Stop(); };
            view.GotAggregateFocus += delegate { if (detail.IsSlideShow) timer.Start(); };
            view.LostAggregateFocus += delegate { if (detail.IsSlideShow) timer.Stop(); };
        }
コード例 #2
0
        static string SelectFile(Detail detail, int index)
        {
            if (detail == null || detail.Images.Count == 0)
                return null;

            if (detail.IsRandom)
            {
                var rand = new Random(DateTime.Now.Millisecond);
                return detail.Images[rand.Next(detail.Images.Count)];
            }
            if (!detail.IsSlideShow)
                return detail.Images[0];
            return detail.Images[index];
        }
コード例 #3
0
ファイル: Detail.cs プロジェクト: bleis-tift/LyricalEditor
 private static Detail ValueOf(string d)
 {
     var elems = d.Split('\t');
     var det = new Detail
     {
         RuleRegex = elems[0],
         Opacity = int.Parse(elems[1]),
         IsRandom = bool.Parse(elems[2]),
         IsSlideShow = bool.Parse(elems[3]),
         SlideShowTiming = decimal.Parse(elems[4]),
         Images = elems.Skip(5).ToList()
     };
     return det;
 }