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

grid.py (3201B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\graphs\grid.py
      2 import trinity
      3 from carbonui import uiconst
      4 from carbonui.graphs.axis import AxisOrientation
      5 from carbonui.primitives.vectorlinetrace import VectorLineTrace, CORNERTYPE_NONE
      6 from carbonui.text.color import TextColor
      7 from carbonui.uicore import uicore
      8 
      9 class Grid(VectorLineTrace):
     10     default_name = 'grid'
     11     default_align = uiconst.TOALL
     12     default_state = uiconst.UI_DISABLED
     13     default_lineWidth = 1
     14     default_spriteEffect = trinity.TR2_SFX_FILL
     15     default_cornerType = CORNERTYPE_NONE
     16     default_gridColor = TextColor.SECONDARY.rgba
     17     default_zeroColor = TextColor.NORMAL.rgba
     18 
     19     def ApplyAttributes(self, attributes):
     20         VectorLineTrace.ApplyAttributes(self, attributes)
     21         self._orientation = attributes['orientation']
     22         self._axis = attributes['axis']
     23         self._minFactor = attributes.get('minFactor', 0.0)
     24         self._maxFactor = attributes.get('maxFactor', 1.0)
     25         self.gridColor = attributes.get('gridColor', self.default_gridColor)
     26         self.zeroColor = attributes.get('zeroColor', self.default_zeroColor)
     27         self._axis.onChange.connect(self._Build)
     28         self._Build()
     29 
     30     def _GetTicks(self):
     31         width, height = self.GetAbsoluteSize()
     32         width *= uicore.dpiScaling
     33         height *= uicore.dpiScaling
     34         size = width if self._orientation == AxisOrientation.HORIZONTAL else height
     35         ticks = []
     36         offsets = []
     37         for tick in self._axis.GetTicks():
     38             v = self._minFactor + self._axis.MapToView(tick) * (self._maxFactor - self._minFactor)
     39             offset = v * size
     40             if offset < 0 or offset >= size:
     41                 continue
     42             ticks.append(tick)
     43             offsets.append(offset)
     44 
     45         return (ticks, offsets)
     46 
     47     def _Build(self, *_):
     48         width, height = self.GetAbsoluteSize()
     49         width *= uicore.dpiScaling
     50         height *= uicore.dpiScaling
     51         self.Flush()
     52         positions = []
     53         colors = []
     54         ticks, offsets = self._GetTicks()
     55         clearColor = self.gridColor[0:3] + (0,)
     56         for tick, offset in zip(ticks, offsets):
     57             if self._orientation == AxisOrientation.HORIZONTAL:
     58                 positions.append((offset, 0))
     59                 positions.append((offset, 0))
     60                 positions.append((offset, height))
     61                 positions.append((offset, height))
     62             else:
     63                 positions.append((0, offset))
     64                 positions.append((0, offset))
     65                 positions.append((width, offset))
     66                 positions.append((width, offset))
     67             if tick == 0:
     68                 colors.append(self.zeroColor[0:3] + (0,))
     69                 colors.append(self.zeroColor)
     70                 colors.append(self.zeroColor)
     71                 colors.append(self.zeroColor[0:3] + (0,))
     72             else:
     73                 colors.append(clearColor)
     74                 colors.append(self.gridColor)
     75                 colors.append(self.gridColor)
     76                 colors.append(clearColor)
     77 
     78         self.AppendVertices(positions, None, colors)
     79 
     80     def _OnResize(self, *args):
     81         self._Build()