Skip to content

Commit

Permalink
highlight current active handle yellow
Browse files Browse the repository at this point in the history
  • Loading branch information
yamahigashi committed Nov 30, 2017
1 parent c1dcc1a commit a777d3f
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions plug-ins/sceneRenderOverride.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(self, name):
def _initializeTemporalyVariables(self):
# type: () -> None

self.hiColor = om.MColor(om.MVector(1, 1, 0))

self.xcolor = om.MColor(om.MVector(1, 0, 0))
self.xmat = om.MMatrix((
(1, 0, 0, 0),
Expand Down Expand Up @@ -97,11 +99,11 @@ def addUIDrawables(self, drawManager, frameContext):
if not target:
return True

tool = self._getToolContext()
tool, axis = self._getToolContext()
if not tool:
return True

self._draw(drawManager, target, tool)
self._draw(drawManager, target, tool, axis)
return True

# ------------------------------------------------------------------------
Expand All @@ -119,22 +121,29 @@ def _getTargetDagPath(self):
return target

def _getToolContext(self):
# type: () -> Text
"""Return current current tool context as Text, "move" or "rotate"."""
# type: () -> Tuple[Text]
"""Return current current tool context and activeHandle as Text.
context: "move" or "rotate"
activeAxis: int [0: x, 1: y, 2:z, 3:not restricted]
"""

ctx = mel.eval("currentCtx;") # type: Text
if "move" in ctx.lower():
return "move"
activeHandle = mel.eval("manipMoveContext -q -currentActiveHandle Move;")
return "move", activeHandle

elif "rotate" in ctx.lower():
return "rotate"
activeHandle = mel.eval("manipRotateContext -q -currentActiveHandle Rotate;")
return "rotate", activeHandle

return ""
return "", None

# ------------------------------------------------------------------------

def _draw(self, manager, dagPath, tool):
# type: (omui.MUIDrawManager, om.MDagPath, Text) -> None
def _draw(self, manager, dagPath, tool, activeAxis):
# type: (omui.MUIDrawManager, om.MDagPath, Text, int) -> None
"""Draw manipulator shape using MUIDrawManager.
Depending the tool context, draw arrow gizmo or spherical gizmo.
Expand All @@ -154,16 +163,20 @@ def _draw(self, manager, dagPath, tool):
point = om.MPoint(posx, posy, posz)

manager.beginDrawable()
xcol = self.hiColor if activeAxis == 0 else self.xcolor
ycol = self.hiColor if activeAxis == 1 else self.ycolor
zcol = self.hiColor if activeAxis == 2 else self.zcolor


if "move" == tool:
self._drawArrow(manager, point, worldMat, rotMat, self.xmat, self.xcolor)
self._drawArrow(manager, point, worldMat, rotMat, self.ymat, self.ycolor)
self._drawArrow(manager, point, worldMat, rotMat, self.zmat, self.zcolor)
self._drawArrow(manager, point, worldMat, rotMat, self.xmat, xcol)
self._drawArrow(manager, point, worldMat, rotMat, self.ymat, ycol)
self._drawArrow(manager, point, worldMat, rotMat, self.zmat, zcol)

elif "rotate" == tool:
self._drawCircle(manager, point, worldMat, rotMat, self.xmat, self.xcolor)
self._drawCircle(manager, point, worldMat, rotMat, self.ymat, self.ycolor)
self._drawCircle(manager, point, worldMat, rotMat, self.zmat, self.zcolor)
self._drawCircle(manager, point, worldMat, rotMat, self.xmat, xcol)
self._drawCircle(manager, point, worldMat, rotMat, self.ymat, ycol)
self._drawCircle(manager, point, worldMat, rotMat, self.zmat, zcol)

manager.endDrawable()

Expand Down Expand Up @@ -273,7 +286,7 @@ def cleanup(self):
super(DrawManipulatorOverride, self).cleanup()

def supportedDrawAPIs(self):
# type: () -> None
# type: () -> int
return omr.MRenderer.kAllDevices

def startOperationIterator(self):
Expand Down

0 comments on commit a777d3f

Please sign in to comment.