public override void Draw(BrightIdeasSoftware.ObjectListView olv, Graphics g, Rectangle r) { Rectangle cellBounds = this.CellBounds; CellBounds.Inflate(-this.CellPadding.Width, -this.CellPadding.Width); //Does what? Rectangle textBounds = cellBounds; // Draw title using (StringFormat format = new StringFormat(StringFormatFlags.NoWrap)) { format.Trimming = StringTrimming.EllipsisCharacter; //Text is trimmed to the nearest character and ... appended format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; using (SolidBrush b = new SolidBrush(this.TitleColor)) { g.DrawString(this.Title, this.TitleFont, b, textBounds, format); } // Draw description SizeF size = g.MeasureString(this.Title, this.TitleFont, (int)textBounds.Width, format); textBounds.Y += (int)size.Height; textBounds.Height -= (int)size.Height; } // Draw description using (StringFormat format2 = new StringFormat()) { format2.Trimming = StringTrimming.EllipsisCharacter; using (SolidBrush b = new SolidBrush(this.DescriptionColor)) { g.DrawString(this.Description, this.DescriptionFont, b, textBounds, format2); } } }
public bool Intersects(CellBounds other) { if (TopLeft.Column >= other.BottomRight.Column || other.TopLeft.Column >= BottomRight.Column) { return(false); } if (TopLeft.Line >= other.BottomRight.Line || other.TopLeft.Line >= BottomRight.Line) { return(false); } return(true); }
void HandleMouseUp(object sender, MouseButtonEventArgs e) { if (enabledEvents.HasFlag(WidgetEvent.ButtonReleased)) { var a = e.ToXwtButtonArgs(sender as FrameworkElement); Load(sender as FrameworkElement); if (!CellBounds.Contains(a.X, a.Y)) { return; } SetCurrentEventRow(); ApplicationContext.InvokeUserCode(delegate { EventSink.OnButtonReleased(a); }); if (a.Handled) { e.Handled = true; } } }
void HandleMouseMove(object sender, MouseEventArgs e) { if (enabledEvents.HasFlag(WidgetEvent.MouseMoved)) { var p = e.GetPosition(sender as FrameworkElement); Load(sender as FrameworkElement); if (!CellBounds.Contains(p.X, p.Y)) { return; } var a = new MouseMovedEventArgs(e.Timestamp, p.X, p.Y); SetCurrentEventRow(); ApplicationContext.InvokeUserCode(delegate { EventSink.OnMouseMoved(a); }); if (a.Handled) { e.Handled = true; } } }
private void Start() { Vector3 topLeftScreen = Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, Camera.main.transform.position.y)); Vector3 gridExtents = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, Camera.main.transform.position.y)); Vector2 cellSize = new Vector2((gridExtents.x - topLeftScreen.x) / (cellsMultiplier - 2), (topLeftScreen.z - gridExtents.z) / (cellsMultiplier - 2)); float2 gridPosition = new float2 { x = topLeftScreen.x - cellSize.x, y = topLeftScreen.z + cellSize.y }; // Cursor.lockState = CursorLockMode.Locked; EntityManager entityManager = World.Active.EntityManager; // Cell EntityArchetype entityArcheType = entityManager.CreateArchetype( typeof(CellBounds), typeof(Units), typeof(NeighboringCells) ); int totalCells = cellsMultiplier * cellsMultiplier; // Array of all the cells in the grid NativeArray <Entity> cells = new NativeArray <Entity>(totalCells, Allocator.Temp); entityManager.CreateEntity(entityArcheType, cells); for (int i = 0; i < cells.Length; i++) { Entity cell = cells[i]; // Calculate the bounds of the current cell CellBounds cellBounds = new CellBounds { minX = gridPosition.x + (cellSize.x * (i % cellsMultiplier)), maxX = gridPosition.x + (cellSize.x * (i % cellsMultiplier)) + cellSize.x, minZ = gridPosition.y - (cellSize.y * (math.floor(i / cellsMultiplier))), maxZ = gridPosition.y - (cellSize.y * (math.floor(i / cellsMultiplier))) - cellSize.y }; entityManager.SetComponentData(cell, cellBounds); entityManager.AddBuffer <Units>(cell); entityManager.AddBuffer <NeighboringCells>(cell); Debug.DrawLine(new Vector3(cellBounds.minX, 0, cellBounds.minZ), new Vector3(cellBounds.maxX, 0, cellBounds.minZ), Color.red, Mathf.Infinity); Debug.DrawLine(new Vector3(cellBounds.maxX, 0, cellBounds.minZ), new Vector3(cellBounds.maxX, 0, cellBounds.maxZ), Color.red, Mathf.Infinity); Debug.DrawLine(new Vector3(cellBounds.minX, 0, cellBounds.maxZ), new Vector3(cellBounds.maxX, 0, cellBounds.maxZ), Color.red, Mathf.Infinity); Debug.DrawLine(new Vector3(cellBounds.minX, 0, cellBounds.minZ), new Vector3(cellBounds.minX, 0, cellBounds.maxZ), Color.red, Mathf.Infinity); } // Create an array of the cell bounds. This is so we can calculate the neighboring cells to each cell EntityQuery entityQuery = entityManager.CreateEntityQuery(ComponentType.ReadOnly <CellBounds>()); NativeArray <CellBounds> cellBoundsArray = entityQuery.ToComponentDataArray <CellBounds>(Allocator.TempJob); // Loop through all the cells to assign their neighboring cells for (int i = 0; i < cells.Length; i++) { // Extract the neighboring cells buffer from the current cell Entity cell = cells[i]; DynamicBuffer <NeighboringCells> neighboringCellsBuffer = entityManager.GetBuffer <NeighboringCells>(cell); int cellIndex = i - (cellsMultiplier + 1); // Upper left neighbor if (cellIndex > -1 && cellBoundsArray[cellIndex].maxX == cellBoundsArray[i].minX) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } // Upper neighbor cellIndex = i - cellsMultiplier; if (cellIndex > -1) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } // Upper right neighbor cellIndex = i - (cellsMultiplier - 1); if (cellIndex > -1 && cellBoundsArray[cellIndex].minX == cellBoundsArray[i].maxX) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } // Left neighbor cellIndex = i - 1; if (cellIndex > -1 && cellBoundsArray[cellIndex].maxX == cellBoundsArray[i].minX) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } // Right neighbor cellIndex = i + 1; if (cellIndex <= totalCells - 1 && cellBoundsArray[i].maxX == cellBoundsArray[cellIndex].minX) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } // Lower left neighbor cellIndex = i + (cellsMultiplier - 1); if (cellIndex <= totalCells - 1 && cellBoundsArray[i].minX == cellBoundsArray[cellIndex].maxX) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } // Lower neighbor cellIndex = i + cellsMultiplier; if (cellIndex <= totalCells - 1) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } // Lower right neighbor cellIndex = i + (cellsMultiplier + 1); if (cellIndex <= totalCells - 1 && cellBoundsArray[i].maxX == cellBoundsArray[cellIndex].minX) { neighboringCellsBuffer.Add(new NeighboringCells { value = cellIndex }); } } cellBoundsArray.Dispose(); cells.Dispose(); // Player entityArcheType = entityManager.CreateArchetype( typeof(Player), typeof(Translation), typeof(RenderMesh), typeof(LocalToWorld), typeof(Rotation), typeof(Velocity), typeof(Rotate), typeof(RotateSpeed), typeof(Size), typeof(CellIndex) ); Entity player = entityManager.CreateEntity(entityArcheType); entityManager.SetSharedComponentData(player, new RenderMesh { mesh = playerMesh, material = material }); entityManager.SetComponentData(player, new Translation { Value = new float3 { x = 0, y = 0, z = 0 } }); entityManager.SetComponentData(player, new Size { value = new float3 { x = 1, y = 1, z = 1 } }); entityManager.SetComponentData(player, new RotateSpeed { value = 0.05f }); entityManager.SetComponentData(player, new CellIndex { value = -1 }); // Bullet entityArcheType = entityManager.CreateArchetype( typeof(Bullet), typeof(Translation), typeof(RenderMesh), typeof(LocalToWorld), typeof(Velocity), typeof(Scale), typeof(Size), typeof(Disabled), typeof(CellIndex) ); NativeArray <Entity> bulletsArray = new NativeArray <Entity>(22, Allocator.Temp); entityManager.CreateEntity(entityArcheType, bulletsArray); for (int i = 0; i < bulletsArray.Length; i++) { Entity bullet = bulletsArray[i]; entityManager.SetSharedComponentData(bullet, new RenderMesh { mesh = bulletMesh, material = material }); entityManager.SetComponentData(bullet, new Scale { Value = 0.1f }); entityManager.SetComponentData(bullet, new Size { value = new float3 { x = 0.1f, y = 0.1f, z = 0.1f } }); entityManager.SetComponentData(bullet, new CellIndex { value = -1 }); } bulletsArray.Dispose(); // Enemy entityArcheType = entityManager.CreateArchetype( typeof(Enemy), typeof(Translation), typeof(RenderMesh), typeof(LocalToWorld), typeof(Rotation), typeof(Velocity), typeof(Size), typeof(Disabled), typeof(CellIndex) ); NativeArray <Entity> enemiesArray = new NativeArray <Entity>(1000, Allocator.Temp); entityManager.CreateEntity(entityArcheType, enemiesArray); float2 extents = new float2 { x = gridExtents.x + (cellSize.x * 0.5f), y = math.abs(gridExtents.z) + (cellSize.y * 0.5f) }; for (int i = 0; i < enemiesArray.Length; i++) { Entity enemy = enemiesArray[i]; entityManager.SetSharedComponentData(enemy, new RenderMesh { mesh = enemyMesh, material = material }); entityManager.SetComponentData(enemy, new Size { value = new float3 { x = 1, y = 1, z = 1 } }); entityManager.SetComponentData(enemy, new CellIndex { value = -1 }); entityManager.SetComponentData(enemy, new Translation { Value = GetEnemyPosition(extents) }); } enemiesArray.Dispose(); }