Example #1
0
        public bool Render(ICanvas canvas, IDisplayObject displayObject)
        {
            IPointer pointer  = displayObject as IPointer;
            Vector3f position = pointer.CanvasPosition;

            // A pointer style object.
            GuiPointer.GuiPointerStyle style =
                displayObject.Style.GetStyle <GuiPointer.GuiPointerStyle>(CommonStyleStates.Normal);
            if (style == null)
            {
                return(false);
            }

            // For now create dot of size in pixels.
            Metrics.GuiVector2 vector = new SharpMedia.Graphics.GUI.Metrics.GuiVector2(new Vector2f(4, 4),
                                                                                       Vector2f.Zero, Vector2f.Zero);

            Vector2f v     = vector.ToConvasSize(canvas, null);
            Rectf    shape = new Rectf(position - v, position + new Vector2f(v.X, -v.Y),
                                       position + v);

            // We now render pointer
            AreaRenderer.RenderBorderAndArea(canvas, shape, shape, style, null, 0.0f);

            return(true);
        }
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.selected is SimVehicle)
            {
                // vehicle
                SimVehicle isv = (SimVehicle)this.selected;

                // notfy
                SimulatorOutput.WriteLine("Removed Vehicle: " + isv.SimVehicleState.VehicleID.ToString());

                // remove
                this.displayObjects.Remove(this.selected);
                this.Simulation.simEngine.Vehicles.Remove(isv.VehicleId);
                this.Simulation.clientHandler.Remove(isv.VehicleId);
                this.Simulation.OnClientsChanged();

                if (this.tracked != null && this.tracked.VehicleId.Equals(isv.VehicleId))
                {
                    this.tracked = null;
                }

                // remove selecation
                this.selected = null;

                // properties
                this.Simulation.simEngine.SetPropertyGridDefault();

                // redraw
                this.Invalidate();
            }
        }
Example #3
0
        private Size GetSizeUsingWpf(IDisplayObject displayObject)
        {
            try
            {
                var photoBytes = File.ReadAllBytes(displayObject.FileNamePhysicalPath);
                using (var photoStream = new MemoryStream(photoBytes))
                {
                    var photo = ReadBitmapFrame(photoStream);
                    return(new Size(photo.PixelWidth, photo.PixelHeight));
                }
            }
            catch (NotSupportedException)
            {
                return(GetSizeUsingGdi(displayObject));
            }
            catch (Exception ex)
            {
                if (!ex.Data.Contains("SizeMsg"))
                {
                    ex.Data.Add("SizeMsg", String.Format("Unable to get the width and height of media object {0} ({1}). Display Type {2}", GalleryObject.Id, displayObject.FileNamePhysicalPath, displayObject.DisplayType));
                }

                EventController.RecordError(ex, AppSetting.Instance, GalleryObject.GalleryId, Factory.LoadGallerySettings());

                return(Size.Empty);
            }
        }
        protected internal BaseSchemeEasySearch(ITableScheme scheme, string idField, string nameField, bool canCache)
        {
            TkDebug.AssertArgumentNull(scheme, "scheme", null);
            TkDebug.AssertArgument(scheme is IDisplayObject, "scheme",
                                   "scheme需要支持IDisplayObject接口", scheme);

            fDisplay = scheme.Convert <IDisplayObject>();
            TkDebug.Assert(fDisplay.SupportDisplay,
                           "scheme的SupportDisplay必须为true,当前是false", scheme);
            SourceScheme = scheme;
            fDisplay     = new TempDisplay(fDisplay, scheme, idField, nameField);
            if (canCache)
            {
                canCache = idField == null && nameField == null;
            }
            if (canCache)
            {
                fScheme = new EasySearchProxyScheme(scheme, fDisplay);
            }
            else
            {
                fScheme = new NoCacheEasySearchProxyScheme(scheme, fDisplay);
            }
            ValueField = fDisplay.Id;
            NameField  = fDisplay.Name;
        }
Example #5
0
        public MediaObjectHtmlBuilder(IGalleryObject mediaObject, IDisplayObject displayObject, Array browsers)
        {
            if (mediaObject == null)
            {
                throw new ArgumentNullException("mediaObject");
            }

            if (displayObject == null)
            {
                throw new ArgumentNullException("displayObject");
            }

            if ((browsers == null) || (browsers.Length < 1))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidBrowsers_Msg));
            }

            this._galleryObject           = mediaObject;
            this._mediaObjectId           = mediaObject.Id;
            this._albumId                 = mediaObject.Parent.Id;
            this._mimeType                = displayObject.MimeType;
            this._mediaObjectPhysicalPath = displayObject.FileNamePhysicalPath;
            this._width              = displayObject.Width;
            this._height             = displayObject.Height;
            this._title              = mediaObject.Title;
            this._browsers           = browsers;
            this._displayType        = displayObject.DisplayType;
            this._isPrivate          = mediaObject.IsPrivate;
            this._galleryId          = mediaObject.GalleryId;
            this._externalHtmlSource = displayObject.ExternalHtmlSource;
        }
        /// <summary>
        /// Create a new display object instance with the specified properties. No data is retrieved from the
        /// data store. A lazy load is used to inflate the object when necessary
        /// </summary>
        /// <param name="parent">The media object to which this display object applies. This will typically be
        /// an Album object.</param>
        /// <param name="sourceMediaObjectId">The ID of the media object to use as the source for setting this
        /// object's properties.</param>
        /// <param name="displayType">The display object type of the source media object to use to set this object's
        /// properties. For example, if displayType=Thumbnail, then use the properties of the source media
        /// object's thumbnail object to assign to this display object's properties.</param>
        /// <returns>Create a new display object instance with the specified properties.</returns>
        /// <remarks>This overload of CreateInstance() is typically used when instantiating albums.</remarks>
        public static IDisplayObject CreateInstance(IGalleryObject parent, int sourceMediaObjectId, DisplayObjectType displayType)
        {
            IDisplayObject newDisObject = CreateInstance(parent, string.Empty, int.MinValue, int.MinValue, displayType, new NullObjects.NullDisplayObjectCreator());

            newDisObject.MediaObjectId = sourceMediaObjectId;

            return(newDisObject);
        }
 /// <summary>
 /// Creates an array of three of <see cref="CacheItemDisplayObject" /> instances representing the three parameters. This instance is suitable for storing in cache.
 /// </summary>
 /// <param name="thumbnail">The thumbnail display object.</param>
 /// <param name="optimized">The optimized display object.</param>
 /// <param name="original">The original display object.</param>
 /// <returns>A three-item array of <see cref="CacheItemDisplayObject" /> instances.</returns>
 public static CacheItemDisplayObject[] CreateFrom(IDisplayObject thumbnail, IDisplayObject optimized, IDisplayObject original)
 {
     return(new[]
     {
         new CacheItemDisplayObject(thumbnail.Width, thumbnail.Height, thumbnail.FileName, thumbnail.FileSizeKB, thumbnail.ExternalHtmlSource, thumbnail.ExternalType),
         new CacheItemDisplayObject(optimized.Width, optimized.Height, optimized.FileName, optimized.FileSizeKB, optimized.ExternalHtmlSource, optimized.ExternalType),
         new CacheItemDisplayObject(original.Width, original.Height, original.FileName, original.FileSizeKB, original.ExternalHtmlSource, original.ExternalType)
     });
 }
Example #8
0
        public SharpMedia.Math.Vector2f GetRelative(IDisplayObject obj)
        {
            // We convert to object's rectangle.
            Vector2f rightBottom, topRight;

            GetBoundingBox(out rightBottom, out topRight);

            throw new NotImplementedException();
        }
Example #9
0
		private bool _hasBeenDisposed; // Used by Dispose() methods

		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="GalleryObject"/> class.
		/// </summary>
		protected GalleryObject()
		{
			this._parent = new NullObjects.NullGalleryObject();
			this._thumbnail = new NullObjects.NullDisplayObject();
			this._optimized = new NullObjects.NullDisplayObject();
			this._original = new NullObjects.NullDisplayObject();

			// Default IsSynchronized to true. It is set to false during a synchronization.
			this.IsSynchronized = true;
		}
Example #10
0
        void Dispose(bool fin)
        {
            // We also free other resources.
            if (!fin)
            {
                canvas     = null;
                rootObject = null;

                GC.SuppressFinalize(this);
            }
        }
        /// <summary>
        /// What to do when user clicks display
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            #region Hit Test

            // perform the hit test over the filter
            HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), this.CarFilter);

            // check current selection if need to set as not selected
            if (this.selected != null && (htr.Hit && !this.selected.Equals(htr.DisplayObject)) ||
                (!htr.Hit))
            {
                if (this.selected != null)
                {
                    // remove current selection
                    this.selected.Selected = SelectionType.NotSelected;
                }

                this.selected = null;
            }

            #endregion

            #region Left

            if (e.Button == MouseButtons.Left)
            {
                // check if we hit a vehicle
                if (htr.Hit && htr.DisplayObject is CarDisplayObject)
                {
                }
                else
                {
                    controlTag     = new Point(e.X, e.Y);
                    isDragging     = true;
                    Cursor.Current = Cursors.Hand;
                }
            }

            #endregion

            #region Right

            else if (e.Button == MouseButtons.Right)
            {
                if (htr.Hit && htr.DisplayObject is CarDisplayObject)
                {
                }
            }

            #endregion

            base.OnMouseDown(e);
            this.Invalidate();
        }
Example #12
0
        protected BaseSchemeCodeTable(ITableScheme scheme)
        {
            TkDebug.AssertArgumentNull(scheme, "scheme", null);
            TkDebug.AssertArgument(scheme is IDisplayObject, "scheme",
                                   "scheme需要支持IDisplayObject接口", scheme);

            fScheme  = scheme;
            fDisplay = scheme.Convert <IDisplayObject>();
            TkDebug.Assert(fDisplay.SupportDisplay,
                           "scheme的SupportDisplay必须为true,当前是false", scheme);
        }
Example #13
0
        void SetStyleState(StyleState stateTo)
        {
            IDisplayObject dObject = displayObject;

            if (dObject != null)
            {
                dObject.StyleAnimation.TransistTo(stateTo);
            }

            animationState.TransistTo(stateTo);
        }
Example #14
0
        protected override void ApplyBoundingRectInternal(ICanvas canvas, Vector2f minPosition, Vector2f maxPosition)
        {
            base.ApplyBoundingRectInternal(canvas, minPosition, maxPosition);


            IDisplayObject obj = displayObject;

            if (obj != null)
            {
                obj.ApplyBoundingRect(canvas, minPosition, maxPosition);
            }
        }
Example #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GalleryObject"/> class.
        /// </summary>
        protected GalleryObject()
        {
            this._parent = new NullObjects.NullGalleryObject();
            this._thumbnail = new NullObjects.NullDisplayObject();
            this._optimized = new NullObjects.NullDisplayObject();
            this._original = new NullObjects.NullDisplayObject();

            // Default IsSynchronized to false. It is set to true during a synchronization.
            this.IsSynchronized = false;
            this.IsWritable = true;

            this.BeforeAddMetaItem += OnBeforeAddMetaItem;
        }
Example #16
0
        public static IDisplayObject GetRoot(IDisplayObject obj)
        {
            if (obj == null)
            {
                return(null);
            }

            while (obj.Parent != null)
            {
                obj = obj.Parent;
            }

            return(obj);
        }
        /// <summary>
        /// Center upon double click
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // Get the offset.
                Point point = new Point(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2);

                // Calculate change in position
                double deltaX = e.X - point.X;
                double deltaY = e.Y - point.Y;

                // Update the world
                Coordinates tempCenter = WorldTransform.CenterPoint;
                tempCenter.X += deltaX / WorldTransform.Scale;
                tempCenter.Y -= deltaY / WorldTransform.Scale;
                WorldTransform.CenterPoint = tempCenter;
            }
            else if (e.Button == MouseButtons.Right)
            {
                // filter for vehicles
                DisplayObjectFilter vhcDof = delegate(IDisplayObject target)
                {
                    // check if target is network object
                    if (target is SimObstacle)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                };

                // check to see if selected a car or obstacle
                HitTestResult vhcHtr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), vhcDof);

                // check for obstacle
                if (vhcHtr.Hit && vhcHtr.DisplayObject is SimObstacle)
                {
                    this.selected = vhcHtr.DisplayObject;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;
                    this.obstacleContextMenuStrip.Show(this, e.X, e.Y);
                    ((SimObstacle)this.selected).Selected = SelectionType.SingleSelected;
                }
            }

            // redraw
            Invalidate();
        }
        /// <summary>
        /// Delete obstacle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteObstacleContextToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (this.selected is SimObstacle)
            {
                SimObstacle so = (SimObstacle)this.selected;
                this.displayObjects.Remove(so);
                this.Simulation.simEngine.WorldService.Obstacles.Remove(so.ObstacleId);
                this.Simulation.simEngine.SetPropertyGridDefault();
                this.selected = null;

                SimulatorOutput.WriteLine("Removed Obstacle: " + so.ObstacleId.ToString());

                this.Invalidate();
            }
        }
Example #19
0
        public virtual bool Render(ICanvas canvas, IDisplayObject displayObject)
        {
            // We extract data.
            Area  area   = displayObject as Area;
            Style styles = displayObject.Style;

            // We determine state.
            Area.AreaStyle style, nextStyle;
            float          alpha = displayObject.Style.GetStyleState <Area.AreaStyle>(
                displayObject.StyleAnimation, out style, out nextStyle);


            RenderBorderAndArea(canvas, displayObject.Shape,
                                displayObject.Outline, style, nextStyle, alpha);

            return(true);
        }
Example #20
0
 /// <summary>
 /// Gets the width and height of the specified <paramref name="displayObject" />. The value is calculated from the
 /// physical file. Returns an empty <see cref="System.Windows.Size" /> instance if the value cannot be computed or
 /// is not applicable to the object (for example, for audio files and external media objects).
 /// </summary>
 /// <returns><see cref="System.Windows.Size" />.</returns>
 public Size GetSize(IDisplayObject displayObject)
 {
     if (AppSetting.Instance.AppTrustLevel == ApplicationTrustLevel.Full)
     {
         try
         {
             return(GetSizeUsingWpf(displayObject));
         }
         catch (NotSupportedException)
         {
             return(GetSizeUsingGdi(displayObject));
         }
     }
     else
     {
         return(GetSizeUsingGdi(displayObject));
     }
 }
Example #21
0
        public override bool Render(ICanvas canvas, IDisplayObject displayObject)
        {
            // Button redirects rendering to underlaying.
            Button button = displayObject as Button;

            // We render button.
            if (!base.Render(canvas, button))
            {
                return(false);
            }

            IDisplayObject obj = button.DisplayObject;

            if (obj != null)
            {
                return(obj.Skin.Render(canvas, button.DisplayObject));
            }
            return(true);
        }
        /// <summary>
        /// Return the requested display object from the specified media object. If Unknown is passed in the
        /// displayType parameter, and the object is an image, return the optimized object. If an optimized
        /// version does not exist, return the original object. If Unknown is passed in the displayType parameter,
        /// and the object is NOT an image, return the original object. If a thumbnail is requested, always
        /// return a thumbnail object.
        /// </summary>
        /// <param name="mediaObject">The media object containing the display object to return.</param>
        /// <param name="displayType">One of the DisplayObjectType enumeration values indicating which object to return.</param>
        /// <returns>Returns the requested display object from the specified media object.</returns>
        public static IDisplayObject GetDisplayObject(IGalleryObject mediaObject, DisplayObjectType displayType)
        {
            IDisplayObject displayObject = null;

            if (displayType == DisplayObjectType.Thumbnail)
            {
                displayObject = mediaObject.Thumbnail;
            }
            else if (mediaObject is GalleryServerPro.Business.Image)
            {
                displayObject = GetDisplayObjectForImage(mediaObject, displayType);
            }
            else
            {
                displayObject = mediaObject.Original;
            }

            return(displayObject);
        }
Example #23
0
        public EasySearchProxyScheme(ITableScheme scheme, IDisplayObject displayObject)
        {
            var creator = scheme as ICacheDependencyCreator;

            if (creator != null)
            {
                fCacheDependency = creator.CreateCacheDependency();
            }
            else
            {
                fCacheDependency = AlwaysDependency.Dependency;
            }

            fScheme        = scheme;
            fDisplayObject = displayObject;
            IFieldInfo info = displayObject.Id;

            fKeyField  = new KeyFieldItem(info.FieldName, DecoderConst.CODE_NICK_NAME, info.DataType);
            info       = displayObject.Name;
            fNameField = new FieldItem(info.FieldName, DecoderConst.NAME_NICK_NAME, info.DataType);
        }
        /// <summary>
        /// Gets the width and height of the specified <paramref name="displayObject" />. The value is calculated from the
        /// physical file. Returns an empty <see cref="Size" /> instance if the value cannot be computed or
        /// is not applicable to the object (for example, for audio files and external media objects).
        /// </summary>
        /// <param name="displayObject">The display object.</param>
        /// <returns><see cref="ISize" />.</returns>
        public ISize GetSize(IDisplayObject displayObject)
        {
            try
            {
                var image = SixLabors.ImageSharp.Image.Load(displayObject.FileNamePhysicalPath);

                return new Size(image.Width, image.Height);
            }
            catch (ArgumentException)
            {
                return Size.Empty;
            }
            catch (ExternalException)
            {
                return Size.Empty;
            }
            catch (OutOfMemoryException)
            {
                return Size.Empty;
            }

        }
Example #25
0
        /// <summary>
        /// Renders object and children recursevelly.
        /// </summary>
        /// <param name="obj"></param>
        void RenderObject(IDisplayObject obj)
        {
            IGuiRenderer renderer = obj.Skin;

            if (renderer == null)
            {
                throw new InvalidOperationException();
            }

            renderer.Render(canvas, obj);

            if (obj is IContainer)
            {
                foreach (object child in (obj as IContainer).Children)
                {
                    if (child is IDisplayObject)
                    {
                        RenderObject(child as IDisplayObject);
                    }
                }
            }
        }
Example #26
0
 private static Size GetSizeUsingGdi(IDisplayObject displayObject)
 {
     try
     {
         using (var source = new System.Drawing.Bitmap(displayObject.FileNamePhysicalPath))
         {
             return(new Size(source.Width, source.Height));
         }
     }
     catch (ArgumentException)
     {
         return(Size.Empty);
     }
     catch (ExternalException ex)
     {
         return(Size.Empty);
     }
     catch (OutOfMemoryException ex)
     {
         return(Size.Empty);
     }
 }
        /// <summary>
        /// Center upon double click
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // Get the offset.
                Point point = new Point(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2);

                // Calculate change in position
                double deltaX = e.X - point.X;
                double deltaY = e.Y - point.Y;

                // Update the world
                Coordinates tempCenter = WorldTransform.CenterPoint;
                tempCenter.X += deltaX / WorldTransform.Scale;
                tempCenter.Y -= deltaY / WorldTransform.Scale;
                WorldTransform.CenterPoint = tempCenter;
            }
            else if (e.Button == MouseButtons.Right)
            {
                // filter for vehicles
                DisplayObjectFilter vhcDof = delegate(IDisplayObject target)
                {
                    // check if target is network object
                    if (target is SimObstacle)
                        return true;
                    else
                        return false;
                };

                // check to see if selected a car or obstacle
                HitTestResult vhcHtr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), vhcDof);

                // check for obstacle
                if (vhcHtr.Hit && vhcHtr.DisplayObject is SimObstacle)
                {
                    this.selected = vhcHtr.DisplayObject;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;
                    this.obstacleContextMenuStrip.Show(this, e.X, e.Y);
                    ((SimObstacle)this.selected).Selected = SelectionType.SingleSelected;
                }
            }

            // redraw
            Invalidate();
        }
        /// <summary>
        /// Delete obstacle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteObstacleContextToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (this.selected is SimObstacle)
            {
                SimObstacle so = (SimObstacle)this.selected;
                this.displayObjects.Remove(so);
                this.Simulation.simEngine.WorldService.Obstacles.Remove(so.ObstacleId);
                this.Simulation.simEngine.SetPropertyGridDefault();
                this.selected = null;

                SimulatorOutput.WriteLine("Removed Obstacle: " + so.ObstacleId.ToString());

                this.Invalidate();
            }
        }
        /// <summary>
        /// What to do when user clicks display
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            #region Hit Test

            // filter for vehicles or obstacles
            DisplayObjectFilter dof = delegate(IDisplayObject target)
            {
                // check if target is network object
                if (target is CarDisplayObject || target is SimObstacle)
                    return true;
                else
                    return false;
            };

            // perform the hit test over the filter
            HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);

            // check current selection if need to set as not selected
            if (this.selected != null && (htr.Hit && !this.selected.Equals(htr.DisplayObject))
                || (!htr.Hit))
            {
                if (this.selected != null)
                {
                    // remove current selection
                    this.selected.Selected = SelectionType.NotSelected;
                }

                this.selected = null;
                this.Simulation.simEngine.SetPropertyGridDefault();
            }

            #endregion

            #region Left

            if (e.Button == MouseButtons.Left)
            {
                // check if we hit a vehicle
                if (htr.Hit &&  htr.DisplayObject is SimVehicle)
                {
                    // display obj
                    CarDisplayObject cdo = (CarDisplayObject)htr.DisplayObject;

                    // set the vehicles as selected
                    cdo.Selected = SelectionType.SingleSelected;
                    this.selected = cdo;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = cdo;

                    // check if we can move the vehicle
                    if (!((SimVehicle)cdo).VehicleState.IsBound)
                    {
                        // set dragging
                        isDragging = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = cdo.Position;
                    }

                    // redraw
                    this.Invalidate();
                }
                // check if hit obstacle
                else if (htr.Hit && htr.DisplayObject is SimObstacle)
                {
                    // set selected
                    this.selected = htr.DisplayObject;
                    this.selected.Selected = SelectionType.SingleSelected;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;

                    // check if can move
                    if (((SimObstacle)htr.DisplayObject).MoveAllowed)
                    {
                        // set dragging
                        isDragging = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = ((SimObstacle)this.selected).Position;
                    }

                    // redraw
                    this.Invalidate();
                }
                else
                {
                    controlTag = new Point(e.X, e.Y);
                    isDragging = true;
                    Cursor.Current = Cursors.Hand;
                }
            }

            #endregion

            #region Right

            else if (e.Button == MouseButtons.Right)
            {
                if (htr.Hit && htr.DisplayObject is CarDisplayObject)
                {
                    this.selected = htr.DisplayObject;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;
                    this.vehicleContextMenuStrip1.Show(this, e.X, e.Y);
                    ((CarDisplayObject)this.selected).Selected = SelectionType.SingleSelected;
                }
                else if (htr.Hit && htr.DisplayObject is SimObstacle)
                {
                    // set selected
                    this.selected = htr.DisplayObject;
                    this.selected.Selected = SelectionType.SingleSelected;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;

                    // check if we can move the obstacle
                    if (((SimObstacle)htr.DisplayObject).MoveAllowed)
                    {
                        // set dragging
                        isDragging = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = transform.GetWorldPoint(new PointF(e.X, e.Y)) - ((SimObstacle)this.selected).Position;
                    }

                    // redraw
                    this.Invalidate();
                }
            }

            #endregion

            base.OnMouseDown(e);
            this.Invalidate();
        }
Example #30
0
 /// <summary>
 /// This method provides an opportunity for a derived class to verify the thumbnail information for this instance has 
 /// been retrieved from the data store. This method is empty.
 /// </summary>
 /// <param name="thumbnail">A reference to the thumbnail display object for this instance.</param>
 protected virtual void VerifyThumbnailIsInflated(IDisplayObject thumbnail)
 {
     // Overridden in Album class.
 }
 public bool ShouldDeselect(IDisplayObject newSelection)
 {
     return true;
 }
        /// <summary>
        /// What to do when user clicks display
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            #region Hit Test

            // perform the hit test over the filter
            HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), this.CarFilter);

            // check current selection if need to set as not selected
            if (this.selected != null && (htr.Hit && !this.selected.Equals(htr.DisplayObject))
                || (!htr.Hit))
            {
                if (this.selected != null)
                {
                    // remove current selection
                    this.selected.Selected = SelectionType.NotSelected;
                }

                this.selected = null;
            }

            #endregion

            #region Left

            if (e.Button == MouseButtons.Left)
            {
                // check if we hit a vehicle
                if (htr.Hit && htr.DisplayObject is CarDisplayObject)
                {
                }
                else
                {
                    controlTag = new Point(e.X, e.Y);
                    isDragging = true;
                    Cursor.Current = Cursors.Hand;
                }
            }

            #endregion

            #region Right

            else if (e.Button == MouseButtons.Right)
            {
                if (htr.Hit && htr.DisplayObject is CarDisplayObject)
                {
                }
            }

            #endregion

            base.OnMouseDown(e);
            this.Invalidate();
        }
 /// <summary>
 /// Adds a new display object to the screen and forces a redraw of the drawing surface
 /// </summary>
 /// <param name="obj">Object to add</param>
 /// <remarks>
 /// Note that if you add the same object twice, nothing complains. However, only one will be removed once if calling RemoveDisplayObject.
 /// </remarks>
 public void AddDisplayObject(IDisplayObject obj)
 {
     displayObjects.Add(obj);
     Invalidate();
 }
Example #34
0
 public bool ShouldDeselect(IDisplayObject newSelection)
 {
     return(true);
 }
 /// <summary>
 /// Sets the waypoint we're using
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="orig"></param>
 public void SetWaypoint(IDisplayObject obj, Coordinates orig)
 {
     this.original = orig;
     this.waypoint = obj;
     obj.BeginMove(orig, t);
 }
 public bool Contains(IDisplayObject displayObject)
 {
     return this.Contains(displayObject, true);
 }
 /// <summary>
 /// Cancel the move
 /// </summary>
 public void CancelMove()
 {
     waypoint.CancelMove(original, t);
     this.waypoint = null;
 }
 public bool Contains(IDisplayObject displayObject, bool deep)
 {
     bool any = this.Children.Any(child => child is DisplayObjectContainer && (child as DisplayObjectContainer).Contains(displayObject, true));
     return deep ? any || this.Children.Contains(displayObject) : this.Children.Contains(displayObject);
 }
 public void AddChild(IDisplayObject displayObject)
 {
     displayObject.Parent = this;
     this.Children.Add(displayObject);
 }
 public void RemoveChild(IDisplayObject displayObject)
 {
     displayObject.Parent = null;
     this.Children.Remove(displayObject);
 }
 public void AddChildAt(IDisplayObject displayObject, int index)
 {
     displayObject.Parent = this;
     this.Children.Insert(index, displayObject);
 }
        /// <summary>
        /// When mouse clicked
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseClick(MouseEventArgs e)
        {
            #region Left

            if (e.Button == MouseButtons.Left)
            {
                if (this.CurrentEditorTool is RulerTool)
                {
                    RulerTool ruler = (RulerTool)this.CurrentEditorTool;

                    if (ruler.Initial == null)
                    {
                        ruler.Initial = transform.GetWorldPoint(new PointF(e.X, e.Y));

                        if (this.SecondaryEditorTool != null && this.SecondaryEditorTool is PointAnalysisTool)
                        {
                            PointAnalysisTool pat = ((PointAnalysisTool)this.SecondaryEditorTool);

                            pat.Save = new List<Coordinates>();
                            pat.Save.Add(ruler.Initial.Value);
                        }
                    }
                    else if (ruler.Current != null)
                    {
                        ruler.Initial = null;
                        ruler.Current = null;

                        if (this.SecondaryEditorTool != null && this.SecondaryEditorTool is PointAnalysisTool)
                        {
                            PointAnalysisTool pat = ((PointAnalysisTool)this.SecondaryEditorTool);

                            pat.Save = null;
                        }
                    }
                }
                else if (this.CurrentEditorTool is SparseTool)
                {
                    ((SparseTool)this.CurrentEditorTool).Click(transform.GetWorldPoint(new PointF(e.X, e.Y)));
                }
                else if (this.CurrentEditorTool is AngleMeasureTool)
                {
                    AngleMeasureTool amt = (AngleMeasureTool)this.CurrentEditorTool;

                    if (amt.SetP1 == false)
                    {
                        amt.VSetP1(transform.GetWorldPoint(new PointF(e.X, e.Y)), this.SecondaryEditorTool);
                    }
                    else if (amt.SetP2 == false)
                    {
                        amt.VSetP2(transform.GetWorldPoint(new PointF(e.X, e.Y)), this.SecondaryEditorTool);
                    }
                    else if (amt.SetP3 == false)
                    {
                        amt.VSetP3(this.SecondaryEditorTool);
                    }
                }
                else if (this.CurrentEditorTool is WaypointAdjustmentTool)
                {
                    if (((WaypointAdjustmentTool)this.CurrentEditorTool).CheckInMove)
                    {
                        this.CurrentEditorTool = new WaypointAdjustmentTool(this.transform);
                    }
                    else
                    {
                        // create display object filter for waypoints
                        DisplayObjectFilter dof = delegate(IDisplayObject target)
                        {
                            // check if target is network object
                            if (target is IGenericWaypoint && target is IDisplayObject)
                                return true;
                            else
                                return false;
                        };

                        // perform hit test
                        HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);

                        // check for validity
                        if (htr.Hit)
                        {
                            // set adjust
                            ((WaypointAdjustmentTool)this.CurrentEditorTool).SetWaypoint(htr.DisplayObject, ((IGenericWaypoint)htr.DisplayObject).Position);
                        }
                    }
                }
                else if (this.CurrentEditorTool is IntersectionPulloutTool)
                {
                    IntersectionPulloutTool tool = (IntersectionPulloutTool)this.CurrentEditorTool;

                    // get key current
                    KeyStateInfo shiftKey = KeyboardInfo.GetKeyState(Keys.ShiftKey);

                    if (!shiftKey.IsPressed)
                    {
                        if (tool.Mode == InterToolboxMode.SafetyZone)
                        {
                            // create display object filter for waypoints
                            DisplayObjectFilter dof = delegate(IDisplayObject target)
                            {
                                // check if target is network object
                                if (target is ArbiterLane)
                                    return true;
                                else
                                    return false;
                            };

                            // perform hit test
                            HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);

                            // check for validity
                            if (htr.Hit)
                            {
                                // set undo
                                tool.ed.SaveUndoPoint();

                                // get lane
                                ArbiterLane al = (ArbiterLane)htr.DisplayObject;

                                // get point on lane
                                LinePath.PointOnPath end = al.GetClosestPoint(transform.GetWorldPoint(new PointF(e.X, e.Y)));

                                ArbiterWaypoint aw = al.GetClosestWaypoint(al.LanePath().GetPoint(end), 5);

                                if (aw != null && aw.IsExit == true)
                                {
                                    end = al.GetClosestPoint(aw.Position);
                                }

                                double dist = -30;
                                LinePath.PointOnPath begin = al.LanePath().AdvancePoint(end, ref dist);
                                if (dist != 0)
                                {
                                    EditorOutput.WriteLine("safety zone too close to start of lane, setting start to start of lane");
                                    begin = al.LanePath().StartPoint;
                                }
                                ArbiterSafetyZone asz = new ArbiterSafetyZone(al, end, begin);
                                al.SafetyZones.Add(asz);
                                al.Way.Segment.RoadNetwork.DisplayObjects.Add(asz);
                                al.Way.Segment.RoadNetwork.ArbiterSafetyZones.Add(asz);

                                if (aw != null && aw.IsExit == true)
                                {
                                    asz.isExit = true;
                                    asz.Exit = aw;
                                }

                                // add to display
                                this.displayObjects.Add(asz);
                            }
                        }
                        else if (tool.Mode == InterToolboxMode.Helpers)
                        {
                            // create display object filter for waypoints
                            DisplayObjectFilter dof = delegate(IDisplayObject target)
                            {
                                // check if target is network object
                                if (target is ArbiterLane)
                                    return true;
                                else
                                    return false;
                            };

                            // perform hit test
                            HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);

                            // check for validity
                            if (htr.Hit)
                            {
                                // get lane
                                ArbiterLane al = (ArbiterLane)htr.DisplayObject;

                                // get point on lane
                                tool.WrappingHelpers.Add(al.GetClosest(transform.GetWorldPoint(new PointF(e.X, e.Y))));
                            }
                        }
                        else if (tool.Mode == InterToolboxMode.Box)
                        {
                            // clicked point
                            Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y));

                            // add points
                            if (tool.WrapInitial == null)
                            {
                                tool.WrapInitial = c;
                            }
                            else if (tool.WrapFinal != null && !tool.WrapInitial.Equals(c))
                            {
                                tool.FinalizeIntersection();
                            }
                        }
                    }
                }
                else if (this.CurrentEditorTool is ZoneTool)
                {
                    // get key current
                    KeyStateInfo shiftKey = KeyboardInfo.GetKeyState(Keys.ShiftKey);

                    ZoneTool zt = (ZoneTool)this.CurrentEditorTool;
                    if (zt.moveNode != null)
                    {
                        zt.moveNode = null;
                        zt.Reset(false);
                    }
                    else
                    {
                        if (!shiftKey.IsPressed)
                        {
                            // get key current
                            KeyStateInfo wKey = KeyboardInfo.GetKeyState(Keys.W);

                            if (!wKey.IsPressed)
                            {
                                // clicked point
                                Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y));
                                zt.Click(c);
                            }
                            else
                            {
                                // clicked point
                                Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y));
                                if (zt.zt.current != null && zt.zt.current.Perimeter.PerimeterPolygon.IsInside(c))
                                {
                                    zt.ed.SaveUndoPoint();
                                    zt.BeginMove(c);
                                }
                            }
                        }
                    }
                }

                this.Invalidate();
            }

            #endregion

            #region Right

            else if (e.Button == MouseButtons.Right)
            {
                if (this.CurrentEditorTool is ZoneTool)
                {
                    // clicked point
                    Coordinates c = transform.GetWorldPoint(new PointF(e.X, e.Y));

                    ZoneTool zt = (ZoneTool)this.CurrentEditorTool;
                    if (zt.zt.current != null && zt.zt.current.Perimeter.PerimeterPolygon.IsInside(c))
                    {
                        zt.RightClick(c);
                        this.Invalidate();

                        if (zt.rightClickNode != null || zt.rightClickEdge != null)
                        {
                            this.removeToolStripMenuItem.Enabled = true;
                            this.zoneContextMenuStrip.Show(this, e.X, e.Y);
                        }
                        else
                        {
                            this.removeToolStripMenuItem.Enabled = false;
                            this.zoneContextMenuStrip.Show(this, e.X, e.Y);
                        }
                    }
                }
                else if (this.CurrentEditorTool != null && this.CurrentEditorTool is PartitionTools)
                {
                    PartitionTools pt = (PartitionTools)this.CurrentEditorTool;

                    if (!pt.RemoveUserWaypointMode)
                    {
                        // create display object filter for waypoints
                        DisplayObjectFilter dof = delegate(IDisplayObject target)
                        {
                            // check if target is network object
                            if (target is ArbiterLanePartition)
                                return true;
                            else
                                return false;
                        };

                        HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);
                        if (htr.DisplayObject != null && htr.DisplayObject is ArbiterLanePartition && htr.Hit)
                        {
                            this.selected = htr.DisplayObject;
                            this.selected.Selected = SelectionType.SingleSelected;
                            this.partitionContextMenuStrip.Show(this, e.X, e.Y);

                            pt.HitPoint = transform.GetWorldPoint(new PointF(e.X, e.Y));
                        }
                        else if (this.selected != null)
                        {
                            this.selected.Selected = SelectionType.NotSelected;
                        }
                    }
                    else
                    {
                        // create display object filter for waypoints
                        DisplayObjectFilter dof = delegate(IDisplayObject target)
                        {
                            // check if target is network object
                            if (target is ArbiterUserWaypoint)
                                return true;
                            else
                                return false;
                        };

                        HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);
                        if (htr.DisplayObject != null && htr.DisplayObject is ArbiterUserWaypoint && htr.Hit)
                        {
                            this.selected = htr.DisplayObject;
                            this.selected.Selected = SelectionType.SingleSelected;
                            this.userWaypointContextMenuStrip.Show(this, e.X, e.Y);
                        }
                        else if (this.selected != null)
                        {
                            this.selected.Selected = SelectionType.NotSelected;
                        }
                    }

                    this.Invalidate();
                }
                else
                {
                    // perform hit test
                    HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), DrawingUtility.DefaultFilter);

                    if (htr.DisplayObject == null)
                    {
                    }
                    else if (htr.DisplayObject is ArbiterIntersection)
                    {
                        this.intersectionContextMenuStrip.Show(this, e.X, e.Y);
                        this.selected = htr.DisplayObject;
                    }
                    else if (this.CurrentEditorTool is IntersectionPulloutTool && ((IntersectionPulloutTool)this.CurrentEditorTool).Mode == InterToolboxMode.SafetyZone)
                    {
                        // create display object filter for waypoints
                        DisplayObjectFilter dof = delegate(IDisplayObject target)
                        {
                            // check if target is network object
                            if (target is ArbiterSafetyZone)
                                return true;
                            else
                                return false;
                        };

                        htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);
                        if (htr.DisplayObject is ArbiterSafetyZone)
                        {
                            this.safetyZoneContextMenu.Show(this, e.X, e.Y);
                            this.selected = htr.DisplayObject;
                        }
                    }
                }
            }

            #endregion
        }
 /// <summary>
 /// add a display object
 /// </summary>
 /// <param name="ido"></param>
 public void AddDisplayObject(IDisplayObject ido)
 {
     this.displayObjects.Add(ido);
 }
        /// <summary>
        /// What to do when user clicks display
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            #region Hit Test

            // filter for vehicles or obstacles
            DisplayObjectFilter dof = delegate(IDisplayObject target)
            {
                // check if target is network object
                if (target is CarDisplayObject || target is SimObstacle)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };

            // perform the hit test over the filter
            HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);

            // check current selection if need to set as not selected
            if (this.selected != null && (htr.Hit && !this.selected.Equals(htr.DisplayObject)) ||
                (!htr.Hit))
            {
                if (this.selected != null)
                {
                    // remove current selection
                    this.selected.Selected = SelectionType.NotSelected;
                }

                this.selected = null;
                this.Simulation.simEngine.SetPropertyGridDefault();
            }

            #endregion

            #region Left

            if (e.Button == MouseButtons.Left)
            {
                // check if we hit a vehicle
                if (htr.Hit && htr.DisplayObject is SimVehicle)
                {
                    // display obj
                    CarDisplayObject cdo = (CarDisplayObject)htr.DisplayObject;

                    // set the vehicles as selected
                    cdo.Selected  = SelectionType.SingleSelected;
                    this.selected = cdo;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = cdo;

                    // check if we can move the vehicle
                    if (!((SimVehicle)cdo).VehicleState.IsBound)
                    {
                        // set dragging
                        isDragging     = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = cdo.Position;
                    }

                    // redraw
                    this.Invalidate();
                }
                // check if hit obstacle
                else if (htr.Hit && htr.DisplayObject is SimObstacle)
                {
                    // set selected
                    this.selected          = htr.DisplayObject;
                    this.selected.Selected = SelectionType.SingleSelected;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;

                    // check if can move
                    if (((SimObstacle)htr.DisplayObject).MoveAllowed)
                    {
                        // set dragging
                        isDragging     = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = ((SimObstacle)this.selected).Position;
                    }

                    // redraw
                    this.Invalidate();
                }
                else
                {
                    controlTag     = new Point(e.X, e.Y);
                    isDragging     = true;
                    Cursor.Current = Cursors.Hand;
                }
            }

            #endregion

            #region Right

            else if (e.Button == MouseButtons.Right)
            {
                if (htr.Hit && htr.DisplayObject is CarDisplayObject)
                {
                    this.selected = htr.DisplayObject;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;
                    this.vehicleContextMenuStrip1.Show(this, e.X, e.Y);
                    ((CarDisplayObject)this.selected).Selected = SelectionType.SingleSelected;
                }
                else if (htr.Hit && htr.DisplayObject is SimObstacle)
                {
                    // set selected
                    this.selected          = htr.DisplayObject;
                    this.selected.Selected = SelectionType.SingleSelected;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;

                    // check if we can move the obstacle
                    if (((SimObstacle)htr.DisplayObject).MoveAllowed)
                    {
                        // set dragging
                        isDragging     = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = transform.GetWorldPoint(new PointF(e.X, e.Y)) - ((SimObstacle)this.selected).Position;
                    }

                    // redraw
                    this.Invalidate();
                }
            }

            #endregion

            base.OnMouseDown(e);
            this.Invalidate();
        }
Example #45
0
 public TempDisplay(IDisplayObject display, ITableScheme scheme, string idField, string nameField)
 {
     Id   = GetField(display.Id, scheme, idField);
     Name = GetField(display.Name, scheme, nameField);
 }
 private void startupPartitionToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.selected is ArbiterLanePartition)
     {
         ArbiterLanePartition alp = (ArbiterLanePartition)this.selected;
         alp.Type = PartitionType.Startup;
         alp.selected = SelectionType.NotSelected;
         this.selected = null;
         this.Invalidate();
     }
 }
 public bool ShouldDeselect(IDisplayObject newSelection)
 {
     throw new Exception("The method or operation is not implemented.");
 }
        private void insertUserWaypointToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.selected is ArbiterLanePartition)
            {
                ArbiterLanePartition alp = (ArbiterLanePartition)this.selected;
                Coordinates c = ((PartitionTools)this.CurrentEditorTool).HitPoint;

                foreach (ArbiterUserPartition aup in alp.UserPartitions)
                {
                    if (aup.IsInsideClose(c))
                    {
                        aup.InsertUserWaypoint(c);
                        alp.selected = SelectionType.NotSelected;
                        this.selected = null;
                        this.displayObjects = new List<IDisplayObject>(alp.Lane.Way.Segment.RoadNetwork.DisplayObjects.ToArray());
                        this.displayObjects.Insert(0, this.DisplayGrid);
                        this.Invalidate();
                        return;
                    }
                }

                alp.selected = SelectionType.NotSelected;
                this.selected = null;
                this.Invalidate();
            }
        }
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.selected is SimVehicle)
            {
                // vehicle
                SimVehicle isv = (SimVehicle)this.selected;

                // notfy
                SimulatorOutput.WriteLine("Removed Vehicle: " + isv.SimVehicleState.VehicleID.ToString());

                // remove
                this.displayObjects.Remove(this.selected);
                this.Simulation.simEngine.Vehicles.Remove(isv.VehicleId);
                this.Simulation.clientHandler.Remove(isv.VehicleId);
                this.Simulation.OnClientsChanged();

                if (this.tracked != null && this.tracked.VehicleId.Equals(isv.VehicleId))
                    this.tracked = null;

                // remove selecation
                this.selected = null;

                // properties
                this.Simulation.simEngine.SetPropertyGridDefault();

                // redraw
                this.Invalidate();
            }
        }
 /// <summary>
 /// Gets the width and height of the specified <paramref name="displayObject" />. The value is calculated from the 
 /// physical file. Returns an empty <see cref="System.Windows.Size" /> instance if the value cannot be computed or 
 /// is not applicable to the object (for example, for audio files and external media objects).
 /// </summary>
 /// <returns><see cref="System.Windows.Size" />.</returns>
 public Size GetSize(IDisplayObject displayObject)
 {
     if (AppSetting.Instance.AppTrustLevel == ApplicationTrustLevel.Full)
     {
         try
         {
             return GetSizeUsingWpf(displayObject);
         }
         catch (NotSupportedException)
         {
             return GetSizeUsingGdi(displayObject);
         }
     }
     else
     {
         return GetSizeUsingGdi(displayObject);
     }
 }
 /// <summary>
 /// add a display object
 /// </summary>
 /// <param name="ido"></param>
 public void AddDisplayObject(IDisplayObject ido)
 {
     this.displayObjects.Add(ido);
 }
 private static Size GetSizeUsingGdi(IDisplayObject displayObject)
 {
     try
     {
         using (var source = new System.Drawing.Bitmap(displayObject.FileNamePhysicalPath))
         {
             return new Size(source.Width, source.Height);
         }
     }
     catch (ArgumentException)
     {
         return Size.Empty;
     }
     catch (ExternalException ex)
     {
         return Size.Empty;
     }
     catch (OutOfMemoryException ex)
     {
         return Size.Empty;
     }
 }
Example #53
0
        /// <summary>
        /// Verify the properties have been set for the thumbnail image in this album, retrieving the information
        /// from the data store if necessary. This method also inflates the album if it is not already inflated 
        /// (but doesn't inflate the children objects).
        /// </summary>
        /// <param name="thumbnail">A reference to the thumbnail display object for this album. The instance
        /// is passed as a parameter rather than directly addressed as a property of our base class because we don't 
        /// want to trigger the property get {} code, which calls this method (and would thus result in an infinite
        /// loop).</param>
        /// <remarks>To be perfectly clear, let me say again that the thumbnail parameter is the same instance
        /// as album.Thumbnail. They both refer to the same memory space. This method updates the albumThumbnail 
        /// parameter, which means that album.Thumbnail is updated as well.</remarks>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="thumbnail" /> is null.</exception>
        protected override void VerifyThumbnailIsInflated(IDisplayObject thumbnail)
        {
            if (thumbnail == null)
                throw new ArgumentNullException("thumbnail");

            // Verify album is inflated (the method only inflates the album if it's not already inflated).
            Inflate(false);

            System.Diagnostics.Debug.Assert(this._thumbnailMediaObjectId >= 0, String.Format(CultureInfo.CurrentCulture, "Album.Inflate(false) should have set ThumbnailMediaObjectId >= 0. Instead, it is {0}.", this._thumbnailMediaObjectId));

            if (!this._isThumbnailInflated)
            {
                // Need to inflate thumbnail.
                if (this._thumbnailMediaObjectId > 0)
                {
                    // ID has been specified. Find media object and retrieve it's thumbnail properties.

                    #region Get reference to the media object used for the album's thumbnail

                    // If thumbnail media object is one of the album's children, use that. Otherwise, load from data store.
                    IGalleryObject thumbnailMediaObject = null;
                    if (this.AreChildrenInflated)
                    {
                        foreach (IGalleryObject mediaObject in this.GetChildGalleryObjects(GalleryObjectType.MediaObject))
                        {
                            if (this._thumbnailMediaObjectId == mediaObject.Id)
                            {
                                thumbnailMediaObject = mediaObject;
                                break;
                            }
                        }
                    }

                    if (thumbnailMediaObject == null)
                    {
                        // this._thumbnailMediaObjectId does not refer to a media object that is a direct child of this
                        // album, so just go to the data store and retrieve it.
                        try
                        {
                            thumbnailMediaObject = Factory.LoadMediaObjectInstance(this._thumbnailMediaObjectId);
                        }
                        catch (InvalidMediaObjectException)
                        {
                            // Get default thumbnail. Copy properties instead of reassigning the albumThumbnail parameter
                            // so we don't lose the reference.
                            using (IDisplayObject defaultAlbumThumb = GetDefaultAlbumThumbnail())
                            {
                                thumbnail.MediaObjectId = defaultAlbumThumb.MediaObjectId;
                                thumbnail.DisplayType = defaultAlbumThumb.DisplayType;
                                thumbnail.FileName = defaultAlbumThumb.FileName;
                                thumbnail.Width = defaultAlbumThumb.Width;
                                thumbnail.Height = defaultAlbumThumb.Height;
                                thumbnail.FileSizeKB = defaultAlbumThumb.FileSizeKB;
                                thumbnail.FileNamePhysicalPath = defaultAlbumThumb.FileNamePhysicalPath;
                            }
                        }
                    }

                    #endregion

                    if (thumbnailMediaObject != null)
                    {
                        thumbnail.MediaObjectId = this._thumbnailMediaObjectId;
                        thumbnail.DisplayType = DisplayObjectType.Thumbnail;
                        thumbnail.FileName = thumbnailMediaObject.Thumbnail.FileName;
                        thumbnail.Width = thumbnailMediaObject.Thumbnail.Width;
                        thumbnail.Height = thumbnailMediaObject.Thumbnail.Height;
                        thumbnail.FileSizeKB = thumbnailMediaObject.Thumbnail.FileSizeKB;
                        thumbnail.FileNamePhysicalPath = thumbnailMediaObject.Thumbnail.FileNamePhysicalPath;
                    }
                }
                else
                {
                    // ID = 0. Set to default values. This is a repeat of what happens in the Album() constructor,
                    // but we need it again just in case the user changes it to 0 and immediately retrieves its properties.
                    // Copy properties instead of reassigning the albumThumbnail parameter so we don't lose the reference.
                    using (IDisplayObject defaultAlbumThumb = GetDefaultAlbumThumbnail())
                    {
                        thumbnail.MediaObjectId = defaultAlbumThumb.MediaObjectId;
                        thumbnail.DisplayType = defaultAlbumThumb.DisplayType;
                        thumbnail.FileName = defaultAlbumThumb.FileName;
                        thumbnail.Width = defaultAlbumThumb.Width;
                        thumbnail.Height = defaultAlbumThumb.Height;
                        thumbnail.FileSizeKB = defaultAlbumThumb.FileSizeKB;
                        thumbnail.FileNamePhysicalPath = defaultAlbumThumb.FileNamePhysicalPath;
                    }
                }

                this._isThumbnailInflated = true;
            }
        }
        private Size GetSizeUsingWpf(IDisplayObject displayObject)
        {
            try
            {
                var photoBytes = File.ReadAllBytes(displayObject.FileNamePhysicalPath);
                using (var photoStream = new MemoryStream(photoBytes))
                {
                    var photo = ReadBitmapFrame(photoStream);
                    return new Size(photo.PixelWidth, photo.PixelHeight);
                }
            }
            catch (NotSupportedException)
            {
                return GetSizeUsingGdi(displayObject);
            }
            catch (Exception ex)
            {
                if (!ex.Data.Contains("SizeMsg"))
                {
                    ex.Data.Add("SizeMsg", String.Format("Unable to get the width and height of media object {0} ({1}). Display Type {2}", GalleryObject.Id, displayObject.FileNamePhysicalPath, displayObject.DisplayType));
                }

                EventController.RecordError(ex, AppSetting.Instance, GalleryObject.GalleryId, Factory.LoadGallerySettings());

                return Size.Empty;
            }
        }
 public HitTestResult(IDisplayObject dispObject, bool hit, float dist)
 {
     this.dispObject = dispObject;
     this.hit = hit;
     this.dist = dist;
 }
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.selected is ArbiterUserWaypoint)
            {
                ArbiterUserWaypoint auw = (ArbiterUserWaypoint)this.selected;

                if(auw.Partition is ArbiterLanePartition)
                {
                    ArbiterLanePartition alp = (ArbiterLanePartition)auw.Partition;
                    ArbiterUserPartition init = auw.Previous;
                    ArbiterUserPartition fin = auw.Next;

                    // remove the waypouints
                    alp.UserWaypoints.Remove(auw);
                    alp.Lane.Way.Segment.RoadNetwork.DisplayObjects.Remove(auw);

                    // remove partition
                    alp.UserPartitions.Remove(fin);
                    alp.Lane.Way.Segment.RoadNetwork.DisplayObjects.Remove(fin);
                    alp.Lane.Way.Segment.RoadNetwork.DisplayObjects.Remove(init);

                    // setup the initial partition
                    init.FinalGeneric = fin.FinalGeneric;
                    init.ReformPath();
                    init.PartitionId = new ArbiterUserPartitionId(alp.ConnectionId, init.InitialGeneric.GenericId, init.FinalGeneric.GenericId);
                    if (init.FinalGeneric is ArbiterUserWaypoint)
                        ((ArbiterUserWaypoint)init.FinalGeneric).Previous = init;

                    // redo the ids
                    foreach (ArbiterUserWaypoint tmp in alp.UserWaypoints)
                    {
                        if (tmp.WaypointId.Number > auw.WaypointId.Number)
                            tmp.WaypointId.Number--;
                    }

                    // refresh paths
                    alp.UserPartitions.Sort();
                    alp.ReformPath();
                    alp.Lane.ReformPath();

                    // display
                    alp.Lane.Way.Segment.RoadNetwork.DisplayObjects.Add(init);

                    // display
                    if (this.selected != null)
                        this.selected.Selected = SelectionType.NotSelected;
                    this.selected = null;
                    this.displayObjects = new List<IDisplayObject>(alp.Lane.Way.Segment.RoadNetwork.DisplayObjects.ToArray());
                    this.displayObjects.Insert(0, this.DisplayGrid);
                    this.Invalidate();
                    return;
                }
            }

            if (this.selected != null)
                this.selected.Selected = SelectionType.NotSelected;
            this.selected = null;
            this.Invalidate();
        }
 public bool ShouldDeselect(IDisplayObject newSelection)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Example #58
0
 /// <summary>
 /// Creates a display object based button.
 /// </summary>
 /// <param name="displayObject"></param>
 public Button(LayoutAnchor anchor, IDisplayObject displayObject)
     : this(displayObject)
 {
     this.anchor = anchor;
 }