示例#1
0
 public static void Add(WElement ct)
 {
     controls.Add(ct);
     ct.MouseDown += Ct_MouseDown;
     ct.MouseMove += Ct_MouseMove;
     ct.MouseUp   += Ct_MouseUp;
 }
示例#2
0
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            CElement el = getSelectedElement();
            WElement ct = getSelectedElementControl();

            if (el != null)
            {
                CropTexture Frmct = new CropTexture(el);
                if (Frmct.ShowDialog() == true)
                {
                    int    x   = Convert.ToInt32(Canvas.GetLeft(Frmct.rect));
                    int    y   = Convert.ToInt32(Canvas.GetTop(Frmct.rect));
                    int    x1  = Convert.ToInt32(x + Frmct.rect.Width);
                    int    y1  = Convert.ToInt32(y + Frmct.rect.Height);
                    WPoint uv1 = new WPoint(x, y);
                    WPoint uv2 = new WPoint(x1, y1);
                    el.SetUV(uv1, uv2);
                    el.Texture                   = Frmct.SelectedTexture.Name;
                    ct.Source                    = el.getImage();
                    pictureBox1.Source           = ct.Source;
                    _propertyGrid.SelectedObject = el.Properties.Properties;
                    _propertyGrid.Update();
                }
            }
        }
示例#3
0
        private void Panel1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.IsDown && e.Key == Key.D && Keyboard.Modifiers == ModifierKeys.Control)
            {
                CElement el = getSelectedElement();
                if (el != null)
                {
                    CElement nw = el.Clone();
                    nw.ID = UniqueID++;
                    nw.setLeft(nw.getLeft() + 10);
                    nw.setTop(nw.getTop() + 10);
                    elements.Add(nw);
                    WElement cnw = addElementControl(nw);
                    Panel.SetZIndex(cnw, panel1.zindex++);
                    SetSelectedElement(cnw.ElementID);

                    lwElementList.Items.Add(nw);

                    for (int i = 0; i < lwElementList.Items.Count; i++)
                    {
                        if (((CElement)lwElementList.Items[i]).ID == cnw.ElementID)
                        {
                            lwElementList.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
        }
示例#4
0
        // Arrange the Adorners.
        protected override Size ArrangeOverride(Size finalSize)
        {
            // desiredWidth and desiredHeight are the width and height of the element that’s being adorned.
            // These will be used to place the ResizingAdorner at the corners of the adorned element.
            double desiredWidth  = AdornedElement.DesiredSize.Width;
            double desiredHeight = AdornedElement.DesiredSize.Height;
            // adornerWidth & adornerHeight are used for placement as well.
            double adornerWidth  = this.DesiredSize.Width;
            double adornerHeight = this.DesiredSize.Height;

            topLeft.Arrange(new Rect(-adornerWidth / 2, -adornerHeight / 2, adornerWidth, adornerHeight));
            topRight.Arrange(new Rect(desiredWidth - adornerWidth / 2, -adornerHeight / 2, adornerWidth, adornerHeight));
            bottomLeft.Arrange(new Rect(-adornerWidth / 2, desiredHeight - adornerHeight / 2, adornerWidth, adornerHeight));
            bottomRight.Arrange(new Rect(desiredWidth - adornerWidth / 2, desiredHeight - adornerHeight / 2, adornerWidth, adornerHeight));

            WElement wc = thisControl as WElement;

            top.Arrange(new Rect(wc.Width / 2 - 5, -5, 10, 10));
            bottom.Arrange(new Rect(wc.Width / 2 - 5, wc.Height - 5, 10, 10));

            left.Arrange(new Rect(-5, wc.Height / 2 - 5, 10, 10));
            right.Arrange(new Rect(wc.Width - 5, wc.Height / 2 - 5, 10, 10));

            // Return the final size.
            return(finalSize);
        }
示例#5
0
        void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseCaptured)
            {
                var    tt = (TranslateTransform)((TransformGroup)this.RenderTransform).Children.First(tr => tr is TranslateTransform);
                Vector v  = start - e.GetPosition((Border)this.Parent);
                tt.X = origin.X - v.X;
                tt.Y = origin.Y - v.Y;
            }

            if (_isDown)
            {
                if ((_isDragging == false) &&
                    ((Math.Abs(e.GetPosition(this).X - _startPoint.X) > SystemParameters.MinimumHorizontalDragDistance) ||
                     (Math.Abs(e.GetPosition(this).Y - _startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)))
                {
                    _isDragging = true;
                }

                if (_isDragging && selectedElement != null)
                {
                    Point position = Mouse.GetPosition(this);
                    Canvas.SetTop(selectedElement, position.Y - (_startPoint.Y - _originalTop));
                    Canvas.SetLeft(selectedElement, position.X - (_startPoint.X - _originalLeft));
                    if (OnChangeElement != null && selectedElement is WElement)
                    {
                        WElement ct = selectedElement as WElement;
                        Point    r1 = new Point(Canvas.GetLeft(ct), Canvas.GetTop(ct));
                        Point    r2 = new Point(r1.X + ct.Width, r1.Y + ct.Height);
                        OnChangeElement(ct.ElementID, r1, r2);
                    }
                }
            }
        }
示例#6
0
 private void Rs_onFinishResize(UIElement ui)
 {
     if (OnChangeElement != null && ui is WElement)
     {
         WElement ct = ui as WElement;
         Point    r1 = new Point(Canvas.GetLeft(ct), Canvas.GetTop(ct));
         Point    r2 = new Point(r1.X + ct.Width, r1.Y + ct.Height);
         OnChangeElement(ct.ElementID, r1, r2);
     }
 }
示例#7
0
        public void updateElementControl(int ID)
        {
            WElement ct = getElementControl(ID);
            CElement el = elements.getID(ID);

            if (ct == null || el == null)
            {
                return;
            }

            ct.Width  = el.getWidth();
            ct.Height = el.getHeight();
            Canvas.SetLeft(ct, el.getLeft());
            Canvas.SetTop(ct, el.getTop());
            ct.Source = el.getImage();
        }
示例#8
0
        public WElement addElementControl(CElement item)
        {
            WElement pc = new WElement();

            pc.ElementID = item.ID;
            Canvas.SetLeft(pc, item.getLeft());
            Canvas.SetTop(pc, item.getTop());
            pc.Stretch = Stretch.Fill;

            try
            {
                pc.Width  = item.getWidth();
                pc.Height = item.getHeight();
            }
            catch (Exception)
            {
            }
            pc.Source      = item.getImage();
            pc.ElementName = item.Name;
            pc.Tip         = item.Type == "Text" ? WElement.ETip.Text : WElement.ETip.Icon;
            if (item.Properties.exist("Size"))
            {
                pc.Size = Convert.ToInt32(item.Properties.getVal("Size").ToString());
            }
            else
            {
                pc.Size = 10;
            }
            if (item.Properties.exist("Color"))
            {
                pc.TColor = item.Properties.getVal("Color").ToString();
            }

            panel1.Children.Add(pc);

            return(pc);
        }
示例#9
0
        internal void onPropertyChanged(CustomProperty _owner, object value)
        {
            WElement wc = getSelectedElementControl();
            CElement el = getSelectedElement();

            if (wc == null)
            {
                return;
            }

            if (_owner.Name.Trim().ToLower() == "visible" && _owner.WProp)
            {
                wc.Visibility = (bool)value == true ? Visibility.Visible : Visibility.Hidden;
            }

            if (_owner.WProp && _owner.Category.Trim().ToLower() == "rect")
            {
                if (_owner.Name.Trim() == "Width")
                {
                    el.setWidth((int)value);
                }
                if (_owner.Name.Trim() == "Height")
                {
                    el.setHeight((int)value);
                }
                if (_owner.Name.Trim() == "Left")
                {
                    el.setLeft((int)value);
                }
                if (_owner.Name.Trim() == "Top")
                {
                    el.setTop((int)value);
                }

                updateElementControl(el.ID);
            }
        }
示例#10
0
        private static void Ct_MouseMove(object sender, MouseEventArgs e)
        {
            WElement rectangle1 = sender as WElement;

            if (!DragInProgress)
            {
                MouseHitType = SetHitType(rectangle1, Mouse.GetPosition(canvas1));
                SetMouseCursor();
            }
            else
            {
                // See how much the mouse has moved.
                Point  point    = Mouse.GetPosition(rectangle1);
                double offset_x = point.X - LastPoint.X;
                double offset_y = point.Y - LastPoint.Y;

                // Get the rectangle's current position.
                double new_x      = Canvas.GetLeft(rectangle1);
                double new_y      = Canvas.GetTop(rectangle1);
                double new_width  = rectangle1.Width;
                double new_height = rectangle1.Height;

                // Update the rectangle.
                switch (MouseHitType)
                {
                case HitType.Body:
                    new_x += offset_x;
                    new_y += offset_y;
                    break;

                case HitType.UL:
                    new_x      += offset_x;
                    new_y      += offset_y;
                    new_width  -= offset_x;
                    new_height -= offset_y;
                    break;

                case HitType.UR:
                    new_y      += offset_y;
                    new_width  += offset_x;
                    new_height -= offset_y;
                    break;

                case HitType.LR:
                    new_width  += offset_x;
                    new_height += offset_y;
                    break;

                case HitType.LL:
                    new_x      += offset_x;
                    new_width  -= offset_x;
                    new_height += offset_y;
                    break;

                case HitType.L:
                    new_x     += offset_x;
                    new_width -= offset_x;
                    break;

                case HitType.R:
                    new_width += offset_x;
                    break;

                case HitType.B:
                    new_height += offset_y;
                    break;

                case HitType.T:
                    new_y      += offset_y;
                    new_height -= offset_y;
                    break;
                }

                // Don't use negative width or height.
                if ((new_width > 0) && (new_height > 0))
                {
                    // Update the rectangle.
                    Canvas.SetLeft(rectangle1, new_x);
                    Canvas.SetTop(rectangle1, new_y);
                    rectangle1.Width  = new_width;
                    rectangle1.Height = new_height;

                    // Save the mouse's new location.
                    LastPoint = point;
                }
            }
        }
示例#11
0
        // Return a HitType value to indicate what is at the point.
        private static HitType SetHitType(WElement ct, Point point)
        {
            point.X += canvas1.Margin.Left;
            point.Y += canvas1.Margin.Top;
            double left   = ct.Margin.Left + canvas1.Margin.Left;
            double top    = ct.Margin.Top + canvas1.Margin.Top;
            double right  = left + ct.Width;
            double bottom = top + ct.Height;

            if (point.X < left)
            {
                return(HitType.None);
            }
            if (point.X > right)
            {
                return(HitType.None);
            }
            if (point.Y < top)
            {
                return(HitType.None);
            }
            if (point.Y > bottom)
            {
                return(HitType.None);
            }

            const double GAP = 10;

            if (point.X - left < GAP)
            {
                // Left edge.
                if (point.Y - top < GAP)
                {
                    return(HitType.UL);
                }
                if (bottom - point.Y < GAP)
                {
                    return(HitType.LL);
                }
                return(HitType.L);
            }
            if (right - point.X < GAP)
            {
                // Right edge.
                if (point.Y - top < GAP)
                {
                    return(HitType.UR);
                }
                if (bottom - point.Y < GAP)
                {
                    return(HitType.LR);
                }
                return(HitType.R);
            }
            if (point.Y - top < GAP)
            {
                return(HitType.T);
            }
            if (bottom - point.Y < GAP)
            {
                return(HitType.B);
            }
            return(HitType.Body);
        }