fix mouse_under in picker_group
This commit is contained in:
+106
-54
@@ -3,7 +3,7 @@ import bpy
|
||||
import gpu
|
||||
from gpu_extras.batch import batch_for_shader
|
||||
import blf
|
||||
from mathutils import bvhtree, Vector
|
||||
from mathutils import bvhtree, Vector, Color
|
||||
from mathutils.geometry import (intersect_point_quad_2d, intersect_point_tri_2d,
|
||||
intersect_tri_tri_2d)
|
||||
from ..constants import PICKERS
|
||||
@@ -30,13 +30,15 @@ class Shape:
|
||||
self.press = False
|
||||
|
||||
self.shader = gpu.shader.from_builtin('UNIFORM_COLOR')
|
||||
self.shader.bind()
|
||||
|
||||
#self.hover_shader = gpu.shader.from_builtin('UNIFORM_COLOR')
|
||||
#self.hover_shader.uniform_float("color", [1, 1, 1, 0.1])
|
||||
self.hover_color = [1, 1, 1, 0.1]
|
||||
|
||||
self.color = color
|
||||
self.hover_color = self.brighten_color(self.color)
|
||||
|
||||
self.tooltip = tooltip
|
||||
self.color = color
|
||||
self.points = points
|
||||
self.polygons = polygons or []
|
||||
self.edges = edges or []
|
||||
@@ -50,6 +52,14 @@ class Shape:
|
||||
def color(self):
|
||||
return self._color
|
||||
|
||||
def brighten_color(self, color):
|
||||
brighten_color = Color(color[:3])
|
||||
brighten_color.v += 0.05
|
||||
brighten_color.v *= 1.1
|
||||
brighten_color.v = max(brighten_color.v, 0.15)
|
||||
|
||||
return [*brighten_color, color[3]]
|
||||
|
||||
@color.setter
|
||||
def color(self, color=None):
|
||||
if not color:
|
||||
@@ -69,11 +79,12 @@ class Shape:
|
||||
|
||||
def draw(self):
|
||||
|
||||
self.shader.bind()
|
||||
#self.shader.bind()
|
||||
self.shader.uniform_float("color", self.color)
|
||||
|
||||
if self.polygons:
|
||||
self.p_batch.draw(self.shader)
|
||||
|
||||
if self.edges:
|
||||
self.e_batch.draw(self.shader)
|
||||
|
||||
@@ -105,6 +116,7 @@ class BoneShape(Shape):
|
||||
self.type = 'bone'
|
||||
self.bone = bone
|
||||
self.active_color = [1, 1, 1, 0.1]
|
||||
self.select_color = self.brighten_color(self.hover_color)
|
||||
|
||||
self.bone_colors = self.get_bone_colors()
|
||||
|
||||
@@ -174,49 +186,71 @@ class BoneShape(Shape):
|
||||
|
||||
return bone_colors
|
||||
|
||||
def draw(self):
|
||||
def draw_hided(self):
|
||||
gpu.state.blend_set('ALPHA')
|
||||
gpu.state.line_width_set(1.0)
|
||||
|
||||
if self.hide:
|
||||
self.shader.uniform_float("color", (*self.color[:3], 0.4))
|
||||
self.p_batch.draw(self.shader)
|
||||
#elif self.select:
|
||||
# self.shader.uniform_float("color", self.bone_color)
|
||||
# self.p_batch.draw(self.shader)
|
||||
else:
|
||||
super().draw()
|
||||
line_color = (1, 1, 1, 0.1)
|
||||
color = Color(self.color[:3])
|
||||
if self.hover:
|
||||
color.v += 0.05
|
||||
color.v *= 1.1
|
||||
|
||||
# Overlay the fill slightly with the bone color
|
||||
#self.shader.uniform_float("color", (*self.bone_color[:3], 0.1))
|
||||
#self.p_batch.draw(self.shader)
|
||||
line_color = (1, 1, 1, 0.3)
|
||||
|
||||
if self.select:
|
||||
color = self.hover_color
|
||||
|
||||
if self.select or self.hover:
|
||||
color = self.hover_color
|
||||
|
||||
if self.select and self.hover:
|
||||
color = self.active_color
|
||||
|
||||
self.shader.uniform_float("color", color)
|
||||
self.p_batch.draw(self.shader)
|
||||
|
||||
#Overlay the fill slightly with the bone color
|
||||
self.shader.uniform_float("color", (*self.bone_colors['normal'][:3], 0.1))
|
||||
self.shader.uniform_float("color", (*color[:3], 0.5))
|
||||
self.p_batch.draw(self.shader)
|
||||
|
||||
self.shader.uniform_float("color", line_color)
|
||||
self.e_batch.draw(self.shader)
|
||||
|
||||
gpu.state.blend_set('NONE')
|
||||
|
||||
def draw_zero_scaled(self):
|
||||
gpu.state.blend_set('ALPHA')
|
||||
gpu.state.line_width_set(1.0)
|
||||
|
||||
#self.contour_shader.bind()
|
||||
line_color = (*self.bone_colors['normal'][:3], 0.2)
|
||||
color = Color(self.color[:3])
|
||||
if self.hover or self.select:
|
||||
color.v += 0.05
|
||||
color.v *= 1.1
|
||||
line_color = (*self.bone_color[:3], 0.66)
|
||||
|
||||
#print(self.bone_color)
|
||||
self.shader.uniform_float("color", (*color[:3], 0.5))
|
||||
self.p_batch.draw(self.shader)
|
||||
|
||||
self.shader.uniform_float("color", line_color)
|
||||
self.e_batch.draw(self.shader)
|
||||
|
||||
gpu.state.blend_set('NONE')
|
||||
|
||||
def draw(self):
|
||||
gpu.state.blend_set('ALPHA')
|
||||
gpu.state.line_width_set(1.0)
|
||||
|
||||
if self.hide:
|
||||
return self.draw_hided()
|
||||
|
||||
elif self.bone.custom_shape_scale_xyz.length < 0.00001:
|
||||
return self.draw_zero_scaled()
|
||||
|
||||
# Draw Fill
|
||||
color = self.color
|
||||
if self.select:
|
||||
color = self.select_color
|
||||
elif self.hover:
|
||||
color = self.hover_color
|
||||
|
||||
self.shader.uniform_float("color", color)
|
||||
self.p_batch.draw(self.shader)
|
||||
|
||||
# Draw Outline
|
||||
gpu.state.blend_set('NONE')
|
||||
if self.select or self.active:
|
||||
gpu.state.line_width_set(2.0)
|
||||
|
||||
#if not self.hide:
|
||||
self.shader.uniform_float("color", self.bone_color)
|
||||
#for b in self.contour_batches:
|
||||
self.e_batch.draw(self.shader)
|
||||
|
||||
gpu.state.line_width_set(1.0)
|
||||
@@ -359,8 +393,8 @@ class OperatorShape(Shape):
|
||||
|
||||
|
||||
class Picker:
|
||||
def __init__(self, rig, shapes):
|
||||
|
||||
def __init__(self, parent, rig, shapes):
|
||||
self.parent = parent
|
||||
self.region = bpy.context.region
|
||||
self.rig = rig
|
||||
|
||||
@@ -421,7 +455,7 @@ class Picker:
|
||||
if shape.type=='bone' and shape.hover:
|
||||
shape.assign_bone_event()
|
||||
|
||||
bpy.ops.rigpicker.save_picker()
|
||||
bpy.ops.rigpicker.save_picker(index=self.index)
|
||||
|
||||
def press_event(self, mode='SET'):
|
||||
for shape in self.shapes:
|
||||
@@ -475,9 +509,9 @@ class Picker:
|
||||
def border_select(self, border, mode):
|
||||
border = [Vector(b) - Vector(self.translation) for b in border]
|
||||
|
||||
|
||||
|
||||
for shape in self.shapes:
|
||||
shape.press = False
|
||||
shape.hover = False
|
||||
if shape.type != 'bone':
|
||||
continue
|
||||
|
||||
@@ -519,16 +553,21 @@ class Picker:
|
||||
relative_center = (self.rect[1] + self.rect[3]) * 0.5
|
||||
return relative_center + self.translation
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
return self.parent.pickers.index(self)
|
||||
|
||||
|
||||
class PickerGroup:
|
||||
def __init__(self, rig, pickers):
|
||||
|
||||
self.view_location = Vector((0, 0))
|
||||
#self.view_location = Vector((0, 0))
|
||||
self.region = bpy.context.region
|
||||
self.rig = rig
|
||||
self.pickers = []
|
||||
|
||||
self.mouse = Vector((0, 0))
|
||||
self.location = Vector((0, 0))
|
||||
|
||||
self.hover_shape = None
|
||||
|
||||
@@ -542,7 +581,7 @@ class PickerGroup:
|
||||
self.add_picker(picker)
|
||||
|
||||
def add_picker(self, picker):
|
||||
self.pickers.append(Picker(self.rig, picker))
|
||||
self.pickers.append(Picker(self, self.rig, picker))
|
||||
|
||||
def draw(self):
|
||||
y = 0
|
||||
@@ -558,22 +597,23 @@ class PickerGroup:
|
||||
|
||||
def move_event(self, mouse):
|
||||
self.mouse = mouse
|
||||
location = self.region.view2d.region_to_view(*mouse)
|
||||
self.location = self.region.view2d.region_to_view(*mouse)
|
||||
|
||||
view_location = self.region.view2d.region_to_view(0, 0)
|
||||
if view_location != self.view_location:
|
||||
self.view_location = view_location
|
||||
self.tooltip = ''
|
||||
if self.timer:
|
||||
self.timer.cancel()
|
||||
return
|
||||
# Try to detect view pan to remove tooltip
|
||||
# view_location = self.region.view2d.region_to_view(0, 0)
|
||||
# if view_location != self.view_location:
|
||||
# self.view_location = view_location
|
||||
# self.tooltip = ''
|
||||
# if self.timer:
|
||||
# self.timer.cancel()
|
||||
# return
|
||||
|
||||
hover_shape = None
|
||||
for picker in self.pickers:
|
||||
if not picker.under_mouse(location):
|
||||
if not picker.under_mouse(self.location):
|
||||
continue
|
||||
|
||||
picker.move_event(location)
|
||||
picker.move_event(self.location)
|
||||
|
||||
if picker.hover_shape:
|
||||
hover_shape = picker.hover_shape
|
||||
@@ -593,16 +633,28 @@ class PickerGroup:
|
||||
self.clear_tooltip()
|
||||
|
||||
for picker in self.pickers:
|
||||
picker.press_event(mode)
|
||||
if picker.under_mouse(self.location):
|
||||
picker.press_event(mode)
|
||||
else:
|
||||
for shape in picker.shapes:
|
||||
shape.press = False
|
||||
|
||||
def release_event(self, mode='SET'):
|
||||
|
||||
if mode == 'SET':
|
||||
for bone in self.rig.data.bones:
|
||||
bone.select = False
|
||||
|
||||
for picker in self.pickers:
|
||||
picker.release_event(mode)
|
||||
if picker.under_mouse(self.location):
|
||||
picker.release_event(mode)
|
||||
else:
|
||||
for shape in picker.shapes:
|
||||
shape.press = False
|
||||
|
||||
def assign_bone_event(self):
|
||||
for picker in self.pickers:
|
||||
if picker.under_mouse(self.location):
|
||||
picker.assign_bone_event()
|
||||
|
||||
def border_select(self, border, mode):
|
||||
border = [self.region.view2d.region_to_view(*b) for b in border]
|
||||
|
||||
Reference in New Issue
Block a user