Пример #1
0
        /// <summary>
        /// Constructs a SelectTargetMouseHandler instance.
        /// </summary>
        /// <param name="scrollEventSource">The UISensitiveObject that will raise the events for scrolling.</param>
        /// <param name="mapDisplay">Reference to the target map display.</param>
        /// <param name="normalMouseEventSource">The UISensitiveObject that will raise the additional mouse events.</param>
        /// <param name="sprites">The sprites to be used when displaying object placement box.</param>
        public SelectTargetMouseHandler(UISensitiveObject scrollEventSource, IMapDisplay mapDisplay,
                                        UISensitiveObject normalMouseEventSource, SpriteGroup sprites)
            : base(scrollEventSource, mapDisplay)
        {
            if (normalMouseEventSource == null)
            {
                throw new ArgumentNullException("normalMouseEventSource");
            }
            if (sprites == null)
            {
                throw new ArgumentNullException("sprites");
            }
            if (this.CommandView.TargetSelectionMode == TargetSelectionModeEnum.NoTargetSelection)
            {
                throw new InvalidOperationException("Target selection is not possible currently!");
            }

            this.targetSelectionMode    = this.CommandView.TargetSelectionMode;
            this.multiplayerService     = ComponentManager.GetInterface <IMultiplayerService>();
            this.normalMouseEventSource = normalMouseEventSource;
            this.objectPlacementInfo    = this.targetSelectionMode == TargetSelectionModeEnum.BuildingLocationSelection
                ? new ObjectPlacementInfo(
                ComponentManager.GetInterface <IViewService>().CreateView <INormalModeMapObjectPlacementView>(),
                sprites)
                : null;

            this.normalMouseEventSource.MouseSensor.ButtonDown += this.OnMouseDown;
            this.multiplayerService.GameUpdated += this.OnGameUpdate;
        }
        /// <summary>Set ScrollBar increments and bounds from map dimensions.</summary>
        public virtual void SetScrollLimits(IMapDisplay model)
        {
            if (model == null || !AutoScroll)
            {
                return;
            }
            var smallChange = Size.Ceiling(model.GridSize.Scale(MapScale));

            HorizontalScroll.SmallChange = smallChange.Width;
            VerticalScroll.SmallChange   = smallChange.Height;

            var largeChange = Size.Round(ClientSize.Scale(0.75F));

            HorizontalScroll.LargeChange = Math.Max(largeChange.Width, smallChange.Width);
            VerticalScroll.LargeChange   = Math.Max(largeChange.Height, smallChange.Height);

            var size = DataContext.Hexgrid.GetSize(MapSizePixels, MapScale)
                       + Margin.Size;

            if (AutoScrollMinSize != size)
            {
                AutoScrollMinSize        = size;
                HorizontalScroll.Maximum = Math.Min(1, Math.Max(1, Margin.Horizontal
                                                                + size.Width - ClientSize.Width));
                VerticalScroll.Maximum = Math.Min(1, Math.Max(1, Margin.Vertical
                                                              + size.Height - ClientSize.Height));
                Invalidate();
            }
        }
Пример #3
0
        /// <summary>
        /// Constructs a NormalMouseHandler instance.
        /// </summary>
        /// <param name="scrollEventSource">The UISensitiveObject that will raise the events for scrolling.</param>
        /// <param name="mapDisplay">Reference to the target map display.</param>
        /// <param name="normalMouseEventSource">The UISensitiveObject that will raise the additional mouse events.</param>
        public NormalMouseHandler(UISensitiveObject scrollEventSource, IMapDisplay mapDisplay,
                                  UISensitiveObject normalMouseEventSource)
            : base(scrollEventSource, mapDisplay)
        {
            if (normalMouseEventSource == null)
            {
                throw new ArgumentNullException("normalMouseEventSource");
            }
            if (this.CommandView.TargetSelectionMode != TargetSelectionModeEnum.NoTargetSelection)
            {
                throw new InvalidOperationException("Normal mouse input is not possible currently!");
            }

            this.multiplayerService     = ComponentManager.GetInterface <IMultiplayerService>();
            this.normalMouseEventSource = normalMouseEventSource;

            this.currentMouseStatus        = MouseStatus.None;
            this.selectionBoxStartPosition = RCIntVector.Undefined;
            this.selectionBoxCurrPosition  = RCIntVector.Undefined;
            this.selectionBox = RCIntRectangle.Undefined;

            this.normalMouseEventSource.MouseSensor.StateReset  += this.OnStateReset;
            this.normalMouseEventSource.MouseSensor.ButtonDown  += this.OnMouseDown;
            this.normalMouseEventSource.MouseSensor.Move        += this.OnMouseMove;
            this.normalMouseEventSource.MouseSensor.ButtonUp    += this.OnMouseUp;
            this.normalMouseEventSource.MouseSensor.DoubleClick += this.OnMouseDoubleClick;

            this.multiplayerService.GameUpdated += this.OnGameUpdate;
        }
Пример #4
0
        /// <summary>
        /// Constructs a MouseHandlerBase instance.
        /// </summary>
        /// <param name="scrollEventSource">The UISensitiveObject that will raise the events for scrolling.</param>
        /// <param name="mapDisplay">Reference to the target map display.</param>
        public MouseHandlerBase(UISensitiveObject scrollEventSource, IMapDisplay mapDisplay)
        {
            if (scrollEventSource == null)
            {
                throw new ArgumentNullException("scrollEventSource");
            }
            if (mapDisplay == null)
            {
                throw new ArgumentNullException("mapDisplay");
            }

            this.selectionService = ComponentManager.GetInterface <ISelectionService>();
            this.commandService   = ComponentManager.GetInterface <ICommandService>();
            this.scrollService    = ComponentManager.GetInterface <IScrollService>();
            this.commandView      = ComponentManager.GetInterface <IViewService>().CreateView <ICommandView>();

            this.currentScrollDir    = ScrollDirectionEnum.NoScroll;
            this.timeSinceLastScroll = 0;
            this.isScrollEnabled     = true;
            this.mapDisplay          = mapDisplay;
            this.scrollEventSource   = scrollEventSource;
            this.scrollEventSource.MouseSensor.Move += this.OnMouseMove;
            UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate += this.OnFrameUpdate;
            this.mapDisplay.AttachMouseHandler(this);
        }
Пример #5
0
 public void SetMap(IMapDisplay mapDisplay)
 {
     if (this.mapDisplay != null)
     {
         this.mapDisplay.Changed -= MapChanged;
     }
     this.mapDisplay = mapDisplay;
     if (mapDisplay != null)
     {
         mapDisplay.Changed += MapChanged;
     }
     viewcache = new ViewCache(mapDisplay);
     ViewportChanged();
 }
Пример #6
0
 /// <summary>Rectangular extent in pixels of the defined mapboard.</summary>
 /// <param name="this">The current <see cref="IMapDisplay{THex}"/>.</param>
 public static HexSize MapSizePixels <THex>(this IMapDisplay <THex> @this)
     where THex : IHex
 => @this.MapSizeHexes * @this.GridSizePixels;
        ///// <summary>Return new AutoScrollPosition for applied muse-wheel scroll.</summary>
        //static Point WheelPanel(ScrollProperties scroll, int delta, ref int remainder,
        //  Func<int,Point> newAutoScroll)
        //{
        //  if (Math.Sign(delta) != Math.Sign(remainder)) remainder = 0;
        //  var steps = (delta+remainder)
        //            / (SystemInformation.MouseWheelScrollDelta / SystemInformation.MouseWheelScrollLines);
        //  remainder = (delta+remainder)
        //            % (SystemInformation.MouseWheelScrollDelta / SystemInformation.MouseWheelScrollLines);
        //  return newAutoScroll(scroll.SmallChange * steps);
        //}
        ///// <summary>TODO</summary>
        //static ScrollEventArgs GetScrollEventArgs(bool isHorizontal, Point oldScroll, Point newScroll) {
        //  return new ScrollEventArgs(
        //    ScrollEventType.ThumbTrack,
        //    isHorizontal ? -oldScroll.X : -oldScroll.Y,
        //    isHorizontal ? -newScroll.X : -newScroll.Y,
        //    isHorizontal ? ScrollOrientation.HorizontalScroll : ScrollOrientation.VerticalScroll
        //  );
        //}

        /// <summary>TODO</summary>
        public void SetModel(IMapDisplay model)
        {
            Model = model;
        }
 /// <summary>TODO</summary>
 public void SetModel(IMapDisplay model)
 {
     SetScrollLimits(DataContext.Model);
     DataContext.SetModel(model);
     SetMapDirty();
 }
Пример #9
0
 /// <summary>
 /// Constructs a MapEditorMouseHandler instance.
 /// </summary>
 /// <param name="scrollEventSource">The UISensitiveObject that will raise the events for scrolling.</param>
 /// <param name="mapDisplay">Reference to the target map display.</param>
 public MapEditorMouseHandler(UISensitiveObject scrollEventSource, IMapDisplay mapDisplay)
     : base(scrollEventSource, mapDisplay)
 {
     this.mapEditorService    = ComponentManager.GetInterface <IMapEditorService>();
     this.objectPlacementInfo = null;
 }
Пример #10
0
        Matrix matTransform; // The transform that maps from map view to the bitmap coordinates.

        #endregion Fields

        #region Constructors

        public ViewCache(IMapDisplay mapDisplay)
        {
            this.mapDisplay = mapDisplay;
            mapDisplay.Changed += MapChanged;
        }
Пример #11
0
 public ViewCache(IMapDisplay mapDisplay)
 {
     this.mapDisplay     = mapDisplay;
     mapDisplay.Changed += MapChanged;
 }