def setupMatrix (self): scale = pow (2.0, (self.zoomSlider.value () - 250) / 50.0) matrix = QMatrix () matrix.scale (scale, scale) self.graphicsView.setMatrix (matrix) self.setResetButtonEnabled ()
def setupTransformationMatrix(self,w, h): """ use a matrix to translate in the gl landmark """ m = QMatrix() m.translate(-w/2, h/2) m.scale(300./w, 300./h) print w, h, w/300., 1-((h/300)-1) #m.scale((self.width()*100)/300, -(self.height()*100)/300) #self.currentSize.x = w #self.currentSize.y = h return m
def setupTransformationMatrix(self, w, h): """ use a matrix to translate in the gl landmark """ m = QMatrix() m.translate(-w / 2, h / 2) m.scale(300. / w, 300. / h) print w, h, w / 300., 1 - ((h / 300) - 1) #m.scale((self.width()*100)/300, -(self.height()*100)/300) #self.currentSize.x = w #self.currentSize.y = h return m
def play(self): line = 0 scene_info = self.nonstop.script_pack[line].scene_info sprite_id = scene_info.sprite sprite_id.sprite_type = SPRITE_TYPE.stand sprite = get_sprite(sprite_id) self.lblSprite = QLabel(self.ui.lblPreview) self.lblSprite.setGeometry(0, 0, 480, 272) qt_pixmap = QtGui.QPixmap.fromImage(sprite) self.lblSprite.setPixmap(qt_pixmap) line = 18 text_img = self.lines[line] line_info = self.nonstop.lines[line] matrix = QMatrix() matrix.rotate(line_info.rot_angle) matrix.scale(line_info.zoom_start / 100.0, line_info.zoom_start / 100.0) text_img = text_img.transformed(matrix, Qt.Qt.SmoothTransformation) x_start = line_info.x_start - (text_img.width() / 2.0) y_start = line_info.y_start - (text_img.height() / 2.0) x_vel = line_info.velocity * math.cos( math.radians(90 - line_info.angle)) y_vel = -line_info.velocity * math.sin( math.radians(90 - line_info.angle)) time_visible = line_info.time_visible / 60.0 width_start = text_img.width() height_start = text_img.height() width_end = width_start * ( (line_info.zoom_change / 100.0)**time_visible) height_end = height_start * ( (line_info.zoom_change / 100.0)**time_visible) x_end = x_start + (x_vel * time_visible) y_end = y_start + (y_vel * time_visible) #x_end = line_info.x_start + (x_vel * time_visible) - (width_end / 2.0) #y_end = line_info.y_start + (y_vel * time_visible) - (height_end / 2.0) print x_start, y_start, width_start, height_start, line_info.zoom_start print x_end, y_end, width_end, height_end self.lblText = QLabel(self.ui.lblPreview) self.lblText.setGeometry(x_start, y_start, text_img.width(), text_img.height()) #self.lblText2 = QLabel(self.ui.lblPreview) #self.lblText2.setGeometry(x_end, y_end, text_img.width(), text_img.height()) qt_pixmap = QtGui.QPixmap.fromImage(text_img) self.lblText.setPixmap(qt_pixmap) #self.lblText2.setPixmap(qt_pixmap) self.anim = QtCore.QPropertyAnimation(self.lblText, "geometry") self.anim.setDuration(time_visible * 1000) self.anim.setStartValue( QRectF(x_start, y_start, width_start, height_start)) self.anim.setEndValue(QRectF(x_end, y_end, width_start, height_start)) self.anim.start()
def get_letter(clt, char): if not clt in CLT: clt = 0 font = CLT[clt]['font'] hscale = CLT[clt]['hscale'] vscale = CLT[clt]['vscale'] try: info = FONT_DATA[font][char] except: # This is the character the game replaces unknown characters with. info = FONT_DATA[font][u'\u2261'] expand_l = 0 expand_r = 0 expand_t = 0 expand_b = 0 if clt in CLT_EXPAND: expand_l = CLT_EXPAND[clt][0] expand_r = CLT_EXPAND[clt][1] expand_t = CLT_EXPAND[clt][2] expand_b = CLT_EXPAND[clt][3] box = QRect(info['x'] - expand_l, info['y'] - expand_t, info['w'] + expand_l + expand_r, info['h'] + expand_t + expand_b) #box = QRect(info['x'] - expand_l, info['y'] - expand_t, info['w'], info['h']) if clt in CLT_BORDER: expand_l += CLT_BORDER[clt]['size'] expand_r += CLT_BORDER[clt]['size'] expand_t += CLT_BORDER[clt]['size'] expand_b += CLT_BORDER[clt]['size'] xshift = -expand_l yshift = -expand_t if font == 1: yshift += 6 #elif font == 2: #yshift += 2 base_w = info['w'] + expand_l + expand_r base_h = info['h'] + expand_t + expand_b final_w = base_w final_h = base_h if hscale != 1.0: final_w = (final_w * hscale) if vscale != 1.0: old_h = final_h final_h = (final_h * vscale) yshift = yshift + old_h - final_h letter = FONTS[CLT[clt]['font']].copy(box) if hscale != 1.0 or vscale != 1.0: matrix = QMatrix() matrix.scale(hscale, vscale) letter = letter.transformed(matrix, Qt.Qt.SmoothTransformation) #letter = letter.scaled(int(final_w), int(final_h), Qt.Qt.IgnoreAspectRatio, Qt.Qt.SmoothTransformation) if clt in CLT_INSIDE: if 'color' in CLT_INSIDE[clt]: letter = replace_all_colors(letter, CLT_INSIDE[clt]['color']) elif 'gradient' in CLT_INSIDE[clt]: letter = add_v_gradient(letter, CLT_INSIDE[clt]['gradient']) if clt in CLT_BORDER: letter = add_border(letter, CLT_BORDER[clt]['color'], CLT_BORDER[clt]['size']) return letter, (xshift, yshift, final_w, final_h)