Swizzbeat Posted April 7, 2014 Share Posted April 7, 2014 I have a lot of people ask me what the code is for my mouse cursor, so I mine as well post this. MousePathPoint class: import java.awt.Point; //CREDITS TO ENFILADE class MousePathPoint extends Point { private long finishTime; private double lastingTime; private int alpha = 255; public MousePathPoint(int x, int y, int lastingTime) { super(x, y); this.lastingTime = lastingTime; finishTime = System.currentTimeMillis() + lastingTime; } //added by Swizzbeat public int getAlpha() { int newAlpha = ((int) ((finishTime - System.currentTimeMillis()) / (lastingTime / alpha))); if (newAlpha > 255) newAlpha = 255; if (newAlpha < 0) newAlpha = 0; return newAlpha; } public boolean isUp() { return System.currentTimeMillis() >= finishTime; } } Class variables in main class: private int mX, mY; private long angle; private BasicStroke cursorStroke = new BasicStroke(2); private Color cursorColor = Color.WHITE; private AffineTransform oldTransform; Code to put in your onPaint: Graphics2D g = (Graphics2D) g1; //replace g1 with Graphics variable name oldTransform = g.getTransform(); mX = client.getMousePosition().x; mY = client.getMousePosition().y; g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); //MOUSE TRAIL while (!mousePath.isEmpty() && mousePath.peek().isUp()) mousePath.remove(); Point clientCursor = client.getMousePosition(); MousePathPoint mpp = new MousePathPoint(clientCursor.x, clientCursor.y, 300); if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp)) mousePath.add(mpp); MousePathPoint lastPoint = null; for (MousePathPoint a : mousePath) { if (lastPoint != null) { g.setColor(new Color(255, 255, 255, a.getAlpha())); //trail color g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y); } lastPoint = a; } if (mX != -1) { g.setStroke(cursorStroke); g.setColor(cursorColor); g.drawLine(mX-3, mY-3, mX+2, mY+2); g.drawLine(mX-3, mY+2, mX+2, mY-3); g.rotate(Math.toRadians(angle+=6), mX, mY); g.draw(new Arc2D.Double(mX-12, mY-12, 24, 24, 330, 60, Arc2D.OPEN)); g.draw(new Arc2D.Double(mX-12, mY-12, 24, 24, 151, 60, Arc2D.OPEN)); g.setTransform(oldTransform); } 1 Link to comment Share on other sites More sharing options...
Novak Posted April 7, 2014 Share Posted April 7, 2014 dat antialiasing Link to comment Share on other sites More sharing options...
lazyy Posted April 20, 2014 Share Posted April 20, 2014 MousePath cannot be resolved?? Link to comment Share on other sites More sharing options...
Apaec Posted April 26, 2014 Share Posted April 26, 2014 Yeah, for some reason mouse path cannot be resolved. Link to comment Share on other sites More sharing options...
Swizzbeat Posted April 29, 2014 Author Share Posted April 29, 2014 You obviously have to create a mousePath object.... List<MousePathPoint> mousePath = new LinkedList<>(); Link to comment Share on other sites More sharing options...
Apaec Posted April 29, 2014 Share Posted April 29, 2014 You obviously have to create a mousePath object.... List<MousePathPoint> mousePath = new LinkedList<>(); k ;p Link to comment Share on other sites More sharing options...