aboutsummaryrefslogtreecommitdiffstats
path: root/src/menu
diff options
context:
space:
mode:
Diffstat (limited to 'src/menu')
-rw-r--r--src/menu/UDisplay.pas747
-rw-r--r--src/menu/UDrawTexture.pas139
-rw-r--r--src/menu/UMenu.pas1804
-rw-r--r--src/menu/UMenuBackground.pas83
-rw-r--r--src/menu/UMenuBackgroundColor.pas73
-rw-r--r--src/menu/UMenuBackgroundFade.pas176
-rw-r--r--src/menu/UMenuBackgroundNone.pas70
-rw-r--r--src/menu/UMenuBackgroundTexture.pas126
-rw-r--r--src/menu/UMenuBackgroundVideo.pas211
-rw-r--r--src/menu/UMenuButton.pas647
-rw-r--r--src/menu/UMenuButtonCollection.pas101
-rw-r--r--src/menu/UMenuEqualizer.pas320
-rw-r--r--src/menu/UMenuInteract.pas54
-rw-r--r--src/menu/UMenuSelectSlide.pas541
-rw-r--r--src/menu/UMenuStatic.pas117
-rw-r--r--src/menu/UMenuText.pas379
16 files changed, 5588 insertions, 0 deletions
diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas
new file mode 100644
index 00000000..6ec8e2ed
--- /dev/null
+++ b/src/menu/UDisplay.pas
@@ -0,0 +1,747 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UDisplay;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UCommon,
+ Math,
+ SDL,
+ gl,
+ glu,
+ SysUtils,
+ UMenu,
+ UPath,
+ UMusic,
+ UHookableEvent;
+
+type
+ TDisplay = class
+ private
+ ePreDraw: THookableEvent;
+ eDraw: THookableEvent;
+
+ // fade-to-black
+ BlackScreen: boolean;
+
+ FadeEnabled: boolean; // true if fading is enabled
+ FadeFailed: boolean; // true if fading is possible (enough memory, etc.)
+ FadeStartTime: cardinal; // time when fading starts, 0 means that the fade texture must be initialized
+ DoneOnShow: boolean; // true if passed onShow after fading
+
+ FadeTex: array[0..1] of GLuint;
+ TexW, TexH: Cardinal;
+
+ FPSCounter: cardinal;
+ LastFPS: cardinal;
+ NextFPSSwap: cardinal;
+
+ OSD_LastError: string;
+
+ { software cursor data }
+ Cursor_X: double;
+ Cursor_Y: double;
+ Cursor_Pressed: boolean;
+ Cursor_HiddenByScreen: boolean; // hides software cursor and deactivate auto fade in
+
+ // used for cursor fade out when there is no movement
+ Cursor_Visible: boolean;
+ Cursor_LastMove: cardinal;
+ Cursor_Fade: boolean;
+
+ procedure DrawDebugInformation;
+
+ { called by MoveCursor and OnMouseButton to update last move and start fade in }
+ procedure UpdateCursorFade;
+ public
+ NextScreen: PMenu;
+ CurrentScreen: PMenu;
+
+ // popup data
+ NextScreenWithCheck: Pmenu;
+ CheckOK: boolean;
+
+ // FIXME: Fade is set to 0 in UMain and other files but not used here anymore.
+ Fade: real;
+
+ constructor Create;
+ destructor Destroy; override;
+
+ procedure InitFadeTextures();
+
+ procedure SaveScreenShot;
+
+ function Draw: boolean;
+
+ { calls ParseInput of cur or next Screen if assigned }
+ function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown : boolean): boolean;
+
+ { sets SDL_ShowCursor depending on options set in Ini }
+ procedure SetCursor;
+
+ { called when cursor moves, positioning of software cursor }
+ procedure MoveCursor(X, Y: double);
+
+ { called when left or right mousebutton is pressed or released }
+ procedure OnMouseButton(Pressed: boolean);
+ { fades to specific screen (playing specified sound) }
+ function FadeTo(Screen: PMenu; const aSound: TAudioPlaybackStream = nil): PMenu;
+
+ { abort fading to the current screen, may be used in OnShow, or during fade process }
+ procedure AbortScreenChange;
+
+ { draws software cursor }
+ procedure DrawCursor;
+ end;
+
+var
+ Display: TDisplay;
+
+const
+ { constants for screen transition
+ time in milliseconds }
+ FADE_DURATION = 400;
+ { constants for software cursor effects
+ time in milliseconds }
+ CURSOR_FADE_IN_TIME = 500; // seconds the fade in effect lasts
+ CURSOR_FADE_OUT_TIME = 2000; // seconds the fade out effect lasts
+ CURSOR_AUTOHIDE_TIME = 5000; // seconds until auto fade out starts if there is no mouse movement
+
+implementation
+
+uses
+ TextGL,
+ UCommandLine,
+ UGraphic,
+ UIni,
+ UImage,
+ ULog,
+ UMain,
+ UTexture,
+ UTime,
+ ULanguage,
+ UPathUtils;
+
+constructor TDisplay.Create;
+begin
+ inherited Create;
+
+ // create events for plugins
+ ePreDraw := THookableEvent.Create('Display.PreDraw');
+ eDraw := THookableEvent.Create('Display.Draw');
+
+ // init popup
+ CheckOK := false;
+ NextScreen := nil;
+ NextScreenWithCheck := nil;
+ BlackScreen := false;
+
+ // init fade
+ FadeStartTime := 0;
+ FadeEnabled := (Ini.ScreenFade = 1);
+ FadeFailed := false;
+ DoneOnShow := false;
+
+ glGenTextures(2, PGLuint(@FadeTex));
+ InitFadeTextures();
+
+ // set LastError for OSD to No Error
+ OSD_LastError := 'No Errors';
+
+ // software cursor default values
+ Cursor_LastMove := 0;
+ Cursor_Visible := false;
+ Cursor_Pressed := false;
+ Cursor_X := -1;
+ Cursor_Y := -1;
+ Cursor_Fade := false;
+ Cursor_HiddenByScreen := true;
+end;
+
+destructor TDisplay.Destroy;
+begin
+ glDeleteTextures(2, @FadeTex);
+ inherited Destroy;
+end;
+
+procedure TDisplay.InitFadeTextures();
+var
+ i: integer;
+begin
+ TexW := Round(Power(2, Ceil(Log2(ScreenW div Screens))));
+ TexH := Round(Power(2, Ceil(Log2(ScreenH))));
+
+ for i := 0 to 1 do
+ begin
+ glBindTexture(GL_TEXTURE_2D, FadeTex[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, TexW, TexH, 0, GL_RGB, GL_UNSIGNED_BYTE, nil);
+ end;
+end;
+
+function TDisplay.Draw: boolean;
+var
+ S: integer;
+ FadeStateSquare: real;
+ FadeW, FadeH: real;
+ FadeCopyW, FadeCopyH: integer;
+ currentTime: cardinal;
+ glError: glEnum;
+
+begin
+ Result := true;
+
+ for S := 1 to Screens do
+ begin
+ ScreenAct := S;
+
+ //if Screens = 1 then ScreenX := 0;
+ //if (Screens = 2) and (S = 1) then ScreenX := -1;
+ //if (Screens = 2) and (S = 2) then ScreenX := 1;
+ ScreenX := 0;
+
+ glViewPort((S-1) * ScreenW div Screens, 0, ScreenW div Screens, ScreenH);
+
+ // popup check was successful... move on
+ if CheckOK then
+ begin
+ if assigned(NextScreenWithCheck) then
+ begin
+ NextScreen := NextScreenWithCheck;
+ NextScreenWithCheck := nil;
+ CheckOk := false;
+ end
+ else
+ begin
+ // on end of game fade to black before exit
+ BlackScreen := true;
+ end;
+ end;
+
+ if (not assigned(NextScreen)) and (not BlackScreen) then
+ begin
+ ePreDraw.CallHookChain(false);
+ CurrentScreen.Draw;
+
+ // popup
+ if (ScreenPopupError <> nil) and ScreenPopupError.Visible then
+ ScreenPopupError.Draw
+ else if (ScreenPopupInfo <> nil) and ScreenPopupInfo.Visible then
+ ScreenPopupInfo.Draw
+ else if (ScreenPopupCheck <> nil) and ScreenPopupCheck.Visible then
+ ScreenPopupCheck.Draw;
+
+ // fade
+ FadeStartTime := 0;
+ if ((Ini.ScreenFade = 1) and (not FadeFailed)) then
+ FadeEnabled := true
+ else
+ FadeEnabled := false;
+
+ eDraw.CallHookChain(false);
+ end
+ else
+ begin
+ // disable fading if initialization failed
+ if (FadeEnabled and FadeFailed) then
+ begin
+ FadeEnabled := false;
+ end;
+
+ if (FadeEnabled and not FadeFailed) then
+ begin
+ // create fading texture if we're just starting
+ if FadeStartTime = 0 then
+ begin
+ // draw screen that will be faded
+ ePreDraw.CallHookChain(false);
+ CurrentScreen.Draw;
+ eDraw.CallHookChain(false);
+
+ // clear OpenGL errors, otherwise fading might be disabled due to some
+ // older errors in previous OpenGL calls.
+ glGetError();
+
+ FadeCopyW := ScreenW div Screens;
+ FadeCopyH := ScreenH;
+
+ // it is possible that our fade textures are too small after a window
+ // resize. In that case resize the fade texture to fit the requirements.
+ if (TexW < FadeCopyW) or (TexH < FadeCopyH) then
+ InitFadeTextures();
+
+ // copy screen to texture
+ glBindTexture(GL_TEXTURE_2D, FadeTex[S-1]);
+ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (S-1) * ScreenW div Screens, 0,
+ FadeCopyW, FadeCopyH);
+
+ glError := glGetError();
+ if (glError <> GL_NO_ERROR) then
+ begin
+ FadeFailed := true;
+ Log.LogError('Fading disabled: ' + gluErrorString(glError), 'TDisplay.Draw');
+ end;
+
+ if not BlackScreen and (S = 1) and not DoneOnShow then
+ begin
+ NextScreen.OnShow;
+ DoneOnShow := true;
+ end;
+
+
+ // set fade time once on second screen (or first if screens = 1)
+ if (Screens = 1) or (S = 2) then
+ FadeStartTime := SDL_GetTicks;
+ end; // end texture creation in first fading step
+
+ if not BlackScreen then
+ begin
+ ePreDraw.CallHookChain(false);
+ NextScreen.Draw; // draw next screen
+ eDraw.CallHookChain(false);
+ end
+ else if ScreenAct = 1 then
+ begin
+ // draw black screen
+ glClearColor(0, 0, 0, 1);
+ glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
+ end;
+
+ // and draw old screen over it... slowly fading out
+ if (FadeStartTime = 0) then
+ FadeStateSquare := 0 // for first screen if screens = 2
+ else
+ FadeStateSquare := sqr((SDL_GetTicks - FadeStartTime) / FADE_DURATION);
+
+ if (FadeStateSquare < 1) then
+ begin
+ FadeW := (ScreenW div Screens)/TexW;
+ FadeH := ScreenH/TexH;
+
+ glBindTexture(GL_TEXTURE_2D, FadeTex[S-1]);
+ // TODO: check if glTexEnvi() gives any speed improvement
+ //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glColor4f(1, 1, 1, 1-FadeStateSquare);
+
+ glEnable(GL_TEXTURE_2D);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ glBegin(GL_QUADS);
+ glTexCoord2f((0+FadeStateSquare/2)*FadeW, (0+FadeStateSquare/2)*FadeH);
+ glVertex2f(0, RenderH);
+
+ glTexCoord2f((0+FadeStateSquare/2)*FadeW, (1-FadeStateSquare/2)*FadeH);
+ glVertex2f(0, 0);
+
+ glTexCoord2f((1-FadeStateSquare/2)*FadeW, (1-FadeStateSquare/2)*FadeH);
+ glVertex2f(RenderW, 0);
+
+ glTexCoord2f((1-FadeStateSquare/2)*FadeW, (0+FadeStateSquare/2)*FadeH);
+ glVertex2f(RenderW, RenderH);
+ glEnd;
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+
+ // reset to default
+ //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ end;
+ end
+
+ // there is no need to init next screen if it is a black screen
+ else if not BlackScreen then
+ begin
+ NextScreen.OnShow;
+ end;
+
+ if ((FadeStartTime + FADE_DURATION < SDL_GetTicks) or
+ (not FadeEnabled) or FadeFailed) and
+ ((Screens = 1) or (S = 2)) then
+ begin
+ // fade out complete...
+ FadeStartTime := 0;
+ DoneOnShow := false;
+ CurrentScreen.onHide;
+ CurrentScreen.ShowFinish := false;
+ CurrentScreen := NextScreen;
+ NextScreen := nil;
+ if not BlackScreen then
+ begin
+ CurrentScreen.OnShowFinish;
+ CurrentScreen.ShowFinish := true;
+ end
+ else
+ begin
+ Result := false;
+ Break;
+ end;
+ end;
+ end; // if
+
+ // Draw OSD only on first Screen if Debug Mode is enabled
+ if ((Ini.Debug = 1) or (Params.Debug)) and (S = 1) then
+ DrawDebugInformation;
+
+ if not BlackScreen then
+ DrawCursor;
+ end; // for
+end;
+
+{ sets SDL_ShowCursor depending on options set in Ini }
+procedure TDisplay.SetCursor;
+var
+ Cursor: Integer;
+begin
+ Cursor := 0;
+
+ if (CurrentScreen <> @ScreenSing) or (Cursor_HiddenByScreen) then
+ begin // hide cursor on singscreen
+ if (Ini.Mouse = 0) and (Ini.FullScreen = 0) then
+ // show sdl (os) cursor in window mode even when mouse support is off
+ Cursor := 1
+ else if (Ini.Mouse = 1) then
+ // show sdl (os) cursor when hardware cursor is selected
+ Cursor := 1;
+
+ if (Ini.Mouse <> 2) then
+ Cursor_HiddenByScreen := false;
+ end
+ else if (Ini.Mouse <> 2) then
+ Cursor_HiddenByScreen := true;
+
+
+ SDL_ShowCursor(Cursor);
+
+ if (Ini.Mouse = 2) then
+ begin
+ if Cursor_HiddenByScreen then
+ begin
+ // show software cursor
+ Cursor_HiddenByScreen := false;
+ Cursor_Visible := false;
+ Cursor_Fade := false;
+ end
+ else if (CurrentScreen = @ScreenSing) then
+ begin
+ // hide software cursor in singscreen
+ Cursor_HiddenByScreen := true;
+ Cursor_Visible := false;
+ Cursor_Fade := false;
+ end;
+ end;
+end;
+
+{ called by MoveCursor and OnMouseButton to update last move and start fade in }
+procedure TDisplay.UpdateCursorFade;
+var
+ Ticks: cardinal;
+begin
+ Ticks := SDL_GetTicks;
+
+ { fade in on movement (or button press) if not first movement }
+ if (not Cursor_Visible) and (Cursor_LastMove <> 0) then
+ begin
+ if Cursor_Fade then // we use a trick here to consider progress of fade out
+ Cursor_LastMove := Ticks - round(CURSOR_FADE_IN_TIME * (1 - (Ticks - Cursor_LastMove)/CURSOR_FADE_OUT_TIME))
+ else
+ Cursor_LastMove := Ticks;
+
+ Cursor_Visible := true;
+ Cursor_Fade := true;
+ end
+ else if not Cursor_Fade then
+ begin
+ Cursor_LastMove := Ticks;
+ end;
+end;
+
+{ called when cursor moves, positioning of software cursor }
+procedure TDisplay.MoveCursor(X, Y: double);
+begin
+ if (Ini.Mouse = 2) and
+ ((X <> Cursor_X) or (Y <> Cursor_Y)) then
+ begin
+ Cursor_X := X;
+ Cursor_Y := Y;
+
+ UpdateCursorFade;
+ end;
+end;
+
+{ called when left or right mousebutton is pressed or released }
+procedure TDisplay.OnMouseButton(Pressed: boolean);
+begin
+ if (Ini.Mouse = 2) then
+ begin
+ Cursor_Pressed := Pressed;
+
+ UpdateCursorFade;
+ end;
+end;
+
+{ draws software cursor }
+procedure TDisplay.DrawCursor;
+var
+ Alpha: single;
+ Ticks: cardinal;
+ DrawX: double;
+begin
+ if (Ini.Mouse = 2) and ((Screens = 1) or ((ScreenAct - 1) = (Round(Cursor_X+16) div RenderW))) then
+ begin // draw software cursor
+ Ticks := SDL_GetTicks;
+
+ if (Cursor_Visible) and (Cursor_LastMove + CURSOR_AUTOHIDE_TIME <= Ticks) then
+ begin // start fade out after 5 secs w/o activity
+ Cursor_Visible := false;
+ Cursor_LastMove := Ticks;
+ Cursor_Fade := true;
+ end;
+
+ // fading
+ if Cursor_Fade then
+ begin
+ if Cursor_Visible then
+ begin // fade in
+ if (Cursor_LastMove + CURSOR_FADE_IN_TIME <= Ticks) then
+ Cursor_Fade := false
+ else
+ Alpha := sin((Ticks - Cursor_LastMove) * 0.5 * pi / CURSOR_FADE_IN_TIME) * 0.7;
+ end
+ else
+ begin //fade out
+ if (Cursor_LastMove + CURSOR_FADE_OUT_TIME <= Ticks) then
+ Cursor_Fade := false
+ else
+ Alpha := cos((Ticks - Cursor_LastMove) * 0.5 * pi / CURSOR_FADE_OUT_TIME) * 0.7;
+ end;
+ end;
+
+ // no else if here because we may turn off fade in if block
+ if not Cursor_Fade then
+ begin
+ if Cursor_Visible then
+ Alpha := 0.7 // alpha when cursor visible and not fading
+ else
+ Alpha := 0; // alpha when cursor is hidden
+ end;
+
+ if (Alpha > 0) and (not Cursor_HiddenByScreen) then
+ begin
+ DrawX := Cursor_X;
+ if (ScreenAct = 2) then
+ DrawX := DrawX - RenderW;
+ glColor4f(1, 1, 1, Alpha);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glDisable(GL_DEPTH_TEST);
+
+ if (Cursor_Pressed) and (Tex_Cursor_Pressed.TexNum > 0) then
+ glBindTexture(GL_TEXTURE_2D, Tex_Cursor_Pressed.TexNum)
+ else
+ glBindTexture(GL_TEXTURE_2D, Tex_Cursor_Unpressed.TexNum);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0);
+ glVertex2f(DrawX, Cursor_Y);
+
+ glTexCoord2f(0, 1);
+ glVertex2f(DrawX, Cursor_Y + 32);
+
+ glTexCoord2f(1, 1);
+ glVertex2f(DrawX + 32, Cursor_Y + 32);
+
+ glTexCoord2f(1, 0);
+ glVertex2f(DrawX + 32, Cursor_Y);
+ glEnd;
+
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+ end;
+ end;
+end;
+
+function TDisplay.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown : boolean): boolean;
+begin
+ if (assigned(NextScreen)) then
+ Result := NextScreen^.ParseInput(PressedKey, CharCode, PressedDown)
+ else if (assigned(CurrentScreen)) then
+ Result := CurrentScreen^.ParseInput(PressedKey, CharCode, PressedDown)
+ else
+ Result := True;
+end;
+
+{ abort fading to the next screen, may be used in OnShow, or during fade process }
+procedure TDisplay.AbortScreenChange;
+ var
+ Temp: PMenu;
+begin
+ // this is some kind of "hack" it is based on the
+ // code that is used to change the screens in TDisplay.Draw
+ // we should rewrite this whole behaviour, as it is not well
+ // structured and not well extendable. Also we should offer
+ // a possibility to change screens to plugins
+ // change this code when restructuring is done
+ if (assigned(NextScreen)) then
+ begin
+ // we have to swap the screens
+ Temp := CurrentScreen;
+ CurrentScreen := NextScreen;
+ NextScreen := Temp;
+
+ // and call the OnShow procedure of the previous screen
+ // because it was already called by default fade procedure
+ NextScreen.OnShow;
+
+ end;
+end;
+
+{ fades to specific screen (playing specified sound)
+ returns old screen }
+function TDisplay.FadeTo(Screen: PMenu; const aSound: TAudioPlaybackStream = nil): PMenu;
+begin
+ Result := CurrentScreen;
+ if (Result <> nil) then
+ begin
+ if (aSound <> nil) then
+ Result.FadeTo(Screen, aSound)
+ else
+ Result.FadeTo(Screen);
+ end;
+end;
+
+procedure TDisplay.SaveScreenShot;
+var
+ Num: integer;
+ FileName: IPath;
+ Prefix: UTF8String;
+ ScreenData: PChar;
+ Surface: PSDL_Surface;
+ Success: boolean;
+ Align: integer;
+ RowSize: integer;
+begin
+ // Exit if Screenshot-path does not exist or read-only
+ if (ScreenshotsPath.IsUnset) then
+ Exit;
+
+ for Num := 1 to 9999 do
+ begin
+ // fill prefix to 4 digits with leading '0', e.g. '0001'
+ Prefix := Format('screenshot%.4d', [Num]);
+ FileName := ScreenshotsPath.Append(Prefix + '.png');
+ if not FileName.Exists() then
+ break;
+ end;
+
+ // we must take the row-alignment (4byte by default) into account
+ glGetIntegerv(GL_PACK_ALIGNMENT, @Align);
+ // calc aligned row-size
+ RowSize := ((ScreenW*3 + (Align-1)) div Align) * Align;
+
+ GetMem(ScreenData, RowSize * ScreenH);
+ glReadPixels(0, 0, ScreenW, ScreenH, GL_RGB, GL_UNSIGNED_BYTE, ScreenData);
+ // on big endian machines (powerpc) this may need to be changed to
+ // Needs to be tests. KaMiSchi Sept 2008
+ // in this case one may have to add " glext, " to the list of used units
+ // glReadPixels(0, 0, ScreenW, ScreenH, GL_BGR, GL_UNSIGNED_BYTE, ScreenData);
+ Surface := SDL_CreateRGBSurfaceFrom(
+ ScreenData, ScreenW, ScreenH, 24, RowSize,
+ $0000FF, $00FF00, $FF0000, 0);
+
+ // Success := WriteJPGImage(FileName, Surface, 95);
+ // Success := WriteBMPImage(FileName, Surface);
+ Success := WritePNGImage(FileName, Surface);
+ if Success then
+ ScreenPopupInfo.ShowPopup(Format(Language.Translate('SCREENSHOT_SAVED'), [FileName.GetName.ToUTF8()]))
+ else
+ ScreenPopupError.ShowPopup(Language.Translate('SCREENSHOT_FAILED'));
+
+ SDL_FreeSurface(Surface);
+ FreeMem(ScreenData);
+end;
+
+//------------
+// DrawDebugInformation - procedure draw fps and some other informations on screen
+//------------
+procedure TDisplay.DrawDebugInformation;
+var
+ Ticks: cardinal;
+begin
+ // Some White Background for information
+ glEnable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+ glColor4f(1, 1, 1, 0.5);
+ glBegin(GL_QUADS);
+ glVertex2f(690, 44);
+ glVertex2f(690, 0);
+ glVertex2f(800, 0);
+ glVertex2f(800, 44);
+ glEnd;
+ glDisable(GL_BLEND);
+
+ // set font specs
+ SetFontStyle(ftNormal);
+ SetFontSize(21);
+ SetFontItalic(false);
+ glColor4f(0, 0, 0, 1);
+
+ // calculate fps
+ Ticks := SDL_GetTicks();
+ if (Ticks >= NextFPSSwap) then
+ begin
+ LastFPS := FPSCounter * 4;
+ FPSCounter := 0;
+ NextFPSSwap := Ticks + 250;
+ end;
+
+ Inc(FPSCounter);
+
+ // draw text
+
+ // fps
+ SetFontPos(695, 0);
+ glPrint ('FPS: ' + InttoStr(LastFPS));
+
+ // rspeed
+ SetFontPos(695, 13);
+ glPrint ('RSpeed: ' + InttoStr(Round(1000 * TimeMid)));
+
+ // lasterror
+ SetFontPos(695, 26);
+ glColor4f(1, 0, 0, 1);
+ glPrint (OSD_LastError);
+
+ glColor4f(1, 1, 1, 1);
+end;
+
+end.
diff --git a/src/menu/UDrawTexture.pas b/src/menu/UDrawTexture.pas
new file mode 100644
index 00000000..bc136f11
--- /dev/null
+++ b/src/menu/UDrawTexture.pas
@@ -0,0 +1,139 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UDrawTexture;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UTexture;
+
+procedure DrawLine(X1, Y1, X2, Y2, ColR, ColG, ColB: real);
+procedure DrawQuad(X, Y, W, H, ColR, ColG, ColB: real);
+procedure DrawTexture(Texture: TTexture);
+
+implementation
+
+uses
+ gl;
+
+procedure DrawLine(X1, Y1, X2, Y2, ColR, ColG, ColB: real);
+begin
+ glColor3f(ColR, ColG, ColB);
+ glBegin(GL_LINES);
+ glVertex2f(x1, y1);
+ glVertex2f(x2, y2);
+ glEnd;
+end;
+
+procedure DrawQuad(X, Y, W, H, ColR, ColG, ColB: real);
+begin
+ glColor3f(ColR, ColG, ColB);
+ glBegin(GL_QUADS);
+ glVertex2f(x, y);
+ glVertex2f(x, y+h);
+ glVertex2f(x+w, y+h);
+ glVertex2f(x+w, y);
+ glEnd;
+end;
+
+procedure DrawTexture(Texture: TTexture);
+var
+ x1, x2, x3, x4: real;
+ y1, y2, y3, y4: real;
+ xt1, xt2, xt3, xt4: real;
+ yt1, yt2, yt3, yt4: real;
+begin
+ with Texture do
+ begin
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glDepthRange(0, 10);
+ glDepthFunc(GL_LEQUAL);
+// glDepthFunc(GL_GEQUAL);
+ glEnable(GL_DEPTH_TEST);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+// glBlendFunc(GL_SRC_COLOR, GL_ZERO);
+ glBindTexture(GL_TEXTURE_2D, TexNum);
+
+ x1 := x;
+ x2 := x;
+ x3 := x+w*scaleW;
+ x4 := x+w*scaleW;
+ y1 := y;
+ y2 := y+h*scaleH;
+ y3 := y+h*scaleH;
+ y4 := y;
+ if Rot <> 0 then
+ begin
+ xt1 := x1 - (x + w/2);
+ xt2 := x2 - (x + w/2);
+ xt3 := x3 - (x + w/2);
+ xt4 := x4 - (x + w/2);
+ yt1 := y1 - (y + h/2);
+ yt2 := y2 - (y + h/2);
+ yt3 := y3 - (y + h/2);
+ yt4 := y4 - (y + h/2);
+
+ x1 := (x + w/2) + xt1 * cos(Rot) - yt1 * sin(Rot);
+ x2 := (x + w/2) + xt2 * cos(Rot) - yt2 * sin(Rot);
+ x3 := (x + w/2) + xt3 * cos(Rot) - yt3 * sin(Rot);
+ x4 := (x + w/2) + xt4 * cos(Rot) - yt4 * sin(Rot);
+
+ y1 := (y + h/2) + yt1 * cos(Rot) + xt1 * sin(Rot);
+ y2 := (y + h/2) + yt2 * cos(Rot) + xt2 * sin(Rot);
+ y3 := (y + h/2) + yt3 * cos(Rot) + xt3 * sin(Rot);
+ y4 := (y + h/2) + yt4 * cos(Rot) + xt4 * sin(Rot);
+
+ end;
+
+{
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glVertex3f(x1, y1, z);
+ glTexCoord2f(0, TexH); glVertex3f(x2, y2, z);
+ glTexCoord2f(TexW, TexH); glVertex3f(x3, y3, z);
+ glTexCoord2f(TexW, 0); glVertex3f(x4, y4, z);
+ glEnd;
+}
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(TexX1*TexW, TexY1*TexH); glVertex3f(x1, y1, z);
+ glTexCoord2f(TexX1*TexW, TexY2*TexH); glVertex3f(x2, y2, z);
+ glTexCoord2f(TexX2*TexW, TexY2*TexH); glVertex3f(x3, y3, z);
+ glTexCoord2f(TexX2*TexW, TexY1*TexH); glVertex3f(x4, y4, z);
+ glEnd;
+ end;
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_TEXTURE_2D);
+end;
+
+end.
diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas
new file mode 100644
index 00000000..b011eddf
--- /dev/null
+++ b/src/menu/UMenu.pas
@@ -0,0 +1,1804 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenu;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ SysUtils,
+ Math,
+ gl,
+ SDL,
+ UPath,
+ UMenuBackground,
+ UMenuButton,
+ UMenuButtonCollection,
+ UMenuInteract,
+ UMenuSelectSlide,
+ UMenuStatic,
+ UMenuText,
+ UMusic,
+ UTexture,
+ UThemes;
+
+type
+{ Int16 = SmallInt;}
+
+ PMenu = ^TMenu;
+ TMenu = class
+ protected
+ Background: TMenuBackground;
+
+ Interactions: array of TInteract;
+ SelInteraction: integer;
+
+ ButtonPos: integer;
+ Button: array of TButton;
+
+ SelectsS: array of TSelectSlide;
+ ButtonCollection: array of TButtonCollection;
+ public
+ Text: array of TText;
+ Statics: array of TStatic;
+ mX: integer; // mouse X
+ mY: integer; // mouse Y
+
+ Fade: integer; // fade type
+ ShowFinish: boolean; // true if there is no fade
+ RightMbESC: boolean; // true to simulate ESC keypress when RMB is pressed
+
+ destructor Destroy; override;
+ constructor Create; overload; virtual;
+ //constructor Create(Back: string); overload; virtual; // Back is a JPG resource name for background
+ //constructor Create(Back: string; W, H: integer); overload; virtual; // W and H are the number of overlaps
+
+ // interaction
+ procedure AddInteraction(Typ, Num: integer);
+ procedure SetInteraction(Num: integer); virtual;
+ property Interaction: integer read SelInteraction write SetInteraction;
+
+ // procedure load bg, texts, statics and button collections from themebasic
+ procedure LoadFromTheme(const ThemeBasic: TThemeBasic);
+
+ procedure PrepareButtonCollections(const Collections: AThemeButtonCollection);
+ procedure AddButtonCollection(const ThemeCollection: TThemeButtonCollection; const Num: byte);
+
+ // background
+ procedure AddBackground(ThemedSettings: TThemeBackground);
+
+ // static
+ function AddStatic(ThemeStatic: TThemeStatic): integer; overload;
+ function AddStatic(X, Y, W, H: real; const TexName: IPath): integer; overload;
+ function AddStatic(X, Y, W, H: real; const TexName: IPath; Typ: TTextureType): integer; overload;
+ function AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const TexName: IPath; Typ: TTextureType): integer; overload;
+ function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const TexName: IPath; Typ: TTextureType): integer; overload;
+ function AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const TexName: IPath; Typ: TTextureType; Color: integer): integer; overload;
+ function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const TexName: IPath; Typ: TTextureType; Color: integer): integer; overload;
+ function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const TexName: IPath; Typ: TTextureType; Color: integer; Reflection: boolean; ReflectionSpacing: real): integer; overload;
+
+ // text
+ function AddText(ThemeText: TThemeText): integer; overload;
+ function AddText(X, Y: real; const Text_: UTF8String): integer; overload;
+ function AddText(X, Y: real; Style: integer; Size, ColR, ColG, ColB: real; const Text: UTF8String): integer; overload;
+ function AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; const Text_: UTF8String; Reflection_: boolean; ReflectionSpacing_: real; Z : real): integer; overload;
+
+ // button
+ procedure SetButtonLength(Length: cardinal); //Function that Set Length of Button Array in one Step instead of register new Memory for every Button
+ function AddButton(ThemeButton: TThemeButton): integer; overload;
+ function AddButton(X, Y, W, H: real; const TexName: IPath): integer; overload;
+ function AddButton(X, Y, W, H: real; const TexName: IPath; Typ: TTextureType; Reflection: boolean): integer; overload;
+ function AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; const TexName: IPath; Typ: TTextureType; Reflection: boolean; ReflectionSpacing, DeSelectReflectionSpacing: real): integer; overload;
+ procedure ClearButtons;
+ procedure AddButtonText(AddX, AddY: real; const AddText: UTF8String); overload;
+ procedure AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: UTF8String); overload;
+ procedure AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: UTF8String); overload;
+ procedure AddButtonText(CustomButton: TButton; AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: UTF8String); overload;
+
+ // select slide
+ function AddSelectSlide(ThemeSelectS: TThemeSelectSlide; var Data: integer; const Values: array of UTF8String): integer; overload;
+ function AddSelectSlide(X, Y, W, H, SkipX, SBGW, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt,
+ TColR, TColG, TColB, TInt, TDColR, TDColG, TDColB, TDInt,
+ SBGColR, SBGColG, SBGColB, SBGInt, SBGDColR, SBGDColG, SBGDColB, SBGDInt,
+ STColR, STColG, STColB, STInt, STDColR, STDColG, STDColB, STDInt: real;
+ const TexName: IPath; Typ: TTextureType; const SBGName: IPath; SBGTyp: TTextureType;
+ const Caption: UTF8String; var Data: integer): integer; overload;
+ procedure AddSelectSlideOption(const AddText: UTF8String); overload;
+ procedure AddSelectSlideOption(SelectNo: cardinal; const AddText: UTF8String); overload;
+ procedure UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; SelectNum: integer; const Values: array of UTF8String; var Data: integer);
+
+// function AddWidget(X, Y : UInt16; WidgetSrc : PSDL_Surface): Int16;
+// procedure ClearWidgets(MinNumber : Int16);
+ procedure FadeTo(Screen: PMenu); overload;
+ procedure FadeTo(Screen: PMenu; aSound: TAudioPlaybackStream); overload;
+ //popup hack
+ procedure CheckFadeTo(Screen: PMenu; Msg: UTF8String);
+
+ function DrawBG: boolean; virtual;
+ function DrawFG: boolean; virtual;
+ function Draw: boolean; virtual;
+ function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown : boolean): boolean; virtual;
+ function ParseMouse(MouseButton: integer; BtnDown: boolean; X, Y: integer): boolean; virtual;
+ function InRegion(X, Y: real; A: TMouseOverRect): boolean;
+ function InteractAt(X, Y: real): integer;
+ function CollectionAt(X, Y: real): integer;
+ procedure OnShow; virtual;
+ procedure OnShowFinish; virtual;
+ procedure OnHide; virtual;
+
+ procedure SetAnimationProgress(Progress: real); virtual;
+
+ function IsSelectable(Int: cardinal): boolean;
+
+ procedure InteractNext; virtual;
+ procedure InteractCustom(CustomSwitch: integer); virtual;
+ procedure InteractPrev; virtual;
+ procedure InteractInc; virtual;
+ procedure InteractDec; virtual;
+ procedure InteractNextRow; virtual; // this is for the options screen, so button down makes sense
+ procedure InteractPrevRow; virtual; // this is for the options screen, so button up makes sense
+ procedure AddBox(X, Y, W, H: real);
+ end;
+
+function RGBFloatToInt(R, G, B: double): cardinal;
+
+const
+ MENU_MDOWN = 8;
+ MENU_MUP = 0;
+
+ pmMove = 1;
+ pmClick = 2;
+ pmUnClick = 3;
+
+ iButton = 0; // interaction type
+ iText = 2;
+ iSelectS = 3;
+ iBCollectionChild = 5;
+
+// fBlack = 0; // fade type
+// fWhite = 1;
+
+implementation
+
+uses
+ UCommon,
+ UCovers,
+ UDisplay,
+ UDrawTexture,
+ UGraphic,
+ ULog,
+ UMain,
+ USkins,
+ UTime,
+ //Background types
+ UMenuBackgroundNone,
+ UMenuBackgroundColor,
+ UMenuBackgroundTexture,
+ UMenuBackgroundVideo,
+ UMenuBackgroundFade;
+
+destructor TMenu.Destroy;
+var
+ I: integer;
+begin
+ for I := 0 to High(Button) do
+ Button[I].Free;
+ for I := 0 to High(ButtonCollection) do
+ ButtonCollection[I].Free;
+ for I := 0 to High(SelectsS) do
+ SelectsS[I].Free;
+ for I := 0 to High(Text) do
+ Text[I].Free;
+ for I := 0 to High(Statics) do
+ Statics[I].Free;
+
+ Background.Free;
+
+ //Log.LogError('Unloaded Succesful: ' + ClassName);
+ inherited;
+end;
+
+constructor TMenu.Create;
+begin
+ inherited;
+
+ Fade := 0;//fWhite;
+
+ SetLength(Statics, 0);
+ SetLength(Button, 0);
+
+ //Set ButtonPos to Autoset Length
+ ButtonPos := -1;
+
+ Background := nil;
+
+ RightMbESC := true;
+end;
+{
+constructor TMenu.Create(Back: string);
+begin
+ inherited Create;
+
+ if Back <> '' then
+ begin
+// BackImg := Texture.GetTexture(true, Back, TEXTURE_TYPE_PLAIN, 0);
+ BackImg := Texture.GetTexture(Back, TEXTURE_TYPE_PLAIN, 0); // new theme system
+ BackImg.W := 800;//640;
+ BackImg.H := 600;//480;
+ BackW := 1;
+ BackH := 1;
+ end
+ else
+ BackImg.TexNum := 0;
+
+ //Set ButtonPos to Autoset Length
+ ButtonPos := -1;
+end;
+
+constructor TMenu.Create(Back: string; W, H: integer);
+begin
+ Create(Back);
+ BackImg.W := BackImg.W / W;
+ BackImg.H := BackImg.H / H;
+ BackW := W;
+ BackH := H;
+end; }
+
+function RGBFloatToInt(R, G, B: double): cardinal;
+begin
+ Result := (Trunc(255 * R) shl 16) or
+ (Trunc(255 * G) shl 8) or
+ Trunc(255 * B);
+end;
+
+procedure TMenu.AddInteraction(Typ, Num: integer);
+var
+ IntNum: integer;
+begin
+ IntNum := Length(Interactions);
+ SetLength(Interactions, IntNum+1);
+ Interactions[IntNum].Typ := Typ;
+ Interactions[IntNum].Num := Num;
+ Interaction := 0;
+end;
+
+procedure TMenu.SetInteraction(Num: integer);
+var
+ OldNum, OldTyp: integer;
+ NewNum, NewTyp: integer;
+begin
+ // set inactive
+ OldNum := Interactions[Interaction].Num;
+ OldTyp := Interactions[Interaction].Typ;
+
+ NewNum := Interactions[Num].Num;
+ NewTyp := Interactions[Num].Typ;
+
+ case OldTyp of
+ iButton: Button[OldNum].Selected := false;
+ iText: Text[OldNum].Selected := false;
+ iSelectS: SelectsS[OldNum].Selected := false;
+ //Button Collection Mod
+ iBCollectionChild:
+ begin
+ Button[OldNum].Selected := false;
+
+ // deselect collection if next button is not from collection
+ if (NewTyp <> iButton) or (Button[NewNum].Parent <> Button[OldNum].Parent) then
+ ButtonCollection[Button[OldNum].Parent-1].Selected := false;
+ end;
+ end;
+
+ // set active
+ SelInteraction := Num;
+ case NewTyp of
+ iButton: Button[NewNum].Selected := true;
+ iText: Text[NewNum].Selected := true;
+ iSelectS: SelectsS[NewNum].Selected := true;
+
+ //Button Collection Mod
+ iBCollectionChild:
+ begin
+ Button[NewNum].Selected := true;
+ ButtonCollection[Button[NewNum].Parent-1].Selected := true;
+ end;
+ end;
+end;
+
+//----------------------
+//LoadFromTheme - Load BG, Texts, Statics and
+//Button Collections from ThemeBasic
+//----------------------
+procedure TMenu.LoadFromTheme(const ThemeBasic: TThemeBasic);
+var
+ I: integer;
+begin
+ //Add Button Collections (Set Button CollectionsLength)
+ //Button Collections are Created when the first ChildButton is Created
+ PrepareButtonCollections(ThemeBasic.ButtonCollection);
+
+ //Add Background
+ AddBackground(ThemeBasic.Background);
+
+ //Add Statics and Texts
+ for I := 0 to High(ThemeBasic.Statics) do
+ AddStatic(ThemeBasic.Statics[I]);
+
+ for I := 0 to High(ThemeBasic.Text) do
+ AddText(ThemeBasic.Text[I]);
+end;
+
+procedure TMenu.AddBackground(ThemedSettings: TThemeBackground);
+ var
+ FileExt: string;
+
+ function IsInArray(const Piece: string; const A: array of string): boolean;
+ var
+ I: integer;
+ begin
+ Result := false;
+
+ for I := 0 to High(A) do
+ if (A[I] = Piece) then
+ begin
+ Result := true;
+ Exit;
+ end;
+ end;
+
+ function TryBGCreate(Typ: cMenuBackground): boolean;
+ begin
+ Result := true;
+
+ try
+ Background := Typ.Create(ThemedSettings);
+ except
+ on E: EMenuBackgroundError do
+ begin //Background failes to create
+ Freeandnil(Background);
+ Result := false;
+ end;
+ end;
+ end;
+
+begin
+ FreeAndNil(Background);
+
+ case ThemedSettings.BGType of
+ bgtAuto: begin //Automaticly choose one out of BGT_Texture, BGT_Video or BGT_Color
+
+ if (Length(ThemedSettings.Tex) > 0) then
+ begin
+
+ //At first some intelligent try to decide which BG to load
+ FileExt := LowerCase(Skin.GetTextureFileName(ThemedSettings.Tex).GetExtension.ToUTF8);
+
+ if IsInArray(FileExt, SUPPORTED_EXTS_BACKGROUNDTEXTURE) then
+ TryBGCreate(TMenuBackgroundTexture)
+ else if IsInArray(FileExt, SUPPORTED_EXTS_BACKGROUNDVIDEO) then
+ TryBGCreate(TMenuBackgroundVideo);
+
+ //If the intelligent method don't succeed
+ //do it by trial and error
+ if (Background = nil) then
+ begin
+ //Try Textured Bg
+ if not TryBGCreate(TMenuBackgroundTexture) then
+ TryBgCreate(TMenuBackgroundVideo); //Try Video BG
+
+ //Color is fallback if Background = nil
+ end;
+ end;
+ end;
+
+ bgtColor: begin
+ try
+ Background := TMenuBackgroundColor.Create(ThemedSettings);
+ except
+ on E: EMenuBackgroundError do
+ begin
+ Log.LogError(E.Message);
+ freeandnil(Background);
+ end;
+ end;
+ end;
+
+ bgtTexture: begin
+ try
+ Background := TMenuBackgroundTexture.Create(ThemedSettings);
+ except
+ on E: EMenuBackgroundError do
+ begin
+ Log.LogError(E.Message);
+ freeandnil(Background);
+ end;
+ end;
+ end;
+
+ bgtVideo: begin
+ try
+ Background := TMenuBackgroundVideo.Create(ThemedSettings);
+ except
+ on E: EMenuBackgroundError do
+ begin
+ Log.LogError(E.Message);
+ freeandnil(Background);
+ end;
+ end;
+ end;
+
+ bgtNone: begin
+ try
+ Background := TMenuBackgroundNone.Create(ThemedSettings);
+ except
+ on E: EMenuBackgroundError do
+ begin
+ Log.LogError(E.Message);
+ freeandnil(Background);
+ end;
+ end;
+ end;
+
+ bgtFade: begin
+ try
+ Background := TMenuBackgroundFade.Create(ThemedSettings);
+ except
+ on E: EMenuBackgroundError do
+ begin
+ Log.LogError(E.Message);
+ freeandnil(Background);
+ end;
+ end;
+ end;
+ end;
+
+ //Fallback to None Background or Colored Background
+ if (Background = nil) then
+ begin
+ if (ThemedSettings.BGType = bgtColor) then
+ Background := TMenuBackgroundNone.Create(ThemedSettings)
+ else
+ Background := TMenuBackgroundColor.Create(ThemedSettings)
+ end;
+end;
+
+//----------------------
+//PrepareButtonCollections:
+//Add Button Collections (Set Button CollectionsLength)
+//----------------------
+procedure TMenu.PrepareButtonCollections(const Collections: AThemeButtonCollection);
+var
+ I: integer;
+begin
+ SetLength(ButtonCollection, Length(Collections));
+ for I := 0 to High(ButtonCollection) do
+ AddButtonCollection(Collections[I], I);
+end;
+
+//----------------------
+//AddButtonCollection:
+//Create a Button Collection;
+//----------------------
+procedure TMenu.AddButtonCollection(const ThemeCollection: TThemeButtonCollection; const Num: byte);
+var
+ BT, BTLen: integer;
+ TempCol, TempDCol: cardinal;
+
+begin
+ if (Num > High(ButtonCollection)) then
+ exit;
+
+ TempCol := 0;
+
+ // colorize hack
+ if (ThemeCollection.Style.Typ = TEXTURE_TYPE_COLORIZED) then
+ begin
+ TempCol := RGBFloatToInt(ThemeCollection.Style.ColR, ThemeCollection.Style.ColG, ThemeCollection.Style.ColB);
+ TempDCol := RGBFloatToInt(ThemeCollection.Style.DColR, ThemeCollection.Style.DColG, ThemeCollection.Style.DColB);
+ // give encoded color to GetTexture()
+ ButtonCollection[Num] := TButtonCollection.Create(
+ Texture.GetTexture(Skin.GetTextureFileName(ThemeCollection.Style.Tex), TEXTURE_TYPE_COLORIZED, TempCol),
+ Texture.GetTexture(Skin.GetTextureFileName(ThemeCollection.Style.Tex), TEXTURE_TYPE_COLORIZED, TempDCol));
+ end
+ else
+ begin
+ ButtonCollection[Num] := TButtonCollection.Create(Texture.GetTexture(
+ Skin.GetTextureFileName(ThemeCollection.Style.Tex), ThemeCollection.Style.Typ));
+ end;
+
+ //Set Parent menu
+ ButtonCollection[Num].ScreenButton := @Self.Button;
+
+ //Set Attributes
+ ButtonCollection[Num].FirstChild := ThemeCollection.FirstChild;
+ ButtonCollection[Num].CountChilds := ThemeCollection.ChildCount;
+ ButtonCollection[Num].Parent := Num + 1;
+
+ //Set Style
+ ButtonCollection[Num].X := ThemeCollection.Style.X;
+ ButtonCollection[Num].Y := ThemeCollection.Style.Y;
+ ButtonCollection[Num].W := ThemeCollection.Style.W;
+ ButtonCollection[Num].H := ThemeCollection.Style.H;
+ if (ThemeCollection.Style.Typ <> TEXTURE_TYPE_COLORIZED) then
+ begin
+ ButtonCollection[Num].SelectColR := ThemeCollection.Style.ColR;
+ ButtonCollection[Num].SelectColG := ThemeCollection.Style.ColG;
+ ButtonCollection[Num].SelectColB := ThemeCollection.Style.ColB;
+ ButtonCollection[Num].DeselectColR := ThemeCollection.Style.DColR;
+ ButtonCollection[Num].DeselectColG := ThemeCollection.Style.DColG;
+ ButtonCollection[Num].DeselectColB := ThemeCollection.Style.DColB;
+ end;
+ ButtonCollection[Num].SelectInt := ThemeCollection.Style.Int;
+ ButtonCollection[Num].DeselectInt := ThemeCollection.Style.DInt;
+ ButtonCollection[Num].Texture.TexX1 := 0;
+ ButtonCollection[Num].Texture.TexY1 := 0;
+ ButtonCollection[Num].Texture.TexX2 := 1;
+ ButtonCollection[Num].Texture.TexY2 := 1;
+ ButtonCollection[Num].SetSelect(false);
+
+ ButtonCollection[Num].Reflection := ThemeCollection.Style.Reflection;
+ ButtonCollection[Num].Reflectionspacing := ThemeCollection.Style.ReflectionSpacing;
+ ButtonCollection[Num].DeSelectReflectionspacing := ThemeCollection.Style.DeSelectReflectionSpacing;
+
+ ButtonCollection[Num].Z := ThemeCollection.Style.Z;
+
+ //Some Things from ButtonFading
+ ButtonCollection[Num].SelectH := ThemeCollection.Style.SelectH;
+ ButtonCollection[Num].SelectW := ThemeCollection.Style.SelectW;
+
+ ButtonCollection[Num].Fade := ThemeCollection.Style.Fade;
+ ButtonCollection[Num].FadeText := ThemeCollection.Style.FadeText;
+ if (ThemeCollection.Style.Typ = TEXTURE_TYPE_COLORIZED) then
+ begin
+ ButtonCollection[Num].FadeTex := Texture.GetTexture(
+ Skin.GetTextureFileName(ThemeCollection.Style.FadeTex), TEXTURE_TYPE_COLORIZED, TempCol)
+ end
+ else
+ begin
+ ButtonCollection[Num].FadeTex := Texture.GetTexture(
+ Skin.GetTextureFileName(ThemeCollection.Style.FadeTex), ThemeCollection.Style.Typ);
+ end;
+ ButtonCollection[Num].FadeTexPos := ThemeCollection.Style.FadeTexPos;
+
+ BTLen := Length(ThemeCollection.Style.Text);
+ for BT := 0 to BTLen-1 do
+ begin
+ AddButtonText(ButtonCollection[Num], ThemeCollection.Style.Text[BT].X, ThemeCollection.Style.Text[BT].Y,
+ ThemeCollection.Style.Text[BT].ColR, ThemeCollection.Style.Text[BT].ColG, ThemeCollection.Style.Text[BT].ColB,
+ ThemeCollection.Style.Text[BT].Font, ThemeCollection.Style.Text[BT].Size, ThemeCollection.Style.Text[BT].Align,
+ ThemeCollection.Style.Text[BT].Text);
+ end;
+end;
+
+function TMenu.AddStatic(ThemeStatic: TThemeStatic): integer;
+begin
+ Result := AddStatic(ThemeStatic.X, ThemeStatic.Y, ThemeStatic.W, ThemeStatic.H, ThemeStatic.Z,
+ ThemeStatic.ColR, ThemeStatic.ColG, ThemeStatic.ColB,
+ ThemeStatic.TexX1, ThemeStatic.TexY1, ThemeStatic.TexX2, ThemeStatic.TexY2,
+ Skin.GetTextureFileName(ThemeStatic.Tex),
+ ThemeStatic.Typ, $FFFFFF, ThemeStatic.Reflection, ThemeStatic.Reflectionspacing);
+end;
+
+function TMenu.AddStatic(X, Y, W, H: real; const TexName: IPath): integer;
+begin
+ Result := AddStatic(X, Y, W, H, TexName, TEXTURE_TYPE_PLAIN);
+end;
+
+function TMenu.AddStatic(X, Y, W, H: real;
+ ColR, ColG, ColB: real;
+ const TexName: IPath;
+ Typ: TTextureType): integer;
+begin
+ Result := AddStatic(X, Y, W, H, ColR, ColG, ColB, TexName, Typ, $FFFFFF);
+end;
+
+function TMenu.AddStatic(X, Y, W, H, Z: real;
+ ColR, ColG, ColB: real;
+ const TexName: IPath;
+ Typ: TTextureType): integer;
+begin
+ Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, TexName, Typ, $FFFFFF);
+end;
+
+function TMenu.AddStatic(X, Y, W, H: real;
+ const TexName: IPath;
+ Typ: TTextureType): integer;
+var
+ StatNum: integer;
+begin
+ // adds static
+ StatNum := Length(Statics);
+ SetLength(Statics, StatNum + 1);
+ Statics[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, $FF00FF)); // new skin
+
+ // configures static
+ Statics[StatNum].Texture.X := X;
+ Statics[StatNum].Texture.Y := Y;
+ Statics[StatNum].Texture.W := W;
+ Statics[StatNum].Texture.H := H;
+ Statics[StatNum].Visible := true;
+ Result := StatNum;
+end;
+
+function TMenu.AddStatic(X, Y, W, H: real;
+ ColR, ColG, ColB: real;
+ const TexName: IPath;
+ Typ: TTextureType;
+ Color: integer): integer;
+begin
+ Result := AddStatic(X, Y, W, H, 0, ColR, ColG, ColB, TexName, Typ, Color);
+end;
+
+function TMenu.AddStatic(X, Y, W, H, Z: real;
+ ColR, ColG, ColB: real;
+ const TexName: IPath;
+ Typ: TTextureType;
+ Color: integer): integer;
+begin
+ Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, 0, 0, 1, 1, TexName, Typ, Color, false, 0);
+end;
+
+function TMenu.AddStatic(X, Y, W, H, Z: real;
+ ColR, ColG, ColB: real;
+ TexX1, TexY1, TexX2, TexY2: real;
+ const TexName: IPath;
+ Typ: TTextureType;
+ Color: integer;
+ Reflection: boolean;
+ ReflectionSpacing: real): integer;
+var
+ StatNum: integer;
+begin
+ // adds static
+ StatNum := Length(Statics);
+ SetLength(Statics, StatNum + 1);
+
+ // colorize hack
+ if (Typ = TEXTURE_TYPE_COLORIZED) then
+ begin
+ // give encoded color to GetTexture()
+ Statics[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB)));
+ end
+ else
+ begin
+ Statics[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, Color)); // new skin
+ end;
+
+ // configures static
+ Statics[StatNum].Texture.X := X;
+ Statics[StatNum].Texture.Y := Y;
+
+ //Set height and width via sprite size if omitted
+ if(H = 0) then
+ Statics[StatNum].Texture.H := Statics[StatNum].Texture.H
+ else
+ Statics[StatNum].Texture.H := H;
+
+ if(W = 0) then
+ Statics[StatNum].Texture.W := Statics[StatNum].Texture.W
+ else
+ Statics[StatNum].Texture.W := W;
+
+ Statics[StatNum].Texture.Z := Z;
+ if (Typ <> TEXTURE_TYPE_COLORIZED) then
+ begin
+ Statics[StatNum].Texture.ColR := ColR;
+ Statics[StatNum].Texture.ColG := ColG;
+ Statics[StatNum].Texture.ColB := ColB;
+ end;
+ Statics[StatNum].Texture.TexX1 := TexX1;
+ Statics[StatNum].Texture.TexY1 := TexY1;
+ Statics[StatNum].Texture.TexX2 := TexX2;
+ Statics[StatNum].Texture.TexY2 := TexY2;
+ Statics[StatNum].Texture.Alpha := 1;
+ Statics[StatNum].Visible := true;
+
+ //ReflectionMod
+ Statics[StatNum].Reflection := Reflection;
+ Statics[StatNum].ReflectionSpacing := ReflectionSpacing;
+
+ Result := StatNum;
+end;
+
+function TMenu.AddText(ThemeText: TThemeText): integer;
+begin
+ Result := AddText(ThemeText.X, ThemeText.Y, ThemeText.W, ThemeText.Font, ThemeText.Size,
+ ThemeText.ColR, ThemeText.ColG, ThemeText.ColB, ThemeText.Align, ThemeText.Text, ThemeText.Reflection, ThemeText.ReflectionSpacing, ThemeText.Z);
+end;
+
+function TMenu.AddText(X, Y: real; const Text_: UTF8String): integer;
+var
+ TextNum: integer;
+begin
+ // adds text
+ TextNum := Length(Text);
+ SetLength(Text, TextNum + 1);
+ Text[TextNum] := TText.Create(X, Y, Text_);
+ Result := TextNum;
+end;
+
+function TMenu.AddText(X, Y: real;
+ Style: integer;
+ Size, ColR, ColG, ColB: real;
+ const Text: UTF8String): integer;
+begin
+ Result := AddText(X, Y, 0, Style, Size, ColR, ColG, ColB, 0, Text, false, 0, 0);
+end;
+
+function TMenu.AddText(X, Y, W: real;
+ Style: integer;
+ Size, ColR, ColG, ColB: real;
+ Align: integer;
+ const Text_: UTF8String;
+ Reflection_: boolean;
+ ReflectionSpacing_: real;
+ Z : real): integer;
+var
+ TextNum: integer;
+begin
+ // adds text
+ TextNum := Length(Text);
+ SetLength(Text, TextNum + 1);
+ Text[TextNum] := TText.Create(X, Y, W, Style, Size, ColR, ColG, ColB, Align, Text_, Reflection_, ReflectionSpacing_, Z);
+ Result := TextNum;
+end;
+
+//Function that Set Length of Button boolean in one Step instead of register new Memory for every Button
+procedure TMenu.SetButtonLength(Length: cardinal);
+begin
+ if (ButtonPos = -1) and (Length > 0) then
+ begin
+ //Set Length of Button
+ SetLength(Button, Length);
+
+ //Set ButtonPos to start with 0
+ ButtonPos := 0;
+ end;
+end;
+
+// Method to add a button in our TMenu. It returns the assigned ButtonNumber
+function TMenu.AddButton(ThemeButton: TThemeButton): integer;
+var
+ BT: integer;
+ BTLen: integer;
+begin
+ Result := AddButton(ThemeButton.X, ThemeButton.Y, ThemeButton.W, ThemeButton.H,
+ ThemeButton.ColR, ThemeButton.ColG, ThemeButton.ColB, ThemeButton.Int,
+ ThemeButton.DColR, ThemeButton.DColG, ThemeButton.DColB, ThemeButton.DInt,
+ Skin.GetTextureFileName(ThemeButton.Tex), ThemeButton.Typ,
+ ThemeButton.Reflection, ThemeButton.Reflectionspacing, ThemeButton.DeSelectReflectionspacing);
+
+ Button[Result].Z := ThemeButton.Z;
+
+ //Button Visibility
+ Button[Result].Visible := ThemeButton.Visible;
+
+ //Some Things from ButtonFading
+ Button[Result].SelectH := ThemeButton.SelectH;
+ Button[Result].SelectW := ThemeButton.SelectW;
+
+ Button[Result].Fade := ThemeButton.Fade;
+ Button[Result].FadeText := ThemeButton.FadeText;
+ if (ThemeButton.Typ = TEXTURE_TYPE_COLORIZED) then
+ begin
+ Button[Result].FadeTex := Texture.GetTexture(
+ Skin.GetTextureFileName(ThemeButton.FadeTex), TEXTURE_TYPE_COLORIZED,
+ RGBFloatToInt(ThemeButton.ColR, ThemeButton.ColG, ThemeButton.ColB));
+ end
+ else
+ begin
+ Button[Result].FadeTex := Texture.GetTexture(
+ Skin.GetTextureFileName(ThemeButton.FadeTex), ThemeButton.Typ);
+ end;
+
+ Button[Result].FadeTexPos := ThemeButton.FadeTexPos;
+
+ BTLen := Length(ThemeButton.Text);
+ for BT := 0 to BTLen-1 do
+ begin
+ AddButtonText(ThemeButton.Text[BT].X, ThemeButton.Text[BT].Y,
+ ThemeButton.Text[BT].ColR, ThemeButton.Text[BT].ColG, ThemeButton.Text[BT].ColB,
+ ThemeButton.Text[BT].Font, ThemeButton.Text[BT].Size, ThemeButton.Text[BT].Align,
+ ThemeButton.Text[BT].Text);
+ end;
+
+ // bautton collection mod
+ if (ThemeButton.Parent <> 0) then
+ begin
+ // if collection exists then change interaction to child button
+ if (@ButtonCollection[ThemeButton.Parent-1] <> nil) then
+ begin
+ Interactions[High(Interactions)].Typ := iBCollectionChild;
+ Button[Result].Visible := false;
+
+ for BT := 0 to BTLen-1 do
+ Button[Result].Text[BT].Alpha := 0;
+
+ Button[Result].Parent := ThemeButton.Parent;
+ if (ButtonCollection[ThemeButton.Parent-1].Fade) then
+ Button[Result].Texture.Alpha := 0;
+ end;
+ end;
+end;
+
+function TMenu.AddButton(X, Y, W, H: real; const TexName: IPath): integer;
+begin
+ Result := AddButton(X, Y, W, H, TexName, TEXTURE_TYPE_PLAIN, false);
+end;
+
+function TMenu.AddButton(X, Y, W, H: real; const TexName: IPath; Typ: TTextureType; Reflection: boolean): integer;
+begin
+ Result := AddButton(X, Y, W, H, 1, 1, 1, 1, 1, 1, 1, 0.5, TexName, TEXTURE_TYPE_PLAIN, Reflection, 15, 15);
+end;
+
+function TMenu.AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real;
+ const TexName: IPath;
+ Typ: TTextureType;
+ Reflection: boolean;
+ ReflectionSpacing, DeSelectReflectionSpacing: real): integer;
+begin
+ // adds button
+ //SetLength is used once to reduce Memory usement
+ if (ButtonPos <> -1) then
+ begin
+ Result := ButtonPos;
+ Inc(ButtonPos)
+ end
+ else //Old Method -> Reserve new Memory for every Button
+ begin
+ Result := Length(Button);
+ SetLength(Button, Result + 1);
+ end;
+
+ // colorize hack
+ if (Typ = TEXTURE_TYPE_COLORIZED) then
+ begin
+ // give encoded color to GetTexture()
+ Button[Result] := TButton.Create(Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB)),
+ Texture.GetTexture(TexName, Typ, RGBFloatToInt(DColR, DColG, DColB)));
+ end
+ else
+ begin
+ Button[Result] := TButton.Create(Texture.GetTexture(TexName, Typ));
+ end;
+
+ // configures button
+ Button[Result].X := X;
+ Button[Result].Y := Y;
+ Button[Result].W := W;
+ Button[Result].H := H;
+ if (Typ <> TEXTURE_TYPE_COLORIZED) then
+ begin
+ Button[Result].SelectColR := ColR;
+ Button[Result].SelectColG := ColG;
+ Button[Result].SelectColB := ColB;
+ Button[Result].DeselectColR := DColR;
+ Button[Result].DeselectColG := DColG;
+ Button[Result].DeselectColB := DColB;
+ end;
+ Button[Result].SelectInt := Int;
+ Button[Result].DeselectInt := DInt;
+ Button[Result].Texture.TexX1 := 0;
+ Button[Result].Texture.TexY1 := 0;
+ Button[Result].Texture.TexX2 := 1;
+ Button[Result].Texture.TexY2 := 1;
+ Button[Result].SetSelect(false);
+
+ Button[Result].Reflection := Reflection;
+ Button[Result].Reflectionspacing := ReflectionSpacing;
+ Button[Result].DeSelectReflectionspacing := DeSelectReflectionSpacing;
+
+ // button collection mod
+ Button[Result].Parent := 0;
+
+ // adds interaction
+ AddInteraction(iButton, Result);
+ Interaction := 0;
+end;
+
+procedure TMenu.ClearButtons;
+begin
+ Setlength(Button, 0);
+end;
+
+// method to draw our tmenu and all his child buttons
+function TMenu.DrawBG: boolean;
+begin
+ Background.Draw;
+ Result := true;
+end;
+
+function TMenu.DrawFG: boolean;
+var
+ J: integer;
+begin
+ // We don't forget about newly implemented static for nice skin ...
+ for J := 0 to High(Statics) do
+ Statics[J].Draw;
+
+ // ... and slightly implemented menutext unit
+ for J := 0 to High(Text) do
+ Text[J].Draw;
+
+ // Draw all ButtonCollections
+ for J := 0 to High(ButtonCollection) do
+ ButtonCollection[J].Draw;
+
+ // Second, we draw all of our buttons
+ for J := 0 to High(Button) do
+ Button[J].Draw;
+
+ for J := 0 to High(SelectsS) do
+ SelectsS[J].Draw;
+
+ // Third, we draw all our widgets
+ // for J := 0 to Length(WidgetsSrc) - 1 do
+ // SDL_BlitSurface(WidgetsSrc[J], nil, ParentBackBuf, WidgetsRect[J]);
+ Result := true;
+end;
+
+function TMenu.Draw: boolean;
+begin
+ DrawBG;
+ DrawFG;
+ Result := true;
+end;
+
+{
+function TMenu.GetNextScreen(): PMenu;
+begin
+ Result := NextScreen;
+end;
+}
+
+{
+function TMenu.AddWidget(X, Y: UInt16; WidgetSrc: PSDL_Surface): Int16;
+var
+ WidgetNum: Int16;
+begin
+ if (Assigned(WidgetSrc)) then
+ begin
+ WidgetNum := Length(WidgetsSrc);
+
+ SetLength(WidgetsSrc, WidgetNum + 1);
+ SetLength(WidgetsRect, WidgetNum + 1);
+
+ WidgetsSrc[WidgetNum] := WidgetSrc;
+ WidgetsRect[WidgetNum] := new(PSDL_Rect);
+ WidgetsRect[WidgetNum]^.x := X;
+ WidgetsRect[WidgetNum]^.y := Y;
+ WidgetsRect[WidgetNum]^.w := WidgetSrc^.w;
+ WidgetsRect[WidgetNum]^.h := WidgetSrc^.h;
+
+ Result := WidgetNum;
+ end
+ else
+ Result := -1;
+end;
+}
+
+{
+procedure TMenu.ClearWidgets(MinNumber: Int16);
+var
+ J: Int16;
+begin
+ for J := MinNumber to (Length(WidgetsSrc) - 1) do
+ begin
+ SDL_FreeSurface(WidgetsSrc[J]);
+ dispose(WidgetsRect[J]);
+ end;
+
+ SetLength(WidgetsSrc, MinNumber);
+ SetLength(WidgetsRect, MinNumber);
+end;
+}
+
+function TMenu.IsSelectable(Int: cardinal): boolean;
+begin
+ Result := true;
+ case Interactions[Int].Typ of
+ //Button
+ iButton: Result := Button[Interactions[Int].Num].Visible and Button[Interactions[Int].Num].Selectable;
+
+ //Select Slide
+ iSelectS: Result := SelectsS[Interactions[Int].Num].Visible;
+
+ //ButtonCollection Child
+ iBCollectionChild:
+ Result := (ButtonCollection[Button[Interactions[Int].Num].Parent - 1].FirstChild - 1 = Int) and ((Interactions[Interaction].Typ <> iBCollectionChild) or (Button[Interactions[Interaction].Num].Parent <> Button[Interactions[Int].Num].Parent));
+ end;
+end;
+
+// implemented for the sake of usablility
+// [curser down] picks the button left to the actual atm
+// this behaviour doesn't make sense for two rows of buttons
+procedure TMenu.InteractPrevRow;
+var
+ Int: integer;
+begin
+// these two procedures just make sense for at least 5 buttons, because we
+// usually start a second row when there are more than 4 buttons
+ Int := Interaction;
+
+ Int := Int - ceil(Length(Interactions) / 2);
+
+ //Set Interaction
+ if ((Int < 0) or (Int > Length(Interactions) - 1)) then
+ Int := Interaction // invalid button, keep current one
+ else
+ Interaction := Int; // select row above
+end;
+
+procedure TMenu.InteractNextRow;
+var
+ Int: integer;
+begin
+ Int := Interaction;
+
+ Int := Int + ceil(Length(Interactions) / 2);
+
+ //Set Interaction
+ if ((Int < 0) or (Int > Length(Interactions) - 1)) then
+ Int := Interaction // invalid button, keep current one
+ else
+ Interaction := Int; // select row above
+end;
+
+procedure TMenu.InteractNext;
+var
+ Int: integer;
+begin
+ Int := Interaction;
+
+ // change interaction as long as it's needed
+ repeat
+ Int := (Int + 1) mod Length(Interactions);
+
+ //If no Interaction is Selectable Simply Select Next
+ if (Int = Interaction) then
+ Break;
+
+ until IsSelectable(Int);
+
+ //Set Interaction
+ Interaction := Int;
+end;
+
+procedure TMenu.InteractPrev;
+var
+ Int: integer;
+begin
+ Int := Interaction;
+
+ // change interaction as long as it's needed
+ repeat
+ Int := Int - 1;
+ if Int = -1 then
+ Int := High(Interactions);
+
+ //If no Interaction is Selectable Simply Select Next
+ if (Int = Interaction) then
+ Break;
+ until IsSelectable(Int);
+
+ //Set Interaction
+ Interaction := Int
+end;
+
+procedure TMenu.InteractCustom(CustomSwitch: integer);
+{ needed only for below
+var
+ Num: integer;
+ Typ: integer;
+ Again: boolean;
+}
+begin
+ //Code Commented atm, because it needs to be Rewritten
+ //it doesn't work with Button Collections
+ {then
+ begin
+ CustomSwitch:= CustomSwitch*(-1);
+ Again := true;
+ // change interaction as long as it's needed
+ while (Again = true) do
+ begin
+ Num := SelInteraction - CustomSwitch;
+ if Num = -1 then
+ Num := High(Interactions);
+ Interaction := Num;
+ Again := false; // reset, default to accept changing interaction
+
+ // checking newly interacted element
+ Num := Interactions[Interaction].Num;
+ Typ := Interactions[Interaction].Typ;
+ case Typ of
+ iButton:
+ begin
+ if Button[Num].Selectable = false then
+ Again := true;
+ end;
+ end; // case
+ end; // while
+ end
+ else if num>0 then
+ begin
+ Again := true;
+ // change interaction as long as it's needed
+ while (Again = true) do
+ begin
+ Num := (Interaction + CustomSwitch) Mod Length(Interactions);
+ Interaction := Num;
+ Again := false; // reset, default to accept changing interaction
+
+ // checking newly interacted element
+ Num := Interactions[Interaction].Num;
+ Typ := Interactions[Interaction].Typ;
+ case Typ of
+ iButton:
+ begin
+ if Button[Num].Selectable = false then
+ Again := true;
+ end;
+ end; // case
+ end; // while
+ end }
+end;
+
+procedure TMenu.FadeTo(Screen: PMenu);
+begin
+ Display.Fade := 0;
+ Display.NextScreen := Screen;
+end;
+
+procedure TMenu.FadeTo(Screen: PMenu; aSound: TAudioPlaybackStream);
+begin
+ FadeTo( Screen );
+ AudioPlayback.PlaySound( aSound );
+end;
+
+procedure OnSaveEncodingError(Value: boolean; Data: Pointer);
+begin
+ Display.CheckOK := Value;
+ if (Value) then
+ begin
+ //Hack to Finish Singscreen correct on Exit with Q Shortcut
+ if (Display.NextScreenWithCheck = nil) then
+ begin
+ if (Display.CurrentScreen = @ScreenSing) then
+ ScreenSing.Finish
+ {else if (Display.CurrentScreen = @ScreenSingModi) then
+ ScreenSingModi.Finish;}
+ end;
+ end
+ else
+ begin
+ Display.NextScreenWithCheck := nil;
+ end;
+end;
+
+//popup hack
+procedure TMenu.CheckFadeTo(Screen: PMenu; Msg: UTF8String);
+begin
+ Display.Fade := 0;
+ Display.NextScreenWithCheck := Screen;
+ Display.CheckOK := false;
+ ScreenPopupCheck.ShowPopup(msg, OnSaveEncodingError, nil, false);
+end;
+
+procedure TMenu.AddButtonText(AddX, AddY: real; const AddText: UTF8String);
+begin
+ AddButtonText(AddX, AddY, 1, 1, 1, AddText);
+end;
+
+procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: UTF8String);
+var
+ Il: integer;
+begin
+ with Button[High(Button)] do
+ begin
+ Il := Length(Text);
+ SetLength(Text, Il+1);
+ Text[Il] := TText.Create(X + AddX, Y + AddY, AddText);
+ Text[Il].ColR := ColR;
+ Text[Il].ColG := ColG;
+ Text[Il].ColB := ColB;
+ Text[Il].Int := 1;//0.5;
+ end;
+end;
+
+procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: UTF8String);
+var
+ Il: integer;
+begin
+ with Button[High(Button)] do
+ begin
+ Il := Length(Text);
+ SetLength(Text, Il+1);
+ Text[Il] := TText.Create(X + AddX, Y + AddY, AddText);
+ Text[Il].ColR := ColR;
+ Text[Il].ColG := ColG;
+ Text[Il].ColB := ColB;
+ Text[Il].Int := 1;//0.5;
+ Text[Il].Style := Font;
+ Text[Il].Size := Size;
+ Text[Il].Align := Align;
+ end;
+end;
+
+procedure TMenu.AddButtonText(CustomButton: TButton; AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: UTF8String);
+var
+ Il: integer;
+begin
+ with CustomButton do
+ begin
+ Il := Length(Text);
+ SetLength(Text, Il+1);
+ Text[Il] := TText.Create(X + AddX, Y + AddY, AddText);
+ Text[Il].ColR := ColR;
+ Text[Il].ColG := ColG;
+ Text[Il].ColB := ColB;
+ Text[Il].Int := 1;//0.5;
+ Text[Il].Style := Font;
+ Text[Il].Size := Size;
+ Text[Il].Align := Align;
+ end;
+end;
+
+function TMenu.AddSelectSlide(ThemeSelectS: TThemeSelectSlide; var Data: integer; const Values: array of UTF8String): integer;
+var
+ SO: integer;
+begin
+ Result := AddSelectSlide(ThemeSelectS.X, ThemeSelectS.Y, ThemeSelectS.W, ThemeSelectS.H, ThemeSelectS.SkipX, ThemeSelectS.SBGW,
+ ThemeSelectS.ColR, ThemeSelectS.ColG, ThemeSelectS.ColB, ThemeSelectS.Int,
+ ThemeSelectS.DColR, ThemeSelectS.DColG, ThemeSelectS.DColB, ThemeSelectS.DInt,
+ ThemeSelectS.TColR, ThemeSelectS.TColG, ThemeSelectS.TColB, ThemeSelectS.TInt,
+ ThemeSelectS.TDColR, ThemeSelectS.TDColG, ThemeSelectS.TDColB, ThemeSelectS.TDInt,
+ ThemeSelectS.SBGColR, ThemeSelectS.SBGColG, ThemeSelectS.SBGColB, ThemeSelectS.SBGInt,
+ ThemeSelectS.SBGDColR, ThemeSelectS.SBGDColG, ThemeSelectS.SBGDColB, ThemeSelectS.SBGDInt,
+ ThemeSelectS.STColR, ThemeSelectS.STColG, ThemeSelectS.STColB, ThemeSelectS.STInt,
+ ThemeSelectS.STDColR, ThemeSelectS.STDColG, ThemeSelectS.STDColB, ThemeSelectS.STDInt,
+ Skin.GetTextureFileName(ThemeSelectS.Tex), ThemeSelectS.Typ,
+ Skin.GetTextureFileName(ThemeSelectS.TexSBG), ThemeSelectS.TypSBG,
+ ThemeSelectS.Text, Data);
+ for SO := 0 to High(Values) do
+ AddSelectSlideOption(Values[SO]);
+
+ SelectsS[High(SelectsS)].Text.Size := ThemeSelectS.TextSize;
+
+ SelectsS[High(SelectsS)].Texture.Z := ThemeSelectS.Z;
+ SelectsS[High(SelectsS)].TextureSBG.Z := ThemeSelectS.Z;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowL.Z := ThemeSelectS.Z;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowR.Z := ThemeSelectS.Z;
+
+ SelectsS[High(SelectsS)].showArrows := ThemeSelectS.showArrows;
+ SelectsS[High(SelectsS)].oneItemOnly := ThemeSelectS.oneItemOnly;
+
+ //Generate Lines
+ SelectsS[High(SelectsS)].GenLines;
+
+ SelectsS[High(SelectsS)].SelectedOption := SelectsS[High(SelectsS)].SelectOptInt; // refresh
+end;
+
+function TMenu.AddSelectSlide(X, Y, W, H, SkipX, SBGW, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt,
+ TColR, TColG, TColB, TInt, TDColR, TDColG, TDColB, TDInt,
+ SBGColR, SBGColG, SBGColB, SBGInt, SBGDColR, SBGDColG, SBGDColB, SBGDInt,
+ STColR, STColG, STColB, STInt, STDColR, STDColG, STDColB, STDInt: real;
+ const TexName: IPath; Typ: TTextureType; const SBGName: IPath; SBGTyp: TTextureType;
+ const Caption: UTF8String; var Data: integer): integer;
+var
+ S: integer;
+ I: integer;
+begin
+ S := Length(SelectsS);
+ SetLength(SelectsS, S + 1);
+ SelectsS[S] := TSelectSlide.Create;
+
+ if (Typ = TEXTURE_TYPE_COLORIZED) then
+ begin
+ SelectsS[S].Colorized := true;
+ SelectsS[S].Texture := Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB));
+ SelectsS[S].DeselectTexture := Texture.GetTexture(TexName, Typ, RGBFloatToInt(DColR, DColG, DColB));
+ end
+ else
+ begin
+ SelectsS[S].Colorized := false;
+ SelectsS[S].Texture := Texture.GetTexture(TexName, Typ);
+
+ SelectsS[S].ColR := ColR;
+ SelectsS[S].ColG := ColG;
+ SelectsS[S].ColB := ColB;
+
+ SelectsS[S].DColR := DColR;
+ SelectsS[S].DColG := DColG;
+ SelectsS[S].DColB := DColB;
+ end;
+
+ SelectsS[S].Int := Int;
+ SelectsS[S].DInt := DInt;
+
+ SelectsS[S].X := X;
+ SelectsS[S].Y := Y;
+ SelectsS[S].W := W;
+ SelectsS[S].H := H;
+
+ if (SBGTyp = TEXTURE_TYPE_COLORIZED) then
+ begin
+ SelectsS[S].ColorizedSBG := true;
+ SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp, RGBFloatToInt(SBGColR, SBGColG, SBGColB));
+ SelectsS[S].DeselectTextureSBG := Texture.GetTexture(SBGName, SBGTyp, RGBFloatToInt(SBGDColR, SBGDColG, SBGDColB));
+ end
+ else
+ begin
+ SelectsS[S].ColorizedSBG := false;
+ SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp);
+
+ SelectsS[S].SBGColR := SBGColR;
+ SelectsS[S].SBGColG := SBGColG;
+ SelectsS[S].SBGColB := SBGColB;
+
+ SelectsS[S].SBGDColR := SBGDColR;
+ SelectsS[S].SBGDColG := SBGDColG;
+ SelectsS[S].SBGDColB := SBGDColB;
+ end;
+
+
+ SelectsS[S].SBGInt := SBGInt;
+ SelectsS[S].SBGDInt := SBGDInt;
+
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowL := Tex_SelectS_ArrowL;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowL.X := X + W + SkipX;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowL.Y := Y + (H - Tex_SelectS_ArrowL.H) / 2;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowL.W := Tex_SelectS_ArrowL.W;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowL.H := Tex_SelectS_ArrowL.H;
+
+
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowR := Tex_SelectS_ArrowR;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowR.X := X + W + SkipX + SBGW - Tex_SelectS_ArrowR.W;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowR.Y := Y + (H - Tex_SelectS_ArrowR.H) / 2;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowR.W := Tex_SelectS_ArrowR.W;
+ SelectsS[High(SelectsS)].Tex_SelectS_ArrowR.H := Tex_SelectS_ArrowR.H;
+
+ SelectsS[S].TextureSBG.X := X + W + SkipX;
+ SelectsS[S].TextureSBG.Y := Y;
+ SelectsS[S].SBGW := SBGW;
+ SelectsS[S].TextureSBG.H := H;
+
+ SelectsS[S].Text.X := X + 20;
+ SelectsS[S].Text.Y := Y + (SelectsS[S].TextureSBG.H / 2) - 15;
+ SelectsS[S].Text.Text := Caption;
+ SelectsS[S].Text.Size := 30;
+ SelectsS[S].Text.Visible := true;
+ SelectsS[S].TColR := TColR;
+ SelectsS[S].TColG := TColG;
+ SelectsS[S].TColB := TColB;
+ SelectsS[S].TInt := TInt;
+ SelectsS[S].TDColR := TDColR;
+ SelectsS[S].TDColG := TDColG;
+ SelectsS[S].TDColB := TDColB;
+ SelectsS[S].TDInt := TDInt;
+
+ SelectsS[S].STColR := STColR;
+ SelectsS[S].STColG := STColG;
+ SelectsS[S].STColB := STColB;
+ SelectsS[S].STInt := STInt;
+ SelectsS[S].STDColR := STDColR;
+ SelectsS[S].STDColG := STDColG;
+ SelectsS[S].STDColB := STDColB;
+ SelectsS[S].STDInt := STDInt;
+
+ // new
+ SelectsS[S].Texture.TexX1 := 0;
+ SelectsS[S].Texture.TexY1 := 0;
+ SelectsS[S].Texture.TexX2 := 1;
+ SelectsS[S].Texture.TexY2 := 1;
+ SelectsS[S].TextureSBG.TexX1 := 0;
+ SelectsS[S].TextureSBG.TexY1 := 0;
+ SelectsS[S].TextureSBG.TexX2 := 1;
+ SelectsS[S].TextureSBG.TexY2 := 1;
+
+ // Sets Data to copy the value of selectops to global value;
+ SelectsS[S].PData := @Data;
+ // Configures Select options
+ {//SelectsS[S].TextOpt[0].Text := IntToStr(I+1);
+ SelectsS[S].TextOpt[0].Size := 30;
+ SelectsS[S].TextOpt[0].Align := 1;
+
+ SelectsS[S].TextOpt[0].ColR := SelectsS[S].STDColR;
+ SelectsS[S].TextOpt[0].ColG := SelectsS[S].STDColG;
+ SelectsS[S].TextOpt[0].ColB := SelectsS[S].STDColB;
+ SelectsS[S].TextOpt[0].Int := SelectsS[S].STDInt;
+ SelectsS[S].TextOpt[0].Visible := true; }
+
+ // Sets default value of selectopt from Data;
+ SelectsS[S].SelectedOption := Data;
+
+ // Disables default selection
+ SelectsS[S].SetSelect(false);
+
+ {// Configures 3 select options
+ for I := 0 to 2 do
+ begin
+ SelectsS[S].TextOpt[I].X := SelectsS[S].TextureSBG.X + 20 + (50 + 20) + (150 - 20) * I;
+ SelectsS[S].TextOpt[I].Y := SelectsS[S].TextureSBG.Y + 20;
+ SelectsS[S].TextOpt[I].Text := IntToStr(I+1);
+ SelectsS[S].TextOpt[I].Size := 30;
+ SelectsS[S].TextOpt[I].Align := 1;
+
+ SelectsS[S].TextOpt[I].ColR := SelectsS[S].STDColR;
+ SelectsS[S].TextOpt[I].ColG := SelectsS[S].STDColG;
+ SelectsS[S].TextOpt[I].ColB := SelectsS[S].STDColB;
+ SelectsS[S].TextOpt[I].Int := SelectsS[S].STDInt;
+ SelectsS[S].TextOpt[I].Visible := true;
+ end;}
+
+ // adds interaction
+ AddInteraction(iSelectS, S);
+ Result := S;
+end;
+
+procedure TMenu.AddSelectSlideOption(const AddText: UTF8String);
+begin
+ AddSelectSlideOption(High(SelectsS), AddText);
+end;
+
+procedure TMenu.AddSelectSlideOption(SelectNo: cardinal; const AddText: UTF8String);
+var
+ SO: integer;
+begin
+ SO := Length(SelectsS[SelectNo].TextOptT);
+
+ SetLength(SelectsS[SelectNo].TextOptT, SO + 1);
+ SelectsS[SelectNo].TextOptT[SO] := AddText;
+{
+ SelectsS[S].SelectedOption := SelectsS[S].SelectOptInt; // refresh
+
+ if SO = Selects[S].PData^ then
+ Selects[S].SelectedOption := SO;
+}
+end;
+
+procedure TMenu.UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide;
+ SelectNum: integer; const Values: array of UTF8String; var Data: integer);
+var
+ SO: integer;
+begin
+ SetLength(SelectsS[SelectNum].TextOptT, 0);
+ for SO := 0 to High(Values) do
+ AddSelectSlideOption(SelectNum, Values[SO]);
+
+ SelectsS[SelectNum].GenLines;
+
+// SelectsS[SelectNum].SelectedOption := SelectsS[SelectNum].SelectOptInt; // refresh
+// SelectS[SelectNum].SetSelectOpt(Data);
+// SelectS[SelectNum].SelectedOption := 0;//Data;
+
+// Log.LogError(IntToStr(High(SelectsS[SelectNum].TextOptT)));
+// if 0 <= High(SelectsS[SelectNum].TextOptT) then
+
+ SelectsS[SelectNum].PData := @Data;
+ SelectsS[SelectNum].SelectedOption := Data;
+end;
+
+procedure TMenu.InteractInc;
+var
+ Num: integer;
+ Value: integer;
+begin
+ case Interactions[Interaction].Typ of
+ iSelectS: begin
+ Num := Interactions[Interaction].Num;
+ Value := SelectsS[Num].SelectedOption;
+// Value := (Value + 1) Mod (Length(SelectsS[Num].TextOptT));
+
+ // limit
+ Value := Value + 1;
+ if Value <= High(SelectsS[Num].TextOptT) then
+ SelectsS[Num].SelectedOption := Value;
+ end;
+ //Button Collection Mod
+ iBCollectionChild:
+ begin
+
+ //Select Next Button in Collection
+ for Num := 1 to High(Button) do
+ begin
+ Value := (Interaction + Num) Mod Length(Button);
+ if Value = 0 then
+ begin
+ InteractNext;
+ Break;
+ end;
+ if (Button[Value].Parent = Button[Interaction].Parent) then
+ begin
+ Interaction := Value;
+ Break;
+ end;
+ end;
+ end;
+ //interact Next if there is Nothing to Change
+ else InteractNext;
+ end;
+end;
+
+procedure TMenu.InteractDec;
+var
+ Num: integer;
+ Value: integer;
+begin
+ case Interactions[Interaction].Typ of
+ iSelectS: begin
+ Num := Interactions[Interaction].Num;
+ Value := SelectsS[Num].SelectedOption;
+ Value := Value - 1;
+// if Value = -1 then
+// Value := High(SelectsS[Num].TextOptT);
+
+ if Value >= 0 then
+ SelectsS[Num].SelectedOption := Value;
+ end;
+ //Button Collection Mod
+ iBCollectionChild:
+ begin
+ //Select Prev Button in Collection
+ for Num := High(Button) downto 1 do
+ begin
+ Value := (Interaction + Num) Mod Length(Button);
+ if Value = High(Button) then
+ begin
+ InteractPrev;
+ Break;
+ end;
+ if (Button[Value].Parent = Button[Interaction].Parent) then
+ begin
+ Interaction := Value;
+ Break;
+ end;
+ end;
+ end;
+ // interact prev if there is nothing to change
+ else
+ begin
+ InteractPrev;
+ // if buttoncollection with more than 1 entry then select last entry
+ if (Button[Interactions[Interaction].Num].Parent <> 0) and (ButtonCollection[Button[Interactions[Interaction].Num].Parent-1].CountChilds > 1) then
+ begin
+ //Select Last Child
+ for Num := High(Button) downto 1 do
+ begin
+ Value := (Interaction + Num) Mod Length(Button);
+ if (Button[Value].Parent = Button[Interaction].Parent) then
+ begin
+ Interaction := Value;
+ Break;
+ end;
+ end;
+ end;
+ end;
+ end;
+end;
+
+procedure TMenu.AddBox(X, Y, W, H: real);
+begin
+ AddStatic(X, Y, W, H, 0, 0, 0, Skin.GetTextureFileName('MainBar'), TEXTURE_TYPE_COLORIZED);
+ AddStatic(X+2, Y+2, W-4, H-4, 1, 1, 1, Skin.GetTextureFileName('MainBar'), TEXTURE_TYPE_COLORIZED);
+end;
+
+procedure TMenu.OnShow;
+begin
+ // FIXME: this needs some work. First, there should be a variable like
+ // VideoBackground so we can check whether a video-background is enabled or not.
+ // Second, a video should be stopped if the screen is hidden, but the Video.Stop()
+ // method is not implemented by now. This is necessary for theme-switching too.
+ // At the moment videos cannot be turned off without restarting USDX.
+
+ {// check if a background texture was found
+ if (BackImg.TexNum = 0) then
+ begin
+ // try to open an animated background
+ // Note: newer versions of ffmpeg are able to open images like jpeg
+ // so do not pass an image's filename to VideoPlayback.Open()
+ if fileexists( fFileName ) then
+ begin
+ if VideoPlayback.Open( fFileName ) then
+ begin
+ VideoBGTimer.SetTime(0);
+ VideoPlayback.Play;
+ end;
+ end;
+ end; }
+ if (Background = nil) then
+ AddBackground(DEFAULT_BACKGROUND);
+
+ Background.OnShow;
+end;
+
+procedure TMenu.OnShowFinish;
+begin
+ // nothing
+end;
+
+procedure TMenu.OnHide;
+begin
+ // nothing
+ Background.OnFinish;
+end;
+
+function TMenu.ParseInput(PressedKey: Cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean;
+begin
+ // nothing
+ Result := true;
+end;
+
+function TMenu.ParseMouse(MouseButton: integer; BtnDown: boolean; X, Y: integer): boolean;
+var
+ nBut: integer;
+ Action: TMouseClickAction;
+begin
+ //default mouse parsing: clicking generates return keypress,
+ // mousewheel selects in select slide
+ //override ParseMouse to customize
+ Result := true;
+
+ if RightMbESC and (MouseButton = SDL_BUTTON_RIGHT) and BtnDown then
+ begin
+ //if RightMbESC is set, send ESC keypress
+ Result:=ParseInput(SDLK_ESCAPE, 0, true);
+ end;
+
+ // transfer mousecords to the 800x600 raster we use to draw
+ X := Round((X / (ScreenW / Screens)) * RenderW);
+ if (X > RenderW) then
+ X := X - RenderW;
+ Y := Round((Y / ScreenH) * RenderH);
+
+ // allways go to next screen if we don't have any interactions
+ if Length(Interactions) = 0 then
+ begin
+ if (BtnDown) and (MouseButton = SDL_BUTTON_LEFT) then
+ Result := ParseInput(SDLK_RETURN, 0, true);
+ end
+ else
+ begin
+ nBut := InteractAt(X, Y);
+ if nBut >= 0 then
+ begin
+ //select on mouse-over
+ if nBut <> Interaction then
+ SetInteraction(nBut);
+
+ Action := maNone;
+
+ if (BtnDown) then
+ begin
+ if (MouseButton = SDL_BUTTON_LEFT) then
+ begin
+ //click button or SelectS
+ if (Interactions[nBut].Typ = iSelectS) then
+ Action := SelectsS[Interactions[nBut].Num].OnClick(X, Y)
+ else
+ Action := maReturn;
+ end
+ else if (MouseButton = SDL_BUTTON_WHEELDOWN) then
+ begin //forward on select slide with mousewheel
+ if (Interactions[nBut].Typ = iSelectS) then
+ Action := maRight;
+ end
+ else if (MouseButton = SDL_BUTTON_WHEELUP) then
+ begin //backward on select slide with mousewheel
+ if (Interactions[nBut].Typ = iSelectS) then
+ Action := maLeft;
+ end;
+ end;
+
+ // do the action we have to do ;)
+ case Action of
+ maReturn: Result := ParseInput(SDLK_RETURN, 0, true);
+ maLeft: Result := ParseInput(SDLK_LEFT, 0, true);
+ maRight: Result := ParseInput(SDLK_RIGHT, 0, true);
+ end;
+ end
+ else
+ begin
+ nBut := CollectionAt(X, Y);
+ if (nBut >= 0) and (not ButtonCollection[nBut].Selected) then
+ begin
+ // if over button collection, that is not already selected
+ // -> select first child but don't allow click
+ nBut := ButtonCollection[nBut].FirstChild - 1;
+ if nBut <> Interaction then
+ SetInteraction(nBut);
+ end;
+ end;
+ end;
+end;
+
+function TMenu.InRegion(X, Y: real; A: TMouseOverRect): boolean;
+begin
+ // check whether A contains X and Y
+ Result := (X >= A.X) and (X <= A.X + A.W) and (Y >= A.Y) and (Y <= A.Y + A.H);
+end;
+
+//takes x,y coordinates and returns the interaction number
+//of the control at this position
+function TMenu.InteractAt(X, Y: real): integer;
+var
+ i, nBut: integer;
+begin
+ Result := -1;
+ for i := Low(Interactions) to High(Interactions) do
+ begin
+ case Interactions[i].Typ of
+ iButton:
+ if InRegion(X, Y, Button[Interactions[i].Num].GetMouseOverArea) and
+ Button[Interactions[i].Num].Visible then
+ begin
+ Result:=i;
+ exit;
+ end;
+ iBCollectionChild:
+ if InRegion(X, Y, Button[Interactions[i].Num].GetMouseOverArea) then
+ begin
+ Result:=i;
+ exit;
+ end;
+ iSelectS:
+ if InRegion(X, Y, SelectSs[Interactions[i].Num].GetMouseOverArea) then
+ begin
+ Result:=i;
+ exit;
+ end;
+ end;
+ end;
+end;
+
+//takes x,y coordinates and returns the button collection id
+function TMenu.CollectionAt(X, Y: real): integer;
+var
+ i, nBut: integer;
+begin
+ Result := -1;
+ for i:= Low(ButtonCollection) to High(ButtonCollection) do
+ begin
+ if InRegion(X, Y, ButtonCollection[i].GetMouseOverArea) and
+ ButtonCollection[i].Visible then
+ begin
+ Result:=i;
+ exit;
+ end;
+ end;
+end;
+
+procedure TMenu.SetAnimationProgress(Progress: real);
+begin
+ // nothing
+end;
+
+end.
diff --git a/src/menu/UMenuBackground.pas b/src/menu/UMenuBackground.pas
new file mode 100644
index 00000000..0e2e63a6
--- /dev/null
+++ b/src/menu/UMenuBackground.pas
@@ -0,0 +1,83 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuBackground;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ SysUtils,
+ UThemes;
+
+//TMenuBackground - abstraction class for MenuBackgrounds
+//this is a class, not an interface because of the constructors
+//and destructors
+//--------
+
+type
+ EMenuBackgroundError = class(Exception);
+ TMenuBackground = class
+ constructor Create(const ThemedSettings: TThemeBackground); virtual;
+ procedure OnShow; virtual;
+ procedure Draw; virtual;
+ procedure OnFinish; virtual;
+ destructor Destroy; override;
+ end;
+ cMenuBackground = class of TMenuBackground;
+
+implementation
+
+constructor TMenuBackground.Create(const ThemedSettings: TThemeBackground);
+begin
+ inherited Create;
+end;
+
+destructor TMenuBackground.Destroy;
+begin
+ inherited;
+end;
+
+procedure TMenuBackground.OnShow;
+begin
+
+end;
+
+procedure TMenuBackground.OnFinish;
+begin
+
+end;
+
+procedure TMenuBackground.Draw;
+begin
+
+end;
+
+end.
diff --git a/src/menu/UMenuBackgroundColor.pas b/src/menu/UMenuBackgroundColor.pas
new file mode 100644
index 00000000..45b58c1e
--- /dev/null
+++ b/src/menu/UMenuBackgroundColor.pas
@@ -0,0 +1,73 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuBackgroundColor;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UThemes,
+ UMenuBackground;
+
+//TMenuBackgroundColor - Background Color
+//--------
+
+type
+ TMenuBackgroundColor = class (TMenuBackground)
+ private
+ Color: TRGB;
+ public
+ constructor Create(const ThemedSettings: TThemeBackground); override;
+ procedure Draw; override;
+ end;
+
+implementation
+uses
+ gl,
+ glext,
+ UGraphic;
+
+constructor TMenuBackgroundColor.Create(const ThemedSettings: TThemeBackground);
+begin
+ inherited;
+ Color := ThemedSettings.Color;
+end;
+
+procedure TMenuBackgroundColor.Draw;
+begin
+ if (ScreenAct = 1) then
+ begin //just clear once, even when using two screens
+ glClearColor(Color.R, Color.G, Color.B, 0);
+ glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
+ end;
+end;
+
+end. \ No newline at end of file
diff --git a/src/menu/UMenuBackgroundFade.pas b/src/menu/UMenuBackgroundFade.pas
new file mode 100644
index 00000000..6d877baa
--- /dev/null
+++ b/src/menu/UMenuBackgroundFade.pas
@@ -0,0 +1,176 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuBackgroundFade;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UThemes,
+ UTexture,
+ UMenuBackground,
+ UPath;
+
+//TMenuBackgroundFade - Background Fade In for Overlay screens
+//--------
+
+type
+ TMenuBackgroundFade = class (TMenuBackground)
+ private
+ Tex: TTexture;
+ Color: TRGB;
+ Alpha: real;
+
+ useTexture: boolean;
+
+ FadeTime: cardinal;
+ public
+ constructor Create(const ThemedSettings: TThemeBackground); override;
+ procedure OnShow; override;
+ procedure Draw; override;
+ destructor Destroy; override;
+ end;
+
+const
+ FADEINTIME = 1500; //Time the bg fades in
+
+implementation
+uses
+ sdl,
+ gl,
+ glext,
+ USkins,
+ UCommon,
+ UGraphic;
+
+constructor TMenuBackgroundFade.Create(const ThemedSettings: TThemeBackground);
+var
+ texFilename: IPath;
+begin
+ inherited;
+ FadeTime := 0;
+
+ Color := ThemedSettings.Color;
+ Alpha := ThemedSettings.Alpha;
+ if (Length(ThemedSettings.Tex) > 0) then
+ begin
+ texFilename := Skin.GetTextureFileName(ThemedSettings.Tex);
+ Tex := Texture.GetTexture(texFilename, TEXTURE_TYPE_PLAIN);
+
+ UseTexture := (Tex.TexNum <> 0);
+ end
+ else
+ UseTexture := false;
+
+ if (not UseTexture) then
+ FreeandNil(Tex);
+end;
+
+destructor TMenuBackgroundFade.Destroy;
+begin
+ //Why isn't there any Tex.free method?
+ {if UseTexture then
+ FreeandNil(Tex); }
+ inherited;
+end;
+
+procedure TMenuBackgroundFade.OnShow;
+begin
+ FadeTime := SDL_GetTicks;
+end;
+
+procedure TMenuBackgroundFade.Draw;
+var
+ Progress: real;
+begin
+ if FadeTime = 0 then
+ Progress := Alpha
+ else
+ Progress := Alpha * (SDL_GetTicks - FadeTime) / FADEINTIME;
+
+ if Progress > Alpha then
+ begin
+ FadeTime := 0;
+ Progress := Alpha;
+ end;
+
+ if (UseTexture) then
+ begin //Draw Texture to Screen
+ if (ScreenAct = 1) then //Clear just once when in dual screen mode
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glColorRGB(Color, Progress);
+ glBindTexture(GL_TEXTURE_2D, Tex.TexNum);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(Tex.TexX1*Tex.TexW, Tex.TexY1*Tex.TexH);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(Tex.TexX1*Tex.TexW, Tex.TexY2*Tex.TexH);
+ glVertex2f(0, 600);
+
+ glTexCoord2f(Tex.TexX2*Tex.TexW, Tex.TexY2*Tex.TexH);
+ glVertex2f(800, 600);
+
+ glTexCoord2f(Tex.TexX2*Tex.TexW, Tex.TexY1*Tex.TexH);
+ glVertex2f(800, 0);
+ glEnd;
+
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+ end
+ else
+ begin //Clear Screen w/ progress Alpha + Color
+ if (ScreenAct = 1) then //Clear just once when in dual screen mode
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ glDisable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glColorRGB(Color, Progress);
+
+ glBegin(GL_QUADS);
+ glVertex2f(0, 0);
+ glVertex2f(0, 600);
+ glVertex2f(800, 600);
+ glVertex2f(800, 0);
+ glEnd;
+
+ glDisable(GL_BLEND);
+ end;
+end;
+
+end.
diff --git a/src/menu/UMenuBackgroundNone.pas b/src/menu/UMenuBackgroundNone.pas
new file mode 100644
index 00000000..c64f3023
--- /dev/null
+++ b/src/menu/UMenuBackgroundNone.pas
@@ -0,0 +1,70 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuBackgroundNone;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UThemes,
+ UMenuBackground;
+
+//TMenuBackgroundNone - Just no Background (e.g. for Overlays)
+//--------
+
+type
+ TMenuBackgroundNone = class (TMenuBackground)
+ private
+
+ public
+ constructor Create(const ThemedSettings: TThemeBackground); override;
+ procedure Draw; override;
+ end;
+
+implementation
+uses
+ gl,
+ glext,
+ UGraphic;
+
+constructor TMenuBackgroundNone.Create(const ThemedSettings: TThemeBackground);
+begin
+ inherited;
+end;
+
+procedure TMenuBackgroundNone.Draw;
+begin
+ //Do just nothing in here!
+ If (ScreenAct = 1) then //Clear just once when in dual screen mode
+ glClear(GL_DEPTH_BUFFER_BIT);
+end;
+
+end. \ No newline at end of file
diff --git a/src/menu/UMenuBackgroundTexture.pas b/src/menu/UMenuBackgroundTexture.pas
new file mode 100644
index 00000000..f71637ff
--- /dev/null
+++ b/src/menu/UMenuBackgroundTexture.pas
@@ -0,0 +1,126 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuBackgroundTexture;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UThemes,
+ UTexture,
+ UMenuBackground,
+ UPath;
+
+//TMenuBackgroundColor - Background Color
+//--------
+
+type
+ TMenuBackgroundTexture = class (TMenuBackground)
+ private
+ Tex: TTexture;
+ Color: TRGB;
+ public
+ constructor Create(const ThemedSettings: TThemeBackground); override;
+ procedure Draw; override;
+ destructor Destroy; override;
+ end;
+
+const
+ SUPPORTED_EXTS_BACKGROUNDTEXTURE: array[0..13] of string = ('.png', '.bmp', '.jpg', '.jpeg', '.gif', '.pnm', '.ppm', '.pgm', '.pbm', '.xpm', '.lbm', '.pcx', '.tga', '.tiff');
+
+implementation
+uses
+ USkins,
+ UCommon,
+ SysUtils,
+ gl,
+ glext,
+ UGraphic;
+
+constructor TMenuBackgroundTexture.Create(const ThemedSettings: TThemeBackground);
+var
+ texFilename: IPath;
+begin
+ inherited;
+
+ if (Length(ThemedSettings.Tex) = 0) then
+ raise EMenuBackgroundError.Create('TMenuBackgroundTexture: No texture filename present');
+
+ Color := ThemedSettings.Color;
+
+ texFilename := Skin.GetTextureFileName(ThemedSettings.Tex);
+ Tex := Texture.GetTexture(texFilename, TEXTURE_TYPE_PLAIN);
+
+ if (Tex.TexNum = 0) then
+ begin
+ freeandnil(Tex);
+ raise EMenuBackgroundError.Create('TMenuBackgroundTexture: Can''t load texture');
+ end;
+end;
+
+destructor TMenuBackgroundTexture.Destroy;
+begin
+ //freeandnil(Tex); <- this causes an Access Violation o0
+ inherited;
+end;
+
+procedure TMenuBackgroundTexture.Draw;
+begin
+ If (ScreenAct = 1) then //Clear just once when in dual screen mode
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ glColorRGB(Color);
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glBindTexture(GL_TEXTURE_2D, Tex.TexNum);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(Tex.TexX1*Tex.TexW, Tex.TexY1*Tex.TexH);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(Tex.TexX1*Tex.TexW, Tex.TexY2*Tex.TexH);
+ glVertex2f(0, 600);
+
+ glTexCoord2f(Tex.TexX2*Tex.TexW, Tex.TexY2*Tex.TexH);
+ glVertex2f(800, 600);
+
+ glTexCoord2f(Tex.TexX2*Tex.TexW, Tex.TexY1*Tex.TexH);
+ glVertex2f(800, 0);
+ glEnd;
+
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+end;
+
+end.
diff --git a/src/menu/UMenuBackgroundVideo.pas b/src/menu/UMenuBackgroundVideo.pas
new file mode 100644
index 00000000..9a33e721
--- /dev/null
+++ b/src/menu/UMenuBackgroundVideo.pas
@@ -0,0 +1,211 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuBackgroundVideo;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UThemes,
+ UMenuBackground,
+ UMusic,
+ UVideo,
+ UPath;
+
+//TMenuBackgroundColor - Background Color
+//--------
+
+type
+ //DefaultBGVideoPlayback = TVideoPlayback_FFmpeg;
+
+{type
+ TBGVideoPool = class;
+
+ PBGVideoPoolItem = ^TBGVideoPoolItem;
+ TBGVideoPoolItem = record
+ Parent: TBGVideoPool;
+ VideoPlayback = IVideoPlayback;
+ ReferenceCounter: cardinal; //Number of Creations
+ end;
+
+ TBGVideo = class
+ private
+ myItem: PBGVideoPoolItem;
+ public
+ constructor Create(Item: PBGVideoPoolItem); override;
+
+ function GetVideoPlayback: IVideoPlayback;
+ procedure Draw;
+
+ destructor Destroy;
+ end;
+
+ TBGVideoPool = class
+ private
+ Items: PBGVideoPoolItem;
+ public
+ constructor Create;
+
+ function GetBGVideo(filename: IPath): TBGVideo;
+ procedure RemoveItem(
+ procedure FreeAllItems;
+
+ destructor Destroy;
+ end;
+
+type }
+ TMenuBackgroundVideo = class (TMenuBackground)
+ private
+ fFilename: IPath;
+ fBgVideo: IVideo;
+ public
+ constructor Create(const ThemedSettings: TThemeBackground); override;
+ procedure OnShow; override;
+ procedure Draw; override;
+ procedure OnFinish; override;
+ destructor Destroy; override;
+ end;
+
+{var
+ BGVideoPool: TBGVideoPool; }
+const
+ SUPPORTED_EXTS_BACKGROUNDVIDEO: array[0..6] of string = ('.avi', '.mov', '.divx', '.mpg', '.mp4', '.mpeg', '.m2v');
+
+implementation
+
+uses
+ gl,
+ glext,
+ SysUtils,
+ UTime,
+ USkins,
+ UCommon,
+ UGraphic;
+
+constructor TMenuBackgroundVideo.Create(const ThemedSettings: TThemeBackground);
+begin
+ inherited;
+ if (Length(ThemedSettings.Tex) = 0) then
+ raise EMenuBackgroundError.Create('TMenuBackgroundVideo: No video filename present');
+
+ fFileName := Skin.GetTextureFileName(ThemedSettings.Tex);
+ if (not fFilename.IsFile) then
+ raise EMenuBackgroundError.Create('TMenuBackgroundVideo: Can''t load background video: ' + fFilename.ToNative);
+end;
+
+destructor TMenuBackgroundVideo.Destroy;
+begin
+end;
+
+procedure TMenuBackgroundVideo.OnShow;
+begin
+ fBgVideo := VideoPlayback.Open(fFileName);
+ if (fBgVideo <> nil) then
+ begin
+ VideoBGTimer.SetTime(0);
+ VideoBGTimer.Start();
+ fBgVideo.Loop := true;
+ fBgVideo.Play;
+ end;
+end;
+
+procedure TMenuBackgroundVideo.OnFinish;
+begin
+ // unload video
+ fBgVideo := nil;
+end;
+
+procedure TMenuBackgroundVideo.Draw;
+begin
+ // clear just once when in dual screen mode
+ if (ScreenAct = 1) then
+ begin
+ glClear(GL_DEPTH_BUFFER_BIT);
+ // video failure -> draw blank background
+ if (fBgVideo = nil) then
+ glClear(GL_COLOR_BUFFER_BIT);
+ end;
+
+ if (fBgVideo <> nil) then
+ begin
+ fBgVideo.GetFrame(VideoBGTimer.GetTime());
+ fBgVideo.SetScreen(ScreenAct);
+ fBgVideo.Draw();
+ end;
+end;
+
+// Implementation of TBGVideo
+//--------
+{constructor TBGVideo.Create(Item: PBGVideoPoolItem);
+begin
+ myItem := PBGVideoPoolItem;
+ Inc(myItem.ReferenceCounter);
+end;
+
+destructor TBGVideo.Destroy;
+begin
+ Dec(myItem.ReferenceCounter);
+end;
+
+function TBGVideo.GetVideoPlayback: IVideoPlayback;
+begin
+
+end;
+
+procedure TBGVideo.Draw;
+begin
+
+end;
+
+// Implementation of TBGVideoPool
+//--------
+
+constructor TBGVideoPool.Create;
+begin
+
+end;
+
+destructor TBGVideoPool.Destroy;
+begin
+
+end;
+
+function TBGVideoPool.GetBGVideo(filename: IPath): TBGVideo;
+begin
+
+end;
+
+procedure TBGVideoPool.FreeAllItems;
+begin
+
+end; }
+
+end.
diff --git a/src/menu/UMenuButton.pas b/src/menu/UMenuButton.pas
new file mode 100644
index 00000000..868a86f3
--- /dev/null
+++ b/src/menu/UMenuButton.pas
@@ -0,0 +1,647 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuButton;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ TextGL,
+ UTexture,
+ gl,
+ UMenuText,
+ SDL,
+ UMenuInteract;
+
+type
+ CButton = class of TButton;
+
+ TButton = class
+ protected
+ SelectBool: boolean;
+
+ FadeProgress: real;
+ FadeLastTick: cardinal;
+
+ DeSelectW,
+ DeSelectH,
+ PosX,
+ PosY: real;
+
+
+ public
+ Text: array of TText;
+ Texture: TTexture; // Button Screen position and size
+ Texture2: TTexture; // second texture only used for fading full resolution covers
+
+ Colorized: boolean;
+ DeSelectTexture: TTexture; // texture for colorized hack
+
+ FadeTex: TTexture; //Texture for beautiful fading
+ FadeTexPos: byte; //Pos of the FadeTexture (0: Top, 1: Left, 2: Bottom, 3: Right)
+
+ DeselectType: integer; // not used yet
+ Visible: boolean;
+
+ Reflection: boolean;
+ Reflectionspacing,
+ DeSelectReflectionspacing: real;
+
+ Fade,
+ FadeText: boolean;
+
+ Selectable: boolean;
+
+ //Number of the Parent Collection, 0 if in no Collection
+ Parent: byte;
+
+ SelectColR,
+ SelectColG,
+ SelectColB,
+ SelectInt,
+ SelectTInt: real;
+ //Fade Mod
+ SelectW: real;
+ SelectH: real;
+
+ DeselectColR,
+ DeselectColG,
+ DeselectColB,
+ DeselectInt,
+ DeselectTInt: real;
+
+ procedure SetY(Value: real);
+ procedure SetX(Value: real);
+ procedure SetW(Value: real);
+ procedure SetH(Value: real);
+
+ procedure SetSelect(Value: boolean); virtual;
+ property X: real read PosX write SetX;
+ property Y: real read PosY write SetY;
+ property Z: real read Texture.z write Texture.z;
+ property W: real read DeSelectW write SetW;
+ property H: real read DeSelectH write SetH;
+ property Selected: boolean read SelectBool write SetSelect;
+
+ procedure Draw; virtual;
+
+ constructor Create(); overload;
+ constructor Create(Textura: TTexture); overload;
+ constructor Create(Textura, DSTexture: TTexture); overload;
+ destructor Destroy; override;
+
+ function GetMouseOverArea: TMouseOverRect;
+ end;
+
+implementation
+
+uses
+ SysUtils,
+ UDrawTexture;
+
+procedure TButton.SetX(Value: real);
+{var
+ dx: real;
+ T: integer; // text}
+begin
+ {dY := Value - Texture.y;
+
+ Texture.X := Value;
+
+ for T := 0 to High(Text) do
+ Text[T].X := Text[T].X + dY;}
+
+ PosX := Value;
+ if (FadeTex.TexNum = 0) then
+ Texture.X := Value;
+
+end;
+
+procedure TButton.SetY(Value: real);
+{var
+ dY: real;
+ T: integer; // text}
+begin
+ {dY := Value - PosY;
+
+
+ for T := 0 to High(Text) do
+ Text[T].Y := Text[T].Y + dY;}
+
+ PosY := Value;
+ if (FadeTex.TexNum = 0) then
+ Texture.y := Value;
+end;
+
+procedure TButton.SetW(Value: real);
+begin
+ if SelectW = DeSelectW then
+ SelectW := Value;
+
+ DeSelectW := Value;
+
+ if not Fade then
+ begin
+ if SelectBool then
+ Texture.W := SelectW
+ else
+ Texture.W := DeSelectW;
+ end;
+end;
+
+procedure TButton.SetH(Value: real);
+begin
+ if SelectH = DeSelectH then
+ SelectH := Value;
+
+ DeSelectH := Value;
+
+ if not Fade then
+ begin
+ if SelectBool then
+ Texture.H := SelectH
+ else
+ Texture.H := DeSelectH;
+ end;
+end;
+
+procedure TButton.SetSelect(Value : boolean);
+var
+ T: integer;
+begin
+ SelectBool := Value;
+
+ if (Value) then
+ begin
+ Texture.ColR := SelectColR;
+ Texture.ColG := SelectColG;
+ Texture.ColB := SelectColB;
+ Texture.Int := SelectInt;
+
+ Texture2.ColR := SelectColR;
+ Texture2.ColG := SelectColG;
+ Texture2.ColB := SelectColB;
+ Texture2.Int := SelectInt;
+
+ for T := 0 to High(Text) do
+ Text[T].Int := SelectTInt;
+
+ //Fade Mod
+ if Fade then
+ begin
+ if (FadeProgress <= 0) then
+ FadeProgress := 0.125;
+ end
+ else
+ begin
+ Texture.W := SelectW;
+ Texture.H := SelectH;
+ end;
+ end
+ else
+ begin
+ Texture.ColR := DeselectColR;
+ Texture.ColG := DeselectColG;
+ Texture.ColB := DeselectColB;
+ Texture.Int := DeselectInt;
+
+ Texture2.ColR := DeselectColR;
+ Texture2.ColG := DeselectColG;
+ Texture2.ColB := DeselectColB;
+ Texture2.Int := DeselectInt;
+
+ for T := 0 to High(Text) do
+ Text[T].Int := DeselectTInt;
+
+ //Fade Mod
+ if Fade then
+ begin
+ if (FadeProgress >= 1) then
+ FadeProgress := 0.875;
+ end
+ else
+ begin
+ Texture.W := DeSelectW;
+ Texture.H := DeSelectH;
+ end;
+ end;
+end;
+
+// ***** Public methods ****** //
+
+procedure TButton.Draw;
+var
+ T: integer;
+ Tick: cardinal;
+ Spacing: real;
+begin
+ if Visible then
+ begin
+ //Fade Mod
+ T:=0;
+ if Fade then
+ begin
+ if (FadeProgress < 1) and (FadeProgress > 0) then
+ begin
+ Tick := SDL_GetTicks() div 16;
+ if (Tick <> FadeLastTick) then
+ begin
+ FadeLastTick := Tick;
+
+ if SelectBool then
+ FadeProgress := FadeProgress + 0.125
+ else
+ FadeProgress := FadeProgress - 0.125;
+
+ if (FadeText) then
+ begin
+ for T := 0 to high(Text) do
+ begin
+ Text[T].MoveX := (SelectW - DeSelectW) * FadeProgress;
+ Text[T].MoveY := (SelectH - DeSelectH) * FadeProgress;
+ end;
+ end;
+
+ end;
+ end;
+
+ //Method without Fade Texture
+ if (FadeTex.TexNum = 0) then
+ begin
+ Texture.W := DeSelectW + (SelectW - DeSelectW) * FadeProgress;
+ Texture.H := DeSelectH + (SelectH - DeSelectH) * FadeProgress;
+ DeSelectTexture.W := Texture.W;
+ DeSelectTexture.H := Texture.H;
+ end
+ else //method with Fade Texture
+ begin
+ Texture.W := DeSelectW;
+ Texture.H := DeSelectH;
+ DeSelectTexture.W := Texture.W;
+ DeSelectTexture.H := Texture.H;
+
+ FadeTex.ColR := Texture.ColR;
+ FadeTex.ColG := Texture.ColG;
+ FadeTex.ColB := Texture.ColB;
+ FadeTex.Int := Texture.Int;
+
+ FadeTex.Z := Texture.Z;
+
+ FadeTex.Alpha := Texture.Alpha;
+ FadeTex.TexX1 := 0;
+ FadeTex.TexX2 := 1;
+ FadeTex.TexY1 := 0;
+ FadeTex.TexY2 := 1;
+
+ case FadeTexPos of
+ 0: //FadeTex on Top
+ begin
+ //Standard Texture
+ Texture.X := PosX;
+ Texture.Y := PosY + (SelectH - DeSelectH) * FadeProgress;
+ DeSelectTexture.X := Texture.X;
+ DeSelectTexture.Y := Texture.Y;
+ //Fade Tex
+ FadeTex.X := PosX;
+ FadeTex.Y := PosY;
+ FadeTex.W := Texture.W;
+ FadeTex.H := (SelectH - DeSelectH) * FadeProgress;
+ FadeTex.ScaleW := Texture.ScaleW;
+ //Some Hack that Fixes a little Space between both Textures
+ FadeTex.TexY2 := 0.9;
+ end;
+ 1: //FadeTex on Left
+ begin
+ //Standard Texture
+ Texture.X := PosX + (SelectW - DeSelectW) * FadeProgress;
+ Texture.Y := PosY;
+ DeSelectTexture.X := Texture.X;
+ DeSelectTexture.Y := Texture.Y;
+ //Fade Tex
+ FadeTex.X := PosX;
+ FadeTex.Y := PosY;
+ FadeTex.H := Texture.H;
+ FadeTex.W := (SelectW - DeSelectW) * FadeProgress;
+ FadeTex.ScaleH := Texture.ScaleH;
+ //Some Hack that Fixes a little Space between both Textures
+ FadeTex.TexX2 := 0.9;
+ end;
+ 2: //FadeTex on Bottom
+ begin
+ //Standard Texture
+ Texture.X := PosX;
+ Texture.Y := PosY;
+ DeSelectTexture.X := Texture.X;
+ DeSelectTexture.Y := Texture.Y;
+ //Fade Tex
+ FadeTex.X := PosX;
+ FadeTex.Y := PosY + (SelectH - DeSelectH) * FadeProgress;;
+ FadeTex.W := Texture.W;
+ FadeTex.H := (SelectH - DeSelectH) * FadeProgress;
+ FadeTex.ScaleW := Texture.ScaleW;
+ //Some Hack that Fixes a little Space between both Textures
+ FadeTex.TexY1 := 0.1;
+ end;
+ 3: //FadeTex on Right
+ begin
+ //Standard Texture
+ Texture.X := PosX;
+ Texture.Y := PosY;
+ DeSelectTexture.X := Texture.X;
+ DeSelectTexture.Y := Texture.Y;
+ //Fade Tex
+ FadeTex.X := PosX + (SelectW - DeSelectW) * FadeProgress;
+ FadeTex.Y := PosY;
+ FadeTex.H := Texture.H;
+ FadeTex.W := (SelectW - DeSelectW) * FadeProgress;
+ FadeTex.ScaleH := Texture.ScaleH;
+ //Some Hack that Fixes a little Space between both Textures
+ FadeTex.TexX1 := 0.1;
+ end;
+ end;
+ end;
+ end
+ else if (FadeText) then
+ begin
+ Text[T].MoveX := (SelectW - DeSelectW);
+ Text[T].MoveY := (SelectH - DeSelectH);
+ end;
+
+ if SelectBool or (FadeProgress > 0) or not Colorized then
+ DrawTexture(Texture)
+ else
+ begin
+ DeSelectTexture.X := Texture.X;
+ DeSelectTexture.Y := Texture.Y;
+ DeSelectTexture.H := Texture.H;
+ DeSelectTexture.W := Texture.W;
+ DrawTexture(DeSelectTexture);
+ end;
+
+ //Draw FadeTex
+ if (FadeTex.TexNum > 0) then
+ DrawTexture(FadeTex);
+
+ if Texture2.Alpha > 0 then
+ begin
+ Texture2.ScaleW := Texture.ScaleW;
+ Texture2.ScaleH := Texture.ScaleH;
+
+ Texture2.X := Texture.X;
+ Texture2.Y := Texture.Y;
+ Texture2.W := Texture.W;
+ Texture2.H := Texture.H;
+
+ Texture2.ColR := Texture.ColR;
+ Texture2.ColG := Texture.ColG;
+ Texture2.ColB := Texture.ColB;
+ Texture2.Int := Texture.Int;
+
+ Texture2.Z := Texture.Z;
+
+ DrawTexture(Texture2);
+ end;
+
+ //Reflection Mod
+ if (Reflection) then // Draw Reflections
+ begin
+ if (FadeProgress <> 0) and (FadeProgress <> 1) then
+ begin
+ Spacing := DeSelectReflectionspacing - (DeSelectReflectionspacing - Reflectionspacing) * FadeProgress;
+ end
+ else if SelectBool then
+ Spacing := Reflectionspacing
+ else
+ Spacing := DeSelectReflectionspacing;
+
+ if SelectBool or not Colorized then
+ with Texture do
+ begin
+ //Bind Tex and GL Attributes
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+
+ glDepthRange(0, 10);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBindTexture(GL_TEXTURE_2D, TexNum);
+
+ //Draw
+ glBegin(GL_QUADS);//Top Left
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
+ glTexCoord2f(TexX1*TexW, TexY2*TexH);
+ glVertex3f(x, y+h*scaleH+ Spacing, z);
+
+ //Bottom Left
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
+ glTexCoord2f(TexX1*TexW, TexY1+TexH*0.5);
+ glVertex3f(x, y+h*scaleH + h*scaleH/2 + Spacing, z);
+
+
+ //Bottom Right
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
+ glTexCoord2f(TexX2*TexW, TexY1+TexH*0.5);
+ glVertex3f(x+w*scaleW, y+h*scaleH + h*scaleH/2 + Spacing, z);
+
+ //Top Right
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
+ glTexCoord2f(TexX2*TexW, TexY2*TexH);
+ glVertex3f(x+w*scaleW, y+h*scaleH + Spacing, z);
+ glEnd;
+
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_BLEND);
+ end
+ else
+ with DeSelectTexture do
+ begin
+ //Bind Tex and GL Attributes
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+
+ glDepthRange(0, 10);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBindTexture(GL_TEXTURE_2D, TexNum);
+
+ //Draw
+ glBegin(GL_QUADS);//Top Left
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
+ glTexCoord2f(TexX1*TexW, TexY2*TexH);
+ glVertex3f(x, y+h*scaleH+ Spacing, z);
+
+ //Bottom Left
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
+ glTexCoord2f(TexX1*TexW, TexY1+TexH*0.5);
+ glVertex3f(x, y+h*scaleH + h*scaleH/2 + Spacing, z);
+
+ //Bottom Right
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
+ glTexCoord2f(TexX2*TexW, TexY1+TexH*0.5);
+ glVertex3f(x+w*scaleW, y+h*scaleH + h*scaleH/2 + Spacing, z);
+
+ //Top Right
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
+ glTexCoord2f(TexX2*TexW, TexY2*TexH);
+ glVertex3f(x+w*scaleW, y+h*scaleH + Spacing, z);
+ glEnd;
+
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_BLEND);
+ end;
+ end;
+
+ for T := 0 to High(Text) do
+ begin
+ Text[T].Draw;
+ end;
+ end;
+end;
+
+function TButton.GetMouseOverArea: TMouseOverRect;
+begin
+ if (FadeTex.TexNum = 0) then
+ begin
+ Result.X := Texture.X;
+ Result.Y := Texture.Y;
+ Result.W := Texture.W;
+ Result.H := Texture.H;
+ end
+ else
+ begin
+ case FadeTexPos of
+ 0: begin // fade tex on top
+ Result.X := Texture.X;
+ Result.Y := FadeTex.Y;
+ Result.W := Texture.W;
+ Result.H := FadeTex.H + Texture.H;
+ end;
+
+ 1: begin // fade tex on left side
+ Result.X := FadeTex.X;
+ Result.Y := Texture.Y;
+ Result.W := FadeTex.W + Texture.W;
+ Result.H := Texture.H;
+ end;
+
+ 2: begin // fade tex on bottom
+ Result.X := Texture.X;
+ Result.Y := Texture.Y;
+ Result.W := Texture.W;
+ Result.H := FadeTex.H + Texture.H;
+ end;
+
+ 3: begin // fade tex on right side
+ Result.X := Texture.X;
+ Result.Y := Texture.Y;
+ Result.W := FadeTex.W + Texture.W;
+ Result.H := Texture.H;
+ end;
+ end;
+ end;
+end;
+
+
+destructor TButton.Destroy;
+begin
+ inherited;
+end;
+
+constructor TButton.Create();
+begin
+ inherited Create;
+ // We initialize all to 0, nil or false
+ Visible := true;
+ SelectBool := false;
+ DeselectType := 0;
+ Selectable := true;
+ Reflection := false;
+ Colorized := false;
+
+ SelectColR := 1;
+ SelectColG := 1;
+ SelectColB := 1;
+ SelectInt := 1;
+ SelectTInt := 1;
+
+ DeselectColR := 1;
+ DeselectColG := 1;
+ DeselectColB := 1;
+ DeselectInt := 0.5;
+ DeselectTInt := 1;
+
+ Fade := false;
+ FadeTex.TexNum := 0;
+ FadeProgress := 0;
+ FadeText := false;
+ SelectW := DeSelectW;
+ SelectH := DeSelectH;
+
+ PosX := 0;
+ PosY := 0;
+
+ Parent := 0;
+end;
+
+constructor TButton.Create(Textura: TTexture);
+begin
+ Create();
+ Texture := Textura;
+ DeSelectTexture := Textura;
+ Texture.ColR := 0;
+ Texture.ColG := 0.5;
+ Texture.ColB := 0;
+ Texture.Int := 1;
+ Colorized := false;
+end;
+
+// Button has the texture-type "colorized"
+// Two textures are generated, one with Col the other one with DCol
+// Check UMenu.pas line 680 to see the call ( AddButton() )
+constructor TButton.Create(Textura, DSTexture: TTexture);
+begin
+ Create();
+ Texture := Textura;
+ DeSelectTexture := DSTexture;
+ Texture.ColR := 1;
+ Texture.ColG := 1;
+ Texture.ColB := 1;
+ Texture.Int := 1;
+ Colorized := true;
+end;
+
+end.
diff --git a/src/menu/UMenuButtonCollection.pas b/src/menu/UMenuButtonCollection.pas
new file mode 100644
index 00000000..8b7a1c3f
--- /dev/null
+++ b/src/menu/UMenuButtonCollection.pas
@@ -0,0 +1,101 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuButtonCollection;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UMenuButton;
+
+type
+ //----------------
+ //TButtonCollection
+ //No Extra Attributes or Functions ATM
+ //----------------
+ AButton = array of TButton;
+ PAButton = ^AButton;
+ TButtonCollection = class(TButton)
+ //num of the First Button, that can be Selected
+ FirstChild: byte;
+ CountChilds: byte;
+
+ ScreenButton: PAButton;
+
+ procedure SetSelect(Value : boolean); override;
+ procedure Draw; override;
+ end;
+
+implementation
+
+procedure TButtonCollection.SetSelect(Value : boolean);
+var
+ Index: integer;
+begin
+ inherited;
+
+ //Set Visible for Every Button that is a Child of this ButtonCollection
+ if (not Fade) then
+ for Index := 0 to High(ScreenButton^) do
+ if (ScreenButton^[Index].Parent = Parent) then
+ ScreenButton^[Index].Visible := Value;
+end;
+
+procedure TButtonCollection.Draw;
+var
+ I, J: integer;
+begin
+ inherited;
+ //If fading is activated, Fade Child Buttons
+ if (Fade) then
+ begin
+ for I := 0 to High(ScreenButton^) do
+ if (ScreenButton^[I].Parent = Parent) then
+ begin
+ if (FadeProgress < 0.5) then
+ begin
+ ScreenButton^[I].Visible := SelectBool;
+
+ for J := 0 to High(ScreenButton^[I].Text) do
+ ScreenButton^[I].Text[J].Visible := SelectBool;
+ end
+ else
+ begin
+ ScreenButton^[I].Texture.Alpha := (FadeProgress-0.666)*3;
+
+ for J := 0 to High(ScreenButton^[I].Text) do
+ ScreenButton^[I].Text[J].Alpha := (FadeProgress-0.666)*3;
+ end;
+ end;
+ end;
+end;
+
+end.
diff --git a/src/menu/UMenuEqualizer.pas b/src/menu/UMenuEqualizer.pas
new file mode 100644
index 00000000..8f57e44a
--- /dev/null
+++ b/src/menu/UMenuEqualizer.pas
@@ -0,0 +1,320 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuEqualizer;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UMusic,
+ UThemes;
+
+type
+ //----------------
+ //Tms_Equalizer
+ //Class displaying an equalizer (Songscreen)
+ //----------------
+ Tms_Equalizer = class(TObject)
+ private
+ FFTData: TFFTData; // moved here to avoid stack overflows
+ BandData: array of byte;
+ RefreshTime: cardinal;
+
+ Source: IAudioPlayback;
+
+ procedure Analyse;
+ public
+ X: integer;
+ Y: integer;
+ Z: real;
+
+ W: integer;
+ H: integer;
+ Space: integer;
+
+ Visible: boolean;
+ Alpha: real;
+ Color: TRGB;
+
+ Direction: boolean;
+ BandLength: integer;
+
+ Reflection: boolean;
+ Reflectionspacing: real;
+
+
+ constructor Create(Source: IAudioPlayback; mySkin: TThemeEqualizer);
+
+ procedure Draw;
+ procedure SetBands(Value: byte);
+ function GetBands: byte;
+ property Bands: byte read GetBands write SetBands;
+ procedure SetSource(newSource: IAudioPlayback);
+ end;
+
+implementation
+uses
+ math,
+ SDL,
+ gl,
+ glext;
+
+constructor Tms_Equalizer.Create(Source: IAudioPlayback; mySkin: TThemeEqualizer);
+var
+ I: integer;
+begin
+ if (Source <> nil) then
+ begin
+ X := mySkin.X;
+ Y := mySkin.Y;
+ W := mySkin.W;
+ H := mySkin.H;
+ Z := mySkin.Z;
+
+ Space := mySkin.Space;
+
+ Visible := mySkin.Visible;
+ Alpha := mySkin.Alpha;
+ Color.R := mySkin.ColR;
+ Color.G := mySkin.ColG;
+ Color.B := mySkin.ColB;
+
+ Direction := mySkin.Direction;
+ Bands := mySkin.Bands;
+ BandLength := mySkin.Length;
+
+ Reflection := mySkin.Reflection;
+ Reflectionspacing := mySkin.Reflectionspacing;
+
+ Self.Source := Source;
+
+
+ //Check if Visible
+ if (Bands <= 0) or
+ (BandLength <= 0) or
+ (W <= 0) or
+ (H <= 0) or
+ (Alpha <= 0) then
+ Visible := false;
+
+ //ClearArray
+ for I := low(BandData) to high(BandData) do
+ BandData[I] := 3;
+ end
+ else
+ Visible := false;
+end;
+
+//--------
+// evaluate FFT-Data
+//--------
+procedure Tms_Equalizer.Analyse;
+var
+ I: integer;
+ ChansPerBand: byte; // channels per band
+ MaxChannel: integer;
+ Pos: real;
+ CurBand: integer;
+begin
+ Source.GetFFTData(FFTData);
+
+ Pos := 0;
+ // use only the first approx. 92 of 256 FFT-channels (approx. up to 8kHz
+ ChansPerBand := ceil(92 / Bands); // How much channels are used for one Band
+ MaxChannel := ChansPerBand * Bands - 1;
+
+ // Change Lengths
+ for i := 0 to MaxChannel do
+ begin
+ // Gain higher freq. data so that the bars are visible
+ if i > 35 then
+ FFTData[i] := FFTData[i] * 8
+ else if i > 11 then
+ FFTData[i] := FFTData[i] * 4.5
+ else
+ FFTData[i] := FFTData[i] * 1.1;
+
+ // clamp data
+ if (FFTData[i] > 1) then
+ FFTData[i] := 1;
+
+ // Get max. pos
+ if (FFTData[i] * BandLength > Pos) then
+ Pos := FFTData[i] * BandLength;
+
+ // Check if this is the last channel in the band
+ if ((i+1) mod ChansPerBand = 0) then
+ begin
+ CurBand := i div ChansPerBand;
+
+ // Smooth delay if new equalizer is lower than the old one
+ if ((BandData[CurBand] > Pos) and (BandData[CurBand] > 1)) then
+ BandData[CurBand] := BandData[CurBand] - 1
+ else
+ BandData[CurBand] := Round(Pos);
+
+ Pos := 0;
+ end;
+ end;
+end;
+
+//--------
+// Draw SpectrumAnalyser, Call Analyse
+//--------
+procedure Tms_Equalizer.Draw;
+var
+ CurTime: cardinal;
+ PosX, PosY: real;
+ I, J: integer;
+ Diff: real;
+
+ function GetAlpha(Diff: single): single;
+ begin
+ if Direction then
+ Result := (Alpha * 0.6) * (0.5 - Diff/(BandLength * (H + Space)))
+ else
+ Result := (Alpha * 0.6) * (0.5 - Diff/(Bands * (H + Space)));
+ end;
+
+begin
+ if (Visible) and not (AudioPlayback.Finished) then
+ begin
+ //Call Analyse if necessary
+ CurTime := SDL_GetTicks();
+ if (CurTime > RefreshTime) then
+ begin
+ Analyse;
+
+ RefreshTime := CurTime + 44;
+ end;
+
+ //Draw Equalizer Bands
+ // Setup OpenGL
+ glColorRGB(Color, Alpha);
+ glDisable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+
+ // Set position of the first equalizer bar
+ PosY := Y;
+ PosX := X;
+
+ // Draw bars for each band
+ for I := 0 to High(BandData) do
+ begin
+ // Reset to lower or left position depending on the drawing-direction
+ if Direction then // Vertical bars
+ // FIXME: Is Y the upper or lower coordinate?
+ PosY := Y //+ (H + Space) * BandLength
+ else // Horizontal bars
+ PosX := X;
+
+ // Draw the bar as a stack of blocks
+ for J := 1 to BandData[I] do
+ begin
+ // Draw block
+ glBegin(GL_QUADS);
+ glVertex3f(PosX, PosY, Z);
+ glVertex3f(PosX, PosY+H, Z);
+ glVertex3f(PosX+W, PosY+H, Z);
+ glVertex3f(PosX+W, PosY, Z);
+ glEnd;
+
+ if (Reflection) and (J <= BandLength div 2) then
+ begin
+ Diff := (Y-PosY) + H;
+
+ //Draw Reflection
+ if Direction then
+ begin
+ glBegin(GL_QUADS);
+ glColorRGB(Color, GetAlpha(Diff));
+ glVertex3f(PosX, Diff + Y + ReflectionSpacing, Z);
+
+ //bottom v
+ glColorRGB(Color, GetAlpha(Diff + H));
+ glVertex3f(PosX, Diff + Y+H + ReflectionSpacing, Z);
+ glVertex3f(PosX+W, Diff + Y+H + ReflectionSpacing, Z);
+
+ glColorRGB(Color, GetAlpha(Diff));
+ glVertex3f(PosX+W, Diff + Y + ReflectionSpacing, Z);
+ glEnd;
+ end
+ else
+ begin
+ glBegin(GL_QUADS);
+ glColorRGB(Color, GetAlpha(Diff));
+ glVertex3f(PosX, Diff + Y + (H + Space)*Bands + ReflectionSpacing, Z);
+ glVertex3f(PosX, Diff + Y+H + (H + Space)*Bands + ReflectionSpacing, Z);
+ glVertex3f(PosX+W, Diff + Y+H + (H + Space)*Bands + ReflectionSpacing, Z);
+ glVertex3f(PosX+W, Diff + Y + (H + Space)*Bands + ReflectionSpacing, Z);
+ glColorRGB(Color, GetAlpha(Diff + H));
+ glEnd;
+ end;
+
+ glColorRGB(Color, Alpha);
+ end;
+
+
+ // Calc position of the bar's next block
+ if Direction then // Vertical bars
+ PosY := PosY - H - Space
+ else // Horizontal bars
+ PosX := PosX + W + Space;
+ end;
+
+ // Calc position of the next bar
+ if Direction then // Vertical bars
+ PosX := PosX + W + Space
+ else // Horizontal bars
+ PosY := PosY + H + Space;
+ end;
+
+
+ end;
+end;
+
+procedure Tms_Equalizer.SetBands(Value: byte);
+begin
+ SetLength(BandData, Value);
+end;
+
+function Tms_Equalizer.GetBands: byte;
+begin
+ Result := Length(BandData);
+end;
+
+procedure Tms_Equalizer.SetSource(newSource: IAudioPlayback);
+begin
+ if (newSource <> nil) then
+ Source := newSource;
+end;
+
+end. \ No newline at end of file
diff --git a/src/menu/UMenuInteract.pas b/src/menu/UMenuInteract.pas
new file mode 100644
index 00000000..7cb92025
--- /dev/null
+++ b/src/menu/UMenuInteract.pas
@@ -0,0 +1,54 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuInteract;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+type
+ TInteract = record // for moving thru menu
+ Typ: integer; // 0 - button, 1 - select, 2 - Text, 3 - Select SLide, 5 - ButtonCollection Child
+ Num: integer; // number of this item in proper list like buttons, selects
+ end;
+
+ { to handle the area where the mouse is over a control }
+ TMouseOverRect = record
+ X, Y: Real;
+ W, H: Real;
+ end;
+
+ { to handle the on click action }
+ TMouseClickAction = (maNone, maReturn, maLeft, maRight);
+
+implementation
+
+end.
+ \ No newline at end of file
diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas
new file mode 100644
index 00000000..09ce3b9f
--- /dev/null
+++ b/src/menu/UMenuSelectSlide.pas
@@ -0,0 +1,541 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuSelectSlide;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ gl,
+ TextGL,
+ UMenuText,
+ UTexture,
+ UMenuInteract;
+
+type
+ PSelectSlide = ^TSelectSlide;
+ TSelectSlide = class
+ private
+ SelectBool: boolean;
+
+ function AdjustOptionTextToFit(OptText: UTF8String): UTF8String;
+ public
+ // objects
+ Text: TText; // Main text describing option
+ TextOpt: array of TText; // 3 texts in the position of possible options
+ TextOptT: array of UTF8String; // array of names for possible options
+
+ Texture: TTexture; // Select Texture
+ TextureSBG: TTexture; // Background Selections Texture
+
+ Colorized: boolean;
+ DeSelectTexture: TTexture; // texture for colorized hack
+ ColorizedSBG: boolean;
+ DeSelectTextureSBG: TTexture; // texture for colorized hack Select BG
+
+ Tex_SelectS_ArrowL: TTexture; // Texture for left arrow
+ Tex_SelectS_ArrowR: TTexture; // Texture for right arrow
+
+ SelectOptInt: integer;
+ PData: ^integer;
+
+ //For automatically Setting LineCount
+ Lines: byte;
+
+ //Arrows on/off
+ showArrows: boolean; //default is false
+
+ //whether to show one item or all that fit into the select
+ oneItemOnly: boolean; //default is false
+
+ //Visibility
+ Visible: boolean;
+
+ // for selection and deselection
+ // main static
+ ColR: real;
+ ColG: real;
+ ColB: real;
+ Int: real;
+ DColR: real;
+ DColG: real;
+ DColB: real;
+ DInt: real;
+
+ // main text
+ TColR: real;
+ TColG: real;
+ TColB: real;
+ TInt: real;
+ TDColR: real;
+ TDColG: real;
+ TDColB: real;
+ TDInt: real;
+
+ // selection background static
+ SBGColR: real;
+ SBGColG: real;
+ SBGColB: real;
+ SBGInt: real;
+ SBGDColR: real;
+ SBGDColG: real;
+ SBGDColB: real;
+ SBGDInt: real;
+
+ // selection text
+ STColR: real;
+ STColG: real;
+ STColB: real;
+ STInt: real;
+ STDColR: real;
+ STDColG: real;
+ STDColB: real;
+ STDInt: real;
+
+ // position and size
+ property X: real read Texture.x write Texture.x;
+ property Y: real read Texture.y write Texture.y;
+ property W: real read Texture.w write Texture.w;
+ property H: real read Texture.h write Texture.h;
+// property X2: real read Texture2.x write Texture2.x;
+// property Y2: real read Texture2.y write Texture2.y;
+// property W2: real read Texture2.w write Texture2.w;
+// property H2: real read Texture2.h write Texture2.h;
+
+ property SBGW: real read TextureSBG.w write TextureSBG.w;
+
+ // procedures
+ procedure SetSelect(Value: boolean);
+ property Selected: boolean read SelectBool write SetSelect;
+ procedure SetSelectOpt(Value: integer);
+ property SelectedOption: integer read SelectOptInt write SetSelectOpt;
+ procedure Draw;
+ constructor Create;
+
+ //Automatically Generate Lines (Texts)
+ procedure genLines;
+
+ function GetMouseOverArea: TMouseOverRect;
+ function OnClick(X, Y: Real): TMouseClickAction;
+ end;
+
+const
+ ArrowAlphaOptionsLeft = 1;
+ ArrowAlphaNoOptionsLeft = 0;
+ MinItemSpacing = 5;
+ MinSideSpacing = 24;
+
+implementation
+
+uses
+ math,
+ SysUtils,
+ UDrawTexture,
+ ULog;
+
+// ------------ Select
+constructor TSelectSlide.Create;
+begin
+ inherited Create;
+ Text := TText.Create;
+ SetLength(TextOpt, 1);
+ TextOpt[0] := TText.Create;
+ Visible := true;
+
+ Colorized := false;
+ ColorizedSBG := false;
+ ColR := 1;
+ ColG := 1;
+ ColB := 1;
+ Int := 1;
+ DColR := 1;
+ DColG := 1;
+ DColB := 1;
+ DInt := 1;
+
+ SBGColR := 1;
+ SBGColG := 1;
+ SBGColB := 1;
+ SBGInt := 1;
+ SBGDColR := 1;
+ SBGDColG := 1;
+ SBGDColB := 1;
+ SBGDInt := 1;
+end;
+
+procedure TSelectSlide.SetSelect(Value: boolean);
+{var
+ SO: integer;
+ I: integer;}
+begin
+ SelectBool := Value;
+ if Value then
+ begin
+ Texture.ColR := ColR;
+ Texture.ColG := ColG;
+ Texture.ColB := ColB;
+ Texture.Int := Int;
+
+ Text.ColR := TColR;
+ Text.ColG := TColG;
+ Text.ColB := TColB;
+ Text.Int := TInt;
+
+ TextureSBG.ColR := SBGColR;
+ TextureSBG.ColG := SBGColG;
+ TextureSBG.ColB := SBGColB;
+ TextureSBG.Int := SBGInt;
+ end
+ else
+ begin
+ if Colorized then
+ DeSelectTexture.Int := DInt
+ else
+ begin
+ Texture.ColR := DColR;
+ Texture.ColG := DColG;
+ Texture.ColB := DColB;
+ Texture.Int := DInt;
+ end;
+
+ Text.ColR := TDColR;
+ Text.ColG := TDColG;
+ Text.ColB := TDColB;
+ Text.Int := TDInt;
+
+ if (ColorizedSBG) then
+ DeselectTextureSBG.Int := SBGDInt
+ else
+ begin
+ TextureSBG.ColR := SBGDColR;
+ TextureSBG.ColG := SBGDColG;
+ TextureSBG.ColB := SBGDColB;
+ TextureSBG.Int := SBGDInt;
+ end;
+ end;
+end;
+
+procedure TSelectSlide.SetSelectOpt(Value: integer);
+var
+ SO: integer;
+ HalfL: integer;
+ HalfR: integer;
+
+ procedure DoSelection(Sel: cardinal);
+ var
+ I: integer;
+ begin
+ for I := Low(TextOpt) to High(TextOpt) do
+ begin
+ TextOpt[I].ColR := STDColR;
+ TextOpt[I].ColG := STDColG;
+ TextOpt[I].ColB := STDColB;
+ TextOpt[I].Int := STDInt;
+ end;
+
+ if (integer(Sel) <= High(TextOpt)) then
+ begin
+ TextOpt[Sel].ColR := STColR;
+ TextOpt[Sel].ColG := STColG;
+ TextOpt[Sel].ColB := STColB;
+ TextOpt[Sel].Int := STInt;
+ end;
+ end;
+
+begin
+ SelectOptInt := Value;
+ PData^ := Value;
+
+ if (Length(TextOpt) > 0) and (Length(TextOptT) > 0) then
+ begin
+
+ //First option selected
+ if (Value <= 0) then
+ begin
+ Value := 0;
+
+ Tex_SelectS_ArrowL.alpha := ArrowAlphaNoOptionsLeft;
+ if (Length(TextOptT) > 1) then
+ Tex_SelectS_ArrowR.alpha := ArrowAlphaOptionsLeft
+ else
+ Tex_SelectS_ArrowR.alpha := ArrowAlphaNoOptionsLeft;
+
+ for SO := Low(TextOpt) to High(TextOpt) do
+ begin
+ TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[SO]);
+ end;
+
+ DoSelection(0);
+ end
+
+ //Last option selected
+ else if (Value >= High(TextOptT)) then
+ begin
+ Value := High(TextOptT);
+
+ Tex_SelectS_ArrowL.alpha := ArrowAlphaOptionsLeft;
+ Tex_SelectS_ArrowR.alpha := ArrowAlphaNoOptionsLeft;
+
+ for SO := High(TextOpt) downto Low(TextOpt) do
+ begin
+ TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[High(TextOptT) - (Lines - SO - 1)]);
+ end;
+ DoSelection(Lines - 1);
+ end
+
+ //in between first and last
+ else
+ begin
+ Tex_SelectS_ArrowL.alpha := ArrowAlphaOptionsLeft;
+ Tex_SelectS_ArrowR.alpha := ArrowAlphaOptionsLeft;
+
+ HalfL := Ceil((Lines - 1) / 2);
+ HalfR := Lines - 1 - HalfL;
+
+ //Selected option is near to the left side
+ if (Value <= HalfL) then
+ begin
+ //Change texts
+ for SO := Low(TextOpt) to High(TextOpt) do
+ begin
+ TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[SO]);
+ end;
+
+ DoSelection(Value);
+ end
+
+ //Selected option is near to the right side
+ else if (Value > High(TextOptT) - HalfR) then
+ begin
+ HalfR := High(TextOptT) - Value;
+ HalfL := Lines - 1 - HalfR;
+ //Change texts
+ for SO := High(TextOpt) downto Low(TextOpt) do
+ begin
+ TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[High(TextOptT) - (Lines - SO - 1)]);
+ end;
+
+ DoSelection (HalfL);
+ end
+
+ else
+ begin
+ //Change Texts
+ for SO := Low(TextOpt) to High(TextOpt) do
+ begin
+ TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[Value - HalfL + SO]);
+ end;
+
+ DoSelection(HalfL);
+ end;
+ end;
+ end;
+end;
+
+{ cuts the text if it is too long to fit on the selectbg }
+function TSelectSlide.AdjustOptionTextToFit(OptText: UTF8String): UTF8String;
+ var
+ MaxLen: real;
+ Len: integer;
+begin
+ Result := OptText;
+
+ if (TextureSBG.W > 0) then
+ begin
+ MaxLen := TextureSBG.W - MinSideSpacing * 2;
+
+ SetFontStyle(ftNormal);
+ SetFontSize(Text.Size);
+
+ // we will remove min. 2 letters by default and replace them w/ points
+ // if the whole text don't fit
+ Len := Length(OptText) - 1;
+
+ while (glTextWidth(Result) > MaxLen) and (Len > 0) do
+ begin
+ { ensure that we only cut at full letters }
+ { this code may be a problem if there is a text that
+ consists of many multi byte characters and only few
+ one byte characters }
+ repeat
+ Dec(Len);
+ until (byte(OptText[Len]) and 128) = 0;
+
+ Result := copy(OptText, 1, Len) + '..';
+ end;
+ end;
+end;
+
+procedure TSelectSlide.Draw;
+var
+ SO: integer;
+begin
+ if Visible then
+ begin
+ if SelectBool or not Colorized then
+ begin
+ DrawTexture(Texture);
+ end
+ else
+ begin
+ DeselectTexture.X := Texture.X;
+ DeselectTexture.Y := Texture.Y;
+ DeselectTexture.W := Texture.W;
+ DeselectTexture.H := Texture.H;
+ DrawTexture(DeselectTexture);
+ end;
+
+ if SelectBool or not ColorizedSBG then
+ begin
+ DrawTexture(TextureSBG);
+ end
+ else
+ begin
+ DeselectTextureSBG.X := TextureSBG.X;
+ DeselectTextureSBG.Y := TextureSBG.Y;
+ DeselectTextureSBG.W := TextureSBG.W;
+ DeselectTextureSBG.H := TextureSBG.H;
+ DrawTexture(DeselectTextureSBG);
+ end;
+
+ if showArrows then
+ begin
+ DrawTexture(Tex_SelectS_ArrowL);
+ DrawTexture(Tex_SelectS_ArrowR);
+ end;
+
+ Text.Draw;
+
+ for SO := Low(TextOpt) to High(TextOpt) do
+ TextOpt[SO].Draw;
+ end;
+end;
+
+procedure TSelectSlide.GenLines;
+var
+ maxlength: real;
+ I: integer;
+begin
+ SetFontStyle(ftNormal{Text.Style});
+ SetFontSize(Text.Size);
+ maxlength := 0;
+
+ for I := Low(TextOptT) to High(TextOptT) do
+ begin
+ if (glTextWidth(TextOptT[I]) > maxlength) then
+ maxlength := glTextWidth(TextOptT[I]);
+ end;
+
+
+ if (oneItemOnly = false) then
+ begin
+ //show all items
+ Lines := floor((TextureSBG.W - MinSideSpacing * 2) / (maxlength + MinItemSpacing));
+ if (Lines > Length(TextOptT)) then
+ Lines := Length(TextOptT);
+
+ if (Lines <= 0) then
+ Lines := 1;
+ end
+ else
+ begin
+ //show one item only
+ Lines := 1;
+ end;
+
+ //Free old Space used by Texts
+ for I := Low(TextOpt) to High(TextOpt) do
+ TextOpt[I].Free;
+
+ SetLength (TextOpt, Lines);
+
+ for I := Low(TextOpt) to High(TextOpt) do
+ begin
+ TextOpt[I] := TText.Create;
+ TextOpt[I].Size := Text.Size;
+ TextOpt[I].Visible := true;
+ TextOpt[I].Style := 0;
+
+ TextOpt[I].ColR := STDColR;
+ TextOpt[I].ColG := STDColG;
+ TextOpt[I].ColB := STDColB;
+ TextOpt[I].Int := STDInt;
+
+ // generate positions
+ TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H - Text.Size) / 2;
+
+ // better look with 2 options and a single option
+ if (Lines = 2) then
+ begin
+ TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(TextOptT[1])) * I;
+ TextOpt[I].Align := 0;
+ end
+ else if (Lines = 1) then
+ begin
+ TextOpt[I].X := TextureSBG.X + (TextureSBG.W / 2);
+ TextOpt[I].Align := 1; //center text
+ end
+ else
+ begin
+ TextOpt[I].X := TextureSBG.X + TextureSBG.W / 2 + (TextureSBG.W - MinSideSpacing*2) * (I / Lines - 0.5);
+ TextOpt[I].Align := 0;
+ end;
+ end;
+end;
+
+function TSelectSlide.GetMouseOverArea: TMouseOverRect;
+begin
+ Result.X := Texture.X;
+ Result.Y := Texture.Y;
+ Result.W := (TextureSBG.X + TextureSBG.W) - Result.X;
+ Result.H := Max(Texture.H, TextureSBG.H);
+end;
+
+function TSelectSlide.OnClick(X, Y: Real): TMouseClickAction;
+ var
+ AreaW: Real;
+begin
+ // default: press return on click
+ Result := maReturn;
+
+ // use left sides to inc or dec selection by click
+ AreaW := TextureSbg.W / 20;
+
+ if (Y >= TextureSBG.Y) and (Y <= TextureSBG.Y + TextureSBG.H) then
+ begin
+ if (X >= TextureSBG.X) and (X <= TextureSBG.X + AreaW) then
+ Result := maLeft // hit left area
+ else if (X >= TextureSBG.X + TextureSBG.W - AreaW) and (X <= TextureSBG.X + TextureSBG.W) then
+ Result := maRight; // hit right area
+ end;
+end;
+
+end.
diff --git a/src/menu/UMenuStatic.pas b/src/menu/UMenuStatic.pas
new file mode 100644
index 00000000..72f4eb36
--- /dev/null
+++ b/src/menu/UMenuStatic.pas
@@ -0,0 +1,117 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuStatic;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ UTexture,
+ gl;
+
+type
+ TStatic = class
+ public
+ Texture: TTexture; // Button Screen position and size
+ Visible: boolean;
+
+ //Reflection Mod
+ Reflection: boolean;
+ Reflectionspacing: real;
+
+ procedure Draw;
+ constructor Create(Textura: TTexture); overload;
+ end;
+
+implementation
+uses
+ UDrawTexture;
+
+procedure TStatic.Draw;
+begin
+ if Visible then
+ begin
+ DrawTexture(Texture);
+
+ //Reflection Mod
+ if (Reflection) then // Draw Reflections
+ begin
+ with Texture do
+ begin
+ //Bind Tex and GL Attributes
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+
+ glDepthRange(0, 10);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBindTexture(GL_TEXTURE_2D, TexNum);
+
+ //Draw
+ glBegin(GL_QUADS);//Top Left
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
+ glTexCoord2f(TexX1*TexW, TexY2*TexH);
+ glVertex3f(x, y+h*scaleH+ Reflectionspacing, z);
+
+ //Bottom Left
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
+ glTexCoord2f(TexX1*TexW, 0.5*TexH+TexY1);
+ glVertex3f(x, y+h*scaleH + h*scaleH/2 + Reflectionspacing, z);
+
+
+ //Bottom Right
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
+ glTexCoord2f(TexX2*TexW, 0.5*TexH+TexY1);
+ glVertex3f(x+w*scaleW, y+h*scaleH + h*scaleH/2 + Reflectionspacing, z);
+
+ //Top Right
+ glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
+ glTexCoord2f(TexX2*TexW, TexY2*TexH);
+ glVertex3f(x+w*scaleW, y+h*scaleH + Reflectionspacing, z);
+ glEnd;
+
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_BLEND);
+ end;
+ end;
+ end;
+end;
+
+constructor TStatic.Create(Textura: TTexture);
+begin
+ inherited Create;
+ Texture := Textura;
+end;
+
+end.
diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas
new file mode 100644
index 00000000..ab180b77
--- /dev/null
+++ b/src/menu/UMenuText.pas
@@ -0,0 +1,379 @@
+{* UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *}
+
+unit UMenuText;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ math,
+ SysUtils,
+ gl,
+ SDL,
+ TextGL,
+ UTexture;
+
+type
+ TText = class
+ private
+ SelectBool: boolean;
+ TextString: UTF8String;
+ TextTiles: array of UTF8String;
+
+ STicks: cardinal;
+ SelectBlink: boolean;
+ public
+ X: real;
+ Y: real;
+ Z: real;
+ MoveX: real; // some modifier for x - position that don't affect the real Y
+ MoveY: real; // some modifier for y - position that don't affect the real Y
+ W: real; // text wider than W is broken
+// H: real;
+ Size: real;
+ ColR: real;
+ ColG: real;
+ ColB: real;
+ Alpha: real;
+ Int: real;
+ Style: integer;
+ Visible: boolean;
+ Align: integer; // 0 = left, 1 = center, 2 = right
+
+ // reflection
+ Reflection: boolean;
+ ReflectionSpacing: real;
+
+ procedure SetSelect(Value: boolean);
+ property Selected: boolean read SelectBool write SetSelect;
+
+ procedure SetText(Value: UTF8String);
+ property Text: UTF8String read TextString write SetText;
+
+ procedure DeleteLastLetter; //< Deletes the rightmost letter
+
+ procedure Draw;
+ constructor Create; overload;
+ constructor Create(X, Y: real; const Text: UTF8String); overload;
+ constructor Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; const ParText: UTF8String; ParReflection: boolean; ParReflectionSpacing: real; ParZ: real); overload;
+ end;
+
+implementation
+
+uses
+ UGraphic,
+ UUnicodeUtils,
+ StrUtils;
+
+procedure TText.SetSelect(Value: boolean);
+begin
+ SelectBool := Value;
+
+ // set cursor visible
+ SelectBlink := true;
+ STicks := SDL_GetTicks() div 550;
+end;
+
+procedure TText.SetText(Value: UTF8String);
+var
+ NextPos: cardinal; // next pos of a space etc.
+ LastPos: cardinal; // last pos "
+ LastBreak: cardinal; // last break
+ isBreak: boolean; // true if the break is not caused because the text is out of the area
+ FirstWord: word; // is first word after break?
+ Len: word; // length of the tiles array
+
+ function GetNextPos: boolean;
+ var
+ T1, {T2,} T3: cardinal;
+ begin
+ LastPos := NextPos;
+
+ // next space (if width is given)
+ if (W > 0) then
+ T1 := PosEx(' ', Value, LastPos + 1)
+ else
+ T1 := Length(Value);
+
+ {// next -
+ T2 := PosEx('-', Value, LastPos + 1);}
+
+ // next break
+ T3 := PosEx('\n', Value, LastPos + 1);
+
+ if T1 = 0 then
+ T1 := Length(Value);
+ {if T2 = 0 then
+ T2 := Length(Value); }
+ if T3 = 0 then
+ T3 := Length(Value);
+
+ // get nearest pos
+ NextPos := min(T1, T3{min(T2, T3)});
+
+ if (LastPos = cardinal(Length(Value))) then
+ NextPos := 0;
+
+ isBreak := (NextPos = T3) and (NextPos <> cardinal(Length(Value)));
+ Result := (NextPos <> 0);
+ end;
+
+ procedure AddBreak(const From, bTo: cardinal);
+ begin
+ if (isBreak) or (bTo - From >= 1) then
+ begin
+ Inc(Len);
+ SetLength (TextTiles, Len);
+ TextTiles[Len-1] := Trim(Copy(Value, From, bTo - From));
+
+ if isBreak then
+ LastBreak := bTo + 2
+ else
+ LastBreak := bTo + 1;
+ FirstWord := 0;
+ end;
+ end;
+
+begin
+ // set TextString
+ TextString := Value;
+
+ // set cursor visible
+ SelectBlink := true;
+ STicks := SDL_GetTicks() div 550;
+
+ // exit if there is no need to create tiles
+ if (W <= 0) and (Pos('\n', Value) = 0) then
+ begin
+ SetLength (TextTiles, 1);
+ TextTiles[0] := Value;
+ Exit;
+ end;
+
+ // create tiles
+ // reset text array
+ SetLength (TextTiles, 0);
+ Len := 0;
+
+ // reset counter vars
+ LastPos := 1;
+ NextPos := 1;
+ LastBreak := 1;
+ FirstWord := 1;
+
+ if (W > 0) then
+ begin
+ // set font properties
+ SetFontStyle(Style);
+ SetFontSize(Size);
+ end;
+
+ // go through text
+ while (GetNextPos) do
+ begin
+ // break in text
+ if isBreak then
+ begin
+ // look for break before the break
+ if (glTextWidth(Copy(Value, LastBreak, NextPos - LastBreak + 1)) > W) AND (NextPos-LastPos > 1) then
+ begin
+ isBreak := false;
+ // not the first word after break, so we don't have to break within a word
+ if (FirstWord > 1) then
+ begin
+ // add break before actual position, because there the text fits the area
+ AddBreak(LastBreak, LastPos);
+ end
+ else // first word after break break within the word
+ begin
+ // to do
+ // AddBreak(LastBreak, LastBreak + 155);
+ end;
+ end;
+
+ isBreak := true;
+ // add break from text
+ AddBreak(LastBreak, NextPos);
+ end
+ // text comes out of the text area -> createbreak
+ else if (glTextWidth(Copy(Value, LastBreak, NextPos - LastBreak + 1)) > W) then
+ begin
+ // not the first word after break, so we don't have to break within a word
+ if (FirstWord > 1) then
+ begin
+ // add break before actual position, because there the text fits the area
+ AddBreak(LastBreak, LastPos);
+ end
+ else // first word after break -> break within the word
+ begin
+ // to do
+ // AddBreak(LastBreak, LastBreak + 155);
+ end;
+ end;
+ //end;
+ Inc(FirstWord)
+ end;
+ // add ending
+ AddBreak(LastBreak, Length(Value)+1);
+end;
+
+procedure TText.DeleteLastLetter;
+begin
+ SetText(UTF8Copy(TextString, 1, LengthUTF8(TextString)-1));
+end;
+
+procedure TText.Draw;
+var
+ X2, Y2: real;
+ Text2: UTF8String;
+ I: integer;
+ Ticks: cardinal;
+begin
+ if Visible then
+ begin
+ SetFontStyle(Style);
+ SetFontSize(Size);
+ SetFontItalic(false);
+
+ glColor4f(ColR*Int, ColG*Int, ColB*Int, Alpha);
+
+ // reflection
+ if Reflection then
+ SetFontReflection(true, ReflectionSpacing)
+ else
+ SetFontReflection(false,0);
+
+ // if selected set blink...
+ if SelectBool then
+ begin
+ Ticks := SDL_GetTicks() div 550;
+ if Ticks <> STicks then
+ begin // change visability
+ STicks := Ticks;
+ SelectBlink := Not SelectBlink;
+ end;
+ end;
+
+ {if (false) then // no width set draw as one long string
+ begin
+ if not (SelectBool AND SelectBlink) then
+ Text2 := Text
+ else
+ Text2 := Text + '|';
+
+ case Align of
+ 0: X2 := X;
+ 1: X2 := X - glTextWidth(Text2)/2;
+ 2: X2 := X - glTextWidth(Text2);
+ end;
+
+ SetFontPos(X2, Y);
+ glPrint(Text2);
+ SetFontStyle(ftNormal); // reset to default
+ end
+ else
+ begin}
+ // now use always:
+ // draw text as many strings
+ Y2 := Y + MoveY;
+ for I := 0 to High(TextTiles) do
+ begin
+ if (not (SelectBool and SelectBlink)) or (I <> High(TextTiles)) then
+ Text2 := TextTiles[I]
+ else
+ Text2 := TextTiles[I] + '|';
+
+ case Align of
+ 1: X2 := X + MoveX - glTextWidth(Text2)/2; { centered }
+ 2: X2 := X + MoveX - glTextWidth(Text2); { right aligned }
+ else X2 := X + MoveX; { left aligned (default) }
+ end;
+
+ SetFontPos(X2, Y2);
+
+ SetFontZ(Z);
+
+ glPrint(Text2);
+
+ {if Size >= 10 then
+ Y2 := Y2 + Size * 0.93
+ else}
+ if (Style = ftBold) then
+ Y2 := Y2 + Size * 0.93
+ else
+ Y2 := Y2 + Size * 0.72;
+ end;
+ SetFontStyle(ftNormal); // reset to default
+
+ //end;
+ end;
+end;
+
+constructor TText.Create;
+begin
+ Create(0, 0, '');
+end;
+
+constructor TText.Create(X, Y: real; const Text: UTF8String);
+begin
+ Create(X, Y, 0, ftNormal, 30, 0, 0, 0, 0, Text, false, 0, 0);
+end;
+
+constructor TText.Create(ParX, ParY, ParW: real;
+ ParStyle: integer;
+ ParSize, ParColR, ParColG, ParColB: real;
+ ParAlign: integer;
+ const ParText: UTF8String;
+ ParReflection: boolean;
+ ParReflectionSpacing: real;
+ ParZ: real);
+begin
+ inherited Create;
+ Alpha := 1;
+ X := ParX;
+ Y := ParY;
+ W := ParW;
+ Z := ParZ;
+ Style := ParStyle;
+ Size := ParSize;
+ Text := ParText;
+ ColR := ParColR;
+ ColG := ParColG;
+ ColB := ParColB;
+ Int := 1;
+ Align := ParAlign;
+ SelectBool := false;
+ Visible := true;
+ Reflection := ParReflection;
+ ReflectionSpacing := ParReflectionSpacing;
+end;
+
+end.