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

xbutton.py (6158B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\drawingpolygon\xbutton.py
      2 from carbonui import uiconst
      3 from carbonui.primitives.container import Container
      4 from carbonui.primitives.sprite import Sprite
      5 from carbonui.uicore import uicore
      6 TEXTURES_FOLDER = 'res:/UI/Texture/classes/DrawingTool/x_button/'
      7 TEXTURE_X = TEXTURES_FOLDER + 'x.png'
      8 TEXTURE_BLACK_CIRCLE = TEXTURES_FOLDER + 'black_circle.png'
      9 TEXTURE_BLUE_CIRCLE = TEXTURES_FOLDER + 'blue_circle.png'
     10 TEXTURE_WHITE_RING = TEXTURES_FOLDER + 'white_ring.png'
     11 TEXTURE_CLEAR = TEXTURES_FOLDER + 'clear.png'
     12 BLUE_COLOR = (0.2, 0.74, 0.95, 1.0)
     13 WHITE_COLOR = (1.0, 1.0, 1.0, 1.0)
     14 ICON_SIZE = 32
     15 LARGE_X_SIZE = 44
     16 CLEAR_WIDTH = 42
     17 CLEAR_HEIGHT = 18
     18 PADDING_ICON_TO_CLEAR = 8
     19 ANIMATION_CLICK_SECONDS = 0.2
     20 ANIMATION_HOVER_SECONDS = 0.5
     21 
     22 class XButton(Container):
     23     default_state = uiconst.UI_NORMAL
     24     default_width = ICON_SIZE
     25     default_height = ICON_SIZE
     26 
     27     def ApplyAttributes(self, attributes):
     28         super(XButton, self).ApplyAttributes(attributes)
     29         self.button_function = attributes.get('button_function')
     30         self.setup_x_area()
     31         self.setup_tooltip_area()
     32 
     33     def setup_x_area(self):
     34         x_area = Container(name='x_area', parent=self, align=uiconst.TOLEFT, width=ICON_SIZE, state=uiconst.UI_DISABLED)
     35         self.x_sprite = Sprite(name='x_sprite', parent=x_area, align=uiconst.CENTER, width=ICON_SIZE, height=ICON_SIZE, texturePath=TEXTURE_X, color=BLUE_COLOR)
     36         self.black_circle = Sprite(name='black_circle', parent=x_area, align=uiconst.CENTER, width=ICON_SIZE, height=ICON_SIZE, texturePath=TEXTURE_BLACK_CIRCLE)
     37         self.blue_circle = Sprite(name='blue_circle', parent=x_area, align=uiconst.CENTER, width=ICON_SIZE, height=ICON_SIZE, texturePath=TEXTURE_BLUE_CIRCLE)
     38         self.white_ring = Sprite(name='white_ring', parent=x_area, align=uiconst.CENTER, width=ICON_SIZE, height=ICON_SIZE, texturePath=TEXTURE_WHITE_RING, opacity=0.0)
     39 
     40     def setup_tooltip_area(self):
     41         tooltip_area = Container(name='tooltip_area', parent=self, align=uiconst.TOLEFT, width=CLEAR_WIDTH, state=uiconst.UI_DISABLED, padLeft=PADDING_ICON_TO_CLEAR)
     42         self.clear_tooltip = Sprite(name='clear_tooltip', parent=tooltip_area, align=uiconst.CENTER, width=CLEAR_WIDTH, height=CLEAR_HEIGHT, texturePath=TEXTURE_CLEAR, opacity=0.0)
     43 
     44     def OnClick(self, *args):
     45         super(XButton, self).OnClick(*args)
     46         self.button_function()
     47 
     48     def OnMouseDown(self, *args):
     49         super(XButton, self).OnMouseDown(*args)
     50         self._restore_ring()
     51         self._restore_black_circle_to_hovered()
     52         self._restore_x_to_hovered()
     53         self._restore_tooltip_to_normal()
     54         self._animate_ring_on_click()
     55         self._animate_x_on_click()
     56 
     57     def OnMouseUp(self, *args):
     58         super(XButton, self).OnMouseUp(*args)
     59         self._restore_ring()
     60         self._restore_black_circle_to_normal()
     61         self._restore_x_to_normal()
     62 
     63     def OnMouseEnter(self, *args):
     64         super(XButton, self).OnMouseEnter(*args)
     65         self._restore_black_circle_to_normal()
     66         self._restore_x_to_normal()
     67         self._restore_tooltip_to_normal()
     68         self._animate_black_circle_on_hover()
     69         self._animate_x_on_hover()
     70         self._animate_tooltip_on_hover()
     71 
     72     def OnMouseExit(self, *args):
     73         super(XButton, self).OnMouseExit(*args)
     74         self._restore_black_circle_to_normal()
     75         self._restore_x_to_normal()
     76         self._restore_tooltip_to_normal()
     77 
     78     def _animate_ring_on_click(self):
     79         animate = uicore.animations.FadeIn
     80         animate(self.white_ring, duration=ANIMATION_CLICK_SECONDS)
     81 
     82     def _animate_x_on_click(self):
     83         animate = uicore.animations.MorphScalar
     84         duration = ANIMATION_CLICK_SECONDS
     85         start_width, start_height = self.x_sprite.width, self.x_sprite.height
     86         end_width, end_height = ICON_SIZE, ICON_SIZE
     87         animate(self.x_sprite, 'width', start_width, end_width, duration)
     88         animate(self.x_sprite, 'height', start_height, end_height, duration)
     89 
     90     def _animate_x_on_hover(self):
     91         animate = uicore.animations.MorphScalar
     92         duration = ANIMATION_HOVER_SECONDS
     93         start_width, start_height = self.x_sprite.width, self.x_sprite.height
     94         end_width, end_height = LARGE_X_SIZE, LARGE_X_SIZE
     95         animate(self.x_sprite, 'width', start_width, end_width, duration)
     96         animate(self.x_sprite, 'height', start_height, end_height, duration)
     97         animate = uicore.animations.SpColorMorphToWhite
     98         duration = ANIMATION_HOVER_SECONDS
     99         animate(self.x_sprite, duration)
    100 
    101     def _animate_black_circle_on_hover(self):
    102         animate = uicore.animations.MorphScalar
    103         duration = ANIMATION_HOVER_SECONDS
    104         start_width, start_height = self.black_circle.width, self.black_circle.height
    105         end_width, end_height = (0, 0)
    106         animate(self.black_circle, 'width', start_width, end_width, duration)
    107         animate(self.black_circle, 'height', start_height, end_height, duration)
    108 
    109     def _animate_tooltip_on_hover(self):
    110         animate = uicore.animations.FadeIn
    111         animate(self.clear_tooltip, duration=ANIMATION_HOVER_SECONDS)
    112 
    113     def _restore_ring(self):
    114         self.white_ring.StopAnimations()
    115         self.white_ring.opacity = 0.0
    116 
    117     def _restore_black_circle_to_normal(self):
    118         self.black_circle.StopAnimations()
    119         self.black_circle.width, self.black_circle.height = ICON_SIZE, ICON_SIZE
    120 
    121     def _restore_x_to_normal(self):
    122         self.x_sprite.StopAnimations()
    123         self.x_sprite.width, self.x_sprite.height = ICON_SIZE, ICON_SIZE
    124         self.x_sprite.SetRGBA(*BLUE_COLOR)
    125 
    126     def _restore_tooltip_to_normal(self):
    127         self.clear_tooltip.StopAnimations()
    128         self.clear_tooltip.opacity = 0.0
    129 
    130     def _restore_black_circle_to_hovered(self):
    131         self.black_circle.StopAnimations()
    132         self.black_circle.width, self.black_circle.height = (0, 0)
    133 
    134     def _restore_x_to_hovered(self):
    135         self.x_sprite.StopAnimations()
    136         self.x_sprite.width, self.x_sprite.height = LARGE_X_SIZE, LARGE_X_SIZE
    137         self.x_sprite.SetRGBA(*WHITE_COLOR)