Skip to content

Commit ff3b172

Browse files
authored
Consistent UI
1 parent 3c676bf commit ff3b172

File tree

1 file changed

+104
-93
lines changed

1 file changed

+104
-93
lines changed

dof-utils.py

Lines changed: 104 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"name": "Depth of Field Utilities",
2121
"author": "Christian Brinkmann (p2or)",
2222
"description": "Displays depth of field in 3D view port.",
23-
"version": (0, 0, 9),
23+
"version": (0, 1, 0),
2424
"blender": (2, 80, 0),
2525
"location": "3d View > Properties Panel (N) > Depth of Field Utilities",
2626
"wiki_url": "https://github.com/p2or/blender-dof-utils",
@@ -42,7 +42,7 @@
4242
# Preferences & Scene Properties
4343
# ------------------------------------------------------------------------
4444

45-
class DofUtilsPreferences(bpy.types.AddonPreferences):
45+
class DOFU_AP_preferences(bpy.types.AddonPreferences):
4646

4747
bl_idname = __name__
4848

@@ -63,7 +63,7 @@ def draw(self, context):
6363
layout.row().operator("dof_utils.reset_preferences", icon='FILE_REFRESH')
6464

6565

66-
class DofUtilsSettings(bpy.types.PropertyGroup):
66+
class DOFU_PG_settings(bpy.types.PropertyGroup):
6767

6868
_visualize_handle = None
6969
_instructions_handle = None
@@ -398,7 +398,7 @@ def draw_circle(matrix, radius=.1, num_segments=16, offset=0, offset_axis="Z", c
398398
# Operators
399399
# ------------------------------------------------------------------------
400400

401-
class DofUtilsFocusPicking(bpy.types.Operator):
401+
class DOFU_OT_focusPicking(bpy.types.Operator):
402402
"""Sets the focus distance by using the 3d cursor"""
403403
bl_idname = "dof_utils.focus_picking"
404404
bl_label = "Set Focus using 3d Cursor"
@@ -428,8 +428,8 @@ def modal(self, context, event):
428428
# Set cursor tool
429429
bpy.ops.wm.tool_set_by_id(name ="builtin.cursor")
430430
except:
431-
bpy.types.SpaceView3D.draw_handler_remove(DofUtilsSettings._instructions_handle, 'WINDOW')
432-
DofUtilsSettings._instructions_handle = None
431+
bpy.types.SpaceView3D.draw_handler_remove(DOFU_PG_settings._instructions_handle, 'WINDOW')
432+
DOFU_PG_settings._instructions_handle = None
433433
context.scene.dof_utils.use_cursor = False
434434
return {'CANCELLED'}
435435

@@ -442,8 +442,8 @@ def modal(self, context, event):
442442
elif event.type in {'RIGHTMOUSE', 'ESC'} or not dofu.use_cursor:
443443
dofu.use_cursor = False
444444
try:
445-
bpy.types.SpaceView3D.draw_handler_remove(DofUtilsSettings._instructions_handle, 'WINDOW')
446-
DofUtilsSettings._instructions_handle = None
445+
bpy.types.SpaceView3D.draw_handler_remove(DOFU_PG_settings._instructions_handle, 'WINDOW')
446+
DOFU_PG_settings._instructions_handle = None
447447
except:
448448
pass
449449
# Reset to selected tool before running the operator
@@ -464,9 +464,9 @@ def invoke(self, context, event):
464464
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
465465
self._tool = ToolSelectPanelHelper.tool_active_from_context(context).idname
466466

467-
if prefs.display_info and not DofUtilsSettings._instructions_handle:
467+
if prefs.display_info and not DOFU_PG_settings._instructions_handle:
468468
args = (self, context)
469-
DofUtilsSettings._instructions_handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d, args, 'WINDOW', 'POST_PIXEL')
469+
DOFU_PG_settings._instructions_handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d, args, 'WINDOW', 'POST_PIXEL')
470470

471471
context.window_manager.modal_handler_add(self)
472472
dofu.use_cursor = True
@@ -479,7 +479,7 @@ def invoke(self, context, event):
479479
return {'CANCELLED'}
480480

481481

482-
class DofUtilsVisualizeLimits(bpy.types.Operator):
482+
class DOFU_OT_visualizeLimits(bpy.types.Operator):
483483
""" Draws depth of field in the viewport via OpenGL """
484484
bl_idname = "dof_utils.visualize_dof"
485485
bl_label = "Visualize Depth of Field"
@@ -508,10 +508,10 @@ def modal(self, context, event):
508508
if event.type in {'RIGHTMOUSE', 'ESC'} or not dofu.draw_dof:
509509
dofu.draw_dof = False
510510
try: # TODO, viewport class
511-
bpy.types.SpaceView3D.draw_handler_remove(DofUtilsSettings._visualize_handle, 'WINDOW')
512-
bpy.types.SpaceView3D.draw_handler_remove(DofUtilsSettings._instructions_handle, 'WINDOW')
513-
DofUtilsSettings._instructions_handle = None
514-
DofUtilsSettings._visualize_handle = None
511+
bpy.types.SpaceView3D.draw_handler_remove(DOFU_PG_settings._visualize_handle, 'WINDOW')
512+
bpy.types.SpaceView3D.draw_handler_remove(DOFU_PG_settings._instructions_handle, 'WINDOW')
513+
DOFU_PG_settings._instructions_handle = None
514+
DOFU_PG_settings._visualize_handle = None
515515
except:
516516
pass
517517
if context.area is not None:
@@ -529,10 +529,10 @@ def invoke(self, context, event):
529529
if context.area.type == 'VIEW_3D':
530530
args = (self, context)
531531
# Add the region OpenGL drawing callback, draw in view space with 'POST_VIEW' and 'PRE_VIEW'
532-
DofUtilsSettings._visualize_handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_3d, args, 'WINDOW', 'POST_VIEW')
532+
DOFU_PG_settings._visualize_handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_3d, args, 'WINDOW', 'POST_VIEW')
533533

534-
if prefs.display_info and not DofUtilsSettings._instructions_handle:
535-
DofUtilsSettings._instructions_handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d, args, 'WINDOW', 'POST_PIXEL')
534+
if prefs.display_info and not DOFU_PG_settings._instructions_handle:
535+
DOFU_PG_settings._instructions_handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d, args, 'WINDOW', 'POST_PIXEL')
536536

537537
context.window_manager.modal_handler_add(self)
538538
dofu.draw_dof = True
@@ -547,7 +547,7 @@ def invoke(self, context, event):
547547
return {'CANCELLED'}
548548

549549

550-
class DofUtilsKillVisualization(bpy.types.Operator):
550+
class DOFU_OT_killVisualisation(bpy.types.Operator):
551551
""" Kill Visualization """
552552
bl_idname = "dof_utils.kill_visualization"
553553
bl_label = "Kill Visualization"
@@ -558,7 +558,7 @@ def execute(self, context):
558558
return {'FINISHED'}
559559

560560

561-
class DofUtilsKillFocusPicking(bpy.types.Operator):
561+
class DOFU_OT_killFocusPicking(bpy.types.Operator):
562562
""" Kill Focus Picking """
563563
bl_idname = "dof_utils.kill_focus_picking"
564564
bl_label = "Kill Visualization"
@@ -569,7 +569,7 @@ def execute(self, context):
569569
return {'FINISHED'}
570570

571571

572-
class DofUtilsResetViewport(bpy.types.Operator):
572+
class DOFU_OT_viewportReset(bpy.types.Operator):
573573
""" Reset Viewport """
574574
bl_idname = "dof_utils.reset_viewport"
575575
bl_label = "Reset Viewport"
@@ -578,17 +578,17 @@ class DofUtilsResetViewport(bpy.types.Operator):
578578
# TODO, viewport class
579579
def execute(self, context):
580580
try:
581-
DofUtilsSettings._instructions_handle = None
582-
DofUtilsSettings._visualize_handle = None
583-
bpy.types.SpaceView3D.draw_handler_remove(DofUtilsSettings._instructions_handle, 'WINDOW')
584-
bpy.types.SpaceView3D.draw_handler_remove(DofUtilsSettings._visualize_handle, 'WINDOW')
581+
DOFU_PG_settings._instructions_handle = None
582+
DOFU_PG_settings._visualize_handle = None
583+
bpy.types.SpaceView3D.draw_handler_remove(DOFU_PG_settings._instructions_handle, 'WINDOW')
584+
bpy.types.SpaceView3D.draw_handler_remove(DOFU_PG_settings._visualize_handle, 'WINDOW')
585585

586586
except:
587587
pass
588588
return {'FINISHED'}
589589

590590

591-
class DofUtilsResetPreferences(bpy.types.Operator):
591+
class DOFU_OT_preferencesReset(bpy.types.Operator):
592592
""" Reset Add-on Preferences """
593593
bl_idname = "dof_utils.reset_preferences"
594594
bl_label = "Reset Properties and Settings"
@@ -613,101 +613,112 @@ def execute(self, context):
613613
# UI
614614
# ------------------------------------------------------------------------
615615

616-
class DOFU_PT_main_panel(bpy.types.Panel):
617-
bl_label = "Depth of Field Utilities"
616+
class DOFU_panel:
618617
bl_space_type = "VIEW_3D"
619618
bl_region_type = "UI"
620619
bl_category = "DoF Utils"
621620

622621
@classmethod
623622
def poll(cls, context):
624-
#rd = context.scene.render
625-
return is_camera(context.object)# and rd.engine == "CYCLES"
623+
return is_camera(context.object)
624+
625+
626+
class DOFU_PT_main_panel(DOFU_panel, bpy.types.Panel):
627+
bl_label = "Depth of Field"
628+
bl_category = "DoF Utils"
626629

630+
def draw_header(self, context):
631+
self.layout.prop(context.active_object.data.dof, "use_dof", text="")
632+
627633
def draw(self, context):
628-
scene = context.scene
629-
dofu = scene.dof_utils #cam_ob = scene.camera.data
634+
dofu = context.scene.dof_utils #cam_ob = scene.camera.data
630635
cam_ob = context.active_object.data
631-
#ccam = cam_ob.cycles
632636

633-
row = self.layout.row()
634-
row.prop(cam_ob.dof, "use_dof", text="Enable Depth of Field", toggle=True)
635-
self.layout.separator()
637+
layout = self.layout
638+
layout.use_property_split = True
636639

637-
col = self.layout.column(align=True)
638-
row = col.row(align=True)
639-
viz = row.row(align=True)
640+
layout.active = cam_ob.dof.use_dof
641+
active_flag = not dofu.use_cursor and cam_ob.dof.focus_object is None
642+
643+
# Visualize
644+
row = layout.row(align=True)
645+
viz = row.column(align=True)
640646
viz.enabled = not dofu.draw_dof # enabled
641647
viz.operator("dof_utils.visualize_dof", icon="SNAP_NORMAL" if not dofu.draw_dof else "REC")
642-
row = row.row(align=True)
648+
row = row.column(align=True)
643649
row.operator("dof_utils.kill_visualization", icon="X", text="")
644650

645-
row = col.row(align=True)
646-
#split = row.split(.07, align=True)
647-
row.prop(dofu, "color_limits", text="")
648-
#row = split.row(align=True)
649-
650-
row = col.row(align=True)
651-
row.prop(dofu, "size_limits")
652-
row.prop(dofu, "opacity_limits")
653-
row.prop(dofu, "segments_limits")
654-
#row.prop(dofu, "fill_limits", text="", icon="META_EMPTY")
655-
656-
row = col.row(align=True)
657-
row.prop(dofu, "overlay", text="Overlay Limits", toggle=True, icon="GHOST_ENABLED")
658-
row.prop(dofu, "draw_focus", toggle=True, icon="FORCE_FORCE")
659-
#row.prop(dofu, "fill_limits", text="", icon="PROP_ON")
660-
#row = col.row(align=True)
661-
#row.prop(dofu, "fill_limits", text="Reset", icon="FILE_REFRESH")
662-
663-
col = self.layout.column(align=True)
664-
col.label(text="Aperture:")
665-
row = col.row(align=True)
666-
#row.prop(ccam, "aperture_type", expand=True)
667-
# Following lines rem as radius option not exist
668-
#if ccam.aperture_type == 'RADIUS':
669-
# col.prop(ccam, "aperture_size", text="Size")
670-
#elif ccam.aperture_type == 'FSTOP':
671-
col.prop(cam_ob.dof, "aperture_fstop", text="Number")
672-
673-
col = self.layout.column(align=True)
674-
col.label(text="Focus:")
675-
row = col.row(align=True)
676-
pic = row.row(align=True)
677-
active_flag = not dofu.use_cursor and cam_ob.dof.focus_object is None
651+
# Focus Picking
652+
row = layout.row(align=True)
653+
pic = row.column(align=True)
678654
pic.enabled = active_flag # enabled
679655
pic.operator("dof_utils.focus_picking", icon="RESTRICT_SELECT_OFF" if active_flag or cam_ob.dof.focus_object else "REC")
680-
row = row.row(align=True) #layout.prop_search(dofu, "camera", bpy.data, "cameras")
656+
row = row.column(align=True) #layout.prop_search(dofu, "camera", bpy.data, "cameras")
681657
row.enabled = cam_ob.dof.focus_object is None
682658
row.operator("dof_utils.kill_focus_picking", icon="X", text="")
683-
row = col.row(align=True)
684-
dis = row.row(align=True)
659+
660+
661+
class DOFU_PT_camera(DOFU_panel, bpy.types.Panel):
662+
bl_label = "Camera Settings"
663+
bl_parent_id = "DOFU_PT_main_panel"
664+
665+
def draw(self, context):
666+
dofu = context.scene.dof_utils #cam_ob = scene.camera.data
667+
cam_ob = context.active_object.data
668+
active_flag = not dofu.use_cursor and cam_ob.dof.focus_object is None
669+
670+
layout = self.layout
671+
layout.use_property_split = True
672+
layout.active = cam_ob.dof.use_dof
673+
674+
col = layout.column()
675+
col.prop(cam_ob.dof, "aperture_fstop", text="F-Stop")
676+
dis = col.column()
685677
dis.enabled = active_flag # active
686-
dis.prop(cam_ob.dof, "focus_distance", text="Distance")
687-
col.prop(cam_ob.dof, "focus_object", text="")
678+
dis.prop(cam_ob.dof, "focus_distance", text="Focus Distance")
679+
col.prop(cam_ob, "lens")
680+
col.prop(cam_ob.dof, "focus_object", text="Focus Object")
681+
layout.separator()
682+
683+
684+
class DOFU_PT_visualize(DOFU_panel, bpy.types.Panel):
685+
bl_label = "Visualisation Options"
686+
bl_parent_id = "DOFU_PT_main_panel"
687+
688+
def draw(self, context):
689+
dofu = context.scene.dof_utils #cam_ob = scene.camera.data
690+
691+
layout = self.layout
692+
layout.use_property_split = True
693+
layout.active = context.active_object.data.dof.use_dof
688694

689-
col = self.layout.column(align=True)
690-
cam_info = ["Cam: {}".format(cam_ob.name)]
691-
if cam_ob.type == "PERSP":
692-
cam_info.append(" Lens: {:.2f}mm".format(cam_ob.lens))
693-
col.label(text=",".join(cam_info))
694-
self.layout.separator()
695+
col = layout.column()
696+
col.prop(dofu, "color_limits", text="Color")
697+
col.prop(dofu, "size_limits")
698+
col.prop(dofu, "opacity_limits")
699+
col.prop(dofu, "segments_limits")
700+
col = layout.column()
701+
col.prop(dofu, "overlay", text="Overlay Limits")#, toggle=True, icon="GHOST_ENABLED")
702+
col.prop(dofu, "draw_focus") #, toggle=True, icon="FORCE_FORCE")
703+
layout.separator()
695704

696705

697706
# ------------------------------------------------------------------------
698707
# Registration
699708
# ------------------------------------------------------------------------
700709

701710
classes = (
702-
DofUtilsPreferences,
703-
DofUtilsFocusPicking,
704-
DofUtilsVisualizeLimits,
705-
DofUtilsKillVisualization,
706-
DofUtilsKillFocusPicking,
707-
DofUtilsResetViewport,
708-
DofUtilsResetPreferences,
711+
DOFU_AP_preferences,
712+
DOFU_PG_settings,
713+
DOFU_OT_focusPicking,
714+
DOFU_OT_visualizeLimits,
715+
DOFU_OT_killVisualisation,
716+
DOFU_OT_killFocusPicking,
717+
DOFU_OT_viewportReset,
718+
DOFU_OT_preferencesReset,
709719
DOFU_PT_main_panel,
710-
DofUtilsSettings
720+
DOFU_PT_camera,
721+
DOFU_PT_visualize
711722
)
712723

713724

@@ -716,7 +727,7 @@ def register():
716727
for cls in classes:
717728
register_class(cls)
718729

719-
bpy.types.Scene.dof_utils = bpy.props.PointerProperty(type=DofUtilsSettings)
730+
bpy.types.Scene.dof_utils = bpy.props.PointerProperty(type=DOFU_PG_settings)
720731

721732
def unregister():
722733
bpy.ops.dof_utils.reset_preferences()

0 commit comments

Comments
 (0)