/// <summary> /// Fills a list with all the children of a node which are drawable and visible. /// </summary> /// <param name="node">Node which is to be recursively searched.</param> /// <param name="drawables">List to be filled with the drawable nodes.</param> private void GetVisibleDrawableNodes(Node node, ref List <IDrawableObject> drawables) { //Verify if the node is an IDrawable. IDrawableObject drawable = node as IDrawableObject; //Add the node if it is drawable and visible. if (drawable != null && drawable.Visible) { //Add the node to the list of drawable nodes. drawables.Add(drawable); } //If the node is a drawable container we add all of the visible drawables in it. IDrawableContainer drawableContainer = node as IDrawableContainer; if (drawableContainer != null && drawableContainer.Visible) { drawables.AddRange(drawableContainer.VisibleDrawables); } //If the node is not a drawable or, if it is drawable and is visible, we check all its //children. if (drawable == null || drawable.Visible) { //Search the node's children. foreach (Node n in node.Children) { GetVisibleDrawableNodes(n, ref drawables); } } }
public void UnbindElement(IDrawableContainer dc) { if (boundContainers.Contains(dc)) { boundContainers.Remove(dc); UpdateFromBoundElements(); } }
protected virtual void Dispose(bool disposing) { if (disposing) { _drawableContainer?.Dispose(); } _drawableContainer = null; }
protected virtual void Dispose(bool disposing) { if (disposing) { if (drawableContainer != null) { drawableContainer.Dispose(); drawableContainer = null; } } }
public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer) { _listOfdrawableContainer = new DrawableContainerList { drawableContainer }; _listOfdrawableContainer.Parent = drawableContainer.Parent; StoreBounds(); }
public void BindElement(IDrawableContainer dc) { if (!(dc is DrawableContainer container) || _boundContainers.Contains(container)) { return; } _boundContainers.Add(container); container.ChildrenChanged += (sender, args) => UpdateFromBoundElements(); UpdateFromBoundElements(); }
public void BindElement(IDrawableContainer dc) { DrawableContainer container = dc as DrawableContainer; if (container != null && !boundContainers.Contains(container)) { boundContainers.Add(container); container.ChildrenChanged += delegate { UpdateFromBoundElements(); }; UpdateFromBoundElements(); } }
public void DeselectElement(IDrawableContainer container) { DrawableContainer element = container as DrawableContainer; element.HideGrippers(); element.Selected = false; selectedElements.Remove(element); FieldAggregator.UnbindElement(element); if (MovingElementChanged != null) { MovingElementChanged(this, selectedElements); } }
/// <summary> /// Fills a list with all the children of a node which are shadow casters and whose /// CastShadows and Visible properties are true or whose CastShadowsWhenInvisible and /// CastShadows properties are true. /// </summary> /// <param name="node">Node which is to be recursively searched.</param> /// <param name="shadowCasters">List to be filled with the shadow casters.</param> private void GetShadowCasters(Node node, ref List <IDrawableObject> shadowCasters) { //Verify if the node is an IShadowCaster. IDrawableObject shadowCaster = node as IDrawableObject; //Add the node if it is a shadow caster and its Visible and CastShadows properties are //true or if it is a shadow caster and its Visible, CastShadows and //CastShadowsWhenInvisible properties are true. if (shadowCaster != null && shadowCaster.CastShadows) { if (shadowCaster.Visible || shadowCaster.CastShadowsWhenInvisible) { //Add the node to the list of shadow casters. shadowCasters.Add(shadowCaster); } } //If the node is a shadow caster container we add all of the shadow casters in it which //are active shadow casters and visible or whose CastShadowsWhenInvisible property is //true. IDrawableContainer shadowCasterContainer = node as IDrawableContainer; if (shadowCasterContainer != null && shadowCasterContainer.CastShadows && (shadowCasterContainer.Visible || shadowCasterContainer.CastShadowsWhenInvisible)) { //Chech each shadow caster in the container because some may be deactivated or //invisible (For the MeshNode the shadow caster properties always match the //container properties, but that need not be the case). foreach (IDrawableObject c in shadowCasterContainer.EnabledShadowCasters) { if (shadowCasterContainer.Visible || shadowCasterContainer.CastShadowsWhenInvisible) { shadowCasters.Add(c); } } } //Check the children. if (shadowCaster == null || (shadowCaster.CastShadows && (shadowCaster.Visible || shadowCaster.CastShadowsWhenInvisible))) { //Search the node's children. foreach (Node n in node.Children) { GetShadowCasters(n, ref shadowCasters); } } }
public void UpdateElement(IDrawableContainer dc) { if (!(dc is DrawableContainer container)) { return; } _internalUpdateRunning = true; foreach (var field in GetFields()) { if (container.HasField(field.FieldType) && field.HasValue) { //if(LOG.IsDebugEnabled) Log.Debug().WriteLine(" "+field+ ": "+field.Value); container.SetFieldValue(field.FieldType, field.Value); } } _internalUpdateRunning = false; }
public void SelectElement(IDrawableContainer container) { DrawableContainer element = container as DrawableContainer; if (!selectedElements.Contains(element)) { selectedElements.Add(element); element.ShowGrippers(); element.Selected = true; FieldAggregator.BindElement(element); if (MovingElementChanged != null) { MovingElementChanged(this, selectedElements); } element.Invalidate(); } }
public IMemento Restore() { var oldState = new DrawableContainerBoundsChangeMemento(_listOfdrawableContainer); for (int index = 0; index < _listOfdrawableContainer.Count; index++) { IDrawableContainer drawableContainer = _listOfdrawableContainer[index]; // Before drawableContainer.Invalidate(); drawableContainer.Left = _points[index].X; drawableContainer.Top = _points[index].Y; drawableContainer.Width = _sizes[index].Width; drawableContainer.Height = _sizes[index].Height; // After drawableContainer.Invalidate(); drawableContainer.Parent.Modified = true; } return(oldState); }
public void UpdateElement(IDrawableContainer dc) { DrawableContainer container = dc as DrawableContainer; if (container == null) { return; } internalUpdateRunning = true; foreach (Field field in GetFields()) { if (container.HasField(field.FieldType) && field.HasValue) { //if(LOG.IsDebugEnabled) LOG.Debug(" "+field+ ": "+field.Value); container.SetFieldValue(field.FieldType, field.Value); } } internalUpdateRunning = false; }
protected virtual void Dispose(bool disposing) { //if (disposing) { } drawableContainer = null; surface = null; }
public void BindAndUpdateElement(IDrawableContainer dc) { UpdateElement(dc); BindElement(dc); }
/// <summary> /// A simple helper method to remove the cursor from the surface /// </summary> public void RemoveCursor() { RemoveElement(_cursorContainer, true); _cursorContainer = null; }
public ChangeFieldHolderMemento(IDrawableContainer drawableContainer, IField fieldToBeChanged) { _drawableContainer = drawableContainer; _fieldToBeChanged = fieldToBeChanged; _oldValue = fieldToBeChanged.Value; }
public ChangeFieldHolderMemento(IDrawableContainer drawableContainer, Field fieldToBeChanged) { this.drawableContainer = drawableContainer; this.fieldToBeChanged = fieldToBeChanged; this.oldValue = fieldToBeChanged.Value; }
public Surface(ICapture capture) : this(capture.Image) { // Make sure the image is NOT disposed, we took the reference directly into ourselves ((Capture)capture).NullImage(); if (capture.Cursor != null && capture.CursorVisible) { cursorContainer = AddIconContainer(capture.Cursor, capture.CursorLocation.X, capture.CursorLocation.Y); SelectElement(cursorContainer); } captureDetails = capture.CaptureDetails; }
/// <summary> /// Auto crop the image /// </summary> /// <returns>true if cropped</returns> public bool AutoCrop() { Rectangle cropRectangle = ImageHelper.FindAutoCropRectangle(Image, conf.AutoCropDifference); if (isCropPossible(ref cropRectangle)) { DeselectAllElements(); // Maybe a bit obscure, but the following line creates a drop container // It's available as "undrawnElement" DrawingMode = DrawingModes.Crop; undrawnElement.Left = cropRectangle.X; undrawnElement.Top = cropRectangle.Y; undrawnElement.Width = cropRectangle.Width; undrawnElement.Height = cropRectangle.Height; undrawnElement.Status = EditStatus.UNDRAWN; AddElement(undrawnElement); SelectElement(undrawnElement); drawingElement = null; undrawnElement = null; return true; } return false; }
/// <summary> /// This event handle is called when the mouse button is unpressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SurfaceMouseUp(object sender, MouseEventArgs e) { Point currentMouse = new Point(e.X, e.Y); _elements.Status = EditStatus.IDLE; if (_mouseDownElement != null) { _mouseDownElement.Status = EditStatus.IDLE; } _mouseDown = false; _mouseDownElement = null; if (DrawingMode == DrawingModes.None) { // check whether an existing element was clicked IDrawableContainer element = _elements.ClickableElementAt(currentMouse.X, currentMouse.Y); bool shiftModifier = (ModifierKeys & Keys.Shift) == Keys.Shift; if (element != null) { element.Invalidate(); bool alreadySelected = selectedElements.Contains(element); if (shiftModifier) { if (alreadySelected) { DeselectElement(element); } else { SelectElement(element); } } else { if (!alreadySelected) { DeselectAllElements(); SelectElement(element); } } } else if (!shiftModifier) { DeselectAllElements(); } } if (selectedElements.Count > 0) { selectedElements.ShowGrippers(); selectedElements.Selected = true; } if (_drawingElement != null) { if (!_drawingElement.InitContent()) { _elements.Remove(_drawingElement); _drawingElement.Invalidate(); } else { _drawingElement.HandleMouseUp(currentMouse.X, currentMouse.Y); _drawingElement.Invalidate(); if (Math.Abs(_drawingElement.Width) < 5 && Math.Abs(_drawingElement.Height) < 5) { _drawingElement.Width = 25; _drawingElement.Height = 25; } SelectElement(_drawingElement); _drawingElement.Selected = true; } _drawingElement = null; } }
/// <summary> /// This event handler is called when someone presses the mouse on a surface. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SurfaceMouseDown(object sender, MouseEventArgs e) { _mouseStart = e.Location; // check contextmenu if (e.Button == MouseButtons.Right) { DrawableContainerList selectedList = null; if (selectedElements != null && selectedElements.Count > 0) { selectedList = selectedElements; } else { // Single element IDrawableContainer rightClickedContainer = _elements.ClickableElementAt(_mouseStart.X, _mouseStart.Y); if (rightClickedContainer != null) { selectedList = new DrawableContainerList(ID); selectedList.Add(rightClickedContainer); } } if (selectedList != null && selectedList.Count > 0) { selectedList.ShowContextMenu(e, this); } return; } _mouseDown = true; _isSurfaceMoveMadeUndoable = false; if (_cropContainer != null && ((_undrawnElement == null) || (_undrawnElement != null && DrawingMode != DrawingModes.Crop))) { RemoveElement(_cropContainer, false); _cropContainer = null; _drawingElement = null; } if (_drawingElement == null && DrawingMode != DrawingModes.None) { if (_undrawnElement == null) { DeselectAllElements(); if (_undrawnElement == null) { CreateUndrawnElement(); } } _drawingElement = _undrawnElement; // if a new element has been drawn, set location and register it if (_drawingElement != null) { _drawingElement.Status = _undrawnElement.DefaultEditMode; _drawingElement.PropertyChanged += ElementPropertyChanged; if (!_drawingElement.HandleMouseDown(_mouseStart.X, _mouseStart.Y)) { _drawingElement.Left = _mouseStart.X; _drawingElement.Top = _mouseStart.Y; } AddElement(_drawingElement); _drawingElement.Selected = true; } _undrawnElement = null; } else { // check whether an existing element was clicked // we save mouse down element separately from selectedElements (checked on mouse up), // since it could be moved around before it is actually selected _mouseDownElement = _elements.ClickableElementAt(_mouseStart.X, _mouseStart.Y); if (_mouseDownElement != null) { _mouseDownElement.Status = EditStatus.MOVING; } } }
/// <summary> /// This is called from the DrawingMode setter, which is not very correct... /// But here an element is created which is not yet draw, thus "undrawnElement". /// The element is than used while drawing on the surface. /// </summary> private void CreateUndrawnElement() { if (_undrawnElement != null) { FieldAggregator.UnbindElement(_undrawnElement); } switch (DrawingMode) { case DrawingModes.Rect: _undrawnElement = new RectangleContainer(this); break; case DrawingModes.Ellipse: _undrawnElement = new EllipseContainer(this); break; case DrawingModes.Text: _undrawnElement = new TextContainer(this); break; case DrawingModes.SpeechBubble: _undrawnElement = new SpeechbubbleContainer(this); break; case DrawingModes.StepLabel: _undrawnElement = new StepLabelContainer(this); break; case DrawingModes.Line: _undrawnElement = new LineContainer(this); break; case DrawingModes.Arrow: _undrawnElement = new ArrowContainer(this); break; case DrawingModes.Highlight: _undrawnElement = new HighlightContainer(this); break; case DrawingModes.Obfuscate: _undrawnElement = new ObfuscateContainer(this); break; case DrawingModes.Crop: _cropContainer = new CropContainer(this); _undrawnElement = _cropContainer; break; case DrawingModes.Bitmap: _undrawnElement = new ImageContainer(this); break; case DrawingModes.Path: _undrawnElement = new FreehandContainer(this); break; case DrawingModes.None: _undrawnElement = null; break; } if (_undrawnElement != null) { FieldAggregator.BindElement(_undrawnElement); } }
protected override void Dispose(bool disposing) { if (disposing) { Count--; LOG.Debug("Disposing surface!"); if (_buffer != null) { _buffer.Dispose(); _buffer = null; } if (_transparencyBackgroundBrush != null) { _transparencyBackgroundBrush.Dispose(); _transparencyBackgroundBrush = null; } // Cleanup undo/redo stacks while (_undoStack != null && _undoStack.Count > 0) { _undoStack.Pop().Dispose(); } while (_redoStack != null && _redoStack.Count > 0) { _redoStack.Pop().Dispose(); } foreach (IDrawableContainer container in _elements) { container.Dispose(); } if (_undrawnElement != null) { _undrawnElement.Dispose(); _undrawnElement = null; } if (_cropContainer != null) { _cropContainer.Dispose(); _cropContainer = null; } } base.Dispose(disposing); }
/// <summary> /// Select the supplied element /// </summary> /// <param name="container"></param> public void SelectElement(IDrawableContainer container) { if (!selectedElements.Contains(container)) { selectedElements.Add(container); container.ShowGrippers(); container.Selected = true; FieldAggregator.BindElement(container); if (_movingElementChanged != null) { SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs(); eventArgs.Elements = selectedElements; _movingElementChanged(this, eventArgs); } container.Invalidate(); } }
/// <summary> /// Remove an element of the elements list /// </summary> /// <param name="elementToRemove">Element to remove</param> /// <param name="makeUndoable">flag specifying if the remove needs to be undoable</param> public void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable) { DeselectElement(elementToRemove); _elements.Remove(elementToRemove); DrawableContainer element = elementToRemove as DrawableContainer; if (element != null) { element.FieldChanged -= element_FieldChanged; } elementToRemove.PropertyChanged -= ElementPropertyChanged; // Do not dispose, the memento should!! element.Dispose(); Invalidate(); if (makeUndoable) { MakeUndoable(new DeleteElementMemento(this, elementToRemove), false); } _modified = true; }
public TargetAdorner(IDrawableContainer owner, NativePoint location) : base(owner) { Location = location; }
public AbstractAdorner(IDrawableContainer owner) { Owner = owner; }
/// <summary> /// Surface contructor with a capture /// </summary> /// <param name="capture"></param> public Surface(ICapture capture) : this(capture.Image) { // check if cursor is captured, and visible if (capture.Cursor != null && capture.CursorVisible) { Rectangle cursorRect = new Rectangle(capture.CursorLocation, capture.Cursor.Size); Rectangle captureRect = new Rectangle(Point.Empty, capture.Image.Size); // check if cursor is on the capture, otherwise we leave it out. if (cursorRect.IntersectsWith(captureRect)) { _cursorContainer = AddIconContainer(capture.Cursor, capture.CursorLocation.X, capture.CursorLocation.Y); SelectElement(_cursorContainer); } } // Make sure the image is NOT disposed, we took the reference directly into ourselves ((Capture)capture).NullImage(); _captureDetails = capture.CaptureDetails; }
/// <summary> /// Wrapper for makeUndoable flag which was introduced later, will call AddElement with makeundoable set to true /// </summary> /// <param name="element">the new element</param> public void AddElement(IDrawableContainer element) { AddElement(element, true); }
public ChangeFieldHolderMemento(IDrawableContainer drawableContainer, Field fieldToBeChanged) { this.drawableContainer = drawableContainer; this.fieldToBeChanged = fieldToBeChanged; oldValue = fieldToBeChanged.Value; }
public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer) { listOfdrawableContainer = new List<IDrawableContainer>(); listOfdrawableContainer.Add(drawableContainer); StoreBounds(); }
public AddElementMemento(Surface surface, IDrawableContainer drawableContainer) { _surface = surface; _drawableContainer = drawableContainer; }
public void UpdateElement(IDrawableContainer dc) { DrawableContainer container = dc as DrawableContainer; if (container == null) { return; } internalUpdateRunning = true; foreach(Field field in GetFields()) { if (container.HasField(field.FieldType) && field.HasValue) { //if(LOG.IsDebugEnabled) LOG.Debug(" "+field+ ": "+field.Value); container.SetFieldValue(field.FieldType, field.Value); } } internalUpdateRunning = false; }
public bool IsOnSurface(IDrawableContainer container) { return _elements.Contains(container); }
public void SelectElement(IDrawableContainer container) { DrawableContainer element = container as DrawableContainer; if(!selectedElements.Contains(element)) { selectedElements.Add(element); element.ShowGrippers(); element.Selected = true; FieldAggregator.BindElement(element); if (MovingElementChanged != null) { MovingElementChanged(this, selectedElements); } element.Invalidate(); } }
protected AbstractAdorner(IDrawableContainer owner) { _size.Width = _size.Height = DpiHandler.ScaleWithDpi(5, NativeDpiMethods.GetDpi(InteropWindowQuery.GetDesktopWindow().Handle)); Owner = owner; }
/// <summary> /// Count all the VISIBLE steplabels in the surface, up to the supplied one /// </summary> /// <param name="stopAtContainer">can be null, if not the counting stops here</param> /// <returns>number of steplabels before the supplied container</returns> public int CountStepLabels(IDrawableContainer stopAtContainer) { int number = 1; foreach (var possibleThis in _stepLabels) { if (possibleThis == stopAtContainer) { break; } if (IsOnSurface(possibleThis)) { number++; } } return number; }
/// <summary> /// Deselect the specified element /// </summary> /// <param name="container"></param> public void DeselectElement(IDrawableContainer container) { container.HideGrippers(); container.Selected = false; selectedElements.Remove(container); FieldAggregator.UnbindElement(container); if (_movingElementChanged != null) { SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs(); eventArgs.Elements = selectedElements; _movingElementChanged(this, eventArgs); } }
public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer) { listOfdrawableContainer = new List <IDrawableContainer>(); listOfdrawableContainer.Add(drawableContainer); StoreBounds(); }
/// <summary> /// Add a new element to the surface /// </summary> /// <param name="element">the new element</param> /// <param name="makeUndoable">true if the adding should be undoable</param> public void AddElement(IDrawableContainer element, bool makeUndoable) { _elements.Add(element); DrawableContainer container = element as DrawableContainer; if (container != null) { container.FieldChanged += element_FieldChanged; } element.PropertyChanged += ElementPropertyChanged; if (element.Status == EditStatus.UNDRAWN) { element.Status = EditStatus.IDLE; } element.Invalidate(); if (makeUndoable) { MakeUndoable(new AddElementMemento(this, element), false); } _modified = true; }
public MoveAdorner(IDrawableContainer owner, Positions position) : base(owner) { Position = position; }
public DeleteElementMemento(Surface surface, IDrawableContainer drawableContainer) { this.surface = surface; this.drawableContainer = drawableContainer; }
/// <summary> /// Auto crop the image /// </summary> /// <returns>true if cropped</returns> public bool AutoCrop() { Rectangle cropRectangle; using (Image tmpImage = GetImageForExport()) { cropRectangle = ImageHelper.FindAutoCropRectangle(tmpImage, conf.AutoCropDifference); } if (!IsCropPossible(ref cropRectangle)) { return false; } DeselectAllElements(); // Maybe a bit obscure, but the following line creates a drop container // It's available as "undrawnElement" DrawingMode = DrawingModes.Crop; _undrawnElement.Left = cropRectangle.X; _undrawnElement.Top = cropRectangle.Y; _undrawnElement.Width = cropRectangle.Width; _undrawnElement.Height = cropRectangle.Height; _undrawnElement.Status = EditStatus.UNDRAWN; AddElement(_undrawnElement); SelectElement(_undrawnElement); _drawingElement = null; _undrawnElement = null; return true; }
/// <summary> /// This method is called to confirm/cancel "confirmable" elements, like the crop-container. /// Called when pressing enter or using the "check" in the editor. /// </summary> /// <param name="confirm"></param> public void ConfirmSelectedConfirmableElements(bool confirm) { // create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel) List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements); foreach (IDrawableContainer dc in selectedDCs) { if (dc.Equals(_cropContainer)) { DrawingMode = DrawingModes.None; // No undo memento for the cropcontainer itself, only for the effect RemoveElement(_cropContainer, false); if (confirm) { ApplyCrop(_cropContainer.Bounds); } _cropContainer.Dispose(); _cropContainer = null; } } }