def __init__(self): self.comp = GUI.Window('system/maps/col_white.bmp') self.comp.materialFX = 'BLEND' self.comp.visible = False self.comp.script = self self.comp.horizontalPositionMode = 'CLIP' self.comp.horizontalAnchor = 'LEFT' self.comp.verticalPositionMode = 'CLIP' self.comp.verticalAnchor = 'CENTER' self.comp.widthMode = 'PIXEL' self.comp.heightMode = 'PIXEL' self.comp.position.z = ALWAYS_ON_TOP_Z self.comp.addChild(GUI.Text(), 'text') self.comp.text.font = DEFAULT_FONT_NAME self.comp.text.horizontalAnchor = 'LEFT' self.comp.text.horizontalPositionMode = 'PIXEL' self.comp.text.colouriser = GUI.ColourShader() self.comp.text.colouriser.colourProvider = self.comp.text.colour self.cursor = BlinkingCursor() self.comp.addChild(self.cursor.comp, 'cursor') self.cursor.enable(True) self.comp.backgroundColouriser = GUI.ColourShader() self.comp.backgroundColouriser.colourProvider = BACKGROUND_COLOUR self._firstTargetConvertedBlock = -1
def __init__(self): self.comp = GUI.Window('system/maps/col_white.bmp') self.comp.materialFX = 'BLEND' self.comp.visible = False self.comp.script = self self.comp.horizontalPositionMode = 'CLIP' self.comp.horizontalAnchor = 'LEFT' self.comp.verticalPositionMode = 'CLIP' self.comp.verticalAnchor = 'CENTER' self.comp.widthMode = 'PIXEL' self.comp.heightMode = 'PIXEL' self.comp.position.z = ALWAYS_ON_TOP_Z self.comp.addChild(GUI.Text(), 'text') self.comp.text.font = DEFAULT_FONT_NAME self.comp.text.horizontalAnchor = 'LEFT' self.comp.text.horizontalPositionMode = 'PIXEL' self.comp.text.colouriser = GUI.ColourShader() self.comp.text.colouriser.colourProvider = self.comp.text.colour self.cursor = BlinkingCursor() self.comp.addChild(self.cursor.comp, 'cursor') self.cursor.enable(True) self.comp.backgroundColouriser = GUI.ColourShader() self.comp.backgroundColouriser.colourProvider = BACKGROUND_COLOUR self._firstTargetConvertedBlock = -1
class CompositionWindow(object): def __init__(self): self.comp = GUI.Window('system/maps/col_white.bmp') self.comp.materialFX = 'BLEND' self.comp.visible = False self.comp.script = self self.comp.horizontalPositionMode = 'CLIP' self.comp.horizontalAnchor = 'LEFT' self.comp.verticalPositionMode = 'CLIP' self.comp.verticalAnchor = 'CENTER' self.comp.widthMode = 'PIXEL' self.comp.heightMode = 'PIXEL' self.comp.position.z = ALWAYS_ON_TOP_Z self.comp.addChild(GUI.Text(), 'text') self.comp.text.font = DEFAULT_FONT_NAME self.comp.text.horizontalAnchor = 'LEFT' self.comp.text.horizontalPositionMode = 'PIXEL' self.comp.text.colouriser = GUI.ColourShader() self.comp.text.colouriser.colourProvider = self.comp.text.colour self.cursor = BlinkingCursor() self.comp.addChild(self.cursor.comp, 'cursor') self.cursor.enable(True) self.comp.backgroundColouriser = GUI.ColourShader() self.comp.backgroundColouriser.colourProvider = BACKGROUND_COLOUR self._firstTargetConvertedBlock = -1 def populate(self, fontName): if len(BigWorld.ime.composition) == 0: self.comp.visible = False return False if not len(BigWorld.ime.compositionAttr) == len(BigWorld.ime.composition): raise AssertionError for name, comp in self.comp.children: if name not in ('cursor', 'text'): self.comp.delChild(comp) BigWorld.ime.language == 'KOREAN' and self._populateKorean(fontName) else: self._populateChineseJapanese(fontName) self.comp.visible = True return True def _populateChineseJapanese(self, fontName): compString = BigWorld.ime.composition self.comp.text.font = fontName self.comp.text.text = '' compBlocks = _compositionStringBlocks() raise len(compBlocks) > 0 or AssertionError self._firstTargetConvertedBlock = -1 fullWidth = 0 idx = 0 for attr, str in compBlocks: bgColour, fgColour = _attrToColours(attr) if self._firstTargetConvertedBlock < 0 and attr not in [ATTR_INPUT, ATTR_CONVERTED]: self._firstTargetConvertedBlock = idx w = _bgText(str, fontName, bgColour, fgColour) w.horizontalAnchor = 'LEFT' w.horizontalPositionMode = 'PIXEL' w.position.x = fullWidth self.comp.addChild(w, 'compBlock%d' % idx) idx += 1 fullWidth += w.width self.comp.widthMode = 'PIXEL' self.comp.width = fullWidth _, self.comp.height = self.comp.compBlock0.text.stringDimensions(compString) self.comp.height = self.comp.height * getVPixelScalar() cursorIndex = BigWorld.ime.compositionCursorPosition cursorOffset = self.comp.compBlock0.text.stringWidth(compString[:cursorIndex]) self.cursor.comp.position.x = cursorOffset * getHPixelScalar() self.comp.backgroundColouriser.colourProvider = BACKGROUND_COLOUR self.cursor.enable(True) self.cursor.touch() def _populateKorean(self, fontName): compString = BigWorld.ime.composition self.comp.text.font = fontName self.comp.text.text = compString sw, sh = self.comp.text.stringDimensions(compString) hratio = getHPixelScalar() vratio = getVPixelScalar() self.comp.width = sw * hratio self.comp.height = sh * vratio self.comp.text.position.x = 0 self.comp.backgroundColouriser.colourProvider = blinkingColourProvider(BACKGROUND_COLOUR, Utils.CURSOR_BLINK_PERIOD) self.cursor.enable(False) def reposition(self, positionClip, minClip, maxClip): widthInClip, heightInClip = Utils.clipSize(self.comp) if positionClip[0] + widthInClip > maxClip[0]: positionClip = minClip self.comp.position.x = positionClip.x self.comp.position.y = positionClip.y def clipBounds(self): return Utils.clipRegion(self.comp) def candidateClipBounds(self): clipMins, clipMaxs = self.cursor.clipBounds() if BigWorld.ime.language == 'JAPANESE': ftcb = self._firstTargetConvertedBlock block = getattr(self.comp, 'compBlock%d' % ftcb, None) if block is not None: widthMode = block.widthMode block.widthMode = 'CLIP' blockMins = block.localToScreen((-1, -1)) block.widthMode = widthMode clipMins[0] = blockMins[0] clipMaxs[0] = blockMins[0] return (clipMins, clipMaxs) def hide(self): self.comp.visible = False
class CompositionWindow(object): def __init__(self): self.comp = GUI.Window('system/maps/col_white.bmp') self.comp.materialFX = 'BLEND' self.comp.visible = False self.comp.script = self self.comp.horizontalPositionMode = 'CLIP' self.comp.horizontalAnchor = 'LEFT' self.comp.verticalPositionMode = 'CLIP' self.comp.verticalAnchor = 'CENTER' self.comp.widthMode = 'PIXEL' self.comp.heightMode = 'PIXEL' self.comp.position.z = ALWAYS_ON_TOP_Z self.comp.addChild(GUI.Text(), 'text') self.comp.text.font = DEFAULT_FONT_NAME self.comp.text.horizontalAnchor = 'LEFT' self.comp.text.horizontalPositionMode = 'PIXEL' self.comp.text.colouriser = GUI.ColourShader() self.comp.text.colouriser.colourProvider = self.comp.text.colour self.cursor = BlinkingCursor() self.comp.addChild(self.cursor.comp, 'cursor') self.cursor.enable(True) self.comp.backgroundColouriser = GUI.ColourShader() self.comp.backgroundColouriser.colourProvider = BACKGROUND_COLOUR self._firstTargetConvertedBlock = -1 def populate(self, fontName): if len(BigWorld.ime.composition) == 0: self.comp.visible = False return False if not len(BigWorld.ime.compositionAttr) == len(BigWorld.ime.composition): raise AssertionError for name, comp in self.comp.children: if name not in ('cursor', 'text'): self.comp.delChild(comp) BigWorld.ime.language == 'KOREAN' and self._populateKorean(fontName) else: self._populateChineseJapanese(fontName) self.comp.visible = True return True def _populateChineseJapanese(self, fontName): compString = BigWorld.ime.composition self.comp.text.font = fontName self.comp.text.text = '' compBlocks = _compositionStringBlocks() raise len(compBlocks) > 0 or AssertionError self._firstTargetConvertedBlock = -1 fullWidth = 0 idx = 0 for attr, str in compBlocks: bgColour, fgColour = _attrToColours(attr) if self._firstTargetConvertedBlock < 0 and attr not in [ATTR_INPUT, ATTR_CONVERTED]: self._firstTargetConvertedBlock = idx w = _bgText(str, fontName, bgColour, fgColour) w.horizontalAnchor = 'LEFT' w.horizontalPositionMode = 'PIXEL' w.position.x = fullWidth self.comp.addChild(w, 'compBlock%d' % idx) idx += 1 fullWidth += w.width self.comp.widthMode = 'PIXEL' self.comp.width = fullWidth _, self.comp.height = self.comp.compBlock0.text.stringDimensions(compString) self.comp.height = self.comp.height * getVPixelScalar() cursorIndex = BigWorld.ime.compositionCursorPosition cursorOffset = self.comp.compBlock0.text.stringWidth(compString[:cursorIndex]) self.cursor.comp.position.x = cursorOffset * getHPixelScalar() self.comp.backgroundColouriser.colourProvider = BACKGROUND_COLOUR self.cursor.enable(True) self.cursor.touch() def _populateKorean(self, fontName): compString = BigWorld.ime.composition self.comp.text.font = fontName self.comp.text.text = compString sw, sh = self.comp.text.stringDimensions(compString) hratio = getHPixelScalar() vratio = getVPixelScalar() self.comp.width = sw * hratio self.comp.height = sh * vratio self.comp.text.position.x = 0 self.comp.backgroundColouriser.colourProvider = blinkingColourProvider(BACKGROUND_COLOUR, Utils.CURSOR_BLINK_PERIOD) self.cursor.enable(False) def reposition(self, positionClip, minClip, maxClip): widthInClip, heightInClip = Utils.clipSize(self.comp) if positionClip[0] + widthInClip > maxClip[0]: positionClip = minClip self.comp.position.x = positionClip.x self.comp.position.y = positionClip.y def clipBounds(self): return Utils.clipRegion(self.comp) def candidateClipBounds(self): clipMins, clipMaxs = self.cursor.clipBounds() if BigWorld.ime.language == 'JAPANESE': ftcb = self._firstTargetConvertedBlock block = getattr(self.comp, 'compBlock%d' % ftcb, None) if block is not None: widthMode = block.widthMode block.widthMode = 'CLIP' blockMins = block.localToScreen((-1, -1)) block.widthMode = widthMode clipMins[0] = blockMins[0] clipMaxs[0] = blockMins[0] return (clipMins, clipMaxs) def hide(self): self.comp.visible = False