Repository navigation
Conversation
The pressureSensitive property makes the strokes of the pencil which a pen draws as wide as the pressure on it, read from PointerEvent.pressure: lineWidth is the width at a medium pressure, and a stroke is between a tenth and twice of it. The strokes of a mouse and of a finger are drawn as before. The canvas keeps reading the mouse and the touches (the pinch zoom is made of them). A sensor listens to the pointer events of the page, which come before them, to know the type of the pointer and its pressure, and only while the property is on. A stroke is a filled path, the outline of the discs along the stroke, so that the canvas selects, moves, erases and copies it as any path. It is the type PressureStroke, and it is saved as the discs: the commands of the path are twenty times as long. The showcase has a Pen pressure switch for the pencil.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #136 (not closed by this: the issue can be answered once it is released).
Change
The issue asks for the pressure of a pen (
PointerEvent.pressure) to drive the thickness of the line.pressureSensitive(defaultfalse). With it, the strokes of the pencil which a pen (a stylus) draws are as wide as the pressure on it:lineWidthis the width at a medium pressure, and a stroke is between a tenth and twice of it. A pen which reports a constant 0.5 draws a line oflineWidth.PenSensorlistens to thepointerdownandpointermoveevents of the page, which come before the mouse and touch events of the same input, to know the type of the pointer and its pressure. It listens only while the property is on, and stops when the canvas goes away.PressureBrushextends fabric'sPencilBrushand replaces it as the brush of the free drawing tools. Without a pen stroke it is the same brush. A pen stroke is drawn on the top canvas piece by piece while the pen moves (all at once for a color which is not opaque), and is the same shape when it is lifted.PressureStroke. The stroke is afabric.Pathsubclass, so it is selected, moved, scaled, erased and copied as any path, and it is one undo step. It is saved as its discs ([x, y, r]) and not as the commands of the path: a stroke of 150 points was 166 KB of path commands against 8 KB for a stroke of the pencil, and is a few kilobytes as discs. The path is made again when it is loaded byvalue,defaultValueorfromJSON().types.tsdocumentation, and the CHANGELOG.Verification
yarn buildpass.geometry.spec.ts(18) renders with node-canvas, so it reads real pixels: the width at each end and between, the six directions including a narrower and a wider end, a disc inside another, a sharp turn of a wide stroke with no hole, and the sampler (the pressure along the stroke, the end at the last point, the smoothing, the distance between discs).PressureBrush.spec.tsx(25) drives the brush with pen pointer events: the width for pressures 0.25, 0.5 and 1, the limits, a stroke which gets wider, a tap, the place of the stroke, a color which is not opaque, one undo step andpath:created, save and load, the size of the saved stroke, copy, move with undo, the stroke stopped by the canvas (a second finger), points which are too close, a mouse and a touch, the property off or turned off, the highlighter, and the listeners (not added when the property is off, removed on unmount and when it is turned off).pointerType: penandforce), at a line weight of 20: a stroke with force from 0.1 to 1 is 5, 21 and 38 px wide at its start, middle and end; a pen at 0.5 is 20 px; a mouse stroke is 20 px as before; with the switch off a pen stroke is 20 px at any pressure. Undo and redo bring the strokes back as wide as before, and there were no page errors.Notes
PressureStrokeis a new type intoJSON(), which a version without this cannot load.lineStyledoes not apply to a pen stroke (it has no dashes), and neither does the straight line of the shift key.PressureStrokein memory is long (a stroke of 150 points is about 2600 commands), as the capsules are many small shapes. The canvas caches objects, so it is drawn from the cache.CHANGELOG.mdandSketchField.tsx, so the second of the two to merge needs a conflict resolution.