当前位置: 首页>>代码示例>>Python>>正文


Python Shape.grabPoint方法代码示例

本文整理汇总了Python中shape.Shape.grabPoint方法的典型用法代码示例。如果您正苦于以下问题:Python Shape.grabPoint方法的具体用法?Python Shape.grabPoint怎么用?Python Shape.grabPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shape.Shape的用法示例。


在下文中一共展示了Shape.grabPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ShapeWindow

# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import grabPoint [as 别名]
class ShapeWindow(Window):
    LINE_COLOR = pygame.Color('white')
    SELECT_COLOR = pygame.Color('yellow')
    def __init__(self, main, x, y, width, height=0):
        Window.__init__(self, main, x, y, width, height)
        self.grid_size = 10
        self.grid_visible = True
        self.selected_point = None
        self.snap_to_grid = False

        self.shape = Shape()

    def setDirty(self):
        self.dirty = True
        self.main.layout_window.setDirty()

    def updateSurface(self):
        self.fillBgd()
        if self.grid_visible:
            self.drawGrid()
            
        offset_x = self.rect.width / 2
        offset_y = self.rect.height / 2
        
        for line in self.shape.getLines():
            pygame.draw.line(self.surface, self.LINE_COLOR,
                             (line.point1.x + offset_x,
                              line.point1.y + offset_y),
                             (line.point2.x + offset_x,
                              line.point2.y + offset_y))

        if self.selected_point:
            x = self.selected_point.x + offset_x
            y = self.selected_point.y + offset_y
            pygame.draw.circle(self.surface, self.SELECT_COLOR,
                               (x, y), 5, 1)
            coords_str = "(%d, %d)" % (x-offset_x, y-offset_y)
            coords_text = self.main.plain_font.render(coords_str, 1,
                                                      self.main.TEXT_COLOR)
            s = self.main.plain_font.size(coords_str)
            x -= s[0] / 2
            if x < 0:
                x = 0
            elif x > self.surface.get_width() - s[0]:
                x = self.surface.get_width() - s[0]
            offset = 20
            y -= offset
            if y < 0:
                y += 2*offset
            self.surface.blit(coords_text, (x, y))

    def handleLeftMouseDown(self, global_point):
        if not self.rect.collidepoint(global_point.x, global_point.y): return
        point = self.localPoint(global_point)
        print "shape display left down ", point.x, point.y
        if not self.selected_point:
            if self.snap_to_grid:
                point = self.snapToGrid(point)
            p2 = Point(point.x, point.y)
            self.shape.newLine(point, p2)
            self.shape.grabPoint(point)
            self.selected_point = self.shape.getPoint(point)
        self.shape.grabPoint(self.selected_point)
        self.setDirty()

    def handleRightMouseDown(self, global_point):
        if not self.rect.collidepoint(global_point.x, global_point.y): return
        point = self.localPoint(global_point)
        print "shape display right down ", point.x, point.y
        if len(self.shape.lines) > 0:
            self.shape.removeLine(self.selected_point)
            self.selected_point = None
            self.setDirty()

    def handleLeftMouseUp(self, global_point):
        if not self.rect.collidepoint(global_point.x, global_point.y): return
        point = self.localPoint(global_point)
        print "shape display left up ", point.x, point.y
        self.shape.releasePoint()

    def handleRightMouseUp(self, global_point):
        if not self.rect.collidepoint(global_point.x, global_point.y): return
        point = self.localPoint(global_point)
        print "shape display right up ", point.x, point.y

    def handleMouseMove(self, global_point, rel):
        if not self.rect.collidepoint(global_point.x, global_point.y): return
        point = self.localPoint(global_point)
        print "shape display mouse move ", point.x, point.y, ":", rel.x, rel.y
        prev = self.selected_point
        self.selected_point = self.shape.getPoint(point)

        if self.snap_to_grid:
            point = self.snapToGrid(point)
                    
        if self.shape.updatePoint(point) or self.selected_point != prev:
            self.setDirty()
开发者ID:Bredgren,项目名称:Fractals,代码行数:99,代码来源:shape_window.py


注:本文中的shape.Shape.grabPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。