UI: Changes to Zoom Menus #121044

Merged
Harley Acheson merged 7 commits from Harley/blender:ZoomMenus into main 2024-04-26 21:36:00 +02:00
4 changed files with 139 additions and 47 deletions

View File

@ -1287,23 +1287,29 @@ class CLIP_PT_tools_grease_pencil_draw(AnnotationDrawingToolsPanel, Panel):
class CLIP_MT_view_zoom(Menu):
bl_label = "Fractional Zoom"
bl_label = "Zoom"
def draw(self, _context):
layout = self.layout
from math import isclose
current_zoom = _context.space_data.zoom_percentage
ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
for i, (a, b) in enumerate(ratios):
if i in {3, 4}: # Draw separators around Zoom 1:1.
layout.separator()
percent = a / b * 100
layout.operator(
"clip.view_zoom_ratio",
text=iface_("Zoom %d:%d") % (a, b),
text=iface_("%g%% (%d:%d)") % (percent, a, b),
translate=False,
icon=('NONE', 'LAYER_ACTIVE')[isclose(percent, current_zoom, abs_tol=0.5)]
).ratio = a / b
layout.separator()
layout.operator("clip.view_zoom_in")
layout.operator("clip.view_zoom_out")
layout.operator("clip.view_all", text="Zoom to Fit").fit_view = True
class CLIP_MT_view(Menu):
bl_label = "View"
@ -1319,26 +1325,20 @@ class CLIP_MT_view(Menu):
layout.prop(sc, "show_region_hud")
layout.separator()
layout.operator("clip.view_selected")
layout.operator("clip.view_all")
layout.operator("clip.view_all", text="View Fit").fit_view = True
layout.operator("clip.view_center_cursor")
layout.menu("CLIP_MT_view_zoom")
layout.separator()
layout.operator("clip.view_zoom_in")
layout.operator("clip.view_zoom_out")
layout.separator()
layout.prop(sc, "show_metadata")
layout.separator()
layout.operator("clip.view_all")
layout.operator("clip.view_selected")
layout.operator("clip.view_center_cursor")
layout.menu("CLIP_MT_view_zoom")
else:
layout.operator_context = 'INVOKE_REGION_PREVIEW'
layout.operator("clip.graph_view_all")
if sc.view == 'GRAPH':
layout.operator("clip.graph_center_current_frame")
layout.operator("view2d.zoom_border", text="Zoom")
layout.operator_context = 'INVOKE_DEFAULT'
layout.separator()

View File

@ -83,29 +83,16 @@ class IMAGE_MT_view(Menu):
layout.prop(sima, "use_realtime_update")
layout.prop(uv, "show_metadata")
if paint.brush and (context.image_paint_object or sima.mode == 'PAINT'):
layout.prop(uv, "show_texpaint")
layout.prop(tool_settings, "show_uv_local_view", text="Show Same Material")
layout.separator()
layout.operator("image.view_zoom_in")
layout.operator("image.view_zoom_out")
layout.separator()
layout.menu("IMAGE_MT_view_zoom")
layout.separator()
if show_uvedit:
layout.operator("image.view_selected", text="Frame Selected")
layout.operator("image.view_all")
layout.operator("image.view_all", text="Frame All Fit").fit_view = True
layout.operator("image.view_center_cursor", text="Center View to Cursor")
layout.menu("IMAGE_MT_view_zoom")
layout.separator()
if show_render:
@ -118,27 +105,38 @@ class IMAGE_MT_view(Menu):
layout.operator("image.cycle_render_slot", text="Render Slot Cycle Previous").reverse = True
layout.separator()
if paint.brush and (context.image_paint_object or sima.mode == 'PAINT'):
layout.prop(uv, "show_texpaint")
layout.prop(tool_settings, "show_uv_local_view", text="Show Same Material")
layout.menu("INFO_MT_area")
class IMAGE_MT_view_zoom(Menu):
bl_label = "Fractional Zoom"
bl_label = "Zoom"
def draw(self, _context):
layout = self.layout
from math import isclose
current_zoom = _context.space_data.zoom_percentage
ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
for i, (a, b) in enumerate(ratios):
if i in {3, 4}: # Draw separators around Zoom 1:1.
layout.separator()
percent = a / b * 100
layout.operator(
"image.view_zoom_ratio",
text=iface_("Zoom %d:%d") % (a, b),
text=iface_("%g%% (%d:%d)") % (percent, a, b),
translate=False,
icon=('NONE', 'LAYER_ACTIVE')[isclose(percent, current_zoom, abs_tol=0.5)]
).ratio = a / b
layout.separator()
layout.operator("image.view_zoom_in")
layout.operator("image.view_zoom_out")
layout.operator("image.view_all", text="Zoom to Fit").fit_view = True
layout.operator("image.view_zoom_border", text="Zoom Region...")
class IMAGE_MT_select(Menu):
bl_label = "Select"

View File

@ -366,24 +366,30 @@ class SEQUENCER_MT_range(Menu):
class SEQUENCER_MT_preview_zoom(Menu):
bl_label = "Fractional Zoom"
bl_label = "Zoom"
def draw(self, _context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_PREVIEW'
from math import isclose
current_zoom = _context.space_data.zoom_percentage
ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
for i, (a, b) in enumerate(ratios):
if i in {3, 4}: # Draw separators around Zoom 1:1.
layout.separator()
percent = a / b * 100
layout.operator(
"sequencer.view_zoom_ratio",
text=iface_("Zoom %d:%d") % (a, b),
text=iface_("%g%% (%d:%d)") % (percent, a, b),
translate=False,
icon=('NONE', 'LAYER_ACTIVE')[isclose(percent, current_zoom, abs_tol=0.5)],
).ratio = a / b
layout.operator_context = 'INVOKE_DEFAULT'
layout.separator()
layout.operator("view2d.zoom_in")
layout.operator("view2d.zoom_out")
layout.operator("view2d.zoom_border", text="Zoom Region...")
class SEQUENCER_MT_proxy(Menu):
@ -444,7 +450,6 @@ class SEQUENCER_MT_view(Menu):
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("sequencer.view_all")
layout.operator("sequencer.view_frame")
layout.operator("view2d.zoom_border", text="Zoom to Border")
layout.prop(st, "use_clamp_view")
if is_preview:
@ -453,12 +458,10 @@ class SEQUENCER_MT_view(Menu):
layout.operator_context = 'INVOKE_REGION_PREVIEW'
layout.operator("sequencer.view_all_preview", text="Fit Preview in Window")
if is_sequencer_view:
layout.menu("SEQUENCER_MT_preview_zoom", text="Fractional Preview Zoom")
layout.menu("SEQUENCER_MT_preview_zoom", text="Preview Zoom")
else:
layout.operator("view2d.zoom_border", text="Zoom to Border")
layout.menu("SEQUENCER_MT_preview_zoom")
layout.prop(st, "use_zoom_to_fit")
layout.prop(st, "use_zoom_to_fit", text="Auto Zoom")
layout.separator()
layout.menu("SEQUENCER_MT_proxy")
layout.operator_context = 'INVOKE_DEFAULT'

View File

@ -1804,6 +1804,18 @@ static void rna_SpaceImageEditor_zoom_get(PointerRNA *ptr, float *values)
}
}
static float rna_SpaceImageEditor_zoom_percentage_get(PointerRNA *ptr)
{
SpaceImage *sima = (SpaceImage *)ptr->data;
return sima->zoom * 100.0f;
}
static void rna_SpaceImageEditor_zoom_percentage_set(PointerRNA *ptr, const float value)
{
SpaceImage *sima = (SpaceImage *)ptr->data;
sima->zoom = value / 100.0f;
}
static void rna_SpaceImageEditor_cursor_location_get(PointerRNA *ptr, float *values)
{
SpaceImage *sima = (SpaceImage *)ptr->data;
@ -2500,6 +2512,41 @@ static std::optional<std::string> rna_SpaceSequencerTimelineOverlay_path(
return "timeline_overlay";
}
static float rna_SpaceSequenceEditor_zoom_percentage_get(PointerRNA *ptr)
{
ScrArea *area = rna_area_from_space(ptr);
if (area == nullptr) {
return 100.0f;
}
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_PREVIEW);
if (region == nullptr) {
return 100.0f;
}
View2D *v2d = &region->v2d;
const float zoom = 1.0f / (BLI_rctf_size_x(&v2d->cur) / float(BLI_rcti_size_x(&v2d->mask))) *
+100.0f;
return zoom;
}
static void rna_SpaceSequenceEditor_zoom_percentage_set(PointerRNA *ptr, const float value)
{
ScrArea *area = rna_area_from_space(ptr);
if (area == nullptr) {
return;
}
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_PREVIEW);
if (region == nullptr) {
return;
}
View2D *v2d = &region->v2d;
BLI_rctf_resize(&v2d->cur,
float(BLI_rcti_size_x(&v2d->mask)) / (value / 100.0f),
float(BLI_rcti_size_y(&v2d->mask)) / (value / 100.0f));
ED_region_tag_redraw(region);
}
/* Space Node Editor */
static PointerRNA rna_SpaceNode_overlay_get(PointerRNA *ptr)
{
@ -2760,6 +2807,18 @@ static void rna_SpaceClipEditor_view_type_update(Main * /*bmain*/,
ED_area_tag_refresh(area);
}
static float rna_SpaceClipEditor_zoom_percentage_get(PointerRNA *ptr)
{
SpaceClip *sc = (SpaceClip *)ptr->data;
return sc->zoom * 100.0f;
}
static void rna_SpaceClipEditor_zoom_percentage_set(PointerRNA *ptr, const float value)
{
SpaceClip *sc = (SpaceClip *)ptr->data;
sc->zoom = value / 100.0f;
}
/* File browser. */
static std::optional<std::string> rna_FileSelectParams_path(const PointerRNA * /*ptr*/)
@ -5616,6 +5675,16 @@ static void rna_def_space_image(BlenderRNA *brna)
RNA_def_property_float_funcs(prop, "rna_SpaceImageEditor_zoom_get", nullptr, nullptr);
RNA_def_property_ui_text(prop, "Zoom", "Zoom factor");
prop = RNA_def_property(srna, "zoom_percentage", PROP_FLOAT, PROP_PERCENTAGE);
RNA_def_property_float_funcs(prop,
"rna_SpaceImageEditor_zoom_percentage_get",
"rna_SpaceImageEditor_zoom_percentage_set",
nullptr);
RNA_def_property_float_default(prop, 100.0);
RNA_def_property_range(prop, .4, 80000);
RNA_def_property_ui_range(prop, 25, 400, 100, 0);
RNA_def_property_ui_text(prop, "Zoom", "Zoom percentage");
/* image draw */
prop = RNA_def_property(srna, "show_repeat", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "flag", SI_DRAW_TILE);
@ -6104,6 +6173,17 @@ static void rna_def_space_sequencer(BlenderRNA *brna)
RNA_def_property_array(prop, 2);
RNA_def_property_ui_text(prop, "2D Cursor Location", "2D cursor location for this view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SEQUENCER, nullptr);
/* Zoom. */
prop = RNA_def_property(srna, "zoom_percentage", PROP_FLOAT, PROP_PERCENTAGE);
RNA_def_property_float_funcs(prop,
"rna_SpaceSequenceEditor_zoom_percentage_get",
"rna_SpaceSequenceEditor_zoom_percentage_set",
nullptr);
RNA_def_property_float_default(prop, 100.0);
RNA_def_property_range(prop, .4, 80000);
RNA_def_property_ui_range(prop, 25, 400, 100, 0);
RNA_def_property_ui_text(prop, "Zoom", "Zoom percentage");
}
static void rna_def_space_text(BlenderRNA *brna)
@ -8015,6 +8095,17 @@ static void rna_def_space_clip(BlenderRNA *brna)
RNA_def_property_boolean_negative_sdna(prop, nullptr, "gizmo_flag", SCLIP_GIZMO_HIDE_NAVIGATE);
RNA_def_property_ui_text(prop, "Navigate Gizmo", "Viewport navigation gizmo");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CLIP, nullptr);
/* Zoom. */
prop = RNA_def_property(srna, "zoom_percentage", PROP_FLOAT, PROP_PERCENTAGE);
RNA_def_property_float_funcs(prop,
"rna_SpaceClipEditor_zoom_percentage_get",
"rna_SpaceClipEditor_zoom_percentage_set",
nullptr);
RNA_def_property_float_default(prop, 100.0);
RNA_def_property_range(prop, .4f, 80000);
RNA_def_property_ui_range(prop, 25, 400, 100, 0);
RNA_def_property_ui_text(prop, "Zoom", "Zoom percentage");
}
static void rna_def_spreadsheet_column_id(BlenderRNA *brna)