/*******************************************************************************
* Copyright (c)                                                                *
*           2005   Tristan Allwood,                                            *
*           2005   Daniel Burke,                                               *
*           2005   Marc Hull,                                                  *
*           2005   Ekaterina Itskova,                                          *
*           2005   Steve Zymler                                                *
*                                                                              *
* Permission is hereby granted, free of charge, to any person obtaining a      *
* copy of this software and associated documentation files (the                *
* "Software"), to deal in the Software without restriction, including          *
* without limitation the rights to use, copy, modify, merge, publish,          *
* distribute, sublicense, and/or sell copies of the Software, and to           *
* permit persons to whom the Software is furnished to do so, subject to        *
* the following conditions:                                                    *
*                                                                              *
* The above copyright notice and this permission notice shall be included      *
* in all copies or substantial portions of the Software.                       *
*                                                                              *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS      *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF                   *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.       *
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY         *
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,         *
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE            *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                       *
*******************************************************************************/
/*
 * Created on 26-Dec-2004
 *
 */
package uk.ac.ic.doc.kevlar.gui.showers.image;

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

import uk.ac.ic.doc.kevlar.gui.internal.ADrawableObject;
import uk.ac.ic.doc.kevlar.gui.internal.caches.ColorCache;

/**
 * @author Daniel Burke
 *
 */
public class ImageClipRegion extends ADrawableObject
{
    ImageArea imageArea;
    public void drawAfter(GC gc, Rectangle redrawArea)
    {
        int x = imageArea.getPosition().x;
        int y = imageArea.getPosition().y;
        int w = imageArea.getArea().width;
        int h = imageArea.getArea().height;
        
        gc.setForeground(ColorCache.get(100, 100, 100));
        
        /*gc.drawRectangle(
                imageArea.getPosition().x - redrawArea.x,
                imageArea.getPosition().y - redrawArea.y,
                imageArea.getArea().width,
                imageArea.getArea().height);
                */
        
        int x1, y1, x2, y2;
        
        x2 = x1 = Math.max(x, 0) - redrawArea.x;
        y1 = Math.max(y, 0) - redrawArea.y;
        y2 = Math.min(y + h - 1, getArea().height - 1) - redrawArea.y;
        gc.drawLine(x1, y1, x2, y2);
        
        x2 = x1 = Math.min(x + w - 1, getArea().width - 1) - redrawArea.x;
        gc.drawLine(x1, y1, x2, y2);
        
        y1 = y2 = Math.max(y, 0) - redrawArea.y;
        x1 = Math.max(x, 0) - redrawArea.x;
        x2 = Math.min(x + w - 1, getArea().width - 1) - redrawArea.x;
        gc.drawLine(x1, y1, x2, y2);
        
        y1 = y2 = Math.min(y + h - 1, getArea().height - 1) - redrawArea.y;
        gc.drawLine(x1, y1, x2, y2);
    }
    
    public void setImageArea(ImageArea imageArea)
    {
        this.imageArea = imageArea;
        addChild(imageArea);
    }
}
