Jump to content

Mouse trail and cursor classes


Recommended Posts

Posted

3 classes u can use to add a trail and a crusor

Classes:

Spoiler

MousePathPoint.java:


package Utils;

import java.awt.Point;

public class MousePathPoint extends Point{
	
	private long finishTime;

	public MousePathPoint(int x, int y, int lastingTime){
		super(x,y);
		finishTime= System.currentTimeMillis() + lastingTime;
	}
	
	public boolean isUp(){
		return System.currentTimeMillis() > finishTime;
	}
}

MouseTrail.java:


package Utils;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.LinkedList;

import org.osbot.rs07.script.MethodProvider;

public class MouseTrail {

	private int r, g, b, duration;
	private LinkedList<MousePathPoint> mousePath  = new LinkedList<MousePathPoint>();;
	private MethodProvider api;


	public MouseTrail(int r, int g, int b, int duration, MethodProvider api) {
		this.r = r;
		this.g = g;
		this.b = b;
		this.duration = duration;
		this.api = api;
	}
	
	public void nextRGB(){
		if(r == 255 && g < 255 & b == 0){
			g++;
		}
        if ( g == 255 && r > 0 && b == 0 )
        {
            r--;
        }
        if ( g == 255 && b < 255 && r == 0 )
        {
            b++;
        }
        if ( b == 255 && g > 0 && r == 0 )
        {
            g--;
        }
        if ( b == 255 && r < 255 && g == 0 )
        {
            r++;
        }
        if ( r == 255 && b > 0 && g == 0 )
        {
            b--;
        }
        
	}
	

	public Color nextColor(){
		nextRGB();
		return new Color(r,g,b);
	}

	public void paint(Graphics2D g){
		while (!mousePath.isEmpty() && mousePath.peek().isUp())
            mousePath.remove();
        Point clientCursor = api.getMouse().getPosition();
        MousePathPoint mpp = new MousePathPoint(clientCursor.x, clientCursor.y, duration);
        if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
            mousePath.add(mpp);
        MousePathPoint lastPoint = null;
        for (MousePathPoint a : mousePath) {
            if (lastPoint != null) {
                g.setColor(nextColor());
                g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
            }
            lastPoint = a;
        }
	}
	
}

MouseCursor.java:


package Utils;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;

import org.osbot.rs07.script.MethodProvider;

public class MouseCursor {

	private int mX, mY;
	private int size;
	private long angle;
	private BasicStroke cursorStroke;
	private Color cursorColor;
	private AffineTransform oldTransform;
	private MethodProvider api;

	public MouseCursor(int size, int thickness, Color color, MethodProvider api) {
		this.size = size;
		this.cursorStroke = new BasicStroke(thickness);
		this.cursorColor = color;
		this.api = api;
	}

	public void paint(Graphics2D g) {
		oldTransform = g.getTransform();
		mX = api.getMouse().getPosition().x;
		mY = api.getMouse().getPosition().y;

		if (mX != -1) {
			g.setStroke(cursorStroke);
			g.setColor(cursorColor);
			g.drawLine(mX - (size / 8), mY - (size / 8), mX + (size / 12), mY + (size / 12));
			g.drawLine(mX - (size / 8), mY + (size / 12), mX + (size / 12), mY - (size / 8));

			g.rotate(Math.toRadians(angle += 6), mX, mY);

			g.draw(new Arc2D.Double(mX - (size / 2), mY - (size / 2), size, size, 330, 60, Arc2D.OPEN));
			g.draw(new Arc2D.Double(mX - (size / 2), mY - (size / 2), size, size, 151, 60, Arc2D.OPEN));

			g.setTransform(oldTransform);
		}
	}

}

 

Usage:

global vars:

private MouseTrail trail = new MouseTrail(0, 255, 255, 2000, this);
private MouseCursor cursor = new MouseCursor(52, 4, Color.white, this);

onPaint:

public void onPaint(Graphics2D g){
	trail.paint(g);
	cursor.paint(g);
}

 

Credit:

swizzbeat -> cursor

DarkMagican -> trail

Original posts:

 

 

 

  • Like 5
  • Heart 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...