/* #endregion Public Static Fields */
        /* #region Private Methods */
        private IViewport GetViewport()
        {
            var uspan    = UVWavHelpers.GetUSpan(this.StartMs, this.EndMs);
            var viewport = new Viewport()
            {
                Left = uspan.Value, Width = uspan.Width, Top = 0, Height = uspan.Width
            };

            return(viewport);
        }
Ejemplo n.º 2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)), (Pen)null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));

            if (!this.CursorMs.HasValue)
            {
            }
            else
            {
                var cu    = (double)this.CursorMs.Value / (double)UVWavHelpers.FullRangeProjection.Width;
                var uspan = UVWavHelpers.GetUSpan(this.StartMs, this.EndMs);
                var lineX = this.ActualWidth * (cu - uspan.Value) / uspan.Width;
                var pen   = new Pen(this.Foreground, this.CursorWidth);
                drawingContext.DrawLine(pen, new System.Windows.Point(lineX, 0), new System.Windows.Point(lineX, this.ActualHeight));
            }
        }
Ejemplo n.º 3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var source = value as IViewMs;

            if (source == null)
            {
                return(null);
            }
            var uspan = UVWavHelpers.GetUSpan(source.StartMs, source.EndMs);

            return(new Viewport
            {
                Left = uspan.Value,
                Width = uspan.Width,
                Top = 0,
                Height = 1.0
            });
        }
        protected override Size MeasureOverride(Size availableSize)
        {
            const double heightProp = 1.0;
            var          baseVal    = base.MeasureOverride(availableSize);

            var tc = TimeCode.FromFrames(this.OffsetFrames, this.FrameRate);

            foreach (var elem in this.SubtitleElements)
            {
                var subtitle   = elem.Item;
                var subStartMs = (subtitle.RecordIn.TotalSeconds - tc.TotalSeconds) * 1000.0;
                var subEndMs   = (subtitle.RecordOut.TotalSeconds - tc.TotalSeconds) * 1000.0;
                var inRange    = subStartMs >= this.StartMs && subStartMs <= this.EndMs || subEndMs >= this.StartMs && subEndMs <= this.EndMs || subStartMs <this.StartMs && subEndMs> this.EndMs;
                if (!inRange)
                {
                    continue;
                }
                var uspan     = UVWavHelpers.GetUSpan(this.StartMs, this.EndMs);
                var subStartU = (double)subStartMs / (double)UVWavHelpers.FullRangeProjection.Width;
                var leftPix   = this.ActualWidth * (subStartU - uspan.Value) / uspan.Width;
                var subEndU   = (double)subEndMs / (double)UVWavHelpers.FullRangeProjection.Width;
                var subEndX   = this.ActualWidth * (subEndU - uspan.Value) / uspan.Width;

                var pen = new Pen(Brushes.Purple, 1.0);
                pen = null;
                //var top = this.ActualHeight * ((1.0 - heightProp) / 2.0);
                var topPix    = this.ActualHeight * ((1.0 - heightProp));
                var bottomPix = topPix + this.ActualHeight * heightProp;
                var rightPix  = leftPix + subEndX - leftPix;

                elem.Element.HasCroppedLeft  = leftPix < 0;
                elem.Element.HasCroppedRight = rightPix > this.ActualWidth;

                leftPix   = leftPix < 0 ? 0 : leftPix;
                rightPix  = rightPix > this.ActualWidth ? this.ActualWidth : rightPix;
                topPix    = topPix < 0 ? 0 : topPix;
                bottomPix = bottomPix > this.ActualHeight ? this.ActualHeight : bottomPix;

                var rect = new Rect(leftPix, topPix, rightPix - leftPix, bottomPix - topPix);
                elem.Rect = rect;
                elem.Element.Measure(rect.Size);
            }
            return(baseVal);
        }
        /* #endregion Private Methods */
        /* #region Protected Methods */
        protected override Size ArrangeOverride(Size finalSize)
        {
            var baseVal = base.ArrangeOverride(finalSize);
            //foreach(FrameworkElement child in this.Children)
            //{
            //    var imageRect = new Rect(0,0, 200,200);
            //    child.Arrange(imageRect);
            //}
            var viewport = this.GetViewport();
            var uspan    = UVWavHelpers.GetUSpan(this.StartMs, this.EndMs);

            foreach (var kvp in this.TileControls)
            {
                QuadkeyHelpers.QuadKeyToTileXY(kvp.Key, out int tileX, out int tileY, out int ld);
                var tile        = new Tile(tileX, tileY, ld);
                var tileUV      = tile.Viewport();
                var imageLeft   = finalSize.Width * (tileUV.Left - uspan.Value) / uspan.Width;
                var imageRight  = finalSize.Width * ((tileUV.Left + tileUV.Width) - uspan.Value) / uspan.Width;
                var tileLeftMs  = tileUV.Left * UVWavHelpers.FullRangeProjection.Width;
                var tileWidthMs = tileUV.Width * UVWavHelpers.FullRangeProjection.Width;
                var imageTop    = 0.0;
                var imageHeight = finalSize.Height;
                //var imageLeft = 0.0;
                //var imageWidth = 100.0;
                //var imageTop = 0.0;
                //var imageHeight = 100.0;
                var imageRect = new Rect(imageLeft, imageTop, imageRight - imageLeft, imageHeight);
                //kvp.Value.SetValue(Canvas.LeftProperty, imageLeft);
                //kvp.Value.SetValue(Canvas.TopProperty, imageTop);
                //kvp.Value.Width = imageWidth;
                //kvp.Value.Height = imageHeight;
                kvp.Value.Arrange(imageRect);
            }

            return(finalSize);
        }