⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _drawn.py

📁 Wxpython Implemented on Windows CE, Source code
💻 PY
📖 第 1 页 / 共 3 页
字号:
            # Look for the point we'd be connecting to. This is
            # a heuristic...
            for point in self._points:
                if point[0] == 0:
                    if y2 > y1 and point[1] > 0:
                        return point[0]+xOffset, point[1]+yOffset
                    elif y2 < y1 and point[1] < 0:
                        return point[0]+xOffset, point[1]+yOffset

        return FindEndForPolyline([ p[0] + xOffset for p in self._points ],
                                  [ p[1] + yOffset for p in self._points ],
                                  x1, y1, x2, y2)
    
                    
class PseudoMetaFile(object):
    """
    A simple metafile-like class which can load data from a Windows
    metafile on all platforms.
    """
    def __init__(self):
        self._currentRotation = 0
        self._rotateable = True
        self._width = 0.0
        self._height = 0.0
        self._outlinePen = None
        self._fillBrush = None
        self._outlineOp = -1
        
        self._ops = []
        self._gdiObjects = []
        
        self._outlineColours = []
        self._fillColours = []

    def Clear(self):
        self._ops = []
        self._gdiObjects = []
        self._outlineColours = []
        self._fillColours = []
        self._outlineColours = -1

    def IsValid(self):
        return self._ops != []

    def GetOps(self):
        return self._ops

    def SetOutlineOp(self, op):
        self._outlineOp = op

    def GetOutlineOp(self):
        return self._outlineOp

    def SetOutlinePen(self, pen):
        self._outlinePen = pen

    def GetOutlinePen(self, pen):
        return self._outlinePen

    def SetFillBrush(self, brush):
        self._fillBrush = brush

    def GetFillBrush(self):
        return self._fillBrush

    def SetSize(self, w, h):
        self._width = w
        self._height = h

    def SetRotateable(self, rot):
        self._rotateable = rot
        
    def GetRotateable(self):
        return self._rotateable

    def GetFillColours(self):
        return self._fillColours

    def GetOutlineColours(self):
        return self._outlineColours
    
    def Draw(self, dc, xoffset, yoffset):
        for op in self._ops:
            op.Do(dc, xoffset, yoffset)

    def Scale(self, sx, sy):
        for op in self._ops:
            op.Scale(sx, sy)

        self._width *= sx
        self._height *= sy

    def Translate(self, x, y):
        for op in self._ops:
            op.Translate(x, y)

    def Rotate(self, x, y, theta):
        theta1 = theta - self._currentRotation
        if theta1 == 0:
            return

        cosTheta = math.cos(theta1)
        sinTheta = math.sin(theta1)

        for op in self._ops:
            op.Rotate(x, y, theta, sinTheta, cosTheta)

        self._currentRotation = theta

    def LoadFromMetaFile(self, filename, rwidth, rheight):
        if not os.path.exist(filename):
            return False

        print "LoadFromMetaFile not implemented yet."
        return False # TODO

    # Scale to fit size
    def ScaleTo(self, w, h):
        scaleX = w / self._width
        scaleY = h / self._height

        self.Scale(scaleX, scaleY)

    def GetBounds(self):
        maxX, maxY, minX, minY = -99999.9, -99999.9, 99999.9, 99999.9

        for op in self._ops:
            if op.GetOp() in [DRAWOP_DRAW_LINE, DRAWOP_DRAW_RECT, DRAWOP_DRAW_ROUNDED_RECT, DRAWOP_DRAW_ELLIPSE, DRAWOP_DRAW_POINT, DRAWOP_DRAW_TEXT]:
                if op._x1 < minX:
                    minX = op._x1
                if op._x1 > maxX:
                    maxX = op._x1
                if op._y1 < minY:
                    minY = op._y1
                if op._y1 > maxY:
                    maxY = op._y1
                if op.GetOp() == DRAWOP_DRAW_LINE:
                    if op._x2 < minX:
                        minX = op._x2
                    if op._x2 > maxX:
                        maxX = op._x2
                    if op._y2 < minY:
                        minY = op._y2
                    if op._y2 > maxY:
                        maxY = op._y2
                elif op.GetOp() in [ DRAWOP_DRAW_RECT, DRAWOP_DRAW_ROUNDED_RECT, DRAWOP_DRAW_ELLIPSE]:
                    if op._x1 + op._x2 < minX:
                        minX = op._x1 + op._x2
                    if op._x1 + op._x2 > maxX:
                        maxX = op._x1 + op._x2
                    if op._y1 + op._y2 < minY:
                        minY = op._y1 + op._y2
                    if op._y1 + op._y2 > maxX:
                        maxY = op._y1 + op._y2
            elif op.GetOp() == DRAWOP_DRAW_ARC:
                # TODO: don't yet know how to calculate the bounding box
                # for an arc. So pretend it's a line; to get a correct
                # bounding box, draw a blank rectangle first, of the 
                # correct size.
                if op._x1 < minX:
                    minX = op._x1
                if op._x1 > maxX:
                    maxX = op._x1
                if op._y1 < minY:
                    minY = op._y1
                if op._y1 > maxY:
                    maxY = op._y1
                if op._x2 < minX:
                    minX = op._x2
                if op._x2 > maxX:
                    maxX = op._x2
                if op._y2 < minY:
                    minY = op._y2
                if op._y2 > maxY:
                    maxY = op._y2
            elif op.GetOp() in [DRAWOP_DRAW_POLYLINE, DRAWOP_DRAW_POLYGON, DRAWOP_DRAW_SPLINE]:
                for point in op._points:
                    if point[0] < minX:
                        minX = point[0]
                    if point[0] > maxX:
                        maxX = point[0]
                    if point[1] < minY:
                        minY = point[1]
                    if point[1] > maxY:
                        maxY = point[1]

        return [minX, minY, maxX, maxY]

    # Calculate size from current operations
    def CalculateSize(self, shape):
        boundMinX, boundMinY, boundMaxX, boundMaxY = self.GetBounds()

        # By Pierre Hj鋖m: This is NOT in the old version, which
        # gets this totally wrong. Since the drawing is centered, we
        # cannot get the width by measuring from left to right, we
        # must instead make enough room to handle the largest
        # coordinates
        #self.SetSize(boundMaxX - boundMinX, boundMaxY - boundMinY)

        w = max(abs(boundMinX), abs(boundMaxX)) * 2
        h = max(abs(boundMinY), abs(boundMaxY)) * 2
        
        self.SetSize(w, h)
        
        if shape:
            shape.SetWidth(self._width)
            shape.SetHeight(self._height)

    # Set of functions for drawing into a pseudo metafile
    def DrawLine(self, pt1, pt2):
        op = OpDraw(DRAWOP_DRAW_LINE, pt1[0], pt1[1], pt2[0], pt2[1])
        self._ops.append(op)

    def DrawRectangle(self, rect):
        op = OpDraw(DRAWOP_DRAW_RECT, rect[0], rect[1], rect[2], rect[3])
        self._ops.append(op)

    def DrawRoundedRectangle(self, rect, radius):
        op = OpDraw(DRAWOP_DRAW_ROUNDED_RECT, rect[0], rect[1], rect[2], rect[3])
        op._radius = radius
        self._ops.append(op)

    def DrawEllipse(self, rect):
        op = OpDraw(DRAWOP_DRAW_ELLIPSE, rect[0], rect[1], rect[2], rect[3])
        self._ops.append(op)

    def DrawArc(self, centrePt, startPt, endPt):
        op = OpDraw(DRAWOP_DRAW_ARC, centrePt[0], centrePt[1], startPt[0], startPt[1])
        op._x3, op._y3 = endPt

        self._ops.append(op)

    def DrawEllipticArc(self, rect, startAngle, endAngle):
        startAngleRadians = startAngle * math.pi * 2 / 360
        endAngleRadians = endAngle * math.pi * 2 / 360

        op = OpDraw(DRAWOP_DRAW_ELLIPTIC_ARC, rect[0], rect[1], rect[2], rect[3])
        op._x3 = startAngleRadians
        op._y3 = endAngleRadians

        self._ops.append(op)

    def DrawPoint(self, pt):
        op = OpDraw(DRAWOP_DRAW_POINT, pt[0], pt[1], 0, 0)
        self._ops.append(op)

    def DrawText(self, text, pt):
        op = OpDraw(DRAWOP_DRAW_TEXT, pt[0], pt[1], 0, 0)
        op._textString = text
        self._ops.append(op)

    def DrawLines(self, pts):
        op = OpPolyDraw(DRAWOP_DRAW_POLYLINE, pts)
        self._ops.append(op)

    # flags:
    # oglMETAFLAGS_OUTLINE: will be used for drawing the outline and
    #                       also drawing lines/arrows at the circumference.
    # oglMETAFLAGS_ATTACHMENTS: will be used for initialising attachment
    #                       points at the vertices (perhaps a rare case...)
    def DrawPolygon(self, pts, flags = 0):
        op = OpPolyDraw(DRAWOP_DRAW_POLYGON, pts)
        self._ops.append(op)

        if flags & METAFLAGS_OUTLINE:
            self._outlineOp = len(self._ops) - 1

    def DrawSpline(self, pts):
        op = OpPolyDraw(DRAWOP_DRAW_SPLINE, pts)
        self._ops.append(op)

    def SetClippingRect(self, rect):
        OpSetClipping(DRAWOP_SET_CLIPPING_RECT, rect[0], rect[1], rect[2], rect[3])

    def DestroyClippingRect(self):
        op = OpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT, 0, 0, 0, 0)
        self._ops.append(op)

    def SetPen(self, pen, isOutline = False):
        self._gdiObjects.append(pen)
        op = OpSetGDI(DRAWOP_SET_PEN, self, len(self._gdiObjects) - 1)
        self._ops.append(op)

        if isOutline:
            self._outlineColours.append(len(self._gdiObjects) - 1)

    def SetBrush(self, brush, isFill = False):
        self._gdiObjects.append(brush)
        op = OpSetGDI(DRAWOP_SET_BRUSH, self, len(self._gdiObjects) - 1)
        self._ops.append(op)

        if isFill:
            self._fillColours.append(len(self._gdiObjects) - 1)

    def SetFont(self, font):
        self._gdiObjects.append(font)
        op = OpSetGDI(DRAWOP_SET_FONT, self, len(self._gdiObjects) - 1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -