예제 #1
0
        private VectorInt2 GetDragDropOffset(DragEventArgs drgevent)
        {
            var newPos = FromVisualCoord(PointToClient(new Point(drgevent.X, drgevent.Y)));
            var result = newPos - _insertionDropPosition;

            return(VectorInt2.FromRounded(result));
        }
예제 #2
0
        private bool UpdateRoomPosition(Vector2 newRoomPos, Room roomReference, bool moveRooms)
        {
            VectorInt2 newRoomPosInt = VectorInt2.FromRounded(newRoomPos);
            VectorInt2 roomMovement  = newRoomPosInt - roomReference.SectorPos;

            if (roomMovement != new VectorInt2())
            {
                if (EditorActions.CheckForLockedRooms(this, _roomsToMove))
                {
                    _roomMouseClicked = null;
                }
                else
                {
                    var delta = new VectorInt3(roomMovement.X, 0, roomMovement.Y);

                    if (roomMovement.X != 0 || roomMovement.Y != 0)
                    {
                        _overallDelta += delta;
                        if (moveRooms)
                        {
                            EditorActions.MoveRooms(delta, _roomsToMove, true);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #3
0
 public Space2DMapContextMenu(Editor editor, IWin32Window owner, Vector2 position)
     : base(editor, owner)
 {
     Items.Add(new ToolStripMenuItem("Paste rooms", Properties.Resources.general_clipboard_16, (o, e) =>
     {
         var roomClipboardData = Clipboard.GetDataObject().GetData(typeof(RoomClipboardData)) as RoomClipboardData;
         if (roomClipboardData == null)
         {
             _editor.SendMessage("Clipboard contains no room data.", PopupType.Error);
         }
         else
         {
             roomClipboardData.MergeInto(_editor, VectorInt2.FromRounded(position - roomClipboardData.DropPosition));
         }
     })
     {
         Enabled = Clipboard.ContainsData(typeof(RoomClipboardData).FullName)
     });
 }
예제 #4
0
        public VectorInt3 GetForTriangle(TextureArea texture)
        {
            const int MaxDirectImageArea = 256 * 256;   // @FIXME: why the hell it was 196 * 196 before?

            // @FIXME: MaxDirectImageArea GREATER comparison against image size area made no sense,
            // so I changed it to LESS-OR-EQUAL. Addressed to TRTomb. -- Lwmte

            VectorInt2 imageSize = texture.Texture.Image.Size;

            if ((imageSize.X * imageSize.Y) <= MaxDirectImageArea &&
                Size.X >= imageSize.X && Size.Y >= imageSize.Y)
            { // If the image is small enough, allocate the entire image...
                VectorInt3 allocatedTexture = Get(new RenderingTexture
                {
                    From  = new VectorInt2(),
                    To    = imageSize,
                    Image = texture.Texture.Image
                });
                return(allocatedTexture);
            }
            else
            { // Allocate a part of the image...
              // @FIXME: replace origRect calculation with commented line when bug with texture allocator atlas
              // corruption is fixed. Addressed to TRTomb. -- Lwmte

                // var origRect = texture.ParentArea.IsZero ? texture.GetRect(true).Round() : texture.ParentArea.Round();
                var origRect = texture.GetRect(true).Round();

                VectorInt3 allocatedTexture = Get(new RenderingTexture
                {
                    From  = VectorInt2.FromRounded(origRect.Start),
                    To    = VectorInt2.FromRounded(origRect.End),
                    Image = texture.Texture.Image
                });

                return(allocatedTexture - new VectorInt3((int)origRect.Start.X, (int)origRect.Start.Y, 0));
            }
        }
예제 #5
0
        public SelectedRoomContextMenu(Editor editor, IWin32Window owner, Vector2 position)
            : base(editor, owner)
        {
            Items.Add(new ToolStripMenuItem("Export rooms...", Properties.Resources.general_Export_16, (o, e) =>
            {
                EditorActions.ExportRooms(_editor.SelectedRooms, this);
            }));

            Items.Add(new ToolStripSeparator());

            Items.Add(new ToolStripMenuItem("Delete rooms", Properties.Resources.general_trash_16, (o, e) =>
            {
                EditorActions.DeleteRooms(_editor.SelectedRooms, this);
            }));

            Items.Add(new ToolStripMenuItem("Copy rooms", Properties.Resources.general_copy_16, (o, e) =>
            {
                Clipboard.SetDataObject(new RoomClipboardData(_editor, position), true);
            }));

            Items.Add(new ToolStripMenuItem("Paste rooms", Properties.Resources.general_clipboard_16, (o, e) =>
            {
                var roomClipboardData = Clipboard.GetDataObject().GetData(typeof(RoomClipboardData)) as RoomClipboardData;
                if (roomClipboardData == null)
                {
                    _editor.SendMessage("Clipboard contains no room data.", PopupType.Error);
                }
                else
                {
                    roomClipboardData.MergeInto(_editor, VectorInt2.FromRounded(position - roomClipboardData.DropPosition));
                }
            })
            {
                Enabled = Clipboard.ContainsData(typeof(RoomClipboardData).FullName)
            });

            Items.Add(new ToolStripSeparator());

            Items.Add(new ToolStripMenuItem("Rotate rooms clockwise", null, (o, e) =>
            {
                EditorActions.TransformRooms(new RectTransformation {
                    QuadrantRotation = -1
                }, Parent);
            }));

            Items.Add(new ToolStripMenuItem("Rotate rooms counterclockwise", null, (o, e) =>
            {
                EditorActions.TransformRooms(new RectTransformation {
                    QuadrantRotation = 1
                }, Parent);
            }));

            Items.Add(new ToolStripMenuItem("Mirror rooms on X axis", null, (o, e) =>
            {
                EditorActions.TransformRooms(new RectTransformation {
                    MirrorX = true
                }, Parent);
            }));

            Items.Add(new ToolStripMenuItem("Mirror rooms on Z axis", null, (o, e) =>
            {
                EditorActions.TransformRooms(new RectTransformation {
                    MirrorX = true, QuadrantRotation = 2
                }, Parent);
            }));

            Items.Add(new ToolStripMenuItem("Merge rooms horizontally", null, (o, e) =>
            {
                EditorActions.MergeRoomsHorizontally(_editor.SelectedRooms, Parent);
            }));
        }
예제 #6
0
        public void RenderText(IEnumerable <Text> texts)
        {
            // Collect actual glyphs to render
            var glyphRenderInfos  = new List <RenderingFont.GlyphRenderInfo>();
            var overlayRectangles = new List <RectangleInt2>();
            RenderingTextureAllocator textureAllocator = null;

            foreach (Text text in texts)
            {
                // Build glyphs using the right font
                Vector2 pixelPos = text.PixelPos + text.Pos * Size * 0.5f;
                pixelPos += (text.ScreenAlignment * 2 - new Vector2(1)) * Size * new Vector2(0.5f, -0.5f);
                RectangleInt2 rect = text.Font.ParseString(text.String, text.Overlay, glyphRenderInfos, VectorInt2.FromRounded(pixelPos), text.TextAlignment);
                if (rect != RectangleInt2.Zero)
                {
                    overlayRectangles.Add(rect);
                }

                // Check texture allocator
                if (textureAllocator == null)
                {
                    textureAllocator = text.Font.TextureAllocator;
                }
                else if (textureAllocator != text.Font.TextureAllocator)
                {
                    throw new ArgumentException("Texts are using different texture allocators. This is not allowed in a single 'RenderText' call.");
                }
            }
            if (glyphRenderInfos.Count == 0)
            {
                return;
            }
            RenderGlyphs(textureAllocator, glyphRenderInfos, overlayRectangles);
        }
예제 #7
0
        public override unsafe void RenderGlyphs(RenderingTextureAllocator textureAllocator, List <RenderingFont.GlyphRenderInfo> glyphRenderInfos, List <RectangleInt2> overlays)
        {
            Vector2 posScaling     = new Vector2(1.0f) / (Size / 2); // Divide the integer coordinates to avoid pixel mishmash.
            Vector2 posOffset      = VectorInt2.FromRounded(posScaling * 0.5f);
            Vector2 textureScaling = new Vector2(16777216.0f) / new Vector2(textureAllocator.Size.X, textureAllocator.Size.Y);

            // Build vertex buffer
            int vertexCount = glyphRenderInfos.Count * 6 + overlays.Count * 6;
            int bufferSize  = vertexCount * (sizeof(Vector2) + sizeof(ulong));

            fixed(byte *data = new byte[bufferSize])
            {
                Vector2 *positions = (Vector2 *)(data);
                ulong *  uvws      = (ulong *)(data + vertexCount * sizeof(Vector2));

                // Setup vertices
                int c = 0;

                for (int i = 0; i < overlays.Count; ++i, ++c)
                {
                    var     overlay  = overlays[i];
                    Vector2 posStart = overlay.Start * posScaling + posOffset;
                    Vector2 posEnd   = (overlay.End - new Vector2(1)) * posScaling + posOffset;

                    positions[c * 6 + 0] = new Vector2(posStart.X, posStart.Y);
                    positions[c * 6 + 2] = positions[c * 6 + 3] = new Vector2(posEnd.X, posStart.Y);
                    positions[c * 6 + 1] = positions[c * 6 + 4] = new Vector2(posStart.X, posEnd.Y);
                    positions[c * 6 + 5] = new Vector2(posEnd.X, posEnd.Y);

                    uvws[c * 6 + 2]         = uvws[c * 6 + 3] =
                        uvws[c * 6 + 1]     = uvws[c * 6 + 4] =
                            uvws[c * 6 + 5] = uvws[c * 6 + 0] = Dx11RenderingDevice.CompressUvw(VectorInt3.Zero, Vector2.Zero, Vector2.Zero, 1);
                }

                for (int i = 0; i < glyphRenderInfos.Count; ++i, ++c)
                {
                    RenderingFont.GlyphRenderInfo info = glyphRenderInfos[i];
                    Vector2 posStart = info.PosStart * posScaling + posOffset;
                    Vector2 posEnd   = (info.PosEnd - new Vector2(1)) * posScaling + posOffset;

                    positions[c * 6 + 0] = new Vector2(posStart.X, posStart.Y);
                    positions[c * 6 + 2] = positions[c * 6 + 3] = new Vector2(posEnd.X, posStart.Y);
                    positions[c * 6 + 1] = positions[c * 6 + 4] = new Vector2(posStart.X, posEnd.Y);
                    positions[c * 6 + 5] = new Vector2(posEnd.X, posEnd.Y);

                    uvws[c * 6 + 0] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(0.5f, 0.5f));
                    uvws[c * 6 + 2] = uvws[c * 6 + 3] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(info.TexSize.X - 0.5f, 0.5f));
                    uvws[c * 6 + 1] = uvws[c * 6 + 4] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(0.5f, info.TexSize.Y - 0.5f));
                    uvws[c * 6 + 5] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(info.TexSize.X - 0.5f, info.TexSize.Y - 0.5f));
                }

                // Create GPU resources
                using (var VertexBuffer = new Buffer(Device.Device, new IntPtr(data),
                                                     new BufferDescription(bufferSize, ResourceUsage.Immutable, BindFlags.VertexBuffer,
                                                                           CpuAccessFlags.None, ResourceOptionFlags.None, 0)))
                {
                    var VertexBufferBindings = new VertexBufferBinding[] {
                        new VertexBufferBinding(VertexBuffer, sizeof(Vector2), (int)((byte *)positions - data)),
                        new VertexBufferBinding(VertexBuffer, sizeof(ulong), (int)((byte *)uvws - data))
                    };

                    // Render
                    Bind();
                    Device.TextShader.Apply(Device.Context);
                    Device.Context.PixelShader.SetSampler(0, Device.SamplerDefault);
                    Device.Context.PixelShader.SetShaderResources(0, ((Dx11RenderingTextureAllocator)(textureAllocator)).TextureView);
                    Device.Context.InputAssembler.SetVertexBuffers(0, VertexBufferBindings);
                    Device.Context.OutputMerger.SetDepthStencilState(Device.DepthStencilNoZBuffer);

                    // Render
                    Device.Context.Draw(vertexCount, 0);

                    // Reset state
                    Device.Context.OutputMerger.SetDepthStencilState(Device.DepthStencilDefault);
                }
            }
        }