alnitak / magnifying_glass

Flutter real-time magnifying glass lens widget with Barrel/Pincushion distortion
Apache License 2.0
19 stars 3 forks source link

web support #4

Closed jtkeyva closed 1 year ago

jtkeyva commented 1 year ago

hi thanks for this cool package. wondering if there are any plans or if it's even possible to work on web? thanks

alnitak commented 1 year ago

Hi @jtkeyva and thanks. since it uses C and Dart:ffi this is not yet possible sorry! I should rewrite using plain Dart with a CustomPainter I think

jtkeyva commented 1 year ago

got it thanks. i'll provide a donation if you do so :) ilm looking to make content seem like it's wrapped around a sphere and this is the closest i've found

alnitak commented 1 year ago

Hi @jtkeyva I have rewritten the C code to Dart! Well, it works nicely :) Let me know!

jtkeyva commented 1 year ago

@alnitak wow very impressive, great job! that was quick work :) i want to try it in my application more thoroughly but have a couple questions before i go too far.

I noticed if i put the magnifier over the sliders and move them, it doesn't show them moving in the magnifier. the way i want to use it may be a bit different than intended.

what i'm trying to do is create a permanent fish-eye lens effect the the center of my page. i have an interactive widget or 2d scrollable grid view behind it similar to this: https://dartpad.dev/?id=4424936c57ed13093eb389123383e894

and then when i scroll/pan around i want to see the items in the center to be magnified in realtime. i will also need to be able to interact with the grid. so not sure if the magnifier can show moving widgets under it in realtime and not sure if i can click on widgets under/through the magnifier.

thanks!

jtkeyva commented 1 year ago

Update: I tried to increase the diameter to 1,000 and it is very slow and choppy. not sure if this can be fixed as i can see how this may be very resource intensive. again, my use case may be beyond the scope but i was hoping to have essentially a full-screen magnifier. so full-screen that you can't even see the circle, just the magnified portion 🤡

alnitak commented 1 year ago

Hi @jtkeyva and thanks! I have to make a premise on how the plugin works. When you press the button to show the glass: 1) the screen is grabbed and stored into a bitmap 2) 2 matrices containing X and Y lens distortions is computed, each with diameter^2 dimension 3) taking care of 2) the lens bitmap is computed and displayed

So when you move the glass, 3) is executed and the new bitmap is displayed inside the lens widget. If you change something in the screen widget (sliders, scrolling widgets, resizing window app etc.), you should go back to 1)

As you can see the computation power increases when you rise the diameter, and a diameter of 1000 takes a bitmap of 1000x1000x4 (4 are the RGBA pixel colors). This is the lag you notice and this when you need only 3). If you also need to update background image and hence restart from 1), the lag could be unacceptable :)

That said, I don't think this package is useful for your purpose. Maybe something more performant could be made using shaders, but the only drawback is that you can't have a circle shader widget, only rectangles without transparent zones.

jtkeyva commented 1 year ago

@alnitak thank you for the thorough response :) i will certainly be using your package for static visual purposes. as for my other intended purpose, i figured it wouldn't be so simple and perhaps flutter wouldn't be best for that anyhow.

great job on the package and i look forward to your other creations!

alnitak commented 1 year ago

@jtkeyva thanks to you! Closing this, but relatively to "other creation" I am into this if you like audio :)

jtkeyva commented 1 year ago

@alnitak thank you, very cool! please check your email ;)