Changeset 607


Ignore:
Timestamp:
12/12/13 10:08:13 (11 years ago)
Author:
jts21
Message:
Make crop values outside of value bounds ( < 0
>= image bounds ) get scaled to correct values. Does not yet tile correctly.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Picture.java

    r603 r607  
    310310                super.paintLink(g);
    311311        }
    312 
    313         @Override
    314         public void paint(Graphics2D g) {
    315                 if (_image == null)
     312       
     313        public void paintImageTiling(Graphics2D g) {
     314                if (_image == null) {
    316315                        return;
    317 
     316                }
     317               
    318318                int width = getWidth();
    319319                int height = getHeight();
    320 
    321                 paintLink(g);
    322 
    323320                int dX1 = _source.getX();
    324321                int dY1 = _source.getY();
    325322                int dX2 = _source.getX() + width;
    326323                int dY2 = _source.getY() + height;
     324                int iw = _image.getWidth(null);
     325                int ih = _image.getHeight(null);
     326                if(iw <= 0 || ih <= 0) {
     327                        return;
     328                }
     329                while(_start.x >= iw) {
     330                        _start.x -= iw;
     331                        _end.x -= iw;
     332                }
     333                while(_start.y >= ih) {
     334                        _start.y -= ih;
     335                        _end.y -= ih;
     336                }
     337                while(_start.x < 0) {
     338                        _start.x += iw;
     339                        _end.x += iw;
     340                }
     341                while(_start.y < 0) {
     342                        _start.y += ih;
     343                        _end.y += ih;
     344                }
     345                int cw = getUnscaledWidth();
     346                int ch = getUnscaledHeight();
     347               
     348                for(int x = dX1; x < dX2; x += cw) {
     349                        for(int y = dY1; y < dY2; y += ch) {
     350                                int endX = x + cw;
     351                                if(endX > dX2) {
     352                                        endX = dX2;
     353                                }
     354                                int endY = y + ch;
     355                                if(endY > dY2) {
     356                                        endY = dY2;
     357                                }
     358                                g.drawImage(_image, x, y, endX, endY, _start.x, _start.y, _end.x,
     359                                        _end.y, _imageObserver);
     360                        }
     361                }
     362        }
     363
     364        @Override
     365        public void paint(Graphics2D g) {
     366                if (_image == null)
     367                        return;
     368
     369                paintLink(g);
    327370
    328371                // if we are showing the cropping, then show the original as transparent
     
    332375                        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
    333376                                        alpha));
    334                         g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
    335                                         _end.y, _imageObserver);
     377                       
     378                        paintImageTiling(g);
    336379
    337380                        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
     
    340383                        Point topLeft = getTopLeftCrop();
    341384                        Point bottomRight = getBottomRightCrop();
    342                         Shape clip = new Rectangle(dX1 + topLeft.x, dY1 + topLeft.y,
     385                        Shape clip = new Rectangle(_source.getX() + topLeft.x, _source.getY() + topLeft.y,
    343386                                        bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
    344387                        g.setColor(getPaintHighlightColor());
     
    346389                        g.setClip(clip);
    347390
    348                         g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
    349                                         _end.y, _imageObserver);
     391                        paintImageTiling(g);
     392                       
    350393                        g.draw(clip);
    351394                        // if the image is cropped, but we are not showing the cropping
    352395                        // otherwise, paint normally
    353396                } else {
    354                         g.drawImage(_image, dX1, dY1, dX2, dY2, _start.x, _start.y, _end.x,
    355                                         _end.y, _imageObserver);
     397                        paintImageTiling(g);
    356398                }
    357399
Note: See TracChangeset for help on using the changeset viewer.