Skip to content

Commit 5141179

Browse files
committed
shadow on brush pointer
1 parent 2bca9a9 commit 5141179

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "croquis.js",
33
"main": "croquis.js",
4-
"version": "0.2.1",
4+
"version": "0.2.2",
55
"homepage": "https://github.com/disjukr/croquis.js",
66
"authors": [
77
"JongChan Choi <disjukr@naver.com>"

croquis.js

+30-10
Original file line numberDiff line numberDiff line change
@@ -876,19 +876,21 @@ Croquis.createChecker = function (cellSize, colorA, colorB) {
876876
return checker;
877877
}
878878
Croquis.createBrushPointer = function (brushImage, brushSize, brushAngle,
879-
threshold, antialias, color) {
879+
threshold, antialias, color,
880+
shadow, shadowOffsetX, shadowOffsetY) {
880881
brushSize = brushSize | 0;
881882
var pointer = document.createElement('canvas');
882883
var pointerContext = pointer.getContext('2d');
884+
var boundWidth;
885+
var boundHeight;
883886
if (brushSize == 0) {
884-
pointer.width = 1;
885-
pointer.height = 1;
886-
return pointer;
887+
pointer.width = boundWidth = 1;
888+
pointer.height = boundHeight = 1;
887889
}
888890
if (brushImage == null) {
889891
var halfSize = (brushSize * 0.5) | 0;
890-
pointer.width = brushSize;
891-
pointer.height = brushSize;
892+
pointer.width = boundWidth = brushSize;
893+
pointer.height = boundHeight = brushSize;
892894
pointerContext.fillStyle = '#000';
893895
pointerContext.beginPath();
894896
pointerContext.arc(halfSize, halfSize, halfSize, 0, Math.PI * 2);
@@ -903,8 +905,8 @@ Croquis.createBrushPointer = function (brushImage, brushSize, brushAngle,
903905
var abs = Math.abs;
904906
var sin = Math.sin;
905907
var cos = Math.cos;
906-
var boundWidth = abs(height * sin(ra)) + abs(width * cos(ra));
907-
var boundHeight = abs(width * sin(ra)) + abs(height * cos(ra));
908+
boundWidth = abs(height * sin(ra)) + abs(width * cos(ra));
909+
boundHeight = abs(width * sin(ra)) + abs(height * cos(ra));
908910
pointer.width = boundWidth;
909911
pointer.height = boundHeight;
910912
pointerContext.save();
@@ -914,8 +916,26 @@ Croquis.createBrushPointer = function (brushImage, brushSize, brushAngle,
914916
pointerContext.drawImage(brushImage, 0, 0, width, height);
915917
pointerContext.restore();
916918
}
917-
return Croquis.createAlphaThresholdBorder(
918-
pointer, threshold, antialias, color);
919+
var result;
920+
var alphaThresholdBorder = Croquis.createAlphaThresholdBorder(
921+
pointer, threshold, antialias, color);
922+
if (shadow) {
923+
shadowOffsetX = shadowOffsetX ? shadowOffsetX : 1;
924+
shadowOffsetY = shadowOffsetY ? shadowOffsetY : 1;
925+
result = document.createElement('canvas');
926+
result.width = boundWidth + shadowOffsetX;
927+
result.height = boundHeight + shadowOffsetY;
928+
var resultContext = result.getContext('2d');
929+
resultContext.shadowOffsetX = shadowOffsetX;
930+
resultContext.shadowOffsetY = shadowOffsetY;
931+
resultContext.shadowColor = shadow;
932+
resultContext.drawImage(
933+
alphaThresholdBorder, 0, 0, boundWidth, boundHeight);
934+
}
935+
else {
936+
result = alphaThresholdBorder;
937+
}
938+
return result;
919939
};
920940
Croquis.createAlphaThresholdBorder = function (image, threshold,
921941
antialias, color) {

0 commit comments

Comments
 (0)