uicore.py (10406B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\uicore.py 2 import weakref 3 import blue 4 import carbonui 5 from carbonui import uiconst 6 import carbonui.uianimations 7 import carbonui.uilib 8 import carbonui.util.effect 9 import localization 10 from carbonui.util.color import Color 11 from eveprefs import boot 12 import evespacemouse 13 import log 14 import trinity 15 16 class UIDeviceResource(): 17 18 def __init__(self): 19 dev = trinity.device 20 dev.RegisterResource(self) 21 22 def OnInvalidate(self, level): 23 pass 24 25 def OnCreate(self, dev): 26 if getattr(uicore, 'uilib', None) is None: 27 return 28 uicore.UpdateCursor(uicore.uilib.mouseOver, 1) 29 30 31 def _ExecuteSpaceMouseAction(action): 32 cmd = uicore.cmd.GetCommandToExecute(action) 33 if cmd: 34 cmd() 35 raise evespacemouse.StopPropagation() 36 37 38 class UICore(): 39 fontHandler = None 40 audioHandler = None 41 imeHandler = None 42 commandHandler = None 43 tooltipHandler = None 44 dpiScaling = 1.0 45 46 def __init__(self, appName = None): 47 import __builtin__ 48 if 'uicore' in __builtin__.__dict__.keys(): 49 pass 50 else: 51 if appName is None: 52 try: 53 appName = boot.appname 54 except: 55 appName = 'CarbonUI' 56 57 self.newRendererEnabled = False 58 self._lastCursor = None 59 self._cursorSprite = None 60 self._hint = None 61 self.isRunning = False 62 self.desktop = None 63 self.dragData = None 64 self.uilib = None 65 self.dragObject = None 66 self.triappargs = {'title': appName, 67 'left': 0, 68 'top': 0, 69 'colordepth': 0, 70 'exclusiveInput': 0, 71 'refreshrate': 0} 72 self.layer = None 73 self.textObjects = weakref.WeakSet() 74 self.deviceResource = UIDeviceResource() 75 76 def Startup(self, layerlist = None, clientStartup = True): 77 if clientStartup: 78 sm.GetService('settings').LoadSettings() 79 deviceSvc = sm.StartServiceAndWaitForRunningState('device') 80 deviceSvc.CreateDevice() 81 self.device = deviceSvc 82 evespacemouse.Enable() 83 evespacemouse.StartListening(None, None, _ExecuteSpaceMouseAction, 1000) 84 self.uilib = self.event = carbonui.uilib.Uilib() 85 self.desktop = self.uilib.desktop 86 if self.fontHandler is None: 87 self.LoadBaseFontHandler() 88 if self.audioHandler is None: 89 self.LoadBaseAudioHandler() 90 from carbonui.services.registry import RegistryHandler 91 self.registry = RegistryHandler() 92 if clientStartup: 93 from carbonui.services.ime import construct_ime_handler 94 self.imeHandler = construct_ime_handler() 95 self.LoadLayers(layerlist) 96 self.effect = carbonui.util.effect.UIEffects() 97 self.animations = carbonui.uianimations.animations 98 trinity.device.RegisterResource(self) 99 from carbonui.window.settings import window_margin_mode 100 window_margin_mode.initialize(get_resolution=lambda : (self.desktop.width, self.desktop.height), service_manager=sm) 101 self.isRunning = True 102 103 def LoadBaseFontHandler(self): 104 from carbonui.services.font import FontHandler 105 self.SetFontHandler(FontHandler()) 106 107 def SetFontHandler(self, fontHandler): 108 self.fontHandler = fontHandler 109 self.font = fontHandler 110 111 def LoadBaseAudioHandler(self): 112 from carbonui.handlers.audioHandler import AudioHandler 113 self.audioHandler = AudioHandler() 114 115 def SetAudioHandler(self, audioHandler): 116 self.audioHandler = audioHandler 117 118 def SetCommandHandler(self, commandHandler): 119 self.commandHandler = commandHandler 120 self.cmd = commandHandler 121 122 def SetTooltipHandler(self, tooltipHandler): 123 self.tooltipHandler = tooltipHandler 124 125 def IsReady(self): 126 return getattr(self, 'isRunning', False) 127 128 def OnInvalidate(self, *args): 129 self.layer.hint.Flush() 130 self._hint = None 131 132 def OnCreate(self, *args): 133 self.layer.hint.Flush() 134 self._hint = None 135 136 def LoadLayers(self, layerlist): 137 self.layer = carbonui.control.layer.LayerManager() 138 self.layerData = {} 139 self.layerList = layerlist 140 layerlist = layerlist or self.GetDefaultLayers() 141 for layerName, className, subLayers in layerlist: 142 self.desktop.AddLayer(layerName, className, subLayers) 143 144 def GetDefaultLayers(self): 145 layers = [('l_hint', None, None), 146 ('l_menu', None, None), 147 ('l_modal', None, None), 148 ('l_abovemain', None, None), 149 ('l_main', None, None), 150 ('l_videoOverlay', None, None), 151 ('l_loading', None, None), 152 ('l_dragging', None, None)] 153 return layers 154 155 def CloseSidePanelsByName(self, name): 156 try: 157 if not self.layer or not self.layer.sidePanels.children: 158 return 159 except AttributeError: 160 return 161 162 for cont in self.layer.sidePanels.children: 163 if cont.name == name: 164 cont.Close() 165 166 def CloseAboveMainPanelsByClass(self, panelClass): 167 try: 168 if not self.layer or not self.layer.abovemain.children: 169 return 170 except AttributeError: 171 return 172 173 for cont in self.layer.abovemain.children: 174 if isinstance(cont, panelClass): 175 cont.Close() 176 177 def CheckCursor(self): 178 self.UpdateCursor(uicore.uilib.mouseOver) 179 180 def CheckHint(self): 181 pass 182 183 def UpdateHint(self, item, force = 0): 184 pass 185 186 def IsHintVisible(self): 187 return self._hint and self._hint.display 188 189 def HideHint(self): 190 if self.IsHintVisible(): 191 self._hint.LoadHint('') 192 193 def UpdateCursor(self, item, force = 0): 194 if not item: 195 cursor = uiconst.UICURSOR_DEFAULT 196 else: 197 cursor = self._GetCursorForItem(item) 198 if force or self._lastCursor != cursor: 199 self.uilib.SetCursor(cursor) 200 self._lastCursor = cursor 201 202 def _GetCursorForItem(self, item): 203 specifiedCursor = self._GetSpecifiedCursorForItem(item) 204 if specifiedCursor is not None: 205 return specifiedCursor 206 if item.HasEventHandler('OnChar'): 207 return uiconst.UICURSOR_IBEAM 208 hasGetMenu = item.HasEventHandler('GetMenu') 209 clickFunc = item.HasEventHandler('OnClick') 210 if clickFunc: 211 if hasGetMenu: 212 return uiconst.UICURSOR_POINTER_MENU 213 else: 214 return uiconst.UICURSOR_SELECT 215 elif hasGetMenu: 216 return uiconst.UICURSOR_HASMENU 217 return uiconst.UICURSOR_DEFAULT 218 219 def _GetSpecifiedCursorForItem(self, item): 220 if hasattr(item, 'GetCursor'): 221 specifiedCursor = item.GetCursor() 222 else: 223 specifiedCursor = getattr(item, 'cursor', None) 224 return specifiedCursor 225 226 def GetLayer(self, name): 227 return self.layer.GetLayer(name) 228 229 def WaitForResourceLoad(self): 230 fence = trinity.device.GetCurrentResourceLoadFence() 231 timeWaited = 0 232 while trinity.device.GetLastResourceLoadFenceReached() < fence: 233 waitMs = 100 234 blue.pyos.synchro.SleepWallclock(waitMs) 235 timeWaited += waitMs 236 if timeWaited % 5000 == 0: 237 log.general.Log('WaitForResourceLoad has waited for %d seconds! (%d vs. %d)' % (timeWaited / 1000, trinity.device.GetLastResourceLoadFenceReached(), fence), log.LGERR) 238 239 def ScaleDpi(self, value): 240 return int(round(value * self.dpiScaling)) 241 242 def ScaleDpiF(self, value): 243 return value * self.dpiScaling 244 245 def ReverseScaleDpi(self, value): 246 if self.dpiScaling != 1.0: 247 try: 248 return int(round(value / self.dpiScaling)) 249 except (ValueError, OverflowError): 250 return 0 251 252 else: 253 try: 254 return int(value) 255 except ValueError: 256 return 0 257 258 def IsDragging(self): 259 return not self.dragObject == None 260 261 def DrawDebugLine(self, pos1, pos2, width = 2, color1 = None, color2 = None): 262 color1 = color1 or Color.YELLOW 263 color2 = color2 or Color.RED 264 self.ConstructDebugLineset() 265 self.debugLineSet.AddStraightLine(pos1, color1, pos2, color2, width) 266 self.debugLineSet.SubmitChanges() 267 268 def DrawDebugAxis(self, pos = None, lineWidth = 5, len = 1000.0): 269 import geo2 270 self.ConstructDebugLineset() 271 if not pos: 272 pos = (0, 0, 0) 273 self.debugLineSet.AddStraightLine(pos, Color.YELLOW, geo2.Add(pos, (len, 0, 0)), Color.YELLOW, lineWidth) 274 self.debugLineSet.AddStraightLine(pos, Color.RED, geo2.Add(pos, (0, len, 0)), Color.RED, lineWidth) 275 self.debugLineSet.AddStraightLine(pos, Color.GREEN, geo2.Add(pos, (0, 0, len)), Color.GREEN, lineWidth) 276 self.debugLineSet.SubmitChanges() 277 278 def ClearDebugLines(self): 279 self.debugLineSet.ClearLines() 280 self.debugLineSet.SubmitChanges() 281 282 def ConstructDebugLineset(self): 283 if hasattr(self, 'debugLineSet'): 284 scene = sm.GetService('sceneManager').GetActiveScene() 285 if self.debugLineSet in scene.objects: 286 return 287 self.debugLineSet = trinity.EveCurveLineSet() 288 self.debugLineSet.scaling = (1.0, 1.0, 1.0) 289 tex2D1 = trinity.TriTextureParameter() 290 tex2D1.name = 'TexMap' 291 tex2D1.resourcePath = 'res:/texture/global/lineSolid.dds' 292 self.debugLineSet.lineEffect.resources.append(tex2D1) 293 tex2D2 = trinity.TriTextureParameter() 294 tex2D2.name = 'OverlayTexMap' 295 tex2D2.resourcePath = 'res:/UI/Texture/Planet/link.dds' 296 self.debugLineSet.lineEffect.resources.append(tex2D2) 297 scene = sm.GetService('sceneManager').GetActiveScene() 298 scene.objects.append(self.debugLineSet) 299 return self.debugLineSet 300 301 302 def GetWindowName(characterid = None): 303 if characterid is not None: 304 return localization.GetByLabel('UI/WindowNameWithCharacterName', player=characterid) 305 return localization.GetByLabel('UI/WindowName') 306 307 308 uicore = UICore()