From 959bbdce321e92c47107af89f979c3b280f00577 Mon Sep 17 00:00:00 2001 From: brunzelchen Date: Sun, 23 May 2010 13:06:11 +0000 Subject: fixed aspect in video preview; added video zoom animation in song screen git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.0.1 Challenge MOD@2406 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVideo.pas | 129 +++++++++++++--------- Game/Code/Screens/UScreenEditSub.pas | 1 + Game/Code/Screens/UScreenSong.pas | 203 +++++++++++++++++++++++++++-------- 3 files changed, 237 insertions(+), 96 deletions(-) diff --git a/Game/Code/Classes/UVideo.pas b/Game/Code/Classes/UVideo.pas index 7957c8a8..c50006e8 100644 --- a/Game/Code/Classes/UVideo.pas +++ b/Game/Code/Classes/UVideo.pas @@ -37,17 +37,17 @@ uses SDL, UIni; type + TAspectCorrection = (acoStretch, acoCrop, acoLetterBox); //from 1.1 + TRectCoords = record //from 1.1 Left, Right: double; Upper, Lower: double; windowed: boolean; Reflection: boolean; ReflactionSpacing: real; + TargetAspect: TAspectCorrection; + ZoomFaktor: real; end; - - TAspectCorrection = (acoStretch, acoCrop, acoLetterBox); //from 1.1 - - procedure Init; procedure acOpenFile(FileName: pAnsiChar); @@ -647,63 +647,87 @@ end; procedure GetVideoRect(var ScreenRect, TexRect: TRectCoords; Window: TRectCoords); var - ScreenAspect: double; // aspect of screen resolution - ScaledVideoWidth, ScaledVideoHeight: double; - rW, rH: double; -begin - // Three aspects to take into account: - // 1. Screen/display resolution (e.g. 1920x1080 -> 16:9) - // 2. Render aspect (fixed to 800x600 -> 4:3) - // 3. Movie aspect (video frame aspect stored in fAspect) - if (Window.windowed) then - begin - rW := Window.Right-Window.Left; - rH := Window.Lower-Window.Upper; - ScreenAspect := rW/rH; - end else - begin - rW := RenderW; - rH := RenderH; - ScreenAspect := (ScreenW/Screens) / ScreenH; - end; + RectS, RectT: TRectCoords; - case fAspectCorrection of - acoStretch: begin - ScaledVideoWidth := rW; - ScaledVideoHeight := rH; + + procedure GetCoords(var SRect: TRectCoords; Win: TRectCoords; Aspect: TAspectCorrection); + var + ScreenAspect: double; // aspect of screen resolution + ScaledVideoWidth: double; + ScaledVideoHeight: double; + rW, rH: double; + + begin + // Three aspects to take into account: + // 1. Screen/display resolution (e.g. 1920x1080 -> 16:9) + // 2. Render aspect (fixed to 800x600 -> 4:3) + // 3. Movie aspect (video frame aspect stored in fAspect) + if (Win.windowed) then + begin + rW := (Win.Right-Win.Left); + rH := (Win.Lower-Win.Upper); + ScreenAspect := rW*((ScreenW/Screens)/RenderW)/(rH*(ScreenH/RenderH)); + end else + begin + rW := RenderW; + rH := RenderH; + ScreenAspect := (ScreenW/Screens) / ScreenH; end; - acoCrop: begin - if (ScreenAspect >= fAspect) then - begin + + case Aspect of + acoStretch: begin ScaledVideoWidth := rW; - ScaledVideoHeight := rH * ScreenAspect/fAspect; - end - else - begin ScaledVideoHeight := rH; - ScaledVideoWidth := rW * fAspect/ScreenAspect; end; - end; - acoLetterBox: begin - if (ScreenAspect <= fAspect) then - begin - ScaledVideoWidth := rW; - ScaledVideoHeight := rH * ScreenAspect/fAspect; + + acoCrop: begin + if (ScreenAspect >= fAspect) then + begin + ScaledVideoWidth := rW; + ScaledVideoHeight := rH * ScreenAspect/fAspect; + end + else + begin + ScaledVideoHeight := rH; + ScaledVideoWidth := rW * fAspect/ScreenAspect; + end; + end; + + acoLetterBox: begin + if (ScreenAspect <= fAspect) then + begin + ScaledVideoWidth := rW; + ScaledVideoHeight := rH * ScreenAspect/fAspect; + end + else + begin + ScaledVideoHeight := rH; + ScaledVideoWidth := rW * fAspect/ScreenAspect; + end; end else - begin - ScaledVideoHeight := rH; - ScaledVideoWidth := rW * fAspect/ScreenAspect; - end; - end - else - raise Exception.Create('Unhandled aspect correction!'); + raise Exception.Create('Unhandled aspect correction!'); + end; + + SRect.Left := (rW - ScaledVideoWidth) / 2 + Win.Left; + SRect.Right := SRect.Left + ScaledVideoWidth; + SRect.Upper := (rH - ScaledVideoHeight) / 2 + Win.Upper; + SRect.Lower := SRect.Upper + ScaledVideoHeight; + end; +begin + if (Window.TargetAspect = fAspectCorrection) then + GetCoords(ScreenRect, Window, fAspectCorrection) + else + begin + GetCoords(RectS, Window, fAspectCorrection); + GetCoords(RectT, Window, Window.TargetAspect); + + ScreenRect.Left := RectS.Left + (RectT.Left-RectS.Left)*Window.ZoomFaktor; + ScreenRect.Right := RectS.Right + (RectT.Right-RectS.Right)*Window.ZoomFaktor; + ScreenRect.Upper := RectS.Upper + (RectT.Upper-RectS.Upper)*Window.ZoomFaktor; + ScreenRect.Lower := RectS.Lower + (RectT.Lower-RectS.Lower)*Window.ZoomFaktor; end; - ScreenRect.Left := (rW - ScaledVideoWidth) / 2 + Window.Left; - ScreenRect.Right := ScreenRect.Left + ScaledVideoWidth; - ScreenRect.Upper := (rH - ScaledVideoHeight) / 2 + Window.Upper; - ScreenRect.Lower := ScreenRect.Upper + ScaledVideoHeight; // texture contains right/lower (power-of-2) padding. // Determine the texture coords of the video frame. @@ -726,6 +750,7 @@ begin Window.Lower := RenderH; Window.windowed := false; Window.Reflection := false; + Window.TargetAspect := fAspectCorrection; acDrawGLi(Screen, Window, 1); end; diff --git a/Game/Code/Screens/UScreenEditSub.pas b/Game/Code/Screens/UScreenEditSub.pas index 7665d8a4..f0d5822c 100644 --- a/Game/Code/Screens/UScreenEditSub.pas +++ b/Game/Code/Screens/UScreenEditSub.pas @@ -2225,6 +2225,7 @@ begin Window.Upper := 65; Window.Lower := 250; Window.Reflection := false; + Window.TargetAspect := acoCrop; Window.windowed := true; {if CoverTime>=Ini.PreviewFading then diff --git a/Game/Code/Screens/UScreenSong.pas b/Game/Code/Screens/UScreenSong.pas index ee6a8aaa..1b70b95f 100644 --- a/Game/Code/Screens/UScreenSong.pas +++ b/Game/Code/Screens/UScreenSong.pas @@ -62,6 +62,10 @@ type VideoIcon: Cardinal; VidVis: TVidVis; //video visiability + TargetVidVis: TVidVis; //target video visiability + TargetAspect: TAspectCorrection; + VidVisHandler:THandler; + StartTry: boolean; MinSource: TMedleySource; @@ -507,26 +511,45 @@ begin SDLK_A: begin if VidVis = full then - + begin ToggleAspectCorrection; DataBase.SetAspect(CatSongs.Song[Interaction].Artist, CatSongs.Song[Interaction].Title, integer(UVideo.fAspectCorrection)); + TargetAspect := UVideo.fAspectCorrection; AspectHandler.changed := true; AspectHandler.change_time := Czas.Teraz; + end; end; SDLK_V: begin if UVideo.VideoOpened then begin - if VidVis=full then - VidVis:=windowed - else begin - VidVis:=full; - UVideo.SetAspectCorrection(TAspectCorrection( + if TargetVidVis=full then + begin + TargetVidVis:=windowed; + TargetAspect := acoCrop; + if not VidVisHandler.changed then + begin + VidVisHandler.changed := true; + VidVisHandler.change_time := 0; + end; + end else + begin + TargetVidVis:=full; + if not VidVisHandler.changed then + begin + VidVisHandler.changed := true; + VidVisHandler.change_time := 0; + end; + //UVideo.SetAspectCorrection(TAspectCorrection( + // DataBase.GetAspect(CatSongs.Song[Interaction].Artist, + // CatSongs.Song[Interaction].Title, Ini.AspectCorrect))); + TargetAspect := TAspectCorrection( DataBase.GetAspect(CatSongs.Song[Interaction].Artist, - CatSongs.Song[Interaction].Title, Ini.AspectCorrect))); + CatSongs.Song[Interaction].Title, Ini.AspectCorrect)); + AspectHandler.changed := true; AspectHandler.change_time := Czas.Teraz; end; @@ -613,7 +636,7 @@ begin //Stop Video acClose; - VidVis := none; + CatSongs.ShowCategoryList; //Show Cat in Top Left Mod @@ -650,7 +673,7 @@ begin Music.Stop; Music.PlayBack; acClose; - VidVis := none; + FadeTo(@ScreenMain); end; @@ -713,7 +736,15 @@ begin 0: StartSong; 1: SelectPlayers; 2:begin - VidVis := windowed; + if (TargetVidVis = full) then + begin + TargetVidVis := windowed; + if not VidVisHandler.changed then + begin + VidVisHandler.changed := true; + VidVisHandler.change_time := 0; + end; + end; If (CatSongs.CatNumShow = -3) then ScreenSongMenu.MenuShow(SM_Playlist) else @@ -724,7 +755,15 @@ begin end else if (Mode = smParty) and not PartyMedley then //PartyMode classic -> Show Menu begin - VidVis := windowed; + if (TargetVidVis = full) then + begin + TargetVidVis := windowed; + if not VidVisHandler.changed then + begin + VidVisHandler.changed := true; + VidVisHandler.change_time := 0; + end; + end; if (Ini.PartyPopup = 1) then ScreenSongMenu.MenuShow(SM_Party_Main) else begin @@ -746,8 +785,10 @@ begin SDLK_M: //Show SongMenu begin - if (Length(Songs.Song) > 0) and (Mode <> smChallenge) then begin //not in M2-Mode - if (Mode = smNormal) then begin + if (Length(Songs.Song) > 0) and (Mode <> smChallenge) then + begin //not in M2-Mode + if (Mode = smNormal) then + begin WaitHandler.changed := false; CatSongs.Selected := Interaction; if not CatSongs.Song[Interaction].Main then begin // clicked on Song @@ -762,6 +803,16 @@ begin end; end //Party Mode -> Show Party Menu else ScreenSongMenu.MenuShow(SM_Party_Main); + + if (TargetVidVis = full) then + begin + TargetVidVis := windowed; + if not VidVisHandler.changed then + begin + VidVisHandler.changed := true; + VidVisHandler.change_time := 0; + end; + end; end; end; @@ -779,7 +830,15 @@ begin begin if (Length(Songs.Song) > 0) AND (Mode = smNormal) then //not in party-modes begin - VidVis := windowed; + if (TargetVidVis = full) then + begin + TargetVidVis := windowed; + if not VidVisHandler.changed then + begin + VidVisHandler.changed := true; + VidVisHandler.change_time := 0; + end; + end; WaitHandler.changed := false; CatSongs.Selected := Interaction; ScreenSongJumpto.Visible := True; @@ -1968,6 +2027,10 @@ begin AspectHandler.changed := false; InfoHandler.changed := false; MP3VolumeHandler.changed := false; + VidVisHandler.changed := false; + TargetVidVis := windowed; + VidVis := windowed; + TargetAspect := UVideo.fAspectCorrection; SetLength(PlaylistMedley.Song, 0); SetLength(SkippedSongs, 0); @@ -2008,7 +2071,7 @@ begin //Stop Video acClose; - VidVis := none; + CatSongs.ShowCategoryList; //Show Cat in Top Left Mod @@ -2227,6 +2290,7 @@ var Blend: real; VisArr: array of integer; txt: string; + faktor: real; //0..1 begin dx := SongTarget-SongCurrent; @@ -2244,8 +2308,8 @@ begin // Log.BenchmarkEnd(5); // Log.LogBenchmark('SetScroll4', 5); - //Fading Functions, Only if Covertime is under 5 Seconds - If (CoverTime < 5) then + //Fading Functions, Only if Covertime is under 10 Seconds + If (CoverTime < 10) then begin // 0.5.0: cover fade if (CoverTime < 1) and (CoverTime + TimeSkip >= 1) then begin @@ -2328,7 +2392,49 @@ begin try acGetFrame(Czas.Teraz); - if VidVis=windowed then + Blend := (CoverTime{-1.75})/Ini.PreviewFading; + if Blend<0 then + Blend := 0 + else if Blend>1 then + Blend := 1; + + if VidVisHandler.changed then + begin + if (VidVisHandler.change_time+TimeSkip<0.4) then + begin + VidVisHandler.change_time := VidVisHandler.change_time + TimeSkip; + faktor := VidVisHandler.change_time/0.4; + + if (TargetVidVis = full) then + begin + Window.Left := Button[Interaction].X*(1-faktor); + Window.Right := Button[Interaction].X+Button[Interaction].W + + (RenderW/Screens-(Button[Interaction].X+Button[Interaction].W))*faktor; + Window.Upper := Button[Interaction].Y*(1-faktor); + Window.Lower := Button[Interaction].Y+Button[Interaction].H + + (RenderH-(Button[Interaction].Y+Button[Interaction].H))*faktor; + end else + begin + Window.Left := Button[Interaction].X*(faktor); + Window.Right := Button[Interaction].X+Button[Interaction].W + + (RenderW/Screens-(Button[Interaction].X+Button[Interaction].W))*(1-faktor); + Window.Upper := Button[Interaction].Y*(faktor); + Window.Lower := Button[Interaction].Y+Button[Interaction].H + + (RenderH-(Button[Interaction].Y+Button[Interaction].H))*(1-faktor); + end; + Window.Reflection := false; + Window.windowed := true; + Window.TargetAspect := TargetAspect; + Window.ZoomFaktor := faktor; + end else + begin + VidVisHandler.changed := false; + VidVis := TargetVidVis; + SetAspectCorrection(TargetAspect); + end; + end; + + if not VidVisHandler.changed and (VidVis = windowed) then begin Window.Left := Button[Interaction].X; Window.Right := Button[Interaction].X+Button[Interaction].W; @@ -2337,13 +2443,9 @@ begin Window.ReflactionSpacing := Button[Interaction].Reflectionspacing; Window.Reflection := Button[Interaction].Reflection; Window.windowed := true; + Window.TargetAspect := acoCrop; SetAspectCorrection(acoCrop); - Blend := (CoverTime-1.75)/Ini.PreviewFading; - if Blend<0 then - Blend := 0 - else if Blend>1 then - Blend := 1; end; except //If an Error occurs drawing: prevent Video from being Drawn again and Close Video @@ -2351,7 +2453,7 @@ begin Log.LogError('Corrupted File: ' + CatSongs.Song[Interaction].Video); try acClose; - VidVis := none; + except end; @@ -2369,25 +2471,23 @@ begin //Draw Video preview and interaction-button if UVideo.VideoOpened then begin - if (Blend<1) or not EnableVideoDraw then + if (Blend<1) or not EnableVideoDraw or VidVisHandler.changed then Button[Interaction].Draw; try - if VidVis=windowed then + if (VidVis=windowed) then acDrawGLi(ScreenAct, Window, Blend); if (Czas.Teraz>=Czas.Razem) then - begin acClose; - VidVis := none; - end; + except //If an Error occurs drawing: prevent Video from being Drawn again and Close Video log.LogError('Error drawing Video, Video has been disabled for this Song/Session.'); Log.LogError('Corrupted File: ' + CatSongs.Song[Interaction].Video); try acClose; - VidVis := none; + except end; end; @@ -2407,29 +2507,27 @@ begin DrawEqualizer; if (CatSongs.Song[Interaction].Main) or (CatSongs.VisibleSongs = 0) then - begin acClose; - VidVis := none; - end; if UVideo.VideoOpened then begin try - if VidVis=full then - acDrawGL(ScreenAct); + if (VidVis=full) and not VidVisHandler.changed then + acDrawGL(ScreenAct) + else if VidVisHandler.changed then + acDrawGLi(ScreenAct, Window, Blend); + if (Czas.Teraz>=Czas.Razem) then - begin acClose; - VidVis := none; - end; + except //If an Error occurs drawing: prevent Video from being Drawn again and Close Video log.LogError('Error drawing Video, Video has been disabled for this Song/Session.'); Log.LogError('Corrupted File: ' + CatSongs.Song[Interaction].Video); try acClose; - VidVis := none; + except end; @@ -2777,9 +2875,14 @@ begin if CoverTime<0.75 then begin acClose; - VidVis := none; StartTry := true; AspectHandler.changed := false; + VidVisHandler.changed := false; + TargetVidVis := windowed; + SetAspectCorrection(acoCrop); + if(VidVis=none) then + VidVis := windowed; + end else if (Ini.MoviePreview=1) and StartTry then begin if (CatSongs.Song[Interaction].Video <> '') and @@ -2793,7 +2896,20 @@ begin StartTry := false; try acGetFrame(Czas.Teraz); - VidVis := windowed; + if (VidVis = full) then + begin + TargetVidVis := full; + VidVis := windowed; + TargetAspect := TAspectCorrection( + DataBase.GetAspect(CatSongs.Song[Interaction].Artist, + CatSongs.Song[Interaction].Title, Ini.AspectCorrect)); + + AspectHandler.changed := true; + AspectHandler.change_time := Czas.Teraz; + + VidVisHandler.changed := true; + VidVisHandler.change_time := 0; + end; except //If an Error occurs Reading Video: prevent Video from being Drawn again and Close Video Log.LogError('Error drawing Video, Video has been disabled for this Song/Session.'); @@ -2801,13 +2917,12 @@ begin CatSongs.Song[Interaction].Video := ''; //dirt fix try acClose; - VidVis := none; + except end; end; - end else - VidVis := none; + end; end; end; end; -- cgit v1.2.3