Esempio n. 1
0
 public override void PreprocessMouseDown(MouseButtonEventArgs e)
 {
     if (SettingsProvider.IsMiddleClickScrollEnabled() == false)
         return;
     if (this._location.HasValue)
     {
         this.StopScrolling();
         e.Handled = true;
     }
     else
     {
         if (e.ChangedButton != MouseButton.Middle || this._view.IsClosed || (!this._view.VisualElement.IsVisible || !this._view.VisualElement.CaptureMouse()))
             return;
         this._oldCursor = this._view.VisualElement.Cursor;
         this._view.VisualElement.Cursor = Cursors.ScrollAll;
         Point position = e.GetPosition((IInputElement)this._view.VisualElement);
         this._location = new Point?(this._view.VisualElement.PointToScreen(position));
         if (this._zeroPointImage == null)
         {
             BitmapSource bitmapSourceFromHicon = Imaging.CreateBitmapSourceFromHIcon(User32.LoadImage(IntPtr.Zero, new IntPtr(32654), 2U, 0, 0, 40960U), Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
             bitmapSourceFromHicon.Freeze();
             this._zeroPointImage = new Image();
             this._zeroPointImage.Source = (ImageSource)bitmapSourceFromHicon;
             this._zeroPointImage.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
             this._zeroPointImage.Opacity = 0.5;
         }
         Canvas.SetLeft((UIElement)this._zeroPointImage, this._view.ViewportLeft + position.X - this._zeroPointImage.DesiredSize.Width * 0.5);
         Canvas.SetTop((UIElement)this._zeroPointImage, this._view.ViewportTop + position.Y - this._zeroPointImage.DesiredSize.Height * 0.5);
         this._layer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, new SnapshotSpan?(), (object)null, (UIElement)this._zeroPointImage, (AdornmentRemovedCallback)null);
         this._lastMoveTime = DateTime.Now;
         this._moveTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 25), DispatcherPriority.Normal, new EventHandler(this.OnTimerElapsed), this._view.VisualElement.Dispatcher);
         this._dismissOnMouseUp = false;
         e.Handled = true;
     }
 }
        /// <summary>
        /// Process selection operation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            // if mouse button is not pressed we have no drag operation, ...
            if (e.LeftButton != MouseButtonState.Pressed)
                this.dragStartPoint = null;

            // but if mouse button is pressed and start point value is set we do have one
            if (this.dragStartPoint.HasValue)
            {
                // create connection adorner 
                DesignerCanvas designer = DiagramHelper.GetDiagramDesigner(this);
                if (designer != null)
                {
                    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designer);
                    if (adornerLayer != null)
                    {
                        DiagramConnectorAdorner adorner = new DiagramConnectorAdorner(designer, this, this.dragStartPoint.Value);
                        if (adorner != null)
                        {
                            adornerLayer.Add(adorner);
                            e.Handled = true;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public MainForm()
 {
     InitializeComponent();
     list = new List<ResponseClass>();
     strlist = new List<string>();
     prevPosition = null;
 }
Esempio n. 4
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            if (this.dragStartPoint.HasValue)
            {
                Point position = e.GetPosition(this);
                if ((SystemParameters.MinimumHorizontalDragDistance <=
                    Math.Abs((double)(position.X - this.dragStartPoint.Value.X))) ||
                    (SystemParameters.MinimumVerticalDragDistance <=
                    Math.Abs((double)(position.Y - this.dragStartPoint.Value.Y))))
                {
                    string xamlString = XamlWriter.Save(this.Content);
                    DataObject dataObject = new DataObject("DESIGNER_ITEM", xamlString);

                    if (dataObject != null)
                    {
                        DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
                    }
                }

                e.Handled = true;
            }
        }
        protected override void OnMouseMove( MouseEventArgs eventArgs )
        {
            base.OnMouseMove( eventArgs );

            if ( eventArgs.LeftButton != MouseButtonState.Pressed )
            {
                myDragStartPoint = null;
                return;
            }

            if ( !myDragStartPoint.HasValue )
            {
                return;
            }

            if ( Content == null )
            {
                return;
            }

            var dataObject = ItemContentTemplate.Create( (ItemContent)Content );
            var panel = VisualTreeHelper.GetParent( this ) as WrapPanel;
            if ( panel != null )
            {
                // desired size for DesignerCanvas is the stretched Toolbox item size
                const double scale = 1.3;
                dataObject.DesiredSize = new Size( panel.ItemWidth * scale, panel.ItemHeight * scale );
            }

            DragDrop.DoDragDrop( this, dataObject, DragDropEffects.Copy );

            eventArgs.Handled = true;
        }
Esempio n. 6
0
 public NodeOperationDetails(NodeOperation operation, INode map, Node node)
 {
     Operation = operation;
     Map = map;
     Nodes = new [] {node};
     OldLocation = node.Location;
 }
Esempio n. 7
0
 public TileData()
 {
     Height = 0;
     Type = ETileType.Grass;
     Redirect = null;
     Attachment = null;
 }
Esempio n. 8
0
 protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
 {
     base.OnMouseLeftButtonUp(e);
     _startPoint = null;
     _endPoint = null;
     System.Diagnostics.Debug.WriteLine("OnMouseLeftButtonUp");
 }
Esempio n. 9
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
                this.dragStartPoint = null;

            if (this.dragStartPoint.HasValue)
            {
                // XamlWriter.Save() has limitations in exactly what is serialized,
                // see SDK documentation; short term solution only;
                string xamlString = XamlWriter.Save(this.Content);
                DragObject dataObject = new DragObject();
                dataObject.Xaml = xamlString;

                WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel;
                if (panel != null)
                {
                    // desired size for DesignerCanvas is the stretched Toolbox item size
                    double scale = 1.3;
                    dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale);
                }

                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);

                e.Handled = true;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// This method is called each time the mouse is moved over the constrol.
        /// </summary>
        /// <param name="pEventArgs">The event arguments.</param>
        protected override void OnMouseDown(MouseButtonEventArgs pEventArgs)
        {
            base.OnMouseMove(pEventArgs);

            SimpleGraphView lParentView = this.FindVisualParent<SimpleGraphView>();
            if (this.mDragStartPoint.HasValue == false)
            {
                if (lParentView != null)
                {
                    // Position relative to DesignerCanvas.
                    this.mDragStartPoint = pEventArgs.GetPosition(lParentView);
                    pEventArgs.Handled = true;
                }
            }

            if (this.mDragStartPoint.HasValue)
            {
                // Create connection.
                if (lParentView != null)
                {
                    lParentView.ConnectionCreationBehavior.StartCreation(this);
                    pEventArgs.Handled = true;
                }
            }
        }
Esempio n. 11
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            // if mouse button is not pressed we have no drag operation, ...
            if (e.LeftButton != MouseButtonState.Pressed)
                this.rubberbandSelectionStartPoint = null;

            // ... but if mouse button is pressed and start
            // point value is set we do have one
            if (this.rubberbandSelectionStartPoint.HasValue)
            {
                // create rubberband adorner
                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
                if (adornerLayer != null)
                {
                    RubberbandAdorner adorner = new RubberbandAdorner(this, rubberbandSelectionStartPoint);
                    if (adorner != null)
                    {
                        adornerLayer.Add(adorner);
                    }
                }
            }
            e.Handled = true;
        }
        /// <summary>
        /// Handles OnMouseMove to auto-select the item that's being moused over
        /// </summary>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            var window = this.GetWindow();

            // If the cursor is currently hidden, don't bother reacting to it
            if (Cursor == Cursors.None || window.Cursor == Cursors.None)
            {
                return;
            }

            // Store the last position for comparison purposes
            // Even if the mouse is not moving this event will fire as elements are showing and hiding
            var pos = e.GetPosition(window);

            if (!_lastMouseMovePoint.HasValue)
            {
                _lastMouseMovePoint = pos;
                return;
            }

            if (pos == _lastMouseMovePoint)
            {
                return;
            }

            _lastMouseMovePoint = pos;

            Focus();
        }
Esempio n. 13
0
 private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (CaptureMouse())
     {
         mousePosition = e.GetPosition(this);
     }
 }
Esempio n. 14
0
        private void On_MouseMove(object sender, MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            if (this.dragStartPoint.HasValue)
            {
                DeviceViewModel viewModel = (sender as Image).DataContext as DeviceViewModel;
                //if (viewModel.DesignerCanvas != null)
                //    viewModel.DesignerCanvas.Toolbox.SetDefault();
                var device = viewModel.Device;
                if (device.Driver.IsPlaceable == false)
                    return;

                if (FiresecManager.LibraryConfiguration.Devices.Any(x => x.DriverId == device.DriverUID) == false)
                    return;

                ElementBase plansElement = new ElementDevice()
                {
                    DeviceUID = device.UID
                };

                var dataObject = new DataObject("DESIGNER_ITEM", plansElement);
                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
            }

            e.Handled = true;
        }
        private void source_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            /* maybe for future use
            if (e.OriginalSource is Image)
            {
                var pos = e.GetPosition((Image)e.OriginalSource);
                MessageBox.Show(pos.X + " x " + pos.Y);
            }
            */
            //  source.ZoomIn();

            if (IsScrollBarChild(e.OriginalSource as DependencyObject))
                // if the mouse click comes from the scrollbar, then we do not scroll
                lastMouseDownLocation = null;
            else
            {
                if (source.ScrollViewer != null)
                {
                    mouseHookListener.Enabled = true;

                    lastMouseDownVerticalOffset = source.ScrollViewer.VerticalOffset;
                    lastMouseDownHorizontalOffset = source.ScrollViewer.HorizontalOffset;
                    lastMouseDownLocation = source.PointToScreen(e.GetPosition(source));
                }
            }
        }
Esempio n. 16
0
        void lineBetweenElipses(object sender, MouseButtonEventArgs e)
        {
            boolean = true;
            if (_lineStart == null)
            {
                _lineStart = e.GetPosition(this);

            }
            else
            {
                _lineEnd = e.GetPosition(this);

                Line lne = new Line();
                lne.X1 = _lineStart.Value.X;
                lne.X2 = _lineEnd.Value.X;
                lne.Y1 = _lineStart.Value.Y;
                lne.Y2 = _lineEnd.Value.Y;
                lne.Stroke = Brushes.Red;
                lne.StrokeThickness = 2;
                Canvas.SetLeft(lne, 0);
                Canvas.SetTop(lne, 0);
                canvas.Children.Add(lne);
                _lineStart = null;
            }

            //    bool isSecondElipse = false;
            //    if (isSecondElipse == false)
            //    {
            //}
        }
        protected override void OnMouseClick(MouseEventArgs e)
        {
            var x = Convert.ToInt32(Math.Floor(e.X/pixelDelta));
            var y = Convert.ToInt32(Math.Floor(e.Y/pixelDelta));
            var clickPoint = new Point(x, y);

            mousePoint = clickPoint;
            edgeFirstPoint = clickPoint;

            if (currentPolygon == null)
                currentPolygon = new Polygon(clickPoint, PanelColor.BackColor);
            else
            {
                currentPolygon.TryAddVertex(clickPoint);
                if (currentPolygon.Closed)
                {
                    polygons.Add(currentPolygon);
                    currentPolygon = null;
                    edgeFirstPoint = null;
                    currentEdge = null;
                }
            }

            Invalidate();
        }
Esempio n. 18
0
        void dragElement_MouseMove(object sender, MouseEventArgs e)
        {
            FrameworkElement dragElement = (FrameworkElement)sender;
            if (startPoint != null && Mouse.LeftButton == MouseButtonState.Pressed)
            {

                Point currentPos = e.GetPosition(null);
                if ((Math.Abs(currentPos.X - startPoint.Value.X) > SystemParameters.MinimumHorizontalDragDistance) ||
                    (Math.Abs(currentPos.Y - startPoint.Value.Y) > SystemParameters.MinimumVerticalDragDistance))
                {
                    object dataObject = dataObjectFactory(dragElement);

                    startPoint = null;

                    DragDropEffects de = DragDrop.DoDragDrop(dragElement, dataObject, allowedEffects); //Leap of faith

                    if (Dropped != null)
                        Dropped(dragElement, de);
                }
            }
            else
            {
                startPoint = null;
            }
        }
Esempio n. 19
0
        private void InitializeMouse()
        {
            renderPanel.MouseDown += (sender, args) =>
            {
                _mouseCoord = new Point(args.X, args.Y);
            };
            renderPanel.MouseUp += (sender, args) =>
            {
                _mouseCoord = null;
            };
            renderPanel.MouseMove += (sender, args) =>
            {
                if (_mouseCoord == null)
                    return;

                var mouseDelta = new Point(args.X - _mouseCoord.Value.X, args.Y - _mouseCoord.Value.Y);
                _mouseCoord = new Point(args.X, args.Y);

                const double koef = 0.01;
                _mouseXMatrix.RotateMatrixX(koef * mouseDelta.Y);
                _mouseYMatrix.RotateMatrixY(koef * mouseDelta.X);

                _transformMatrix.Chain(
                    _mouseYMatrix,
                    _mouseXMatrix);

                renderPanel.Invalidate();
            };
        }
Esempio n. 20
0
        private void chart1_MouseMove(object sender, MouseEventArgs e)
        {
            var pos = e.Location;
            if (prevPosition.HasValue && pos == prevPosition.Value)
                return;
            tooltip.RemoveAll();
            prevPosition = pos;
            var results = chart1.HitTest(pos.X, pos.Y, false,
                                            ChartElementType.DataPoint);
            foreach (var result in results)
            {
                if (result.ChartElementType == ChartElementType.DataPoint)
                {
                    var prop = result.Object as DataPoint;
                    if (prop != null)
                    {
                        var pointXPixel = result.ChartArea.AxisX.ValueToPixelPosition(prop.XValue);
                        var pointYPixel = result.ChartArea.AxisY.ValueToPixelPosition(prop.YValues[0]);

                        if (Math.Abs(pos.X - pointXPixel) < 5 &&
                            Math.Abs(pos.Y - pointYPixel) < 5)
                        {
                            tooltip.Show(string.Format(Strings.GraphTip, DateTime.FromOADate(prop.XValue).ToString("HH:mm:ss"), MainScanItem.LogItem.DoFracture(prop.YValues[0].ToString()), currency), this.chart1, pos.X, pos.Y - 30);
                        }
                    }
                }
            }

        }
Esempio n. 21
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
                this.dragStartPoint = null;

            if (this.dragStartPoint.HasValue)
            {
                DragObject dataObject = new DragObject();
                if (this.Content is ShapeInfoUnit)
                {
                    dataObject.ShapeInfoUnites = new ShapeInfoUnit[]{this.Content as ShapeInfoUnit};
                }
                else if (this.Content is IEnumerable<ShapeInfoUnit>)
                {
                    var shapeInfoUnites = new List<ShapeInfoUnit>(this.Content as IEnumerable<ShapeInfoUnit>).ToArray();
                    dataObject.ShapeInfoUnites = shapeInfoUnites;
                }

                WrapPanel panel = VisualTreeHelper.GetParent(this) as WrapPanel;
                if (panel != null)
                {
                    // desired size for DesignCanvas is the stretched Toolbox item size
                    double scale = 1.3;
                    dataObject.DesiredSize = new Size(panel.ItemWidth * scale, panel.ItemHeight * scale);
                }

                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.All);

                e.Handled = true;
            }
        }
Esempio n. 22
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
                this.dragStartPoint = null;

            if (this.dragStartPoint.HasValue)
            {
                // XamlWriter.Save() has limitations in exactly what is serialized,
                // see SDK documentation; short term solution only;
                string xamlString = XamlWriter.Save(this.Content);
                DragObject dataObject = new DragObject();
                dataObject.Xaml = xamlString;
                Grid grid = this.Content as Grid;
                if (grid != null)
                {
                    RowDefinition row1 = grid.RowDefinitions[0];
                    RowDefinition row2 = grid.RowDefinitions[1];
                    double height = row1.ActualHeight + row2.ActualHeight;
                    this.Height = height;
                    dataObject.DesiredSize = new Size(this.ActualWidth, this.Height);
                }
                else
                {
                    dataObject.DesiredSize = new Size(this.ActualWidth, this.ActualHeight);
                }

                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);

                e.Handled = true;
            }
        }
        public DiagramMouseManager(Diagram diagram)
        {
            _diagram = diagram;

            _currentResizeDirection = ResizeDirection.None;

            _leftButtonAction = MouseAction.None;
            _rightButtonAction = MouseAction.None;

            _leftButtonDown = false;
            _rightButtonDown = false;
            _leftButtonDownMousePosition = null;

            _currentMousePosition = null;
            _leftButtonDownMousePosition = null;

            _itemUnderCursor = null;

            _baseXViewOffset = 0;
            _baseYViewOffset = 0;

            _offsetWorker = null;

            Selector = null;
        }
Esempio n. 24
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            Console.WriteLine("DraggableWindow.OnMouseLeftButtonDown");
            _mouseDownPoint = e.MouseDevice.GetPosition(null);

            base.OnMouseLeftButtonDown(e);
        }
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            this.TopShape.UpdateMinBounds();
            this.BottomShape.UpdateMinBounds();
            if (this.Orientation == System.Windows.Controls.Orientation.Vertical)
            {
                this.min = this.TopShape.MinBounds != Rect.Empty ? this.TopShape.MinBounds.Bottom : this.TopShape.Bounds.Top + CustomResizingService.MinShapeHeight;
                this.max = this.BottomShape.MinBounds != Rect.Empty ? this.BottomShape.MinBounds.Top : this.BottomShape.Bounds.Bottom - CustomResizingService.MinShapeHeight;
                this.topShapeStart = this.TopShape.Bounds.Bottom;
                this.start = this.Y;
            }
            else
            {
                this.min = this.TopShape.MinBounds != Rect.Empty ? this.TopShape.MinBounds.Right : this.TopShape.Bounds.Left + CustomResizingService.MinShapeWidth;
                this.max = this.BottomShape.MinBounds != Rect.Empty ? this.BottomShape.MinBounds.Left : this.BottomShape.Bounds.Right - CustomResizingService.MinShapeWidth;
                this.topShapeStart = this.TopShape.Bounds.Right;
                this.start = this.X;
            }

            this.CaptureMouse();
            this.startPosition = e.GetPosition(null);
            this.TopShape.IsInnerResize = true;
            this.BottomShape.IsInnerResize = true;

            e.Handled = true;
        }
        public override int GetCreditWithPosition(Troop source, out Point? position)
        {
            //position = 0;
            position = new Point(0, 0);

            if (source == null || source.BelongedLegion == null || source.BelongedLegion.Troops == null
                || source.BelongedLegion.WillArchitecture == null || source.BaseViewArea == null) return 0;
            
            if (((source.BelongedLegion != null) && (GameObject.Random(source.BelongedLegion.Troops.Count) == 0)) && ((source.BelongedLegion.WillArchitecture.BelongedFaction != null) && !source.BelongedFaction.IsArchitectureKnown(source.BelongedLegion.WillArchitecture)))
            {
                bool flag = false;
                foreach (Point point in source.BaseViewArea.Area)
                {
                    Architecture architectureByPosition = source.Scenario.GetArchitectureByPosition(point);
                    if (source.BelongedLegion.WillArchitecture == architectureByPosition)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!(!flag || source.BelongedLegion.InformationDestination.HasValue))
                {
                    position = new Point?(source.Position);
                    return 150;
                }
            }
            return 0;
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            if (this.dragStartPoint.HasValue)
            {
                Point position = e.GetPosition(this);
                if ((SystemParameters.MinimumHorizontalDragDistance <=
                    Math.Abs((double)(position.X - this.dragStartPoint.Value.X))) ||
                    (SystemParameters.MinimumVerticalDragDistance <=
                    Math.Abs((double)(position.Y - this.dragStartPoint.Value.Y))))
                {
                    
                    ToolboxObject aux=(ToolboxObject)this.Content;
                    DataObject dataObject = new DataObject("ObjectType",aux.Type);

                    if (dataObject != null)
                    {
                        DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
                    }
                }

                e.Handled = true;
            }
        }
Esempio n. 28
0
 private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (mousePosition.HasValue)
     {
         mousePosition = null;
         ReleaseMouseCapture();
     }
 }
Esempio n. 29
0
 private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
 {
     if (this.pictureBox2.Capture)
     {
         this.pointEnd = new Point(e.X, e.Y);
         this.pictureBox2.Refresh();
     }
 }
Esempio n. 30
0
 public RubberbandAdorner(DesignerCanvas designerCanvas, Point? dragStartPoint)
     : base(designerCanvas)
 {
     this.designerCanvas = designerCanvas;
     this.startPoint = dragStartPoint;
     rubberbandPen = new Pen(Brushes.LightSlateGray, 1);
     rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1);
 }
Esempio n. 31
0
 public override void PostprocessMouseLeftButtonDown(MouseButtonEventArgs e)
 {
     this._mouseDownAnchorPoint = RelativeToView(e.GetPosition(this._view.VisualElement));
 }
 void TextAreaMouseDown(object sender, PointerEventArgs e)
 {
     mouseDownPos = e.GetPosition(this);
 }
Esempio n. 33
0
 void OnMouseRightButtonUp(object sender, MouseButtonEventArgs e)
 {
     scrollViewer.Cursor = Cursors.Arrow;
     scrollViewer.ReleaseMouseCapture();
     lastDragPoint = null;
 }
Esempio n. 34
0
        public static void ConvertFromBluRaySupToBluRaySup(string fileName, List <BluRaySupParser.PcsData> sub, Point?resolution)
        {
            var screenWidth  = 1920;
            var screenHeight = 1080;

            if (sub.Count > 0 && sub[0].Size.Width > 0 && sub[0].Size.Height > 0)
            {
                screenWidth  = sub[0].Size.Width;
                screenHeight = sub[0].Size.Height;
            }
            var leftRightMargin = (int)Math.Round(screenWidth * 4.0 / 100.0);
            var bottomMargin    = (int)Math.Round(screenHeight * 4.0 / 100.0);

            using (var binarySubtitleFile = new FileStream(fileName, FileMode.Create))
            {
                for (int index = 0; index < sub.Count; index++)
                {
                    var p     = sub[index];
                    var brSub = new BluRaySupPicture
                    {
                        StartTime         = (long)p.StartTimeCode.TotalMilliseconds,
                        EndTime           = (long)p.EndTimeCode.TotalMilliseconds,
                        Width             = screenWidth,
                        Height            = screenHeight,
                        IsForced          = p.IsForced,
                        CompositionNumber = (index + 1) * 2
                    };
                    var bitmap      = p.GetBitmap();
                    var pos         = p.GetPosition();
                    var overridePos = new Point(pos.Left, pos.Top);
                    var buffer      = BluRaySupPicture.CreateSupFrame(brSub, bitmap, Configuration.Settings.General.CurrentFrameRate, bottomMargin, leftRightMargin, ContentAlignment.BottomCenter, overridePos);
                    binarySubtitleFile.Write(buffer, 0, buffer.Length);
                    bitmap?.Dispose();
                }
            }
        }
 public override void OnModifierMouseUp(ModifierMouseArgs e)
 {
     base.OnModifierMouseUp(e);
     _lastPoint = null;
 }
Esempio n. 36
0
 private void PrintElement(int elem, Point?position)
 {
     Console.SetCursorPosition(position.Value.Column * PrintInterval, position.Value.Row * PrintInterval);
     Console.Write(elem);
 }
Esempio n. 37
0
        public void WriteParagraph(Paragraph p, Bitmap bmp, ContentAlignment alignment, Point?overridePosition = null)  // inspired by code from SubtitleCreator
        {
            // timestamp: 00:00:33:900, filepos: 000000000
            _idx.AppendLine($"timestamp: {p.StartTime.Hours:00}:{p.StartTime.Minutes:00}:{p.StartTime.Seconds:00}:{p.StartTime.Milliseconds:000}, filepos: {_subFile.Position.ToString("X").PadLeft(9, '0').ToLowerInvariant()}");

            var nbmp = new NikseBitmap(bmp);

            _emphasis2 = nbmp.ConvertToFourColors(_background, _pattern, _emphasis1, _useInnerAntiAliasing);
            var twoPartBuffer = nbmp.RunLengthEncodeForDvd(_background, _pattern, _emphasis1, _emphasis2);
            var imageBuffer   = GetSubImageBuffer(twoPartBuffer, nbmp, p, alignment, overridePosition);

            int  bufferIndex = 0;
            byte vobSubId    = (byte)_languageStreamId;
            var  mwsub       = new MemWriter(200000);

            byte[] subHeader = new byte[30];
            byte[] ts        = new byte[4];

            // Lent from "Son2VobSub" by Alain Vielle and Petr Vyskocil
            // And also from Sup2VobSub by Emmel
            subHeader[0]  = 0x00; // MPEG 2 PACK HEADER
            subHeader[1]  = 0x00;
            subHeader[2]  = 0x01;
            subHeader[3]  = 0xba;
            subHeader[4]  = 0x44;
            subHeader[5]  = 0x02;
            subHeader[6]  = 0xc4;
            subHeader[7]  = 0x82;
            subHeader[8]  = 0x04;
            subHeader[9]  = 0xa9;
            subHeader[10] = 0x01;
            subHeader[11] = 0x89;
            subHeader[12] = 0xc3;
            subHeader[13] = 0xf8;

            subHeader[14] = 0x00; // PES
            subHeader[15] = 0x00;
            subHeader[16] = 0x01;
            subHeader[17] = 0xbd;

            int  packetSize = imageBuffer.Length;
            long toWrite    = packetSize; // Image buffer + control sequence length
            bool header0    = true;

            while (toWrite > 0)
            {
                long headerSize;
                if (header0)
                {
                    header0 = false;

                    // This is only for first packet
                    subHeader[20] = 0x81;   // mark as original
                    subHeader[21] = 0x80;   // first packet: PTS
                    subHeader[22] = 0x05;   // PES header data length

                    // PTS (90kHz):
                    //--------------
                    subHeader[23] = (byte)((ts[3] & 0xc0) >> 5 | 0x21);
                    subHeader[24] = (byte)((ts[3] & 0x3f) << 2 | (ts[2] & 0xc0) >> 6);
                    subHeader[25] = (byte)((ts[2] & 0x3f) << 2 | (ts[1] & 0x80) >> 6 | 0x01);
                    subHeader[26] = (byte)((ts[1] & 0x7f) << 1 | (ts[0] & 0x80) >> 7);
                    subHeader[27] = (byte)((ts[0] & 0x7f) << 1 | 0x01);

                    const string pre             = "0010"; // 0011 or 0010 ? (KMPlayer will not understand 0011!!!)
                    long         newPts          = (long)(p.StartTime.TotalSeconds * 90000.0);
                    string       bString         = Convert.ToString(newPts, 2).PadLeft(33, '0');
                    string       fiveBytesString = pre + bString.Substring(0, 3) + "1" + bString.Substring(3, 15) + "1" + bString.Substring(18, 15) + "1";
                    for (int i = 0; i < 5; i++)
                    {
                        subHeader[23 + i] = Convert.ToByte(fiveBytesString.Substring(i * 8, 8), 2);
                    }
                    subHeader[28] = vobSubId;
                    headerSize    = 29;
                }
                else
                {
                    subHeader[20] = 0x81; // mark as original
                    subHeader[21] = 0x00; // no PTS
                    subHeader[22] = 0x00; // header data length
                    subHeader[23] = vobSubId;
                    headerSize    = 24;
                }

                if ((toWrite + headerSize) <= 0x800)
                {
                    // write whole image in one 0x800 part

                    long j = (headerSize - 20) + toWrite;
                    subHeader[18] = (byte)(j / 0x100);
                    subHeader[19] = (byte)(j % 0x100);

                    // First Write header
                    for (int x = 0; x < headerSize; x++)
                    {
                        mwsub.WriteByte(subHeader[x]);
                    }

                    // Write Image Data
                    for (int x = 0; x < toWrite; x++)
                    {
                        mwsub.WriteByte(imageBuffer[bufferIndex++]);
                    }

                    // Pad remaining space
                    long paddingSize = 0x800 - headerSize - toWrite;
                    for (int x = 0; x < paddingSize; x++)
                    {
                        mwsub.WriteByte(0xff);
                    }

                    toWrite = 0;
                }
                else
                {
                    // write multiple parts

                    long blockSize = 0x800 - headerSize;
                    long j         = (headerSize - 20) + blockSize;
                    subHeader[18] = (byte)(j / 0x100);
                    subHeader[19] = (byte)(j % 0x100);

                    // First Write header
                    for (int x = 0; x < headerSize; x++)
                    {
                        mwsub.WriteByte(subHeader[x]);
                    }

                    // Write Image Data
                    for (int x = 0; x < blockSize; x++)
                    {
                        mwsub.WriteByte(imageBuffer[bufferIndex++]);
                    }

                    toWrite -= blockSize;
                }
            }

            // Write whole memory stream to file
            long endPosition = mwsub.GetPosition();

            mwsub.GotoBegin();
            _subFile.Write(mwsub.GetBuf(), 0, (int)endPosition);
        }
Esempio n. 38
0
        private void WriteDisplayArea(Stream stream, NikseBitmap nbmp, ContentAlignment alignment, Point?overridePosition)
        {
            stream.WriteByte(5);

            // Write 6 bytes of area - starting X, ending X, starting Y, ending Y, each 12 bits
            ushort startX = (ushort)((_screenWidth - nbmp.Width) / 2);
            ushort startY = (ushort)(_screenHeight - nbmp.Height - _bottomMargin);

            if (alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.TopCenter || alignment == ContentAlignment.TopRight)
            {
                startY = (ushort)_bottomMargin;
            }
            if (alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.MiddleCenter || alignment == ContentAlignment.MiddleRight)
            {
                startY = (ushort)(_screenHeight / 2 - nbmp.Height / 2);
            }
            if (alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.BottomLeft)
            {
                startX = (ushort)_leftRightMargin;
            }
            if (alignment == ContentAlignment.TopRight || alignment == ContentAlignment.MiddleRight || alignment == ContentAlignment.BottomRight)
            {
                startX = (ushort)(_screenWidth - nbmp.Width - _leftRightMargin);
            }

            if (overridePosition != null &&
                overridePosition.Value.X >= 0 && overridePosition.Value.X < _screenWidth &&
                overridePosition.Value.Y >= 0 && overridePosition.Value.Y < _screenHeight)
            {
                startX = (ushort)overridePosition.Value.X;
                startY = (ushort)overridePosition.Value.Y;
            }

            ushort endX = (ushort)(startX + nbmp.Width - 1);
            ushort endY = (ushort)(startY + nbmp.Height - 1);

            WriteEndianWord((ushort)(startX << 4 | endX >> 8), stream); // 16 - 12 start x + 4 end x
            WriteEndianWord((ushort)(endX << 8 | startY >> 4), stream); // 16 - 8 endx + 8 starty
            WriteEndianWord((ushort)(startY << 12 | endY), stream);     // 16 - 4 start y + 12 end y
        }
Esempio n. 39
0
        private byte[] GetSubImageBuffer(RunLengthTwoParts twoPartBuffer, NikseBitmap nbmp, Paragraph p, ContentAlignment alignment, Point?overridePosition)
        {
            var ms = new MemoryStream();

            // sup picture data size
            WriteEndianWord(twoPartBuffer.Length + 34, ms);

            // first display control sequence table address
            int startDisplayControlSequenceTableAddress = twoPartBuffer.Length + 4;

            WriteEndianWord(startDisplayControlSequenceTableAddress, ms);

            // Write image
            const int imageTopFieldDataAddress = 4;

            ms.Write(twoPartBuffer.Buffer1, 0, twoPartBuffer.Buffer1.Length);
            int imageBottomFieldDataAddress = 4 + twoPartBuffer.Buffer1.Length;

            ms.Write(twoPartBuffer.Buffer2, 0, twoPartBuffer.Buffer2.Length);

            // Write zero delay
            ms.WriteByte(0);
            ms.WriteByte(0);

            // next display control sequence table address (use current is last)
            WriteEndianWord(startDisplayControlSequenceTableAddress + 24, ms); // start of display control sequence table address

            // Control command start
            ms.WriteByte(p.Forced ? (byte)0 : (byte)1);

            // Control command 3 = SetColor
            WriteColors(ms); // 3 bytes

            // Control command 4 = SetContrast
            WriteContrast(ms); // 3 bytes

            // Control command 5 = SetDisplayArea
            WriteDisplayArea(ms, nbmp, alignment, overridePosition); // 7 bytes

            // Control command 6 = SetPixelDataAddress
            WritePixelDataAddress(ms, imageTopFieldDataAddress, imageBottomFieldDataAddress); // 5 bytes

            // Control command exit
            ms.WriteByte(255); // 1 byte

            // Control Sequence Table
            // Write delay - subtitle duration
            WriteEndianWord(Convert.ToInt32(p.Duration.TotalMilliseconds * 90.0) >> 10, ms);

            // next display control sequence table address (use current is last)
            WriteEndianWord(startDisplayControlSequenceTableAddress + 24, ms); // start of display control sequence table address

            // Control command 2 = StopDisplay
            ms.WriteByte(2);

            // extra byte - for compatibility with gpac/MP4BOX
            ms.WriteByte(255); // 1 byte

            return(ms.ToArray());
        }
Esempio n. 40
0
 public static string ToString(Point?value)
 {
     return(value.HasValue ? $"{value.Value.X},{value.Value.Y}" : null);
 }
Esempio n. 41
0
 public override void PreprocessMouseLeave(MouseEventArgs e)
 {
     this._mouseDownAnchorPoint = null;
 }