Skip to content

Commit 3bba0be

Browse files
authored
Merge pull request #16 from satopian/タイプヒンティング
タイプヒンティング
2 parents 98177c9 + eee2970 commit 3bba0be

9 files changed

Lines changed: 274 additions & 129 deletions

File tree

petitnote/app/neo/neo.js

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ document.addEventListener("DOMContentLoaded", () => {
2121

2222
var Neo = function () {};
2323

24-
Neo.version = "1.6.51";
24+
Neo.version = "1.6.55";
2525
Neo.painter = null;
2626
Neo.fullScreen = false;
2727
Neo.uploaded = false;
@@ -2023,6 +2023,8 @@ Neo.Painter.prototype.toneTool = null;
20232023
Neo.Painter.prototype.blurTool = null;
20242024
Neo.Painter.prototype.dodgeTool = null;
20252025
Neo.Painter.prototype.burnTool = null;
2026+
Neo.Painter.prototype.sliderTool = null;
2027+
Neo.Painter.prototype.dummyTool = null;
20262028

20272029
Neo.Painter.prototype.rectTool = null;
20282030
Neo.Painter.prototype.rectFillTool = null;
@@ -2288,8 +2290,9 @@ Neo.Painter.prototype._initCanvas = function (div, width, height) {
22882290
container.onmouseout = function (e) {
22892291
ref._rollOutHandler(e);
22902292
};
2293+
// 先にNeo.Buttonのtouchstart()がトリガーされる
22912294
container.addEventListener(
2292-
"mousedown",
2295+
"mousedown", //pointerdownに変更するとここが先にトリガーされ、線幅を保存できなくなる
22932296
function (e) {
22942297
ref._mouseDownHandler(e);
22952298
},
@@ -2475,6 +2478,9 @@ Neo.Painter.prototype._initTools = function () {
24752478
this.ellipseFillTool = new Neo.EllipseFillTool();
24762479
this.blurRectTool = new Neo.BlurRectTool();
24772480
this.turnTool = new Neo.TurnTool();
2481+
2482+
this.sliderTool = new Neo.SliderTool();
2483+
this.dummyTool = new Neo.DummyTool();
24782484
};
24792485

24802486
Neo.Painter.prototype.hideInputText = function () {
@@ -2655,20 +2661,22 @@ Neo.Painter.prototype._mouseDownHandler = function (e) {
26552661

26562662
if (!this.isUIPaused()) {
26572663
if (e.target["data-bar"]) {
2658-
this.pushTool(new Neo.HandTool());
2664+
this.pushTool(this.handTool);
2665+
this.handTool.reverse = false;
26592666
} else if (this.isSpaceDown && document.activeElement != this.inputText) {
2660-
this.pushTool(new Neo.HandTool());
2661-
this.tool.reverse = true;
2667+
this.pushTool(this.handTool);
2668+
this.handTool.reverse = true;
26622669
} else if (e.target["data-slider"] != undefined) {
2663-
this.pushTool(new Neo.SliderTool());
2664-
this.tool.target = e.target;
2670+
this.pushTool(this.sliderTool);
2671+
this.sliderTool.target = e.target;
2672+
this.sliderTool.alt = false;
26652673
} else if (e.ctrlKey && e.altKey && !e.shiftKey) {
2666-
this.pushTool(new Neo.SliderTool());
2667-
this.tool.target = Neo.sliders[Neo.SLIDERTYPE_SIZE].element;
2668-
this.tool.alt = true;
2674+
this.pushTool(this.sliderTool);
2675+
this.sliderTool.target = Neo.sliders[Neo.SLIDERTYPE_SIZE].element;
2676+
this.sliderTool.alt = true;
26692677
} else if (this.isWidget(e.target)) {
26702678
this.isMouseDown = false;
2671-
this.pushTool(new Neo.DummyTool());
2679+
this.pushTool(this.dummyTool);
26722680
}
26732681
}
26742682

@@ -2770,12 +2778,16 @@ Neo.Painter.prototype._stabilizer = function (e) {
27702778
if (this.isMouseDown) {
27712779
// 手ぶれ補正の強さ
27722780
// 補正なし 0.0 最強 0.99
2773-
const level = Neo.stabiliz_level;
2781+
const level = Math.max(0, Math.min(Neo.stabiliz_level, 5));
27742782
//手ぶれ補正のレベルを6段階に分けたテーブル
27752783
//0で補正なし、5で最強
27762784
// [0:無効, 1:0.55, 2:0.8, 3:0.85, 4:0.9, 5:0.96]
27772785
const stabilityTable = [0.0, 0.55, 0.8, 0.85, 0.9, 0.96];
2778-
const stability = stabilityTable[Math.max(0, Math.min(level, 5))];
2786+
const stabilityLebel = stabilityTable[level];
2787+
//ブラシサイズが大きい時と拡大時は補正強度を下げる
2788+
const zoomModifier = this.zoom <= 1 ? 1 : 0.88;
2789+
const sizeModifier = this.lineWidth <= 8 ? 1 : 0.96;
2790+
const stability = stabilityLebel * zoomModifier * sizeModifier;
27792791
const factor = 1.0 - stability;
27802792

27812793
// stabilizedX が未定義なら現在の位置で初期化
@@ -4804,32 +4816,31 @@ Neo.Painter.prototype.getDestCanvasPosition = function (
48044816
};
48054817

48064818
Neo.Painter.prototype.isWidget = function (element) {
4807-
while (1) {
4808-
if (
4809-
element == null ||
4810-
element.id == "neo-canvas" ||
4811-
element.id == "neo-container"
4812-
)
4813-
break;
4819+
if (!element || !(element instanceof Element)) return false;
48144820

4815-
if (
4816-
element.id == "neo-tools" ||
4817-
element.className == "buttonOn" ||
4818-
element.className == "buttonOff" ||
4819-
element.className == "inputText"
4820-
) {
4821-
return true;
4822-
}
4823-
element = element.parentNode;
4821+
// #NEO の外側を除外
4822+
const root = element.closest("#NEO");
4823+
if (!root) return false;
4824+
4825+
// ツール領域・ボタン類
4826+
if (
4827+
element.closest(
4828+
"#neo-tools, .NEO .buttonOn, .NEO .buttonOff, .NEO .inputText",
4829+
)
4830+
) {
4831+
return true;
48244832
}
4833+
48254834
return false;
48264835
};
48274836

48284837
Neo.Painter.prototype.isContainer = function (element) {
4829-
while (1) {
4830-
if (element == null) break;
4831-
if (element.id == "neo-container") return true;
4832-
element = element.parentNode;
4838+
if (!element || !(element instanceof Element)) return false;
4839+
// #NEO の外側を除外
4840+
const root = element.closest("#NEO");
4841+
if (!root) return false;
4842+
if (element.closest("#neo-container")) {
4843+
return true;
48334844
}
48344845
return false;
48354846
};
@@ -5102,6 +5113,7 @@ Neo.ToolBase.prototype.startX = null;
51025113
Neo.ToolBase.prototype.startY = null;
51035114
Neo.ToolBase.prototype.type = null;
51045115
Neo.ToolBase.prototype.step = 0;
5116+
Neo.ToolBase.prototype.reverse = false;
51055117

51065118
Neo.ToolBase.prototype.init = function (oe) {};
51075119
Neo.ToolBase.prototype.kill = function (oe) {};

0 commit comments

Comments
 (0)