void ResetViewport() { offset = MATRIX2x3.Identity; offset.M31 = 400; offset.M32 = 400; MATRIX2x3.Invert(ref offset, out offsetInvert); }
void ResetViewport() { offset.M11 = 1; offset.M22 = 1; offset.M31 = TBMap.Width * 0.5f; offset.M32 = TBMap.Height * 0.5f; MATRIX2x3.Invert(ref offset, out offsetInvert); }
void DrawThumbnail(UIElement sender, GRAPHICS sb, Entry e) { var box = map.BoundingBox; VECTOR2 offset; float scale; __GRAPHICS.ViewAdapt(box.Size, TBThumnail.Size, out scale, out offset); sb.Begin(MATRIX2x3.CreateTransform(0, box.X, box.Y, scale, scale, TBThumnail.X + offset.X, TBThumnail.Y + offset.Y)); foreach (var item in map.Terrains) { item.Draw(); } //VECTOR2 p1 = VECTOR2.Transform(VECTOR2.Zero, offsetInvert); //VECTOR2 p2 = VECTOR2.Transform(TBMap.Size, offsetInvert); //RECT rect = RECT.CreateRectangle(p1, p2); //__GRAPHICS.Draw(patchViewport, rect); sb.End(); }
protected override void InternalEvent(Entry e) { base.InternalEvent(e); // 切换锚点 if (e.INPUT.Keyboard.IsClick(PCKeys.Enter)) { pivot++; if (pivot == pivots.Length) { pivot = 0; } } // 空格重置视口 if (e.INPUT.Keyboard.IsClick(PCKeys.Space)) { ResetViewport(); } // 保存数据到剪切板 if (e.INPUT.Keyboard.Ctrl && e.INPUT.Keyboard.IsClick(PCKeys.S)) { Copy(); } // 创建或选中时上下左右微调 if (dragIndex != -1) { if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.A) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Left)) { dragOffset.X--; } if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.D) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Right)) { dragOffset.X++; } if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.S) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Down)) { dragOffset.Y++; } if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.W) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Up)) { dragOffset.Y--; } } //else if (Creating) //{ // if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.A) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Left)) // start.X--; // if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.D) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Right)) // start.X++; // if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.S) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Down)) // start.Y++; // if (e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.W) || e.INPUT.Keyboard.IsInputKeyPressed(PCKeys.Up)) // start.Y--; //} // 左键拖拽/生成矩形 if (TBCanvas.IsHover && e.INPUT.Pointer.IsClick(0)) { VECTOR2 position; int index = ClickIndex(out position); if (index == -1) { // 创建新矩形 start = position; } else { // 拖拽旧矩形 dragIndex = index; dragOffset = rects[dragIndex].Location; } } if (dragIndex != -1 && e.INPUT.Pointer.IsPressed(0)) { // 拖拽 rects[dragIndex] = new RECT(e.INPUT.Pointer.Position - e.INPUT.Pointer.ClickPosition + dragOffset, rects[dragIndex].Size); } if (e.INPUT.Pointer.IsRelease(0)) { if (dragIndex != -1) { // 确认拖拽 dragIndex = -1; } else if (Creating) { // 确认创建 var add = RECT.CreateRectangle(start, GetCurrentPosition()); if (add.Width >= 1 && add.Height >= 1) { rects.Add(add); } start.X = float.NaN; } } if (e.INPUT.Pointer.IsClick(1)) { if (dragIndex != -1) { // 取消拖拽 rects[dragIndex] = new RECT(e.INPUT.Pointer.ClickPosition - dragOffset, rects[dragIndex].Size); dragIndex = -1; } else if (Creating) { // 取消创建新矩形 start.X = float.NaN; } else { // 删除矩形 int index = ClickIndex(); if (index != -1) { rects.RemoveAt(index); } } } if (e.INPUT.Pointer.IsPressed(1)) { // 拖拽地图 var delta = e.INPUT.Pointer.DeltaPosition; offset.M31 += delta.X; offset.M32 += delta.Y; MATRIX2x3.Invert(ref offset, out offsetInvert); } }
protected override void InternalEvent(Entry e) { base.InternalEvent(e); // 空格重置视口 if (e.INPUT.Keyboard.IsClick(PCKeys.Space)) { ResetViewport(); } // 滑轮缩放地图 if (e.INPUT.Mouse.ScrollWheelValue != 0) { float scale = offset.M11; scale = _MATH.Clamp(scale + e.INPUT.Mouse.ScrollWheelValue * 0.1f, 0.2f, 1); offset.M11 = scale; offset.M22 = scale; MATRIX2x3.Invert(ref offset, out offsetInvert); } if (e.INPUT.Pointer.IsPressed(1)) { // 拖拽地图 var delta = e.INPUT.Pointer.DeltaPosition; offset.M31 += delta.X; offset.M32 += delta.Y; MATRIX2x3.Invert(ref offset, out offsetInvert); } if (e.INPUT.Keyboard.Ctrl && e.INPUT.Keyboard.IsClick(PCKeys.A)) { NewMap(); } VECTOR2 position = GetCurrentPosition(); painting.X = (int)position.X; painting.Y = (int)position.Y; int index = -1; for (int i = 0; i < map.Terrains.Count; i++) { if (map.Terrains[i].X == position.X && map.Terrains[i].Y == position.Y) { index = i; break; } } if (e.INPUT.Pointer.IsTap(1)) { // 右键删除地形 if (index != -1) { map.Terrains.RemoveAt(index); } // 右键取消绘制 else { painting.ID = 0; } } // 左键刷地形 if (e.INPUT.Pointer.IsClick(0)) { if (painting.ID == 0) { // 拿起之前绘制的地形变成笔刷 if (index != -1) { painting.ID = map.Terrains[index].ID; painting.Data = map.Terrains[index].Data; painting.Texture = map.Terrains[index].Texture; } } } if (e.INPUT.Pointer.IsPressed(0)) { if (e.INPUT.Keyboard.Alt) { // Alt + 左键删除地形 if (index != -1) { map.Terrains.RemoveAt(index); } } else if (painting.ID != 0 && TBMap.IsHover) { RECT rect = painting.Area; if (!map.Terrains.Any(t => t.Area.Intersects(rect))) { // 刷地形 TERRAIN terrain = new TERRAIN(); terrain.ID = painting.ID; terrain.X = painting.X; terrain.Y = painting.Y; terrain.Data = painting.Data; terrain.Texture = painting.Texture; map.Terrains.Add(terrain); } } } if (e.INPUT.Keyboard.IsClick(PCKeys.D1)) { // 1修改锁定信息 if (index != -1) { int value = (int)map.Terrains[index].Lock + 1; if (value > 2) { value = 0; } map.Terrains[index].Lock = (ELockMode)value; } } else if (e.INPUT.Keyboard.IsClick(PCKeys.D2)) { } else if (e.INPUT.Keyboard.IsClick(PCKeys.D3)) { // 3修改显示额外信息 display = !display; } // 保存地图 if (e.INPUT.Keyboard.Ctrl && e.INPUT.Keyboard.IsClick(PCKeys.S)) { if (e.INPUT.Keyboard.Shift || string.IsNullOrEmpty(mapFile)) { _IO._iO.FileBrowserSave("NewMap", new string[] { MAP.FILE.Substring(1) }, file => { mapFile = Path.GetFileNameWithoutExtension(file.File); MAP.Save(mapFile, map.Terrains); }); } else { MAP.Save(mapFile, map.Terrains); } } }