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

elevated.py (7192B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dynamicresources\client\ui\elevated.py
      2 from __future__ import division
      3 import math
      4 import weakref
      5 import eveui
      6 import signals
      7 import trinity
      8 from carbonui import uiconst
      9 from carbonui.primitives.container import Container
     10 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     11 from carbonui.uicore import uicore
     12 
     13 class ElevatedControllerBase(object):
     14 
     15     def __init__(self):
     16         self.inertia = 2.0
     17         self.elevation_inertia_coefficient = 1.0
     18         self.focus_position = None
     19         self.focus_falloff = 100.0
     20         self.focus_elevation_multiplier = 5.0
     21         self._closed = False
     22         self.on_close = signals.Signal()
     23         self.on_update = signals.Signal()
     24 
     25     @property
     26     def closed(self):
     27         return self._closed
     28 
     29     def close(self):
     30         self._closed = True
     31         self.on_close()
     32 
     33 
     34 class CurveSetBinding(object):
     35 
     36     def __init__(self, curve_set, obj):
     37         self._object_ref = weakref.ref(obj)
     38         self._curve_set_ref = weakref.ref(curve_set)
     39         curve_set.curves.append(obj)
     40 
     41     def __del__(self):
     42         obj = self._object_ref()
     43         curve_set = self._curve_set_ref()
     44         if obj is not None and curve_set is not None:
     45             curve_set.curves.fremove(obj)
     46 
     47 
     48 class ElevatedController(ElevatedControllerBase):
     49 
     50     def __init__(self, transform):
     51         self._transform = transform
     52         super(ElevatedController, self).__init__()
     53         self.follow_mouse = False
     54         self._tracker = None
     55         self._tracker_binding = None
     56         self._init_tracker()
     57 
     58     @property
     59     def transform(self):
     60         return self._transform
     61 
     62     @transform.setter
     63     def transform(self, transform):
     64         self._transform = transform
     65         if self._tracker:
     66             self._tracker.trackTransform = self._transform
     67 
     68     @property
     69     def offset_target(self):
     70         if self.follow_mouse:
     71             return eveui.Mouse.position()
     72         else:
     73             l, t, w, h = uicore.layer.inflight.GetAbsolute()
     74             return (w / 2 - l, h / 2 - t)
     75 
     76     def _init_tracker(self):
     77         self._tracker = trinity.EveProjectBracket()
     78         self._tracker.parent = uicore.layer.inflight.GetRenderObject()
     79         self._tracker.trackTransform = self._transform
     80 
     81         def update_callback(tracker, object_ref = weakref.ref(self)):
     82             obj = object_ref()
     83             if obj is not None:
     84                 obj._update()
     85 
     86         self._tracker.bracketUpdateCallback = update_callback
     87         self._tracker_binding = CurveSetBinding(uicore.uilib.bracketCurveSet, self._tracker)
     88 
     89     def _stop_tracker(self):
     90         self._tracker.bracketUpdateCallback = None
     91         self._tracker = None
     92         self._tracker_binding = None
     93 
     94     def close(self):
     95         if self._tracker is not None:
     96             self._stop_tracker()
     97         super(ElevatedController, self).close()
     98 
     99     def _update(self):
    100         bracket_x, bracket_y = self._tracker.projectedPosition
    101         bracket_x = eveui.reverse_scale_dpi(bracket_x)
    102         bracket_y = eveui.reverse_scale_dpi(bracket_y)
    103         self.on_update((bracket_x, bracket_y))
    104 
    105 
    106 class ElevatedBase(Container):
    107 
    108     def __init__(self, controller, layer, anchor = (0.5, 0.5), elevation = 0.0, offset = (0, 0), parent = None, **kwargs):
    109         super(ElevatedBase, self).__init__(parent=layer, align=uiconst.TOPLEFT, **kwargs)
    110         self._controller = controller
    111         self._elevation = elevation
    112         self._anchor = anchor
    113         self._offset = offset
    114         self._parent = parent
    115         self._current_position = None
    116         self._controller.on_update.connect(self._on_update)
    117         self._controller.on_close.connect(self.Close)
    118 
    119     @property
    120     def offset(self):
    121         return self._offset
    122 
    123     @offset.setter
    124     def offset(self, offset):
    125         self._offset = offset
    126 
    127     @property
    128     def controller(self):
    129         return self._controller
    130 
    131     def _on_update(self, position):
    132         old_x, old_y = position
    133         if self._current_position is not None:
    134             old_x, old_y = self._current_position
    135         x, y = position
    136         offset_x, offset_y = self._get_offset()
    137         x += offset_x
    138         y += offset_y
    139         inertia_multiplier = 1.0 + abs(self._elevation * self._controller.elevation_inertia_coefficient)
    140         divisor = 1.0 + self._controller.inertia * inertia_multiplier
    141         delta_x = (x - old_x) / divisor
    142         delta_y = (y - old_y) / divisor
    143         if abs(delta_x) <= 1.0:
    144             delta_x = 0.0
    145         if abs(delta_y) <= 1.0:
    146             delta_y = 0.0
    147         anchor_x, anchor_y = self._anchor
    148         width, height = self.GetCurrentAbsoluteSize()
    149         if width is None:
    150             width = 0
    151         if height is None:
    152             height = 0
    153         if self._elevation > 0:
    154             left = old_x - anchor_x * width + delta_x
    155             top = old_y - anchor_y * height + delta_y
    156         else:
    157             left = x + (x - old_x) - anchor_x * width - delta_x
    158             top = y + (y - old_y) - anchor_y * height - delta_y
    159         focus_position = self._controller.focus_position
    160         if focus_position is not None:
    161             focus_x = focus_position[0] - x
    162             focus_y = focus_position[1] - y
    163             focus_distance = math.sqrt(focus_x ** 2 + focus_y ** 2)
    164             if focus_distance < self._controller.focus_falloff:
    165                 focus_distance *= self._controller.focus_falloff / focus_distance
    166             focus_x /= focus_distance
    167             focus_y /= focus_distance
    168             elevation_multiplier = self._elevation * self._controller.focus_elevation_multiplier
    169             left += focus_x * elevation_multiplier
    170             top += focus_y * elevation_multiplier
    171         self.left = left
    172         self.top = top
    173         self._current_position = (old_x + delta_x, old_y + delta_y)
    174 
    175     def _get_offset(self):
    176         if self._parent is not None:
    177             parent_offset_x, parent_offset_y = self._parent.offset
    178             return (self._offset[0] + parent_offset_x, self._offset[1] + parent_offset_y)
    179         else:
    180             return self._offset
    181 
    182     def Close(self):
    183         self._controller.on_update.disconnect(self._on_update)
    184         self._controller.on_close.disconnect(self.Close)
    185         super(ElevatedBase, self).Close()
    186 
    187 
    188 class ElevatedContainer(ElevatedBase):
    189     default_name = 'ElevatedContainer'
    190 
    191     def __init__(self, controller, layer, anchor = (0.5, 0.5), elevation = 0.0, offset = (0, 0), parent = None, width = 0, height = 0):
    192         super(ElevatedContainer, self).__init__(controller=controller, layer=layer, anchor=anchor, elevation=elevation, width=width, height=height, offset=offset, parent=parent)
    193 
    194 
    195 class ElevatedContainerAutoSize(ElevatedBase, ContainerAutoSize):
    196     default_name = 'ElevatedContainerAutoSize'
    197 
    198     def __init__(self, controller, layer, anchor = (0.5, 0.5), elevation = 0.0, offset = (0, 0), parent = None, width = 0, height = 0, align_mode = None):
    199         super(ElevatedContainerAutoSize, self).__init__(controller=controller, layer=layer, anchor=anchor, elevation=elevation, width=width, height=height, offset=offset, parent=parent, alignMode=align_mode)