void newThumb_MouseDoubleClick(object sender, MouseButtonEventArgs e) { cedit = new ComponentEdit(entityfile); MyThumb thumb = sender as MyThumb; cedit.Left = e.GetPosition(canvas1).X; cedit.Top = e.GetPosition(canvas1).Y; cedit.stackPanel1.Children.Clear(); Component clicked = LoadedComponents[thumb.Title]; foreach (var item in clicked.Items) { Label lb1 = new Label(); lb1.Content = item.name; TextBox tb1 = new TextBox(); tb1.Name = "_" + item.name; cedit.stackPanel1.Children.Add(lb1); cedit.stackPanel1.Children.Add(tb1); } cedit.editingcomponentname = thumb.Title; cedit.Title = "Editing Component " + thumb.Title; cedit.Owner = this; cedit.Show(); }
private void tabControl1_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) { Mouse.OverrideCursor = null; // If "Add link" mode enabled and line drawing started (line placed to canvas) if (isAddNewLink && isLinkStarted) { // declare the linking state bool linked = false; // We released the button on MyThumb object if (e.Source.GetType() == typeof(MyThumb)) { MyThumb targetThumb = e.Source as MyThumb; // define the final endpoint of line link.EndPoint = e.GetPosition(canvas1); // if any line was drawn (avoid just clicking on the thumb) if (link.EndPoint != link.StartPoint && linkedThumb != targetThumb && linkedThumb != null) { // establish connection linkedThumb.LinkTo(targetThumb, link); // set linked state to true linked = true; DinamicComponentPresenter prop = new DinamicComponentPresenter(); Component cc = LoadedComponents[linkedThumb.Title]; prop.Name = cc.Name; foreach (var item in cc.Items) { prop.val.Add(item.name, ""); } entityfile.Components.Add(prop); ComponentProperty cp = new ComponentProperty(prop); cp.Name = linkedThumb.Title; AddComponent(cp); } } // if we didn't manage to approve the linking state // button is not released on MyThumb object or double-clicking was performed if (!linked) { // remove line from the canvas connectors.Children.Remove(link); // clear the link variable link = null; } // exit link drawing mode isLinkStarted = isAddNewLink = false; // configure GUI //btnNewAction.IsEnabled = btnNewLink.IsEnabled = true; Mouse.OverrideCursor = null; e.Handled = true; } }
// This method establishes a link between current thumb and target thumb using a predefined line geometry // Note: this is commonly to be used for drawing links with mouse when the line object is predefined outside this class public bool LinkTo(MyThumb target, LineGeometry line) { // Save as starting line for current thumb this.StartLines.Add(line); // Save as ending line for target thumb target.EndLines.Add(line); // Ensure both tumbs the latest layout this.UpdateLayout(); target.UpdateLayout(); // Update line position line.StartPoint = new Point(Canvas.GetLeft(this) + this.ActualWidth / 2, Canvas.GetTop(this) + this.ActualHeight / 2); line.EndPoint = new Point(Canvas.GetLeft(target) + target.ActualWidth / 2, Canvas.GetTop(target) + target.ActualHeight / 2); return(true); }
private void onDragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) { // Exit dragging operation during adding new link if (isAddNewLink) { return; } MyThumb thumb = e.Source as MyThumb; Canvas.SetLeft(thumb, Canvas.GetLeft(thumb) + e.HorizontalChange); Canvas.SetTop(thumb, Canvas.GetTop(thumb) + e.VerticalChange); // Update links' layouts for active thumb thumb.UpdateLinks(); }
// This method establishes a link between current thumb and specified thumb. // Returns a line geometry with updated positions to be processed outside. public LineGeometry LinkTo(MyThumb target) { // Create new line geometry LineGeometry line = new LineGeometry(); // Save as starting line for current thumb this.StartLines.Add(line); // Save as ending line for target thumb target.EndLines.Add(line); // Ensure both tumbs the latest layout this.UpdateLayout(); target.UpdateLayout(); // Update line position line.StartPoint = new Point(Canvas.GetLeft(this) + this.ActualWidth / 2, Canvas.GetTop(this) + this.ActualHeight / 2); line.EndPoint = new Point(Canvas.GetLeft(target) + target.ActualWidth / 2, Canvas.GetTop(target) + target.ActualHeight / 2); // return line for further processing return line; }
// This method establishes a link between current thumb and specified thumb. // Returns a line geometry with updated positions to be processed outside. public LineGeometry LinkTo(MyThumb target) { // Create new line geometry LineGeometry line = new LineGeometry(); // Save as starting line for current thumb this.StartLines.Add(line); // Save as ending line for target thumb target.EndLines.Add(line); // Ensure both tumbs the latest layout this.UpdateLayout(); target.UpdateLayout(); // Update line position line.StartPoint = new Point(Canvas.GetLeft(this) + this.ActualWidth / 2, Canvas.GetTop(this) + this.ActualHeight / 2); line.EndPoint = new Point(Canvas.GetLeft(target) + target.ActualWidth / 2, Canvas.GetTop(target) + target.ActualHeight / 2); // return line for further processing return(line); }
private void dockPanel1_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { Mouse.OverrideCursor = Cursors.Cross; // Is adding new link and a thumb object is clicked... if (!isLinkStarted) { if (link == null || link.EndPoint != link.StartPoint) { Point position = e.GetPosition(canvas1); link = new LineGeometry(position, position); connectors.Children.Add(link); isLinkStarted = true; isAddNewLink = true; linkedThumb = e.Source as MyThumb; e.Handled = true; } } }
private void tabControl1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // If adding new action... if (isAddNewAction || isAddNewTag) { string imagename = "/Images/Component.png"; if (isAddNewTag) { imagename = "/Images/Tag.png"; AddComponentName = AddComponentName.Replace("Tag", ""); } else { imagename = "/Images/Component.png"; AddComponentName = AddComponentName.Replace("Component", ""); } // Create new thumb object based on a static template "BasicShape1" // specifying thumb text as "action" and icon as "/Images/gear_connection.png" MyThumb newThumb = new MyThumb( Application.Current.Resources["BasicShape1"] as ControlTemplate, AddComponentName, imagename, e.GetPosition(canvas1), onDragDelta); //newThumb.MouseDown += new MouseButtonEventHandler(newThumb_MouseDown); newThumb.MouseDoubleClick += new MouseButtonEventHandler(newThumb_MouseDoubleClick); // Put newly created thumb on the canvas canvas1.Children.Add(newThumb); // resume common layout for application isAddNewAction = false; isAddNewTag = false; Mouse.OverrideCursor = null; // btnNewAction.IsEnabled = btnNewLink.IsEnabled = true; e.Handled = true; } }
private void dockPanel1_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { Mouse.OverrideCursor = Cursors.Cross; // Is adding new link and a thumb object is clicked... if (!isLinkStarted) { if (link == null || link.EndPoint != link.StartPoint) { Point position = e.GetPosition( canvas1); link = new LineGeometry(position, position); connectors.Children.Add(link); isLinkStarted = true; isAddNewLink = true; linkedThumb = e.Source as MyThumb; e.Handled = true; } } }
// This method establishes a link between current thumb and target thumb using a predefined line geometry // Note: this is commonly to be used for drawing links with mouse when the line object is predefined outside this class public bool LinkTo(MyThumb target, LineGeometry line) { // Save as starting line for current thumb this.StartLines.Add(line); // Save as ending line for target thumb target.EndLines.Add(line); // Ensure both tumbs the latest layout this.UpdateLayout(); target.UpdateLayout(); // Update line position line.StartPoint = new Point(Canvas.GetLeft(this) + this.ActualWidth / 2, Canvas.GetTop(this) + this.ActualHeight / 2); line.EndPoint = new Point(Canvas.GetLeft(target) + target.ActualWidth / 2, Canvas.GetTop(target) + target.ActualHeight / 2); return true; }