divider.py (4173B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\divider.py 2 import mathext 3 from carbonui import Axis, AxisAlignment, uiconst 4 from carbonui.decorative.resize_handle import ResizeHandle 5 from carbonui.primitives.container import Container 6 from carbonui.uicore import uicore 7 8 def axis_from_legacy_xory(xory): 9 if xory == 'x': 10 return Axis.HORIZONTAL 11 if xory == 'y': 12 return Axis.VERTICAL 13 14 15 class Divider(Container): 16 _axis = None 17 _drag_start_x = None 18 _drag_start_y = None 19 _dragging = False 20 _property_name = None 21 _property_value_initial = None 22 _property_value_max = None 23 _property_value_min = None 24 _target = None 25 _line = None 26 27 def __init__(self, show_line = False, cross_axis_alignment = AxisAlignment.CENTER, **kwargs): 28 super(Divider, self).__init__(**kwargs) 29 self._handle = ResizeHandle(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, orientation=Axis.HORIZONTAL, show_line=show_line, cross_axis_alignment=cross_axis_alignment) 30 31 @property 32 def cross_axis_alignment(self): 33 return self._handle.cross_axis_alignment 34 35 @cross_axis_alignment.setter 36 def cross_axis_alignment(self, value): 37 self._handle.cross_axis_alignment = value 38 39 @property 40 def min(self): 41 return self._property_value_min 42 43 @min.setter 44 def min(self, value): 45 self._property_value_min = value 46 47 @property 48 def max(self): 49 return self._property_value_max 50 51 @max.setter 52 def max(self, value): 53 self._property_value_max = value 54 55 @property 56 def show_line(self): 57 return self._handle.show_line 58 59 @show_line.setter 60 def show_line(self, value): 61 self._handle.show_line = value 62 63 def Close(self): 64 self.OnSizeChanged = None 65 self.OnSizeChanging = None 66 self.OnSizeChangeStarting = None 67 super(Divider, self).Close() 68 69 def Startup(self, victim, attribute, xory, minValue = 1, maxValue = 1600): 70 self._target = victim 71 self._property_name = attribute 72 self._axis = axis_from_legacy_xory(xory) 73 self._handle.orientation = self._get_handle_orientation() 74 self.SetMinMax(minValue, maxValue) 75 if self._axis == Axis.HORIZONTAL: 76 self.cursor = uiconst.UICORSOR_HORIZONTAL_RESIZE 77 else: 78 self.cursor = uiconst.UICORSOR_VERTICAL_RESIZE 79 80 def _get_handle_orientation(self): 81 if self._axis == Axis.HORIZONTAL: 82 return Axis.VERTICAL 83 if self._axis == Axis.VERTICAL: 84 return Axis.HORIZONTAL 85 86 def OnMouseDown(self, *args): 87 self._dragging = True 88 self.OnSizeChangeStarting(self) 89 self._drag_start_x = uicore.uilib.x 90 self._drag_start_y = uicore.uilib.y 91 self._property_value_initial = getattr(self._target, self._property_name, 0) 92 93 def OnMouseUp(self, *args): 94 self._dragging = False 95 self.OnSizeChanged() 96 97 def SetMinMax(self, minValue = None, maxValue = None): 98 if minValue is not None: 99 self.min = minValue 100 if maxValue is not None: 101 self.max = maxValue 102 103 def OnMouseMove(self, *args): 104 self._handle.OnMouseMove(*args) 105 if self._dragging: 106 delta = 0 107 if self._axis == Axis.HORIZONTAL: 108 delta = uicore.uilib.x - self._drag_start_x 109 elif self._axis == Axis.VERTICAL: 110 delta = uicore.uilib.y - self._drag_start_y 111 if self._target.align in (uiconst.TOBOTTOM, uiconst.TORIGHT): 112 delta = -delta 113 new_property_value = mathext.clamp(value=self._property_value_initial + delta, low=self.min, high=self.max) 114 setattr(self._target, self._property_name, new_property_value) 115 self.OnSizeChanging() 116 117 def OnMouseEnter(self, *args): 118 self._handle.OnMouseEnter(*args) 119 120 def OnMouseExit(self, *args): 121 self._handle.OnMouseExit(*args) 122 123 def OnSizeChangeStarting(self, *args): 124 pass 125 126 def OnSizeChanged(self, *args): 127 pass 128 129 def OnSizeChanging(self, *args): 130 pass