Skip to content
Snippets Groups Projects
ui.py 37 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    
                prop = row.operator("view3d.view_move_qcd_slot", text="", icon=icon,
                                    icon_value=icon_value, depress=not qcd_laycol.exclude)
                prop.slot = str(x+1)
    
            else:
                row.label(text="", icon='X')
    
    
            if idx%5==0:
                row.separator()
    
            if idx == 10:
                row = col.row(align=True)
                row.scale_y = 0.5
    
            idx += 1
    
    
    
    def view_layer_update(self, context):
        if context.view_layer.name != CollectionManager.last_view_layer:
            bpy.app.timers.register(update_qcd_header)
            CollectionManager.last_view_layer = context.view_layer.name
    
    
    
    def get_active_icon(context, qcd_laycol):
        global last_icon_theme_text
        global last_icon_theme_text_sel
    
        tool_theme = context.preferences.themes[0].user_interface.wcol_tool
        pcoll = preview_collections["icons"]
    
        if qcd_laycol.exclude:
            theme_color = tool_theme.text
            last_theme_color = last_icon_theme_text
            icon = pcoll["active_icon_text"]
    
        else:
            theme_color = tool_theme.text_sel
            last_theme_color = last_icon_theme_text_sel
            icon = pcoll["active_icon_text_sel"]
    
        if last_theme_color == None or theme_color.hsv != last_theme_color:
            update_icon(pcoll["active_icon_base"], icon, theme_color)
    
            if qcd_laycol.exclude:
                last_icon_theme_text = theme_color.hsv
    
            else:
                last_icon_theme_text_sel = theme_color.hsv
    
        return icon
    
    
    def update_icon(base, icon, theme_color):
        icon.icon_pixels = base.icon_pixels
        colored_icon = []
    
        for offset in range(len(icon.icon_pixels)):
            idx = offset * 4
    
            r = icon.icon_pixels_float[idx]
            g = icon.icon_pixels_float[idx+1]
            b = icon.icon_pixels_float[idx+2]
            a = icon.icon_pixels_float[idx+3]
    
            # add back some brightness and opacity blender takes away from the custom icon
            r = min(r+r*0.2,1)
            g = min(g+g*0.2,1)
            b = min(b+b*0.2,1)
            a = min(a+a*0.2,1)
    
            # make the icon follow the theme color (assuming the icon is white)
            r *= theme_color.r
            g *= theme_color.g
            b *= theme_color.b
    
            colored_icon.append(r)
            colored_icon.append(g)
            colored_icon.append(b)
            colored_icon.append(a)
    
        icon.icon_pixels_float = colored_icon
    
    
    
    def filter_items_by_name_custom(pattern, bitflag, items, propname="name", flags=None, reverse=False):
    
            """
            Set FILTER_ITEM for items which name matches filter_name one (case-insensitive).
            pattern is the filtering pattern.
            propname is the name of the string property to use for filtering.
            flags must be a list of integers the same length as items, or None!
            return a list of flags (based on given flags if not None),
            or an empty list if no flags were given and no filtering has been done.
            """
            import fnmatch
    
            if not pattern or not items:  # Empty pattern or list = no filtering!
                return flags or []
    
            if flags is None:
                flags = [0] * len(items)
    
            # Make pattern case-insensitive
            pattern = pattern.lower()
    
            # Implicitly add heading/trailing wildcards.
            pattern = "*" + pattern + "*"
    
            for i, item in enumerate(items):
                name = getattr(item, propname, None)
    
                # Make name case-insensitive
                name = name.lower()
    
                # This is similar to a logical xor
                if bool(name and fnmatch.fnmatch(name, pattern)) is not bool(reverse):
                    flags[i] |= bitflag
    
    
                # add in any recently created collections
                if item.name in CM_UL_items.new_collections:
                    flags[i] |= bitflag
    
    
    
    def merge_flt_flags(l1, l2):
        for idx, _ in enumerate(l1):
            l1[idx] &= l2.pop(0)
    
        return l1 + l2