Workbench: Lights user pref

This commit is contained in:
Jeroen Bakker 2018-06-08 14:30:11 +02:00
parent 33437719c1
commit aff6cc9cf1
2 changed files with 68 additions and 33 deletions

@ -72,6 +72,10 @@ class USERPREF_HT_header(Header):
layout.operator("wm.addon_install", icon='FILESEL')
layout.operator("wm.addon_refresh", icon='FILE_REFRESH')
layout.menu("USERPREF_MT_addons_online_resources")
elif userpref.active_section == 'LIGHTS':
layout.operator('wm.studiolight_install', text="Install MatCap").orientation='MATCAP'
layout.operator('wm.studiolight_install', text="Install World HDRI").orientation='WORLD'
layout.operator('wm.studiolight_install', text="Install Camera HDRI").orientation='CAMERA'
elif userpref.active_section == 'THEMES':
layout.operator("ui.reset_default_theme")
layout.operator("wm.theme_install")
@ -1571,11 +1575,9 @@ class USERPREF_PT_addons(Panel):
row.label(text=module_name, translate=False)
class USERPREF_PT_studiolight(Panel):
class StudioLightPanelMixin():
bl_space_type = 'USER_PREFERENCES'
bl_label = "Lights"
bl_region_type = 'WINDOW'
bl_options = {'HIDE_HEADER'}
@classmethod
def poll(cls, context):
@ -1586,33 +1588,44 @@ class USERPREF_PT_studiolight(Panel):
box = layout.box()
row = box.row()
op = row.operator('wm.studiolight_expand', emboss=False, text="", icon='TRIA_DOWN' if studio_light.show_expanded else 'TRIA_RIGHT')
op.index = studio_light.index
row.label(text=studio_light.name, icon_value=studio_light.radiance_icon_id)
row.template_icon_view(studio_light, "icon_id")
op = row.operator('wm.studiolight_uninstall', text="", icon='ZOOMOUT')
op.index = studio_light.index
if studio_light.show_expanded:
box.label(studio_light.path)
class USERPREF_PT_studiolight_matcaps(Panel, StudioLightPanelMixin):
bl_label = "MatCaps"
def draw(self, context):
layout = self.layout
flow = layout.column_flow(4)
userpref = context.user_preferences
lights = [light for light in userpref.studio_lights if light.is_user_defined]
layout.label("MatCaps")
for studio_light in filter(lambda x: x.orientation=='MATCAP', lights):
self.draw_studio_light(layout, studio_light)
layout.operator('wm.studiolight_install', text="Install Custom MatCap").orientation='MATCAP'
layout.label("World HDRI")
self.draw_studio_light(flow, studio_light)
class USERPREF_PT_studiolight_world(Panel, StudioLightPanelMixin):
bl_label = "World HDRI"
def draw(self, context):
layout = self.layout
flow = layout.column_flow(4)
userpref = context.user_preferences
lights = [light for light in userpref.studio_lights if light.is_user_defined]
for studio_light in filter(lambda x: x.orientation=='WORLD', lights):
self.draw_studio_light(layout, studio_light)
layout.operator('wm.studiolight_install', text="Install Custom HDRI").orientation='WORLD'
layout.label("Camera HDRI")
self.draw_studio_light(flow, studio_light)
class USERPREF_PT_studiolight_camera(Panel, StudioLightPanelMixin):
bl_label = "Camera HDRI"
def draw(self, context):
layout = self.layout
flow = layout.column_flow(4)
userpref = context.user_preferences
lights = [light for light in userpref.studio_lights if light.is_user_defined]
for studio_light in filter(lambda x: x.orientation=='CAMERA', lights):
self.draw_studio_light(layout, studio_light)
layout.operator('wm.studiolight_install', text="Install Custom Camera HDRI").orientation='CAMERA'
self.draw_studio_light(flow, studio_light)
classes = (
@ -1635,7 +1648,9 @@ classes = (
USERPREF_PT_input,
USERPREF_MT_addons_online_resources,
USERPREF_PT_addons,
USERPREF_PT_studiolight,
USERPREF_PT_studiolight_matcaps,
USERPREF_PT_studiolight_world,
USERPREF_PT_studiolight_camera,
)
if __name__ == "__main__": # only for live edit.

@ -78,6 +78,12 @@ const EnumPropertyItem rna_enum_navigation_mode_items[] = {
{0, NULL, 0, NULL, NULL}
};
static const EnumPropertyItem rna_enum_studio_light_icons_id_items[] = {
{0, "DEFAULT", 0, "Default", ""},
{0, NULL, 0, NULL, NULL}
};
#if defined(WITH_INTERNATIONAL) || !defined(RNA_RUNTIME)
static const EnumPropertyItem rna_enum_language_default_items[] = {
{0, "DEFAULT", 0, "Default (Default)", ""},
@ -698,18 +704,36 @@ static int rna_UserDef_studiolight_index_get(PointerRNA *ptr)
return sl->index;
}
/* StudioLight.radiance_icon_id */
static int rna_UserDef_studiolight_radiance_icon_id_get(PointerRNA *ptr)
/* StudioLight.icon_id */
static int rna_UserDef_studiolight_icon_id_get(PointerRNA *ptr)
{
StudioLight *sl = (StudioLight *)ptr->data;
return sl->radiance_icon_id;
if (sl->flag & (STUDIOLIGHT_ORIENTATION_VIEWNORMAL | STUDIOLIGHT_ORIENTATION_CAMERA)) {
return 1;
}
return 0;
}
/* StudioLight.irradiance_icon_id */
static int rna_UserDef_studiolight_irradiance_icon_id_get(PointerRNA *ptr)
static const EnumPropertyItem *rna_UserDef_studiolight_icon_id_itemf(
bContext *UNUSED(C), PointerRNA *ptr,
PropertyRNA *UNUSED(prop), bool *r_free)
{
EnumPropertyItem *item = NULL;
int totitem = 0;
StudioLight *sl = (StudioLight *)ptr->data;
return sl->irradiance_icon_id;
if ((sl->flag & (STUDIOLIGHT_ORIENTATION_VIEWNORMAL | STUDIOLIGHT_ORIENTATION_CAMERA)) == 0)
{
EnumPropertyItem tmp = {0, sl->name, sl->radiance_icon_id, sl->name, ""};
RNA_enum_item_add(&item, &totitem, &tmp);
}
{
EnumPropertyItem tmp = {1, sl->name, sl->irradiance_icon_id, sl->name, ""};
RNA_enum_item_add(&item, &totitem, &tmp);
}
RNA_enum_item_end(&item, &totitem);
*r_free = true;
return item;
}
/* StudioLight.is_user_defined */
@ -3291,15 +3315,11 @@ static void rna_def_userdef_studiolight(BlenderRNA *brna)
RNA_def_property_enum_funcs(prop, "rna_UserDef_studiolight_orientation_get", "rna_UserDef_studiolight_orientation_set", NULL);
RNA_def_property_ui_text(prop, "Orientation", "");
prop = RNA_def_property(srna, "radiance_icon_id", PROP_INT, PROP_NONE);
RNA_def_property_int_funcs(prop, "rna_UserDef_studiolight_radiance_icon_id_get", NULL, NULL);
prop = RNA_def_property(srna, "icon_id", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_funcs(prop, "rna_UserDef_studiolight_icon_id_get", NULL, "rna_UserDef_studiolight_icon_id_itemf");
RNA_def_property_enum_items(prop, rna_enum_studio_light_icons_id_items);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Radiance Icon", "");
prop = RNA_def_property(srna, "irradiance_icon_id", PROP_INT, PROP_NONE);
RNA_def_property_int_funcs(prop, "rna_UserDef_studiolight_irradiance_icon_id_get", NULL, NULL);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Irradiance Icon", "");
RNA_def_property_ui_text(prop, "Preview", "Preview of the studiolight");
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_string_funcs(prop, "rna_UserDef_studiolight_name_get", "rna_UserDef_studiolight_name_length", NULL);