Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 31f58d86 authored by Mark Harman's avatar Mark Harman
Browse files

Fix crop guides in portrait orientation.

parent 658c159c
Loading
Loading
Loading
Loading
+32 −22
Original line number Diff line number Diff line
@@ -1008,18 +1008,27 @@ public class DrawPreview {
                        crop_ratio = 2.4;
                        break;
                }
                // we should compare to getCurrentPreviewAspectRatio() not getCurrentPreviewAspectRatio(), as the actual preview
                if( crop_ratio > 0.0 ) {
                    // we should compare to getCurrentPreviewAspectRatio() not getTargetRatio(), as the actual preview
                    // aspect ratio may differ to the requested photo/video resolution's aspect ratio, in which case it's still useful
                    // to display the crop guide
                if( crop_ratio > 0.0 && Math.abs(preview.getCurrentPreviewAspectRatio() - crop_ratio) > 1.0e-5 ) {
                    double preview_aspect_ratio = preview.getCurrentPreviewAspectRatio();
                    MainActivity.SystemOrientation system_orientation = main_activity.getSystemOrientation();
                    boolean system_orientation_portrait = system_orientation == MainActivity.SystemOrientation.PORTRAIT;
                    if( system_orientation_portrait ) {
                        // crop ratios are always drawn as if in landscape
                        crop_ratio = 1.0/crop_ratio;
                        preview_aspect_ratio = 1.0/preview_aspect_ratio;
                    }
                    if( Math.abs(preview_aspect_ratio - crop_ratio) > 1.0e-5 ) {
                        /*if( MyDebug.LOG ) {
                            Log.d(TAG, "crop_ratio: " + crop_ratio);
		    			Log.d(TAG, "preview_targetRatio: " + preview_targetRatio);
                            Log.d(TAG, "preview_aspect_ratio: " + preview_aspect_ratio);
                            Log.d(TAG, "canvas width: " + canvas.getWidth());
                            Log.d(TAG, "canvas height: " + canvas.getHeight());
                        }*/
                        int left = 1, top = 1, right = canvas.getWidth()-1, bottom = canvas.getHeight()-1;
                    if( crop_ratio > preview.getTargetRatio() ) {
                        if( crop_ratio > preview_aspect_ratio ) {
                            // crop ratio is wider, so we have to crop top/bottom
                            double new_hheight = ((double)canvas.getWidth()) / (2.0f*crop_ratio);
                            top = (canvas.getHeight()/2 - (int)new_hheight);
@@ -1033,6 +1042,7 @@ public class DrawPreview {
                        }
                        canvas.drawRect(left, top, right, bottom, p);
                    }
                }
                p.setStyle(Paint.Style.FILL); // reset
            }
        }