NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

vertex.py (1878B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\drawingpolygon\components\vertex.py
      2 from drawingpolygon.drawingelement import DrawingElement
      3 from drawingpolygon.operations import are_points_within_distance
      4 from carbonui.primitives.sprite import Sprite
      5 VERTEX_SIZE = 16
      6 VERTEX_OVERLAP_RANGE = 16
      7 
      8 class PolygonVertex(DrawingElement, Sprite):
      9     default_width = VERTEX_SIZE
     10     default_height = VERTEX_SIZE
     11     default_draggingTexturePath = None
     12 
     13     def ApplyAttributes(self, attributes):
     14         super(PolygonVertex, self).ApplyAttributes(attributes)
     15         self.order = attributes.get('order')
     16         self.dragging_texture = attributes.get('draggingTexturePath', self.default_draggingTexturePath)
     17         self.base_texture = self.texturePath
     18         self.update_position(x=attributes.get('x'), y=attributes.get('y'))
     19 
     20     def update_position(self, x, y):
     21         self.x = x
     22         self.y = y
     23         self.left = x - VERTEX_SIZE / 2
     24         self.top = y - VERTEX_SIZE / 2
     25 
     26     def set_texture(self, texture_path):
     27         self.SetTexturePath(texture_path)
     28 
     29     def set_base_texture(self, texture_path):
     30         self.base_texture = texture_path
     31         self.reset_texture()
     32 
     33     def reset_texture(self):
     34         self.SetTexturePath(self.base_texture)
     35 
     36     def is_within_range(self, other_vertex):
     37         point_1 = [self.x, self.y]
     38         point_2 = [other_vertex.x, other_vertex.y]
     39         return are_points_within_distance(point_1, point_2, VERTEX_OVERLAP_RANGE)
     40 
     41     def OnMouseMove(self, *args):
     42         super(PolygonVertex, self).OnMouseMove(*args)
     43         if self.dragging_texture and self.is_dragging:
     44             self.set_texture(self.dragging_texture)
     45 
     46     def OnMouseUp(self, *args):
     47         super(PolygonVertex, self).OnMouseUp(*args)
     48         if self.dragging_texture and not self.is_dragging:
     49             self.reset_texture()