App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Brush.java
Go to the documentation of this file.
1 package mhr.appcore.tools.brushlike;
2
3 import mhr.appcore.bitmap.NBitmap;
4 import mhr.appcore.blending.BlendMode;
5 import mhr.appcore.blending.Blender;
6 import mhr.appcore.image.Image;
7 import mhr.appcore.image.ImageSelectedState;
8 import mhr.appcore.tools.actiondata.ToolActionData;
9 import mhr.appcore.tools.exceptions.ToolNotApplicableException;
10 import mhr.appcore.utils.Rect;
11
15 public class Brush extends BrushLikeTool {
16
17 protected int color;
18
19 protected BlendMode blendMode;
20
30 public Brush(NBitmap brush, BlendMode mode, double opacity, double flow, int color, double spacing) {
31 super(brush, BrushMode.MODE_ADD, opacity, flow, spacing);
32 this.color = color;
33 this.blendMode = mode;
34 }
35
36 @Override
37 public void applyTo(Image img, ToolActionData data) throws ToolNotApplicableException {
38 if (img.getSelectedState() == ImageSelectedState.SELECTED_LAYER) {
39 super.applyTo(img, data);
40 } else {
41 throw new ToolNotApplicableException("Brush tool is not applicable to selected element");
42 }
43 }
44
45 @Override
46 public void onRender(Image i, NBitmap c, NBitmap l, NBitmap o, NBitmap m, Rect src, int srcOrigX, int srcOrigY) {
47 o.copyTo(l, src, srcOrigX, srcOrigY);
48 Blender.drawTo(blendMode, l, c, color, src, srcOrigX, srcOrigY, opacity);
49
50 }
51
52 @Override
53 public void onCommit(Image i, NBitmap c, NBitmap l, NBitmap o, NBitmap m, Rect src, int srcOrigX, int srcOrigY) {
54 Blender.drawTo(blendMode, o, c, color, src, srcOrigX, srcOrigY, opacity);
55 }
56 }