| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.drawing; |
| 16 | |
| 17 | import java.awt.Rectangle; |
| 18 | import java.awt.image.BufferedImage; |
| 19 | |
| 20 | import net.sourceforge.hiveboard.util.ImageHolder; |
| 21 | import net.sourceforge.hiveboard.util.RGBAImageHolder; |
| 22 | |
| 23 | public class ImageDrawingAction implements DrawingAction |
| 24 | { |
| 25 | public ImageDrawingAction(int x, int y, BufferedImage image, ImageCompositor compositor) |
| 26 | { |
| 27 | _x = Math.max(0, x); |
| 28 | _y = Math.max(0, y); |
| 29 | _image.setImage(image); |
| 30 | _area = new Rectangle(_x, _y, image.getWidth(), image.getHeight()); |
| 31 | _compositor = compositor; |
| 32 | } |
| 33 | |
| 34 | public void perform(BufferedImage image) |
| 35 | { |
| 36 | _compositor.compose(_image.getImage(), image, _x, _y); |
| 37 | } |
| 38 | |
| 39 | public Rectangle getActionArea() |
| 40 | { |
| 41 | return _area; |
| 42 | } |
| 43 | |
| 44 | final private int _x; |
| 45 | final private int _y; |
| 46 | final private ImageHolder _image = new RGBAImageHolder(); |
| 47 | final private Rectangle _area; |
| 48 | final private ImageCompositor _compositor; |
| 49 | } |