Properties Editor: Grease Pencil and pinning fixes

The UI was trying to use screen_context.c for its poll and draw
functions. So the active object and active object data and active layer
was used in the UI, instead of the context one.

Besides, for the material, the wrong context path was used altogether
when the active object was a greasepencil.

This would lead to all sort of pinning problems:

* A Mesh panel is pinned, but the active object is a grease pencil, the
grease pencil panels would show.

* If a Grease Pencil (data) panel is pinned, but the active object is not
the one pinned, nothing would show.

* Material panels and pinning were totally broken, showing the material
context for pinned mesh data panels even.

I also sanitized the name of the panels, their inheritance and poll
functions.

Reviewers: antoniov, brecht

Subscribers: billrey

Differential Revision: https://developer.blender.org/D4470
This commit is contained in:
Dalai Felinto
2019-03-07 14:55:03 +00:00
parent 81a09628c2
commit 92d185faeb
6 changed files with 172 additions and 218 deletions

View File

@@ -1613,7 +1613,8 @@ class CYCLES_MATERIAL_PT_preview(CyclesButtonsPanel, Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.material and CyclesButtonsPanel.poll(context) mat = context.material
return mat and (not mat.grease_pencil) and CyclesButtonsPanel.poll(context)
def draw(self, context): def draw(self, context):
self.layout.template_preview(context.material) self.layout.template_preview(context.material)
@@ -1625,7 +1626,8 @@ class CYCLES_MATERIAL_PT_surface(CyclesButtonsPanel, Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.material and CyclesButtonsPanel.poll(context) mat = context.material
return mat and (not mat.grease_pencil) and CyclesButtonsPanel.poll(context)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@@ -1643,7 +1645,7 @@ class CYCLES_MATERIAL_PT_volume(CyclesButtonsPanel, Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
mat = context.material mat = context.material
return mat and mat.node_tree and CyclesButtonsPanel.poll(context) return mat and (not mat.grease_pencil) and mat.node_tree and CyclesButtonsPanel.poll(context)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@@ -1661,7 +1663,7 @@ class CYCLES_MATERIAL_PT_displacement(CyclesButtonsPanel, Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
mat = context.material mat = context.material
return mat and mat.node_tree and CyclesButtonsPanel.poll(context) return mat and (not mat.grease_pencil) and mat.node_tree and CyclesButtonsPanel.poll(context)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@@ -1677,7 +1679,8 @@ class CYCLES_MATERIAL_PT_settings(CyclesButtonsPanel, Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.material and CyclesButtonsPanel.poll(context) mat = context.material
return mat and (not mat.grease_pencil) and CyclesButtonsPanel.poll(context)
@staticmethod @staticmethod
def draw_shared(self, mat): def draw_shared(self, mat):

View File

@@ -35,7 +35,7 @@ class DataButtonsPanel:
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.gpencil_data return context.gpencil
class ObjectButtonsPanel: class ObjectButtonsPanel:
@@ -45,7 +45,8 @@ class ObjectButtonsPanel:
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.object and context.object.type == 'GPENCIL' ob = context.object
return ob and ob.type == 'GPENCIL'
class LayerDataButtonsPanel: class LayerDataButtonsPanel:
@@ -55,24 +56,28 @@ class LayerDataButtonsPanel:
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return (context.gpencil_data and gpencil = context.gpencil
context.active_gpencil_layer) return gpencil and gpencil.layers.active
############################### ###############################
# GP Object Properties Panels and Helper Classes # GP Object Properties Panels and Helper Classes
class DATA_PT_gpencil(DataButtonsPanel, Panel): class DATA_PT_context_gpencil(DataButtonsPanel, Panel):
bl_label = "" bl_label = ""
bl_options = {'HIDE_HEADER'} bl_options = {'HIDE_HEADER'}
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
# Grease Pencil data selector ob = context.object
gpd_owner = context.gpencil_data_owner gpencil = context.gpencil
space = context.space_data
layout.template_ID(gpd_owner, "data") if ob:
layout.template_ID(ob, "data")
else:
layout.template_ID(space, "pin_id")
class GPENCIL_MT_layer_specials(Menu): class GPENCIL_MT_layer_specials(Menu):
@@ -80,7 +85,7 @@ class GPENCIL_MT_layer_specials(Menu):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
gpd = context.gpencil_data gpd = context.gpencil
layout.operator("gpencil.layer_duplicate", icon='ADD') # XXX: needs a dedicated icon layout.operator("gpencil.layer_duplicate", icon='ADD') # XXX: needs a dedicated icon
@@ -103,23 +108,15 @@ class GPENCIL_MT_layer_specials(Menu):
layout.menu("VIEW3D_MT_gpencil_copy_layer") layout.menu("VIEW3D_MT_gpencil_copy_layer")
class DATA_PT_gpencil_datapanel(Panel): class DATA_PT_gpencil_layers(DataButtonsPanel, Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_label = "Layers" bl_label = "Layers"
@classmethod
def poll(cls, context):
return context.gpencil_data
@staticmethod
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
#layout.use_property_split = True #layout.use_property_split = True
layout.use_property_decorate = False layout.use_property_decorate = False
gpd = context.gpencil_data gpd = context.gpencil
# Grease Pencil data... # Grease Pencil data...
if (gpd is None) or (not gpd.layers): if (gpd is None) or (not gpd.layers):
@@ -136,7 +133,8 @@ class DATA_PT_gpencil_datapanel(Panel):
col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index", col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
rows=layer_rows, sort_reverse=True, sort_lock=True) rows=layer_rows, sort_reverse=True, sort_lock=True)
gpl = context.active_gpencil_layer gpl = gpd.layers.active
if gpl: if gpl:
srow = col.row(align=True) srow = col.row(align=True)
srow.prop(gpl, "blend_mode", text="Blend") srow.prop(gpl, "blend_mode", text="Blend")
@@ -172,12 +170,9 @@ class DATA_PT_gpencil_datapanel(Panel):
sub.operator("gpencil.layer_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True sub.operator("gpencil.layer_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
class DATA_PT_gpencil_layer_optionpanel(LayerDataButtonsPanel, Panel): class DATA_PT_gpencil_layer_adjustments(LayerDataButtonsPanel, Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_label = "Adjustments" bl_label = "Adjustments"
bl_parent_id = 'DATA_PT_gpencil_datapanel' bl_parent_id = 'DATA_PT_gpencil_layers'
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
def draw(self, context): def draw(self, context):
@@ -185,7 +180,8 @@ class DATA_PT_gpencil_layer_optionpanel(LayerDataButtonsPanel, Panel):
layout.use_property_split = True layout.use_property_split = True
scene = context.scene scene = context.scene
gpl = context.active_gpencil_layer gpd = context.gpencil
gpl = gpd.layers.active
layout.active = not gpl.lock layout.active = not gpl.lock
# Layer options # Layer options
@@ -209,12 +205,9 @@ class DATA_PT_gpencil_layer_optionpanel(LayerDataButtonsPanel, Panel):
col.prop(gpl, "lock_material") col.prop(gpl, "lock_material")
class DATA_PT_gpencil_parentpanel(LayerDataButtonsPanel, Panel): class DATA_PT_gpencil_layer_relations(LayerDataButtonsPanel, Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_label = "Relations" bl_label = "Relations"
bl_parent_id = 'DATA_PT_gpencil_datapanel' bl_parent_id = 'DATA_PT_gpencil_layers'
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
def draw(self, context): def draw(self, context):
@@ -222,7 +215,9 @@ class DATA_PT_gpencil_parentpanel(LayerDataButtonsPanel, Panel):
layout.use_property_split = True layout.use_property_split = True
layout.use_property_decorate = False layout.use_property_decorate = False
gpl = context.active_gpencil_layer gpd = context.gpencil
gpl = gpd.layers.active
col = layout.column() col = layout.column()
col.active = not gpl.lock col.active = not gpl.lock
col.prop(gpl, "parent") col.prop(gpl, "parent")
@@ -233,19 +228,12 @@ class DATA_PT_gpencil_parentpanel(LayerDataButtonsPanel, Panel):
col.prop_search(gpl, "parent_bone", parent.data, "bones", text="Bone") col.prop_search(gpl, "parent_bone", parent.data, "bones", text="Bone")
class DATA_PT_gpencil_onionpanel(Panel): class DATA_PT_gpencil_onion_skinning(DataButtonsPanel, Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_label = "Onion Skinning" bl_label = "Onion Skinning"
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return bool(context.active_gpencil_layer)
def draw(self, context): def draw(self, context):
gpd = context.gpencil_data gpd = context.gpencil
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
@@ -268,21 +256,18 @@ class DATA_PT_gpencil_onionpanel(Panel):
col.prop(gpd, "ghost_after_range", text="Keyframes After") col.prop(gpd, "ghost_after_range", text="Keyframes After")
class DATA_PT_gpencil_onionpanel_custom_colors(Panel): class DATA_PT_gpencil_onion_skinning_custom_colors(DataButtonsPanel, Panel):
bl_space_type = 'PROPERTIES' bl_parent_id = "DATA_PT_gpencil_onion_skinning"
bl_region_type = 'WINDOW'
bl_context = "data"
bl_parent_id = "DATA_PT_gpencil_onionpanel"
bl_label = "Custom Colors" bl_label = "Custom Colors"
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
def draw_header(self, context): def draw_header(self, context):
gpd = context.gpencil_data gpd = context.gpencil
self.layout.prop(gpd, "use_ghost_custom_colors", text="") self.layout.prop(gpd, "use_ghost_custom_colors", text="")
def draw(self, context): def draw(self, context):
gpd = context.gpencil_data gpd = context.gpencil
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
@@ -292,16 +277,13 @@ class DATA_PT_gpencil_onionpanel_custom_colors(Panel):
layout.prop(gpd, "after_color", text="After") layout.prop(gpd, "after_color", text="After")
class DATA_PT_gpencil_onionpanel_display(Panel): class DATA_PT_gpencil_onion_skinning_display(DataButtonsPanel, Panel):
bl_space_type = 'PROPERTIES' bl_parent_id = "DATA_PT_gpencil_onion_skinning"
bl_region_type = 'WINDOW'
bl_context = "data"
bl_parent_id = "DATA_PT_gpencil_onionpanel"
bl_label = "Display" bl_label = "Display"
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
def draw(self, context): def draw(self, context):
gpd = context.gpencil_data gpd = context.gpencil
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
@@ -354,10 +336,7 @@ class GPENCIL_UL_vgroups(UIList):
layout.label(text="", icon_value=icon) layout.label(text="", icon_value=icon)
class DATA_PT_gpencil_vertexpanel(ObjectButtonsPanel, Panel): class DATA_PT_gpencil_vertex_groups(ObjectButtonsPanel, Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_label = "Vertex Groups" bl_label = "Vertex Groups"
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
@@ -402,12 +381,13 @@ class DATA_PT_gpencil_strokes(DataButtonsPanel, Panel):
layout.use_property_decorate = False layout.use_property_decorate = False
ob = context.object ob = context.object
gpd = context.gpencil
gpd = context.gpencil_data
col = layout.column(align=True) col = layout.column(align=True)
col.prop(gpd, "stroke_depth_order") col.prop(gpd, "stroke_depth_order")
col.enabled = not ob.show_in_front
if ob:
col.enabled = not ob.show_in_front
col = layout.column(align=True) col = layout.column(align=True)
col.prop(gpd, "stroke_thickness_space") col.prop(gpd, "stroke_thickness_space")
@@ -419,7 +399,7 @@ class DATA_PT_gpencil_strokes(DataButtonsPanel, Panel):
layout.prop(gpd, "use_adaptive_uv", text="Adaptive UVs") layout.prop(gpd, "use_adaptive_uv", text="Adaptive UVs")
class DATA_PT_gpencil_display(ObjectButtonsPanel, Panel): class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
bl_label = "Viewport Display" bl_label = "Viewport Display"
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
@@ -428,10 +408,8 @@ class DATA_PT_gpencil_display(ObjectButtonsPanel, Panel):
layout.use_property_split = True layout.use_property_split = True
layout.use_property_decorate = False layout.use_property_decorate = False
ob = context.object gpd = context.gpencil
gpl = gpd.layers.active
gpd = context.gpencil_data
gpl = context.active_gpencil_layer
layout.prop(gpd, "edit_line_color", text="Edit Line Color") layout.prop(gpd, "edit_line_color", text="Edit Line Color")
if gpl: if gpl:
@@ -447,7 +425,7 @@ class DATA_PT_gpencil_canvas(DataButtonsPanel, Panel):
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
layout.use_property_decorate = False layout.use_property_decorate = False
gpd = context.gpencil_data gpd = context.gpencil
grid = gpd.grid grid = gpd.grid
row = layout.row(align=True) row = layout.row(align=True)
@@ -468,14 +446,14 @@ class DATA_PT_custom_props_gpencil(DataButtonsPanel, PropertyPanel, Panel):
classes = ( classes = (
DATA_PT_gpencil, DATA_PT_context_gpencil,
DATA_PT_gpencil_datapanel, DATA_PT_gpencil_layers,
DATA_PT_gpencil_onionpanel, DATA_PT_gpencil_onion_skinning,
DATA_PT_gpencil_onionpanel_custom_colors, DATA_PT_gpencil_onion_skinning_custom_colors,
DATA_PT_gpencil_onionpanel_display, DATA_PT_gpencil_onion_skinning_display,
DATA_PT_gpencil_layer_optionpanel, DATA_PT_gpencil_layer_adjustments,
DATA_PT_gpencil_parentpanel, DATA_PT_gpencil_layer_relations,
DATA_PT_gpencil_vertexpanel, DATA_PT_gpencil_vertex_groups,
DATA_PT_gpencil_strokes, DATA_PT_gpencil_strokes,
DATA_PT_gpencil_display, DATA_PT_gpencil_display,
DATA_PT_gpencil_canvas, DATA_PT_gpencil_canvas,

View File

@@ -860,65 +860,70 @@ class GreasePencilMaterialsPanel:
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
ob = context.object ob = context.object
return ob and ob.type == 'GPENCIL' ma = context.material
return (ob and ob.type == 'GPENCIL') or (ma and ma.grease_pencil)
@staticmethod @staticmethod
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
show_full_ui = (self.bl_space_type == 'PROPERTIES') show_full_ui = (self.bl_space_type == 'PROPERTIES')
gpd = context.gpencil_data
ob = context.object ob = context.object
gpd = context.gpencil
is_sortable = len(ob.material_slots) > 1 space = context.space_data
rows = 7
row = layout.row() row = layout.row()
row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows) if ob:
is_sortable = len(ob.material_slots) > 1
rows = 7
col = row.column(align=True) row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
if show_full_ui:
col.operator("object.material_slot_add", icon='ADD', text="")
col.operator("object.material_slot_remove", icon='REMOVE', text="")
col.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="") col = row.column(align=True)
if show_full_ui:
col.operator("object.material_slot_add", icon='ADD', text="")
col.operator("object.material_slot_remove", icon='REMOVE', text="")
if is_sortable: col.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="")
col.separator()
col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP' if is_sortable:
col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN' col.separator()
col.separator() col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
sub = col.column(align=True) col.separator()
sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
sub.operator("gpencil.color_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
if show_full_ui: sub = col.column(align=True)
row = layout.row() sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
sub.operator("gpencil.color_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
row.template_ID(ob, "active_material", new="material.new", live_icon=True) if show_full_ui:
row = layout.row()
slot = context.material_slot row.template_ID(ob, "active_material", new="material.new", live_icon=True)
if slot:
icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
row.prop(slot, "link", icon=icon_link, icon_only=True)
if gpd.use_stroke_edit_mode: slot = context.material_slot
row = layout.row(align=True) if slot:
row.operator("gpencil.stroke_change_color", text="Assign") icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
row.operator("gpencil.color_select", text="Select").deselect = False row.prop(slot, "link", icon=icon_link, icon_only=True)
row.operator("gpencil.color_select", text="Deselect").deselect = True
if gpd and gpd.use_stroke_edit_mode:
row = layout.row(align=True)
row.operator("gpencil.stroke_change_color", text="Assign")
row.operator("gpencil.color_select", text="Select").deselect = False
row.operator("gpencil.color_select", text="Deselect").deselect = True
else:
row.template_ID(space, "pin_id")
class GPENCIL_UL_layer(UIList): class GPENCIL_UL_layer(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
# assert(isinstance(item, bpy.types.GPencilLayer) # assert(isinstance(item, bpy.types.GPencilLayer)
gpl = item gpl = item
gpd = context.gpencil_data gpd = context.gpencil
if self.layout_type in {'DEFAULT', 'COMPACT'}: if self.layout_type in {'DEFAULT', 'COMPACT'}:
if gpl.lock: if gpl.lock:

View File

@@ -60,7 +60,8 @@ class MaterialButtonsPanel:
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.material and (context.engine in cls.COMPAT_ENGINES) mat = context.material
return mat and (context.engine in cls.COMPAT_ENGINES) and not mat.grease_pencil
class MATERIAL_PT_preview(MaterialButtonsPanel, Panel): class MATERIAL_PT_preview(MaterialButtonsPanel, Panel):
@@ -86,11 +87,8 @@ class EEVEE_MATERIAL_PT_context_material(MaterialButtonsPanel, Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
if context.active_object and context.active_object.type == 'GPENCIL': mat = context.material
return False return (context.object or mat) and (context.engine in cls.COMPAT_ENGINES) and not mat.grease_pencil
else:
engine = context.engine
return (context.material or context.object) and (engine in cls.COMPAT_ENGINES)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@@ -161,11 +159,6 @@ class EEVEE_MATERIAL_PT_surface(MaterialButtonsPanel, Panel):
bl_context = "material" bl_context = "material"
COMPAT_ENGINES = {'BLENDER_EEVEE'} COMPAT_ENGINES = {'BLENDER_EEVEE'}
@classmethod
def poll(cls, context):
engine = context.engine
return context.material and (engine in cls.COMPAT_ENGINES)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@@ -194,7 +187,7 @@ class EEVEE_MATERIAL_PT_volume(MaterialButtonsPanel, Panel):
def poll(cls, context): def poll(cls, context):
engine = context.engine engine = context.engine
mat = context.material mat = context.material
return mat and mat.use_nodes and (engine in cls.COMPAT_ENGINES) return mat and mat.use_nodes and (engine in cls.COMPAT_ENGINES) and not mat.grease_pencil
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@@ -209,11 +202,6 @@ class EEVEE_MATERIAL_PT_settings(MaterialButtonsPanel, Panel):
bl_context = "material" bl_context = "material"
COMPAT_ENGINES = {'BLENDER_EEVEE'} COMPAT_ENGINES = {'BLENDER_EEVEE'}
@classmethod
def poll(cls, context):
engine = context.engine
return context.material and (engine in cls.COMPAT_ENGINES)
@staticmethod @staticmethod
def draw_shared(self, mat): def draw_shared(self, mat):
layout = self.layout layout = self.layout
@@ -247,7 +235,8 @@ class MATERIAL_PT_viewport(MaterialButtonsPanel, Panel):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.material mat = context.material
return mat and not mat.grease_pencil
@staticmethod @staticmethod
def draw_shared(self, mat): def draw_shared(self, mat):

View File

@@ -81,10 +81,8 @@ class GPMaterialButtonsPanel:
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
ob = context.object ma = context.material
return (ob and ob.type == 'GPENCIL' and return ma and ma.grease_pencil
ob.active_material and
ob.active_material.grease_pencil)
class MATERIAL_PT_gpencil_slots(GreasePencilMaterialsPanel, Panel): class MATERIAL_PT_gpencil_slots(GreasePencilMaterialsPanel, Panel):
@@ -99,18 +97,6 @@ class MATERIAL_PT_gpencil_slots(GreasePencilMaterialsPanel, Panel):
class MATERIAL_PT_gpencil_surface(GPMaterialButtonsPanel, Panel): class MATERIAL_PT_gpencil_surface(GPMaterialButtonsPanel, Panel):
bl_label = "Surface" bl_label = "Surface"
@classmethod
def poll(cls, context):
ob = context.object
if not (ob and ob.type == 'GPENCIL'):
return False
ma = ob.active_material
if not (ma and ma.grease_pencil):
return False
return True
def draw_header_preset(self, context): def draw_header_preset(self, context):
MATERIAL_PT_gpencil_material_presets.draw_panel_header(self.layout) MATERIAL_PT_gpencil_material_presets.draw_panel_header(self.layout)
@@ -125,7 +111,7 @@ class MATERIAL_PT_gpencil_strokecolor(GPMaterialButtonsPanel, Panel):
bl_parent_id = 'MATERIAL_PT_gpencil_surface' bl_parent_id = 'MATERIAL_PT_gpencil_surface'
def draw_header(self, context): def draw_header(self, context):
ma = context.object.active_material ma = context.material
if ma is not None and ma.grease_pencil is not None: if ma is not None and ma.grease_pencil is not None:
gpcolor = ma.grease_pencil gpcolor = ma.grease_pencil
self.layout.prop(gpcolor, "show_stroke", text="") self.layout.prop(gpcolor, "show_stroke", text="")
@@ -135,7 +121,7 @@ class MATERIAL_PT_gpencil_strokecolor(GPMaterialButtonsPanel, Panel):
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
ma = context.object.active_material ma = context.material
if ma is not None and ma.grease_pencil is not None: if ma is not None and ma.grease_pencil is not None:
gpcolor = ma.grease_pencil gpcolor = ma.grease_pencil
@@ -163,74 +149,72 @@ class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
bl_parent_id = 'MATERIAL_PT_gpencil_surface' bl_parent_id = 'MATERIAL_PT_gpencil_surface'
def draw_header(self, context): def draw_header(self, context):
ma = context.object.active_material ma = context.material
if ma is not None and ma.grease_pencil is not None: gpcolor = ma.grease_pencil
gpcolor = ma.grease_pencil self.layout.prop(gpcolor, "show_fill", text="")
self.layout.prop(gpcolor, "show_fill", text="")
@staticmethod @staticmethod
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
ma = context.object.active_material ma = context.material
if ma is not None and ma.grease_pencil: gpcolor = ma.grease_pencil
gpcolor = ma.grease_pencil
# color settings # color settings
col = layout.column() col = layout.column()
col.active = not gpcolor.lock col.active = not gpcolor.lock
col.prop(gpcolor, "fill_style", text="Style") col.prop(gpcolor, "fill_style", text="Style")
if gpcolor.fill_style == 'GRADIENT':
col.prop(gpcolor, "gradient_type")
if gpcolor.fill_style != 'TEXTURE':
col.prop(gpcolor, "fill_color", text="Color")
if gpcolor.fill_style in {'GRADIENT', 'CHESSBOARD'}:
col.prop(gpcolor, "mix_color", text="Secondary Color")
if gpcolor.fill_style == 'GRADIENT': if gpcolor.fill_style == 'GRADIENT':
col.prop(gpcolor, "gradient_type") col.prop(gpcolor, "mix_factor", text="Mix Factor", slider=True)
if gpcolor.fill_style != 'TEXTURE': if gpcolor.fill_style in {'GRADIENT', 'CHESSBOARD'}:
col.prop(gpcolor, "fill_color", text="Color") col.prop(gpcolor, "flip", text="Flip Colors")
if gpcolor.fill_style in {'GRADIENT', 'CHESSBOARD'}: col.prop(gpcolor, "pattern_shift", text="Location")
col.prop(gpcolor, "mix_color", text="Secondary Color") col.prop(gpcolor, "pattern_scale", text="Scale")
if gpcolor.fill_style == 'GRADIENT': if gpcolor.gradient_type == 'RADIAL' and gpcolor.fill_style not in {'SOLID', 'CHESSBOARD'}:
col.prop(gpcolor, "pattern_radius", text="Radius")
else:
if gpcolor.fill_style != 'SOLID':
col.prop(gpcolor, "pattern_angle", text="Angle")
if gpcolor.fill_style == 'CHESSBOARD':
col.prop(gpcolor, "pattern_gridsize", text="Box Size")
# Texture
if gpcolor.fill_style == 'TEXTURE' or (gpcolor.texture_mix is True and gpcolor.fill_style == 'SOLID'):
col.template_ID(gpcolor, "fill_image", open="image.open")
if gpcolor.fill_style == 'TEXTURE':
col.prop(gpcolor, "use_fill_pattern", text="Use As Pattern")
if gpcolor.use_fill_pattern is True:
col.prop(gpcolor, "fill_color", text="Color")
col.prop(gpcolor, "texture_offset", text="Offset")
col.prop(gpcolor, "texture_scale", text="Scale")
col.prop(gpcolor, "texture_angle")
col.prop(gpcolor, "texture_opacity")
col.prop(gpcolor, "texture_clamp", text="Clip Image")
if gpcolor.use_fill_pattern is False:
col.prop(gpcolor, "texture_mix", text="Mix With Color")
if gpcolor.texture_mix is True:
col.prop(gpcolor, "fill_color", text="Mix Color")
col.prop(gpcolor, "mix_factor", text="Mix Factor", slider=True) col.prop(gpcolor, "mix_factor", text="Mix Factor", slider=True)
if gpcolor.fill_style in {'GRADIENT', 'CHESSBOARD'}:
col.prop(gpcolor, "flip", text="Flip Colors")
col.prop(gpcolor, "pattern_shift", text="Location")
col.prop(gpcolor, "pattern_scale", text="Scale")
if gpcolor.gradient_type == 'RADIAL' and gpcolor.fill_style not in {'SOLID', 'CHESSBOARD'}:
col.prop(gpcolor, "pattern_radius", text="Radius")
else:
if gpcolor.fill_style != 'SOLID':
col.prop(gpcolor, "pattern_angle", text="Angle")
if gpcolor.fill_style == 'CHESSBOARD':
col.prop(gpcolor, "pattern_gridsize", text="Box Size")
# Texture
if gpcolor.fill_style == 'TEXTURE' or (gpcolor.texture_mix is True and gpcolor.fill_style == 'SOLID'):
col.template_ID(gpcolor, "fill_image", open="image.open")
if gpcolor.fill_style == 'TEXTURE':
col.prop(gpcolor, "use_fill_pattern", text="Use As Pattern")
if gpcolor.use_fill_pattern is True:
col.prop(gpcolor, "fill_color", text="Color")
col.prop(gpcolor, "texture_offset", text="Offset")
col.prop(gpcolor, "texture_scale", text="Scale")
col.prop(gpcolor, "texture_angle")
col.prop(gpcolor, "texture_opacity")
col.prop(gpcolor, "texture_clamp", text="Clip Image")
if gpcolor.use_fill_pattern is False:
col.prop(gpcolor, "texture_mix", text="Mix With Color")
if gpcolor.texture_mix is True:
col.prop(gpcolor, "fill_color", text="Mix Color")
col.prop(gpcolor, "mix_factor", text="Mix Factor", slider=True)
class MATERIAL_PT_gpencil_preview(GPMaterialButtonsPanel, Panel): class MATERIAL_PT_gpencil_preview(GPMaterialButtonsPanel, Panel):
bl_label = "Preview" bl_label = "Preview"
@@ -238,7 +222,7 @@ class MATERIAL_PT_gpencil_preview(GPMaterialButtonsPanel, Panel):
bl_options = {'DEFAULT_CLOSED'} bl_options = {'DEFAULT_CLOSED'}
def draw(self, context): def draw(self, context):
ma = context.object.active_material ma = context.material
self.layout.label(text=ma.name) self.layout.label(text=ma.name)
self.layout.template_preview(ma) self.layout.template_preview(ma)
@@ -258,10 +242,9 @@ class MATERIAL_PT_gpencil_options(GPMaterialButtonsPanel, Panel):
layout = self.layout layout = self.layout
layout.use_property_split = True layout.use_property_split = True
ma = context.object.active_material ma = context.material
if ma is not None and ma.grease_pencil is not None: gpcolor = ma.grease_pencil
gpcolor = ma.grease_pencil layout.prop(gpcolor, "pass_index")
layout.prop(gpcolor, "pass_index")
class MATERIAL_PT_gpencil_material_presets(PresetMenu): class MATERIAL_PT_gpencil_material_presets(PresetMenu):

View File

@@ -494,7 +494,6 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
wmWindow *window = CTX_wm_window(C); wmWindow *window = CTX_wm_window(C);
Scene *scene = WM_window_get_active_scene(window); Scene *scene = WM_window_get_active_scene(window);
ViewLayer *view_layer = WM_window_get_active_view_layer(window); ViewLayer *view_layer = WM_window_get_active_view_layer(window);
Object *ob = OBACT(view_layer);
ID *id; ID *id;
int found; int found;
@@ -562,14 +561,7 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
found = buttons_context_path_particle(path); found = buttons_context_path_particle(path);
break; break;
case BCONTEXT_MATERIAL: case BCONTEXT_MATERIAL:
/* NOTE: Grease Pencil materials use different panels... */ found = buttons_context_path_material(path);
if (ob && ob->type == OB_GPENCIL) {
/* XXX: Why path_data? */
found = buttons_context_path_data(path, -1);
}
else {
found = buttons_context_path_material(path);
}
break; break;
case BCONTEXT_TEXTURE: case BCONTEXT_TEXTURE:
found = buttons_context_path_texture(C, path, sbuts->texuser); found = buttons_context_path_texture(C, path, sbuts->texuser);
@@ -708,7 +700,7 @@ const char *buttons_context_dir[] = {
"texture", "texture_user", "texture_user_property", "bone", "edit_bone", "texture", "texture_user", "texture_user_property", "bone", "edit_bone",
"pose_bone", "particle_system", "particle_system_editable", "particle_settings", "pose_bone", "particle_system", "particle_system_editable", "particle_settings",
"cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint", "cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint",
"line_style", "collection", NULL, "line_style", "collection", "gpencil", NULL,
}; };
int buttons_context(const bContext *C, const char *member, bContextDataResult *result) int buttons_context(const bContext *C, const char *member, bContextDataResult *result)
@@ -981,6 +973,10 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
set_pointer_type(path, result, &RNA_FreestyleLineStyle); set_pointer_type(path, result, &RNA_FreestyleLineStyle);
return 1; return 1;
} }
else if (CTX_data_equals(member, "gpencil")) {
set_pointer_type(path, result, &RNA_GreasePencil);
return 1;
}
else { else {
return 0; /* not found */ return 0; /* not found */
} }