cathoderaydude / Babel

A simple translation tool for on-screen text using Google Cloud Vision and Translate. Intended for translating emulated videogames and similar things.
MIT License
2 stars 0 forks source link

Enable scaling #21

Open cathoderaydude opened 4 years ago

cathoderaydude commented 4 years ago

Scaling the image with Ctrl+Mousewheel and Ctrl+ (+ / -) should be an option. I initially thought this was too hard but have realized it can be implemented with caveats. Notes:

I tested scaling the pbx and yeah, unsurprisingly onpaint does not know the scaling occurred. Thinking about it however, I think we could implement this in a fairly clever way.

PictureBox has a StretchImage mode which will automatically scale the image buffer to fit the control. However, since all our graphics code is in OnPaint, and it refers to the underlying image (via coordinates from the AsyncOCR object), it draws unscaled, because OnPaint occurs after the control has drawn the image scaled.

If, instead, we point the pbx to the 'edit' image buffer, and tell our paint routine to draw directly into that image, when the pbx renders it, all our drawn boxes and text will be scaled along with it. There are two issues:

  1. Editing an image is slower than OnPaint, as we discovered - but unless/until we figure this out, we could simply allow scaled mode as a slow-path option and 1:1 mode as fast-path.

  2. We need to adapt all mouse input to the scale factor, which shouldn't be that hard - if the scale factor is 50%, we literally divide the mouse position by 2 and we should be golden.