forked from jayanam/shortcut_VUr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scv_draw_util.py
74 lines (54 loc) · 2.83 KB
/
scv_draw_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
class SCV_Draw_Util:
def __init__(self, context):
self.x_off = 14
self.y_off = 50
self.width_all = 70
self.indices = ((0, 1, 2), (0, 2, 3))
def set_color_buttons(self, context):
cb = context.scene.color_buttons
cba = context.scene.color_buttons_active
self.color = (cb.r, cb.g, cb.b, 1.0)
self.color_active = (cba.r, cba.g, cba.b, 1.0)
def create_batches(self, context, mouse_input):
ox = context.scene.cursor_offset_x
oy = context.scene.cursor_offset_y
self.y_off = 50 + oy
if context.scene.h_dock == "0":
self.x_off = 14 + ox
elif context.scene.h_dock == "1":
self.x_off = context.region.width - 100 - ox
# Follow cursor
elif context.scene.h_dock == "3":
self.x_off = mouse_input.mouse_x - 35 + ox
self.y_off = mouse_input.mouse_y - 100 - oy
else:
self.x_off = ((context.region.width - self.width_all) / 2.0) - 1
# bottom left, top left, top right, bottom right
self.vertices_left = ((self.x_off, 20 + self.y_off), (self.x_off, 50 + self.y_off), (self.x_off + 20, 50 + self.y_off), (self.x_off + 20, 20 + self.y_off))
self.vertices_right = ((self.x_off + 50, 20 + self.y_off), (self.x_off + 50, 50 + self.y_off), (self.x_off + 70, 50 + self.y_off), (self.x_off + 70, 20 + self.y_off))
self.vertices_middle = ((self.x_off + 30, 30 + self.y_off), (self.x_off + 30, 50 + self.y_off), (self.x_off + 40, 50 + self.y_off), (self.x_off + 40, 30 + self.y_off))
if bpy.app.version < (4, 0, 0):
self.shader = gpu.shader.from_builtin("2D_UNIFORM_COLOR")
else:
self.shader = gpu.shader.from_builtin("UNIFORM_COLOR")
self.batch_left_button = batch_for_shader(self.shader, 'TRIS', {"pos" : self.vertices_left}, indices = self.indices)
self.batch_right_button = batch_for_shader(self.shader, 'TRIS', {"pos" : self.vertices_right}, indices = self.indices)
self.batch_middle_button = batch_for_shader(self.shader, 'TRIS', {"pos" : self.vertices_middle}, indices = self.indices)
def __get_color(self, key_state):
if key_state is True:
return self.color_active
else:
return self.color
def __set_color(self, key_state):
self.shader.uniform_float("color", self.__get_color(key_state))
def draw_buttons(self, left, middle, right):
self.shader.bind()
self.__set_color(left)
self.batch_left_button.draw(self.shader)
self.__set_color(middle)
self.batch_middle_button.draw(self.shader)
self.__set_color(right)
self.batch_right_button.draw(self.shader)