Esempio n. 1
0
        private static void Centering()
        {
            // ペイントの中央揃え
            using (var process = Process.GetProcessesByName("mspaint").FirstOrDefault())
            {
                if (process == null)
                {
                    Console.WriteLine($"No process.");
                    return;
                }
                var windowHandle = process.MainWindowHandle;

                var clientPoint = new NetCoreEx.Geometry.Point(0, 0);
                User32Methods.GetClientRect(windowHandle, out var clientRect);
                User32Methods.ClientToScreen(windowHandle, ref clientPoint);
                Console.WriteLine($"clientRect: {clientRect.ToString()}");
                Console.WriteLine($"clientPoint: {clientPoint.ToString()}");

                var screen = Screen.PrimaryScreen;
                Console.WriteLine($"PrimaryScreen: {screen.Bounds.ToString()}");
                // 小数点以下は切り捨て
                var x = (screen.Bounds.Width - clientRect.Width) / 2;
                var y = (screen.Bounds.Height - clientRect.Height) / 2;
                Console.WriteLine($"Move to ({x}, {y})");

                // Move Window
                User32Methods.MoveWindow(windowHandle, x, y, clientRect.Width, clientRect.Height, true);
            }
        }
Esempio n. 2
0
        protected override void OnMouseWheel(ref MouseWheelPacket packet)
        {
            Point mousePosition = ScreenToClient(packet.Point);

            var positionWorld = new Vector2(mousePosition.X / zoom - translation.X,
                                            mousePosition.Y / zoom - translation.Y);

            if (packet.WheelDelta > 0)
            {
                float z = zoom * zoomFactor;

                if (z <= maxZoom)
                {
                    zoom        = z;
                    translation = new Vector2((translation.X - (positionWorld.X * zoomFactor - positionWorld.X)) / zoomFactor, (translation.Y - (positionWorld.Y * zoomFactor - positionWorld.Y)) / zoomFactor);
                }
            }
            else
            {
                float z = zoom / zoomFactor;

                if (z >= minZoom)
                {
                    zoom        = z;
                    translation = new Vector2((translation.X + (positionWorld.X - (positionWorld.X / zoomFactor))) * zoomFactor, (translation.Y + (positionWorld.Y - (positionWorld.Y / zoomFactor))) * zoomFactor);
                }
            }

            UpdateTransformation();
        }
Esempio n. 3
0
        private Point ScreenToClient(Point point)
        {
            var client = new Rectangle();

            User32Methods.AdjustWindowRectEx(ref client, GetStyles(), User32Methods.GetMenu(Handle) != IntPtr.Zero,
                                             GetExStyles());
            GetWindowRect(out Rectangle window);

            return(new Point(point.X - window.Left + client.Left, point.Y - window.Top + client.Top));
        }
Esempio n. 4
0
        protected void OnLeftMouseButtonUp(Point point)
        {
            if (isWireForced)
            {
                if (!User32Methods.GetKeyState(VirtualKey.SHIFT).IsPressed)
                {
                    circuitBoard.UnforceWireAt(forcedWireX, forcedWireY);
                }

                isWireForced = false;
            }
        }
Esempio n. 5
0
        protected override void OnMouseMove(ref MousePacket packet)
        {
            if (isRightMouseButtonDown)
            {
                Point mousePosition = packet.Point;

                float diffX = mousePosition.X - lastMousePosition.X;
                float diffY = mousePosition.Y - lastMousePosition.Y;

                translation = new Vector2(translation.X + diffX / zoom, translation.Y + diffY / zoom);

                lastMousePosition = mousePosition;
                UpdateTransformation();
            }
        }
Esempio n. 6
0
        protected void OnLeftMouseButtonDown(Point point)
        {
            Image image = circuitBoard.Image;

            float width  = image.Width;
            float height = image.Height;

            float x = point.X / zoom - translation.X + width / 2f;
            float y = point.Y / zoom - translation.Y + height / 2f;

            if (x >= 0 && x < width && y >= 0 && y < height)
            {
                circuitBoard.ForceWireAt((int)x, (int)y);
                isWireForced = true;
                forcedWireX  = (int)x;
                forcedWireY  = (int)y;
            }
        }
Esempio n. 7
0
 protected void OnRightMouseButtonUp(Point point)
 {
     isRightMouseButtonDown = false;
     User32Methods.ReleaseCapture();
 }
Esempio n. 8
0
 protected void OnRightMouseButtonDown(Point point)
 {
     isRightMouseButtonDown = true;
     lastMousePosition      = point;
     User32Methods.SetCapture(Handle);
 }