def drawImage(self, image, scale = (1.0, -1.0), coord = (0, 0), rot = 0, \ color = (1,1,1,1), rect = (0,1,0,1), stretched = 0, fit = CENTER, \ alignment = CENTER, valignment = MIDDLE): """ Draws the image/surface to screen @depreciated please use the specific methods of the image or Im.drawImage @param image: The openGL surface @param scale: Scale factor (between 0.0 and 1.0, second value must be negative due to texture flipping) @param coord: Where the image will be translated to on the screen @param rot: How many degrees it will be rotated @param color: The color of the image (values are between 0.0 and 1.0) (can have 3 values or 4, if 3 are given the alpha is automatically set to 1.0) @param rect: The surface rectangle, this is used for cropping the texture Any other values will have the image maintain its size passed by scale @param alignment: Adjusts the texture so the coordinate for x-axis placement can either be on the left side (0), center point (1), or right(2) side of the image @param valignment: Adjusts the texture so the coordinate for y-axis placement can either be on the bottom side (0), center point (1), or top(2) side of the image """ return ImgDrawing.drawImage(image, scale, coord, rot, color, rect, stretched, fit, alignment, valignment)
def createMask(self, drawing): #these determine the size of the PIL pie-slice self.centerX = self.drawing.width1() / 2 self.centerY = self.drawing.height1() / 2 self.inRadius = 0 self.outRadius = self.drawing.width1() / 2 #generates all the images needed for the circle self.drawnOverlays = {} baseFillImageSize = self.drawing.pixelSize for degrees in range(0, 361, 5): image = Image.open(self.drawing.path) mask = Image.new('RGBA', baseFillImageSize) overlay = Image.new('RGBA', baseFillImageSize) draw = ImageDraw.Draw(mask) draw.pieslice( (self.centerX - self.outRadius, self.centerY - self.outRadius, self.centerX + self.outRadius, self.centerY + self.outRadius), -90, degrees - 90, outline=(255, 255, 255, 255), fill=(255, 255, 255, 255)) draw.ellipse( (self.centerX - self.inRadius, self.centerY - self.inRadius, self.centerX + self.inRadius, self.centerY + self.inRadius), outline=(0, 0, 0, 0), fill=(0, 0, 0, 0)) r, g, b, a = mask.split() overlay.paste(image, mask=a) dispOverlay = ImgDrawing(self.engine.data.svg, overlay) self.drawnOverlays[degrees] = dispOverlay
def getImgDrawing(self, fileName, openImage=True, dirLoad=False): imgDrawing = None for dataPath in self.resource.dataPaths: fileName1 = os.path.join(dataPath, fileName) if self.logLoadings == 1: if openImage: Log.notice("Trying to load image: %s" % fileName1) else: Log.notice("Checking image: %s" % fileName1) #check if fileName1 exists (has extension) if os.path.exists(fileName1): if openImage == True: try: imgDrawing = ImgDrawing(self.svg, fileName1) return imgDrawing except IOError: Log.warn("Unable to load image file: %s" % fileName1) except OverflowError: Log.warn("Unable to read image file: %s" % fileName1) else: return True else: #find extension fileName1 = os.path.splitext(fileName1)[0] files = glob.glob('%s.*' % fileName1) if openImage == True: for i in range(len(files)): try: imgDrawing = ImgDrawing(self.svg, files[i]) return imgDrawing except IOError: Log.warn("Unable to load image file: %s" % files[i]) elif len(files) > 0: return True #image not found log = self.logImageNotFound - (dirLoad and 1 or 0) if log > 0: Log.debug("Image not found: %s" % fileName) return False
def loadCircle(self): #stump: continuous star fillup self.drawnOverlays = {} baseStarGreyImageSize = Image.open(self.drawing.texture.name).size for degrees in range(0, 360, 5): overlay = Image.new('RGBA', baseStarGreyImageSize) draw = ImageDraw.Draw(overlay) draw.pieslice((self.starFillupCenterX-self.starFillupOutRadius, self.starFillupCenterY-self.starFillupOutRadius, self.starFillupCenterX+self.starFillupOutRadius, self.starFillupCenterY+self.starFillupOutRadius), -90, degrees-90, outline=self.starFillupColor, fill=self.starFillupColor) draw.ellipse((self.starFillupCenterX-self.starFillupInRadius, self.starFillupCenterY-self.starFillupInRadius, self.starFillupCenterX+self.starFillupInRadius, self.starFillupCenterY+self.starFillupInRadius), outline=(0, 0, 0, 0), fill=(0, 0, 0, 0)) dispOverlay = ImgDrawing(self.engine.data.svg, overlay) self.drawnOverlays[degrees] = dispOverlay
def loadImgDrawing(self, target, name, fileName, textureSize = None): """ Load an SVG drawing synchronously. @param target: An object that will own the drawing @param name: The name of the attribute the drawing will be assigned to @param fileName: The name of the file in the data directory @param textureSize Either None or (x, y), in which case the file will be rendered to an x by y texture @return: L{ImgDrawing} instance """ fileName = self.resource.fileName(fileName) drawing = self.resource.load(target, name, lambda: ImgDrawing(self.svg, fileName), synch = True) if textureSize: drawing.convertToTexture(textureSize[0], textureSize[1]) return drawing
def drawImage(self, image, scale = (1.0, -1.0), coord = (0, 0), rot = 0, \ color = (1,1,1,1), rect = (0,1,0,1), stretched = 0, fit = 0, \ alignment = CENTER, valignment = 1): """ Draws the image/surface to screen @depreciated please use the specific methods of the image or Im.drawImage @param image: The openGL surface @param scale: Scale factor (between 0.0 and 1.0, second value must be negative due to texture flipping) @param coord: Where the image will be translated to on the screen @param rot: How many degrees it will be rotated @param color: The color of the image (values are between 0.0 and 1.0) (can have 3 values or 4, if 3 are given the alpha is automatically set to 1.0) @param rect: The surface rectangle, this is used for cropping the texture Any other values will have the image maintain its size passed by scale @param alignment: Adjusts the texture so the coordinate for x-axis placement can either be on the left side (0), center point (1), or right(2) side of the image @param valignment: Adjusts the texture so the coordinate for y-axis placement can either be on the bottom side (0), center point (1), or top(2) side of the image """ return ImgDrawing.drawImage(image, scale, coord, rot, color, rect, stretched, fit, alignment, valignment)
def __init__(self, engine, playerObj, editorMode = False, player = 0): self.engine = engine self.mic = Microphone(self.engine, playerObj.controller) #Get theme themename = self.engine.data.themeLabel #now theme determination logic is only in data.py: self.theme = self.engine.data.theme self.showData = self.engine.config.get("debug", "show_raw_vocal_data") #unused variables for compatibility with other instrument classes self.isDrum = False self.isBassGuitar = False self.isVocal = True self.neck = None self.canGuitarSolo = False self.guitarSolo = False self.useMidiSoloMarkers = False self.earlyHitWindowSizeFactor = 0 self.starNotesSet = True self.spEnabled = False self.bigRockEndingMarkerSeen = False self.freestyleStart = 0 self.freestyleFirstHit = 0 self.freestyleLength = 0 self.freestyleBonusFret = 0 self.freestyleLastFretHitTime = [0 for i in range(5)] self.twoChord = False self.leftyMode = False self.drumFlip = False self.keys = [] self.actions = [] self.neckSpeed = 0.0 self.hitw = 1.4 self.lateMargin = 100.0 self.earlyMargin = 100.0 self.oldNote = 2.0 self.pitchFudge = 0 self.barFudge = 600 self.stayEnd = 0 self.awardEnd = True self.formants = [None] * 3 self.currentNote = None self.currentNoteItem = None self.currentNoteTime = 0 self.currentLyric = None self.requiredNote = None self.lastPhrase = None self.phrase = None self.tapping = False self.activePhrase = None self.nextPhrase = None self.currentPhraseTime = 0 self.currentPhraseLength = 0 self.phraseMin = 0 self.phraseMax = 0 self.phraseTimes = [] self.doneLastPhrase = False #scoring variables self.allowedDeviation = 1.4 self.scoreThresholds = [.95, .80, .60, .40, .20, 0] self.scoredPhrases = [0 for i in self.scoreThresholds] self.scoreMultiplier = 1 self.totalPhrases = 0 self.starPhrases = [] self.phraseInTune = 0 self.phraseNoteTime = 0 self.phraseTaps = 0 self.phraseTapsHit = 0 self.lastPos = 0 self.showText = 0 self.textTrans = 0 self.scoreBox = (0,1) self.scorePhrases = [_("Amazing!"), _("Great!"), _("Decent"), _("Average"), _("Meh"), _("Bad"), _("Terrible...")] self.textScore = -1 self.lastScore = None self.coOpRB = False self.phraseIndex = 0 self.lyricMode = self.engine.config.get("game", "midi_lyric_mode") self.nstype = self.engine.config.get("game", "vocal_scroll") self.speed = self.engine.config.get("game", "vocal_speed")*0.01 self.actualBpm = 0 self.currentBpm = 120.0 self.lastBpmChange = -1.0 self.baseBeat = 0.0 self.currentPeriod = 60000.0 self.oldTime = 0 self.oldLength = 0 self.useOld = False self.arrowVis = 0 self.minPitch = 0 self.maxPitch = 0 self.pitchRange = 0 #akedrou self.coOpFailed = False self.coOpRestart = False self.coOpRescueTime = 0 self.lyricScale = .00170 self.engine.loadImgDrawing(self, "vocalLyricSheet", os.path.join(self.engine.data.vocalPath,"lyricsheet.png")) imgwidth = self.vocalLyricSheet.width1() self.vocalLyricSheetWFactor = 640.000/imgwidth try: self.engine.loadImgDrawing(self, "vocalLyricSheetGlow", os.path.join(self.engine.data.vocalPath,"lyricsheetglow.png")) imgwidth = self.vocalLyricSheetGlow.width1() self.vocalLyricSheetGlowWFactor = 640.000/imgwidth except: self.vocalLyricSheetGlow = None try: self.engine.loadImgDrawing(self, "vocalLyricSheetSP", os.path.join(self.engine.data.vocalPath,"lyricsheetactivate.png")) self.vocalSheetSPWidth = float(self.vocalLyricSheetSP.width1()*self.vocalLyricSheetWFactor)*(self.engine.view.geometry[2]/640.0) except: self.vocalLyricSheetSP = None self.engine.loadImgDrawing(self, "vocalArrow", os.path.join(self.engine.data.vocalPath,"arrow.png")) try: self.engine.loadImgDrawing(self, "vocalSplitArrow", os.path.join(self.engine.data.vocalPath,"split_arrow.png")) except IOError: self.vocalSplitArrow = self.vocalArrow self.engine.loadImgDrawing(self, "vocalBar", os.path.join(self.engine.data.vocalPath,"beatline.png")) self.arrowW = self.vocalArrow.width1() self.engine.loadImgDrawing(self, "vocalMult", os.path.join(self.engine.data.vocalPath,"mult.png")) self.engine.loadImgDrawing(self, "vocalMeter", os.path.join(self.engine.data.vocalPath,"meter.png")) try: self.engine.loadImgDrawing(self, "vocalFill", os.path.join(self.engine.data.vocalPath,"meter_fill.png")) except IOError: self.vocalFill = self.vocalMeter try: self.engine.loadImgDrawing(self, "vocalGlow", os.path.join(self.engine.data.vocalPath,"meter_glow.png")) except IOError: self.vocalGlow = None self.engine.loadImgDrawing(self, "vocalTap", os.path.join(self.engine.data.vocalPath,"tap.png")) self.engine.loadImgDrawing(self, "vocalTapNote", os.path.join(self.engine.data.vocalPath,"tap_note.png")) try: self.engine.loadImgDrawing(self, "vocalText", os.path.join(self.engine.data.vocalPath,"text.png")) except IOError: self.vocalText = None self.engine.loadImgDrawing(self, "vocalODBottom", os.path.join(self.engine.data.vocalPath,"bottom.png")) self.engine.loadImgDrawing(self, "vocalODFill", os.path.join(self.engine.data.vocalPath,"fill.png")) self.vocalODFillWidth = self.vocalODFill.width1()/1280.000 try: self.engine.loadImgDrawing(self, "vocalODTop", os.path.join(self.engine.data.vocalPath,"top.png")) except IOError: self.vocalODTop = None try: self.engine.loadImgDrawing(self, "vocalODGlow", os.path.join(self.engine.data.vocalPath,"glow.png")) except IOError: self.vocalODGlow = None height = self.vocalMeter.height1() vocalSize = Theme.vocalMeterSize self.vocalMeterScale = (vocalSize/height)*.5 self.vocalFillWidth = self.vocalFill.width1()*self.vocalMeterScale/640.000 olFactor = height/Theme.vocalFillupFactor self.vocalFillupCenterX = int(Theme.vocalFillupCenterX*olFactor) self.vocalFillupCenterY = int(Theme.vocalFillupCenterY*olFactor) self.vocalFillupInRadius = int(Theme.vocalFillupInRadius*olFactor) self.vocalFillupOutRadius = int(Theme.vocalFillupOutRadius*olFactor) self.vocalFillupColor = Theme.vocalFillupColor self.vocalContinuousAvailable = Theme.vocalCircularFillup and \ None not in (self.vocalFillupCenterX, self.vocalFillupCenterY, self.vocalFillupInRadius, self.vocalFillupOutRadius, self.vocalFillupColor) if self.vocalContinuousAvailable: try: self.drawnVocalOverlays = {} baseVocalFillImageSize = Image.open(self.vocalMeter.texture.name).size for degrees in range(0, 361, 5): overlay = Image.new('RGBA', baseVocalFillImageSize) draw = ImageDraw.Draw(overlay) draw.pieslice((self.vocalFillupCenterX-self.vocalFillupOutRadius, self.vocalFillupCenterY-self.vocalFillupOutRadius, self.vocalFillupCenterX+self.vocalFillupOutRadius, self.vocalFillupCenterY+self.vocalFillupOutRadius), -90, degrees-90, outline=self.vocalFillupColor, fill=self.vocalFillupColor) draw.ellipse((self.vocalFillupCenterX-self.vocalFillupInRadius, self.vocalFillupCenterY-self.vocalFillupInRadius, self.vocalFillupCenterX+self.vocalFillupInRadius, self.vocalFillupCenterY+self.vocalFillupInRadius), outline=(0, 0, 0, 0), fill=(0, 0, 0, 0)) dispOverlay = ImgDrawing(self.engine.data.svg, overlay) self.drawnVocalOverlays[degrees] = dispOverlay except: Log.error('Could not prebuild vocal overlay textures: ') self.vocalContinuousAvailable = False self.vocalLaneSize = Theme.vocalLaneSize self.vocalGlowSize = Theme.vocalGlowSize self.vocalGlowFade = Theme.vocalGlowFade self.vocalLaneColor = list(Theme.vocalLaneColor) self.vocalShadowColor = list(Theme.vocalShadowColor) self.vocalGlowColor = list(Theme.vocalGlowColor) self.vocalLaneColorStar = list(Theme.vocalLaneColorStar) self.vocalShadowColorStar = list(Theme.vocalShadowColorStar) self.vocalGlowColorStar = list(Theme.vocalGlowColorStar) self.lastVal = 0 self.vocalMeterX = Theme.vocalMeterX self.vocalMeterY = Theme.vocalMeterY self.vocalMultX = Theme.vocalMultX self.vocalMultY = Theme.vocalMultY self.vocalPowerX = Theme.vocalPowerX self.vocalPowerY = Theme.vocalPowerY self.time = 0.0 self.tap = 0 self.tapBuffer = 0 self.peak = -100.0 self.starPowerDecreaseDivisor = 400.0/self.engine.audioSpeedFactor self.starPower = 0 self.starPowerActive = False self.starPowerGained = False self.starPowerEnable = False self.starPowerCountdown = False self.starPowerTimer = 200 self.starPowerActivate = False self.paused = False self.player = player self.tapPartStart = [] self.tapPartLength = [] self.tapNoteTotals = [] self.tapNoteHits = [] self.tapPhraseActive = False self.currentTapPhrase = -1 self.difficulty = playerObj.getDifficultyInt() self.tapMargin = 100 + (100 * self.difficulty) self.tapBufferMargin = 300 - (50 * self.difficulty) self.accuracy = 5000 - (self.difficulty * 1000) self.difficultyModifier = diffMod[self.difficulty] self.baseScore = 50 self.vocalBaseScore = baseScores[self.difficulty] #Controls Jurgen in vocal parts self.jurgenEnabled = False self.jurgenSkill = 5