Example #1
0
        /// <summary>
        /// Figure out real position of texture, after taking alignment into account
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static Vector2 GetRealPosition(IMapItem item)
        {
            Vector2 realPos = item.Position.GetPosition();

            // Adjust horizontal.
            if (item.PositionAlignment.HasFlag(MapItemAlignment.Right))
            {
                // Shift position one texture size to the left,
                // so that the position is located at the right
                // side of the texture.
                realPos.X -= item.Size.X;
            }
            else if (!item.PositionAlignment.HasFlag(MapItemAlignment.Left))
            {
                // Horizontal position should be centered.
                realPos.X -= item.Size.X / 2;
            }

            // Adjust vertical
            if (item.PositionAlignment.HasFlag(MapItemAlignment.Bottom))
            {
                // Shift position one texture size upwards,
                // so that the position is located at the
                // bottom of the texture.
                realPos.Y -= item.Size.Y;
            }
            else if (!item.PositionAlignment.HasFlag(MapItemAlignment.Top))
            {
                // Vertical position should be centered.
                realPos.Y -= item.Size.Y / 2;
            }
            return(new Vector2((int)Math.Round(realPos.X), (int)Math.Round(realPos.Y)));
        }
Example #2
0
 public virtual void OnPropertyChanged(IMapItem mi, string strProperty)
 {
     if (PropertyChanged != null)
     {
         PropertyChanged(mi, strProperty);
     }
 }
Example #3
0
        private void PictureBox_MouseDown(Object sender, MouseEventArgs e)
        {
            Control ctlSelected = (Control)sender;

            if (!Globals.IsKit())
            {
                if (e.Button == MouseButtons.Right)
                {
                    contextMenuTiles.Show(ctlSelected, new Point(e.X, e.Y));
                    return;
                }
            }

            Tile tile = (Tile)((PictureBox)sender).Tag;

            Globals.PropertyGrid.SelectedObject = tile.GetTemplate(m_tmpdActive);

            // Start drag drop

            LevelData ldat = new LevelData();
            IMapItem  mi   = (IMapItem)ctlSelected.Tag;

            ldat.ami = new IMapItem[] { mi };
            Size sizTile = m_tmpdActive.TileSize;

            ldat.txMouse     = e.X / (double)sizTile.Width;
            ldat.tyMouse     = e.Y / (double)sizTile.Height;
            ldat.Grid.Width  = mi.Grid.Width;
            ldat.Grid.Height = mi.Grid.Height;
            DoDragDrop(ldat, DragDropEffects.Copy);
        }
Example #4
0
 //-----------------------------------------------------------------------------
 public void ExecuteAction(CActionSur2iLink actionSurClick, IMapItem itemClicked)
 {
     if (ExecuteurAction != null)
     {
         ExecuteurAction(actionSurClick, itemClicked);
     }
 }
Example #5
0
        //---------------------------------------------------------------------------
        public bool GenereItem(
            object obj,
            double fLat,
            double fLong, CMapLayer layer)
        {
            CResultAErreur result             = CResultAErreur.True;
            CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(this.m_mapItemGenerator);

            if (FormuleCondition != null && !(FormuleCondition is C2iExpressionVrai))
            {
                result = FormuleCondition.Eval(ctx);
                if (!result || result.Data == null)
                {
                    return(false);
                }
                bool?bResult = CUtilBool.BoolFromString(result.Data.ToString());
                if (bResult == null || !bResult.Value)
                {
                    return(false);
                }
            }
            string strLibelle = "";

            if (FormuleToolTip != null)
            {
                result = FormuleToolTip.Eval(ctx);
                if (result && result.Data != null)
                {
                    strLibelle = result.Data.ToString();
                }
            }
            IMapItem item = null;

            if (MarkerType != EMapMarkerType.none)
            {
                item = new CMapItemSimple(layer, fLat, fLong, MarkerType);
            }
            else if (Image != null)
            {
                if (layer.Database.GetImage(m_strImageId) == null)
                {
                    layer.Database.AddImage(m_strImageId, Image);
                }
                item = new CMapItemImage(layer, fLat, fLong, m_strImageId);
            }
            else
            {
                item = new CMapItemSimple(layer, fLat, fLong, EMapMarkerType.green);
            }
            item.Tag              = obj;
            item.ToolTip          = strLibelle;
            item.PermanentToolTip = PermanentToolTip;

            if (ItemGenerator.ActionSurClick != null)
            {
                item.MouseClicked += new MapItemClickEventHandler(OnMouseClick);
            }

            return(true);
        }
Example #6
0
 public void OnMouseClick(IMapItem item)
 {
     if (LineGenerator != null && item != null)
     {
         LineGenerator.OnMapItemClick(item);
     }
 }
Example #7
0
 //--------------------------------------------------------------
 public void OnMapItemClick(IMapItem itemClicked)
 {
     if (ActionSurClick != null && Generator != null)
     {
         Generator.ExecuteAction(ActionSurClick, itemClicked);
     }
 }
Example #8
0
        private void AddToMap(IMapItem item)
        {
            // Draw the item image over the map.
            var pb = new PictureBox();

            pb.SizeMode  = PictureBoxSizeMode.AutoSize;
            pb.Parent    = SeaChart;
            pb.BackColor = Color.Transparent;
            pb.Image     = item.GetImage();
            pb.BringToFront();
            pb.MouseMove     += IMapItem_MouseMove;
            pb.ParentChanged += IMapItem_ParentChanged;
            pb.Location       = item.GetLocation();

            if (item.GetType() == typeof(Stamp))
            {
                pb.Tag        = "Stamp";
                pb.MouseUp   += Stamp_MouseUp;
                pb.MouseDown += Stamp_MouseDown;
            }
            else if (item.GetType() == typeof(Waypoint))
            {
                pb.Tag         = "Waypoint";
                pb.MouseUp    += Waypoint_MouseUp;
                pb.MouseEnter += Waypoint_MouseEnter;
                pb.MouseLeave += Waypoint_MouseLeave;
                pb.MouseDown  += Waypoint_MouseDown;
            }
        }
Example #9
0
 //-----------------------------------------------
 public void ExecuteAction(CActionSur2iLink action, IMapItem item)
 {
     if (action != null && item != null)
     {
         CExecuteurActionSur2iLink.ExecuteAction(this, action, item.Tag);
     }
 }
Example #10
0
        public void CalculateWay(IMapItem start, IMapItem finish)
        {
            _start  = start;
            _finish = finish;
            _queue.Clear();
            ClearMapItems();

            _start.Cost = 0;
            IMapItem current = _start;

            while (current != _finish && !ReferenceEquals(current, null))
            {
                IMapItem[] neighbors = Map.GetNeighbors(current);

                foreach (var neighbor in neighbors)
                {
                    if (!neighbor.IsPassable)
                    {
                        continue;
                    }

                    int cost = Heuristic(current, neighbor);
                    if (cost < neighbor.Cost)
                    {
                        neighbor.Cost = cost;
                        neighbor.Last = current;

                        _queue.Push(neighbor, neighbor.Cost);
                    }
                }
                current = _queue.Pop();
            }
        }
Example #11
0
 //----------------------------------------------
 public void AddItem(IMapItem item)
 {
     if (!m_listeItems.Contains(item))
     {
         m_listeItems.Add(item);
     }
 }
Example #12
0
 //------------------------------------
 public IWin32MapItem GetGMapItemFromIMapItem(IMapItem item)
 {
     //Trouve l'object qui représente cet item
     foreach (GMapOverlay overlay in m_dicLayers.Values)
     {
         foreach (IWin32MapItem w32Item in overlay.Markers.OfType <IWin32MapItem>())
         {
             if (w32Item.Item == item)
             {
                 return(w32Item);
             }
         }
         foreach (IWin32MapItem w32Item in overlay.Routes.OfType <IWin32MapItem>())
         {
             if (w32Item.Item == item)
             {
                 return(w32Item);
             }
         }
         foreach (IWin32MapItem w32Item in overlay.Polygons.OfType <IWin32MapItem>())
         {
             if (w32Item.Item == item)
             {
                 return(w32Item);
             }
         }
     }
     return(null);
 }
Example #13
0
        void PlaceMapItems(Point ptMouse, LevelData ldat)
        {
            // Figure out where we want to place these map items

            PointF ptOrigin;

            PointF[] aptPlace = GetPlacementPoints2(ptMouse, ldat, out ptOrigin);

            // Set their positions

            IMapItem[] ami = new IMapItem[ldat.ami.Length];
            for (int imi = 0; imi < ldat.ami.Length; imi++)
            {
                ami[imi]    = (IMapItem)ldat.ami[imi].Clone();
                ami[imi].tx = aptPlace[imi].X;
                ami[imi].ty = aptPlace[imi].Y;
            }

            // Add them to the level, make them selected

            m_lvld.AddMapItems(ami);
            ArrayList alsmiSelected = new ArrayList();

            alsmiSelected.AddRange(ami);
            m_lvld.Selection = alsmiSelected;
            Globals.PropertyGrid.SelectedObjects = (Object[])alsmiSelected.ToArray(typeof(Object));
        }
Example #14
0
 public void AddMap(IMapItem mapItem)
 {
     if (mapItem == null)
     {
         return;
     }
     Maps.Add(mapItem);
 }
Example #15
0
 public void UpdateItemReferences(Dictionary <ulong, MapItem> allItems)
 {
     if (PrefabLink is UnresolvedItem &&
         allItems.TryGetValue(PrefabLink.Uid, out var resolvedPrefab))
     {
         PrefabLink = resolvedPrefab;
     }
 }
Example #16
0
        //------------------------------------
        public void DeleteItem(IMapItem item)
        {
            IWin32MapItem w32Item = GetGMapItemFromIMapItem(item);

            if (w32Item != null)
            {
                w32Item.DeleteItem();
            }
        }
 public CMoveablePointForGPSPoint(CMapDatabase database, CGPSPoint pt)
     : base(database, new SLatLong(pt.Latitude, pt.Longitude))
 {
     m_gpsPoint = pt;
     foreach (IMapItem item in pt.FindMapItems(database))
     {
         m_mapItem = item;
     }
 }
Example #18
0
        PictureBox CreatePictureBox(TemplateDoc tmpd, Size sizTile, IMapItem mi)
        {
            PictureBox picb = new PictureBox();

            picb.Image      = Misc.TraceEdges(mi.GetBitmap(sizTile, tmpd), 1, Color.Azure);
            picb.SizeMode   = PictureBoxSizeMode.AutoSize;
            picb.Tag        = (Object)mi;
            picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown);
            return(picb);
        }
Example #19
0
        PictureBox CreatePictureBox(IMapItem mi)
        {
            PictureBox picb = new PictureBox();

            picb.Image      = mi.GetBitmap(new Size(16, 16), null);
            picb.SizeMode   = PictureBoxSizeMode.AutoSize;
            picb.Tag        = (Object)mi;
            picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown);
            return(picb);
        }
Example #20
0
        //------------------------------------
        public void AddMapItem(IMapItem item)
        {
            IWin32MapItem win32Item = CAllocateurWin32MapItem.GetNewMapItem(item);

            if (win32Item != null)
            {
                m_listeWin32Items.Add(win32Item);
                win32Item.AddToLayer(GetLayer(item.Layer.LayerName, true));
            }
        }
Example #21
0
        private void LevelView_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Point       ptMouse = ViewToWorld(new Point(e.X - AutoScrollPosition.X, e.Y - AutoScrollPosition.Y));
            TemplateDoc tmpd    = GetTemplateDoc();
            Size        sizTile = GetTileSize();

            // Update status bar

            int tx = ptMouse.X / sizTile.Width;
            int ty = ptMouse.Y / sizTile.Height;

            Globals.StatusBar.Text = String.Format("Coords: {0}, {1}", tx, ty);

            // If we're dragging a selection, handle it here

            if (m_fDragSelect)
            {
                DragSelectExtend(e);
                return;
            }

            // Send input to MapItem, see if it wants it

            IMapItem mi = m_miCapturedMouse;

            if (mi == null)
            {
                mi = m_lvld.HitTest(ptMouse.X, ptMouse.Y, sizTile, tmpd, m_lyrf);
            }
            if (mi != null)
            {
                if (mi.OnMouseMove(e, ptMouse, sizTile, tmpd))
                {
                    return;
                }
            }

            // We're not extending a selection. Perhaps we're initiating a drag drop operation
            // Check initiation conditions

            if (m_lvld.Selection.Count == 0)
            {
                return;
            }
            if (MouseButtons != MouseButtons.Left)
            {
                return;
            }
            if (m_rcDragStart.Contains(ptMouse.X, ptMouse.Y))
            {
                return;
            }

            PerformDragDrop(e, m_ptMouseDown);
        }
Example #22
0
    public void SetData(IMapItem item)
    {
        this.item = item;
        item.Load();
        Vector2 index = item.Index;
        Vector2 size  = item.Size;

        (transform as RectTransform).sizeDelta        = size;
        (transform as RectTransform).anchoredPosition = new Vector2(index.x * size.x + size.x / 2, -index.y * size.y - size.y / 2);
        text.text = item.Index.x.ToString() + "_" + item.Index.y.ToString();
    }
Example #23
0
        //------------------------------------------------------------------------
        private bool SelectItemInTree(IMapItem item)
        {
            TreeNode node = FindNode(item.Tag, m_arbreCartographie.Nodes);

            if (node != null)
            {
                m_arbreCartographie.SelectedNode = node;
                return(true);
            }
            return(false);
        }
        public CMoveablePointForLineStart(CMapDatabase database, CGPSLine line)
            : base(database, line.DetailLigne.PointDepart)
        {
            m_line = line;
            IEnumerable <IMapItem> items = line.FindMapItems(database);

            if (items.Count() > 0)
            {
                m_mapItem = items.ElementAt(0);
            }
        }
Example #25
0
 private void AddDisplayList(Vector2Int index)
 {
     if (!displayItems.ContainsKey(index))
     {
         IMapItem item = factory.GetMapItem(index, itemSize);
         addDisplayItems.Add(index, item);
         displayItems.Add(index, item);
     }
     else
     {
         removeDisplayItems.Remove(index);
     }
 }
Example #26
0
        public IMapItem[] ToMapItem(DrawMode mode, int x, int y)
        {
            var items = new IMapItem[this.mapItems.Count];

            for (int i = 0; i < items.Length; i++)
            {
                var item = this.mapItems[i].Clone() as MapText;
                item.Position      = new PositionDefinition(item.Position.X + x, item.Position.Y + y);
                item.Position.Type = mode;
                items[i]           = item;
            }
            return(items.ToArray());
        }
Example #27
0
 //------------------------------------------------------------------------
 private void m_menuDeleteItem_Click(object sender, EventArgs e)
 {
     if (m_currentSelectedMapItem != null && m_currentSelectedMapItem.Tag is IElementDeGPSCarte)
     {
         if (MessageBox.Show(I.T("Delete this item ?|20055"), "", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             ((IElementDeGPSCarte)m_currentSelectedMapItem.Tag).DeleteThisMapItem();
             m_currentSelectedMapItem = null;
             DisplayItemProperties(null);
             FillArbre();
             UpdateMapDatabase();
         }
     }
 }
Example #28
0
        //------------------------------------------------------------------------
        private void m_wndMap_MapItemClicked(CVEarthCtrl ctrl, MapItemClickEventArgs args)
        {
            IMapItem item = args.Item;

            if (item != null)
            {
                SelectItemInTree(item);
            }
            m_currentSelectedMapItem = item;
            if (args.MouseArgs.Button == System.Windows.Forms.MouseButtons.Right)
            {
                m_menuItem.Show(this, new Point(args.MouseArgs.X, args.MouseArgs.Y));
            }
        }
Example #29
0
        public void SetLayerFlags(LayerFlags lyrf)
        {
            // If already set to this, return

            if (lyrf == m_lyrf)
            {
                return;
            }

            // Remove the appropriate items from the current selection

            ArrayList alsmiSelected = m_lvld.Selection;

            for (int imi = 0; imi < alsmiSelected.Count;)
            {
                IMapItem mi = (IMapItem)alsmiSelected[imi];
                if (mi is Tile)
                {
                    if ((lyrf & LayerFlags.Templates) == 0)
                    {
                        alsmiSelected.RemoveAt(imi);
                        continue;
                    }
                }
                else if (mi is Area)
                {
                    if ((lyrf & LayerFlags.Areas) == 0)
                    {
                        alsmiSelected.RemoveAt(imi);
                        continue;
                    }
                }
                else
                {
                    if ((lyrf & LayerFlags.Gobs) == 0)
                    {
                        alsmiSelected.RemoveAt(imi);
                        continue;
                    }
                }
                imi++;
            }
            m_lvld.Selection = alsmiSelected;

            // Set new flags and redraw

            m_lyrf = lyrf;
            Redraw();
        }
Example #30
0
     //---------------------------------------------------------
     public IEnumerable <IMapItem> DeleteSegment(CMapDatabase database, CGPSLineSegment segment)
     {
         if (segment != null && m_listeSegments.Count() > 1)
         {
             IMapItem item = database.FindItemFromTag(segment);
             m_listeSegments.Remove(segment);
             if (item != null)
             {
                 return new IMapItem[] { item }
             }
             ;
         }
         return(new IMapItem[0]);
     }
 }
Example #31
0
 public void RemoveMapItems(IMapItem[] ami)
 {
     for (int n = 0; n < ami.Length; n++)
         m_alsmi.Remove(ami[n]);
     RemoveEventHandlers(ami);
     if (ItemsRemoved != null)
         ItemsRemoved(ami);
     m_fUpdateDirty = true;
     SetModified(true);
 }
Example #32
0
        public void Draw(Bitmap bm, IMapItem miExclude, Size sizTile, TemplateDoc tmpd, LayerFlags lyrf)
        {
            ArrayList alsmiSelected = m_alsmiSelected;

            // Draw tile map
            DrawTileMap(bm, alsmiSelected, sizTile, tmpd, lyrf);

            // Draw other layers
            using (Graphics g = Graphics.FromImage(bm)) {
                for (LayerType layer = LayerType.Galaxite; layer < LayerType.End; layer++) {
                    if (layer == LayerType.Area) {
                        if ((lyrf & LayerFlags.Areas) == 0)
                            continue;
                    } else {
                        if ((lyrf & LayerFlags.Gobs) == 0)
                            continue;
                    }
                    foreach (IMapItem mi in m_alsmi) {
                        if (mi != miExclude) {
                            int x = (int)(mi.tx * sizTile.Width);
                            int y = (int)(mi.ty * sizTile.Height);
                            mi.Draw(g, x, y, sizTile, tmpd, layer, alsmiSelected != null ? alsmiSelected.Contains(mi) : false);
                        }
                    }
                }

                // Draw bounds
                Pen pen = new Pen(new SolidBrush(Color.FromArgb(0, 255, 0)));
                pen.Width = 2;
                g.DrawRectangle(pen, Bounds.X * sizTile.Width - pen.Width + 1, Bounds.Y * sizTile.Height - pen.Width + 1, Bounds.Width * sizTile.Width + pen.Width, Bounds.Height * sizTile.Height + pen.Width);
            }
        }
Example #33
0
 public void AddMapItems(IMapItem[] ami)
 {
     m_alsmi.AddRange(ami);
     AddEventHandlers(ami);
     m_fUpdateDirty = true;
     SetModified(true);
 }
Example #34
0
 void RemoveEventHandlers(IMapItem[] ami)
 {
     foreach (IMapItem mi in ami)
         mi.PropertyChanged -= new PropertyChangedHandler(IMapItem_PropertyChanged);
 }
Example #35
0
 PictureBox CreatePictureBox(IMapItem mi)
 {
     PictureBox picb = new PictureBox();
     picb.Image = mi.GetBitmap(new Size(16, 16), null);
     picb.SizeMode = PictureBoxSizeMode.AutoSize;
     picb.Tag = (Object)mi;
     picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown);
     return picb;
 }
Example #36
0
        void PlaceMapItems(Point ptMouse, LevelData ldat)
        {
            // Figure out where we want to place these map items

            PointF ptOrigin;
            PointF[] aptPlace = GetPlacementPoints2(ptMouse, ldat, out ptOrigin);

            // Set their positions

            IMapItem[] ami = new IMapItem[ldat.ami.Length];
            for (int imi = 0; imi < ldat.ami.Length; imi++) {
                ami[imi] = (IMapItem)ldat.ami[imi].Clone();
                ami[imi].tx = aptPlace[imi].X;
                ami[imi].ty = aptPlace[imi].Y;
            }

            // Add them to the level, make them selected

            m_lvld.AddMapItems(ami);
            ArrayList alsmiSelected = new ArrayList();
            alsmiSelected.AddRange(ami);
            m_lvld.Selection = alsmiSelected;
            Globals.PropertyGrid.SelectedObjects = (Object[])alsmiSelected.ToArray(typeof(Object));
        }
Example #37
0
        private void LevelView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            m_fJustSelected = false;

            m_ptMouseDown = ViewToWorld(new Point(e.X - AutoScrollPosition.X, e.Y - AutoScrollPosition.Y));

            // Select / clear items
            IMapItem mi = m_lvld.HitTest(m_ptMouseDown.X, m_ptMouseDown.Y, GetTileSize(), GetTemplateDoc(), m_lyrf);
            if (e.Button == MouseButtons.Left) {
                if (mi == null) {
                    // Clear selection
                    m_lvld.Selection = new ArrayList();
                    Globals.PropertyGrid.SelectedObject = null;
                    m_ptDragSelectAnchor.X = m_ptMouseDown.X;
                    m_ptDragSelectAnchor.Y = m_ptMouseDown.Y;
                    m_rcDragSelect = new Rectangle(m_ptDragSelectAnchor, new Size(0, 0));
                    m_fDragSelect = true;
                } else {
                    m_rcDragStart.X = m_ptMouseDown.X - 5;
                    m_rcDragStart.Y = m_ptMouseDown.Y - 5;
                    m_rcDragStart.Width = 10;
                    m_rcDragStart.Height = 10;

                    // Add to selection. Extend if control is down
                    ArrayList alsmiSelected = m_lvld.Selection;
                    if (!alsmiSelected.Contains(mi)) {
                        if ((Control.ModifierKeys & Keys.Control) != Keys.Control)
                            alsmiSelected.Clear();
                        alsmiSelected.Add(mi);
                        Globals.PropertyGrid.SelectedObjects = (IMapItem[])alsmiSelected.ToArray(typeof(IMapItem));
                        m_fJustSelected = true;
                        m_lvld.Selection = alsmiSelected;
                    }

                    if (mi.OnMouseDown(e, m_ptMouseDown, GetTileSize(), GetTemplateDoc()))
                        m_miCapturedMouse = mi;
                }
                Redraw();
            } else if (e.Button == MouseButtons.Right) {
                if (mi != null) {
                    // If this is not already selected, then clear selection and add this
                    if (!m_lvld.Selection.Contains(mi)) {
                        ArrayList als = new ArrayList();
                        als.Add(mi);
                        m_lvld.Selection = als;
                        Globals.PropertyGrid.SelectedObject = mi;
                        Redraw();
                    }

                    if (mi.OnMouseDown(e, m_ptMouseDown, GetTileSize(), GetTemplateDoc())) {
                        m_miCapturedMouse = mi;
                        return;
                    }

                    m_miContextMenu = mi;
                    m_contextMenu.Show(this, new Point(e.X, e.Y));
                }
            }
        }
Example #38
0
        private void LevelView_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Point ptMouse = ViewToWorld(new Point(e.X - AutoScrollPosition.X, e.Y - AutoScrollPosition.Y));

            // If a MapItem has captured the mouse, give it a crack at the event

            IMapItem miT = m_miCapturedMouse;
            m_miCapturedMouse = null;
            if (miT != null) {
                if (miT.OnMouseUp(e, ptMouse, GetTileSize(), GetTemplateDoc()))
                    return;
            }

            if (e.Button != MouseButtons.Left)
                return;
            if (m_fDragSelect) {
                m_fDragSelect = false;
                Graphics gWin = CreateGraphics();
                Rectangle rcSrcWorld = new Rectangle(m_rcDragSelect.Left, m_rcDragSelect.Top, m_rcDragSelect.Width, m_rcDragSelect.Height);
                rcSrcWorld.Inflate(1, 1);
                Rectangle rcDstView = new Rectangle(WorldToView(rcSrcWorld.Location), WorldToViewSize(rcSrcWorld.Size));
                rcDstView.Offset(AutoScrollPosition);
                gWin.InterpolationMode = InterpolationMode.NearestNeighbor;
                gWin.PixelOffsetMode = PixelOffsetMode.Half;
                gWin.DrawImage(m_bm, rcDstView, rcSrcWorld, GraphicsUnit.Pixel);
                gWin.Dispose();
            }

            // Clear selected placement?
            if (m_fJustSelected) {
                m_fJustSelected = false;
                return;
            }
            IMapItem mi = m_lvld.HitTest(ptMouse.X, ptMouse.Y, GetTileSize(), GetTemplateDoc(), m_lyrf);
            if (mi == null)
                return;
            if ((Control.ModifierKeys & Keys.Control) != Keys.Control)
                return;
            ArrayList alsmiSelected = m_lvld.Selection;
            if (!alsmiSelected.Contains(mi))
                return;
            alsmiSelected.Remove(mi);
            m_lvld.Selection = alsmiSelected;
            Globals.PropertyGrid.SelectedObject = null;
            Redraw();
        }
Example #39
0
        private void AddToMap(IMapItem item)
        {
            // Draw the item image over the map.
            var pb = new PictureBox();

            pb.SizeMode = PictureBoxSizeMode.AutoSize;
            pb.Parent = SeaChart;
            pb.BackColor = Color.Transparent;
            pb.Image = item.GetImage();
            pb.BringToFront();
            pb.MouseMove += IMapItem_MouseMove;
            pb.ParentChanged += IMapItem_ParentChanged;
            pb.Location = item.GetLocation();

            if (item.GetType() == typeof(Stamp))
            {
                pb.Tag = "Stamp";
                pb.MouseUp += Stamp_MouseUp;
                pb.MouseDown += Stamp_MouseDown;
            }
            else if (item.GetType() == typeof(Waypoint))
            {
                pb.Tag = "Waypoint";
                pb.MouseUp += Waypoint_MouseUp;
                pb.MouseEnter += Waypoint_MouseEnter;
                pb.MouseLeave += Waypoint_MouseLeave;
                pb.MouseDown += Waypoint_MouseDown;
            }
        }
 PictureBox CreatePictureBox(TemplateDoc tmpd, Size sizTile, IMapItem mi)
 {
     PictureBox picb = new PictureBox();
     picb.Image = Misc.TraceEdges(mi.GetBitmap(sizTile, tmpd), 1, Color.Azure);
     picb.SizeMode = PictureBoxSizeMode.AutoSize;
     picb.Tag = (Object)mi;
     picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown);
     return picb;
 }
Example #41
0
 private Rectangle GetBoundingRect(IMapItem[] ami)
 {
     Rectangle rc = new Rectangle();
     TemplateDoc tmpd = GetTemplateDoc();
     Size sizTile = GetTileSize();
     foreach (IMapItem mi in ami) {
         int x = (int)(mi.tx * sizTile.Width);
         int y = (int)(mi.ty * sizTile.Height);
         rc = UnionRect(rc, mi.GetBoundingRectAt(x, y, sizTile, tmpd));
     }
     return rc;
 }
Example #42
0
        LevelData PrepareLevelData(int x, int y, Size sizTile, IMapItem[] ami)
        {
            // Figure out relative spacing

            double txMin = double.MaxValue;
            double tyMin = double.MaxValue;
            foreach (IMapItem mi in ami) {
                if (mi.tx < txMin)
                    txMin = mi.tx;
                if (mi.ty < tyMin)
                    tyMin = mi.ty;
            }

            LevelData ldat = new LevelData();
            ldat.Grid.Width = 0.0000001f;
            ldat.Grid.Height = 0.0000001f;

            for (int imi = 0; imi < ami.Length; imi++) {
                IMapItem mi = (IMapItem)ami[imi];

                // Keep track of the maximum gridding required by the various items
                // NOTE: all the grids must be evenly divisible into the largest grid
                // or final placement of the items will have the indivisible ones
                // realigning themselves.

                ldat.Grid.Width = Math.Max(ldat.Grid.Width, mi.Grid.Width);
                ldat.Grid.Height = Math.Max(ldat.Grid.Height, mi.Grid.Height);
            }

            // Offset tx/yMin so the clones will be grid-aligned

            txMin -= Math.IEEERemainder(txMin, ldat.Grid.Width);
            tyMin -= Math.IEEERemainder(tyMin, ldat.Grid.Height);

            // Now clone the map items and readjust tile coordinates
            // for origin of 0,0 (or as close as we can get and still be grid-aligned)

            ldat.ami = new IMapItem[ami.Length];
            for (int imi = 0; imi < ami.Length; imi++) {
                IMapItem mi = (IMapItem)ami[imi].Clone();
                ldat.ami[imi] = mi;
                mi.tx -= txMin;
                mi.ty -= tyMin;
            }

            // Figure out mouse position relative to this origin

            int xOrigin = (int)(txMin * sizTile.Width);
            int yOrigin = (int)(tyMin * sizTile.Height);
            ldat.txMouse = (double)(x - xOrigin) / (double)sizTile.Width;
            ldat.tyMouse = (double)(y - yOrigin) / (double)sizTile.Height;

            // All done

            return ldat;
        }
Example #43
0
 void IMapItem_PropertyChanged(IMapItem mi, string strProperty)
 {
     SetModified(true);
     m_fUpdateDirty = true;
 }
Example #44
0
 public virtual void OnPropertyChanged(IMapItem mi, string strProperty)
 {
     if (PropertyChanged != null)
         PropertyChanged(mi, strProperty);
 }
Example #45
0
 private void LevelDoc_ItemsRemoved(IMapItem[] ami)
 {
     ArrayList alsmiSelected = m_lvld.Selection;
     foreach (IMapItem mi in ami) {
         alsmiSelected.Remove(mi);
         if (m_miContextMenu == mi)
             m_miContextMenu = null;
         if (m_miCapturedMouse == mi)
             m_miCapturedMouse = null;
         break;
     }
     m_lvld.Selection = alsmiSelected;
 }