Beispiel #1
0
        public void MouseLeftButtonUp(double point_x, double point_y, int brush_index, double slider_value)
        {
            if (m_DrawingStarted == false)
            {
                return;
            }

            m_DrawingStarted = false;
            double endX = point_x;
            double endY = point_y;

            if (m_moving)
            {
                m_moving = false;
            }
            else if ((shapeIndex == 2 || shapeIndex == 3) && brush_index == 4)
            {
                if (shapeIndex == 3)
                {
                    m_shape = new Rectangle();
                }
                else if (shapeIndex == 2)
                {
                    m_shape = new Ellipse();
                }
                m_shape.Stroke          = new SolidColorBrush(borderColor);
                m_shape.StrokeThickness = slider_value;
                m_shape.Fill            = new SolidColorBrush(fillColor);

                if (endX > m_StartX)
                {
                    m_shape.Width = endX - m_StartX;
                    InkCanvas.SetLeft(m_shape, m_StartX);
                }
                else
                {
                    m_shape.Width = m_StartX - endX;
                    InkCanvas.SetLeft(m_shape, endX);
                }
                if (endY > m_StartY)
                {
                    m_shape.Height = endY - m_StartY;
                    InkCanvas.SetTop(m_shape, m_StartY);
                }
                else
                {
                    m_shape.Height = m_StartY - endY;
                    InkCanvas.SetTop(m_shape, endY);
                }

                MyCanvas.Children.Add(m_shape);
            }
            else if (shapeIndex == 1 && brush_index == 4)
            {
                Line line = new Line();
                line.X1 = m_StartX;
                line.Y1 = m_StartY;
                line.X2 = endX;
                line.Y2 = endY;
                line.StrokeThickness = slider_value;
                MyCanvas.Children.Add(line);
                line.Stroke = new SolidColorBrush(borderColor);
                line.Fill   = new SolidColorBrush(borderColor);
            }
        }
Beispiel #2
0
        private void OCRText(int mode = 0)
        {
            StrokeCollection sc;

            switch (mode)
            {
            case 0:
                sc = OCRCanvas.Strokes;
                break;

            case 1:
                sc = TegakiCanvas.GetSelectedStrokes();
                break;

            default:
                return;
            }

            ia = new InkAnalyzer();
            if (sc.Count == 0)
            {
                return;
            }
            CustomRecognizerNode node;
            double x, y;
            int    height;

            getStrokeZahyo(sc, out x, out y, out height);

            // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット
            if (EngineList.SelectedItem != null)
            {
                node = ia.CreateCustomRecognizer((Guid)EngineList.SelectedValue);
                ia.AddStrokesToCustomRecognizer(sc, node);
            }
            else
            {
                ia.AddStrokes(sc);
            }
            ia.SetStrokesType(sc, StrokeType.Writing);

            // 文字を解析
            ia.Analyze();

            //罫線にピタッとなるようにする
            y = ((int)((y + lineMargine / 2) / lineMargine) * lineMargine) + 1 * (int)((y + lineMargine / 2) / lineMargine);

            height = (int)((height + lineMargine / 2) / lineMargine) * lineMargine;
            if (height >= 8)
            {
                TextBlock tb = new TextBlock()
                {
                    Text = ia.GetRecognizedString(), FontSize = height - 8, VerticalAlignment = System.Windows.VerticalAlignment.Top, LineStackingStrategy = LineStackingStrategy.BlockLineHeight, LineHeight = height
                };
                //noteRoot.Children.Add(tb);
                TegakiCanvas.Children.Add(tb);
                InkCanvas.SetLeft(tb, x);
                InkCanvas.SetTop(tb, y);
            }
            //textBox1.Text += ia.GetRecognizedString();
            switch (mode)
            {
            case 0:
                OCRCanvas.Strokes.Clear();
                break;

            case 1:
                foreach (Stroke s in sc)
                {
                    TegakiCanvas.Strokes.Remove(s);
                }
                break;
            }

            /*
             * // その他の候補を表示する
             * AnalysisAlternateCollection alternates = theInkAnalyzer.GetAlternates();
             * foreach (var alternate in alternates)
             * MessageBox.Show(alternate.RecognizedString);
             */
        }
Beispiel #3
0
        //読込ボタン
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            tabDeleted = true;
            TegakiCanvas.Strokes.Clear();
            TegakiCanvas.Children.Clear();
            OCRCanvas.Strokes.Clear();
            OCRCanvas.Children.Clear();
            Pages.Clear();
            TabControl1.Items.Clear();
            tabCount = 0;
            AddAddTabButton();

            OpenFileDialog ofd = new OpenFileDialog()
            {
                AddExtension = true, DefaultExt = "note", Multiselect = false, CheckPathExists = true, CheckFileExists = true
            };

            ofd.ShowDialog();
            if (ofd.FileName == "" || !File.Exists(ofd.FileName))
            {
                return;
            }
            FileStream    fs = new FileStream(ofd.FileName, FileMode.Open);
            XmlSerializer XS = new XmlSerializer(typeof(List <byte[]>));

            List <byte[]> DATA = (List <byte[]>)XS.Deserialize(fs);

            foreach (byte[] data in DATA)
            {
                tabCount++;
                XmlSerializer xs  = new XmlSerializer(typeof(NoteData));
                MemoryStream  ms  = new MemoryStream(data);
                TabItem       tab = new TabItem();
                Pages.Add("Page" + tabCount, (NoteData)xs.Deserialize(ms));
                AddTabHeaderWithCloseButton(tab, "Page" + tabCount);
                TabControl1.Items.Add(tab);
            }
            if (tabCount > 0)
            {
                TegakiCanvas.Strokes = new StrokeCollection(new MemoryStream(Pages["Page1"].tegaki));
                lineMargine          = Pages["Page1"].borderMargin;
                for (int i = 0; i < Pages["Page1"].TBFontSizes.Count; i++)
                {
                    TextBlock tb = new TextBlock()
                    {
                        Text = Pages["Page1"].TBtexts[i], FontSize = Pages["Page1"].TBFontSizes[i], LineHeight = Pages["Page1"].TBLineHeights[i]
                    };
                    TegakiCanvas.Children.Add(tb);
                    InkCanvas.SetLeft(tb, Pages["Page1"].TBXs[i]);
                    InkCanvas.SetTop(tb, Pages["Page1"].TBYs[i]);
                }
            }
            else
            {
                TabAddButton_Click(null, null);
            }
            fs.Dispose();
            lastSelectedTab           = 1;
            TabControl1.SelectedIndex = 1;
            tabDeleted = false;
        }
Beispiel #4
0
        /// <summary>
        /// OnPreviewMouseDown is called before InkCanvas sees the Down.  We use this
        /// handler to hit test any selection and initiate a drag and drop operation
        /// if the user clicks on the selection to move it.
        /// </summary>
        private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            InkCanvas inkCanvas    = (InkCanvas)sender;
            Point     downPosition = e.GetPosition(inkCanvas);

            //see if we hit the selection, and not a grab handle
            if (inkCanvas.HitTestSelection(downPosition) == InkCanvasSelectionHitResult.Selection)
            {
                //clone the selected strokes so we can transform them without affecting the actual selection
                StrokeCollection selectedStrokes = inkCanvas.GetSelectedStrokes();

                List <UIElement> selectedElements = new List <UIElement>(inkCanvas.GetSelectedElements());
                DataObject       dataObject       = new DataObject();

                //copy ink to the clipboard if we have any.  we do this even if there are no
                //strokes since clonedStrokes will be used by the Xaml clipboard code below
                StrokeCollection clonedStrokes = selectedStrokes.Clone();
                if (clonedStrokes.Count > 0)
                {
                    //translate the strokes relative to the down position
                    Matrix translation = new Matrix();
                    translation.Translate(-downPosition.X, -downPosition.Y);
                    clonedStrokes.Transform(translation, false);

                    //save the strokes to a dataobject to use during the dragdrop operation
                    MemoryStream ms = new MemoryStream();
                    clonedStrokes.Save(ms);
                    ms.Position = 0;
                    dataObject.SetData(StrokeCollection.InkSerializedFormat, ms);

                    //we don't close the MemoryStream here, we'll do it in OnDrop
                }

                //Now we're going to add Xaml to the dragdrop dataobject.  We'll create an
                //InkCanvas and add any selected strokes and elements in the selection to it
                InkCanvas inkCanvasForDragDrop = new InkCanvas();
                foreach (UIElement childElement in selectedElements)
                {
                    //we can't add elements in the selection to the InkCanvas that
                    //represents selection (since they are already parented to the
                    //inkCanvas that has the selection) so we need to clone them.
                    //To clone each element, we need to convert it to Xaml and back again
                    string    childXaml          = XamlWriter.Save(childElement);
                    UIElement clonedChildElement =
                        (UIElement)XamlReader.Load(new XmlTextReader(new StringReader(childXaml)));

                    //adjust top and left relative to the down position
                    double childLeft = InkCanvas.GetLeft(clonedChildElement);
                    InkCanvas.SetLeft(clonedChildElement, childLeft - downPosition.X);

                    double childTop = InkCanvas.GetTop(clonedChildElement);
                    InkCanvas.SetTop(clonedChildElement, childTop - downPosition.Y);

                    inkCanvasForDragDrop.Children.Add(clonedChildElement);
                }

                //last, add the cloned strokes in case our drop location only supports Xaml
                //this preserves both the ink and the selected elements
                inkCanvasForDragDrop.Strokes = clonedStrokes;

                //now copy the Xaml for the InkCanvas that represents selection to the clipboard
                string inkCanvasXaml = XamlWriter.Save(inkCanvasForDragDrop);
                dataObject.SetData(DataFormats.Xaml, inkCanvasXaml);

                //The call to DragDrop.DoDragDrop will block until the drag and drop operation is completed
                //once it does, 'effects' will have been updated by OnDragOver getting called
                //if we're moving the strokes and elements, we'll remove them.  If we're copying them
                //(the CTRL key is pressed) we won't remove them.
                DragDropEffects effects =
                    DragDrop.DoDragDrop(inkCanvas, dataObject, DragDropEffects.Move | DragDropEffects.Copy);

                if (effects == DragDropEffects.Move)
                {
                    inkCanvas.Strokes.Remove(selectedStrokes);

                    foreach (UIElement childElement in selectedElements)
                    {
                        inkCanvas.Children.Remove(childElement);
                    }
                }
            }
        }
Beispiel #5
0
        void InkCanvasKeyDown(object sender, KeyEventArgs e)
        {
            oldkey = e.Key;
            for (int i = 0; i < 5; i++)
            {
                if (Keyboard.IsKeyDown(Key.D1 + i))
                {
                    SelectCanvas(i);
                }
            }
            //D = (int)e.Key - 83;
            //if (D >= 0 && D <= 5)
            //    SelectCanvas(D);

            if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.Z))
            {
                if (_Stroke != null)
                {
                    if (_curentPoint > 0)
                    {
                        _Stroke.StylusPoints.RemoveAt(_curentPoint);
                        _curentPoint--;
                    }
                    else
                    {
                        _InkCanvas.Strokes.Remove(_Stroke);
                        _Stroke = null;
                    }
                }
            }

            if (e.Key == Key.Q)
            {
                SetMode(InkCanvasEditingMode.Select, CustomMode.select);
            }
            if (e.Key == Key.W)
            {
                SetMode(InkCanvasEditingMode.None, CustomMode.polygon);
            }
            if (e.Key == Key.E)
            {
                SetMode(InkCanvasEditingMode.EraseByPoint, CustomMode.erase);
            }

            if (e.Key == Key.Add || e.Key == Key.Subtract)
            {
                double _ScaleFactor = e.Key == Key.Add ? 1.2 : .8;
                _Scale         *= _ScaleFactor;
                _ScaleText.Text = _Scale.ToString();
                foreach (InkCanvas _InkCanvas in _CanvasList.Children)
                {
                    foreach (Stroke _Stroke in _InkCanvas.Strokes)
                    {
                        for (int i = 0; i < _Stroke.StylusPoints.Count; i++)
                        {
                            StylusPoint _StylusPoint = _Stroke.StylusPoints[i];
                            _Stroke.StylusPoints[i] = new StylusPoint(_StylusPoint.X * _ScaleFactor, _StylusPoint.Y * _ScaleFactor);
                        }
                    }
                    foreach (FrameworkElement _Image in _InkCanvas.Children)
                    {
                        InkCanvas.SetLeft(_Image, InkCanvas.GetLeft(_Image) * _ScaleFactor);
                        InkCanvas.SetTop(_Image, InkCanvas.GetTop(_Image) * _ScaleFactor);
                        _Image.Width  = _Image.ActualWidth * _ScaleFactor;
                        _Image.Height = _Image.ActualHeight * _ScaleFactor;
                    }
                }
            }
            if (e.Key == Key.C)
            {
                SelectColor();
            }
            if (e.Key == Key.PageUp)
            {
                StrokeCollection _StrokeCollection = _InkCanvas.GetSelectedStrokes();
                foreach (Stroke _Stroke in _StrokeCollection)
                {
                    _InkCanvas.Strokes.Remove(_Stroke);
                    _InkCanvas.Strokes.Add(_Stroke);
                }
            }
            if (e.Key == Key.PageDown)
            {
                StrokeCollection _StrokeCollection = _InkCanvas.GetSelectedStrokes();
                foreach (Stroke _Stroke in _StrokeCollection)
                {
                    _InkCanvas.Strokes.Remove(_Stroke);
                    _InkCanvas.Strokes.Insert(0, _Stroke);
                }
            }
            if (Keyboard.IsKeyDown(Key.C) && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                _InkCanvas.CopySelection();
            }
            //if (Keyboard.IsKeyDown(Key.X) && Keyboard.IsKeyDown(Key.LeftCtrl))
            //{
            //    _InkCanvas.CutSelection();
            //}
            if (Keyboard.IsKeyDown(Key.V) && Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                _InkCanvas.Paste();
            }
            if (e.Key == Key.B)
            {
                if (_PolygonsCanvas.Children.Count > 0)
                {
                    _PolygonsCanvas.Children.Clear();
                }
                else
                {
                    foreach (InkCanvas _InkCanvas1 in _CanvasList.Children)
                    {
                        foreach (Stroke _Stroke in _InkCanvas1.Strokes)
                        {
                            if (_Stroke.StylusPoints.Last() == _Stroke.StylusPoints.First())
                            {
                                Polygon _Polygon = new Polygon();
                                foreach (StylusPoint _Point in _Stroke.StylusPoints)
                                {
                                    _Polygon.Points.Add(new Point(_Point.X, _Point.Y));
                                }
                                _Polygon.Fill = new SolidColorBrush(_Stroke.DrawingAttributes.Color);
                                _PolygonsCanvas.Children.Add(_Polygon);
                            }
                        }
                    }
                }
            }
        }
        private void preview_mouseup(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (shapeFlag < 3)
                {
                    par[1] = Mouse.GetPosition(canvas);
                }
                else
                {
                }
                switch (shapeFlag)
                {
                case 1:

                    Ellipse ell = new Ellipse();
                    if (par[0].X < par[1].X)
                    {
                        ell.Width  = par[1].X - par[0].X;
                        ell.Height = par[1].Y - par[0].Y;
                        InkCanvas.SetTop(ell, par[0].Y);
                        InkCanvas.SetLeft(ell, par[0].X);
                    }
                    else
                    {
                        ell.Width  = par[0].X - par[1].X;
                        ell.Height = par[0].Y - par[1].Y;
                        InkCanvas.SetTop(ell, par[1].Y);
                        InkCanvas.SetLeft(ell, par[1].X);
                    }
                    ell.StrokeThickness = 4;
                    ell.Fill            = System.Windows.Media.Brushes.Transparent;
                    ell.Stroke          = System.Windows.Media.Brushes.LightSteelBlue;

                    canvas.Children.Add(ell);

                    break;

                case 2:
                    Line l = new Line();

                    l.X1 = par[0].X;
                    l.Y1 = par[0].Y;
                    l.X2 = par[1].X;
                    l.Y2 = par[1].Y;

                    l.StrokeThickness = 4;
                    l.Stroke          = System.Windows.Media.Brushes.LightSteelBlue;
                    canvas.Children.Add(l);
                    break;

                case 3:
                    if (i == 4)
                    {
                        // ZeichneBezier(6,new System.Drawing.Point((int)par[0].X, (int)par[0].Y), new System.Drawing.Point((int)par[1].X, (int)par[1].Y), new System.Drawing.Point((int)par[2].X, (int)par[2].Y), e, true);
                        for (int j = 0; j < NUMOFPOINTS - 1; ++j)
                        {
                            canvas.Children.Add(nline(par[j], par[j + 1]));
                        }
                    }
                    break;
                }
            }catch (Exception) { return; }
        }
Beispiel #7
0
        /// <summary>
        /// OnDrop - called when drag and drop contents are dropped on an InkCanvas
        /// </summary>
        private void OnDrop(object sender, DragEventArgs e)
        {
            InkCanvas inkCanvas = (InkCanvas)sender;

            //see if ISF is present in the drag and drop IDataObject
            if (e.Data.GetDataPresent(StrokeCollection.InkSerializedFormat) ||
                e.Data.GetDataPresent(DataFormats.Xaml))
            {
                SetDragDropEffects(e);

                if (e.Effects == DragDropEffects.Move || e.Effects == DragDropEffects.Copy)
                {
                    Point dropPosition = e.GetPosition(inkCanvas);

                    //after we drop, we need to select the elements and strokes that were
                    //copied into the inkCanvas
                    List <UIElement> elementsToSelect = new List <UIElement>();
                    if (e.Data.GetDataPresent(DataFormats.Xaml))
                    {
                        //paste Xaml
                        string xamlData = (string)e.Data.GetData(DataFormats.Xaml);
                        if (!String.IsNullOrEmpty(xamlData))
                        {
                            UIElement element =
                                XamlReader.Load(new XmlTextReader(new StringReader(xamlData))) as UIElement;
                            if (element != null)
                            {
                                //check to see if this is an InkCanvas
                                InkCanvas inkCanvasFromDragDrop = element as InkCanvas;
                                if (inkCanvasFromDragDrop != null)
                                {
                                    //we assume this was put on the data object by us.
                                    //remove the children and add them to the drop inkCanvas.
                                    while (inkCanvasFromDragDrop.Children.Count > 0)
                                    {
                                        UIElement childElement = inkCanvasFromDragDrop.Children[0];
                                        double    childLeft    = InkCanvas.GetLeft(childElement);
                                        InkCanvas.SetLeft(childElement, childLeft + dropPosition.X);

                                        double childTop = InkCanvas.GetTop(childElement);
                                        InkCanvas.SetTop(childElement, childTop + dropPosition.Y);

                                        inkCanvasFromDragDrop.Children.Remove(childElement);

                                        inkCanvas.Children.Add(childElement);
                                        elementsToSelect.Add(childElement);
                                    }
                                }
                                else
                                {
                                    //just add the element, it wasn't another InkCanvas that we
                                    //added to the dataobject as a container
                                    inkCanvas.Children.Add(element);
                                    elementsToSelect.Add(element);
                                }
                            }
                        }
                    }

                    //now check to see if we have ISF as well
                    StrokeCollection strokesToSelect = new StrokeCollection();
                    if (e.Data.GetDataPresent(StrokeCollection.InkSerializedFormat))
                    {
                        //only ISF was present
                        MemoryStream     ms = (MemoryStream)e.Data.GetData(StrokeCollection.InkSerializedFormat);
                        StrokeCollection sc = new StrokeCollection(ms);
                        ms.Close();

                        //translate the strokes back from the origin to the current position
                        Matrix translation = new Matrix();
                        translation.Translate(dropPosition.X, dropPosition.Y);
                        sc.Transform(translation, false);

                        //add the strokes from the IDataObject to the inkCanvas and select them.
                        inkCanvas.Strokes.Add(sc);
                        strokesToSelect.Add(sc);
                    }

                    //now that we're done, we select
                    if (elementsToSelect.Count > 0 || strokesToSelect.Count > 0)
                    {
                        inkCanvas.Select(strokesToSelect, elementsToSelect);
                    }

                    e.Handled = true;
                }
            }
        }
Beispiel #8
0
        public void SetDataInControl4CurCanvas()
        {
            try
            {
                _currentInkCanvas.Strokes.Clear();

                //Set start locations of terrorists and counterterrorist

                /*InkCanvas.SetLeft(_counterTerroristStartPos, _mapDatabase.CounterTerroristStartPos.X);
                 * InkCanvas.SetTop(_counterTerroristStartPos, _mapDatabase.CounterTerroristStartPos.Y);
                 * InkCanvas.SetLeft(_terroristStartPos, _mapDatabase.TerroristStartPos.X);
                 * InkCanvas.SetTop(_terroristStartPos, _mapDatabase.TerroristStartPos.Y);*/

                for (int i = 0; i < _mapDatabase.Layers.Count; i++)
                {
                    MapDatabase.Layer layer     = _mapDatabase.Layers[i];
                    InkCanvas         inkCanvas = (InkCanvas)_canvasList.Children[i];
                    // _currentInkCanvas = inkCanvas;
                    foreach (MapDatabase.Image image in layer.Images)
                    {
                        Image img = new Image();
                        img.Stretch = Stretch.Fill;
                        if (!File.Exists(image.Path))
                        {
                            throw new FileNotFoundException(image.Path);
                        }

                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.BeginInit();
                        bitmapImage.UriSource = new Uri(image.Path, UriKind.Absolute);
                        bitmapImage.EndInit();
                        img.Source = bitmapImage;

                        img.Width  = image.Width;
                        img.Height = image.Height;
                        InkCanvas.SetLeft(img, image.X);
                        InkCanvas.SetTop(img, image.Y);
                        inkCanvas.Children.Add(img);
                    }

                    foreach (MapDatabase.Polygon polygon in layer.Polygons)
                    {
                        //Create a collection of points of the current polygon
                        StylusPointCollection stylusPointCollection = new StylusPointCollection();
                        foreach (Point point in polygon.Points)
                        {
                            StylusPoint stylusPoint = new StylusPoint(point.X, point.Y);
                            stylusPointCollection.Add(stylusPoint);
                        }

                        //Add polygon as a new stroke
                        Stroke stroke = new Stroke(stylusPointCollection);
                        stroke.DrawingAttributes.Color = polygon.Color;
                        inkCanvas.Strokes.Add(stroke);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageBox.Show(ex);
            }
        }
Beispiel #9
0
 // Token: 0x06006D82 RID: 28034 RVA: 0x001F7060 File Offset: 0x001F5260
 internal void UpdateElementBounds(UIElement originalElement, UIElement updatedElement, Matrix transform)
 {
     if (originalElement.DependencyObjectType.Id == updatedElement.DependencyObjectType.Id)
     {
         GeneralTransform generalTransform = originalElement.TransformToAncestor(this._inkCanvas.InnerCanvas);
         FrameworkElement frameworkElement = originalElement as FrameworkElement;
         Thickness        thickness        = default(Thickness);
         Size             renderSize;
         if (frameworkElement == null)
         {
             renderSize = originalElement.RenderSize;
         }
         else
         {
             renderSize = new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight);
             thickness  = frameworkElement.Margin;
         }
         Rect rect = new Rect(0.0, 0.0, renderSize.Width, renderSize.Height);
         rect = generalTransform.TransformBounds(rect);
         Rect rect2 = Rect.Transform(rect, transform);
         if (!DoubleUtil.AreClose(rect.Width, rect2.Width))
         {
             if (frameworkElement == null)
             {
                 Size renderSize2 = originalElement.RenderSize;
                 renderSize2.Width         = rect2.Width;
                 updatedElement.RenderSize = renderSize2;
             }
             else
             {
                 ((FrameworkElement)updatedElement).Width = rect2.Width;
             }
         }
         if (!DoubleUtil.AreClose(rect.Height, rect2.Height))
         {
             if (frameworkElement == null)
             {
                 Size renderSize3 = originalElement.RenderSize;
                 renderSize3.Height        = rect2.Height;
                 updatedElement.RenderSize = renderSize3;
             }
             else
             {
                 ((FrameworkElement)updatedElement).Height = rect2.Height;
             }
         }
         double left   = InkCanvas.GetLeft(originalElement);
         double top    = InkCanvas.GetTop(originalElement);
         double right  = InkCanvas.GetRight(originalElement);
         double bottom = InkCanvas.GetBottom(originalElement);
         Point  point  = default(Point);
         if (!double.IsNaN(left))
         {
             point.X = left;
         }
         else if (!double.IsNaN(right))
         {
             point.X = right;
         }
         if (!double.IsNaN(top))
         {
             point.Y = top;
         }
         else if (!double.IsNaN(bottom))
         {
             point.Y = bottom;
         }
         Point point2 = point * transform;
         if (!double.IsNaN(left))
         {
             InkCanvas.SetLeft(updatedElement, point2.X - thickness.Left);
         }
         else if (!double.IsNaN(right))
         {
             InkCanvas.SetRight(updatedElement, right - (point2.X - point.X));
         }
         else
         {
             InkCanvas.SetLeft(updatedElement, point2.X - thickness.Left);
         }
         if (!double.IsNaN(top))
         {
             InkCanvas.SetTop(updatedElement, point2.Y - thickness.Top);
             return;
         }
         if (!double.IsNaN(bottom))
         {
             InkCanvas.SetBottom(updatedElement, bottom - (point2.Y - point.Y));
             return;
         }
         InkCanvas.SetTop(updatedElement, point2.Y - thickness.Top);
     }
 }
Beispiel #10
0
        public override void Draw(Point p)
        {
            _doorPoints.Push(p);

            //Count two point to create the rectangle area
            if (_doorPoints.Count == 2)
            {
                Point p2 = _doorPoints.Pop();
                Point p1 = _doorPoints.Pop();

                this._fillBrush = new SolidColorBrush(ImageUtil.RandomColor());

                // Get the last shape on the canvas, this represents the preview rectangle
                Rect rect = new Rect(InkCanvas.GetLeft(_receiver.LastShape), InkCanvas.GetTop(_receiver.LastShape), _receiver.LastShape.Width, _receiver.LastShape.Height);

                List <Point> doorAnchorPoints = new List <Point>(); // Contains the points inside the selection rectangle preview

                // Loop through the points available for the drawing of a door, If these points are in the selection rectangle they are added to the list of selected points
                // Check also if the point isn't already in the list
                foreach (Point doorPoint in _doorAvailablePoints)
                {
                    if (rect.Contains(doorPoint) && !doorAnchorPoints.Contains(doorPoint))
                    {
                        doorAnchorPoints.Add(doorPoint);
                    }
                }

                // There must be at least 2 dots to draw a door.
                if (doorAnchorPoints.Count >= 2)
                {
                    double pointsDoorDistance = MathUtil.DistanceBetweenTwoPoints(doorAnchorPoints[0], doorAnchorPoints[1]);

                    //The door must respect a maximum and minimum distance
                    if (pointsDoorDistance > DOOR_MINIMUM_DISTANCE && pointsDoorDistance < DOOR_MAXIMUM_DISTANCE && !IsDoorOnWall(doorAnchorPoints[0], doorAnchorPoints[1]))
                    {
                        Rectangle rectangle = new Rectangle
                        {
                            Fill = Application.Current.TryFindResource("PrimaryHueLightBrush") as SolidColorBrush
                        };

                        // Add the door to the canvas
                        doorAnchorPoints = doorAnchorPoints.OrderBy(point => point.X).ToList();
                        InkCanvas.SetLeft(rectangle, doorAnchorPoints[0].X);

                        doorAnchorPoints = doorAnchorPoints.OrderBy(point => point.Y).ToList();
                        InkCanvas.SetTop(rectangle, doorAnchorPoints[0].Y);

                        double width  = Math.Abs(doorAnchorPoints[1].X - doorAnchorPoints[0].X);
                        double height = Math.Abs(doorAnchorPoints[1].Y - doorAnchorPoints[0].Y);

                        // If the height or width of the door is below the size threshold it is set to a certain value, otherwise it is not shown in the drawing
                        if (width <= COMPONENT_OFFSET)
                        {
                            width = COMPONENT_OFFSET;
                        }
                        if (height <= COMPONENT_OFFSET)
                        {
                            height = COMPONENT_OFFSET;
                        }

                        rectangle.Width  = width;
                        rectangle.Height = height;

                        _receiver.ViewModel._mainWindow.canvas.Children.Add(rectangle);

                        Door door = _receiver.ViewModel._plan.AddDoor(doorAnchorPoints[0], doorAnchorPoints[1]); // add the door to the plan

                        //Add the door to the history
                        MainWindow.main.History = "Door";
                        _receiver.ViewModel._stackHistory.Push(new Tuple <object, object, string>(rectangle, door, "Door"));
                    }
                }

                _receiver.ViewModel._mainWindow.canvas.Children.Remove(_receiver.LastShape);
                _receiver.LastShape = null;
            }
        }
Beispiel #11
0
        // Button für Erstellung einer Spielfigur
        private void CharButton_Click(object sender, RoutedEventArgs e)
        {
            int   size             = 0;
            int   side             = 0;
            Brush affiliationColor = Brushes.Gray;

            // Check und Erstellung der Spielfiguren auf dem Canvas
            if ((bool)Player.IsChecked)
            {
                size             = (int)CreatureSize.Medium;
                side             = (int)Affiliation.Player;
                affiliationColor = Brushes.Green;
            }
            else if ((bool)Ally.IsChecked)
            {
                size             = (int)CreatureSize.Medium;
                side             = (int)Affiliation.Ally;
                affiliationColor = Brushes.SlateBlue;
            }
            else if ((bool)FoeM.IsChecked)
            {
                size             = (int)CreatureSize.Medium;
                side             = (int)Affiliation.Foe;
                affiliationColor = Brushes.Red;
            }
            else if ((bool)FoeL.IsChecked)
            {
                size             = (int)CreatureSize.Large;
                side             = (int)Affiliation.Foe;
                affiliationColor = Brushes.Red;
            }
            else
            {
                size             = (int)CreatureSize.ExtraLarge;
                side             = (int)Affiliation.Foe;
                affiliationColor = Brushes.Red;
            }

            CharakterToken Unit = new CharakterToken(MapSquareSize, ++IDStarter, UnitName.Text, side, size)
            {
                Background      = affiliationColor,
                BorderThickness = new Thickness(4, 4, 4, 4),
                BorderBrush     = UnitBorder,
                CornerRadius    = new CornerRadius(100),
            };

            Unit.InitiativeMember = Initiativetracker.InitiativeMemberCreator(Unit);

            Point startPunkt = new Point(180, 60);

            //Unit.TokenID = IDStarter++;

            // Check und Erstellung der Spielfiguren auf dem Canvas
            if ((bool)Player.IsChecked)
            {
                spielerFiguren.Add(Unit);
            }
            else if ((bool)Ally.IsChecked)
            {
                allies.Add(Unit);
            }
            else
            {
                monster.Add(Unit);
            }

            all.Add(Unit);

            // Drag&Drop Eventhandler für die Spielfiguren
            MouseButtonEventHandler mouseDown = (sendert, args) => {
                var element = (UIElement)sendert;
                distance.X1 = InkCanvas.GetLeft(element) + (element.RenderSize.Width / 2);
                distance.Y1 = InkCanvas.GetTop(element) + (element.RenderSize.Height / 2);
                dragStart   = args.GetPosition(element);
                element.CaptureMouse();
            };
            MouseButtonEventHandler mouseUp = (sendert, args) => {
                var element = (UIElement)sendert;
                distance.Visibility       = Visibility.Collapsed;
                distanceValue.Visibility  = Visibility.Collapsed;
                distanceValue2.Visibility = Visibility.Collapsed;
                dragStart   = null;
                distance.X1 = 0;
                distance.Y1 = 0;
                distance.X2 = 0;
                distance.Y2 = 0;
                element.ReleaseMouseCapture();
            };
            MouseEventHandler mouseMove = (sendert, args) => {
                if (dragStart != null && args.LeftButton == MouseButtonState.Pressed)
                {
                    string distanceText = (Math.Round(((Math.Sqrt(Math.Pow(Math.Abs(distance.X1 - distance.X2), 2) + Math.Pow(Math.Abs(distance.Y1 - distance.Y2), 2))) / 40), 2)).ToString() + " m";
                    var    element      = (UIElement)sendert;
                    var    p2           = args.GetPosition(GameMap);

                    InkCanvas.SetLeft(element, p2.X - dragStart.Value.X);
                    InkCanvas.SetTop(element, p2.Y - dragStart.Value.Y);
                    distance.Visibility = Visibility.Visible;
                    distance.X2         = InkCanvas.GetLeft(element) + (element.RenderSize.Width / 2);
                    distance.Y2         = InkCanvas.GetTop(element) + (element.RenderSize.Height / 2);

                    distanceValue.Text        = distanceText;
                    distanceValue2.Text       = distanceText;
                    distanceValue.FontSize    = 16;
                    distanceValue.Visibility  = Visibility.Visible;
                    distanceValue2.Visibility = Visibility.Visible;
                    InkCanvas.SetLeft(distanceValue, (Math.Abs(distance.X1 + distance.X2) / 2) + 15);
                    InkCanvas.SetTop(distanceValue, (Math.Abs(distance.Y1 + distance.Y2) / 2) - 30);
                }
            };
            MouseButtonEventHandler mouseRightClick = (sendert, args) =>
            {
                Initiativetracker.RemoveInitElement(((CharakterToken)sendert).InitiativeMember);
                all.Remove((CharakterToken)sendert);
                GameMap.Children.Remove((UIElement)sendert);
                InitiativeUpdate();
            };
            Action <UIElement> enableDrag = (element) => {
                element.MouseDown          += mouseDown;
                element.MouseMove          += mouseMove;
                element.MouseUp            += mouseUp;
                element.MouseRightButtonUp += mouseRightClick;
            };

            // Eventhandler für das neue Element aktivieren
            enableDrag(Unit);
            GameMap.Children.Add(Unit);

            // Position des neuen Element im Canvas setzen
            InkCanvas.SetTop(Unit, startPunkt.Y - 10);
            InkCanvas.SetLeft(Unit, startPunkt.X - 10);
        }
Beispiel #12
0
 /// <summary>
 /// 绘制图形
 /// </summary>
 /// <param name="canvas"></param>
 public virtual void Draw(InkCanvas canvas)
 {
     InkCanvas.SetLeft(this, Position.X);
     InkCanvas.SetTop(this, Position.Y);
     canvas.Children.Add(this);
 }
        /// <summary>
        /// Draw selected shape on canvas
        /// </summary>
        private void DrawShape()
        {
            Shape Rendershape = null;

            switch (Shape1)
            {
            case SelectedShape.Circle:
                Rendershape = new Ellipse()
                {
                    Height = 100, Width = 100
                };
                RadialGradientBrush Ellipsebrush = new RadialGradientBrush();
                Ellipsebrush.GradientStops.Add(new GradientStop(Color.FromArgb(0, 255, 255, 255), 0));
                Rendershape.Stroke          = SelectedColorRect.Stroke;
                Rendershape.StrokeThickness = 2;
                Rendershape.Fill            = Ellipsebrush;
                break;

            case SelectedShape.Rectangle:
                Rendershape = new Rectangle()
                {
                    Height = 100, Width = 100, RadiusX = 2, RadiusY = 2
                };
                RadialGradientBrush Rectbrush = new RadialGradientBrush();
                Rectbrush.GradientStops.Add(new GradientStop(Color.FromArgb(0, 255, 255, 255), 0));
                Rendershape.Stroke          = SelectedColorRect.Stroke;
                Rendershape.StrokeThickness = 2;
                Rendershape.Fill            = Rectbrush;
                break;

            case SelectedShape.Line:
                Rendershape = new Rectangle()
                {
                    Height = 1, Width = 100, RadiusX = 12, RadiusY = 12
                };
                RadialGradientBrush Linebrush = new RadialGradientBrush();
                Linebrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 0), 0));
                Rendershape.Fill            = Linebrush;
                Rendershape.Stroke          = SelectedColorRect.Stroke;
                Rendershape.StrokeThickness = 2;
                break;

            case SelectedShape.Triangle:
                PointCollection myPointCollection = new PointCollection();
                myPointCollection.Add(new System.Windows.Point(0, 0));
                myPointCollection.Add(new System.Windows.Point(50, 100));
                myPointCollection.Add(new System.Windows.Point(100, 0));
                Rendershape = new Polygon()
                {
                    Height = 100, Width = 100, Points = myPointCollection
                };
                Rendershape.Stroke          = SelectedColorRect.Stroke;
                Rendershape.StrokeThickness = 2;
                break;

            default:
                return;
            }
            InkCanvas.SetTop(Rendershape, 300);
            InkCanvas.SetLeft(Rendershape, 300);
            m_inkCanvas.Children.Add(Rendershape);
        }
Beispiel #14
0
        protected override void OnStartup(StartupEventArgs e)
        {
            myWindow         = new Window();
            myCanvas         = new Canvas();
            myWindow.Content = myCanvas;

            inkCanvas1 = new InkCanvas();

            inkCanvas1.StrokeCollected +=
                new InkCanvasStrokeCollectedEventHandler(myIC_StrokeCollected);

            inkCanvas1.Background = Brushes.LightGray;

            inkCanvas1.SetValue(Canvas.TopProperty, 30d);
            inkCanvas1.SetValue(Canvas.LeftProperty, 30d);
            inkCanvas1.SetValue(Canvas.WidthProperty, 450d);
            inkCanvas1.SetValue(Canvas.HeightProperty, 400d);

            myCanvas.Children.Add(inkCanvas1);

            Rectangle box = new Rectangle();

            box.Height = 100;
            box.Width  = 100;
            box.Stroke = Brushes.Black;
            InkCanvas.SetLeft(box, 100);
            InkCanvas.SetTop(box, 100);
            inkCanvas1.Children.Add(box);

            //add the stack panel and radio buttons;
            buttonPanel        = new StackPanel();
            buttonPanel.Width  = 200;
            buttonPanel.Height = 400;
            Canvas.SetLeft(buttonPanel, 500);
            Canvas.SetTop(buttonPanel, 30);

            myCanvas.Children.Add(buttonPanel);

            rbclipWithPoints         = new RadioButton();
            rbclipWithPoints.Content = "ClipWithPoints";
            rbclipWithPoints.Click  += new RoutedEventHandler(rbclipWithPoints_Click);
            buttonPanel.Children.Add(rbclipWithPoints);

            rbClipWithRect         = new RadioButton();
            rbClipWithRect.Content = "ClipWithRect";
            rbClipWithRect.Click  += new RoutedEventHandler(rbClipWithRect_Click);
            buttonPanel.Children.Add(rbClipWithRect);

            rbChangeColorWithStylusShape         = new RadioButton();
            rbChangeColorWithStylusShape.Content = "ChangeColorWithStylusShape";
            rbChangeColorWithStylusShape.Click  += new RoutedEventHandler(rbChangeColorWithStylusShape_Click);
            buttonPanel.Children.Add(rbChangeColorWithStylusShape);

            rbChangeColorWithRect         = new RadioButton();
            rbChangeColorWithRect.Content = "ChangeColorWithRect";
            rbChangeColorWithRect.Click  += new RoutedEventHandler(rbChangeColorWithRect_Click);
            buttonPanel.Children.Add(rbChangeColorWithRect);

            rbChangeColorWithPoints         = new RadioButton();
            rbChangeColorWithPoints.Content = "ChangeColorWithPoints";
            rbChangeColorWithPoints.Click  += new RoutedEventHandler(rbChangeColorWithPoints_Click);
            buttonPanel.Children.Add(rbChangeColorWithPoints);

            rbChangeColorAtPoint         = new RadioButton();
            rbChangeColorAtPoint.Content = "ChangeColorAtPoint";
            rbChangeColorAtPoint.Click  += new RoutedEventHandler(rbChangeColorAtPoint_Click);
            buttonPanel.Children.Add(rbChangeColorAtPoint);

            rbEraseWithStylusShape         = new RadioButton();
            rbEraseWithStylusShape.Content = "EraseWithStylusShape";
            rbEraseWithStylusShape.Click  += new RoutedEventHandler(rbEraseWithStylusShape_Click);
            buttonPanel.Children.Add(rbEraseWithStylusShape);

            rbEraseWithPoints         = new RadioButton();
            rbEraseWithPoints.Content = "EraseWithPoints";
            rbEraseWithPoints.Click  += new RoutedEventHandler(rbEraseWithPoints_Click);
            buttonPanel.Children.Add(rbEraseWithPoints);

            rbEraseWithRect         = new RadioButton();
            rbEraseWithRect.Content = "EraseWithRect";
            rbEraseWithRect.Click  += new RoutedEventHandler(rbEraseWithRect_Click);
            buttonPanel.Children.Add(rbEraseWithRect);

            myWindow.Show();
        }
Beispiel #15
0
        private int _caretLineBeforeChanges = -1;                   //Индекс строки, в которой находится карректа

        #endregion

        #region КОНСТРУКТОР

        public Editor()
        {
            try
            {
                this._historyHelper   = new BoardHistoryHelper(this);
                this._drawingHelper   = new DrawingHelper(this);
                this._changesHistory  = new List <string>();
                this._clientsUpdate   = new Dictionary <string, ClientInfo>();
                this._cTimer          = new System.Windows.Threading.DispatcherTimer();
                this._cTimer.Interval = TimeSpan.FromSeconds(5);
                this._cTimer.Tick    += _cTimer_Tick;
                this._cTimer.Start();

                InitializeComponent();

                this.ShowBoardsInList();
                this.tbCurrentBoard.Text       = this._historyHelper.CurrentBoard.ToString();
                this.cbFontFamaly.SelectedItem = new FontFamily("Courier New");

                this.SaveState();

                //Выбор IP

                IPHostEntry ipEntry = Dns.GetHostEntry("");
                IPAddress[] addr    = ipEntry.AddressList;

                if (addr.Length > 0)
                {
                    this._ipServer = addr.First <IPAddress>(ip => !ip.IsIPv6LinkLocal).ToString();
                }

                string ipConf   = null;
                string portConf = null;

                try
                {
                    ipConf   = ConfigurationManager.AppSettings["IP"];
                    portConf = ConfigurationManager.AppSettings["Port"];
                }
                catch { }

                IPAddress ipAddr = null;
                IPAddress.TryParse(ipConf, out ipAddr);

                int portAddr = 0;
                Int32.TryParse(portConf, out portAddr);

                if (ipAddr != null && (addr.Contains(ipAddr) || IPAddress.IsLoopback(ipAddr)) && portAddr > 1024 && portAddr < 65535)
                {
                    this._ipServer   = ipAddr.ToString();
                    this._portServer = portAddr;
                }

                //Прямоугольник для подсветки активной строки

                Rectangle highlightingRect = new Rectangle()
                {
                    Name = "rcHighlight"
                };
                InkCanvas.SetLeft(highlightingRect, 0);
                InkCanvas.SetTop(highlightingRect, 0);
                highlightingRect.Width  = 0;
                highlightingRect.Height = 0;
                this.inkBoard.Children.Add(highlightingRect);
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
#endif
                MessageBox.Show(ex.Message, "Всё сломалось", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(1);
            }

            //Чтение настроек из реестра

            try
            {
                RegistryHelper regHelper = new RegistryHelper(this);
                regHelper.LoadSetting();
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
#endif
            }
        }
Beispiel #16
0
        /// <summary>
        /// Начало рисования фигуры
        /// </summary>
        /// <param name="beginPoint">Точка начала фигуры</param>
        private void BeginDrawingShape(Point beginPoint)
        {
            if (this.inkBoard.Children.Count >= 100)
            {
                MessageBox.Show("Достигнуто максиальное колчичество фигур", "Внимание", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            //Добавление надписи

            if (this._drawMode == BOADR_DRAW_SHAPE.LABEL)
            {
                this.AddLabel(beginPoint);
                this.ShowShapesInList();
                return;
            }

            //Создание фигуры

            this._isDrawing  = true;
            this._beginPoint = beginPoint;

            switch (this._drawMode)
            {
            case BOADR_DRAW_SHAPE.POLYLINE:
                this._currentShape = new Polyline();
                ((Polyline)this._currentShape).Points.Add(beginPoint);
                break;

            case BOADR_DRAW_SHAPE.LINE:
                this._currentShape            = new Line();
                ((Line)this._currentShape).X1 = this._beginPoint.X;
                ((Line)this._currentShape).Y1 = this._beginPoint.Y;
                ((Line)this._currentShape).X2 = this._beginPoint.X;
                ((Line)this._currentShape).Y2 = this._beginPoint.Y;
                break;

            case BOADR_DRAW_SHAPE.RECTANGLE:
                this._currentShape = new Rectangle();
SetPosition:
                InkCanvas.SetLeft(this._currentShape, this._beginPoint.X);
                InkCanvas.SetTop(this._currentShape, this._beginPoint.Y);
                break;

            case BOADR_DRAW_SHAPE.ROUND_RECTANGLE:
                this._currentShape = new Rectangle();
                ((Rectangle)this._currentShape).RadiusX = this._RECT_RADIUS;
                ((Rectangle)this._currentShape).RadiusY = this._RECT_RADIUS;
                goto SetPosition;

            case BOADR_DRAW_SHAPE.ELLIPSE:
                this._currentShape = new Ellipse();
                goto SetPosition;

            default:
                break;
            }

            //Настройка фигуры

            this._currentShape.SnapsToDevicePixels = true;
            this._currentShape.Stroke = (Brush)this.cbStrokeColor.SelectedItem;
            if (this._drawMode != BOADR_DRAW_SHAPE.POLYLINE)
            {
                this._currentShape.Fill = (Brush)this.cbFillColor.SelectedItem;
            }
            this._currentShape.StrokeThickness = (double)this.cbThickness.SelectedItem;
            this._currentShape.StrokeDashArray = (((DoubleCollection)this.cbDash.SelectedItem)[0] == 0.0) ? null : (DoubleCollection)this.cbDash.SelectedItem;

            this.inkBoard.Children.Add(this._currentShape);

            this.ShowShapesInList();
        }