Skip to content

Commit c685fc0

Browse files
2 parents 0599484 + 1b823b2 commit c685fc0

File tree

3 files changed

+103
-9
lines changed

3 files changed

+103
-9
lines changed

.github/workflows/greetings.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Greetings
2+
3+
on: [pull_request_target, issues]
4+
5+
jobs:
6+
greeting:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
issues: write
10+
pull-requests: write
11+
steps:
12+
- uses: actions/first-interaction@v1
13+
with:
14+
repo-token: ${{ secrets.GITHUB_TOKEN }}
15+
issue-message: "Hi there! Thanks for opening this issue. We appreciate your contribution to this open-source project. We aim to respond or assign your issue as soon as possible."
16+
pr-message: "Welcome to Our repository.🎊 Thank you so much for taking the time to point this out."

components/Canvas.jsx

+45-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const Canvas = () => {
6262
const [scale, setscale] = useState(1);
6363
const textAreaRef = useRef();
6464
const [mouseEvent,setMouseEvent] = useState(null);
65+
const [keys, setKeys] = useState(new Set());
66+
const [IsPanning, setIsPanning] = useState("");;
67+
const [startPanning, setStartPanning] = useState({ x:0, y:0 });
6568

6669

6770
const isFontLoaded = useFontFaceObserver([
@@ -109,7 +112,28 @@ const Canvas = () => {
109112
}, [roughCanvasRef]);
110113

111114

115+
useEffect(()=>{
116+
const canvas = document.getElementById("canvas")
117+
const handleKeyDown = (event) => {
118+
setKeys(keys => new Set(keys).add(event.key));
119+
}
112120

121+
const handleKeyUp = event => {
122+
setKeys(keys => {
123+
const updatedKeys = new Set(keys);
124+
updatedKeys.delete(event.key);
125+
return updatedKeys;
126+
});
127+
};
128+
129+
// console.log(keys)
130+
canvas.addEventListener("keydown", handleKeyDown);
131+
canvas.addEventListener("keyup", handleKeyUp);
132+
return () => {
133+
canvas.removeEventListener("keydown", handleKeyDown);
134+
canvas.removeEventListener("keyup", handleKeyUp);
135+
};
136+
},[keys])
113137

114138

115139

@@ -315,17 +339,23 @@ const Canvas = () => {
315339
const modifyClient = (event) => {
316340
event.clientX = (event.clientX - panOffset.x * scale + scaleOffset.x) / scale;
317341
event.clientY = (event.clientY - panOffset.y * scale + scaleOffset.y) / scale;
318-
319-
}
342+
343+
}
320344

321345
const handleMouseDown = (event) => {
322-
346+
const canvas = document.getElementById("canvas");
323347
if (event.button == 1) {
324348
dispatch(changeToolWheel(true));
325349
return;
326350
}
327351

328352
modifyClient(event);
353+
if(keys.has(" ")){
354+
canvas.style.cursor = "grabbing"
355+
setIsPanning("panning");
356+
setStartPanning({ x: event.clientX, y: event.clientY })
357+
return;
358+
}
329359
if (action === 'writing') {
330360
return;
331361
}
@@ -472,7 +502,9 @@ const Canvas = () => {
472502

473503
const handleMouseUp = (event) => {
474504
// according to scale and traslation , we have to modify indexes
475-
505+
setIsPanning("");
506+
const canvas = document.getElementById("canvas");
507+
canvas.style.cursor = ""
476508
modifyClient(event);
477509

478510
if (action === 'writing') {
@@ -618,6 +650,14 @@ const Canvas = () => {
618650

619651
const handleMouseMove = (event) => {
620652
modifyClient(event);
653+
if(IsPanning === 'panning'){
654+
const deltaX = event.clientX - startPanning.x;
655+
const deltaY = event.clientY - startPanning.y;
656+
setpanOffset(prevState => ({
657+
x: prevState.x + deltaX / 2,
658+
y: prevState.y + deltaY / 2
659+
}))
660+
}
621661
setMouseEvent(event);
622662
if (tool === 'selection') {
623663

@@ -814,7 +854,7 @@ const Canvas = () => {
814854
onMouseMove={handleMouseMove}
815855
></canvas>
816856

817-
857+
818858
</div>
819859

820860

components/PropertiesBar/PropertiesBar.jsx

+42-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const PropertiesBar = () => {
2323

2424
const [stroke, setStroke] = useState("#000000");
2525
const [background, setBackground] = useState(null);
26+
const [fillStyle, setFillStyle] = useState('solid');
2627
const [strokeStyle, setStrokeStyle] = useState([]);
2728
const [strokeWidth, setStrokeWidth] = useState(2);
2829
const [sharp, setSharp] = useState(false);
@@ -51,10 +52,20 @@ const PropertiesBar = () => {
5152
'#09203f',
5253
]
5354

55+
const fillStyles = [
56+
'solid',
57+
'zigzag',
58+
'cross-hatch',
59+
// 'dots',
60+
'sunburst',
61+
'dashed',
62+
'zigzag-line'
63+
]
64+
5465
// useEffect used to preload the already applied properties on the elements
5566
useEffect(() => {
5667

57-
if (selectedElement != null) {
68+
if (selectedElement !== null) {
5869
element = elements[parseInt(selectedElement.id.split("#")[1])];
5970
if (element === null || element === undefined) {
6071

@@ -67,8 +78,10 @@ const PropertiesBar = () => {
6778
const currentSharp = GlobalProps.sharp;
6879
const bowing = GlobalProps.bowing;
6980
const currentFontSize = GlobalProps.fontSize;
81+
const currentFillStyle = GlobalProps.fillStyle;
7082

7183
setBackground(currentBackground);
84+
setFillStyle(currentFillStyle);
7285
setStrokeStyle(currentStrokeStyle);
7386
setStrokeWidth(currentStrokeWidth);
7487
setSharp(currentSharp);
@@ -80,14 +93,16 @@ const PropertiesBar = () => {
8093

8194
const currentStroke = element.stroke
8295

83-
if (element.type != "text") {
96+
if (element.type !== "text") {
8497
const currentBackground = element.fill;
98+
const currentFillStyle = element.fillStyle;
8599
const currentStrokeStyle = element.strokeStyle;
86100
const currentStrokeWidth = element.strokeWidth;
87101
const currentSharp = element.sharp;
88102
const bowing = element.bowing;
89103

90104
setBackground(currentBackground);
105+
setFillStyle(currentFillStyle);
91106
setStrokeStyle(currentStrokeStyle);
92107
setStrokeWidth(currentStrokeWidth);
93108
setSharp(currentSharp);
@@ -103,13 +118,15 @@ const PropertiesBar = () => {
103118

104119
const currentStroke = GlobalProps.stroke
105120
const currentBackground = GlobalProps.fill;
121+
const currentFillStyle = GlobalProps.fillStyle;
106122
const currentStrokeStyle = GlobalProps.strokeStyle;
107123
const currentStrokeWidth = GlobalProps.strokeWidth;
108124
const currentSharp = GlobalProps.sharp;
109125
const bowing = GlobalProps.bowing;
110126
const currentFontSize = GlobalProps.fontSize;
111127

112128
setBackground(currentBackground);
129+
setFillStyle(currentFillStyle);
113130
setStrokeStyle(currentStrokeStyle);
114131
setStrokeWidth(currentStrokeWidth);
115132
setSharp(currentSharp);
@@ -132,6 +149,7 @@ const PropertiesBar = () => {
132149
if (selectedElement === null || tool !== 'selection') {
133150
GlobalProps.stroke = stroke;
134151
GlobalProps.fill = background;
152+
GlobalProps.fillStyle = fillStyle;
135153
GlobalProps.strokeStyle = strokeStyle;
136154
GlobalProps.strokeWidth = strokeWidth;
137155
GlobalProps.sharp = sharp;
@@ -163,7 +181,7 @@ const PropertiesBar = () => {
163181
case "rectangle":
164182
case "diamond":
165183
case "ellipse":
166-
options = { stroke: stroke, fill: background, strokeStyle: strokeStyle, strokeWidth: strokeWidth, sharp: sharp, bowing: bowing };
184+
options = { stroke: stroke, fill: background, fillStyle: fillStyle, strokeStyle: strokeStyle, strokeWidth: strokeWidth, sharp: sharp, bowing: bowing };
167185
break;
168186
case "text":
169187
options = { stroke: stroke, fontSize: fontSize };
@@ -228,7 +246,7 @@ const PropertiesBar = () => {
228246

229247

230248
setChangedByUser(false);
231-
}, [firstEffectCompleted, stroke, background, strokeStyle, strokeWidth, sharp, bowing, fontSize])
249+
}, [firstEffectCompleted, stroke, background,fillStyle, strokeStyle, strokeWidth, sharp, bowing, fontSize])
232250

233251

234252
if (tool === "eraser") {
@@ -299,6 +317,26 @@ const PropertiesBar = () => {
299317

300318
<SimpleColorPicker stroke={background} setStroke={setBackground} setChangedByUser={setChangedByUser}></SimpleColorPicker></div>
301319

320+
</CardContent>
321+
322+
: null}
323+
324+
{(tool != 'pencil' && tool != 'text' && tool != 'line' && selectedElement === null) || (selectedElement != null && selectedElement.type != "pencil" && selectedElement.type != 'text' && selectedElement.type != "line" === true) ? <CardContent >
325+
<span className='text-xs'>Fill style</span>
326+
<div className="flex flex-wrap max-w-[230px] gap-2 mt-1">
327+
{fillStyles.map((style) => (
328+
<div key={style} className={`border border-1 cursor-pointer active:scale-105 inline-flex items-center rounded-md bg-gray-50 px-2 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10 ${fillStyle === style ? 'border-2 border-black ' : null}`}
329+
onClick={() => {
330+
setChangedByUser(true);
331+
setFillStyle(style);
332+
}}>
333+
<p className="text-xs rounded-md ">
334+
{style}
335+
</p>
336+
</div>
337+
))}
338+
</div>
339+
302340
</CardContent>
303341

304342
: null}

0 commit comments

Comments
 (0)