/// <summary> /// This method parses the given <see cref="VGElement"/> /// for sound files and fills them in the <see cref="OgamaControls.AudioPlayer"/>. /// If they should be played on click, they are stored in the /// <see cref="SlidePresentationContainer.ElementsWithAudioOnClick"/> list. /// </summary> /// <param name="slideContainer"> /// The <see cref="SlidePresentationContainer"/> /// this element belongs to. /// </param> /// <param name="element"> /// The <see cref="VGElement"/> to search for audio content /// </param> private static void ParseElementForAudio(SlidePresentationContainer slideContainer, VGElement element) { if (element.Sound != null && element.Sound.ShouldPlay) { if (!element.Sound.ShowOnClick) { slideContainer.AudioPlayer.AddAudioChannel(element.Sound.FullFilename); } else { slideContainer.ElementsWithAudioOnClick.Add(element); } } }
/////////////////////////////////////////////////////////////////////////////// // Eventhandler // /////////////////////////////////////////////////////////////////////////////// #region EVENTS /////////////////////////////////////////////////////////////////////////////// // Eventhandler for UI, Menu, Buttons, Toolbars etc. // /////////////////////////////////////////////////////////////////////////////// #region WINDOWSEVENTHANDLER #endregion //WINDOWSEVENTHANDLER /////////////////////////////////////////////////////////////////////////////// // Eventhandler for Custom Defined Events // /////////////////////////////////////////////////////////////////////////////// #region CUSTOMEVENTHANDLER #endregion //CUSTOMEVENTHANDLER #endregion //EVENTS /////////////////////////////////////////////////////////////////////////////// // Methods and Eventhandling for Background tasks // /////////////////////////////////////////////////////////////////////////////// #region BACKGROUNDWORKER #endregion //BACKGROUNDWORKER /////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region METHODS /// <summary> /// This method updates the given element with the new resources path /// </summary> /// <param name="newResourcesPath">The new resource path</param> /// <param name="element">The <see cref="VGElement"/> to update.</param> private static void UpdateElement(string newResourcesPath, VGElement element) { // check all element for sounds if (element.Sound == null) { element.Sound = new AudioFile(); } if (element.Sound.Filename != null) { if (element.Sound.Filename.Contains(@"\")) { element.Sound.Filename = System.IO.Path.GetFileName(element.Sound.Filename); } element.Sound.Filepath = newResourcesPath; } // check file based elements if (element is VGScrollImage) { var scrollImage = (VGScrollImage)element; if (scrollImage.Filepath != newResourcesPath) { scrollImage.Filename = System.IO.Path.GetFileName(scrollImage.Filename); scrollImage.Filepath = newResourcesPath; scrollImage.Canvas = Document.ActiveDocument.PresentationSize; } scrollImage.CreateInternalImage(); } else if (element is VGImage) { VGImage image = (VGImage)element; if (image.Filepath != newResourcesPath) { image.Filename = System.IO.Path.GetFileName(image.Filename); image.Filepath = newResourcesPath; image.Canvas = Document.ActiveDocument.PresentationSize; image.CreateInternalImage(); } } else if (element is VGFlash) { VGFlash flash = (VGFlash)element; if (flash.Filepath != newResourcesPath) { flash.Filename = System.IO.Path.GetFileName(flash.Filename); flash.Filepath = newResourcesPath; } } }
/////////////////////////////////////////////////////////////////////////////// // Public methods // /////////////////////////////////////////////////////////////////////////////// #region PUBLICMETHODS /// <summary> /// This static method serializes the current <see cref="VGElement"/> /// to a memorystream which itself is converted to a base64 string. /// This is needed for lossless copying and retreiving from clipboard. /// </summary> /// <param name="objectToSerialize">The <see cref="VGElement"/> /// to be serialized.</param> /// <returns>A base64 encoded string with the memory stream of the /// <see cref="VGElement"/>.</returns> public static string Serialize(VGElement objectToSerialize) { string serialString = null; using (System.IO.MemoryStream ms1 = new System.IO.MemoryStream()) { XmlSerializer serializer = new XmlSerializer(typeof(VGElement)); serializer.Serialize(ms1, objectToSerialize); byte[] arrayByte = ms1.ToArray(); serialString = Convert.ToBase64String(arrayByte); } return serialString; }
/// <summary> /// This method updates the forms numeric up and downs /// for the shapes position and size with the given /// elements new values. /// </summary> /// <param name="shape"> /// A <see cref="VGElement"/> that values /// should be available on the form. /// </param> private void UpdateShapePositionAndSizeNumerics(VGElement shape) { try { this.isInitializingSelectedShape = true; this.nudLayoutLeft.Value = (decimal)shape.Location.X; this.nudLayoutTop.Value = (decimal)shape.Location.Y; this.nudLayoutWidth.Value = (decimal)shape.Width; this.nudLayoutHeight.Value = (decimal)shape.Height; this.isInitializingSelectedShape = false; } catch (ArgumentOutOfRangeException ex) { ExceptionMethods.HandleException(ex); } }
/// <summary> /// When properties changed the selected element in the picture /// and the property control <see cref="PenAndBrushControl"/> /// should be updated. /// </summary> /// <param name="modifiedElement"> /// The element with the new properties, /// that should be copied to the selected element. /// </param> private void UpdateSelectedElementAndPropertyControl(VGElement modifiedElement) { this.designPicture.SelectedElement.ShapeDrawAction = modifiedElement.ShapeDrawAction; this.designPicture.SelectedElement.Pen = modifiedElement.Pen; this.designPicture.SelectedElement.Brush = modifiedElement.Brush; this.designPicture.SelectedElement.Font = modifiedElement.Font; this.designPicture.SelectedElement.FontColor = modifiedElement.FontColor; this.designPicture.SelectedElement.Name = modifiedElement.Name; this.pbcElements.DrawAction = modifiedElement.ShapeDrawAction; this.pbcElements.NewPen = modifiedElement.Pen; this.pbcElements.NewBrush = modifiedElement.Brush; this.pbcElements.NewFont = modifiedElement.Font; this.pbcElements.NewFontColor = modifiedElement.FontColor; this.pbcElements.NewName = modifiedElement.Name; }
/// <summary> /// Overridden <see cref="Control.MouseMove"/> event handler. /// During shape creation this finishes creation. So the /// <see cref="ShapeAdded"/> event is raised. /// Otherwise update bounds of moved objects. /// </summary> /// <param name="e">The <see cref="MouseEventArgs"/> with the event data.</param> protected override void OnMouseUp(MouseEventArgs e) { if (Control.ModifierKeys != Keys.ShiftKey) { // Transform mouse down point to stimulus coordinates PointF mouseLocation = this.GetTransformedMouseLocation(e.Location); // If is in new shape creation mode if (this.state == BuildState.FirstPointSet) { // Special handling for VGPolylines // return if only a new point is set, and // the polyline is not closed yet. if (this.newShape is VGPolyline) { VGPolyline poly = (VGPolyline)this.newShape; if (!poly.IsClosed) { return; } } else if (this.newShape is VGLine) { // Cast newShape to VGLine VGLine line = (VGLine)this.newShape; line.SecondPoint = mouseLocation; } else { // Shape creation done this.newShape.Bounds = this.GetBoundingRectFromMousePosition(mouseLocation); } this.state = BuildState.None; // New Graphic element created, so notify listeners. this.OnShapeAdded(new ShapeEventArgs(this.newShape)); // CleanUp creation mode this.newShape = null; } else if (this.SelectedElement != null) { // Is not in creation mode, so look for selected elements that were moved. if (this.SelectedElement.Modified) { // Reset modified flag. this.SelectedElement.Modified = false; // Existing GraphicElement Changed, so notify listeners. this.OnShapeChanged(new ShapeEventArgs(this.SelectedElement)); } } this.Cursor = Cursors.Default; } }
/// <summary> /// Resets the selected element and its dependencies to null. /// If there was a selected element, invokes <see cref="ShapeDeselected"/> event. /// </summary> public void ResetSelectedElement() { if (this.selectedElement != null) { this.selectedElement.IsInEditMode = false; // Use property to invoke the ShapeDeselected event this.SelectedElement = null; this.activeGrabHandle = null; this.DrawForeground(false); } }
/// <summary> /// Starts new textual shape by setting the <see cref="VGText"/> /// in the <see cref="newShape"/> field. /// Then calls <see cref="StartCreation(Cursor)"/>. /// </summary> /// <param name="text">The <see cref="VGText"/> to be added to the <see cref="Picture"/></param> public void NewTextStart(VGText text) { Point position = this.Location; position.Offset( (int)((this.Width / 2) - (text.Size.Width / 2)), (int)((this.Height / 2) - (text.Size.Height / 2))); text.Location = position; this.newShape = text; this.StartCreation(CustomCursors.Text); }
/// <summary> /// Starts new image object by setting the <see cref="VGImage"/> /// in the <see cref="newShape"/> field. /// Then calls <see cref="StartCreation(Cursor)"/>. /// </summary> /// <param name="image">The <see cref="VGImage"/> to be added to the <see cref="Picture"/></param> public void NewImageStart(VGImage image) { switch (image.Layout) { case ImageLayout.Stretch: case ImageLayout.Tile: case ImageLayout.Zoom: case ImageLayout.Center: // In this cases no more drag and pull is needed, // so add the new image to the list. this.Elements.Add(image); // Select it this.SelectedElement = image; break; case ImageLayout.None: // Position and size is needed, so start dragging this.newShape = image; this.StartCreation(CustomCursors.Image); break; } }
/// <summary> /// Starts new line shape by creating a <see cref="VGLine"/> /// in the <see cref="newShape"/> field. /// Then calls <see cref="StartCreation(Cursor)"/>. /// </summary> /// <param name="newShapeDrawAction">The <see cref="ShapeDrawAction"/> for the /// new shape.</param> /// <param name="pen">The <see cref="Pen"/> for the new shape.</param> /// <param name="brush">The <see cref="Brush"/> for the new shape.</param> /// <param name="font">The <see cref="Font"/> for the new shape.</param> /// <param name="fontColor">The <see cref="Color"/> for the font of the new shape.</param> /// <param name="group">The <see cref="VGStyleGroup"/> for the new shape.</param> /// <param name="name">The optional name for the new shape.</param> public void NewLineStart( ShapeDrawAction newShapeDrawAction, Pen pen, Brush brush, Font font, Color fontColor, VGStyleGroup group, string name) { if (pen != null) { this.defaultPen = pen; } if (brush != null) { this.defaultBrush = brush; } if (font != null) { this.defaultFont = font; } if (fontColor != Color.Empty) { this.defaultFontColor = fontColor; } this.newShape = new VGLine( newShapeDrawAction, this.defaultPen, this.defaultFont, this.defaultFontColor, group, name, string.Empty); this.StartCreation(CustomCursors.Line); }
/// <summary> /// Starts new shape by setting the <see cref="VGElement"/> /// in the <see cref="newShape"/> field. /// Then calls <see cref="StartCreation(Cursor)"/>. /// </summary> /// <param name="element">The <see cref="VGElement"/> to be added to the <see cref="Picture"/></param> public void NewShapeStart(VGElement element) { this.newShape = element; if (this.newShape is VGRectangle) { this.StartCreation(CustomCursors.Rectangle); } else if (this.newShape is VGEllipse) { this.StartCreation(CustomCursors.Ellipse); } else if (this.newShape is VGPolyline) { this.currentLine = new VGLine(ShapeDrawAction.Edge, this.newShape.Pen); this.StartCreation(CustomCursors.Polyline); } else if (this.newShape is VGLine) { this.StartCreation(CustomCursors.Line); } else if (this.newShape is VGSound) { this.StartCreation(CustomCursors.Sound); } else if (this.newShape is VGSharp) { this.StartCreation(CustomCursors.Sharp); } }
/// <summary> /// Starts new rectangular shape by creating a <see cref="VGRectangle"/> /// in the <see cref="newShape"/> field. /// Then calls <see cref="StartCreation(Cursor)"/>. /// </summary> /// <param name="newShapeDrawAction">The <see cref="ShapeDrawAction"/> for the /// new shape.</param> /// <param name="pen">The <see cref="Pen"/> for the new shape.</param> /// <param name="brush">The <see cref="Brush"/> for the new shape.</param> /// <param name="font">The <see cref="Font"/> for the new shape.</param> /// <param name="fontColor">The <see cref="Color"/> for the font of the new shape.</param> /// <param name="group">The <see cref="VGStyleGroup"/> for the new shape.</param> /// <param name="name">The optional name for the new shape.</param> public void NewRectangleStart( ShapeDrawAction newShapeDrawAction, Pen pen, Brush brush, Font font, Color fontColor, VGStyleGroup group, string name) { if (pen != null) { this.defaultPen = pen; } if (brush != null) { this.defaultBrush = brush; } if (font != null) { this.defaultFont = font; } if (fontColor != Color.Empty) { this.defaultFontColor = fontColor; } // Create Rect with defined stroke this.newShape = new VGRectangle( newShapeDrawAction, this.defaultPen, this.defaultBrush, this.defaultFont, this.defaultFontColor, RectangleF.Empty, group, name, string.Empty); this.StartCreation(CustomCursors.Rectangle); }
/// <summary> /// Handles the Paste event by pasting an <see cref="VGElement"/> from the /// clipboard into the picture. /// </summary> public virtual void OnPaste() { // Retrieves the data from the clipboard. object test = Clipboard.GetData(DataFormats.StringFormat); if (test == null) { return; } VGElement t = VGElement.Deserialize(test.ToString()); // Determines whether the data is in a format you can use. if (t != null) { VGElement elementToAdd = t; this.ResetSelectedElement(); if (!this.Elements.Contains(elementToAdd)) { this.Elements.Add(elementToAdd); this.selectedElement = elementToAdd; // New Graphic element created, so notify listeners. this.OnShapeAdded(new ShapeEventArgs(elementToAdd)); } } }
/// <summary> /// Overridden <see cref="Control.MouseDown"/> event handler. /// Starts requested shape creation when left mouse button is pressed. /// Otherwise looks for elements under mouse cursor and selects them. /// If there is already a selected element and the mouse is over a grab /// handle it is selected. /// </summary> /// <remarks>Pressing the ALT key during selection iterates /// through the elementsUnderMouseCursor collection.</remarks> /// <param name="e">The <see cref="MouseEventArgs"/> with the event data (click point).</param> protected override void OnMouseDown(MouseEventArgs e) { // base.OnMouseDown(e); // Achieve focus to the picture, because otherwise it will not // receive input keys which are interesting as modifiers. this.Focus(); if (Control.ModifierKeys != Keys.ShiftKey) { // Transform mouse down point to stimulus coordinates PointF mouseLocationF = this.GetTransformedMouseLocation(e.Location); Point mouseLocation = Point.Round(mouseLocationF); if (this.state != BuildState.None) { // Is creating a new shape // Left Mouse Button pressed, so start Logging if (e.Button == MouseButtons.Left) { this.state = BuildState.FirstPointSet; // Add the new shape to the list. if (!this.Elements.Contains(this.newShape)) { this.Elements.Add(this.newShape); } // Select it this.SelectedElement = this.newShape; // save click point for later bounding rectangle creation this.firstClickPoint = mouseLocationF; // Special handling for polyline construction // every click is a polyline point // up to the moment the polyline is closed if (this.newShape is VGPolyline) { this.currentLine.FirstPoint = this.firstClickPoint; // Add the _CurrentLine element during polyline // creation if (!Elements.Contains(this.currentLine)) { Elements.Add(this.currentLine); } // Cast newShape to polyline VGPolyline poly = (VGPolyline)this.newShape; // Check for closing polyline conditions if (this.PointsAreNear(poly.FirstPt, mouseLocationF) && poly.GetPointCount() > 2) { // If the mouse click point is near the first point // close polyline. poly.ClosePolyline(); this.state = BuildState.None; // New Graphic element created, so notify listeners. this.OnShapeAdded(new ShapeEventArgs(this.newShape)); // CleanUp creation mode this.Elements.Remove(this.currentLine); this.newShape = null; } else { // Point is anywhere else, but not near the first // polyline point. // Add new polyline point and update CurrentLine. this.currentLine.FirstPoint = mouseLocationF; poly.AddPt(mouseLocationF); } } else if (this.newShape is VGLine) { // Cast newShape to VGLine VGLine line = (VGLine)this.newShape; line.FirstPoint = this.firstClickPoint; } else if (this.newShape is VGFlash) { // Cast newShape to VGFlash VGFlash flash = (VGFlash)this.newShape; flash.InitializeOnControl(this.Parent, false, this.StimulusToScreen); } } } else { // We are not in new shape creation mode if (e.Button == MouseButtons.Left) { this.mouseDownPoint = e.Location; // Store elements under mouse cursor. VGElementCollection elementsUnderMouseCursor = new VGElementCollection(); int numberOfElements = this.Elements.Count; for (int i = 0; i < numberOfElements; i++) { VGElement currentElement = this.Elements[numberOfElements - i - 1]; if (currentElement.Contains(mouseLocation)) { elementsUnderMouseCursor.Add(currentElement); if (currentElement == this.SelectedElement) { this.counterUnderCursor = elementsUnderMouseCursor.Count - 1; } } } if (this.selectedElement == null) { // Check whether an element lies under // mouse cursor. Select the next item. if (elementsUnderMouseCursor.Count > 0) { this.SelectedElement = elementsUnderMouseCursor[0]; this.selectedElement.IsInEditMode = true; } else { this.SelectedElement = null; } } else if (this.selectedElement.Contains(mouseLocation)) { // Click in selected element // could be more than one, so iterate if Modifier alt is pressed. if (Control.ModifierKeys == Keys.Alt) { this.Cursor = Cursors.Default; this.counterUnderCursor++; // Reset counter if larger than element list size. if (this.counterUnderCursor >= elementsUnderMouseCursor.Count) { this.counterUnderCursor = 0; } // Select next item if there is any if (elementsUnderMouseCursor.Count > 1) { this.ResetSelectedElement(); // Use property to invoke Shape Selected event. this.SelectedElement = elementsUnderMouseCursor[this.counterUnderCursor]; this.selectedElement.IsInEditMode = true; } } else { // No alt is pressed // Select grab handle, if mouse is over it foreach (GrabHandle handle in this.selectedElement.GrabHandles) { if (handle.Contains(mouseLocation)) { this.activeGrabHandle = handle; break; } // Select center handle this.activeGrabHandle = this.selectedElement.GrabHandles[0]; } } } else { // Click in region outside current selected element // Reset selected element. And look for other element // under mouse cursor. this.ResetSelectedElement(); // Select the first element that lies under mouse cursor. if (elementsUnderMouseCursor.Count > 0) { this.SelectedElement = elementsUnderMouseCursor[0]; this.selectedElement.IsInEditMode = true; } else { this.SelectedElement = null; } } this.DrawForeground(false); } } } }
/// <summary> /// The delete shape. /// </summary> /// <param name="vGElement"> /// The v g element. /// </param> internal void DeleteShape(VGElement vGElement) { if (this.AoiCollection.Contains(vGElement)) { this.AoiCollection.Remove(vGElement); } if (this.Elements.Contains(vGElement)) { this.Elements.Remove(vGElement); } this.DrawForeground(true); }
/// <summary> /// Starts new flash object by setting the <see cref="VGFlash"/> /// in the <see cref="newShape"/> field. /// Then calls <see cref="StartCreation(Cursor)"/>. /// </summary> /// <param name="flash">The <see cref="VGFlash"/> to be added to the <see cref="Picture"/></param> public void NewFlashStart(VGFlash flash) { this.newShape = flash; this.StartCreation(CustomCursors.Image); }
/////////////////////////////////////////////////////////////////////////////// // Construction and Initializing methods // /////////////////////////////////////////////////////////////////////////////// #region CONSTRUCTION /// <summary> /// Initializes a new instance of the ShapeEventArgs class. /// </summary> /// <param name="shape">The <see cref="VGElement"/> to store.</param> public ShapeEventArgs(VGElement shape) { this.shape = shape; }
/// <summary> /// Calculates whether the fixation given in datarow hits one of the /// areas of interest given in the AOI collection. /// </summary> /// <param name="aoi">A <see cref="VGElement"/> with the area of interest to check for.</param> /// <param name="fixationRow">fixational row</param> /// <returns>True if aoi is hitted from fixation.</returns> private static bool IsFixAtTarget(VGElement aoi, DataRowView fixationRow) { // Check for intersection PointF searchPoint = new PointF( Convert.ToSingle(fixationRow["PosX"]), Convert.ToSingle(fixationRow["PosY"])); if (aoi.Contains(searchPoint, tolerance)) { return true; } return false; }