private void CompositionTarget_Rendering(object sender, EventArgs e) { RenderingEventArgs args = (RenderingEventArgs)e; if (_lastRender != args.RenderingTime) { SetSize(); if (CurrentTileset != null && !string.IsNullOrEmpty(CurrentTileset.SpritePath)) { TexData spr = LoadImage(CurrentTileset.SpritePath); DX_Article[] articles = new DX_Article[3]; int articles_count = 0; int tile_span = spr.image.Width / CurrentTileset.TileWidth; if (spr.image.Width % CurrentTileset.TileWidth != 0) { tile_span++; } int tile_depth = spr.image.Height / CurrentTileset.TileHeight; if (spr.image.Height % CurrentTileset.TileHeight != 0) { tile_depth++; } int lines_count = tile_span + tile_depth; DX_Line[] lines = new DX_Line[lines_count]; for (int i = 0; i < tile_span; i++) { lines[i] = new DX_Line( new Point(i * CurrentTileset.TileWidth, 0), new Point(i * CurrentTileset.TileWidth, spr.image.Height), 1, -1, WhiteBrush); } for (int i = 0; i < tile_depth; i++) { lines[tile_span + i] = new DX_Line( new Point(0, i * CurrentTileset.TileHeight), new Point(spr.image.Width, i * CurrentTileset.TileHeight), 1, -1, WhiteBrush); } articles[articles_count++] = new DX_Article(spr.texture, new Point(0, 0), new Point(1, 1), 0); var selected_x = (TilesetEditor.Instance.SelectedTile) % tile_span; var selected_y = (TilesetEditor.Instance.SelectedTile) / tile_span; articles[articles_count++] = new DX_Article(LoadedImages["roaam_zone"].texture, new Point(selected_x * CurrentTileset.TileWidth, selected_y * CurrentTileset.TileHeight), new Point(CurrentTileset.TileWidth, CurrentTileset.TileHeight), -1, unchecked ((int)0xAAFF8000)); var mousePos = Mouse.GetPosition(this); if (new Rect(0, 0, ActualWidth, ActualHeight).Contains(mousePos)) { int highlight_x = (int)((mousePos.X / (HwndControl.ActualWidth / spr.image.Width)) / CurrentTileset.TileWidth); int highlight_y = (int)((mousePos.Y / (HwndControl.ActualHeight / spr.image.Height)) / CurrentTileset.TileHeight); articles[articles_count++] = new DX_Article(LoadedImages["roaam_zone"].texture, new Point(highlight_x * CurrentTileset.TileWidth, highlight_y * CurrentTileset.TileHeight), new Point(CurrentTileset.TileWidth, CurrentTileset.TileHeight), -2, unchecked ((int)0xAAFFFFFF)); } WindowAPI.PrepareForRender(renderer); WindowAPI.SetCameraTransform(renderer, new Point(0, 0), (float)(HwndControl.ActualWidth / spr.image.Width)); WindowAPI.Render(renderer, articles, articles_count, lines, lines_count, null, 0); if (Mouse.LeftButton == MouseButtonState.Pressed) { var pos = GetMousePos(); if (pos != null) { TilesetEditor.Instance.SelectedTile = pos.Item1 + pos.Item2 * tile_span; } } } _lastRender = args.RenderingTime; } }