How exactly do I get zoom level in GUI?

While working on a re-engineering of a filter, I’d like to know how exactly can I get the zoom level. My goal is to be able to use point, and zoom level to accurately crop preview using selected image given code. The selection of image to be displayed is done in my GUI preview code.

Side note: Which gives me a idea, can we change what image is to be automatically displayed when using multiple layers and to have reference variables generated from? Like, if I coded the selected image to be displayed is #8, then preview will be using #8 image?

Also, it’d be nice to have new predefined GUI variables like _full_image_width, and _full_image_height which defines the width and height of the image that is being previewed on, but I don’t think that’s needed if I have a predefined variable that tells me what image is displayed on preview.

For this, use these pre-defined variables:

  • $_preview_x0: X-coordinate of the upper-left corner of the preview (expressed in the image space).
  • $_preview_y0: Y-coordinate of the upper-left corner of the preview (exressed in the image space).
  • $_preview_x1: X-coordinate of the lower-right corner of the preview (expressed in the image space).
  • $_preview_y1: Y-coordinate of the lower-right corner of the preview (expressed in the image space).

I know of these things. It doesn’t tell me how to get zoom level. And I definitely plan to have GUI preview displays output depending on whether I am previewing effect on gray or color or color-alpha or gray-alpha image. Hence my asking of a feature request which is a predefined variable to display a selected image before initialization of filter preview and get the preview[x|y][0|1]. Either that or zoom level.

Yes it does.
Knowing the (x0,y0)-(x1,y1) coordinates of the image region that is previewed on the preview widget is actually linked to the zoom level.

I gave it a bit of a try:

eval "
 const image_width = w#0 ; # Width of image being previewed
 const image_height = h#0 ; # Height of image being previewed
 const image_ratio = image_height / image_width ;
 const preview_area_width = ( $_preview_x1 - $_preview_x0) + 1  ;
 const preview_area_height = ( $_preview_y1 - $_preview_y0) + 1  ;
 const preview_ratio = preview_area_height / preview_area_width ;
 1 / ( preview_ratio < image_ratio ? preview_area_width / image_width : preview_area_height / image_height );
 "
crop $_preview_x0,$_preview_y0,$_preview_x1,$_preview_y1

The status in Code[Full] does not correspond to it.

This comes close:

norm(image_width,image_height) / norm(preview_area_width,preview_area_height) ;

But, maybe I’m thinking about my problem the wrong way.

Ok, let me clarify my goal.

My goal is using preview_crop coordinates in order to get the closest corresponding crop coordinates to another dimension while preserving ratio and relative size.

I think this is what I want and should have clarified from the beginning. But, while simple to state, this seem like a hard problem.


EDIT:

I think I decided to use point GUI element to get around the limitations of this and keep it at 1:1 crop.