コード例 #1
0
ファイル: textarea.py プロジェクト: yueyihua/libavg
    def __updateCursor(self, cursorNode, cursorContainer, textNode):
        if self.__cursorPosition == 0:
            lastCharPos = (0,0)
            lastCharExtents = (0,0)
        else:
            lastCharPos = textNode.getGlyphPos(self.__cursorPosition - 1)
            lastCharExtents = textNode.getGlyphSize(self.__cursorPosition - 1)

            if self.__data[self.__cursorPosition - 1] == '\n':
                lastCharPos = (0, lastCharPos[1] + lastCharExtents[1])
                lastCharExtents = (0, lastCharExtents[1])

        xPos = cursorNode.pos2.x
        cursorNode.pos2 = Point2D(xPos, textNode.realFontSize.y * \
                (1 - CURSOR_PADDING_PCT/100.0))

        if textNode.alignment != "left":
            if len(self.__data) > 0:
                lineWidth = textNode.getLineExtents(self.__selectTextLine(lastCharPos,
                        textNode))
            else:
                lineWidth = Point2D(0,0)
            if textNode.alignment == "center":
                lineWidth *= 0.5
            cursorContainer.x = textNode.alignmentOffset.x - lineWidth.x + \
                        lastCharPos[0] + lastCharExtents[0] + self.__border[0]
        else:
            cursorContainer.x = lastCharPos[0] + lastCharExtents[0] + self.__border[0]
        cursorContainer.y = (lastCharPos[1] +
                cursorNode.pos2.y * CURSOR_PADDING_PCT/200.0 + self.__border[1])
コード例 #2
0
ファイル: textarea.py プロジェクト: yueyihua/libavg
    def __updateCursorPosition(self, event):
        eventPos = self.__textNode.getRelPos(event.pos)
        if len(self.__data) > 0:
            lineWidth = self.__textNode.getLineExtents(self.__selectTextLine(eventPos,
                    self.__textNode))
        else:
            lineWidth = Point2D(0,0)
        if self.__textNode.alignment != "left":
            if self.__textNode.alignment == "center":
                eventPos = Point2D(eventPos.x + lineWidth.x / 2, eventPos.y)
            else:
                eventPos = Point2D(eventPos.x + lineWidth.x, eventPos.y)
        length = len(self.__data)
        if length > 0:
            index = self.__textNode.getCharIndexFromPos(eventPos) # click on letter
            if index is None: # click behind line
                realLines = self.__textNode.getNumLines() - 1
                for line in range(realLines + 1):
                    curLine = self.__textNode.getLineExtents(line)
                    minMaxHight = (curLine[1] * line,curLine[1] * (line + 1) )
                    if minMaxHight[0] <= eventPos[1] < minMaxHight[1]:
                        if curLine[0] != 0: # line with letters
                            correction = 1
                            if self.__textNode.alignment != "left":
                                if eventPos[0] < 0:
                                    targetLine = (1, curLine[1] * line)
                                    correction = 0
                                else:
                                    targetLine = (curLine[0] - 1, curLine[1] * line)
                            else:
                                targetLine = (curLine[0] - 1, curLine[1] * line)
                            index = (self.__textNode.getCharIndexFromPos(targetLine) 
                                    + correction)
                        else: # empty line
                            count = 0
                            for char in range(length-1):
                                if count < line:
                                    if self.__textNode.text[char] == "\n":
                                        count += 1
                                else:
                                    index = char
                                    break
                        break
            if index is None: # click under text
                curLine = self.__textNode.getLineExtents(realLines)
                curLine *= realLines
                index = self.__textNode.getCharIndexFromPos( (eventPos[0],curLine[1]) )
            if index is None:
                index = length
            self.__cursorPosition = index

            self.__update()
        self.__updateLoupe(event)
コード例 #3
0
ファイル: textarea.py プロジェクト: yueyihua/libavg
    def __updateLoupe(self, event):
        # setzt es mittig ueber das orginal
#        self.__zoomedImage.pos = - self.getRelPos(event.pos) + self.__loupe.size / 2.0
        # add zoomfactor position
#        self.__zoomedImage.pos = - self.getRelPos(event.pos) + self.__loupe.size / 2.0 -\
#                ( 0.0,(self.__textNode.fontsize * self.__loupeZoomFactor)) 
        # add scrolling | without zoom positioning

        self.__zoomedImage.pos = - self.getRelPos(event.pos) + self.__loupe.size / 2.0 - \
                self.getRelPos(event.pos)* self.__loupeZoomFactor + Point2D(0,5)
        self.__loupe.pos = self.getRelPos(event.pos) - self.__loupeOffset
コード例 #4
0
ファイル: textarea.py プロジェクト: yueyihua/libavg
    def setStyle(self, font='sans', fontsize=12, alignment='left', variant='Regular', 
            color='000000', multiline=True, cursorWidth=None, border=(0,0), 
            blurOpacity=DEFAULT_BLUR_OPACITY, flashingCursor=False, cursorColor='000000',
            lineSpacing=0, letterSpacing=0):
        """
        Set TextArea's graphical appearance
        @param font: font face
        @param fontsize: font size in pixels
        @param alignment: one among 'left', 'right', 'center'
        @param variant: font variant (eg: 'bold')
        @param color: RGB hex for text color
        @param multiline: boolean, whether TextArea has to wrap (undefinitely)
            or stop at full width
        @param cursorWidth: int, width of the cursor in pixels
        @param border: amount of offsetting pixels that words node will have from image
            extents
        @param blurOpacity: opacity that textarea gets when goes to blur state
        @param flashingCursor: whether the cursor should flash or not
        @param cursorColor: RGB hex for cursor color
        @param lineSpacing: linespacing property of words node
        @param letterSpacing: letterspacing property of words node
        """
        self.__textNode.fontstyle = avg.FontStyle(font=font, fontsize=fontsize, 
                alignment=alignment, variant=variant, linespacing=lineSpacing,
                letterspacing=letterSpacing)
        self.__textNode.color = color
        self.__isMultiline = multiline
        self.__border = border
        self.__maxLength = -1
        self.__blurOpacity = blurOpacity

        if multiline:
            self.__textNode.width = int(self.width) - self.__border[0] * 2
            self.__textNode.wrapmode = 'wordchar'
        else:
            self.__textNode.width = 0

        self.__textNode.x = self.__border[0]
        self.__textNode.y = self.__border[1]

        tempNode = avg.WordsNode(text=u'W', font=font, fontsize=int(fontsize),
                variant=variant)
        self.__textNode.realFontSize = tempNode.getGlyphSize(0)
        del tempNode
        self.__textNode.alignmentOffset = Point2D(0,0)

        if alignment != "left":
            offset = Point2D(self.size.x / 2,0)
            if alignment == "right":
                offset = Point2D(self.size.x,0)
            self.__textNode.pos += offset
            self.__textNode.alignmentOffset = offset
            self.__cursorContainer.pos = offset

        self.__cursorNode.color = cursorColor
        if cursorWidth is not None:
            self.__cursorNode.strokewidth = cursorWidth
        else:
            w = float(fontsize) * CURSOR_WIDTH_PCT / 100.0
            if w < 1:
                w = 1
            self.__cursorNode.strokewidth = w
        x  = self.__cursorNode.strokewidth / 2.0
        self.__cursorNode.pos1 = Point2D(x, self.__cursorNode.pos1.y)
        self.__cursorNode.pos2 = Point2D(x, self.__cursorNode.pos2.y)

        self.__flashingCursor = flashingCursor
        if not flashingCursor:
            self.__cursorContainer.opacity = 1

        if self.__loupe:
            zoomfactor = (1.0 + self.__loupeZoomFactor)
            self.__loupeTextNode.fontstyle = self.__textNode.fontstyle
            self.__loupeTextNode.fontsize = int(fontsize) * zoomfactor
            self.__loupeTextNode.color = color
            if multiline:
                self.__loupeTextNode.width = self.__textNode.width * zoomfactor
                self.__loupeTextNode.wrapmode = 'wordchar'
            else:
                self.__loupeTextNode.width = 0

            self.__loupeTextNode.x = self.__border[0] * 2
            self.__loupeTextNode.y = self.__border[1] * 2
            
            self.__loupeTextNode.realFontSize = self.__textNode.realFontSize * zoomfactor

            if alignment != "left":
                self.__loupeTextNode.pos = self.__textNode.pos * zoomfactor 
                self.__loupeTextNode.alignmentOffset = self.__textNode.alignmentOffset * \
                        zoomfactor 
                self.__loupeCursorContainer.pos = self.__cursorContainer.pos * zoomfactor

            self.__loupeCursorNode.color = cursorColor
            if cursorWidth is not None:
                self.__loupeCursorNode.strokewidth = cursorWidth * zoomfactor
            else:
                w = float(self.__loupeTextNode.fontsize) * CURSOR_WIDTH_PCT / 100.0
                if w < 1:
                    w = 1
                self.__loupeCursorNode.strokewidth = w * zoomfactor
            x  = self.__loupeCursorNode.strokewidth / 2.0
            self.__loupeCursorNode.pos1 = Point2D(x, self.__loupeCursorNode.pos1.y)
            self.__loupeCursorNode.pos2 = Point2D(x, self.__loupeCursorNode.pos2.y)

            if not flashingCursor:
                self.__loupeCursorContainer.opacity = 1
        self.__updateCursors()