home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 2.4 KB | 135 lines |
- import java.awt.*;
-
- /*
- * a helper class to manage the zoom rectangle
- */
- public class MandelRect {
-
- /*
- * the coordinates of the zoom rectangle
- * in screen space
- */
- int x;
- int y;
- int width;
- int height;
-
- /*
- * the final image width and height
- */
- int imgWidth;
- int imgHeight;
-
- /*
- * the coordinates of the zoom rectangle
- * in set space
- */
- double mandelX;
- double mandelY;
- double mandelWidth;
- double mandelHeight;
-
- /*
- * set to true if the zoom rectangle should be painted
- */
- boolean paintRect;
-
- /**
- * constructor initializes variables
- * @param iW - final image width
- * @param iH - final image height
- */
- public MandelRect (int iW, int iH) {
-
- imgWidth = iW;
- imgHeight = iH;
- paintRect = false;
-
- mandelX = -1.75;
- mandelY = -1.125;
- mandelWidth = 2.25;
- mandelHeight = 2.25;
- }
-
- /**
- * set the top left of the zoom rectangle in screen space
- * @param ix, iy - top-left corner of zoom rectangle
- */
- void setXY (int ix, int iy) {
-
- x = ix;
- y = iy;
- }
-
- /**
- * set the width, height of the zoom rectangle in screen space
- * @param ix, iy - bottom-right corner of zoom rectangle
- */
- void setWidthHeight (int ix, int iy) {
-
- width = ix - x;
- height = iy - y;
- }
-
- /*
- * translate screen coordinates to set coordinates
- */
- void scaleSet () {
-
- int tx, ty, tw, th;
-
- tx = x;
- ty = y;
- tw = width;
- th = height;
- if (tw < 0) {
- tw = -width;
- tx = x-tw;
- }
- if (th < 0) {
- th = -height;
- ty = y-th;
- }
- mandelX = mandelX + (mandelWidth) * ((double) tx)/((double) imgWidth);
- mandelY = mandelY + (mandelHeight) * ((double) ty)/((double) imgHeight);
- mandelWidth = mandelWidth * ((double) tw)/((double)imgWidth);
- mandelHeight = mandelHeight * ((double) th)/((double)imgHeight);
- }
-
- /**
- * set the paintRect flag
- * @param p - true means zoom rectangle should be painted
- */
- void setPaintRect (boolean p) {
-
- paintRect = p;
- }
-
- /**
- * paint the zoom rectangle if necessary
- * @param g - destination graphics object
- */
- void paint (Graphics g) {
-
- if (paintRect == false) return;
-
- int tx, ty, tw, th;
-
- tx = x;
- ty = y;
- tw = width;
- th = height;
- if (tw < 0) {
- tw = -width;
- tx = x-tw;
- }
- if (th < 0) {
- th = -height;
- ty = y-th;
- }
- g.setColor (Color.white);
- g.drawRect (tx, ty, tw, th);
- }
- }
-
-