viliusle / miniPaint

online image editor
http://viliusle.github.io/miniPaint/
Other
2.76k stars 638 forks source link

[Feature Request] Pen pressure support #179

Open Giwayume opened 4 years ago

Giwayume commented 4 years ago

https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure

For people with drawing tablets or other devices that have a compatible pen with pressure sensitivity, would be nice if the brush tool could take this into account when sizing instead of basing it off stroke speed. Any other tool that has an effect based on size would be a candidate.

viliusle commented 4 years ago

Change is easy, just replace this line with code below: https://github.com/viliusle/miniPaint/blob/master/src/js/tools/brush.js#L113

if(typeof e.pressure !== "undefined"){
    new_size = size * e.pressure * 2; //e.pressure has range [0 - 1]
}
else if (params.smart_brush == true) {

Sadly, i can not push, dont have any device with pressure support and can not test it.

If anybody could test it, i would implement it.

Giwayume commented 4 years ago

The variable only shows up on pointer events, like "pointermove". https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onpointermove

"pointermove" fires along-side "mousemove" and "touchmove", so you have to be careful not to handle the events twice.

Giwayume commented 4 years ago

I'm looking at it

Giwayume commented 4 years ago

Hmmm... looks like it's more complicated than checking e.pressure. There are some devices that have false positives, like I have a laptop with a touch screen that does not support pressure, but it always reports the value as "0.5".

There's a library called pressure.js that checks if the value is "0.5" in order to determine whether or not pressure is supported. https://github.com/stuyam/pressure/blob/323d8078f1b605d34da1b56a5d58f269acf0b042/src/adapters/adapter_pointer.js#L18

So it looks like that's a common problem.

Giwayume commented 4 years ago

I'd say what's left on this is:

viliusle commented 4 years ago

I could agree, but we will have problem, where i will not be able even to touch that code without physical device for testing pressure. Already happened with brush, i implemented line smoothing and broke your code. Lets hold with it for now.

Giwayume commented 4 years ago

If you're interested, drawing pads are relatively cheap. Takes some getting used to with hand eye coordination though.

https://www.amazon.com/StarG640-Ultrathin-Graphics-Battery-Free-Pressure/dp/B078YR2MTF/

viliusle commented 4 years ago

i will check if it is possible to use:

viliusle commented 3 years ago

@Giwayume what is your opinion on pressure feature on pencil tool? I have requests on it.

personally believe that pencil is tool is only for precise/accurate edits when zoomed in. And if you want pressure here, brush should be used instead.

Giwayume commented 3 years ago

I think you'd need to consider the future of these tools.

Photoshop kind of created this pencil/brush tool convention, so far as I know. In Photoshop, whatever source image is used for the brush is essentially given a hard pixel edge when used in the pencil tool (pixels that were semi-transparent are fully opaque instead).

image

Left: pencil, Right: brush, same brush image.

In minipaint the brush creates a vector arc line instead of using a raster image as base, so you're limited to a circular brush but the lines are pefect.

To me it makes more sense to ditch the pencil/brush convention and have something more like raster brush & vector brush. I wouldn't use those exact names, but that's just to give the idea. The raster brush works like Photoshop pencil/brush tool where what you draw is based on a bitmap source image, and you can have a setting to switch hard edges on/off to simulate the difference between pencil/brush tool. Vector brush would be the current brush tool, with maybe more shape options down the line.

wbuk commented 3 years ago

We need to Pencil tool to be pressure-sensitive as well as the brush tool. Please can this be added to the list?

viliusle commented 2 years ago

Can anybody test pressure support on real device using "pencil" tool on latest code from master?

Related commit: https://github.com/viliusle/miniPaint/commit/dae340d0eae3b4ed2c0a894f9b423198e08a3baf

wbuk commented 2 years ago

Yes, we can.  I can do it tomorrow. 

⁣Sent from BlueMail ​

On 14 Mar 2022, 19:23, at 19:23, Vilius @.***> wrote:

Can anybody test pressure support on real device using "pencil" tool on latest code from master?

Related commit: https://github.com/viliusle/miniPaint/commit/dae340d0eae3b4ed2c0a894f9b423198e08a3baf

-- Reply to this email directly or view it on GitHub: https://github.com/viliusle/miniPaint/issues/179#issuecomment-1067199599 You are receiving this because you commented.

Message ID: @.***>

wbuk commented 2 years ago

Is it on the mini paint site?  I can test it tomorrow.

⁣Sent from BlueMail ​

On 14 Mar 2022, 19:23, at 19:23, Vilius @.***> wrote:

Can anybody test pressure support on real device using "pencil" tool on latest code from master?

Related commit: https://github.com/viliusle/miniPaint/commit/dae340d0eae3b4ed2c0a894f9b423198e08a3baf

-- Reply to this email directly or view it on GitHub: https://github.com/viliusle/miniPaint/issues/179#issuecomment-1067199599 You are receiving this because you commented.

Message ID: @.***>

viliusle commented 2 years ago

no, only on github master branch

wbuk commented 2 years ago

Ok.  We van test on saturday as our installer is away until then

⁣Sent from BlueMail ​

On 14 Mar 2022, 21:27, at 21:27, Vilius @.***> wrote:

no, only on github master branch

-- Reply to this email directly or view it on GitHub: https://github.com/viliusle/miniPaint/issues/179#issuecomment-1067312820 You are receiving this because you commented.

Message ID: @.***>

Giwayume commented 2 years ago

It's working like the brush tool. Might want to make pressure toggle-able like the brush, otherwise a pen user will have little control if they want an exact size.