Skip to content

Commit

Permalink
Apply black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanLovato committed Aug 17, 2019
1 parent cf151b8 commit 5c51508
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 43 deletions.
24 changes: 6 additions & 18 deletions operators/mouse_cut.py
Expand Up @@ -12,7 +12,6 @@
from .utils.draw import draw_line, draw_arrow_head, get_color_gizmo_primary
from .utils.doc import doc_name, doc_idname, doc_brief, doc_description


if not bpy.app.background:
SHADER = gpu.shader.from_builtin("2D_UNIFORM_COLOR")

Expand Down Expand Up @@ -344,28 +343,17 @@ def draw(

bgl.glLineWidth(3)
draw_line(SHADER, start, end, color)
draw_line(SHADER, Vector((start.x, min_bottom)), Vector(
(start.x, max_top)), color)
draw_line(SHADER, Vector((end.x, min_bottom)), Vector((end.x, max_top)),
color)
draw_line(SHADER, Vector((start.x, min_bottom)), Vector((start.x, max_top)), color)
draw_line(SHADER, Vector((end.x, min_bottom)), Vector((end.x, max_top)), color)

if draw_arrows:
first_arrow_center = Vector(
[start.x + ((end.x - start.x) * 0.25), start.y])
second_arrow_center = Vector(
[end.x - ((end.x - start.x) * 0.25), start.y])
first_arrow_center = Vector([start.x + ((end.x - start.x) * 0.25), start.y])
second_arrow_center = Vector([end.x - ((end.x - start.x) * 0.25), start.y])
arrow_size = Vector([10, 20])

bgl.glLineWidth(6)
draw_arrow_head(SHADER,
first_arrow_center,
arrow_size,
color=color)
draw_arrow_head(SHADER,
second_arrow_center,
arrow_size,
points_right=False,
color=color)
draw_arrow_head(SHADER, first_arrow_center, arrow_size, color=color)
draw_arrow_head(SHADER, second_arrow_center, arrow_size, points_right=False, color=color)

bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
Expand Down
1 change: 0 additions & 1 deletion operators/mouse_trim.py
Expand Up @@ -112,7 +112,6 @@ def invoke(self, context, event):
else:
context.scene.frame_current = self.frame_start if self.frame_start else frame


# FIXME: Workaround Blender 2.80's audio bug, remove when fixed in Blender
for s in bpy.context.sequences:
if s.lock:
Expand Down
41 changes: 17 additions & 24 deletions operators/utils/draw.py
Expand Up @@ -40,34 +40,33 @@ def draw_line(shader, start, end, color=(1.0, 1.0, 1.0, 1.0)):


def draw_rectangle(shader, origin, size, color=(1.0, 1.0, 1.0, 1.0)):
vertices = ((origin.x, origin.y), (origin.x + size.x, origin.y),
(origin.x, origin.y + size.y), (origin.x + size.x,
origin.y + size.y))
vertices = (
(origin.x, origin.y),
(origin.x + size.x, origin.y),
(origin.x, origin.y + size.y),
(origin.x + size.x, origin.y + size.y),
)
indices = ((0, 1, 2), (2, 1, 3))
batch = batch_for_shader(shader,
'TRIS', {"pos": vertices},
indices=indices)
batch = batch_for_shader(shader, "TRIS", {"pos": vertices}, indices=indices)
shader.bind()
shader.uniform_float('color', color)
shader.uniform_float("color", color)
batch.draw(shader)


def draw_triangle(point_1, point_2, point_3, color=(1.0, 1.0, 1.0, 1.0)):
vertices = (point_1, point_2, point_3)
indices = ((0, 1, 2), )
shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
batch = batch_for_shader(shader,
'TRIS', {"pos": vertices},
indices=indices)
indices = ((0, 1, 2),)
shader = gpu.shader.from_builtin("2D_UNIFORM_COLOR")
batch = batch_for_shader(shader, "TRIS", {"pos": vertices}, indices=indices)
shader.bind()
shader.uniform_float('color', color)
shader.uniform_float("color", color)
batch.draw(shader)


def draw_text(x, y, size, text, justify='left', color=(1.0, 1.0, 1.0, 1.0)):
def draw_text(x, y, size, text, justify="left", color=(1.0, 1.0, 1.0, 1.0)):
font_id = 0
blf.color(font_id, *color)
if justify == 'right':
if justify == "right":
text_width, text_height = blf.dimensions(font_id, text)
else:
text_width = 0
Expand All @@ -76,23 +75,17 @@ def draw_text(x, y, size, text, justify='left', color=(1.0, 1.0, 1.0, 1.0)):
blf.draw(font_id, text)


def draw_arrow_head(shader,
center,
size,
points_right=True,
color=(1.0, 1.0, 1.0, 1.0)):
def draw_arrow_head(shader, center, size, points_right=True, color=(1.0, 1.0, 1.0, 1.0)):
"""
Draws a triangular arrow using two Vectors:
- the triangle's center
- the triangle's size
"""
direction = 1 if points_right else -1

point_upper = Vector(
[center.x - size.x / 2 * direction, center.y + size.y / 2])
point_upper = Vector([center.x - size.x / 2 * direction, center.y + size.y / 2])
point_tip = Vector([center.x + size.x / 2 * direction, center.y])
point_lower = Vector(
[center.x - size.x / 2 * direction, center.y - size.y / 2])
point_lower = Vector([center.x - size.x / 2 * direction, center.y - size.y / 2])

draw_line(shader, point_upper, point_tip, color)
draw_line(shader, point_tip, point_lower, color)
Expand Down

0 comments on commit 5c51508

Please sign in to comment.