/// <summary> /// Hides the entire grid (makes it not revealed). /// </summary> public void MakeAllHidden() { Color shadedColor = Color.FromNonPremultiplied(FogColor.R, FogColor.G, FogColor.B, FogShade); int y; for (int x = 0; x < mNumberOfXTiles; x++) { for (y = 0; y < mNumberOfYTiles; y++) { if (mFogFactor > 0) { for (int fogX = 0; fogX < mFogFactor; fogX++) { for (int fogY = 0; fogY < mFogFactor; fogY++) { shadedColor = mFogImageData.GetPixelColor(x * mFogFactor + fogX, y * mFogFactor + fogY); if (shadedColor.R > FogShade) { shadedColor.R = shadedColor.G = shadedColor.B = FogShade; } mFogImageData.SetPixel(x * mFogFactor + fogX, y * mFogFactor + fogY, shadedColor); } } } mRevealedTiles[x][y] = 0; } } }
public EOInventoryItem(PacketAPI api, int slot, ItemRecord itemData, InventoryItem itemInventoryInfo, EOInventory inventory) : base(null, null, inventory) { m_api = api; m_itemData = itemData; m_inventory = itemInventoryInfo; Slot = slot; UpdateItemLocation(Slot); m_itemgfx = GFXLoader.TextureFromResource(GFXTypes.Items, 2 * itemData.Graphic, true); m_highlightBG = new Texture2D(Game.GraphicsDevice, DrawArea.Width - 3, DrawArea.Height - 3); Color[] highlight = new Color[(drawArea.Width - 3) * (drawArea.Height - 3)]; for (int i = 0; i < highlight.Length; ++i) { highlight[i] = Color.FromNonPremultiplied(200, 200, 200, 60); } m_highlightBG.SetData(highlight); _initItemLabel(); m_recentClickTimer = new Timer( _state => { if (m_recentClickCount > 0) { Interlocked.Decrement(ref m_recentClickCount); } }, null, 0, 1000); }
public void RevealArea(int x0, int y0, int x1, int y1) { int x, fogX, fogY; Color revealedColor = Color.FromNonPremultiplied(127, 127, 127, 255); for (int y = y0; y < y1; y++) { for (x = x0; x < x1; x++) { mRevealedTiles[x][y] = 1; if (mFogFactor != 0) { for (fogY = 0; fogY < mFogFactor; fogY++) { for (fogX = 0; fogX < mFogFactor; fogX++) { mFogImageData.SetPixel((x) * mFogFactor + fogX, (y) * mFogFactor + fogY, revealedColor); } } } } } if (mFogFactor > 0 && mFogTexture != null) { mFogImageData.ToTexture2D(mFogTexture); } }
public override void Draw(GameTime gameTime) { if (!Visible) { return; } SpriteBatch.Begin(); //White @ 75% opacity background SpriteBatch.Draw(m_fill, DrawAreaWithOffset, Color.FromNonPremultiplied(0xff, 0xff, 0xff, 192)); SpriteBatch.Draw(m_bg, DrawAreaWithOffset, Color.White); if (m_overRect != null) { SpriteBatch.Draw(m_bgOver, new Vector2(m_overRect.Value.X + DrawAreaWithOffset.X, m_overRect.Value.Y + DrawAreaWithOffset.Y), m_overRect, Color.White); } SpriteBatch.End(); base.Draw(gameTime); }
public void filter(Filter kind, float param = -1f) { var p = new Color[texture.Width * texture.Height]; texture.GetData(p); switch (kind) { case Filter.THRESHOLD: if (param < 0f || param > 1f) { param = 0.5f; } p = p.AsParallel().AsOrdered() .Select(c => (grey: (int)((0.3 * c.R) + (0.59 * c.G) + (0.11 * c.B)), c.A)) .Select(t => (grey: t.grey / 255.0 < param ? 255 : 0, t.A)) .Select(t => Color.FromNonPremultiplied(t.grey, t.grey, t.grey, t.A)).ToArray(); break; case Filter.GRAY: p = p.AsParallel().AsOrdered() .Select(c => (grey: (int)((0.3 * c.R) + (0.59 * c.G) + (0.11 * c.B)), c.A)) .Select(t => Color.FromNonPremultiplied(t.grey, t.grey, t.grey, t.A)).ToArray(); break; case Filter.OPAQUE: p = p.AsParallel().AsOrdered().Select(c => Color.FromNonPremultiplied(c.R, c.G, c.B, 255)) .ToArray(); break; case Filter.INVERT: p = p.AsParallel().AsOrdered() .Select(c => Color.FromNonPremultiplied(255 - c.R, 255 - c.G, 255 - c.B, c.A)).ToArray(); break; case Filter.POSTERIZE: if (param < 2f) { param = 2f; } if (param > 255f) { param = 255f; } p = p.AsParallel().AsOrdered() .Select(c => Color.FromNonPremultiplied((int)Math.Min(c.R, param), (int)Math.Min(c.G, param), (int)Math.Min(c.B, param), c.A)).ToArray(); break; case Filter.BLUR: case Filter.ERODE: case Filter.DILATE: break; } texture.SetData(p); }
void UpdateGrid() { int cellSize = 16; int x = 0; int y = 0; RectangleF rect = RectangleF.Empty; Color c1 = Color.FromNonPremultiplied(68, 68, 68, 255); Color c2 = Color.FromNonPremultiplied(77, 77, 77, 255); bool flag = true; bool lastFlag = flag; gridSurface = Sgml.surface_create(Width, Height); Sgml.surface_set_target(gridSurface); for (var i = 0; i < Height / cellSize + 1; i++) { for (var j = 0; j < Width / cellSize + 1; j++) { if (j == 0) { lastFlag = flag; } rect.Size = new Size2(cellSize, cellSize); rect.Position = new Point2(x, y); if (flag) { Sgml.draw_set_color(c1); } else { Sgml.draw_set_color(c2); } Sgml.draw_rectangle(rect, false); x += cellSize; flag = !flag; } x = 0; y += cellSize; lastFlag = !lastFlag; flag = lastFlag; } Sgml.surface_reset_target(); }
public void update_loc(int x, int y, sbyte fgd_block) { if (y < (map.GetLength(1) * 100) - map[0, map.GetLength(1) - 1].Height) { Color[] col = new Color[1]; Rectangle r = new Rectangle(x % 100, y % 100, 1, 1); if (fgd_block < 0) { col[0] = Color.FromNonPremultiplied(0, 0, 0, 127); } else { col[0] = Exilania.block_types.blocks[fgd_block].map_represent; } map[x / 100, y / 100].SetData <Color>(0, r, col, 0, 1); } }
public override void Draw(GameTime gameTime) { if (!Visible) { return; } SpriteBatch.Begin(); if (MouseOver) { int currentSlot = ItemCurrentSlot(); Vector2 drawLoc = m_beingDragged ? new Vector2(m_oldOffX + 13 + 26 * (currentSlot % EOInventory.INVENTORY_ROW_LENGTH), m_oldOffY + 9 + 26 * (currentSlot / EOInventory.INVENTORY_ROW_LENGTH)) //recalculate the top-left point for the highlight based on the current drag position : new Vector2(DrawAreaWithOffset.X, DrawAreaWithOffset.Y); if (EOInventory.GRID_AREA.Contains(new Rectangle((int)drawLoc.X, (int)drawLoc.Y, DrawArea.Width, DrawArea.Height))) { SpriteBatch.Draw(m_highlightBG, drawLoc, Color.White); } } if (m_itemgfx != null) { SpriteBatch.Draw(m_itemgfx, new Vector2(DrawAreaWithOffset.X, DrawAreaWithOffset.Y), Color.FromNonPremultiplied(255, 255, 255, m_alpha)); } SpriteBatch.End(); base.Draw(gameTime); }
protected override void Draw() { if (parentForm != null) { ms = Mouse.GetState(); if (ttl < 10) { if (ttl == 9) { ScaleToFit(90); } ttl++; } base.Draw(); double framerate = Editor.GetFrameRate; Matrix transformMatrix = cam.Camera.GetViewMatrix(); MousePositionTranslated = cam.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); BackgroundColor = Color.Black; Editor.graphics.Clear(BackgroundColor); Input.MousePosition = MousePositionTranslated; MousePosition = new Vector2(ms.X, ms.Y); Sgml.sb = Editor.spriteBatch; Sgml.vb = vertexBuffer; Sgml.be = basicEffect; Sgml.m = transformMatrix; Sgml.currentObject = representativeGameObject; Matrix view = cam.Camera.GetViewMatrix(); Matrix projection = m; basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.VertexColorEnabled = true; Sgml.mouse = MousePositionTranslated; // Actual logic int cellSize = 16; int x = 0; int y = 0; RectangleF rect = RectangleF.Empty; Color c1 = Color.FromNonPremultiplied(68, 68, 68, 255); Color c2 = Color.FromNonPremultiplied(77, 77, 77, 255); bool flag = true; bool lastFlag = flag; cam.Camera.Origin = new Vector2(Width / 2f, Height / 2f); basicEffect.View = Matrix.Identity; Sgml.m = Matrix.Identity; Vector2 origin = Vector2.Zero; Sgml.draw_surface(origin, gridSurface); basicEffect.View = view; Sgml.m = transformMatrix; if (selectedFrame != null) { Sgml.draw_set_aa(!parentForm.drawModeOn); if (selectedFrame.layers[0].texture != null) { Sgml.draw_surface(origin, selectedFrame.layers[selectedLayer].texture); Sgml.draw_surface(origin, selectedFrame.previewLayer.texture); } Sgml.draw_set_aa(true); // draw cells int xx = 0; int yy = 0; int xIndex = 0; int yIndex = 0; RectangleF temp = RectangleF.Empty; float x1 = origin.X; float y1 = origin.Y; float x2 = x1 + (int)parentForm.darkNumericUpDown1.Value; float y2 = y1 + (int)parentForm.darkNumericUpDown2.Value; Sgml.draw_set_alpha(0.8); Sgml.draw_set_color(Color.Black); for (var i = 0; i < parentForm.darkNumericUpDown1.Value + 1; i++) { Sgml.draw_line(x1, y1 + i, x2, y1 + i); } for (var i = 0; i < parentForm.darkNumericUpDown2.Value + 1; i++) { Sgml.draw_line(x1 + i, y1, x1 + i, y2); } Sgml.draw_set_alpha(1); Sgml.draw_set_color(Color.White); Sgml.draw_set_aa(false); if (selectedFrame.layers.Count > 0) { if (selectedFrame.layers[0].texture != null) { Sgml.draw_rectangle(origin, new Vector2(selectedFrame.layers[0].texture.Width, selectedFrame.layers[0].texture.Height), true); } } } basicEffect.View = Matrix.Identity; Sgml.m = Matrix.Identity; Sgml.draw_set_color(Color.White); Sgml.draw_text(new Vector2(10, 10), framerate.ToString()); Sgml.draw_text(new Vector2(10, 30), "[X: " + Sgml.round(Sgml.mouse.X - 0.5f) + " Y: " + Sgml.round(Sgml.mouse.Y - 0.5f) + "]"); // Sgml.draw_text(new Vector2(10, 50), parentForm.darkNumericUpDown1.Value.ToString()); Sgml.draw_text(new Vector2(10, 70), cam.Zoom.ToString()); Sgml.draw_text(new Vector2(10, 90), "DIR: " + Sgml.point_direction(toolOriginSubpixel, mouseSubpixel)); Sgml.draw_text(new Vector2(10, 110), "CLICK: " + toolOriginSubpixel.X + "x " + toolOriginSubpixel.Y + "y"); } }
private void UpdateViewersLocalVisibilityGrid(IViewer viewer, ViewerInformation viewerInformation) { VisibilityGrid localGrid = viewerInformation.LocalVisibilityGrid; localGrid.MakeAllHidden(); localGrid.ClearBlockedTiles(); int viewRadius = MathFunctions.RoundToInt(viewer.WorldViewRadius / mGridSpacing); int xIndex; int yIndex; WorldToIndex(viewer.X, viewer.Y, out xIndex, out yIndex); float tileCenteredXPosition; float tileCenteredYPosition; IndexToWorld(xIndex, yIndex, out tileCenteredXPosition, out tileCenteredYPosition); viewerInformation.LastX = xIndex; viewerInformation.LastY = yIndex; localGrid.mXSeed = tileCenteredXPosition - viewer.WorldViewRadius; localGrid.mYSeed = tileCenteredYPosition - viewer.WorldViewRadius; int xOffset = MathFunctions.RoundToInt((localGrid.mXSeed - mXSeed) / mGridSpacing); int yOffset = MathFunctions.RoundToInt((localGrid.mYSeed - mYSeed) / mGridSpacing); // copy over the blocked areas to the viewer int y; int fogX, fogY; byte shadedValue; Color shadedColor; float invertedFogFactor = 1.0f; if (mFogFactor > 1) { invertedFogFactor = 1.0f / mFogFactor; } for (int x = 0; x < localGrid.mNumberOfXTiles; x++) { for (y = 0; y < localGrid.mNumberOfYTiles; y++) { localGrid.mBlockedTiles[x][y] = mBlockedTiles[x + xOffset][y + yOffset]; } } localGrid.MakeAllHidden(); localGrid.RevealCircle(viewRadius, viewRadius, viewRadius); localGrid.BleedDirectlyVisibleToWalls(); if (mFogFactor > 0) { for (int x = 0; x < localGrid.mNumberOfXTiles; x++) { for (y = 0; y < localGrid.mNumberOfYTiles; y++) { for (fogX = 0; fogX < mFogFactor; fogX++) { for (fogY = 0; fogY < mFogFactor; fogY++) { shadedColor = localGrid.mFogImageData.GetPixelColor(x * mFogFactor + fogX, y * mFogFactor + fogY); shadedValue = 0; if (localGrid.mRevealedTiles[x][y] != 0) { shadedValue = localGrid.CalculateFogColorByDistance(x + (fogX * invertedFogFactor), y + (fogY * invertedFogFactor), shadedColor.R, viewer); } else if (shadedColor.R > FogShade) { shadedValue = FogShade; } //shadedColor = Color.FromNonPremultiplied(FogColor.R, FogColor.G, FogColor.B, shadedValue); shadedColor = Color.FromNonPremultiplied(shadedValue, shadedValue, shadedValue, 255); localGrid.mFogImageData.SetPixel(x * mFogFactor + fogX, y * mFogFactor + fogY, shadedColor); } } } } } }
public MiniMap(World w, GraphicsDevice g) { map_pieces = new List <MapMarker>(); map = new Texture2D[w.map.GetLength(0) / 100, w.map.GetLength(1) / 100]; int width = 100; int height = 100; for (int x = 0; x < map.GetLength(0); x++) { for (int y = 0; y < map.GetLength(1); y++) { if (x < map.GetLength(0) - 1) { width = 100; } else { if (w.map.GetLength(0) % 100 != 0) { width = w.map.GetLength(0) % 100; } else { width = 100; } } if (y < map.GetLength(1) - 1) { height = 100; } else { if (w.map.GetLength(1) % 100 != 0) { height = w.map.GetLength(1) % 100; } else { height = 100; } } map[x, y] = new Texture2D(g, width, height); Color[] total_map = new Color[width * height]; sbyte temp_col = -1; for (int ys = 0; ys < height; ys++) { for (int xs = 0; xs < width; xs++) { temp_col = w.map[(x * 100) + xs, (y * 100) + ys].fgd_block; if (temp_col < 0) { if (w.map[(x * 100) + xs, (y * 100) + ys].liquid_id > 0) { total_map[(ys * width) + xs] = Exilania.block_types.blocks[World.liquid_blocks[w.map[(x * 100) + xs, (y * 100) + ys].liquid_id]].map_represent; } else { total_map[(ys * width) + xs] = Color.FromNonPremultiplied(0, 0, 0, 127); } } else { total_map[(ys * width) + xs] = Exilania.block_types.blocks[temp_col].map_represent; } } } map[x, y].SetData <Color>(total_map); } } }