private void GLSurface_GLMouseDown(object sender, GLMouseEventArgs e) { try { MouseManager.BeginDrag(e.Location); if (e.Button.HasFlag(MouseButtons.Left)) { int tx = (int)Math.Round(-OffsetX + e.X + GLSurface.FieldW / 2 - 0.5); int ty = (int)Math.Round(-OffsetY + e.Y + GLSurface.FieldH / 2 - 0.5); if (GLSurface.GetTile(tx, ty) == null) { GLSurface.PlaceTile(TileComboBox.SelectedIndex <= 0 ? TileName : (string)TileComboBox.SelectedItem, tx, ty); MouseState = MouseStatus.Placing; } else { GLSurface.PlaceTile(null, tx, ty); MouseState = MouseStatus.Removing; } } } catch (Exception ex) { MessageBox.Show(this, ex.ToString(), "Error: Can not handle MouseDown event.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void GLSurface_DragDrop(object sender, DragEventArgs e) { try { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { return; } var paths = e.Data.GetData(DataFormats.FileDrop) as string[]; if (paths.Length != 1 || Resource.GetType(paths[0]) != ResourceType.Tile) { return; } var path = ExtraPath.MakeDirectoryRelated(Directory.GetCurrentDirectory(), paths[0]); bool insert = !GLSurface.TileLoaded(path); if (GLSurface.LoadTile(path, path)) { if (insert) { TileComboBox.Items.Add(path); } var pos = GLSurface.AdjustMouse(GLSurface.PointToClient(new Point(e.X, e.Y))); MouseManager.UpdateLocation(pos); int tx = (int)Math.Round(-OffsetX + pos.X + GLSurface.FieldW / 2 - 0.5); int ty = (int)Math.Round(-OffsetY + pos.Y + GLSurface.FieldH / 2 - 0.5); if (GLSurface.GetTile(tx, ty) == null) { GLSurface.PlaceTile(path, tx, ty); } else { GLSurface.PlaceTile(null, tx, ty); } TileComboBox.SelectedItem = path; } } catch (Exception ex) { MessageBox.Show(this, ex.ToString(), "Error: Can not place tile.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }