logo
down
shadow

How to move circle with mouse in delphi?


How to move circle with mouse in delphi?

By : user3851750
Date : October 15 2020, 11:12 PM
it helps some times Be sure to convert the Mouse X,Y client coordinates that you get from MouseMove on your Control to the Parent's client using ClientToScreen and ScreenToClient.
The following procedure moves the center of a Control to the point (X,Y) in it's client coordinates:
code :


Share : facebook icon twitter icon
Make circle and then move circle on mouse dragged event

Make circle and then move circle on mouse dragged event


By : Enrique
Date : March 29 2020, 07:55 AM
it helps some times How to draw circle on mouse dragged event, and then how to move that circle on mouse dragged event in Java? , Something along those lines works nicely for me:
code :
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Ellipse2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

class DragCircle extends JPanel {

    private final class MouseDrag extends MouseAdapter {
        private boolean dragging = false;
        private Point last;

        @Override
        public void mousePressed(MouseEvent m) {
            last = m.getPoint();
            dragging = isInsideEllipse(last);
            if (!dragging) {
                x = last.x;
                y = last.y;
                width = 0;
                height = 0;
            }
            repaint();
        }

        @Override
        public void mouseReleased(MouseEvent m) {
            last = null;
            dragging = false;
            repaint();
        }

        @Override
        public void mouseDragged(MouseEvent m) {
            int dx = m.getX() - last.x;
            int dy = m.getY() - last.y;
            if (dragging) {
                x += dx;
                y += dy;
            } else {
                width += dx;
                height += dy;
            }
            last = m.getPoint();
            repaint();
        }
    }

    private int x;
    private int y;
    private int width;
    private int height;

    private MouseDrag mouseDrag;

    public DragCircle() {
        setBackground(Color.WHITE);
        mouseDrag = new MouseDrag();
        addMouseListener(mouseDrag);
        addMouseMotionListener(mouseDrag);
    }

    public boolean isInsideEllipse(Point point) {
        return new Ellipse2D.Float(x, y, width, height).contains(point);
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawOval(x, y, width, height);
    }

    public static void main(String[] args) {
        JFrame jFrame = new JFrame();
        jFrame.setSize(300, 300);
        jFrame.add(new DragCircle());
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
Move a circle on mouse click

Move a circle on mouse click


By : amaury babu
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , See if this helps, here i have filled the entire rect with background color before drawing the circle. Though not efficient but serves the purpose
replace the paint method as follows
code :
public void paint (Graphics g) {
        setBackground (Color.red);
        g.setColor(Color.red);
        g.fillRect(0, 0, width, height);
        g.setColor(Color.yellow);
        int a, b;
        a = -50 + (int)(Math.random()*(width+40));
        b = (int)(Math.random()*(height+20));
        g.fillOval(a, b, 130, 110);
    }
Detect if mouse move in circle way

Detect if mouse move in circle way


By : pretyAngle
Date : March 29 2020, 07:55 AM
Any of those help You probably want to track the mouse movements as a series of line segments, and use those line segments to create an approximation of a circle. If the center of the circle stays relatively consistent, then the user is moving in a circle.
They key to this is that any two consecutive line segments approximate an arc of a circle. The normals from the center of to these line segments (normals are perpendicular lines) form lines that pass through the center of the circle. When you have two or more normals, you can calculate the center of the circle. If that center stays relatively consistent as the user moves the mouse around, and the angles of those normals around the center of the circle are proceeding clockwise or counter-clockwise, then you have a circle.
Create a circle at mouse location on mouse move

Create a circle at mouse location on mouse move


By : madaca123
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Your divs change position because you're setting the position of every div with the class name "circle".
You need to change
code :
$('.circle').css({position:"absolute", top:posY,left:posX});
circles[randCircle].css({position:"absolute", top:posY,left:posX});
d3.js - Circle added to the mouse move is not visible

d3.js - Circle added to the mouse move is not visible


By : Oleg Lapshynov
Date : March 29 2020, 07:55 AM
I wish this helpful for you You cannot append a element to a element. That simply won't work.
Instead of that, append the circle to the same container of the line:
code :
var hoverCircle = hoverLineGroup.append("circle")
shadow
Privacy Policy - Terms - Contact Us © bighow.org