aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/src/menu/UDisplay.pas
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/src/menu/UDisplay.pas')
-rw-r--r--cmake/src/menu/UDisplay.pas218
1 files changed, 206 insertions, 12 deletions
diff --git a/cmake/src/menu/UDisplay.pas b/cmake/src/menu/UDisplay.pas
index 58c416db..f2eb2ced 100644
--- a/cmake/src/menu/UDisplay.pas
+++ b/cmake/src/menu/UDisplay.pas
@@ -45,7 +45,7 @@ type
TDisplay = class
private
//fade-to-black-hack
- BlackScreen: boolean;
+ BlackScreen: boolean;
FadeEnabled: boolean; // true if fading is enabled
FadeFailed: boolean; // true if fading is possible (enough memory, etc.)
@@ -60,6 +60,17 @@ type
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;
public
NextScreen: PMenu;
@@ -78,10 +89,27 @@ type
procedure SaveScreenShot;
function Draw: 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; Pressed: boolean);
+
+
+ { draws software cursor }
+ procedure DrawCursor;
end;
var
- Display: TDisplay;
+ Display: TDisplay;
+
+const
+ { constants for software cursor effects
+ time in milliseconds }
+ Cursor_FadeIn_Time = 500; // seconds the fade in effect lasts
+ Cursor_FadeOut_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
@@ -110,9 +138,9 @@ begin
BlackScreen := false;
// fade mod
- FadeState := 0;
+ FadeState := 0;
FadeEnabled := (Ini.ScreenFade = 1);
- FadeFailed:= false;
+ FadeFailed := false;
glGenTextures(2, @FadeTex);
@@ -125,6 +153,15 @@ begin
//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;
@@ -306,6 +343,162 @@ begin
if ((Ini.Debug = 1) or (Params.Debug)) and (S = 1) then
DrawDebugInformation;
end; // for
+
+ if not BlackScreen then
+ DrawCursor;
+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 when cursor moves, positioning of software cursor }
+procedure TDisplay.MoveCursor(X, Y: double; Pressed: boolean);
+var
+ Ticks: cardinal;
+begin
+ if (Ini.Mouse = 2) and
+ ((X <> Cursor_X) or (Y <> Cursor_Y) or (Pressed <> Cursor_Pressed)) then
+ begin
+ Cursor_X := X;
+ Cursor_Y := Y;
+ Cursor_Pressed := Pressed;
+
+ 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_FadeIn_Time * (1 - (Ticks - Cursor_LastMove)/Cursor_FadeOut_Time))
+ else
+ Cursor_LastMove := Ticks;
+
+ Cursor_Visible := true;
+ Cursor_Fade := true;
+ end
+ else if not Cursor_Fade then
+ begin
+ Cursor_LastMove := Ticks;
+ end;
+ end;
+end;
+
+{ draws software cursor }
+procedure TDisplay.DrawCursor;
+var
+ Alpha: single;
+ Ticks: cardinal;
+begin
+ if (Ini.Mouse = 2) 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_FadeIn_Time <= Ticks) then
+ Cursor_Fade := false
+ else
+ Alpha := sin((Ticks - Cursor_LastMove) * 0.5 * pi / Cursor_FadeIn_Time) * 0.7;
+ end
+ else
+ begin //fade out
+ if (Cursor_LastMove + Cursor_FadeOut_Time <= Ticks) then
+ Cursor_Fade := false
+ else
+ Alpha := cos((Ticks - Cursor_LastMove) * 0.5 * pi / Cursor_FadeOut_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
+ 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(Cursor_X, Cursor_Y);
+
+ glTexCoord2f(0, 1);
+ glVertex2f(Cursor_X, Cursor_Y + 32);
+
+ glTexCoord2f(1, 1);
+ glVertex2f(Cursor_X + 32, Cursor_Y + 32);
+
+ glTexCoord2f(1, 0);
+ glVertex2f(Cursor_X + 32, Cursor_Y);
+ glEnd;
+
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+ end;
+ end;
end;
procedure TDisplay.SaveScreenShot;
@@ -360,10 +553,11 @@ begin
end;
//------------
-// DrawDebugInformation - Procedure draw FPS and some other Informations on Screen
+// DrawDebugInformation - procedure draw fps and some other informations on screen
//------------
procedure TDisplay.DrawDebugInformation;
-var Ticks: cardinal;
+var
+ Ticks: cardinal;
begin
// Some White Background for information
glEnable(GL_BLEND);
@@ -377,13 +571,13 @@ begin
glEnd;
glDisable(GL_BLEND);
-// Set Font Specs
+// set font specs
SetFontStyle(0);
SetFontSize(21);
SetFontItalic(false);
glColor4f(0, 0, 0, 1);
-// Calculate FPS
+// calculate fps
Ticks := SDL_GetTicks();
if (Ticks >= NextFPSSwap) then
begin
@@ -394,17 +588,17 @@ begin
Inc(FPSCounter);
-// Draw Text
+// draw text
-// FPS
+// fps
SetFontPos(695, 0);
glPrint ('FPS: ' + InttoStr(LastFPS));
-// RSpeed
+// rspeed
SetFontPos(695, 13);
glPrint ('RSpeed: ' + InttoStr(Round(1000 * TimeMid)));
-// LastError
+// lasterror
SetFontPos(695, 26);
glColor4f(1, 0, 0, 1);
glPrint (OSD_LastError);