Package: CropOverlay
CropOverlay
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CropOverlay() |
|
|
|
|
|
||||||||||||||||||||
fillRect(Graphics2D, int, int, int, int) |
|
|
|
|
|
||||||||||||||||||||
isVisible() |
|
|
|
|
|
||||||||||||||||||||
paint(Graphics2D, EditableImageRenderer) |
|
|
|
|
|
||||||||||||||||||||
setVisible(boolean) |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.mistral.example.viewer;
28:
29: import java.awt.Color;
30: import java.awt.Graphics2D;
31: import it.tidalwave.image.render.EditableImageRenderer;
32: import it.tidalwave.image.render.Overlay;
33:
34: /***********************************************************************************************************************
35: *
36: * An Overlay is something that is drawn over a rendered image.
37: *
38: * @author Fabrizio Giudici
39: *
40: **********************************************************************************************************************/
41: public class CropOverlay implements Overlay
42: {
43: private boolean visible;
44:
45: private int left = 400;
46:
47: private int top = 300;
48:
49: private int width = 2000;
50:
51: private int height = 800;
52:
53: @Override
54: public void paint (final Graphics2D g, final EditableImageRenderer imageRenderer)
55: {
56: final var bounds = imageRenderer.getBounds();
57: final var color = new Color(0, 0, 0, 128);
58: g.setColor(color);
59: final var scale = imageRenderer.getScale();
60: final var origin = imageRenderer.getOrigin();
61:
62: final var x1 = bounds.x + (int)Math.round((left - origin.x) * scale);
63: final var y1 = bounds.y + (int)Math.round((top - origin.y) * scale);
64: final var x2 = bounds.x + (int)Math.round((left + width - origin.x) * scale);
65: final var y2 = bounds.y + (int)Math.round((top + height - origin.y) * scale);
66:
67: fillRect(g, bounds.x, bounds.y, bounds.x + bounds.width - 1, y1 - 1); // top
68: fillRect(g, bounds.x, y1, x1 - 1, y2); // left
69: fillRect(g, x2 + 1, y1, bounds.x + bounds.width - 1, y2); // right
70: fillRect(g, bounds.x, y2 + 1, bounds.x + bounds.width - 1, bounds.y + bounds.height - 1); // bottom
71: }
72:
73: public void setVisible (final boolean visible)
74: {
75: this.visible = visible;
76: }
77:
78: @Override
79: public boolean isVisible()
80: {
81: return visible;
82: }
83:
84: private void fillRect (final Graphics2D g, final int x1, final int y1, final int x2, final int y2)
85: {
86: g.fillRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
87: }
88: }