Jump to content

Returning a rectangle from the mouse cords


Recommended Posts

Posted (edited)

this is useful for a mouse destination  it's so you don't have to do maths because some people are bad at math

    /*
     * @param minX  this is the top left hand  corner of the rectangle
     * @param minY this is the top left hand  corner  of the rectangle
     * @param maxX this is the bottom right hand corner of the rectangle
     * @param maxY this is the bottom right hand corner of the rectangle
     */
    private Rectangle returnRectangle(int minX, int minY, int maxX, int maxY){
        int height = maxY-minY;
        int width = maxX-minX;
        Rectangle r = new Rectangle(minX, minY, width, height);
        return r;
    }

use:

  MouseDestination md = new RectangleDestination(returnRectangle(20,30,40,50));

this will do the math for the height and width.....

 

so the width and height in this example would return:

width:20

height:20

 

Edited by TheScrub
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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