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

image.py (4318B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\image.py
      2 import carbonui.const as uiconst
      3 import uthread
      4 import copy
      5 from carbon.client.script.environment.AudioUtil import PlaySound
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.primitives.fill import Fill
      9 from carbonui.util.various_unsorted import MapIcon
     10 from carbonui.control.link import Link
     11 from carbonui.uicore import uicore
     12 from menu import MenuLabel
     13 
     14 class ImageCore(Container):
     15 
     16     def Load(self, attrs, *args):
     17         self.Flush()
     18         self.hint = attrs.alt or ''
     19         self.attrs = copy.copy(attrs)
     20         self.width = attrs.width
     21         self.height = attrs.height
     22         self.left = getattr(attrs, 'pictureLeft', 0)
     23         self.top = getattr(attrs, 'pictureTop', 0)
     24         if getattr(self.attrs, 'loadlater', 0):
     25             uthread.new(self.LoadImage)
     26         attrs.size = int(getattr(attrs, 'size', 128))
     27         self.LoadAttrs(self.attrs)
     28         if getattr(attrs, 'bgcolor', None):
     29             Fill(parent=self, color=attrs.bgcolor)
     30         if not self.IsClickable():
     31             self.cursor = uiconst.UICURSOR_DEFAULT
     32         else:
     33             self.cursor = uiconst.UICURSOR_SELECT
     34         self.state = uiconst.UI_NORMAL
     35         self.loaded = 1
     36 
     37     def LoadAttrs(self, attrs):
     38         src = attrs.src
     39         if attrs.texture:
     40             sprite = Sprite(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED)
     41             sprite.rectWidth = attrs.width
     42             sprite.rectHeight = attrs.height
     43             sprite.texture = attrs.texture
     44         elif src.startswith('icon:'):
     45             uthread.new(self.LoadIcon)
     46 
     47     def OnClick(self, *args):
     48         if self.IsClickable():
     49             PlaySound(uiconst.SOUND_BUTTON_CLICK)
     50             Link().ClickLink(self, self.attrs.a.href.replace('&', '&'))
     51 
     52     def GetMenu(self):
     53         m = []
     54         if getattr(self, 'attrs', None) and getattr(self.attrs, 'src', None) and self.attrs.src:
     55             src = self.attrs.src
     56             m += [(MenuLabel('UI/Common/ReloadImage'), self.Reload)]
     57             if self.IsClickable():
     58                 m += self.GetLinkMenu(self, self.attrs.a.href)
     59         return m
     60 
     61     def OnMouseMove(self, *args):
     62         if getattr(self, 'attrs', None) and getattr(self.attrs, 'areamap', None):
     63             url = self.GetLink()
     64             if url:
     65                 self.cursor = uiconst.UICURSOR_SELECT
     66             else:
     67                 self.cursor = uiconst.UICURSOR_DEFAULT
     68 
     69     def OnMouseEnter(self, *args):
     70         if self.IsClickable():
     71             PlaySound(uiconst.SOUND_BUTTON_HOVER)
     72 
     73     def IsClickable(self):
     74         return getattr(self.attrs, 'a', None)
     75 
     76     def Reload(self, *args):
     77         if getattr(self, 'attrs', None):
     78             self.Load(self.attrs)
     79 
     80     def LoadImage(self, *args):
     81         if not getattr(self, 'attrs', None):
     82             return
     83         browserImageSvc = sm.GetServiceIfRunning('browserImage')
     84         if not browserImageSvc:
     85             return
     86         texture, tWidth, tHeight = browserImageSvc.GetTextureFromURL(getattr(self.attrs, 'src', ''), getattr(self.attrs, 'currentURL', ''), fromWhere='Img::Load')
     87         if texture:
     88             sprite = Sprite(parent=self, align=uiconst.TOALL, pos=(0, 0, 0, 0))
     89             sprite.rectWidth = tWidth
     90             sprite.rectHeight = tHeight
     91             sprite.rectTop = 0
     92             sprite.rectLeft = 0
     93             sprite.texture = texture
     94             sprite.state = uiconst.UI_DISABLED
     95 
     96     def LoadIcon(self, *args):
     97         sprite = Sprite(parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, idx=0, pos=(0, 0, 0, 0))
     98         if not hasattr(self, 'attrs'):
     99             return
    100         icon = self.attrs.src[5:]
    101         if isinstance(icon, unicode):
    102             icon = icon.encode('ascii', 'xmlcharrefreplace')
    103         MapIcon(sprite, icon, ignoreSize=True)
    104 
    105     def GetLink(self):
    106         aL, aT, aW, aH = self.GetAbsolute()
    107         for each in self.attrs.areamap:
    108             if each['x0'] <= uicore.uilib.x - aL <= each['x1'] and each['y0'] <= uicore.uilib.y - aT <= each['y1']:
    109                 return each['url']
    110 
    111 
    112 class ImageCoreOverride(ImageCore):
    113 
    114     @classmethod
    115     def __reload_update__(cls, old_cls):
    116         return old_cls