public void OnUpdatePositionBtnClick() { int x = 0, y = 0; if (InputFieldX) { if (!int.TryParse(InputFieldX.text, out x)) { Debug.Log("Error Input X"); return; } } if (InputFieldY) { if (!int.TryParse(InputFieldY.text, out y)) { Debug.Log("Error Input Y"); return; } } Vector3 localPos = CoordConverter.UtmToLocal(new Vector3(x, y, 0)); MinimapPositioner.SetWorldPoint(localPos); Minimap.FocusOnWorldPoint(localPos); }
private void Set(SetLocation msg) { if (msg.ReceiverId == Entity.MyEntityId) { Target.position = CoordConverter.GeocToLocal(new CppStructs.XYZ(msg.X, msg.Y, msg.Z)); } }
protected internal override void OnCursorPressHold(CursorInputEventArgs e) { // default processing (this is now essential as it controls event firing). base.OnCursorPressHold(e); if (e.Source == CursorInputSource.Left) { if (IsSizingEnabled()) { // get position of mouse as co-ordinates local to this window. var localPos = CoordConverter.ScreenToWindow(this, e.Position); // if the mouse is on the sizing border if (GetSizingBorderAtPoint(localPos) != SizingLocation.SizingNone) { // ensure all inputs come to us for now if (CaptureInput()) { // setup the 'dragging' state variables _beingSized = true; _dragPoint = localPos; // do drag-sizing started notification OnDragSizingStarted(new WindowEventArgs(this)); ++e.handled; } } } } }
private TurnError ActAnalyse(Ant ant, HexDirection direction) { if (direction == HexDirection.CENTER) { return(TurnError.ILLEGAL); } Vector2Int target = CoordConverter.MoveHex(ant.gameCoordinates, direction); TurnError tileError = CheckAnalyzability(target); if (tileError != TurnError.NONE) { return(tileError); } // Set all the fields of the response to 0 TerrainType terrainType = TerrainType.NONE; AntType antType = AntType.NONE; bool isAllied = false; Value foodValue = Value.NONE; bool egg = false; if (terrain[target.x][target.y] == null || terrain[target.x][target.y].tile == null) { } // Leave everything like that else { terrainType = terrain[target.x][target.y].tile.Type; if (terrain[target.x][target.y].ant == null) { } // Leave everything like that else { antType = terrain[target.x][target.y].ant.Type; isAllied = terrain[target.x][target.y].ant.team.teamId == ant.team.teamId; terrain[target.x][target.y].ant.eventInputs.Add(new EventInputBump(CoordConverter.InvertDirection(direction))); } if (terrain[target.x][target.y].food == null) { } // Leave everything like that else { foodValue = ValueConverter.Convert(terrain[target.x][target.y].food.value, Const.FOOD_SIZE); } egg = terrain[target.x][target.y].egg != null; if (egg) { isAllied = terrain[target.x][target.y].egg.team.teamId == ant.team.teamId; } } ant.analyseReport = new AnalyseReport(terrainType, antType, egg, isAllied, foodValue, null); return(TurnError.NONE); }
public Vector3 GetRandomPositionInHalf() { Random rand = new Random(); Vector2 pos = new Vector2(rand.Next((int)gridHalfStart.X, (int)gridHalfEnd.X + 1), rand.Next((int)gridHalfStart.Y, (int)gridHalfEnd.Y + 1)); return(CoordConverter.OffsetToCube(pos)); }
private void GenerateTiles(int offsetSizeX, int offsetSizeY, Vector2 screenBoardOrigin, float boardScale) { tiles = new HexTile[offsetSizeX, offsetSizeY]; //generate offset grid and convert to cube coords for (int x = 0; x < offsetSizeX; x++) { for (int y = 0; y < offsetSizeY; y++) { Vector2 verticalRowOffset = Vector2.Zero; //calculate the rows offset from the grid draw origin. use this to calculate each tile's pixel position. // (position to draw on screen so they tessalate) for (int i = 0; i < y; i++) { if ((i & 1) == 1) //if current row is odd { verticalRowOffset += oddToEvenRowOffset; } else { verticalRowOffset += evenToOddRowOffset; } } //pixel position: Vector2 pixelCoordinate = screenBoardOrigin + (((x * horizontalRowOffset) + verticalRowOffset) * boardScale); tiles[x, y] = new HexTile(CoordConverter.OffsetToCube(new Vector2(x, y)), pixelCoordinate); } } }
public override float GetValueFromThumb() { var w = (Slider)Window; // get area the thumb is supposed to use as it's area. var wlf = GetLookNFeel(); var area = wlf.GetNamedArea("ThumbTrackArea").GetArea().GetPixelRect(w); // get accesss to the thumb var theThumb = w.GetThumb(); // slider is vertical if (_vertical) { // pixel extent of total available area the thumb moves in var slideExtent = area.Height - theThumb.GetPixelSize().Height; // calculate value represented by current thumb position var thumbValue = (CoordConverter.AsAbsolute(theThumb.GetYPosition(), w.GetPixelSize().Height) - area.Top) / (slideExtent / w.GetMaxValue()); // return final thumb value according to slider settings return(_reversed ? thumbValue : w.GetMaxValue() - thumbValue); } // slider is horizontal else { // pixel extent of total available area the thumb moves in var slideExtent = area.Width - theThumb.GetPixelSize().Width; // calculate value represented by current thumb position var thumbValue = (CoordConverter.AsAbsolute(theThumb.GetXPosition(), w.GetPixelSize().Width) - area.Left) / (slideExtent / w.GetMaxValue()); // return final thumb value according to slider settings return(_reversed ? w.GetMaxValue() - thumbValue : thumbValue); } }
public void LayoutCeGui() { // used to compare UDims var absWidth = GetChildContentArea().Get().Width; // this is where we store the top offset // we continually increase this number as we go through the windows var topOffset = UDim.Zero; var layoutWidth = UDim.Zero; foreach (var window in d_children.Cast <Window>()) { var offset = GetOffsetForWindow(window); var boundingSize = GetBoundingSizeForWindow(window); // full child window width, including margins var childWidth = boundingSize.d_x; if (CoordConverter.AsAbsolute(layoutWidth, absWidth) < CoordConverter.AsAbsolute(childWidth, absWidth)) { layoutWidth = childWidth; } window.SetPosition(offset + new UVector2(UDim.Zero, topOffset)); topOffset += boundingSize.d_y; } SetSize(new USize(layoutWidth, topOffset)); //SetHeight(topOffset); }
private void LayoutCeGui() { // used to compare UDims var absHeight = GetChildContentArea().Get().Height; // this is where we store the left offset // we continually increase this number as we go through the windows var leftOffset = UDim.Zero; var layoutHeight = UDim.Zero; foreach (Window window in d_children) { //Window* window = static_cast<Window*>(*it); var offset = GetOffsetForWindow(window); var boundingSize = GetBoundingSizeForWindow(window); // full child window width, including margins var childHeight = boundingSize.d_y; if (CoordConverter.AsAbsolute(layoutHeight, absHeight) < CoordConverter.AsAbsolute(childHeight, absHeight)) { layoutHeight = childHeight; } window.SetPosition(offset + new UVector2(leftOffset, UDim.Zero)); leftOffset += boundingSize.d_x; } SetSize(new USize(leftOffset, layoutHeight)); }
/// <summary> /// set the movement range of the thumb for the vertical axis. /// /// The values specified here are relative to the parent window for the thumb, and are specified in whichever /// metrics mode is active for the widget. /// </summary> /// <param name="min"> /// the minimum setting for the thumb on the vertical axis. /// </param> /// <param name="max"> /// the maximum setting for the thumb on the vertical axis. /// </param> public void SetVertRange(float min, float max) { // ensure min <= max, swap if not. if (min > max) { var tmp = min; max = min; min = tmp; } _vertMax = max; _vertMin = min; // validate current position. var cp = CoordConverter.AsRelative(GetYPosition(), GetParentPixelSize().Height); if (cp < min) { SetYPosition(UDim.Relative(min)); } else if (cp > max) { SetYPosition(UDim.Relative(max)); } }
/// <summary> /// set the movement range of the thumb for the horizontal axis. /// /// The values specified here are relative to the parent window for the thumb, and are specified in whichever /// metrics mode is active for the widget. /// </summary> /// <param name="min"> /// the minimum setting for the thumb on the horizontal axis. /// </param> /// <param name="max"> /// the maximum setting for the thumb on the horizontal axis. /// </param> public void SetHorzRange(float min, float max) { var parentSize = GetParentPixelSize(); // ensure min <= max, swap if not. if (min > max) { var tmp = min; max = min; min = tmp; } _horzMax = max; _horzMin = min; // validate current position. var cp = CoordConverter.AsAbsolute(GetXPosition(), parentSize.Width); if (cp < min) { SetXPosition(UDim.Absolute(min)); } else if (cp > max) { SetXPosition(UDim.Absolute(max)); } }
protected internal override void OnCursorPressHold(CursorInputEventArgs e) { // base class processing base.OnCursorPressHold(e); if (e.Source == CursorInputSource.Left) { // ensure all inputs come to us for now if (CaptureInput()) { // get position of mouse as co-ordinates local to this window. var localPos = CoordConverter.ScreenToWindow(this, e.Position); // store drag point for possible sizing or moving operation. _dragPoint = localPos; // if the mouse is in the sizing area if (_splitterHover) { if (IsSizingEnabled()) { // setup the 'dragging' state variables _dragSizing = true; } } else { _segmentPushed = true; } } ++e.handled; } }
private bool DeadRecoknedPositionOrRotationIsWrong() { GeocentricCoord deadReckonedPosition; Vector3Float deadReckonedRotation; DeadReckoningCalculator.Calculate(_lastSentState, Time.time - _lastSendTime, out deadReckonedPosition, out deadReckonedRotation); double positionDeltaSquared = Math.Pow(deadReckonedPosition.X - State.Location.X, 2) + Math.Pow(deadReckonedPosition.Y - State.Location.Y, 2) + Math.Pow(deadReckonedPosition.Z - State.Location.Z, 2); if (positionDeltaSquared > MovementThreshold * MovementThreshold) { return(true); } var deadRecoknedLatLon = (LatLonCoord)CoordConverter.GeocentricToGeodetic(deadReckonedPosition); var currentLatLon = (LatLonCoord)CoordConverter.GeocentricToGeodetic((GeocentricCoord)State.Location); Vector3 deadReckonedEuler = CoordConverter.OrientationToUnityEuler(deadReckonedRotation, deadRecoknedLatLon); Vector3 currentEuler = CoordConverter.OrientationToUnityEuler(State.Orientation, currentLatLon); float rotationDelta = Quaternion.Angle(Quaternion.Euler(deadReckonedEuler), Quaternion.Euler(currentEuler)); if (rotationDelta > RotationThreshold) { return(true); } return(false); }
private void Draw_Grid(SpriteBatch spriteBatch) { for (int y = (int)grid.Size.Y - 1; y > -1; y--) { for (int x = (int)grid.Size.X - 1; x > -1; x--) { //draw a gray tile if the tile in question is in the opponents half if (pickedUpTileData.Item2 && (!turnPlayer.IsPointInHalf(grid.Tiles[x, y].OffsetCoordinate, false))) { spriteBatch.Draw(isoTile, position: grid.Tiles[x, y].PixelCoordinate, scale: boardScaleVector, color: Color.Gray); } //draw a red tile if there is a picked up tile from the bench and the // unit cap has been reached, and there is no unit on the hovered tile. // (unit cannot be placed on hovered tile). else if (pickedUpTileData.Item2 && pickedUpTileData.Item3 && grid.CountPlayerUnitsOnGrid(turnPlayer.Id) >= turnPlayer.UnitCap && ((grid.GetUnitFromCoordinate(CoordConverter.OffsetToCube(new Vector2(x, y))) == null) ? true : !(grid.GetUnitFromCoordinate(CoordConverter.OffsetToCube(new Vector2(x, y))).OwnerId == turnPlayer.Id))) { spriteBatch.Draw(isoTile, position: grid.Tiles[x, y].PixelCoordinate, scale: boardScaleVector, color: Color.DarkRed); } //otherwise draw an outline around the tile if its hovered. else if (hoveredTileData.Item2 && !hoveredTileData.Item3 && grid.Tiles[x, y].OffsetCoordinate == hoveredTileData.Item1) { //note the position must be decremented by (1,1)*boardScale as the sprite is (1,1) larger. spriteBatch.Draw(hoveredIsoTile, position: grid.Tiles[x, y].PixelCoordinate - boardScaleVector, scale: boardScaleVector); } else { spriteBatch.Draw(isoTile, position: grid.Tiles[x, y].PixelCoordinate, scale: boardScaleVector); } } } }
private void SpawnTerrainTile(int i, int j) { if (groundTilePrefab != null) { Vector2 currentTilePosition = CoordConverter.HexToPos(new Vector2Int(i, j)); float rand = Random.Range(0f, 1f); // Water is placed if the random number picked it AND the tile is not protected Tile newTile = null; Food newFood = null; if (!protectedTiles.Contains(new Vector2Int(i, j)) && rand < waterProbability) { newTile = Instantiate(waterTilePrefab, CoordConverter.PlanToWorld(currentTilePosition, waterTilePrefab.transform.position.y), waterTilePrefab.transform.rotation); } else { newTile = Instantiate(groundTilePrefab, CoordConverter.PlanToWorld(currentTilePosition, groundTilePrefab.transform.position.y), groundTilePrefab.transform.rotation); rand = Random.Range(0f, 1f); // Food is placed if the random number picked it AND the tile is not protected (AND the tile is not water) if (!protectedTiles.Contains(new Vector2Int(i, j)) && rand < foodProbability) { newFood = Instantiate(foodPrefab, CoordConverter.PlanToWorld(currentTilePosition, foodPrefab.transform.position.y), foodPrefab.transform.rotation); foods.Add(newFood); } } terrain[i][j] = new TileContent(newTile, newFood); } }
protected internal override void OnCursorMove(CursorInputEventArgs e) { base.OnCursorMove(e); // get position of mouse as co-ordinates local to this window. var localMousePos = CoordConverter.ScreenToWindow(this, e.Position); // handle dragging if (_dragging) { DoDragging(localMousePos); } // not dragging else { // if mouse button is down (but we're not yet being dragged) if (_leftPointerHeld) { if (IsDraggingThresholdExceeded(localMousePos)) { // Trigger the event OnDragStarted(new WindowEventArgs(this)); } } } }
protected override void LayoutItemWidgets() { // get render area var renderRect = GetItemRenderArea(); // get starting position var x0 = CoordConverter.AlignToPixels(renderRect.d_min.X); var y0 = CoordConverter.AlignToPixels(renderRect.d_min.Y); var sz = new UVector2(UDim.Absolute(CoordConverter.AlignToPixels(renderRect.Width)), UDim.Absolute(0)); // set item width // iterate through all items attached to this window foreach (var item in ListItems) { // get the "optimal" height of the item and use that! sz.d_y.d_offset = CoordConverter.AlignToPixels(item.GetItemPixelSize().Height); // rounding errors ? // set destination rect var rect = new URect { Position = new UVector2(UDim.Absolute(x0), UDim.Absolute(y0)), Size = new USize(sz.d_x, sz.d_y) }; // todo: vector vs size item.SetArea(rect); // next position y0 += CoordConverter.AlignToPixels(sz.d_y.d_offset + ItemSpacing); } }
private TurnError ActMove(Ant ant, HexDirection direction) { if (direction == HexDirection.CENTER) { return(TurnError.ILLEGAL); } Vector2Int newCoord = CoordConverter.MoveHex(ant.gameCoordinates, direction); TurnError tileError = CheckWalkability(newCoord); if (tileError != TurnError.NONE) { if (tileError == TurnError.COLLISION_ANT) { terrain[newCoord.x][newCoord.y].ant.eventInputs.Add(new EventInputBump(CoordConverter.InvertDirection(direction))); } return(tileError); } if (ant.CheckEnergy(Const.MOVE_COST)) { ant.UpdateEnergy(-Const.MOVE_COST); } else { return(TurnError.NO_ENERGY); } terrain[ant.gameCoordinates.x][ant.gameCoordinates.y].ant = null; terrain[newCoord.x][newCoord.y].ant = ant; ant.gameCoordinates = newCoord; return(TurnError.NONE); }
public override void MouseClick(object sender, MouseEventArgs e) { if (map.InsertionLayer == null) return; CoordSys layerCoordsys = map.InsertionLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)map.MapOffsetX, (double)map.MapOffsetY); atPan.MultiplyInPlace(map.MapScale, -map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); oCC.ConvertInverse(e.X, e.Y); DPoint pt = new DPoint(oCC.X, oCC.Y); // szukaj w tym miejscu feature List<Feature> ftrs = map.InsertionLayer.Search(pt); if (ftrs.Count == 0) { Feature oF = FeatureFactory.CreateSymbol(oCC.X, oCC.Y); map.InsertionLayer.FeaturesAdd(oF); } MapControl.Globals.Instance.MapControl.InvalidateMap(); }
private TurnError ActStock(Ant ant, HexDirection direction, int quantity) { if (direction == HexDirection.CENTER) { return(TurnError.ILLEGAL); } Vector2Int target = CoordConverter.MoveHex(ant.gameCoordinates, direction); TurnError tileError = CheckEdibility(target); if (tileError != TurnError.NONE) { if (tileError != TurnError.COLLISION_VOID && terrain[target.x][target.y].ant != null) { terrain[target.x][target.y].ant.eventInputs.Add(new EventInputBump(CoordConverter.InvertDirection(direction))); } return(tileError); } Food victim = terrain[target.x][target.y].food; int quantityToStock = Mathf.Min(quantity, Const.MAX_STOCK_BY_TURN); quantityToStock = victim.GetFood(quantityToStock); // The ant can eat more than it can store, so that it can remove food from the terrain if needed ant.UpdateStock(quantityToStock); isPermanentModif = true; return(TurnError.NONE); }
public void GeocToGeod() { var geod = CoordConverter.GeocentricToGeodetic(Real.Geoc); Assert.AreEqual(Real.Geod.Lat, geod.Lat, 0.00001); Assert.AreEqual(Real.Geod.Lon, geod.Lon, 0.00001); Assert.AreEqual(Real.Geod.Alt, geod.Alt, 0.001); }
private void Start() { CoordConverter.SetRefLatLon(new LatLonCoord(32.055304, 34.7564563)); _publishedEntity.State.EntityId.Entity = (ushort)UnityEngine.Random.Range(0, ushort.MaxValue); ExerciseConnection.Instance.Subscribe <DetonationPDU>(ReceivedDetonationPDU); CustomEventReportsManager.Instance.Subscribe <SampleEventReport>(ReceivedSampleEventReport); }
public void GeodToGeoc() { var geoc = CoordConverter.GeodeticToGeocentric(Real.Geod); Assert.AreEqual(Real.Geoc.X, geoc.X, 0.001); Assert.AreEqual(Real.Geoc.Y, geoc.Y, 0.001); Assert.AreEqual(Real.Geoc.Z, geoc.Z, 0.001); }
protected internal override void OnCursorMove(CursorInputEventArgs e) { // default processing base.OnCursorMove(e); // only react if we are being dragged if (_beingDragged) { var parentSize = GetParentPixelSize(); var delta = CoordConverter.ScreenToWindow(this, e.Position); var hmin = _horzMin; var hmax = _horzMax; var vmin = _vertMin; var vmax = _vertMax; // calculate amount of movement delta -= _dragPoint; delta.X /= parentSize.Width; delta.Y /= parentSize.Height; // // Calculate new (pixel) position for thumb // var newPos = GetPosition(); if (_horzFree) { newPos.d_x.d_scale += delta.X; // limit value to within currently set range newPos.d_x.d_scale = (newPos.d_x.d_scale < hmin) ? hmin : (newPos.d_x.d_scale > hmax) ? hmax : newPos.d_x.d_scale; } if (_vertFree) { newPos.d_y.d_scale += delta.Y; // limit new position to within currently set range newPos.d_y.d_scale = (newPos.d_y.d_scale < vmin) ? vmin : (newPos.d_y.d_scale > vmax) ? vmax : newPos.d_y.d_scale; } // update thumb position if needed if (newPos != GetPosition()) { SetPosition(newPos); // send notification as required if (_hotTrack) { OnThumbPositionChanged(new WindowEventArgs(this)); } } } ++e.handled; }
/// <summary> /// Return whether the required minimum movement threshold before initiating dragging /// has been exceeded. /// </summary> /// <param name="localMouse"> /// Mouse position as a pixel offset from the top-left corner of this window. /// </param> /// <returns> /// - true if the threshold has been exceeded and dragging should be initiated. /// - false if the threshold has not been exceeded. /// </returns> protected bool IsDraggingThresholdExceeded(Lunatics.Mathematics.Vector2 localMouse) { // calculate amount mouse has moved. var deltaX = Math.Abs(localMouse.X - CoordConverter.AsAbsolute(_dragPoint.d_x, d_pixelSize.Width)); var deltaY = Math.Abs(localMouse.Y - CoordConverter.AsAbsolute(_dragPoint.d_y, d_pixelSize.Height)); // see if mouse has moved far enough to start dragging operation return(deltaX > _dragThreshold || deltaY > _dragThreshold); }
public override void Layout() { var colSizes = new List <UDim>(Enumerable.Repeat(UDim.Zero, _gridWidth)); var rowSizes = new List <UDim>(Enumerable.Repeat(UDim.Zero, _gridHeight)); // used to compare UDims var absWidth = GetChildContentArea().Get().Width; var absHeight = GetChildContentArea().Get().Height; // first, we need to determine rowSizes and colSizes, this is needed before // any layouting work takes place for (var y = 0; y < _gridHeight; ++y) { for (var x = 0; x < _gridWidth; ++x) { // x and y is the position of window in the grid var childIdx = MapFromGridToIdx(x, y, _gridWidth, _gridHeight); var window = GetChildAtIdx(childIdx); var size = GetBoundingSizeForWindow(window); if (CoordConverter.AsAbsolute(colSizes[x], absWidth) < CoordConverter.AsAbsolute(size.d_x, absWidth)) { colSizes[x] = size.d_x; } if (CoordConverter.AsAbsolute(rowSizes[y], absHeight) < CoordConverter.AsAbsolute(size.d_y, absHeight)) { rowSizes[y] = size.d_y; } } } // OK, now in rowSizes[y] is the height of y-th row // in colSizes[x] is the width of x-th column // second layouting phase starts now for (var y = 0; y < _gridHeight; ++y) { for (var x = 0; x < _gridWidth; ++x) { // x and y is the position of window in the grid var childIdx = MapFromGridToIdx(x, y, _gridWidth, _gridHeight); var window = GetChildAtIdx(childIdx); var offset = GetOffsetForWindow(window); var gridCellOffset = GetGridCellOffset(colSizes, rowSizes, x, y); window.SetPosition(gridCellOffset + offset); } } // now we just need to determine the total width and height and set it SetSize(GetGridSize(colSizes, rowSizes)); }
protected internal override void OnCursorMove(CursorInputEventArgs e) { // default processing (this is now essential as it controls event firing). base.OnCursorMove(e); // if we are not the window containing the mouse, do NOT change the cursor if (GetGUIContext().GetWindowContainingCursor() != this) { return; } if (IsSizingEnabled()) { var localMousePos = CoordConverter.ScreenToWindow(this, e.Position); if (_beingSized) { var dragEdge = GetSizingBorderAtPoint(_dragPoint); // calculate sizing deltas... var deltaX = localMousePos.X - _dragPoint.X; var deltaY = localMousePos.Y - _dragPoint.Y; var newArea = d_area; var topLeftSizing = false; // size left or right edges if (IsLeftSizingLocation(dragEdge)) { topLeftSizing |= MoveLeftEdge(deltaX, ref newArea); } else if (IsRightSizingLocation(dragEdge)) { topLeftSizing |= MoveRightEdge(deltaX, ref newArea); } // size top or bottom edges if (IsTopSizingLocation(dragEdge)) { topLeftSizing |= MoveTopEdge(deltaY, ref newArea); } else if (IsBottomSizingLocation(dragEdge)) { topLeftSizing |= MoveBottomEdge(deltaY, ref newArea); } SetAreaImpl(newArea.d_min, newArea.Size, topLeftSizing); } else { SetCursorForPoint(localMousePos); } } // mark event as handled ++e.handled; }
/// <summary> /// Internal implementation of make tab visible. /// </summary> /// <param name="wnd"> /// Pointer to a Window which is the root of the tab content to make visible /// </param> protected virtual void MakeTabVisibleImpl(Window wnd) { TabButton tb = null; foreach (var item in d_tabButtonVector) { // get corresponding tab button and content window tb = item; var child = tb.GetTargetWindow(); if (child == wnd) { break; } tb = null; } if (tb == null) { return; } var ww = GetPixelSize().Width; var x = CoordConverter.AsAbsolute(tb.GetPosition().d_x, ww); var w = tb.GetPixelSize().Width; float lx = 0f, rx = ww; if (IsChild(ButtonScrollLeft)) { var scrollLeftBtn = GetChild(ButtonScrollLeft); lx = CoordConverter.AsAbsolute(scrollLeftBtn.GetArea().d_max.d_x, ww); scrollLeftBtn.SetWantsMultiClickEvents(false); } if (IsChild(ButtonScrollRight)) { var scrollRightBtn = GetChild(ButtonScrollRight); rx = CoordConverter.AsAbsolute(scrollRightBtn.GetPosition().d_x, ww); scrollRightBtn.SetWantsMultiClickEvents(false); } if (x < lx) { d_firstTabOffset += lx - x; } else { if (x + w <= rx) { return; // nothing to do } d_firstTabOffset += rx - (x + w); } PerformChildWindowLayout(); }
protected virtual void SetLocationHandler(SetLocation msg) { if (msg.ReceiverId == Entity.MyEntityId) { if (OnSetPosition != null) { OnSetPosition(CoordConverter.GeocToLocal(new CppStructs.XYZ(msg.X, msg.Y, msg.Z))); } } }
public override void ResizeListToContent(bool fitWidth, bool fitHeight) { var lb = (Listbox)Window; var totalArea = lb.GetUnclippedOuterRect().Get(); var contentArea = GetItemRenderingArea(!fitWidth && lb.GetHorzScrollbar().IsVisible(), !fitHeight && lb.GetVertScrollbar().IsVisible()); var withScrollContentArea = GetItemRenderingArea(true, true); var frameSize = totalArea.Size - contentArea.Size; var withScrollFrameSize = totalArea.Size - withScrollContentArea.Size; var contentSize = new Sizef(lb.GetWidestItemWidth(), lb.GetTotalItemsHeight()); var parentSize = lb.GetParentPixelSize(); var maxSize = new Sizef(parentSize.Width - CoordConverter.AsAbsolute(lb.GetXPosition(), parentSize.Width), parentSize.Height - CoordConverter.AsAbsolute(lb.GetYPosition(), parentSize.Height)); var requiredSize = frameSize + contentSize + new Sizef(1, 1); if (fitHeight) { if (requiredSize.Height > maxSize.Height) { requiredSize.Height = maxSize.Height; requiredSize.Width = Math.Min(maxSize.Width, requiredSize.Width - frameSize.Width + withScrollFrameSize.Width); } } if (fitWidth) { if (requiredSize.Width > maxSize.Width) { requiredSize.Width = maxSize.Width; requiredSize.Height = Math.Min(maxSize.Height, requiredSize.Height - frameSize.Height + withScrollFrameSize.Height); } } if (fitHeight) { lb.SetHeight(new UDim(0, requiredSize.Height)); } if (fitWidth) { lb.SetWidth(new UDim(0, requiredSize.Width)); } }
private const double zoomElevateUpscale = 1024 * 8; //1024; #endregion Fields #region Methods public void Download(int zoom, MapType mapType, CoordConverter oCC, System.Drawing.Rectangle Rect) { // produce a list of needed tiles // ustal dla jakiego zoom wyswietlac bedziemy kafelki for (int enlarge = 0; enlarge < 7; enlarge++) { DownloadZoom(zoom, enlarge, mapType, oCC, Rect); } //System.Windows.Forms.MessageBox }
List <Vector2> GetUwPath(List <Point> pfsPath) { var usPath = pfsPath.Select(p => CoordConverter.PFS_To_US(p)).ToList(); //--------------------------------------------------------------------------------------- //Debug.Log("НАЙДЕННЫЙ ПУТЬ: " + StringManipulation.ListToString(usPath)); //--------------------------------------------------------------------------------------- //А теперь путь в UW: var uwPath = usPath.Select(p => CoordConverter.US_To_UW(p)).ToList(); uwPath.Remove(uwPath[0]); return(uwPath); }
public override void MouseMove(object sender, MouseEventArgs e) { base.MouseMove(sender, e); // highlight polilines and points if (map.InsertionLayer == null) return; CoordSys layerCoordsys = map.InsertionLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)map.MapOffsetX, (double)map.MapOffsetY); atPan.MultiplyInPlace(map.MapScale, -map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); int margin = 5; oCC.ConvertInverse(e.X, e.Y); DPoint pt_center = new DPoint(oCC.X, oCC.Y); oCC.ConvertInverse(e.X - margin, e.Y - margin); DPoint pt1 = new DPoint(oCC.X, oCC.Y); oCC.ConvertInverse(e.X + margin, e.Y + margin); DPoint pt2 = new DPoint(oCC.X, oCC.Y); // szukaj w tym miejscu feature //List<Feature> ftrs = map.InsertionLayer.Search(pt); // construct search rectangle (10px wide) DRect rect = new DRect(pt1.X, pt2.Y, pt2.X, pt1.Y); //map.InsertionLayer.SelectWithinRectangle(rect); }
/// <summary> /// Rednders contained features /// </summary> /// <param name="g"></param> /// <param name="Rect"></param> /// <param name="oCC"></param> public void draw(Graphics g, Rectangle Rect, CoordConverter oCC) { if (boundsOK == false) { calculateBounds(); } // calculate Bound in Layer Coordsys double xmin, xmax, ymin, ymax; // bounds of current viewport (in map coordsys) // TODO: respoct rotation of coordsys oCC.ConvertInverse(Rect.Left, Rect.Top); xmin = oCC.X; ymin = oCC.Y; oCC.ConvertInverse(Rect.Right, Rect.Bottom); xmax = oCC.X; ymax = oCC.Y; if (ymin > ymax) { double t = ymin; ymin = ymax; ymax = t; } DRect rectScreenInLayer = new DRect(xmin, ymin, xmax, ymax); // refresh value of Feature.MBR for (int i = 0; i < m_oFeatures.Count; i++) { Feature feature = m_oFeatures[i]; if (feature != null) { int pixelMargin = feature.pixelMargin(); if (feature.MBR.X2 >= xmin - pixelMargin && feature.MBR.X1 <= xmax + pixelMargin && feature.MBR.Y2 >= ymin - pixelMargin && feature.MBR.Y1 <= ymax + pixelMargin) { drawMapFeature(g, Rect, rectScreenInLayer, oCC, feature, false); } } } }
private void mapControl1_MouseMove(object sender, MouseEventArgs e) { DPoint pt; mapControl1.Map.DisplayTransform.FromDisplay(new System.Drawing.Point(e.X, e.Y), out pt); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt.X, pt.Y); // calculate zoom CoordSys layerCoordsys = tileLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, mapControl1.Map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)mapControl1.Map.MapOffsetX, (double)mapControl1.Map.MapOffsetY); atPan.MultiplyInPlace(mapControl1.Map.MapScale, -mapControl1.Map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); double zoomElevateUpscale = 1024 * 8; //1024; double scale = oCC.atMaster.A; int zoom = (int)Math.Log(scale * zoomElevateUpscale, 2); lblInfo.Text = string.Format("x={0:0.00000}, y={1:0.00000} Mercator: x={2:0}, y={3:0}, zoom={4}", occ.X, occ.Y, pt.X, pt.Y, zoom); }
private void tileDownloaderToolStripMenuItem_Click(object sender, EventArgs e) { // auto download tiles // calculate x,y, range // calculate zoom range CoordSys layerCoordsys = tileLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, mapControl1.Map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)mapControl1.Map.MapOffsetX, (double)mapControl1.Map.MapOffsetY); atPan.MultiplyInPlace(mapControl1.Map.MapScale, -mapControl1.Map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); double zoomElevateUpscale = 1024 * 8; //1024; double scale = oCC.atMaster.A; int zoom = (int)Math.Log(scale * zoomElevateUpscale, 2); TileDownloader downloader = new TileDownloader(); downloader.Download(zoom, ((LayerTilesAsynch)tileLayer).MapType, oCC, new System.Drawing.Rectangle(0, 0, mapControl1.Width, mapControl1.Height)); }
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { // test coordsys Datum datumEllipse = CoordSysFactory.CreateDatum(DatumID.WGS84); Datum datumSphere = CoordSysFactory.CreateDatum(Ellipsoid.Sphere, 0, 0, 0, 0, 0, 0, 0, 0); CoordSys source = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, datumEllipse, new AffineTransform()); CoordSys target = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, datumEllipse, new AffineTransform()); CoordConverter oCC = new CoordConverter(); oCC.Init(source, target); oCC.Convert(21, 52); double x = oCC.X; // 2337709.3066587453 double y = oCC.Y; // 6800125.4543973068 // (21, 52) -> (2337709.3066587453, 6800125.4543973068) (alg. Sphere) // (21, 52) -> (2337709.3066587453, 6766432.7231710562) (alg. Ellipse) // (21, 52) -> (2337709.3066587453, 6800078.8362877583) (DatumConv + Ellipse) // (21, 52) -> (2337709.3066587453, 6800125.4543973068) (alg. Ellipse , data Sphere) }
private void DrawImageGMap(int x1, int y1, int w, int h, Graphics g, CoordConverter oCC, int picx, int picy, int picZoom) { PureImage img = null; try { Exception result; img = GMaps.Instance.GetImageFrom(mapType, new GMap.NET.Point(picx, picy), picZoom, out result); } catch (Exception) { } WindowsFormsImage imgWin = (WindowsFormsImage)img; if (imgWin == null) return; // bitmap position oCC.Convert(x1, y1); int xScr = (int)Math.Round(oCC.X); int yScr = (int)Math.Round(oCC.Y); oCC.Convert(x1 + w, y1 + h); int xScrWidth = (int)Math.Round(oCC.X - xScr); int yScrWidth = (int)Math.Round(oCC.Y - yScr); if (xScrWidth < 0) { xScrWidth = -xScrWidth; xScr = xScr - xScrWidth; } if (yScrWidth < 0) { yScrWidth = -yScrWidth; yScr = yScr - yScrWidth; } if (img != null) { Debug.Assert(xScrWidth == 256); Debug.Assert(yScrWidth == 256); g.DrawImage(imgWin.Img, xScr, yScr, xScrWidth, yScrWidth); } else { Assembly myAssembly = Assembly.GetExecutingAssembly(); Stream myStream = myAssembly.GetManifestResourceStream("hiMapNet.Resources.h0.jpeg"); Bitmap bmp = new Bitmap(myStream); g.DrawImage(bmp, xScr, yScr, xScrWidth, yScrWidth); bmp.Dispose(); } }
private void InitMapAndPresenter() { // set Display coordsys mapControl1.Map.DisplayCoordSys = CoordSysFactory.CreateCoordSys("Mercator Datum(WGS84)"); // make Map Layer mapControl1.Map.Layers.Clear(); mapControl1.ResizeScaleMode = MapControl.ResizeScaleConst.NoChange; // One Tile Layer tileLayer = new LayerTilesAsynch(); // mercator (datum(wgs84)) mapControl1.Map.Layers.Add(tileLayer); // MVC ------------ // bind view to presentation surface (control) gpxMapView = new GPXViewMap(mapControl1); gpxViewTree = new GPXViewTree(treeView1); gpxViewScrollbar = new GPXViewScrollbar(gpxScrollBar); gpxViewTimeSlide = new GPXViewTimeSlide(timeSlide1); gpxPresenter = new GPXPresenter(); gpxPresenter.registerView(gpxMapView); gpxPresenter.registerView(gpxViewTree); gpxPresenter.registerView(gpxViewScrollbar); gpxPresenter.registerView(gpxViewTimeSlide); mapControl1.Map.InsertionLayer = gpxMapView.o_LayerGPXPolylines; // CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); oCCGPS = new CoordConverter(); oCCGPS.Init(gpxMapView.o_LayerGPXPolylines.LayerCoordSys, mapControl1.Map.DisplayCoordSys); // show zoom=0 (whole world) in scale 1px screen = 1px layer Datum datumWGS84 = CoordSysFactory.CreateDatum(DatumID.WGS84); double r = datumWGS84.SemiMajorAxis; double zoom = mapControl1.Bounds.Width / 256.0 * 2 * Math.PI * r; //mapControl1.SetCenterZoom(0.0, 0.0, zoom, mapControl1.Bounds); /* if (gpxFile.getWptCount() > 0) { GpxWpt wpt = gpxFile.getWpt(0); oCCGPS.Convert(wpt.lon, wpt.lat); mapControl1.SetCenterZoom(oCCGPS.X, -oCCGPS.Y, zoom / 256.0, mapControl1.Bounds); // center poland } else {*/ oCCGPS.Convert(21.0, 52.0); mapControl1.SetCenterZoom(oCCGPS.X, -oCCGPS.Y, zoom / 256.0, mapControl1.Bounds); // center poland //} }
void DrawLayer(LayerAbstract oL, Graphics g, Rectangle Rect) { CoordSys layerCoordsys = oL.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)mapOffsetX, (double)mapOffsetY); atPan.MultiplyInPlace(mapScale, -mapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); oL.Draw(g, Rect, oCC); }
/// <summary> /// Select all objects within the rectangle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { bool modified = false; base.MouseUp(sender, e); bool keyShift = ((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.Shift); bool keyControl = ((System.Windows.Forms.Control.ModifierKeys & Keys.Control) == Keys.Control); MapControl.Globals.Instance.MapControl.Cursor = Cursors.Arrow; if (ActiveRectangle.Width == 0 && ActiveRectangle.Height == 0) { relocateMode = false; rotateMode = false; rectSelectionMode = false; relocateModeAllowRelocation = false; DRect rect = calculateRectangleFromPoint(e.X, e.Y); List<DPoint> points = polylineLayer.SearchForPolylinePoints(rect); if (points.Count > 0) { if (points[0].Selected) { if (!keyControl && !keyShift) { polylineLayer.selectionClear(); points[0].Selected = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } if (keyControl && !keyShift) { points[0].Selected = false; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } } else { if (keyControl && !keyShift) { points[0].Selected = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } return; } // select polyline // try to select an object List<Feature> features = polylineLayer.SearchForFeaturesColliding(rect); if (features.Count > 0) { if (features[0].Selected) { if (!keyControl && !keyShift) { polylineLayer.selectionClear(); features[0].Selected = true; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } if (keyControl && !keyShift) { features[0].Selected = false; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } } else { if (keyControl && !keyShift) { features[0].Selected = true; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } return; } if (!keyControl && !keyShift) { polylineLayer.selectionClear(); modified = true; } } else { // Dragging done if (relocateMode && relocateModeAllowRelocation) { List<Feature> features = polylineLayer.selectionFeatures(); List<DPoint> points = polylineLayer.selectionPoints(true); // calculate delta... // mouse start: m_oMouseStart // mouse end: m_oMouseCurrent int dxi = m_oMouseStart.X - m_oMouseCurrent.X; int dyi = m_oMouseStart.Y - m_oMouseCurrent.Y; int pixelDelta = (int)Math.Sqrt(dxi * dxi + dyi * dyi); DRect r1 = calculateRectangleFromPoint(m_oMouseStart.X, m_oMouseStart.Y); DRect r2 = calculateRectangleFromPoint(m_oMouseCurrent.X, m_oMouseCurrent.Y); double dx = r2.X1 - r1.X1; double dy = r2.Y1 - r1.Y1; // store copy of original point for undo polylineLayer.Manager.startRecordingUndoElement(); symbolLayer.Manager.startRecordingUndoElement(); // move polylines for (int i = 0; i < points.Count; i++) { DPoint newPoint = new DPoint(points[i].X + dx, points[i].Y + dy); polylineLayer.Manager.recordMovePoint(points[i], newPoint); // find correcponding symbol in symbolLayer SymbolFeature symbol = (SymbolFeature)points[i].Tag; Debug.Assert(symbol != null); SymbolFeature newSymbol = new SymbolFeature(symbol.x + dx, symbol.y + dy); symbolLayer.Manager.recordMoveFeature(symbol, newSymbol); modified = true; } polylineLayer.Manager.stopRecordingUndoElement(); symbolLayer.Manager.stopRecordingUndoElement(); // refresh view MapControl.Globals.Instance.MapControl.InvalidateMap(); } if (rotateMode) { // rotation } if (rectSelectionMode) { if (!keyShift && !keyControl) { polylineLayer.selectionClear(); modified = true; /* // emit clear selection for all wpt-s for (int i = 0; i < symbolLayer.FeaturesCount; i++) { SymbolFeature symbol = symbolLayer.FeatureGet(i) as SymbolFeature; if (symbol != null) { //WptSelected(this, (symbol.Tag as GpxWpt), false); } }*/ } if (!keyControl) { System.Drawing.Rectangle r = ActiveRectangle; System.Drawing.Point p1 = new System.Drawing.Point(r.X, r.Y); System.Drawing.Point p2 = new System.Drawing.Point(r.X + r.Width, r.Y + r.Height); DPoint pt1, pt2; map.DisplayTransform.FromDisplay(p1, out pt1); map.DisplayTransform.FromDisplay(p2, out pt2); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt1.X, pt1.Y); DPoint dp1 = new DPoint(occ.X, occ.Y); occ.Convert(pt2.X, pt2.Y); DPoint dp2 = new DPoint(occ.X, occ.Y); DRect rect = new DRect(dp1.X, dp2.Y, dp2.X, dp1.Y); List<DPoint> points = polylineLayer.SearchForPolylinePoints(rect); for (int i = 0; i < points.Count; i++) { points[i].Selected = true; modified = true; } List<Feature> features = polylineLayer.SearchForFeaturesContained(rect); for (int i = 0; i < features.Count; i++) { features[i].Selected = true; modified = true; } MapControl.Globals.Instance.MapControl.InvalidateMap(); } } if (timer != null) { timer.Stop(); timer = null; } relocateMode = false; rotateMode = false; rectSelectionMode = false; relocateModeAllowRelocation = false; } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } }
private DRect calculateRectangleFromPoint(int x, int y) { // try to select a polyline point int margin = 3; System.Drawing.Point p1 = new System.Drawing.Point(x - margin, y - margin); System.Drawing.Point p2 = new System.Drawing.Point(x + margin, y + margin); DPoint pt1, pt2; map.DisplayTransform.FromDisplay(p1, out pt1); map.DisplayTransform.FromDisplay(p2, out pt2); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt1.X, pt1.Y); DPoint dp1 = new DPoint(occ.X, occ.Y); occ.Convert(pt2.X, pt2.Y); DPoint dp2 = new DPoint(occ.X, occ.Y); DRect rect = new DRect(dp1.X, dp2.Y, dp2.X, dp1.Y); return rect; }
public void DownloadZoom(int zoom, int enlarge, MapType mapType, CoordConverter oCC, System.Drawing.Rectangle Rect) { int enlargeMul = 1 << enlarge; // produce a list of needed tiles // ustal dla jakiego zoom wyswietlac bedziemy kafelki if (oCC.atMaster.IsRotating()) return; //can not display double scale = oCC.atMaster.A * enlargeMul; //System.Diagnostics.Debug.Print("Scale={0}", scale); // scale = 1,2,4,8 int zoom1 = (int)Math.Log(scale * zoomElevateUpscale, 2); int tileSizePx = (int)Math.Round(256.0 / scale); // zoom=0 -> 256 * zoomElevate if (tileSizePx < 1) return; // ustal uklad wsp. w jakim są przechowywane kafelki // jest to inny uklad w kazdym zoomie // zoom=0 -> 0;0 - 256;256 (2^0=1) 0x100 // zoom=1 -> 0;0 - 512;512 (2^1=2) 0x200 // zoom=2 -> 0;0 - 1024;1024 (2^2=4) 0x400 // ... // zoom=17 -> 0;0 - 33554432;33554432 (2^17=131072) 0x02000000 (32bit) // zoom=18 -> // zoom=19 -> // oblicz prostokat widocznosci w ukladzie kafelkow (z Display Coordsys do Layer Coordsys) int x1, y1; oCC.ConvertInverse(Rect.X, Rect.Y); x1 = (int)oCC.X; y1 = (int)oCC.Y; int x2, y2; oCC.ConvertInverse(Rect.X + Rect.Width, Rect.Y + Rect.Height); x2 = (int)oCC.X; y2 = (int)oCC.Y; if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; } // zoom=0 -> 256 // zoom=1 -> 128 // zoom=2 -> 64 // zaokraglij wsp. w ukl mapy do pelnych rozmiarow kafelka int xx1 = (x1 / tileSizePx) * tileSizePx; int yy1 = (y1 / tileSizePx) * tileSizePx; int xx2 = (x2 / tileSizePx) * tileSizePx + tileSizePx; int yy2 = (y2 / tileSizePx) * tileSizePx + tileSizePx; // cache System.Drawing.Rectangle rect = new System.Drawing.Rectangle( xx1 / tileSizePx, yy1 / tileSizePx, (xx2 - xx1) / tileSizePx, (yy2 - yy1) / tileSizePx); int max = (int)(scale * zoomElevateUpscale); int xcount = xx2 / tileSizePx - xx1 / tileSizePx ; int ycount = yy2 / tileSizePx - yy1 / tileSizePx ; int total = xcount * ycount; frmTileDownloader frm = new frmTileDownloader(); frm.Show(); int count = 0; for (int x = xx1; x < xx2; x += tileSizePx) { for (int y = yy1; y < yy2; y += tileSizePx) { int picx = x / tileSizePx; int picy = y / tileSizePx; int picZoom = zoom; if (picx >= 0 && picy >= 0 && picx < max && picy < max) { // drawOneLayerTile(x, y, (int)(tileSizePx), (int)(tileSizePx), oCC, picx, picy, picZoom, false); drawOneLayerTile(picx, picy, picZoom, mapType); } count++; } //Debug.Print("progress for zoom {0}: {1}/{2}", zoom, count, total); string message = String.Format("progress for zoom {0}: {1}/{2}", zoom1, count, total); frm.Update(message, 100 * count / total); if (frm.cancel) break; } frm.Close(); }
private void DrawEllipse(int x1, int y1, int w, int h, Graphics g, CoordConverter oCC1) { // bitmap position oCC1.Convert(x1, y1); int xScr = (int)oCC1.X; int yScr = (int)oCC1.Y; oCC1.Convert(x1 + w, y1 + h); int xScrWidth = (int)(oCC1.X - xScr); int yScrWidth = (int)(oCC1.Y - yScr); g.DrawEllipse(Pens.Red, xScr, yScr, xScrWidth, yScrWidth); string s = string.Format("x={0}, y={1}", x1, y1); g.DrawString(s, new Font("Arial", 16), Brushes.Green, xScr + 64, yScr + 128, StringFormat.GenericDefault); }
private void drawMapFeature(Graphics g, Rectangle Rect, DRect rectScreenInLayer, CoordConverter oCC, Feature feature, bool selectionStyle) { Debug.Assert(feature != null); if (feature is PolylineFeature) { PolylineFeature oP = (PolylineFeature)feature; // draw polyline points for (int iPart = 0; iPart < oP.m_oParts.Count; iPart++) { List<DPoint> Points_list = oP.m_oParts[iPart].Points; if (Points_list.Count > 0) { DPoint[] Points_src = oP.m_oParts[iPart].Points.ToArray(); int ipp_count = Points_src.GetLength(0); Point[] Points_array = new Point[ipp_count]; Rectangle rect = new Rectangle(0, 0, 6, 6); int? currPointX = null; int? currPointY = null; int? prevPointX = null; int? prevPointY = null; for (int ipp = 0; ipp < ipp_count; ipp++) { // only points withing screen area if (rectScreenInLayer.Contains((double)Points_src[ipp].X, (double)Points_src[ipp].Y)) { oCC.Convert(Points_src[ipp].X, Points_src[ipp].Y); currPointX = (int)oCC.X; currPointY = (int)oCC.Y; rect.X = (int)oCC.X - 3; rect.Y = (int)oCC.Y - 3; rect.Width = 6; rect.Height = 6; if (Points_src[ipp].Selected) { m_oRenderGDIplus.FillRectangle(g, rect, 0xffff0000); // red } else { m_oRenderGDIplus.DrawRectangle(g, rect, 0xff0000ff); // blue } } else { currPointX = null; currPointY = null; } // "add point marker" if (ipp > 0) { if (currPointX != null || prevPointX != null) { // draw if at least one point is visible if (prevPointX == null) { // failed to calculate earlier (not visible), do it now oCC.Convert(Points_src[ipp - 1].X, Points_src[ipp - 1].Y); prevPointX = (int)oCC.X; prevPointY = (int)oCC.Y; } if (currPointX == null) { // failed to calculate earlier (not visible), do it now oCC.Convert(Points_src[ipp].X, Points_src[ipp].Y); currPointX = (int)oCC.X; currPointY = (int)oCC.Y; } int dx = (int)(currPointX - prevPointX); int dy = (int)(currPointY - prevPointY); int len = (int)Math.Sqrt(dx * dx + dy * dy); // draw when line segment longer than 20 pixels if (len > 20) { int pointX = (int)(prevPointX + currPointX) / 2; int pointY = (int)(prevPointY + currPointY) / 2; //m_oRenderGDIplus.DrawLine(g, pointX - 3, pointY - 3, pointX + 3, pointY + 3, 2, Color.Blue, 1); //m_oRenderGDIplus.DrawLine(g, pointX - 3, pointY + 3, pointX + 3, pointY - 3, 2, Color.Blue, 1); } } } prevPointX = currPointX; prevPointY = currPointY; } } } // draw actual polyline for (int iPart = 0; iPart < oP.m_oParts.Count; iPart++) { List<DPoint> Points_list = oP.m_oParts[iPart].Points; if (Points_list.Count > 0) { DPoint[] Points_src = oP.m_oParts[iPart].Points.ToArray(); int ipp_count = Points_src.GetLength(0); Point[] Points_array = new Point[ipp_count]; for (int ipp = 0; ipp < ipp_count; ipp++) { oCC.Convert((double)Points_src[ipp].X, (double)Points_src[ipp].Y); Points_array[ipp] = new Point((int)oCC.X, (int)oCC.Y); } if (oP.Selected) { m_oRenderGDIplus.DrawPolylineFeature(g, Points_array, oP.Style.LinePattern, Color.Red, oP.Style.LineWidth); } else { m_oRenderGDIplus.DrawPolylineFeature(g, Points_array, oP.Style.LinePattern, oP.Style.LineColor, oP.Style.LineWidth); } } } } else if (feature is SymbolFeature) { SymbolFeature oP = (SymbolFeature)feature; oCC.Convert(oP.x, oP.y); Rectangle rect = new Rectangle((int)oCC.X - 2, (int)oCC.Y - 2, 4, 4); if ((oP.color & 0xff000000) != 0x00) { if (feature.Selected) { m_oRenderGDIplus.DrawRectangle(g, rect, (uint)Color.Red.ToArgb()); } else { m_oRenderGDIplus.DrawRectangle(g, rect, oP.color); } } } else if (feature is RectangleFeature) { RectangleFeature oP = (RectangleFeature)feature; oCC.Convert(oP.x, oP.y); Rectangle rect = new Rectangle((int)oCC.X - 2, (int)oCC.Y - 2, 4, 4); m_oRenderGDIplus.DrawRectangle(g, rect, (uint)0xff000000); } else if (feature is BitmapFeature) { BitmapFeature oB = feature as BitmapFeature; oCC.Convert(oB.X, oB.Y); int x = (int)oCC.X; int y = (int)oCC.Y; g.DrawImageUnscaled(oB.Bitmap, new Point(x - oB.Anchorx, y - oB.Anchory)); } else { throw new NotImplementedException(); } }
private void drawOneLayerTile(int x1, int y1, int w, int h, Graphics g, CoordConverter oCC, int picx, int picy, int picZoom, bool tryDownloading) { Image imageToScreen = null; // get image from cache or schedule its download imageToScreen = TileImageLoaderAndCache.Instance.getImage(picx, picy, picZoom, mapType, tryDownloading); // bitmap position oCC.Convert(x1, y1); int xScr = (int)Math.Round(oCC.X); int yScr = (int)Math.Round(oCC.Y); oCC.Convert(x1 + w, y1 + h); int xScrWidth = (int)Math.Round(oCC.X - xScr); int yScrWidth = (int)Math.Round(oCC.Y - yScr); if (xScrWidth < 0) { xScrWidth = -xScrWidth; xScr = xScr - xScrWidth; } if (yScrWidth < 0) { yScrWidth = -yScrWidth; yScr = yScr - yScrWidth; } if (imageToScreen != null) { Debug.Assert(xScrWidth == 256); Debug.Assert(yScrWidth == 256); g.DrawImage(imageToScreen, xScr, yScr, xScrWidth, yScrWidth); } else { Assembly myAssembly = Assembly.GetExecutingAssembly(); Stream myStream = myAssembly.GetManifestResourceStream("hiMapNet.Resources.h0.jpeg"); if (myStream != null) { Bitmap bmp = new Bitmap(myStream); g.DrawImage(bmp, xScr, yScr, xScrWidth, yScrWidth); bmp.Dispose(); } } }
private void mapControl1_MouseClick(object sender, MouseEventArgs e) { if (mapControl1.CurrentTool == MapControl.ToolConst.InfoTool) { // get gpx coordinate (from map or from gpx table) DPoint pt; mapControl1.Map.DisplayTransform.FromDisplay(new System.Drawing.Point(e.X, e.Y), out pt); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt.X, pt.Y); lblInfo.Text = string.Format("x={0:0.00000}, y={1:0.00000} Mercator: x={2:0}, y={3:0}", occ.X, occ.Y, pt.X, pt.Y); // search for features //Feature[] fts = oLayerPointer.Search(pt); //e.X } }
void drawLayerTiles(System.Drawing.Rectangle area, int zoom, Graphics g, CoordConverter oCC, bool tryDownloading) { int tileSizePx = (1 << (8 - zoom)) * (int)zoomElevateUpscale; int maxIdx = 1 << zoom; int count = 0; for (int x = area.X; x < area.X + area.Width; x++) { for (int y = area.Y; y < area.Y + area.Height; y++) { if (count < 66 && x >= 0 && y >= 0 && x < maxIdx && y < maxIdx) { drawOneLayerTile(x * tileSizePx, y * tileSizePx, tileSizePx, tileSizePx, g, oCC, x, y, zoom, tryDownloading); } //DrawEllipse(x, y, tileSizePx, tileSizePx, g, oCC); count++; } } }
public virtual void Draw(Graphics g, Rectangle Rect, CoordConverter oCC1) { bDirty = false; }
/// <summary> /// /// </summary> /// <param name="g">Graphics na ktorym robimy rysunek w ukladzie wspolrzenych screen</param> /// <param name="Rect">Obszar ekranu do odrysowania we wsp. screen</param> /// <param name="oCC">obsolete</param> /// <param name="oCC1">converter layer->screen</param> public override void Draw(Graphics g, System.Drawing.Rectangle Rect, CoordConverter oCC) { base.Draw(g, Rect, oCC); // produce a list of needed tiles // ustal dla jakiego zoom wyswietlac bedziemy kafelki if (oCC.atMaster.IsRotating()) return; //can not display double scale = oCC.atMaster.A; //System.Diagnostics.Debug.Print("Scale={0}", scale); // scale = 1,2,4,8 int zoom = (int)Math.Log(scale * zoomElevateUpscale, 2); // ustal uklad wsp. w jakim są przechowywane kafelki // jest to inny uklad w kazdym zoomie // zoom=0 -> 0;0 - 256;256 (2^0=1) 0x100 // zoom=1 -> 0;0 - 512;512 (2^1=2) 0x200 // zoom=2 -> 0;0 - 1024;1024 (2^2=4) 0x400 // ... // zoom=17 -> 0;0 - 33554432;33554432 (2^17=131072) 0x02000000 (32bit) // zoom=18 -> // zoom=19 -> // oblicz prostokat widocznosci w ukladzie kafelkow (z Display Coordsys do Layer Coordsys) int x1, y1; oCC.ConvertInverse(Rect.X, Rect.Y); x1 = (int)oCC.X; y1 = (int)oCC.Y; int x2, y2; oCC.ConvertInverse(Rect.X + Rect.Width, Rect.Y + Rect.Height); x2 = (int)oCC.X; y2 = (int)oCC.Y; if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; } // zoom=0 -> 256 // zoom=1 -> 128 // zoom=2 -> 64 int tileSizePx = (int)Math.Round(256.0 / scale); // zoom=0 -> 256 * zoomElevate if (tileSizePx < 1) return; // okresl liste kafelkow do wyswietlenia int xx1 = (x1 / tileSizePx) * tileSizePx; int yy1 = (y1 / tileSizePx) * tileSizePx; int xx2 = (x2 / tileSizePx) * tileSizePx + tileSizePx; int yy2 = (y2 / tileSizePx) * tileSizePx + tileSizePx; int max = (int)(scale * zoomElevateUpscale); int count = 0; for (int x = xx1; x < xx2; x += tileSizePx) { for (int y = yy1; y < yy2; y += tileSizePx) { int picx = x / tileSizePx; int picy = y / tileSizePx; int picZoom = zoom; if (count < 66 && picx >= 0 && picy >= 0 && picx < max && picy < max) { DrawImageGMap(x, y, (int)(tileSizePx), (int)(tileSizePx), g, oCC, picx, picy, picZoom); } //DrawEllipse(x, y, tileSizePx, tileSizePx, g, oCC1); count++; } } }