Draw Rectangle and Polygon In Squsih

时间:2016-07-11 22:13:44

标签: squish

How to draw a rectangle, ellipse, circle and polygon using mouse press and mouse release or mouse drag in Squish.

1 个答案:

答案 0 :(得分:1)

您可以使用mousePressmouseMovemouseRelease功能执行此操作。

您可以将所有这些形状描述为一系列点,例如顺时针。因此,位于150/200的宽度为300像素,高100像素的矩形可以描述为

rectangle = [(150,200), (450,200), (450,300), (150, 300)]

然后,您可以将此点列表提供给通用函数' drawShape'或者这样绘制形状,就像这样(在Python中,但同样的事情可以在Squish支持的任何其他脚本语言中完成):

def drawShape(shape):
    firstPoint = shape[0]

    # Press mouse button at first position
    mousePress(firstPoint[0], firstPoint[1], MouseButton.PrimaryButton)

    # Call mouseMove repeatedly for all subsequent positions
    for x in range(1, len(shape)):
        mouseMove(shape[x][0], shape[x][1])

    # Close the shape by connecting last with the first position
    mouseMove(firstPoint[0], firstPoint[1])

    # Release mouse button to finish drawing
    mouseRelease()