Skip to content

Commit da2ef7d

Browse files
committed
CPBrushInfo CPBrushManager をclass構文に変更。
1 parent 0be7adf commit da2ef7d

6 files changed

Lines changed: 1205 additions & 1215 deletions

File tree

chickenpaint/js/chickenpaint.js

Lines changed: 456 additions & 457 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chickenpaint/js/chickenpaint.min.js

Lines changed: 456 additions & 457 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/engine/CPArtwork.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,8 @@ function memoryUsedByCanvas(canvas) {
9797
* @param {number} _width
9898
* @param {number} _height
9999
* @constructor
100-
*/
101-
102-
/**
103100
* @this {any}
104101
*/
105-
106102
export default function CPArtwork(_width, _height) {
107103
_width = _width | 0;
108104
_height = _height | 0;

js/engine/CPBlendTree.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ CPBlendNode.prototype.addChildren = function (children) {
112112
* @param {boolean} requireSimpleFusion - Set to true if the result must have alpha 100 and no mask.
113113
*
114114
* @constructor
115-
*/
116-
117-
/**
118115
* @this {any}
119116
*/
120117

js/engine/CPBrushInfo.js

Lines changed: 75 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,87 @@
4848
* @property {boolean} isAA
4949
*
5050
* @constructor
51-
*/
52-
53-
/**
5451
* @this {any}
5552
*/
5653

57-
export default function CPBrushInfo(properties) {
58-
var propName;
59-
60-
// Set brush setting fields with default values, then apply the supplied 'properties' on top
61-
for (propName in CPBrushInfo.DEFAULTS) {
62-
if (CPBrushInfo.DEFAULTS.hasOwnProperty(propName)) {
63-
this[propName] = CPBrushInfo.DEFAULTS[propName];
54+
export default class CPBrushInfo {
55+
constructor(properties) {
56+
var propName;
57+
58+
this.isAA = false;
59+
this.minSpacing = 0.0;
60+
this.spacing = 0.0;
61+
62+
this.pressureSize = true;
63+
this.pressureAlpha = false;
64+
this.pressureScattering = false;
65+
this.alphaScale = 1.0;
66+
67+
this.tip = CPBrushInfo.TIP_ROUND_PIXEL;
68+
this.brushMode = CPBrushInfo.BRUSH_MODE_PAINT;
69+
this.paintMode = CPBrushInfo.PAINT_MODE_OPACITY;
70+
this.strokeMode = CPBrushInfo.STROKE_MODE_FREEHAND;
71+
this.resat = 1.0;
72+
this.bleed = 0.0;
73+
74+
this.texture = 1.0;
75+
this.toolNb = 0;
76+
77+
// "cur" values are current brush settings (once tablet pressure and stuff is applied)
78+
this.size = 0.0;
79+
this.curSize = 0;
80+
this.alpha = 0.0;
81+
this.curAlpha = 0.0;
82+
this.scattering = 0.0;
83+
this.curScattering = 0;
84+
this.squeeze = 0.0;
85+
this.curSqueeze = 0;
86+
this.angle = Math.PI;
87+
this.curAngle = 0.0;
88+
89+
this.smoothing = 0.0;
90+
91+
for (propName in properties) {
92+
if (properties.hasOwnProperty(propName)) {
93+
this[propName] = properties[propName];
94+
}
6495
}
6596
}
66-
67-
for (propName in properties) {
68-
if (properties.hasOwnProperty(propName)) {
69-
this[propName] = properties[propName];
97+
applyPressure(pressure, isFirstPoint) {
98+
// 1. 目標サイズ
99+
let targetSize = this.pressureSize
100+
? Math.max(0.6, this.size * pressure)
101+
: Math.max(0.6, this.size);
102+
103+
// 2. 線幅ローパスフィルタ
104+
const sizeSmooth = 0.3;
105+
106+
if (isFirstPoint || !this._lastSize) {
107+
// 書き始めの1点目なら、フィルタを通さず即座に目標値にする
108+
this.curSize = targetSize;
109+
this._lastSize = targetSize;
110+
} else {
111+
// 2点目以降は滑らかに変化させる
112+
this.curSize =
113+
this._lastSize + sizeSmooth * (targetSize - this._lastSize);
114+
this._lastSize = this.curSize;
70115
}
116+
// 3. 不透明度
117+
this.curAlpha = this.pressureAlpha
118+
? Math.floor(this.alpha * Math.min(pressure, 1.0))
119+
: this.alpha;
120+
121+
// 4. その他
122+
this.curSqueeze = this.squeeze;
123+
this.curAngle = this.angle;
124+
this.curScattering =
125+
this.scattering *
126+
this.curSize *
127+
(this.pressureScattering ? pressure : 1.0);
128+
}
129+
130+
clone() {
131+
return new CPBrushInfo(this);
71132
}
72133
}
73134

@@ -94,71 +155,3 @@ CPBrushInfo.BRUSH_MODE_OIL = 7;
94155

95156
CPBrushInfo.PAINT_MODE_OPACITY = 0;
96157
CPBrushInfo.PAINT_MODE_FLOW = 1;
97-
98-
CPBrushInfo.DEFAULTS = {
99-
isAA: false,
100-
minSpacing: 0,
101-
spacing: 0,
102-
103-
pressureSize: true,
104-
pressureAlpha: false,
105-
pressureScattering: false,
106-
alphaScale: 1.0,
107-
108-
tip: CPBrushInfo.TIP_ROUND_PIXEL,
109-
brushMode: CPBrushInfo.BRUSH_MODE_PAINT,
110-
paintMode: CPBrushInfo.PAINT_MODE_OPACITY,
111-
strokeMode: CPBrushInfo.STROKE_MODE_FREEHAND,
112-
resat: 1.0,
113-
bleed: 0.0,
114-
115-
texture: 1.0,
116-
117-
// "cur" values are current brush settings (once tablet pressure and stuff is applied)
118-
size: 0,
119-
curSize: 0,
120-
alpha: 0,
121-
curAlpha: 0,
122-
scattering: 0.0,
123-
curScattering: 0,
124-
squeeze: 0.0,
125-
curSqueeze: 0,
126-
angle: Math.PI,
127-
curAngle: 0,
128-
129-
smoothing: 0.0,
130-
};
131-
132-
CPBrushInfo.prototype.applyPressure = function (pressure, isFirstPoint) {
133-
// 1. 目標サイズ
134-
let targetSize = this.pressureSize
135-
? Math.max(0.6, this.size * pressure)
136-
: Math.max(0.6, this.size);
137-
138-
// 2. 線幅ローパスフィルタ
139-
const sizeSmooth = 0.3;
140-
141-
if (isFirstPoint || !this._lastSize) {
142-
// 書き始めの1点目なら、フィルタを通さず即座に目標値にする
143-
this.curSize = targetSize;
144-
this._lastSize = targetSize;
145-
} else {
146-
// 2点目以降は滑らかに変化させる
147-
this.curSize = this._lastSize + sizeSmooth * (targetSize - this._lastSize);
148-
this._lastSize = this.curSize;
149-
}
150-
// 3. 不透明度
151-
this.curAlpha = this.pressureAlpha
152-
? Math.floor(this.alpha * Math.min(pressure, 1.0))
153-
: this.alpha;
154-
155-
// 4. その他
156-
this.curSqueeze = this.squeeze;
157-
this.curAngle = this.angle;
158-
this.curScattering =
159-
this.scattering * this.curSize * (this.pressureScattering ? pressure : 1.0);
160-
};
161-
162-
CPBrushInfo.prototype.clone = function () {
163-
return new CPBrushInfo(this);
164-
};

0 commit comments

Comments
 (0)