diff options
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 126 |
1 files changed, 103 insertions, 23 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index f704ac0e203..ec2b4f5adf0 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -34,11 +34,14 @@ #include "DNA_dynamicpaint_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" +#include "DNA_object_force.h" #include "BLI_utildefines.h" #include "BLI_string.h" #include "BLI_ghash.h" #include "BLI_rect.h" +#include "BLI_math.h" +#include "BLI_listbase.h" #include "BLF_api.h" #include "BLF_translation.h" @@ -46,22 +49,26 @@ #include "BKE_animsys.h" #include "BKE_colortools.h" #include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_displist.h" #include "BKE_dynamicpaint.h" #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" -#include "BKE_object.h" #include "BKE_material.h" -#include "BKE_texture.h" +#include "BKE_modifier.h" +#include "BKE_object.h" +#include "BKE_particle.h" #include "BKE_report.h" -#include "BKE_displist.h" #include "BKE_sca.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_texture.h" #include "ED_screen.h" #include "ED_object.h" #include "ED_render.h" +#include "ED_util.h" #include "RNA_access.h" #include "RNA_enum_types.h" @@ -726,21 +733,6 @@ void uiTemplatePathBuilder(uiLayout *layout, PointerRNA *ptr, const char *propna #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata" -#include <string.h> - -#include "DNA_object_force.h" - -#include "BKE_depsgraph.h" -#include "BKE_modifier.h" -#include "BKE_particle.h" - -#include "ED_util.h" - -#include "BLI_math.h" -#include "BLI_listbase.h" - -#include "ED_object.h" - static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v) { Scene *scene = CTX_data_scene(C); @@ -1564,6 +1556,88 @@ void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname MEM_freeN(cb); } + +/********************* Icon viewer Template ************************/ + +/* ID Search browse menu, open */ +static uiBlock *icon_view_menu(bContext *C, ARegion *ar, void *arg_litem) +{ + static RNAUpdateCb cb; + uiBlock *block; + uiBut *but; + int icon; + EnumPropertyItem *item; + int a, free; + + /* arg_litem is malloced, can be freed by parent button */ + cb = *((RNAUpdateCb *)arg_litem); + + icon = RNA_property_enum_get(&cb.ptr, cb.prop); + + block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS); + uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW); + + + RNA_property_enum_items(C, &cb.ptr, cb.prop, &item, NULL, &free); + + for (a = 0; item[a].identifier; a++) { + int x, y; + + x = (a % 8) * UI_UNIT_X * 6; + y = (a / 8) * UI_UNIT_X * 6; + + icon = item[a].icon; + but = uiDefIconButR_prop(block, ROW, 0, icon, x, y, UI_UNIT_X * 6, UI_UNIT_Y * 6, &cb.ptr, cb.prop, -1, 0, icon, -1, -1, NULL); + uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW); + } + + uiBoundsBlock(block, 0.3f * U.widget_unit); + uiBlockSetDirection(block, UI_TOP); + uiEndBlock(C, block); + + if (free) { + MEM_freeN(item); + } + + return block; +} + +void uiTemplateIconView(uiLayout *layout, PointerRNA *ptr, const char *propname) +{ + PropertyRNA *prop = RNA_struct_find_property(ptr, propname); + RNAUpdateCb *cb; + uiBlock *block; + uiBut *but; +// rctf rect; /* UNUSED */ + int icon; + + if (!prop || RNA_property_type(prop) != PROP_ENUM) + return; + + icon = RNA_property_enum_get(ptr, prop); + + cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb"); + cb->ptr = *ptr; + cb->prop = prop; + +// rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X; +// rect.ymin = 0; rect.ymax = 10.0f * UI_UNIT_X; + + block = uiLayoutAbsoluteBlock(layout); + + but = uiDefBlockButN(block, icon_view_menu, MEM_dupallocN(cb), "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6, ""); + + +// but = uiDefIconButR_prop(block, ROW, 0, icon, 0, 0, BLI_rctf_size_x(&rect), BLI_rctf_size_y(&rect), ptr, prop, -1, 0, icon, -1, -1, NULL); + + but->icon = icon; + uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW); + + uiButSetNFunc(but, rna_update_cb, MEM_dupallocN(cb), NULL); + + MEM_freeN(cb); +} + /********************* Histogram Template ************************/ void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, const char *propname) @@ -2030,16 +2104,22 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe } if (cmp) { - const float range_clamp[2] = {0.0f, 1.0f}; - const float range_unclamp[2] = {-1000.0f, 1000.0f}; /* arbitrary limits here */ - const float *range = (cumap->flag & CUMA_DO_CLIP) ? range_clamp : range_unclamp; + rctf bounds; + + if (cumap->flag & CUMA_DO_CLIP) { + bounds = cumap->clipr; + } + else { + bounds.xmin = bounds.ymin = -1000.0; + bounds.xmax = bounds.ymax = 1000.0; + } uiLayoutRow(layout, TRUE); uiBlockSetNFunc(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap); bt = uiDefButF(block, NUM, 0, "X", 0, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &cmp->x, range[0], range[1], 1, 5, ""); + &cmp->x, bounds.xmin, bounds.xmax, 1, 5, ""); bt = uiDefButF(block, NUM, 0, "Y", 0, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &cmp->y, range[0], range[1], 1, 5, ""); + &cmp->y, bounds.ymin, bounds.ymax, 1, 5, ""); } /* black/white levels */ |