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

transform.py (4512B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\primitives\transform.py
      2 import math
      3 import blue
      4 import log
      5 import trinity
      6 from carbonui import uiconst
      7 from carbonui.primitives.container import Container
      8 
      9 class Transform(Container):
     10     __guid__ = 'uiprimitives.Transform'
     11     __renderObject__ = trinity.Tr2Sprite2dTransform
     12     default_align = uiconst.RELATIVE
     13     default_state = uiconst.UI_PICKCHILDREN
     14     default_rotation = 0.0
     15     default_rotationCenter = (0.5, 0.5)
     16     default_scale = (1, 1)
     17     default_scalingCenter = (0, 0)
     18     default_scalingRotation = 0.0
     19     isTransformed = True
     20 
     21     def ApplyAttributes(self, attributes):
     22         Container.ApplyAttributes(self, attributes)
     23         self.rotation = attributes.get('rotation', self.default_rotation)
     24         self.rotationCenter = attributes.get('rotationCenter', self.default_rotationCenter)
     25         self.scale = attributes.get('scale', self.default_scale)
     26         self.scalingCenter = attributes.get('scalingCenter', self.default_scalingCenter)
     27         self.scalingRotation = attributes.get('scalingRotation', self.default_scalingRotation)
     28 
     29     def SetRotation(self, rotation = 0):
     30         self.rotation = rotation
     31 
     32     def GetRotation(self):
     33         return self.rotation
     34 
     35     @property
     36     def scale(self):
     37         return self._scale
     38 
     39     @scale.setter
     40     def scale(self, value):
     41         self._scale = value
     42         ro = self.renderObject
     43         if ro:
     44             ro.scale = value
     45 
     46     @property
     47     def scalingCenter(self):
     48         return self._scalingCenter
     49 
     50     @scalingCenter.setter
     51     def scalingCenter(self, value):
     52         self._scalingCenter = value
     53         ro = self.renderObject
     54         if ro:
     55             ro.scalingCenter = value
     56 
     57     @property
     58     def scalingRotation(self):
     59         return self._scalingRotation
     60 
     61     @scalingRotation.setter
     62     def scalingRotation(self, value):
     63         self._scalingRotation = value
     64         ro = self.renderObject
     65         if ro:
     66             ro.scalingRotation = value
     67 
     68     @property
     69     def rotation(self):
     70         return self._rotation
     71 
     72     @rotation.setter
     73     def rotation(self, value):
     74         self._rotation = value
     75         ro = self.renderObject
     76         if ro:
     77             ro.rotation = -value
     78 
     79     @property
     80     def rotationCenter(self):
     81         return self._rotationCenter
     82 
     83     @rotationCenter.setter
     84     def rotationCenter(self, value):
     85         self._rotationCenter = value
     86         ro = self.renderObject
     87         if ro:
     88             ro.rotationCenter = self._rotationCenter
     89 
     90     def StartRotationCycle(self, direction = 1, cycleTime = 1000.0, cycles = None):
     91         if getattr(self, '_rotateCycle', False):
     92             self._rotateCycle = False
     93             blue.pyos.synchro.Yield()
     94         self._rotateCycle = True
     95         fullRotation = math.pi * 2
     96         start = blue.os.GetWallclockTime()
     97         ndt = 0.0
     98         current = self.GetRotation()
     99         while getattr(self, '_rotateCycle', False):
    100             try:
    101                 ndt = max(ndt, blue.os.TimeDiffInMs(start, blue.os.GetWallclockTime()) / cycleTime)
    102             except:
    103                 log.LogWarn('StartRotationCycle::Failed getting time diff. Diff should not exceed %s but is %s' % (cycleTime, start - blue.os.GetWallclockTimeNow()))
    104                 ndt = 1.0
    105 
    106             self.SetRotation(current - fullRotation * ndt * direction)
    107             blue.pyos.synchro.Yield()
    108             if self.destroyed:
    109                 return
    110             if cycles is not None and cycles <= int(ndt):
    111                 return
    112 
    113     def Rotate(self, delta):
    114         newRotation = self.ClampRotation(self.rotation + delta)
    115         self.rotation = newRotation
    116 
    117     def ClampRotation(self, rotation):
    118         if rotation > math.pi * 2:
    119             rotation -= math.pi * 2
    120         elif rotation < 0:
    121             rotation += math.pi * 2
    122         return rotation
    123 
    124     def StopRotationCycle(self):
    125         self._rotateCycle = False
    126 
    127     def TransformPoint(self, x, y):
    128         return self.renderObject.TransformPoint(x, y)
    129 
    130     def _GetScale(self):
    131         return self.scale
    132 
    133     def _GetAbsolutePosition(self, childLeft, childTop):
    134         parent = self.GetParent()
    135         left, top = self._GetRelativePosition()
    136         childLeft, childTop = self.TransformPoint(childLeft, childTop)
    137         left += childLeft
    138         top += childTop
    139         if parent and self.align not in (uiconst.ABSOLUTE, uiconst.NOALIGN):
    140             left, top = parent._GetAbsolutePosition(left, top)
    141         return (left, top)