From e06c097dbfbebee3c03bf82cdcd05805f546a61d Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Wed, 27 Aug 2008 15:01:16 +0000 Subject: rename Menu part2 git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1310 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 383 ++++++++++ src/menu/UDrawTexture.pas | 105 +++ src/menu/UMenu.pas | 1432 ++++++++++++++++++++++++++++++++++++ src/menu/UMenuButton.pas | 564 ++++++++++++++ src/menu/UMenuButtonCollection.pas | 71 ++ src/menu/UMenuInteract.pas | 16 + src/menu/UMenuSelectSlide.pas | 355 +++++++++ src/menu/UMenuStatic.pas | 85 +++ src/menu/UMenuText.pas | 350 +++++++++ 9 files changed, 3361 insertions(+) create mode 100644 src/menu/UDisplay.pas create mode 100644 src/menu/UDrawTexture.pas create mode 100644 src/menu/UMenu.pas create mode 100644 src/menu/UMenuButton.pas create mode 100644 src/menu/UMenuButtonCollection.pas create mode 100644 src/menu/UMenuInteract.pas create mode 100644 src/menu/UMenuSelectSlide.pas create mode 100644 src/menu/UMenuStatic.pas create mode 100644 src/menu/UMenuText.pas (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas new file mode 100644 index 00000000..2b10b2c6 --- /dev/null +++ b/src/menu/UDisplay.pas @@ -0,0 +1,383 @@ +unit UDisplay; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses + ucommon, + SDL, + UMenu, + gl, + glu, + SysUtils; + +type + TDisplay = class + private + //fade-to-black-hack + BlackScreen: Boolean; + + FadeEnabled: Boolean; // true if fading is enabled + FadeFailed: Boolean; // true if fading is possible (enough memory, etc.) + FadeState: integer; // fading state, 0 means that the fade texture must be initialized + LastFadeTime: Cardinal; // last fade update time + + FadeTex: array[1..2] of GLuint; + + FPSCounter : Cardinal; + LastFPS : Cardinal; + NextFPSSwap : Cardinal; + + OSD_LastError : String; + + procedure DrawDebugInformation; + 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 SaveScreenShot; + + function Draw: Boolean; + end; + +var + Display: TDisplay; + +implementation + +uses + UImage, + TextGL, + ULog, + UMain, + UTexture, + UIni, + UGraphic, + UTime, + UCommandLine; + +constructor TDisplay.Create; +var + i: integer; +begin + inherited Create; + + //popup hack + CheckOK := False; + NextScreen := nil; + NextScreenWithCheck := nil; + BlackScreen := False; + + // fade mod + FadeState := 0; + FadeEnabled := (Ini.ScreenFade = 1); + FadeFailed:= false; + + glGenTextures(2, @FadeTex); + + for i := 1 to 2 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); + end; + + //Set LastError for OSD to No Error + OSD_LastError := 'No Errors'; +end; + +destructor TDisplay.Destroy; +begin + glDeleteTextures(2, @FadeTex); + inherited Destroy; +end; + +function TDisplay.Draw: Boolean; +var + S: integer; + FadeStateSquare: Real; + currentTime: Cardinal; + glError: glEnum; +begin + Result := True; + + glClearColor(1, 1, 1 , 0); + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); + + 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 hack + // 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 + CurrentScreen.Draw; + + //popup mod + if (ScreenPopupError <> nil) and ScreenPopupError.Visible then + ScreenPopupError.Draw + else if (ScreenPopupCheck <> nil) and ScreenPopupCheck.Visible then + ScreenPopupCheck.Draw; + + // fade mod + FadeState := 0; + if ((Ini.ScreenFade = 1) and (not FadeFailed)) then + FadeEnabled := True + else if (Ini.ScreenFade = 0) then + FadeEnabled := 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 FadeState = 0 then + begin + // save old viewport and resize to fit texture + glPushAttrib(GL_VIEWPORT_BIT); + glViewPort(0, 0, 512, 512); + + // draw screen that will be faded + CurrentScreen.Draw; + + // clear OpenGL errors, otherwise fading might be disabled due to some + // older errors in previous OpenGL calls. + glGetError(); + + // copy screen to texture + glBindTexture(GL_TEXTURE_2D, FadeTex[S]); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0); + glError := glGetError(); + if (glError <> GL_NO_ERROR) then + begin + FadeFailed := true; + Log.LogWarn('Fading disabled: ' + gluErrorString(glError), 'TDisplay.Draw'); + end; + + // restore viewport + glPopAttrib(); + + // blackscreen-hack + if not BlackScreen then + NextScreen.onShow; + + // update fade state + LastFadeTime := SDL_GetTicks(); + if (S = 2) or (Screens = 1) then + FadeState := FadeState + 1; + end; // end texture creation in first fading step + + //do some time-based fading + currentTime := SDL_GetTicks(); + if (currentTime > LastFadeTime+30) and (S = 1) then + begin + FadeState := FadeState + 4; + LastFadeTime := currentTime; + end; + + // blackscreen-hack + if not BlackScreen then + NextScreen.Draw // draw next screen + else if ScreenAct = 1 then + begin + glClearColor(0, 0, 0 , 0); + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); + end; + + // and draw old screen over it... slowly fading out + + FadeStateSquare := (FadeState*FadeState)/10000; + + glBindTexture(GL_TEXTURE_2D, FadeTex[S]); + 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, 0+FadeStateSquare); glVertex2f(0, 600); + glTexCoord2f(0+FadeStateSquare, 1-FadeStateSquare); glVertex2f(0, 0); + glTexCoord2f(1-FadeStateSquare, 1-FadeStateSquare); glVertex2f(800, 0); + glTexCoord2f(1-FadeStateSquare, 0+FadeStateSquare); glVertex2f(800, 600); + glEnd; + glDisable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + end + // blackscreen hack + else if not BlackScreen then + begin + NextScreen.OnShow; + end; + + if ((FadeState > 40) or (not FadeEnabled) or FadeFailed) and (S = 1) then + begin + // fade out complete... + FadeState := 0; + 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; + end; // for +end; + +procedure TDisplay.SaveScreenShot; +var + Num: integer; + FileName: string; + ScreenData: PChar; + Surface: PSDL_Surface; + Success: boolean; + Align: integer; + RowSize: integer; +begin + // Exit if Screenshot-path does not exist or read-only + if (ScreenshotsPath = '') then + Exit; + + for Num := 1 to 9999 do + begin + FileName := IntToStr(Num); + while Length(FileName) < 4 do + FileName := '0' + FileName; + FileName := ScreenshotsPath + 'screenshot' + FileName + '.png'; + if not FileExists(FileName) 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); + 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 + ScreenPopupError.ShowPopup('Screenshot saved: ' + ExtractFileName(FileName)) + else + ScreenPopupError.ShowPopup('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(0); + SetFontSize(7); + 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 (PChar('FPS: ' + InttoStr(LastFPS))); + + //RSpeed + SetFontPos(695, 13); + glPrint (PChar('RSpeed: ' + InttoStr(Round(1000 * TimeMid)))); + + //LastError + SetFontPos(695, 26); + glColor4f(1, 0, 0, 1); + glPrint (PChar(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..a7dde18f --- /dev/null +++ b/src/menu/UDrawTexture.pas @@ -0,0 +1,105 @@ +unit UDrawTexture; + +interface + +{$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 + // rysuje paski gracza + 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..e352febd --- /dev/null +++ b/src/menu/UMenu.pas @@ -0,0 +1,1432 @@ +unit UMenu; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses gl, SysUtils, UTexture, UMenuStatic, UMenuText, UMenuButton, UMenuSelectSlide, + UMenuInteract, UThemes, UMenuButtonCollection, Math, UMusic; + +type +{ Int16 = SmallInt;} + + PMenu = ^TMenu; + TMenu = class + protected + ButtonPos: Integer; + + Interactions: array of TInteract; + SelInteraction: integer; + Button: array of TButton; + SelectsS: array of TSelectSlide; + ButtonCollection: array of TButtonCollection; + BackImg: TTexture; + BackW: integer; + BackH: integer; + + fFileName : string; + public + Text: array of TText; + Static: array of TStatic; + mX: integer; // mouse X + mY: integer; // mouse Y + + Fade: integer; // fade type + ShowFinish: boolean; // true if there is no fade + + + 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 + function WideCharUpperCase(wchar: WideChar) : WideString; + function WideStringUpperCase(wstring: WideString) : WideString; + procedure AddInteraction(Typ, Num: integer); + procedure SetInteraction(Num: integer); + 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(Name: string); + + // static + function AddStatic(ThemeStatic: TThemeStatic): integer; overload; + function AddStatic(X, Y, W, H: real; const Name: string): integer; overload; + function AddStatic(X, Y, W, H: real; const Name: string; Typ: TTextureType): integer; overload; + function AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; overload; + function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; overload; + function AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; overload; + function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; overload; + function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: Boolean; ReflectionSpacing: Real): integer; overload; + + // text + function AddText(ThemeText: TThemeText): integer; overload; + function AddText(X, Y: real; const Text_: string): integer; overload; + function AddText(X, Y: real; Style: integer; Size, ColR, ColG, ColB: real; const Text: string): integer; overload; + function AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; const Text_: string; 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 Name: String): integer; overload; + function AddButton(X, Y, W, H: real; const Name: String; Typ: TTextureType; Reflection: Boolean): integer; overload; + function AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; const Name: String; Typ: TTextureType; Reflection: Boolean; ReflectionSpacing, DeSelectReflectionSpacing: Real): integer; overload; + procedure ClearButtons; + procedure AddButtonText(AddX, AddY: real; const AddText: string); overload; + procedure AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: string); overload; + procedure AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); overload; + procedure AddButtonText(CustomButton: TButton; AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); overload; + + // select slide + function AddSelectSlide(ThemeSelectS: TThemeSelectSlide; var Data: integer; Values: array of string): 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 Name: String; Typ: TTextureType; const SBGName: String; SBGTyp: TTextureType; + const Caption: string; var Data: integer): integer; overload; + procedure AddSelectSlideOption(const AddText: string); overload; + procedure AddSelectSlideOption(SelectNo: Cardinal; const AddText: string); overload; + procedure UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; SelectNum: integer; Values: array of string; 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: String); + + function DrawBG: boolean; virtual; + function DrawFG: boolean; virtual; + function Draw: boolean; virtual; + function ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown : Boolean): Boolean; virtual; + // FIXME: ParseMouse is not implemented in any subclass and not even used anywhere in the code + // -> do this before activation of this method + //function ParseMouse(Typ: integer; X: integer; Y: integer): Boolean; virtual; abstract; + 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; + +const + 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, + ULog, + UMain, + UDrawTexture, + UGraphic, + UDisplay, + UCovers, + UTime, + USkins; + +destructor TMenu.Destroy; +begin + inherited; +end; + +constructor TMenu.Create; +begin + inherited; + + Fade := 0;//fWhite; + + SetLength(Static, 0); + SetLength(Button, 0); + + BackImg.TexNum := 0; + + //Set ButtonPos to Autoset Length + ButtonPos := -1; +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.Tex); + + //Add Statics and Texts + for I := 0 to High(ThemeBasic.Static) do + AddStatic(ThemeBasic.Static[I]); + + for I := 0 to High(ThemeBasic.Text) do + AddText(ThemeBasic.Text[I]); +end; + +procedure TMenu.AddBackground(Name: string); +//var +// lFileName : string; +begin + if Name <> '' then + begin + fFileName := Skin.GetTextureFileName(Name); + fFileName := AdaptFilePaths( fFileName ); + + if fileexists( fFileName ) then + begin + BackImg := Texture.GetTexture( fFileName , TEXTURE_TYPE_PLAIN); + + if ( BackImg.TexNum = 0 ) then + begin + if VideoPlayback.Open( fFileName ) then + begin + VideoBGTimer.SetTime(0); + VideoPlayback.Play; + end; + end; + + BackImg.W := 800; + BackImg.H := 600; + BackW := 1; + BackH := 1; + end; + 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 Name: string): integer; +begin + Result := AddStatic(X, Y, W, H, Name, TEXTURE_TYPE_PLAIN); +end; + +function TMenu.AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; +begin + Result := AddStatic(X, Y, W, H, ColR, ColG, ColB, Name, Typ, $FFFFFF); +end; + +function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; +begin + Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, Name, Typ, $FFFFFF); +end; + +function TMenu.AddStatic(X, Y, W, H: real; const Name: string; Typ: TTextureType): integer; +var + StatNum: integer; +begin + // adds static + StatNum := Length(Static); + SetLength(Static, StatNum + 1); + Static[StatNum] := TStatic.Create(Texture.GetTexture(Name, Typ, $FF00FF)); // new skin + + // configures static + Static[StatNum].Texture.X := X; + Static[StatNum].Texture.Y := Y; + Static[StatNum].Texture.W := W; + Static[StatNum].Texture.H := H; + Static[StatNum].Visible := true; + Result := StatNum; +end; + +function TMenu.AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; +begin + Result := AddStatic(X, Y, W, H, 0, ColR, ColG, ColB, Name, Typ, Color); +end; + +function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; +begin + Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, 0, 0, 1, 1, Name, Typ, Color, False, 0); +end; + +function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: Boolean; ReflectionSpacing: Real): integer; +var + StatNum: integer; +begin + // adds static + StatNum := Length(Static); + SetLength(Static, StatNum + 1); + + // colorize hack + if (Typ = TEXTURE_TYPE_COLORIZED) then + begin + // give encoded color to GetTexture() + Static[StatNum] := TStatic.Create(Texture.GetTexture(Name, Typ, RGBFloatToInt(ColR, ColG, ColB))); + end + else + begin + Static[StatNum] := TStatic.Create(Texture.GetTexture(Name, Typ, Color)); // new skin + end; + + // configures static + Static[StatNum].Texture.X := X; + Static[StatNum].Texture.Y := Y; + Static[StatNum].Texture.W := W; + Static[StatNum].Texture.H := H; + Static[StatNum].Texture.Z := Z; + if (Typ <> TEXTURE_TYPE_COLORIZED) then + begin + Static[StatNum].Texture.ColR := ColR; + Static[StatNum].Texture.ColG := ColG; + Static[StatNum].Texture.ColB := ColB; + end; + Static[StatNum].Texture.TexX1 := TexX1; + Static[StatNum].Texture.TexY1 := TexY1; + Static[StatNum].Texture.TexX2 := TexX2; + Static[StatNum].Texture.TexY2 := TexY2; + Static[StatNum].Texture.Alpha := 1; + Static[StatNum].Visible := true; + + //ReflectionMod + Static[StatNum].Reflection := Reflection; + Static[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_: string): 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: string): 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_: string; 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 Array 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; + Log.BenchmarkEnd(6); + Log.LogBenchmark('====> Screen Options32', 6); +end; + +function TMenu.AddButton(X, Y, W, H: real; const Name: String): integer; +begin + Result := AddButton(X, Y, W, H, Name, TEXTURE_TYPE_PLAIN, False); +end; + +function TMenu.AddButton(X, Y, W, H: real; const Name: String; Typ: TTextureType; Reflection: Boolean): integer; +begin + Result := AddButton(X, Y, W, H, 1, 1, 1, 1, 1, 1, 1, 0.5, Name, TEXTURE_TYPE_PLAIN, Reflection, 15, 15); +end; + +function TMenu.AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; + const Name: String; 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(Name, Typ, RGBFloatToInt(ColR, ColG, ColB)), + Texture.GetTexture(Name, Typ, RGBFloatToInt(DColR, DColG, DColB))); + end + else + begin + Button[Result] := TButton.Create(Texture.GetTexture(Name, 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 + BackImg.ColR := 1; + BackImg.ColG := 1; + BackImg.ColB := 1; + BackImg.TexX1 := 0; + BackImg.TexY1 := 0; + BackImg.TexX2 := 1; + BackImg.TexY2 := 1; + + if (BackImg.TexNum > 0) then + begin + BackImg.X := 0; + BackImg.Y := 0; + BackImg.Z := 0; // todo: eddie: to the opengl experts: please check this! On the mac z is not initialized??? + BackImg.W := 800; + BackImg.H := 600; + DrawTexture(BackImg); + end + else if (VideoPlayback <> nil) then + begin + VideoPlayback.GetFrame(VideoBGTimer.GetTime()); + // FIXME: why do we draw on screen 2? Seems to be wrong. + VideoPlayback.DrawGL(2); + end; + + 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 Length(Static) - 1 do + Static[J].Draw; + + // ... and slightly implemented menutext unit + for J := 0 to Length(Text) - 1 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 Length(Button) - 1 do + Button[J].Draw; + + for J := 0 to Length(SelectsS) - 1 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 //nonvalid 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 //nonvalid 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; + + +//popup hack +procedure TMenu.CheckFadeTo(Screen: PMenu; msg: String); +begin + Display.Fade := 0; + Display.NextScreenWithCheck := Screen; + Display.CheckOK:=False; + ScreenPopupCheck.ShowPopup(msg); +end; + +procedure TMenu.AddButtonText(AddX, AddY: real; const AddText: string); +begin + AddButtonText(AddX, AddY, 1, 1, 1, AddText); +end; + +procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: string); +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: string); +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: string); +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; Values: array of string): 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), TEXTURE_TYPE_COLORIZED, + Skin.GetTextureFileName(ThemeSelectS.TexSBG), TEXTURE_TYPE_COLORIZED, + 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; + + //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 Name: String; Typ: TTextureType; const SBGName: String; SBGTyp: TTextureType; + const Caption: string; 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 + SelectsS[S].Texture := Texture.GetTexture(Name, Typ, RGBFloatToInt(ColR, ColG, ColB)) + else + SelectsS[S].Texture := Texture.GetTexture(Name, Typ); + SelectsS[S].X := X; + SelectsS[S].Y := Y; + SelectsS[S].W := W; + SelectsS[S].H := H; + + SelectsS[S].ColR := ColR; + SelectsS[S].ColG := ColG; + SelectsS[S].ColB := ColB; + SelectsS[S].Int := Int; + SelectsS[S].DColR := DColR; + SelectsS[S].DColG := DColG; + SelectsS[S].DColB := DColB; + SelectsS[S].DInt := DInt; + + if (SBGTyp = TEXTURE_TYPE_COLORIZED) then + SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp, RGBFloatToInt(SBGColR, SBGColG, SBGColB)) + else + SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp); + SelectsS[S].TextureSBG.X := X + W + SkipX; + SelectsS[S].TextureSBG.Y := Y; + //SelectsS[S].TextureSBG.W := 450; + SelectsS[S].SBGW := SBGW; + SelectsS[S].TextureSBG.H := H; + SelectsS[S].SBGColR := SBGColR; + SelectsS[S].SBGColG := SBGColG; + SelectsS[S].SBGColB := SBGColB; + SelectsS[S].SBGInt := SBGInt; + SelectsS[S].SBGDColR := SBGDColR; + SelectsS[S].SBGDColG := SBGDColG; + SelectsS[S].SBGDColB := SBGDColB; + SelectsS[S].SBGDInt := SBGDInt; + + 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 := 10; + 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 := 10; + 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 := 10; + 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: string); +begin + AddSelectSlideOption(High(SelectsS), AddText); +end; + +procedure TMenu.AddSelectSlideOption(SelectNo: Cardinal; const AddText: string); +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; Values: array of string; 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; +end; + +procedure TMenu.onShowFinish; +begin + // nothing +end; + +(* + * Wrapper for WideUpperCase. Needed because some plattforms have problems with + * unicode support. + *) +function TMenu.WideCharUpperCase(wchar: WideChar) : WideString; +begin + // On Linux and MacOSX the cwstring unit is necessary for Unicode function-calls. + // Otherwise you will get an EIntOverflow exception (thrown by unimplementedwidestring()). + // The Unicode manager cwstring does not work with MacOSX at the moment because + // of missing references to iconv. So we have to use Ansi... for the moment. + + {$IFNDEF DARWIN} + // The FPC implementation of WideUpperCase returns nil if wchar is #0 (e.g. if an arrow key is pressed) + if (wchar <> #0) then + Result := WideUpperCase(wchar) + else + Result := #0; + {$ELSE} + Result := AnsiUpperCase(wchar) + {$ENDIF} +end; + +(* + * Wrapper for WideUpperCase. Needed because some plattforms have problems with + * unicode support. + *) +function TMenu.WideStringUpperCase(wstring: WideString) : WideString; +begin + {$IFNDEF DARWIN} + Result := WideUpperCase(wstring) + {$ELSE} + Result := AnsiUpperCase(wstring); + {$ENDIF} +end; + +procedure TMenu.onHide; +begin + // nothing +end; + +function TMenu.ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; +begin + // nothing + Result := true; +end; + +procedure TMenu.SetAnimationProgress(Progress: real); +begin + // nothing +end; + +end. + diff --git a/src/menu/UMenuButton.pas b/src/menu/UMenuButton.pas new file mode 100644 index 00000000..60b92b9f --- /dev/null +++ b/src/menu/UMenuButton.pas @@ -0,0 +1,564 @@ +unit UMenuButton; + +interface + +{$I switches.inc} + +uses TextGL, UTexture, gl, UMenuText,SDL; + +type + CButton = class of TButton; + + TButton = class + protected + SelectBool: Boolean; + + FadeProgress: Real; + FadeLastTick: Cardinal; + + DeSelectW, + DeSelectH, + PosX, + PosY: Real; + + constructor Create(); overload; + + 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(Textura: TTexture); overload; + constructor Create(Textura, DSTexture: TTexture); overload; + destructor Destroy; override; + 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; + +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; + +// ***** 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; + + +destructor TButton.Destroy; +begin + inherited; +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..c700c812 --- /dev/null +++ b/src/menu/UMenuButtonCollection.pas @@ -0,0 +1,71 @@ +unit UMenuButtonCollection; + +interface + +{$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 I: Integer; +begin + inherited; + + //Set Visible for Every Button that is a Child of this ButtonCollection + if (Not Fade) then + For I := 0 to High(ScreenButton^) do + if (ScreenButton^[I].Parent = Parent) then + ScreenButton^[I].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/UMenuInteract.pas b/src/menu/UMenuInteract.pas new file mode 100644 index 00000000..e0b4fa11 --- /dev/null +++ b/src/menu/UMenuInteract.pas @@ -0,0 +1,16 @@ +unit UMenuInteract; + +interface + +{$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; + +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..76299e80 --- /dev/null +++ b/src/menu/UMenuSelectSlide.pas @@ -0,0 +1,355 @@ +unit UMenuSelectSlide; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses TextGL, + UTexture, + gl, + UMenuText; + +type + PSelectSlide = ^TSelectSlide; + TSelectSlide = class + private + SelectBool: boolean; + public + // objects + Text: TText; // Main text describing option + TextOpt: array of TText; // 3 texts in the position of possible options + TextOptT: array of string; // array of names for possible options + + Texture: TTexture; // Select Texture + TextureSBG: TTexture; // Background Selections Texture +// TextureS: array of TTexture; // Selections Texture (not used) + +// TextureArrowL: TTexture; // Texture for left arrow (not used yet) +// TextureArrowR: TTexture; // Texture for right arrow (not used yet) + + SelectOptInt: integer; + PData: ^integer; + + //For automatically Setting LineCount + Lines: Byte; + + //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; + end; + +implementation +uses UDrawTexture, math, ULog, SysUtils; + +// ------------ Select +constructor TSelectSlide.Create; +begin + inherited Create; + Text := TText.Create; + SetLength(TextOpt, 1); + TextOpt[0] := TText.Create; + + //Set Standard Width for Selections Background + SBGW := 450; + + Visible := True; + {SetLength(TextOpt, 3); + TextOpt[0] := TText.Create; + TextOpt[1] := TText.Create; + TextOpt[2] := TText.Create;} +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; + +{ for I := 0 to High(TextOpt) do begin + TextOpt[I].ColR := STColR; + TextOpt[I].ColG := STColG; + TextOpt[I].ColB := STColB; + TextOpt[I].Int := STInt; + end;} + + end else begin + Texture.ColR := DColR; + Texture.ColG := DColG; + Texture.ColB := DColB; + Texture.Int := DInt; + + Text.ColR := TDColR; + Text.ColG := TDColG; + Text.ColB := TDColB; + Text.Int := TDInt; + + TextureSBG.ColR := SBGDColR; + TextureSBG.ColG := SBGDColG; + TextureSBG.ColB := SBGDColB; + TextureSBG.Int := SBGDInt; + +{ for I := 0 to High(TextOpt) do begin + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + end;} + end; +end; + +procedure TSelectSlide.SetSelectOpt(Value: integer); +var + SO: integer; + Sel: 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; +// SetSelect(true); // reset all colors + + if (Length(TextOpt)>0) AND (Length(TextOptT)>0) then + begin + + if (Value <= 0) then + begin //First Option Selected + Value := 0; + + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(0); + end + else if (Value >= high(TextOptT)) then + begin //Last Option Selected + Value := high(TextOptT); + + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + end; + DoSelection(Lines-1); + end + else + begin + HalfL := Ceil((Lines-1)/2); + HalfR := Lines-1-HalfL; + + if (Value <= HalfL) then + begin //Selected Option is near to the left side + {HalfL := Value; + HalfR := Lines-1-HalfL;} + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(Value); + end + else if (Value > High(TextOptT)-HalfR) then + begin //Selected is too near to the right border + HalfR := high(TextOptT) - Value; + HalfL := Lines-1-HalfR; + //Change Texts + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := 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 := TextOptT[Value - HalfL + SO]; + end; + + DoSelection(HalfL); + end; + + end; + + end; + +end; + +procedure TSelectSlide.Draw; +var + SO: integer; +begin + if Visible then + begin + DrawTexture(Texture); + DrawTexture(TextureSBG); + + 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(0{Text.Style}); + SetFontSize(Text.Size); + maxlength := 0; + + for I := low(TextOptT) to high (TextOptT) do + begin + if (glTextWidth(PChar(TextOptT[I])) > maxlength) then + maxlength := glTextWidth(PChar(TextOptT[I])); + end; + + Lines := floor((TextureSBG.W-40) / (maxlength+7)); + if (Lines > Length(TextOptT)) then + Lines := Length(TextOptT); + + if (Lines <= 0) then + Lines := 1; + + //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].Align := 1; + TextOpt[I].Align := 0; + TextOpt[I].Visible := True; + + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + + //Generate Positions + //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); + if (I <> High(TextOpt)) OR (High(TextOpt) = 0) OR (Length(TextOptT) = Lines) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I + else + TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; + + TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; + + //Better Look with 2 Options + if (Lines=2) AND (Length(TextOptT)= 2) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; + end; +end; + +end. diff --git a/src/menu/UMenuStatic.pas b/src/menu/UMenuStatic.pas new file mode 100644 index 00000000..ac8fa2dc --- /dev/null +++ b/src/menu/UMenuStatic.pas @@ -0,0 +1,85 @@ +unit UMenuStatic; + +interface + +{$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..fecf936e --- /dev/null +++ b/src/menu/UMenuText.pas @@ -0,0 +1,350 @@ +unit UMenuText; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses TextGL, + UTexture, + gl, + math, + SysUtils, + SDL; + +type + TText = class + private + SelectBool: boolean; + TextString: string; + TextTiles: array of string; + + 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: string); + property Text: string read TextString write SetText; + + procedure DeleteLastL; //Procedure to Delete Last Letter + + procedure Draw; + constructor Create; overload; + constructor Create(X, Y: real; Tekst: string); overload; + constructor Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ: real); overload; + end; + +implementation + +uses UGraphic, + StrUtils; + +procedure TText.SetSelect(Value: boolean); +begin + SelectBool := Value; + + //Set Cursor Visible + SelectBlink := True; + STicks := SDL_GetTicks() div 550; +end; + +procedure TText.SetText(Value: string); +var + NextPos: Cardinal; //NextPos of a Space etc. + LastPos: Cardinal; //LastPos " + 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 = Length(Value)) then + NextPos := 0; + + isBreak := (NextPos = T3) AND (NextPos <> 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(PChar(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 + //ToDo + //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(PChar(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 + //ToDo + //AddBreak(LastBreak, LastBreak + 155); + end; + end; + //end; + Inc(FirstWord) + end; + //Add Ending + AddBreak(LastBreak, Length(Value)+1); +end; + +procedure TText.DeleteLastL; +var + S: string; + L: integer; +begin + S := TextString; + L := Length(S); + if (L > 0) then + SetLength(S, L-1); + + SetText(S); +end; + +procedure TText.Draw; +var + X2, Y2: real; + Text2: string; + I: integer; +begin + if Visible then + begin + SetFontStyle(Style); + SetFontSize(Size); + SetFontItalic(False); + + glColor4f(ColR*Int, ColG*Int, ColB*Int, Alpha); + + //Reflection + if Reflection = true then + SetFontReflection(true, ReflectionSpacing) + else + SetFontReflection(false,0); + + //if selected set blink... + if SelectBool then + begin + I := SDL_GetTicks() div 550; + if I <> STicks then + begin //Change Visability + STicks := I; + 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(pchar(Text2))/2; + 2: X2 := X - glTextWidth(pchar(Text2)); + end; + + SetFontPos(X2, Y); + glPrint(PChar(Text2)); + SetFontStyle(0); // reset to default + end + else + begin} + //now use allways: + //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 + 0: X2 := X + MoveX; + 1: X2 := X + MoveX - glTextWidth(pchar(Text2))/2; + 2: X2 := X + MoveX - glTextWidth(pchar(Text2)); + end; + + SetFontPos(X2, Y2); + + SetFontZ(Z); + + glPrint(PChar(Text2)); + + {if Size >= 10 then + Y2 := Y2 + Size * 2.8 + else} + if (Style = 1) then + Y2 := Y2 + Size * 2.8 + else + Y2 := Y2 + Size * 2.15; + end; + SetFontStyle(0); // reset to default + + //end; + end; +end; + +constructor TText.Create; +begin + Create(0, 0, ''); +end; + +constructor TText.Create(X, Y: real; Tekst: string); +begin + Create(X, Y, 0, 0, 10, 0, 0, 0, 0, Tekst, false, 0, 0); +end; + +constructor TText.Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ:real); +begin + inherited Create; + Alpha := 1; + X := ParX; + Y := ParY; + W := ParW; + Z := ParZ; + Style := ParStyle; + Size := ParSize; + Text := ParTekst; + ColR := ParColR; + ColG := ParColG; + ColB := ParColB; + Int := 1; + Align := ParAlign; + SelectBool := false; + Visible := true; + Reflection:= ParReflection; + ReflectionSpacing:= ParReflectionSpacing; +end; + +end. -- cgit v1.2.3 From 1ef212ba89e50965b6b3b2d756be2c17e110b3ee Mon Sep 17 00:00:00 2001 From: tobigun Date: Sat, 6 Sep 2008 09:53:53 +0000 Subject: Delphi-mode set for FPC git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1348 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDrawTexture.pas | 4 ++++ src/menu/UMenuButton.pas | 11 ++++++++++- src/menu/UMenuButtonCollection.pas | 4 ++++ src/menu/UMenuInteract.pas | 4 ++++ src/menu/UMenuStatic.pas | 8 +++++++- 5 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDrawTexture.pas b/src/menu/UDrawTexture.pas index a7dde18f..3ea1c5eb 100644 --- a/src/menu/UDrawTexture.pas +++ b/src/menu/UDrawTexture.pas @@ -2,6 +2,10 @@ unit UDrawTexture; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + {$I switches.inc} uses UTexture; diff --git a/src/menu/UMenuButton.pas b/src/menu/UMenuButton.pas index 60b92b9f..3d7442c0 100644 --- a/src/menu/UMenuButton.pas +++ b/src/menu/UMenuButton.pas @@ -2,9 +2,18 @@ unit UMenuButton; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + {$I switches.inc} -uses TextGL, UTexture, gl, UMenuText,SDL; +uses + TextGL, + UTexture, + gl, + UMenuText, + SDL; type CButton = class of TButton; diff --git a/src/menu/UMenuButtonCollection.pas b/src/menu/UMenuButtonCollection.pas index c700c812..1e36a565 100644 --- a/src/menu/UMenuButtonCollection.pas +++ b/src/menu/UMenuButtonCollection.pas @@ -2,6 +2,10 @@ unit UMenuButtonCollection; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + {$I switches.inc} uses UMenuButton; diff --git a/src/menu/UMenuInteract.pas b/src/menu/UMenuInteract.pas index e0b4fa11..a81a41c4 100644 --- a/src/menu/UMenuInteract.pas +++ b/src/menu/UMenuInteract.pas @@ -2,6 +2,10 @@ unit UMenuInteract; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + {$I switches.inc} type diff --git a/src/menu/UMenuStatic.pas b/src/menu/UMenuStatic.pas index ac8fa2dc..93ee9fa6 100644 --- a/src/menu/UMenuStatic.pas +++ b/src/menu/UMenuStatic.pas @@ -2,9 +2,15 @@ unit UMenuStatic; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + {$I switches.inc} -uses UTexture, gl; +uses + UTexture, + gl; type TStatic = class -- cgit v1.2.3 From 688182ae4f56aabaf12233f32763274286c5d634 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 21 Sep 2008 11:34:25 +0000 Subject: missing files commited Equalizer now loads reflection settings from theme old equalizer methods removed git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1388 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuEqualizer.pas | 285 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 src/menu/UMenuEqualizer.pas (limited to 'src/menu') diff --git a/src/menu/UMenuEqualizer.pas b/src/menu/UMenuEqualizer.pas new file mode 100644 index 00000000..8cff606d --- /dev/null +++ b/src/menu/UMenuEqualizer.pas @@ -0,0 +1,285 @@ +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(H: Single): Single; + begin + Result := (Alpha * 0.3) *(1 - H/(Bands * (W + 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); + glVertex3f(PosX, Diff + Y+H + ReflectionSpacing, Z); + glVertex3f(PosX+W, Diff + Y+H + ReflectionSpacing, Z); + glVertex3f(PosX+W, Diff + Y + ReflectionSpacing, Z); + glColorRGB(Color, GetAlpha(Diff + H)); + 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 -- cgit v1.2.3 From dbf39d5bfc56c24a67d481187c619dc84828221f Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Tue, 23 Sep 2008 21:17:22 +0000 Subject: gpl header added and property svn:header set to "HeadURL Id" git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1403 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 25 ++ src/menu/UDrawTexture.pas | 25 ++ src/menu/UMenu.pas | 25 ++ src/menu/UMenuButton.pas | 25 ++ src/menu/UMenuButtonCollection.pas | 25 ++ src/menu/UMenuEqualizer.pas | 593 +++++++++++++++++++------------------ src/menu/UMenuInteract.pas | 25 ++ src/menu/UMenuSelectSlide.pas | 25 ++ src/menu/UMenuStatic.pas | 25 ++ src/menu/UMenuText.pas | 25 ++ 10 files changed, 534 insertions(+), 284 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 2b10b2c6..0f8344d7 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UDrawTexture.pas b/src/menu/UDrawTexture.pas index 3ea1c5eb..cb4daa61 100644 --- a/src/menu/UDrawTexture.pas +++ b/src/menu/UDrawTexture.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index e352febd..ccc22688 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UMenuButton.pas b/src/menu/UMenuButton.pas index 3d7442c0..a0cdaeef 100644 --- a/src/menu/UMenuButton.pas +++ b/src/menu/UMenuButton.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UMenuButtonCollection.pas b/src/menu/UMenuButtonCollection.pas index 1e36a565..3cf22417 100644 --- a/src/menu/UMenuButtonCollection.pas +++ b/src/menu/UMenuButtonCollection.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UMenuEqualizer.pas b/src/menu/UMenuEqualizer.pas index 8cff606d..438c1c03 100644 --- a/src/menu/UMenuEqualizer.pas +++ b/src/menu/UMenuEqualizer.pas @@ -1,285 +1,310 @@ -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(H: Single): Single; - begin - Result := (Alpha * 0.3) *(1 - H/(Bands * (W + 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); - glVertex3f(PosX, Diff + Y+H + ReflectionSpacing, Z); - glVertex3f(PosX+W, Diff + Y+H + ReflectionSpacing, Z); - glVertex3f(PosX+W, Diff + Y + ReflectionSpacing, Z); - glColorRGB(Color, GetAlpha(Diff + H)); - 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; - - - +{* 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(H: Single): Single; + begin + Result := (Alpha * 0.3) *(1 - H/(Bands * (W + 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); + glVertex3f(PosX, Diff + Y+H + ReflectionSpacing, Z); + glVertex3f(PosX+W, Diff + Y+H + ReflectionSpacing, Z); + glVertex3f(PosX+W, Diff + Y + ReflectionSpacing, Z); + glColorRGB(Color, GetAlpha(Diff + H)); + 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 index a81a41c4..4c2d4e86 100644 --- a/src/menu/UMenuInteract.pas +++ b/src/menu/UMenuInteract.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 76299e80..79c11ac7 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UMenuStatic.pas b/src/menu/UMenuStatic.pas index 93ee9fa6..9a10fade 100644 --- a/src/menu/UMenuStatic.pas +++ b/src/menu/UMenuStatic.pas @@ -1,3 +1,28 @@ +{* 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 diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index fecf936e..597210a6 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -1,3 +1,28 @@ +{* 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 -- cgit v1.2.3 From 015b6c092b0779ee9b53ed1ee78044737f8dc592 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Tue, 23 Sep 2008 21:43:52 +0000 Subject: indentation unified, no code change. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1406 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDrawTexture.pas | 3 ++- src/menu/UMenu.pas | 15 +++++++++++++-- src/menu/UMenuButtonCollection.pas | 3 ++- src/menu/UMenuEqualizer.pas | 4 +++- src/menu/UMenuSelectSlide.pas | 9 +++++---- src/menu/UMenuText.pas | 13 +++++++------ 6 files changed, 32 insertions(+), 15 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDrawTexture.pas b/src/menu/UDrawTexture.pas index cb4daa61..2f3e4abe 100644 --- a/src/menu/UDrawTexture.pas +++ b/src/menu/UDrawTexture.pas @@ -33,7 +33,8 @@ interface {$I switches.inc} -uses UTexture; +uses + UTexture; procedure DrawLine(X1, Y1, X2, Y2, ColR, ColG, ColB: real); procedure DrawQuad(X, Y, W, H, ColR, ColG, ColB: real); diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index ccc22688..dd182d5f 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -33,8 +33,19 @@ interface {$I switches.inc} -uses gl, SysUtils, UTexture, UMenuStatic, UMenuText, UMenuButton, UMenuSelectSlide, - UMenuInteract, UThemes, UMenuButtonCollection, Math, UMusic; +uses + gl, + SysUtils, + UTexture, + UMenuStatic, + UMenuText, + UMenuButton, + UMenuSelectSlide, + UMenuInteract, + UThemes, + UMenuButtonCollection, + Math, + UMusic; type { Int16 = SmallInt;} diff --git a/src/menu/UMenuButtonCollection.pas b/src/menu/UMenuButtonCollection.pas index 3cf22417..c6c6dd81 100644 --- a/src/menu/UMenuButtonCollection.pas +++ b/src/menu/UMenuButtonCollection.pas @@ -33,7 +33,8 @@ interface {$I switches.inc} -uses UMenuButton; +uses + UMenuButton; type //---------------- diff --git a/src/menu/UMenuEqualizer.pas b/src/menu/UMenuEqualizer.pas index 438c1c03..75a75439 100644 --- a/src/menu/UMenuEqualizer.pas +++ b/src/menu/UMenuEqualizer.pas @@ -33,7 +33,9 @@ interface {$I switches.inc} -uses UMusic, UThemes; +uses + UMusic, + UThemes; type //---------------- diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 79c11ac7..4779094c 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -33,10 +33,11 @@ interface {$I switches.inc} -uses TextGL, - UTexture, - gl, - UMenuText; +uses + TextGL, + UTexture, + gl, + UMenuText; type PSelectSlide = ^TSelectSlide; diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index 597210a6..bc3d5ebd 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -33,12 +33,13 @@ interface {$I switches.inc} -uses TextGL, - UTexture, - gl, - math, - SysUtils, - SDL; +uses + TextGL, + UTexture, + gl, + math, + SysUtils, + SDL; type TText = class -- cgit v1.2.3 From 2b99e27aee7efb65f25b2444e6b574c8c66b7e2e Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Tue, 23 Sep 2008 22:17:59 +0000 Subject: indentation, no code change git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1409 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDrawTexture.pas | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDrawTexture.pas b/src/menu/UDrawTexture.pas index 2f3e4abe..92837fab 100644 --- a/src/menu/UDrawTexture.pas +++ b/src/menu/UDrawTexture.pas @@ -37,23 +37,26 @@ uses UTexture; procedure DrawLine(X1, Y1, X2, Y2, ColR, ColG, ColB: real); -procedure DrawQuad(X, Y, W, H, ColR, ColG, ColB: real); +procedure DrawQuad(X, Y, W, H, ColR, ColG, ColB: real); procedure DrawTexture(Texture: TTexture); implementation -uses gl; +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); + 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); @@ -65,13 +68,16 @@ begin 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; + 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 + with Texture do + begin // rysuje paski gracza glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha); glEnable(GL_TEXTURE_2D); @@ -92,7 +98,8 @@ begin y2 := y+h*scaleH; y3 := y+h*scaleH; y4 := y; - if Rot <> 0 then begin + if Rot <> 0 then + begin xt1 := x1 - (x + w/2); xt2 := x2 - (x + w/2); xt3 := x3 - (x + w/2); @@ -114,12 +121,14 @@ begin end; -{ glBegin(GL_QUADS); +{ + 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;} + glEnd; +} glBegin(GL_QUADS); glTexCoord2f(TexX1*TexW, TexY1*TexH); glVertex3f(x1, y1, z); -- cgit v1.2.3 From ab1423bcf52ec322218fa6a7351795da38e16da5 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Tue, 23 Sep 2008 22:24:27 +0000 Subject: indentation, no code change git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1410 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDrawTexture.pas | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDrawTexture.pas b/src/menu/UDrawTexture.pas index 92837fab..33082765 100644 --- a/src/menu/UDrawTexture.pas +++ b/src/menu/UDrawTexture.pas @@ -46,7 +46,6 @@ uses gl; procedure DrawLine(X1, Y1, X2, Y2, ColR, ColG, ColB: real); - begin glColor3f(ColR, ColG, ColB); glBegin(GL_LINES); @@ -56,7 +55,6 @@ begin end; procedure DrawQuad(X, Y, W, H, ColR, ColG, ColB: real); - begin glColor3f(ColR, ColG, ColB); glBegin(GL_QUADS); @@ -68,13 +66,11 @@ begin 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 -- cgit v1.2.3 From c304618403c21aca88ce6bd4d019a78030402ca4 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 24 Sep 2008 16:09:39 +0000 Subject: fixed some bugs in equalizer reflection git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1415 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuEqualizer.pas | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuEqualizer.pas b/src/menu/UMenuEqualizer.pas index 75a75439..6d77721c 100644 --- a/src/menu/UMenuEqualizer.pas +++ b/src/menu/UMenuEqualizer.pas @@ -194,9 +194,12 @@ procedure Tms_Equalizer.Draw; I, J: Integer; Diff: Real; - Function GetAlpha(H: Single): Single; + Function GetAlpha(Diff: Single): Single; begin - Result := (Alpha * 0.3) *(1 - H/(Bands * (W + Space))); + 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 @@ -241,7 +244,7 @@ begin glVertex3f(PosX+W, PosY, Z); glEnd; - If (Reflection) AND (J < BandLength div 2) then + If (Reflection) AND (J <= BandLength div 2) then begin Diff := (Y-PosY) + H; @@ -251,10 +254,14 @@ 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); - glColorRGB(Color, GetAlpha(Diff + H)); glEnd; end else -- cgit v1.2.3 From cbf062e0f808c56c51932a06ae015db764d0e056 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 28 Sep 2008 14:00:53 +0000 Subject: Adding hints to possible endian related problems. No code change, yet. Only suggestions for test. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1420 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 0f8344d7..cd8241ae 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -336,6 +336,10 @@ begin 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); -- cgit v1.2.3 From 322b798413826681915eca1960f081cbc4dd302c Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Mon, 13 Oct 2008 14:14:32 +0000 Subject: Abstraction of the menus background 5 different bg types: none(fallback), colored, texture, video, and fade(for overlays) Some sideeffect is 5 mb less memory usage, don't know for which reasons :P git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1446 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 6 +- src/menu/UMenu.pas | 206 ++++++++++++++++++++++++++---------- src/menu/UMenuBackground.pas | 85 +++++++++++++++ src/menu/UMenuBackgroundColor.pas | 69 ++++++++++++ src/menu/UMenuBackgroundFade.pas | 172 ++++++++++++++++++++++++++++++ src/menu/UMenuBackgroundNone.pas | 68 ++++++++++++ src/menu/UMenuBackgroundTexture.pas | 122 +++++++++++++++++++++ src/menu/UMenuBackgroundVideo.pas | 204 +++++++++++++++++++++++++++++++++++ 8 files changed, 877 insertions(+), 55 deletions(-) create mode 100644 src/menu/UMenuBackground.pas create mode 100644 src/menu/UMenuBackgroundColor.pas create mode 100644 src/menu/UMenuBackgroundFade.pas create mode 100644 src/menu/UMenuBackgroundNone.pas create mode 100644 src/menu/UMenuBackgroundTexture.pas create mode 100644 src/menu/UMenuBackgroundVideo.pas (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index cd8241ae..ebd25e50 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -141,8 +141,10 @@ var begin Result := True; - glClearColor(1, 1, 1 , 0); - glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); + //We don't need this here anymore, + //Because the background care about cleaning the buffers + //glClearColor(1, 1, 1 , 0); + //glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); for S := 1 to Screens do begin diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index dd182d5f..9068e4cb 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -42,6 +42,7 @@ uses UMenuButton, UMenuSelectSlide, UMenuInteract, + UMenuBackground, UThemes, UMenuButtonCollection, Math, @@ -53,18 +54,16 @@ type PMenu = ^TMenu; TMenu = class protected - ButtonPos: Integer; + Background: TMenuBackground; Interactions: array of TInteract; SelInteraction: integer; + + ButtonPos: Integer; Button: array of TButton; + SelectsS: array of TSelectSlide; ButtonCollection: array of TButtonCollection; - BackImg: TTexture; - BackW: integer; - BackH: integer; - - fFileName : string; public Text: array of TText; Static: array of TStatic; @@ -94,7 +93,7 @@ type procedure AddButtonCollection(const ThemeCollection: TThemeButtonCollection; Const Num: Byte); // background - procedure AddBackground(Name: string); + procedure AddBackground(ThemedSettings: TThemeBackground); // static function AddStatic(ThemeStatic: TThemeStatic): integer; overload; @@ -191,10 +190,21 @@ uses UCommon, UDisplay, UCovers, UTime, - USkins; + USkins, + //Background types + UMenuBackgroundNone, + UMenuBackgroundColor, + UMenuBackgroundTexture, + UMenuBackgroundVideo, + UMenuBackgroundFade; destructor TMenu.Destroy; begin + If (Background <> nil) then + begin + Background.Destroy; + end; + //Log.LogError('Unloaded Succesful: ' + ClassName); inherited; end; @@ -207,10 +217,10 @@ begin SetLength(Static, 0); SetLength(Button, 0); - BackImg.TexNum := 0; - //Set ButtonPos to Autoset Length ButtonPos := -1; + + Background := nil; end; { constructor TMenu.Create(Back: String); @@ -314,7 +324,7 @@ begin PrepareButtonCollections(ThemeBasic.ButtonCollection); //Add Background - AddBackground(ThemeBasic.Background.Tex); + AddBackground(ThemeBasic.Background); //Add Statics and Texts for I := 0 to High(ThemeBasic.Static) do @@ -324,34 +334,141 @@ begin AddText(ThemeBasic.Text[I]); end; -procedure TMenu.AddBackground(Name: string); -//var -// lFileName : string; +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 - if Name <> '' then + If (Background <> nil) then begin - fFileName := Skin.GetTextureFileName(Name); - fFileName := AdaptFilePaths( fFileName ); + Background.Destroy; + Background := nil; + end; - if fileexists( fFileName ) then - begin - BackImg := Texture.GetTexture( fFileName , TEXTURE_TYPE_PLAIN); + Case ThemedSettings.BGType of + BGT_Auto: begin //Automaticly choose one out of BGT_Texture, BGT_Video or BGT_Color - if ( BackImg.TexNum = 0 ) then + If (Length(ThemedSettings.Tex) > 0) then begin - if VideoPlayback.Open( fFileName ) then + + //At first some intelligent try to decide which BG to load + FileExt := lowercase(ExtractFileExt(Skin.GetTextureFileName(ThemedSettings.Tex))); + + 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; + + BGT_Color: begin + try + Background := TMenuBackgroundColor.Create(ThemedSettings); + except + on E: EMenuBackgroundError do + begin + Log.LogError(E.Message); + freeandnil(Background); + end; + end; + end; + + BGT_Texture: begin + try + Background := TMenuBackgroundTexture.Create(ThemedSettings); + except + on E: EMenuBackgroundError do + begin + Log.LogError(E.Message); + freeandnil(Background); + end; + end; + end; + + BGT_Video: begin + try + Background := TMenuBackgroundVideo.Create(ThemedSettings); + except + on E: EMenuBackgroundError do + begin + Log.LogError(E.Message); + freeandnil(Background); + end; + end; + end; + + BGT_None: begin + try + Background := TMenuBackgroundNone.Create(ThemedSettings); + except + on E: EMenuBackgroundError do begin - VideoBGTimer.SetTime(0); - VideoPlayback.Play; + Log.LogError(E.Message); + freeandnil(Background); end; end; + end; - BackImg.W := 800; - BackImg.H := 600; - BackW := 1; - BackH := 1; + BGT_Fade: 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 = BGT_Color) then + Background := TMenuBackgroundNone.Create(ThemedSettings) + Else + Background := TMenuBackgroundColor.Create(ThemedSettings) + end; end; //---------------------- @@ -752,29 +869,7 @@ end; // Method to draw our TMenu and all his child buttons function TMenu.DrawBG: boolean; begin - BackImg.ColR := 1; - BackImg.ColG := 1; - BackImg.ColB := 1; - BackImg.TexX1 := 0; - BackImg.TexY1 := 0; - BackImg.TexX2 := 1; - BackImg.TexY2 := 1; - - if (BackImg.TexNum > 0) then - begin - BackImg.X := 0; - BackImg.Y := 0; - BackImg.Z := 0; // todo: eddie: to the opengl experts: please check this! On the mac z is not initialized??? - BackImg.W := 800; - BackImg.H := 600; - DrawTexture(BackImg); - end - else if (VideoPlayback <> nil) then - begin - VideoPlayback.GetFrame(VideoBGTimer.GetTime()); - // FIXME: why do we draw on screen 2? Seems to be wrong. - VideoPlayback.DrawGL(2); - end; + Background.Draw; Result := true; end; @@ -1391,7 +1486,7 @@ begin // 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 + {// check if a background texture was found if (BackImg.TexNum = 0) then begin // try to open an animated background @@ -1405,7 +1500,11 @@ begin VideoPlayback.Play; end; end; - end; + end; } + If (Background = nil) then + AddBackground(DEFAULTBACKGROUND); + + Background.OnShow; end; procedure TMenu.onShowFinish; @@ -1451,6 +1550,7 @@ end; procedure TMenu.onHide; begin // nothing + Background.OnFinish; end; function TMenu.ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; diff --git a/src/menu/UMenuBackground.pas b/src/menu/UMenuBackground.pas new file mode 100644 index 00000000..762faf34 --- /dev/null +++ b/src/menu/UMenuBackground.pas @@ -0,0 +1,85 @@ +{* 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; virtual; + 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..26385b44 --- /dev/null +++ b/src/menu/UMenuBackgroundColor.pas @@ -0,0 +1,69 @@ +{* 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; + +Constructor TMenuBackgroundColor.Create(const ThemedSettings: TThemeBackground); +begin + inherited; + Color := ThemedSettings.Color; +end; + +Procedure TMenuBackgroundColor.Draw; +begin + glClearColor(Color.R, Color.G, Color.B, 0); + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); +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..3bdd631e --- /dev/null +++ b/src/menu/UMenuBackgroundFade.pas @@ -0,0 +1,172 @@ +{* 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; + +//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; + +Constructor TMenuBackgroundFade.Create(const ThemedSettings: TThemeBackground); +var texFilename: String; +begin + inherited; + FadeTime := 0; + + Color := ThemedSettings.Color; + Alpha := ThemedSettings.Alpha; + If (Length(ThemedSettings.Tex) > 0) then + begin + texFilename := Skin.GetTextureFileName(ThemedSettings.Tex); + texFilename := AdaptFilePaths(texFilename); + 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 + 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 + 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..d4188395 --- /dev/null +++ b/src/menu/UMenuBackgroundNone.pas @@ -0,0 +1,68 @@ +{* 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; + +Constructor TMenuBackgroundNone.Create(const ThemedSettings: TThemeBackground); +begin + inherited; +end; + +Procedure TMenuBackgroundNone.Draw; +begin + //Do just nothing in here! + 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..55d1d0b6 --- /dev/null +++ b/src/menu/UMenuBackgroundTexture.pas @@ -0,0 +1,122 @@ +{* 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; + +//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; + +Constructor TMenuBackgroundTexture.Create(const ThemedSettings: TThemeBackground); +var texFilename: String; +begin + inherited; + + If (Length(ThemedSettings.Tex) = 0) then + raise EMenuBackgroundError.Create('TMenuBackgroundTexture: No texture filename present'); + + Color := ThemedSettings.Color; + + texFilename := Skin.GetTextureFileName(ThemedSettings.Tex); + texFilename := AdaptFilePaths(texFilename); + 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 + 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..a6d02828 --- /dev/null +++ b/src/menu/UMenuBackgroundVideo.pas @@ -0,0 +1,204 @@ +{* 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, + UVideo; + +//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: String): TBGVideo; + Procedure RemoveItem( + Procedure FreeAllItems; + + Destructor Destroy; + end; + +type } + TMenuBackgroundVideo = class (TMenuBackground) + private + fFilename: String; + 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, + UMusic, + SysUtils, + UTime, + USkins, + UCommon; + +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); + fFileName := AdaptFilePaths( fFileName ); + + if fileexists(fFilename) AND VideoPlayback.Open( fFileName ) then + begin + VideoBGTimer.SetTime(0); + VideoPlayback.Play; + end + else + raise EMenuBackgroundError.Create('TMenuBackgroundVideo: Can''t load background video: ' + fFilename); +end; + +Destructor TMenuBackgroundVideo.Destroy; +begin + +end; + + +Procedure TMenuBackgroundVideo.OnShow; +begin + if VideoPlayback.Open( fFileName ) then + begin + VideoBGTimer.SetTime(0); + VideoPlayback.Play; + end; +end; + +Procedure TMenuBackgroundVideo.OnFinish; +begin + +end; + + +Procedure TMenuBackgroundVideo.Draw; +begin + glClear(GL_DEPTH_BUFFER_BIT); + + VideoPlayback.GetFrame(VideoBGTimer.GetTime()); + // FIXME: why do we draw on screen 2? Seems to be wrong. + VideoPlayback.DrawGL(2); +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: String): TBGVideo; +begin + +end; + +Procedure TBGVideoPool.FreeAllItems; +begin + +end; } + +end. -- cgit v1.2.3 From e60c0d3e29be2c77e7ab8deca6c37d0b07ebf085 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sat, 18 Oct 2008 21:13:16 +0000 Subject: style adjustments. no code change. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1456 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 275 ++++++++++++++++++------------------ src/menu/UMenuBackground.pas | 22 ++- src/menu/UMenuBackgroundColor.pas | 8 +- src/menu/UMenuBackgroundFade.pas | 46 +++--- src/menu/UMenuBackgroundNone.pas | 8 +- src/menu/UMenuBackgroundTexture.pas | 18 +-- src/menu/UMenuBackgroundVideo.pas | 68 +++++---- 7 files changed, 222 insertions(+), 223 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 9068e4cb..c4e0ece6 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -59,9 +59,9 @@ type Interactions: array of TInteract; SelInteraction: integer; - ButtonPos: Integer; + ButtonPos: integer; Button: array of TButton; - + SelectsS: array of TSelectSlide; ButtonCollection: array of TButtonCollection; public @@ -73,7 +73,6 @@ type Fade: integer; // fade type ShowFinish: boolean; // true if there is no fade - destructor Destroy; override; constructor Create; overload; virtual; //constructor Create(Back: string); overload; virtual; // Back is a JPG resource name for background @@ -90,7 +89,7 @@ type procedure LoadFromTheme(const ThemeBasic: TThemeBasic); procedure PrepareButtonCollections(const Collections: AThemeButtonCollection); - procedure AddButtonCollection(const ThemeCollection: TThemeButtonCollection; Const Num: Byte); + procedure AddButtonCollection(const ThemeCollection: TThemeButtonCollection; const Num: byte); // background procedure AddBackground(ThemedSettings: TThemeBackground); @@ -103,20 +102,20 @@ type function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; overload; function AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; overload; function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; overload; - function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: Boolean; ReflectionSpacing: Real): integer; overload; + function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: boolean; ReflectionSpacing: real): integer; overload; // text function AddText(ThemeText: TThemeText): integer; overload; function AddText(X, Y: real; const Text_: string): integer; overload; function AddText(X, Y: real; Style: integer; Size, ColR, ColG, ColB: real; const Text: string): integer; overload; - function AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; const Text_: string; Reflection_: Boolean; ReflectionSpacing_: Real; Z : Real): integer; overload; + function AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; const Text_: string; 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 + 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 Name: String): integer; overload; - function AddButton(X, Y, W, H: real; const Name: String; Typ: TTextureType; Reflection: Boolean): integer; overload; - function AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; const Name: String; Typ: TTextureType; Reflection: Boolean; ReflectionSpacing, DeSelectReflectionSpacing: Real): integer; overload; + function AddButton(X, Y, W, H: real; const Name: string): integer; overload; + function AddButton(X, Y, W, H: real; const Name: string; Typ: TTextureType; Reflection: boolean): integer; overload; + function AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; const Name: string; Typ: TTextureType; Reflection: boolean; ReflectionSpacing, DeSelectReflectionSpacing: real): integer; overload; procedure ClearButtons; procedure AddButtonText(AddX, AddY: real; const AddText: string); overload; procedure AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: string); overload; @@ -129,10 +128,10 @@ type 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 Name: String; Typ: TTextureType; const SBGName: String; SBGTyp: TTextureType; + const Name: string; Typ: TTextureType; const SBGName: string; SBGTyp: TTextureType; const Caption: string; var Data: integer): integer; overload; procedure AddSelectSlideOption(const AddText: string); overload; - procedure AddSelectSlideOption(SelectNo: Cardinal; const AddText: string); overload; + procedure AddSelectSlideOption(SelectNo: cardinal; const AddText: string); overload; procedure UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; SelectNum: integer; Values: array of string; var Data: integer); // function AddWidget(X, Y : UInt16; WidgetSrc : PSDL_Surface): Int16; @@ -140,23 +139,23 @@ type procedure FadeTo(Screen: PMenu); overload; procedure FadeTo(Screen: PMenu; aSound: TAudioPlaybackStream); overload; //popup hack - procedure CheckFadeTo(Screen: PMenu; msg: String); + procedure CheckFadeTo(Screen: PMenu; msg: string); function DrawBG: boolean; virtual; function DrawFG: boolean; virtual; function Draw: boolean; virtual; - function ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown : Boolean): Boolean; virtual; + function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown : boolean): boolean; virtual; // FIXME: ParseMouse is not implemented in any subclass and not even used anywhere in the code // -> do this before activation of this method - //function ParseMouse(Typ: integer; X: integer; Y: integer): Boolean; virtual; abstract; + //function ParseMouse(Typ: integer; X: integer; Y: integer): boolean; virtual; abstract; procedure onShow; virtual; procedure onShowFinish; virtual; procedure onHide; virtual; procedure SetAnimationProgress(Progress: real); virtual; - function IsSelectable(Int: Cardinal): Boolean; - + function IsSelectable(Int: cardinal): boolean; + procedure InteractNext; virtual; procedure InteractCustom(CustomSwitch: integer); virtual; procedure InteractPrev; virtual; @@ -200,7 +199,7 @@ uses UCommon, destructor TMenu.Destroy; begin - If (Background <> nil) then + if (Background <> nil) then begin Background.Destroy; end; @@ -223,21 +222,23 @@ begin Background := nil; end; { -constructor TMenu.Create(Back: String); +constructor TMenu.Create(Back: string); begin inherited Create; - if Back <> '' then begin + 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 + end + else BackImg.TexNum := 0; - //Set ButtonPos to Autoset Length + //Set ButtonPos to Autoset Length ButtonPos := -1; end; @@ -250,7 +251,7 @@ begin BackH := H; end; } -function RGBFloatToInt(R, G, B: Double): Cardinal; +function RGBFloatToInt(R, G, B: Double): cardinal; begin Result := (Trunc(255 * R) shl 16) or (Trunc(255 * G) shl 8) or @@ -259,7 +260,7 @@ end; procedure TMenu.AddInteraction(Typ, Num: integer); var - IntNum: integer; + IntNum: integer; begin IntNum := Length(Interactions); SetLength(Interactions, IntNum+1); @@ -270,8 +271,8 @@ end; procedure TMenu.SetInteraction(Num: integer); var - OldNum, OldTyp: integer; - NewNum, NewTyp: integer; + OldNum, OldTyp: integer; + NewNum, NewTyp: integer; begin // set inactive OldNum := Interactions[Interaction].Num; @@ -281,32 +282,32 @@ begin NewTyp := Interactions[Num].Typ; case OldTyp of - iButton: Button[OldNum].Selected := False; - iText: Text[OldNum].Selected := False; - iSelectS: SelectsS[OldNum].Selected := False; + iButton: Button[OldNum].Selected := false; + iText: Text[OldNum].Selected := false; + iSelectS: SelectsS[OldNum].Selected := false; //Button Collection Mod iBCollectionChild: begin - Button[OldNum].Selected := False; - + 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; + 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; + 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; + Button[NewNum].Selected := true; + ButtonCollection[Button[NewNum].Parent-1].Selected := true; end; end; end; @@ -317,7 +318,7 @@ end; //---------------------- procedure TMenu.LoadFromTheme(const ThemeBasic: TThemeBasic); var - I: Integer; + I: integer; begin //Add Button Collections (Set Button CollectionsLength) //Button Collections are Created when the first ChildButton is Created @@ -336,24 +337,24 @@ end; procedure TMenu.AddBackground(ThemedSettings: TThemeBackground); var - FileExt: String; + FileExt: string; - Function IsInArray(const Piece: String; const A: Array of String): Boolean; - var I: Integer; + 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 + Result := false; + + for I := 0 to High(A) do + if (A[I] = Piece) then begin - Result := True; + Result := true; Exit; end; end; - Function TryBGCreate(Typ: cMenuBackground): Boolean; + Function TryBGCreate(Typ: cMenuBackground): boolean; begin - Result := True; + Result := true; try Background := Typ.Create(ThemedSettings); @@ -361,12 +362,13 @@ procedure TMenu.AddBackground(ThemedSettings: TThemeBackground); on E: EMenuBackgroundError do begin //Background failes to create Freeandnil(Background); - Result := False; + Result := false; end; end; end; + begin - If (Background <> nil) then + if (Background <> nil) then begin Background.Destroy; Background := nil; @@ -375,21 +377,20 @@ begin Case ThemedSettings.BGType of BGT_Auto: begin //Automaticly choose one out of BGT_Texture, BGT_Video or BGT_Color - If (Length(ThemedSettings.Tex) > 0) then + if (Length(ThemedSettings.Tex) > 0) then begin //At first some intelligent try to decide which BG to load FileExt := lowercase(ExtractFileExt(Skin.GetTextureFileName(ThemedSettings.Tex))); - If IsInArray(FileExt, SUPPORTED_EXTS_BACKGROUNDTEXTURE) then + if IsInArray(FileExt, SUPPORTED_EXTS_BACKGROUNDTEXTURE) then TryBGCreate(TMenuBackgroundTexture) - Else If IsInArray(FileExt, SUPPORTED_EXTS_BACKGROUNDVIDEO) then + 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 + if (Background = nil) then begin //Try Textured Bg if not TryBGCreate(TMenuBackgroundTexture) then @@ -462,11 +463,11 @@ begin end; //Fallback to None Background or Colored Background - If (Background = nil) then + if (Background = nil) then begin - If (ThemedSettings.BGType = BGT_Color) then + if (ThemedSettings.BGType = BGT_Color) then Background := TMenuBackgroundNone.Create(ThemedSettings) - Else + else Background := TMenuBackgroundColor.Create(ThemedSettings) end; end; @@ -477,10 +478,10 @@ end; //---------------------- procedure TMenu.PrepareButtonCollections(const Collections: AThemeButtonCollection); var - I: Integer; + I: integer; begin SetLength(ButtonCollection, Length(Collections)); - For I := 0 to High(ButtonCollection) do + for I := 0 to High(ButtonCollection) do AddButtonCollection(Collections[I], I); end; @@ -488,10 +489,10 @@ end; //AddButtonCollection: //Create a Button Collection; //---------------------- -procedure TMenu.AddButtonCollection(const ThemeCollection: TThemeButtonCollection; Const Num: Byte); +procedure TMenu.AddButtonCollection(const ThemeCollection: TThemeButtonCollection; const Num: byte); var - BT, BTLen: Integer; - TempCol, TempDCol: Cardinal; + BT, BTLen: integer; + TempCol, TempDCol: cardinal; begin if (Num > High(ButtonCollection)) then @@ -528,7 +529,8 @@ begin 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 + 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; @@ -560,15 +562,17 @@ begin begin ButtonCollection[Num].FadeTex := Texture.GetTexture( Skin.GetTextureFileName(ThemeCollection.Style.FadeTex), TEXTURE_TYPE_COLORIZED, TempCol) - end else begin + 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 + 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, @@ -602,7 +606,7 @@ end; function TMenu.AddStatic(X, Y, W, H: real; const Name: string; Typ: TTextureType): integer; var - StatNum: integer; + StatNum: integer; begin // adds static StatNum := Length(Static); @@ -625,12 +629,12 @@ end; function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; begin - Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, 0, 0, 1, 1, Name, Typ, Color, False, 0); + Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, 0, 0, 1, 1, Name, Typ, Color, false, 0); end; -function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: Boolean; ReflectionSpacing: Real): integer; +function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: boolean; ReflectionSpacing: real): integer; var - StatNum: integer; + StatNum: integer; begin // adds static StatNum := Length(Static); @@ -681,7 +685,7 @@ end; function TMenu.AddText(X, Y: real; const Text_: string): integer; var - TextNum: integer; + TextNum: integer; begin // adds text TextNum := Length(Text); @@ -695,9 +699,9 @@ 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_: string; Reflection_: Boolean; ReflectionSpacing_: Real; Z : Real): integer; +function TMenu.AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; const Text_: string; Reflection_: boolean; ReflectionSpacing_: real; Z : real): integer; var - TextNum: integer; + TextNum: integer; begin // adds text TextNum := Length(Text); @@ -706,8 +710,8 @@ begin Result := TextNum; end; -//Function that Set Length of Button Array in one Step instead of register new Memory for every Button -Procedure TMenu.SetButtonLength(Length: Cardinal); +//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 @@ -719,12 +723,11 @@ begin 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; + BT: integer; + BTLen: integer; begin Result := AddButton(ThemeButton.X, ThemeButton.Y, ThemeButton.W, ThemeButton.H, ThemeButton.ColR, ThemeButton.ColG, ThemeButton.ColB, ThemeButton.Int, @@ -773,7 +776,7 @@ begin if (@ButtonCollection[ThemeButton.Parent-1] <> nil) then begin Interactions[High(Interactions)].Typ := iBCollectionChild; - Button[Result].Visible := False; + Button[Result].Visible := false; for BT := 0 to BTLen-1 do Button[Result].Text[BT].Alpha := 0; @@ -787,19 +790,19 @@ begin Log.LogBenchmark('====> Screen Options32', 6); end; -function TMenu.AddButton(X, Y, W, H: real; const Name: String): integer; +function TMenu.AddButton(X, Y, W, H: real; const Name: string): integer; begin - Result := AddButton(X, Y, W, H, Name, TEXTURE_TYPE_PLAIN, False); + Result := AddButton(X, Y, W, H, Name, TEXTURE_TYPE_PLAIN, false); end; -function TMenu.AddButton(X, Y, W, H: real; const Name: String; Typ: TTextureType; Reflection: Boolean): integer; +function TMenu.AddButton(X, Y, W, H: real; const Name: string; Typ: TTextureType; Reflection: boolean): integer; begin Result := AddButton(X, Y, W, H, 1, 1, 1, 1, 1, 1, 1, 0.5, Name, TEXTURE_TYPE_PLAIN, Reflection, 15, 15); end; function TMenu.AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; - const Name: String; Typ: TTextureType; - Reflection: Boolean; ReflectionSpacing, DeSelectReflectionSpacing: Real): integer; + const Name: string; Typ: TTextureType; + Reflection: boolean; ReflectionSpacing, DeSelectReflectionSpacing: real): integer; begin // adds button //SetLength is used once to reduce Memory usement @@ -855,7 +858,6 @@ begin //Button Collection Mod Button[Result].Parent := 0; - // adds interaction AddInteraction(iButton, Result); Interaction := 0; @@ -876,7 +878,7 @@ end; function TMenu.DrawFG: boolean; var - J: Integer; + J: integer; begin // We don't forget about newly implemented static for nice skin ... for J := 0 to Length(Static) - 1 do @@ -900,7 +902,7 @@ begin // Third, we draw all our widgets // for J := 0 to Length(WidgetsSrc) - 1 do // SDL_BlitSurface(WidgetsSrc[J], nil, ParentBackBuf, WidgetsRect[J]); - Result := True; + Result := true; end; function TMenu.Draw: boolean; @@ -959,9 +961,9 @@ begin end; } -function TMenu.IsSelectable(Int: Cardinal): Boolean; +function TMenu.IsSelectable(Int: cardinal): boolean; begin - Result := True; + Result := true; case Interactions[Int].Typ of //Button iButton: Result := Button[Interactions[Int].Num].Visible and Button[Interactions[Int].Num].Selectable; @@ -980,7 +982,7 @@ end; // this behaviour doesn't make sense for two rows of buttons procedure TMenu.InteractPrevRow; var - Int: integer; + 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 @@ -996,7 +998,7 @@ end; procedure TMenu.InteractNextRow; var - Int: integer; + Int: integer; begin Int := Interaction; @@ -1046,22 +1048,23 @@ begin Interaction := Int end; - procedure TMenu.InteractCustom(CustomSwitch: integer); { needed only for below var - Num: integer; - Typ: integer; - Again: boolean; + 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 + {then + begin CustomSwitch:= CustomSwitch*(-1); Again := true; // change interaction as long as it's needed - while (Again = true) do begin + while (Again = true) do + begin Num := SelInteraction - CustomSwitch; if Num = -1 then Num := High(Interactions); Interaction := Num; @@ -1073,34 +1076,36 @@ begin case Typ of iButton: begin - if Button[Num].Selectable = false then Again := True; + if Button[Num].Selectable = false then + Again := true; end; end; // case end; // while end - else if num>0 then begin + else if num>0 then + begin Again := true; // change interaction as long as it's needed - while (Again = true) do begin + 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; + if Button[Num].Selectable = false then + Again := true; end; end; // case end; // while end } end; - procedure TMenu.FadeTo(Screen: PMenu); begin Display.Fade := 0; @@ -1113,13 +1118,12 @@ begin AudioPlayback.PlaySound( aSound ); end; - //popup hack -procedure TMenu.CheckFadeTo(Screen: PMenu; msg: String); +procedure TMenu.CheckFadeTo(Screen: PMenu; msg: string); begin Display.Fade := 0; Display.NextScreenWithCheck := Screen; - Display.CheckOK:=False; + Display.CheckOK := false; ScreenPopupCheck.ShowPopup(msg); end; @@ -1130,9 +1134,10 @@ end; procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: string); var - Il: integer; + Il: integer; begin - with Button[High(Button)] do begin + with Button[High(Button)] do + begin Il := Length(Text); SetLength(Text, Il+1); Text[Il] := TText.Create(X + AddX, Y + AddY, AddText); @@ -1145,9 +1150,10 @@ end; procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); var - Il: integer; + Il: integer; begin - with Button[High(Button)] do begin + with Button[High(Button)] do + begin Il := Length(Text); SetLength(Text, Il+1); Text[Il] := TText.Create(X + AddX, Y + AddY, AddText); @@ -1163,9 +1169,10 @@ end; procedure TMenu.AddButtonText(CustomButton: TButton; AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); var - Il: integer; + Il: integer; begin - with CustomButton do begin + with CustomButton do + begin Il := Length(Text); SetLength(Text, Il+1); Text[Il] := TText.Create(X + AddX, Y + AddY, AddText); @@ -1179,10 +1186,9 @@ begin end; end; - function TMenu.AddSelectSlide(ThemeSelectS: TThemeSelectSlide; var Data: integer; Values: array of string): integer; var - SO: integer; + 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, @@ -1214,11 +1220,11 @@ function TMenu.AddSelectSlide(X, Y, W, H, SkipX, SBGW, ColR, ColG, ColB, Int, DC 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 Name: String; Typ: TTextureType; const SBGName: String; SBGTyp: TTextureType; + const Name: string; Typ: TTextureType; const SBGName: string; SBGTyp: TTextureType; const Caption: string; var Data: integer): integer; var - S: integer; - I: integer; + S: integer; + I: integer; begin S := Length(SelectsS); SetLength(SelectsS, S + 1); @@ -1313,14 +1319,14 @@ begin SelectsS[S].SetSelect(false); {// Configures 3 select options - for I := 0 to 2 do begin + 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 := 10; 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; @@ -1328,7 +1334,6 @@ begin SelectsS[S].TextOpt[I].Visible := true; end;} - // adds interaction AddInteraction(iSelectS, S); Result := S; @@ -1339,12 +1344,12 @@ begin AddSelectSlideOption(High(SelectsS), AddText); end; -procedure TMenu.AddSelectSlideOption(SelectNo: Cardinal; const AddText: string); +procedure TMenu.AddSelectSlideOption(SelectNo: cardinal; const AddText: string); var - SO: integer; + SO: integer; begin SO := Length(SelectsS[SelectNo].TextOptT); - + SetLength(SelectsS[SelectNo].TextOptT, SO + 1); SelectsS[SelectNo].TextOptT[SO] := AddText; @@ -1355,7 +1360,7 @@ end; procedure TMenu.UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; SelectNum: integer; Values: array of string; var Data: integer); var - SO: integer; + SO: integer; begin SetLength(SelectsS[SelectNum].TextOptT, 0); for SO := 0 to High(Values) do @@ -1376,8 +1381,8 @@ end; procedure TMenu.InteractInc; var - Num: integer; - Value: integer; + Num: integer; + Value: integer; begin case Interactions[Interaction].Typ of iSelectS: begin @@ -1395,7 +1400,7 @@ begin begin //Select Next Button in Collection - For Num := 1 to High(Button) do + for Num := 1 to High(Button) do begin Value := (Interaction + Num) Mod Length(Button); if Value = 0 then @@ -1417,8 +1422,8 @@ end; procedure TMenu.InteractDec; var - Num: integer; - Value: integer; + Num: integer; + Value: integer; begin case Interactions[Interaction].Typ of iSelectS: begin @@ -1435,7 +1440,7 @@ begin iBCollectionChild: begin //Select Prev Button in Collection - For Num := High(Button) downto 1 do + for Num := High(Button) downto 1 do begin Value := (Interaction + Num) Mod Length(Button); if Value = High(Button) then @@ -1458,7 +1463,7 @@ begin 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 + for Num := High(Button) downto 1 do begin Value := (Interaction + Num) Mod Length(Button); if (Button[Value].Parent = Button[Interaction].Parent) then @@ -1484,7 +1489,7 @@ begin // 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. + // At the moment videos cannot be turned off without restarting USDX. {// check if a background texture was found if (BackImg.TexNum = 0) then @@ -1501,7 +1506,7 @@ begin end; end; end; } - If (Background = nil) then + if (Background = nil) then AddBackground(DEFAULTBACKGROUND); Background.OnShow; @@ -1553,7 +1558,7 @@ begin Background.OnFinish; end; -function TMenu.ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; +function TMenu.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; begin // nothing Result := true; diff --git a/src/menu/UMenuBackground.pas b/src/menu/UMenuBackground.pas index 762faf34..6a73b621 100644 --- a/src/menu/UMenuBackground.pas +++ b/src/menu/UMenuBackground.pas @@ -45,39 +45,37 @@ uses type EMenuBackgroundError = class(Exception); TMenuBackground = class - Constructor Create(const ThemedSettings: TThemeBackground); virtual; - Procedure OnShow; virtual; - Procedure Draw; virtual; - Procedure OnFinish; virtual; - Destructor Destroy; virtual; + constructor Create(const ThemedSettings: TThemeBackground); virtual; + procedure OnShow; virtual; + procedure Draw; virtual; + procedure OnFinish; virtual; + destructor Destroy; virtual; end; cMenuBackground = class of TMenuBackground; implementation -Constructor TMenuBackground.Create(const ThemedSettings: TThemeBackground); +constructor TMenuBackground.Create(const ThemedSettings: TThemeBackground); begin inherited Create; end; -Destructor TMenuBackground.Destroy; +destructor TMenuBackground.Destroy; begin inherited; end; - -Procedure TMenuBackground.OnShow; +procedure TMenuBackground.OnShow; begin end; -Procedure TMenuBackground.OnFinish; +procedure TMenuBackground.OnFinish; begin end; - -Procedure TMenuBackground.Draw; +procedure TMenuBackground.Draw; begin end; diff --git a/src/menu/UMenuBackgroundColor.pas b/src/menu/UMenuBackgroundColor.pas index 26385b44..68cf2de4 100644 --- a/src/menu/UMenuBackgroundColor.pas +++ b/src/menu/UMenuBackgroundColor.pas @@ -45,8 +45,8 @@ type private Color: TRGB; public - Constructor Create(const ThemedSettings: TThemeBackground); override; - Procedure Draw; override; + constructor Create(const ThemedSettings: TThemeBackground); override; + procedure Draw; override; end; implementation @@ -54,13 +54,13 @@ uses gl, glext; -Constructor TMenuBackgroundColor.Create(const ThemedSettings: TThemeBackground); +constructor TMenuBackgroundColor.Create(const ThemedSettings: TThemeBackground); begin inherited; Color := ThemedSettings.Color; end; -Procedure TMenuBackgroundColor.Draw; +procedure TMenuBackgroundColor.Draw; begin glClearColor(Color.R, Color.G, Color.B, 0); glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); diff --git a/src/menu/UMenuBackgroundFade.pas b/src/menu/UMenuBackgroundFade.pas index 3bdd631e..b6174738 100644 --- a/src/menu/UMenuBackgroundFade.pas +++ b/src/menu/UMenuBackgroundFade.pas @@ -44,18 +44,18 @@ uses type TMenuBackgroundFade = class (TMenuBackground) private - Tex: TTexture; + Tex: TTexture; Color: TRGB; - Alpha: Real; + Alpha: real; - useTexture: Boolean; + useTexture: boolean; - FadeTime: Cardinal; + FadeTime: cardinal; public - Constructor Create(const ThemedSettings: TThemeBackground); override; - Procedure OnShow; override; - Procedure Draw; override; - Destructor Destroy; override; + constructor Create(const ThemedSettings: TThemeBackground); override; + procedure OnShow; override; + procedure Draw; override; + destructor Destroy; override; end; const @@ -68,15 +68,15 @@ uses sdl, USkins, UCommon; -Constructor TMenuBackgroundFade.Create(const ThemedSettings: TThemeBackground); -var texFilename: String; +constructor TMenuBackgroundFade.Create(const ThemedSettings: TThemeBackground); +var texFilename: string; begin inherited; FadeTime := 0; Color := ThemedSettings.Color; Alpha := ThemedSettings.Alpha; - If (Length(ThemedSettings.Tex) > 0) then + if (Length(ThemedSettings.Tex) > 0) then begin texFilename := Skin.GetTextureFileName(ThemedSettings.Tex); texFilename := AdaptFilePaths(texFilename); @@ -85,43 +85,41 @@ begin UseTexture := (Tex.TexNum <> 0); end else - UseTexture := False; + UseTexture := false; - If (not UseTexture) then + if (not UseTexture) then FreeandNil(Tex); end; -Destructor TMenuBackgroundFade.Destroy; +destructor TMenuBackgroundFade.Destroy; begin //Why isn't there any Tex.free method? - {If UseTexture then + {if UseTexture then FreeandNil(Tex); } inherited; end; - -Procedure TMenuBackgroundFade.OnShow; +procedure TMenuBackgroundFade.OnShow; begin FadeTime := SDL_GetTicks; end; - -Procedure TMenuBackgroundFade.Draw; +procedure TMenuBackgroundFade.Draw; var - Progress: Real; + Progress: real; begin - If FadeTime = 0 then + if FadeTime = 0 then Progress := Alpha - Else + else Progress := Alpha * (SDL_GetTicks - FadeTime) / FADEINTIME; - If Progress > Alpha then + if Progress > Alpha then begin FadeTime := 0; Progress := Alpha; end; - If (UseTexture) then + if (UseTexture) then begin //Draw Texture to Screen glClear(GL_DEPTH_BUFFER_BIT); diff --git a/src/menu/UMenuBackgroundNone.pas b/src/menu/UMenuBackgroundNone.pas index d4188395..6b63742a 100644 --- a/src/menu/UMenuBackgroundNone.pas +++ b/src/menu/UMenuBackgroundNone.pas @@ -45,8 +45,8 @@ type private public - Constructor Create(const ThemedSettings: TThemeBackground); override; - Procedure Draw; override; + constructor Create(const ThemedSettings: TThemeBackground); override; + procedure Draw; override; end; implementation @@ -54,12 +54,12 @@ uses gl, glext; -Constructor TMenuBackgroundNone.Create(const ThemedSettings: TThemeBackground); +constructor TMenuBackgroundNone.Create(const ThemedSettings: TThemeBackground); begin inherited; end; -Procedure TMenuBackgroundNone.Draw; +procedure TMenuBackgroundNone.Draw; begin //Do just nothing in here! glClear(GL_DEPTH_BUFFER_BIT); diff --git a/src/menu/UMenuBackgroundTexture.pas b/src/menu/UMenuBackgroundTexture.pas index 55d1d0b6..e8678fc5 100644 --- a/src/menu/UMenuBackgroundTexture.pas +++ b/src/menu/UMenuBackgroundTexture.pas @@ -47,13 +47,13 @@ type Tex: TTexture; Color: TRGB; public - Constructor Create(const ThemedSettings: TThemeBackground); override; - Procedure Draw; override; - Destructor Destroy; override; + 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'); + SUPPORTED_EXTS_BACKGROUNDTEXTURE: array[0..13] of string = ('.png', '.bmp', '.jpg', '.jpeg', '.gif', '.pnm', '.ppm', '.pgm', '.pbm', '.xpm', '.lbm', '.pcx', '.tga', '.tiff'); implementation uses @@ -63,12 +63,12 @@ uses gl, glext; -Constructor TMenuBackgroundTexture.Create(const ThemedSettings: TThemeBackground); -var texFilename: String; +constructor TMenuBackgroundTexture.Create(const ThemedSettings: TThemeBackground); +var texFilename: string; begin inherited; - If (Length(ThemedSettings.Tex) = 0) then + if (Length(ThemedSettings.Tex) = 0) then raise EMenuBackgroundError.Create('TMenuBackgroundTexture: No texture filename present'); Color := ThemedSettings.Color; @@ -84,13 +84,13 @@ begin end; end; -Destructor TMenuBackgroundTexture.Destroy; +destructor TMenuBackgroundTexture.Destroy; begin //freeandnil(Tex); <- this causes an Access Violation o0 inherited; end; -Procedure TMenuBackgroundTexture.Draw; +procedure TMenuBackgroundTexture.Draw; begin glClear(GL_DEPTH_BUFFER_BIT); glColorRGB(Color); diff --git a/src/menu/UMenuBackgroundVideo.pas b/src/menu/UMenuBackgroundVideo.pas index a6d02828..377c2170 100644 --- a/src/menu/UMenuBackgroundVideo.pas +++ b/src/menu/UMenuBackgroundVideo.pas @@ -44,57 +44,57 @@ uses type //DefaultBGVideoPlayback = TVideoPlayback_FFmpeg; -{type +{type TBGVideoPool = class; PBGVideoPoolItem = ^TBGVideoPoolItem; TBGVideoPoolItem = record Parent: TBGVideoPool; VideoPlayback = IVideoPlayback; - ReferenceCounter: Cardinal; //Number of Creations + ReferenceCounter: cardinal; //Number of Creations end; TBGVideo = class private myItem: PBGVideoPoolItem; public - Constructor Create(Item: PBGVideoPoolItem); override; + constructor Create(Item: PBGVideoPoolItem); override; - Function GetVideoPlayback: IVideoPlayback; - Procedure Draw; + function GetVideoPlayback: IVideoPlayback; + procedure Draw; - Destructor Destroy; + destructor Destroy; end; TBGVideoPool = class private Items: PBGVideoPoolItem; public - Constructor Create; + constructor Create; - Function GetBGVideo(filename: String): TBGVideo; - Procedure RemoveItem( - Procedure FreeAllItems; + function GetBGVideo(filename: string): TBGVideo; + procedure RemoveItem( + procedure FreeAllItems; - Destructor Destroy; + destructor Destroy; end; - + type } TMenuBackgroundVideo = class (TMenuBackground) private - fFilename: String; + fFilename: string; public - Constructor Create(const ThemedSettings: TThemeBackground); override; - Procedure OnShow; override; - Procedure Draw; override; - Procedure OnFinish; override; - Destructor Destroy; override; + 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'); + SUPPORTED_EXTS_BACKGROUNDVIDEO: array[0..6] of string = ('.avi', '.mov', '.divx', '.mpg', '.mp4', '.mpeg', '.m2v'); implementation @@ -107,10 +107,10 @@ uses USkins, UCommon; -Constructor TMenuBackgroundVideo.Create(const ThemedSettings: TThemeBackground); +constructor TMenuBackgroundVideo.Create(const ThemedSettings: TThemeBackground); begin inherited; - If (Length(ThemedSettings.Tex) = 0) then + if (Length(ThemedSettings.Tex) = 0) then raise EMenuBackgroundError.Create('TMenuBackgroundVideo: No video filename present'); fFileName := Skin.GetTextureFileName(ThemedSettings.Tex); @@ -125,13 +125,12 @@ begin raise EMenuBackgroundError.Create('TMenuBackgroundVideo: Can''t load background video: ' + fFilename); end; -Destructor TMenuBackgroundVideo.Destroy; +destructor TMenuBackgroundVideo.Destroy; begin end; - -Procedure TMenuBackgroundVideo.OnShow; +procedure TMenuBackgroundVideo.OnShow; begin if VideoPlayback.Open( fFileName ) then begin @@ -140,13 +139,12 @@ begin end; end; -Procedure TMenuBackgroundVideo.OnFinish; +procedure TMenuBackgroundVideo.OnFinish; begin end; - -Procedure TMenuBackgroundVideo.Draw; +procedure TMenuBackgroundVideo.Draw; begin glClear(GL_DEPTH_BUFFER_BIT); @@ -157,23 +155,23 @@ end; // Implementation of TBGVideo //-------- -{Constructor TBGVideo.Create(Item: PBGVideoPoolItem); +{constructor TBGVideo.Create(Item: PBGVideoPoolItem); begin myItem := PBGVideoPoolItem; Inc(myItem.ReferenceCounter); end; -Destructor TBGVideo.Destroy; +destructor TBGVideo.Destroy; begin Dec(myItem.ReferenceCounter); end; -Function TBGVideo.GetVideoPlayback: IVideoPlayback; +function TBGVideo.GetVideoPlayback: IVideoPlayback; begin end; -Procedure TBGVideo.Draw; +procedure TBGVideo.Draw; begin end; @@ -181,22 +179,22 @@ end; // Implementation of TBGVideoPool //-------- -Constructor TBGVideoPool.Create; +constructor TBGVideoPool.Create; begin end; -Destructor TBGVideoPool.Destroy; +destructor TBGVideoPool.Destroy; begin end; -Function TBGVideoPool.GetBGVideo(filename: String): TBGVideo; +function TBGVideoPool.GetBGVideo(filename: string): TBGVideo; begin end; -Procedure TBGVideoPool.FreeAllItems; +procedure TBGVideoPool.FreeAllItems; begin end; } -- cgit v1.2.3 From af9523c588b9440880e2d1bebe0cf79235cc4d59 Mon Sep 17 00:00:00 2001 From: tobigun Date: Sun, 19 Oct 2008 11:45:07 +0000 Subject: - background-type -> enum - some string function-parameters defined const git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1458 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index c4e0ece6..c660b585 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -375,7 +375,7 @@ begin end; Case ThemedSettings.BGType of - BGT_Auto: begin //Automaticly choose one out of BGT_Texture, BGT_Video or BGT_Color + bgtAuto: begin //Automaticly choose one out of BGT_Texture, BGT_Video or BGT_Color if (Length(ThemedSettings.Tex) > 0) then begin @@ -401,7 +401,7 @@ begin end; end; - BGT_Color: begin + bgtColor: begin try Background := TMenuBackgroundColor.Create(ThemedSettings); except @@ -413,7 +413,7 @@ begin end; end; - BGT_Texture: begin + bgtTexture: begin try Background := TMenuBackgroundTexture.Create(ThemedSettings); except @@ -425,7 +425,7 @@ begin end; end; - BGT_Video: begin + bgtVideo: begin try Background := TMenuBackgroundVideo.Create(ThemedSettings); except @@ -437,7 +437,7 @@ begin end; end; - BGT_None: begin + bgtNone: begin try Background := TMenuBackgroundNone.Create(ThemedSettings); except @@ -449,7 +449,7 @@ begin end; end; - BGT_Fade: begin + bgtFade: begin try Background := TMenuBackgroundFade.Create(ThemedSettings); except @@ -465,7 +465,7 @@ begin //Fallback to None Background or Colored Background if (Background = nil) then begin - if (ThemedSettings.BGType = BGT_Color) then + if (ThemedSettings.BGType = bgtColor) then Background := TMenuBackgroundNone.Create(ThemedSettings) else Background := TMenuBackgroundColor.Create(ThemedSettings) @@ -1507,7 +1507,7 @@ begin end; end; } if (Background = nil) then - AddBackground(DEFAULTBACKGROUND); + AddBackground(DEFAULT_BACKGROUND); Background.OnShow; end; -- cgit v1.2.3 From 2f768387f3849699320229a5b756db78af1207a2 Mon Sep 17 00:00:00 2001 From: tobigun Date: Sun, 19 Oct 2008 16:24:59 +0000 Subject: The size given to TextGL.SetSize() now expresses the size in pixel (formerly it was 1/3 of the pixel-size). For theme and plugin compatibility the following functions multiply the size with 3: - UScreenSingModi.Print - TTheme.ThemeLoadText - TTheme.ThemeLoadSelectSlide TODO: Convert the themes/plugins and remove the "*3" git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1459 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 2 +- src/menu/UMenu.pas | 12 ++++++------ src/menu/UMenuSelectSlide.pas | 2 +- src/menu/UMenuText.pas | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index ebd25e50..bea9b58d 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -378,7 +378,7 @@ begin //Set Font Specs SetFontStyle(0); - SetFontSize(7); + SetFontSize(21); SetFontItalic(False); glColor4f(0, 0, 0, 1); diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index c660b585..88f00e30 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -574,9 +574,9 @@ begin 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); + 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; @@ -1269,7 +1269,7 @@ begin 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 := 10; + SelectsS[S].Text.Size := 30; SelectsS[S].Text.Visible := true; SelectsS[S].TColR := TColR; SelectsS[S].TColG := TColG; @@ -1303,7 +1303,7 @@ begin SelectsS[S].PData := @Data; // Configures Select options {//SelectsS[S].TextOpt[0].Text := IntToStr(I+1); - SelectsS[S].TextOpt[0].Size := 10; + SelectsS[S].TextOpt[0].Size := 30; SelectsS[S].TextOpt[0].Align := 1; SelectsS[S].TextOpt[0].ColR := SelectsS[S].STDColR; @@ -1324,7 +1324,7 @@ 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 := 10; + SelectsS[S].TextOpt[I].Size := 30; SelectsS[S].TextOpt[I].Align := 1; SelectsS[S].TextOpt[I].ColR := SelectsS[S].STDColR; diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 4779094c..ed1db6cf 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -370,7 +370,7 @@ begin else TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; - TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H / 2) - 1.5 * Text.Size{20}; + TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H - Text.Size) / 2; //Better Look with 2 Options if (Lines=2) AND (Length(TextOptT)= 2) then diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index bc3d5ebd..1a7c15a1 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -328,12 +328,12 @@ begin glPrint(PChar(Text2)); {if Size >= 10 then - Y2 := Y2 + Size * 2.8 + Y2 := Y2 + Size * 0.93 else} if (Style = 1) then - Y2 := Y2 + Size * 2.8 + Y2 := Y2 + Size * 0.93 else - Y2 := Y2 + Size * 2.15; + Y2 := Y2 + Size * 0.72; end; SetFontStyle(0); // reset to default @@ -348,7 +348,7 @@ end; constructor TText.Create(X, Y: real; Tekst: string); begin - Create(X, Y, 0, 0, 10, 0, 0, 0, 0, Tekst, false, 0, 0); + Create(X, Y, 0, 0, 30, 0, 0, 0, 0, Tekst, false, 0, 0); end; constructor TText.Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ:real); -- cgit v1.2.3 From beb06421d53294357184e8e761bf9fae10a0c4be Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 20 Oct 2008 09:58:54 +0000 Subject: FPC 2.2.2 compatibility. USDX crashed with an error in iconv_close. After disabling the cwstring unit everything works fine again. Drawback: WideUpperCase() as other unicode support does not work anymore (cwstring was a dummy in 2.2.0 so this is not a big deal). git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1462 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 88f00e30..16ecc658 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1528,7 +1528,9 @@ begin // The Unicode manager cwstring does not work with MacOSX at the moment because // of missing references to iconv. So we have to use Ansi... for the moment. - {$IFNDEF DARWIN} + // cwstring crashes in FPC 2.2.2 so do not use the cwstring stuff + {.$IFNDEF DARWIN} + {$IFDEF NOIGNORE} // The FPC implementation of WideUpperCase returns nil if wchar is #0 (e.g. if an arrow key is pressed) if (wchar <> #0) then Result := WideUpperCase(wchar) @@ -1545,7 +1547,9 @@ end; *) function TMenu.WideStringUpperCase(wstring: WideString) : WideString; begin - {$IFNDEF DARWIN} + // cwstring crashes in FPC 2.2.2 so do not use the cwstring stuff + {.$IFNDEF DARWIN} + {$IFDEF NOIGNORE} Result := WideUpperCase(wstring) {$ELSE} Result := AnsiUpperCase(wstring); -- cgit v1.2.3 From e8a388e32a4563ac9ea0895ca6c7cdf83cf9d3ec Mon Sep 17 00:00:00 2001 From: tobigun Date: Tue, 28 Oct 2008 18:57:02 +0000 Subject: - glPrint(Pchar) -> glPrint(string) - glPrintLetter removed - font engine handles FT_PIXEL_MODE_MONO as FT_Glyph_To_Bitmap(FT_RENDER_MODE_NORMAL) might return a 1bit/pixel black/white image instead of 8bit/pixel gray shaded one (happened with 16px japanese glyphs of simsun.ttf, latin ones were correct). git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1482 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 6 +++--- src/menu/UMenuSelectSlide.pas | 6 +++--- src/menu/UMenuText.pas | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index bea9b58d..f4cca4a5 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -397,16 +397,16 @@ begin //FPS SetFontPos(695, 0); - glPrint (PChar('FPS: ' + InttoStr(LastFPS))); + glPrint ('FPS: ' + InttoStr(LastFPS)); //RSpeed SetFontPos(695, 13); - glPrint (PChar('RSpeed: ' + InttoStr(Round(1000 * TimeMid)))); + glPrint ('RSpeed: ' + InttoStr(Round(1000 * TimeMid))); //LastError SetFontPos(695, 26); glColor4f(1, 0, 0, 1); - glPrint (PChar(OSD_LastError)); + glPrint (OSD_LastError); glColor4f(1, 1, 1, 1); end; diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index ed1db6cf..d04b20d0 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -333,8 +333,8 @@ begin for I := low(TextOptT) to high (TextOptT) do begin - if (glTextWidth(PChar(TextOptT[I])) > maxlength) then - maxlength := glTextWidth(PChar(TextOptT[I])); + if (glTextWidth(TextOptT[I]) > maxlength) then + maxlength := glTextWidth(TextOptT[I]); end; Lines := floor((TextureSBG.W-40) / (maxlength+7)); @@ -374,7 +374,7 @@ begin //Better Look with 2 Options if (Lines=2) AND (Length(TextOptT)= 2) then - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(PChar(TextOptT[1]))) * I; + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(TextOptT[1])) * I; end; end; diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index 1a7c15a1..5c41eba5 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -200,7 +200,7 @@ begin if isBreak then begin //Look for Break before the Break - if (glTextWidth(PChar(Copy(Value, LastBreak, NextPos - LastBreak + 1))) > W) AND (NextPos-LastPos > 1) then + 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 @@ -221,7 +221,7 @@ begin AddBreak(LastBreak, NextPos); end //Text comes out of the Text Area -> CreateBreak - else if (glTextWidth(PChar(Copy(Value, LastBreak, NextPos - LastBreak + 1))) > W) then + 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 @@ -295,12 +295,12 @@ begin case Align of 0: X2 := X; - 1: X2 := X - glTextWidth(pchar(Text2))/2; - 2: X2 := X - glTextWidth(pchar(Text2)); + 1: X2 := X - glTextWidth(Text2)/2; + 2: X2 := X - glTextWidth(Text2); end; SetFontPos(X2, Y); - glPrint(PChar(Text2)); + glPrint(Text2); SetFontStyle(0); // reset to default end else @@ -317,15 +317,15 @@ begin case Align of 0: X2 := X + MoveX; - 1: X2 := X + MoveX - glTextWidth(pchar(Text2))/2; - 2: X2 := X + MoveX - glTextWidth(pchar(Text2)); + 1: X2 := X + MoveX - glTextWidth(Text2)/2; + 2: X2 := X + MoveX - glTextWidth(Text2); end; SetFontPos(X2, Y2); SetFontZ(Z); - glPrint(PChar(Text2)); + glPrint(Text2); {if Size >= 10 then Y2 := Y2 + Size * 0.93 -- cgit v1.2.3 From 6585afce2ccd8e7c5ccb3bb3599d4723b00a0433 Mon Sep 17 00:00:00 2001 From: tobigun Date: Tue, 28 Oct 2008 20:16:05 +0000 Subject: some compiler warnings/hints removed git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1485 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuBackground.pas | 2 +- src/menu/UMenuSelectSlide.pas | 3 +-- src/menu/UMenuText.pas | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuBackground.pas b/src/menu/UMenuBackground.pas index 6a73b621..c85f0806 100644 --- a/src/menu/UMenuBackground.pas +++ b/src/menu/UMenuBackground.pas @@ -49,7 +49,7 @@ type procedure OnShow; virtual; procedure Draw; virtual; procedure OnFinish; virtual; - destructor Destroy; virtual; + destructor Destroy; override; end; cMenuBackground = class of TMenuBackground; diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index d04b20d0..1a0fa725 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -209,7 +209,6 @@ end; procedure TSelectSlide.SetSelectOpt(Value: integer); var SO: integer; - Sel: integer; HalfL: integer; HalfR: integer; @@ -252,7 +251,7 @@ begin end else if (Value >= high(TextOptT)) then begin //Last Option Selected - Value := high(TextOptT); + Value := high(TextOptT); for SO := high(TextOpt) downto low (TextOpt) do begin diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index 5c41eba5..3fc60384 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -111,7 +111,7 @@ var function GetNextPos: boolean; var - T1, T2, T3: Cardinal; + T1, {T2,} T3: Cardinal; begin LastPos := NextPos; -- cgit v1.2.3 From d33f56a40d9e8325a2782f90bb253dece5127c5f Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 3 Nov 2008 14:53:17 +0000 Subject: All comments are English now (Polish ones have been translated) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1498 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDrawTexture.pas | 1 - src/menu/UMenuText.pas | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDrawTexture.pas b/src/menu/UDrawTexture.pas index 33082765..bc136f11 100644 --- a/src/menu/UDrawTexture.pas +++ b/src/menu/UDrawTexture.pas @@ -74,7 +74,6 @@ var begin with Texture do begin - // rysuje paski gracza glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index 3fc60384..a3d13834 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -82,8 +82,8 @@ type procedure Draw; constructor Create; overload; - constructor Create(X, Y: real; Tekst: string); overload; - constructor Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ: real); overload; + constructor Create(X, Y: real; Text: string); overload; + constructor Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParText: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ: real); overload; end; implementation @@ -346,12 +346,12 @@ begin Create(0, 0, ''); end; -constructor TText.Create(X, Y: real; Tekst: string); +constructor TText.Create(X, Y: real; Text: string); begin - Create(X, Y, 0, 0, 30, 0, 0, 0, 0, Tekst, false, 0, 0); + Create(X, Y, 0, 0, 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; ParTekst: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ:real); +constructor TText.Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParText: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ:real); begin inherited Create; Alpha := 1; @@ -361,7 +361,7 @@ begin Z := ParZ; Style := ParStyle; Size := ParSize; - Text := ParTekst; + Text := ParText; ColR := ParColR; ColG := ParColG; ColB := ParColB; -- cgit v1.2.3 From 235e666baa94ee526eb3c040dc5fb805d7e80ada Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sat, 21 Feb 2009 23:36:13 +0000 Subject: editing git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1597 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuButton.pas | 63 +++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuButton.pas b/src/menu/UMenuButton.pas index a0cdaeef..c6ff8ab7 100644 --- a/src/menu/UMenuButton.pas +++ b/src/menu/UMenuButton.pas @@ -45,24 +45,24 @@ type TButton = class protected - SelectBool: Boolean; + SelectBool: boolean; - FadeProgress: Real; - FadeLastTick: Cardinal; + FadeProgress: real; + FadeLastTick: cardinal; DeSelectW, DeSelectH, PosX, - PosY: Real; + PosY: real; constructor Create(); overload; public - Text: Array of TText; + Text: array of TText; Texture: TTexture; // Button Screen position and size Texture2: TTexture; // second texture only used for fading full resolution covers - Colorized: Boolean; + Colorized: boolean; DeSelectTexture: TTexture; // texture for colorized hack FadeTex: TTexture; //Texture for beautiful fading @@ -73,15 +73,15 @@ type Reflection: boolean; Reflectionspacing, - DeSelectReflectionspacing: Real; + DeSelectReflectionspacing: real; Fade, - FadeText: Boolean; + FadeText: boolean; Selectable: boolean; //Number of the Parent Collection, 0 if in no Collection - Parent: Byte; + Parent: byte; SelectColR, SelectColG, @@ -103,13 +103,13 @@ type procedure SetW(Value: real); procedure SetH(Value: real); - procedure SetSelect(Value: Boolean); virtual; + 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; + property Selected: boolean read SelectBool write SetSelect; procedure Draw; virtual; @@ -120,8 +120,9 @@ type implementation -uses SysUtils, - UDrawTexture; +uses + SysUtils, + UDrawTexture; procedure TButton.SetX(Value: real); {var @@ -143,8 +144,8 @@ end; procedure TButton.SetY(Value: real); {var - dY: real; - T: integer; // text} + dY: real; + T: integer; // text} begin {dY := Value - PosY; @@ -164,7 +165,7 @@ begin DeSelectW := Value; - if Not Fade then + if not Fade then begin if SelectBool then Texture.W := SelectW @@ -180,7 +181,7 @@ begin DeSelectH := Value; - if Not Fade then + if not Fade then begin if SelectBool then Texture.H := SelectH @@ -189,9 +190,9 @@ begin end; end; -procedure TButton.SetSelect(Value : Boolean); +procedure TButton.SetSelect(Value : boolean); var - T: integer; + T: integer; begin SelectBool := Value; @@ -291,9 +292,9 @@ end; procedure TButton.Draw; var - T: integer; - Tick: Cardinal; - Spacing: Real; + T: integer; + Tick: cardinal; + Spacing: real; begin if Visible then begin @@ -315,7 +316,7 @@ begin if (FadeText) then begin - For T := 0 to high(Text) do + for T := 0 to high(Text) do begin Text[T].MoveX := (SelectW - DeSelectW) * FadeProgress; Text[T].MoveY := (SelectH - DeSelectH) * FadeProgress; @@ -353,7 +354,7 @@ begin FadeTex.TexY1 := 0; FadeTex.TexY2 := 1; - Case FadeTexPos of + case FadeTexPos of 0: //FadeTex on Top begin //Standard Texture @@ -465,7 +466,7 @@ begin //Reflection Mod if (Reflection) then // Draw Reflections begin - if (FadeProgress <> 0) AND (FadeProgress <> 1) then + if (FadeProgress <> 0) and (FadeProgress <> 1) then begin Spacing := DeSelectReflectionspacing - (DeSelectReflectionspacing - Reflectionspacing) * FadeProgress; end @@ -514,9 +515,10 @@ begin glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); - end else + end + else with DeSelectTexture do - begin + begin //Bind Tex and GL Attributes glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); @@ -556,7 +558,8 @@ begin end; end; - for T := 0 to High(Text) do begin + for T := 0 to High(Text) do + begin Text[T].Draw; end; end; @@ -577,7 +580,7 @@ begin Texture.ColG := 0.5; Texture.ColB := 0; Texture.Int := 1; - Colorized := False; + Colorized := false; end; // Button has the texture-type "colorized" @@ -592,7 +595,7 @@ begin Texture.ColG := 1; Texture.ColB := 1; Texture.Int := 1; - Colorized := True; + Colorized := true; end; end. -- cgit v1.2.3 From f57b5a260d4d98a910f62316efe653a1a7e704b7 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 1 Mar 2009 12:53:55 +0000 Subject: fixed first screen was cleared when second screen was drawn. #76 should be fixed now commented some weird stuff in TScreenSing.Draw git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1613 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuBackgroundColor.pas | 6 +++++- src/menu/UMenuBackgroundFade.pas | 10 +++++++--- src/menu/UMenuBackgroundNone.pas | 6 ++++-- src/menu/UMenuBackgroundTexture.pas | 7 +++++-- src/menu/UMenuBackgroundVideo.pas | 6 ++++-- 5 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuBackgroundColor.pas b/src/menu/UMenuBackgroundColor.pas index 68cf2de4..a5c2a70a 100644 --- a/src/menu/UMenuBackgroundColor.pas +++ b/src/menu/UMenuBackgroundColor.pas @@ -52,7 +52,8 @@ type implementation uses gl, - glext; + glext, + UGraphic; constructor TMenuBackgroundColor.Create(const ThemedSettings: TThemeBackground); begin @@ -62,8 +63,11 @@ 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 index b6174738..dc37da45 100644 --- a/src/menu/UMenuBackgroundFade.pas +++ b/src/menu/UMenuBackgroundFade.pas @@ -66,7 +66,8 @@ uses sdl, gl, glext, USkins, - UCommon; + UCommon, + UGraphic; constructor TMenuBackgroundFade.Create(const ThemedSettings: TThemeBackground); var texFilename: string; @@ -121,7 +122,8 @@ begin if (UseTexture) then begin //Draw Texture to Screen - glClear(GL_DEPTH_BUFFER_BIT); + If (ScreenAct = 1) then //Clear just once when in dual screen mode + glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); @@ -149,7 +151,9 @@ begin end else begin //Clear Screen w/ progress Alpha + Color - glClear(GL_DEPTH_BUFFER_BIT); + 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); diff --git a/src/menu/UMenuBackgroundNone.pas b/src/menu/UMenuBackgroundNone.pas index 6b63742a..1fccc007 100644 --- a/src/menu/UMenuBackgroundNone.pas +++ b/src/menu/UMenuBackgroundNone.pas @@ -52,7 +52,8 @@ type implementation uses gl, - glext; + glext, + UGraphic; constructor TMenuBackgroundNone.Create(const ThemedSettings: TThemeBackground); begin @@ -62,7 +63,8 @@ end; procedure TMenuBackgroundNone.Draw; begin //Do just nothing in here! - glClear(GL_DEPTH_BUFFER_BIT); + 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 index e8678fc5..a1b9e88a 100644 --- a/src/menu/UMenuBackgroundTexture.pas +++ b/src/menu/UMenuBackgroundTexture.pas @@ -61,7 +61,8 @@ uses UCommon, SysUtils, gl, - glext; + glext, + UGraphic; constructor TMenuBackgroundTexture.Create(const ThemedSettings: TThemeBackground); var texFilename: string; @@ -92,7 +93,9 @@ end; procedure TMenuBackgroundTexture.Draw; begin - glClear(GL_DEPTH_BUFFER_BIT); + If (ScreenAct = 1) then //Clear just once when in dual screen mode + glClear(GL_DEPTH_BUFFER_BIT); + glColorRGB(Color); glEnable(GL_TEXTURE_2D); diff --git a/src/menu/UMenuBackgroundVideo.pas b/src/menu/UMenuBackgroundVideo.pas index 377c2170..d1ce0f09 100644 --- a/src/menu/UMenuBackgroundVideo.pas +++ b/src/menu/UMenuBackgroundVideo.pas @@ -105,7 +105,8 @@ uses SysUtils, UTime, USkins, - UCommon; + UCommon, + UGraphic; constructor TMenuBackgroundVideo.Create(const ThemedSettings: TThemeBackground); begin @@ -146,7 +147,8 @@ end; procedure TMenuBackgroundVideo.Draw; begin - glClear(GL_DEPTH_BUFFER_BIT); + If (ScreenAct = 1) then //Clear just once when in dual screen mode + glClear(GL_DEPTH_BUFFER_BIT); VideoPlayback.GetFrame(VideoBGTimer.GetTime()); // FIXME: why do we draw on screen 2? Seems to be wrong. -- cgit v1.2.3 From 458111738476004a914af6fd3e117eb84a35ab6a Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sat, 7 Mar 2009 01:06:07 +0000 Subject: unclutter UMain.pas. Create UPath.pas. Tests on all platformssvn statussvn status git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1625 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index f4cca4a5..3e653183 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -34,7 +34,7 @@ interface {$I switches.inc} uses - ucommon, + UCommon, SDL, UMenu, gl, @@ -86,15 +86,16 @@ var implementation uses - UImage, TextGL, + UCommandLine, + UGraphic, + UIni, + UImage, ULog, UMain, UTexture, - UIni, - UGraphic, UTime, - UCommandLine; + UPath; constructor TDisplay.Create; var -- cgit v1.2.3 From 82073bcf47587fd2ec4322bc4541a7fd74115963 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sat, 18 Apr 2009 11:18:51 +0000 Subject: removal of type warnings and cosmetics git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1678 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuText.pas | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index a3d13834..6cf53200 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -102,23 +102,24 @@ end; procedure TText.SetText(Value: string); var - NextPos: Cardinal; //NextPos of a Space etc. - LastPos: Cardinal; //LastPos " - 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 + NextPos: cardinal; // NextPos of a Space etc. + LastPos: cardinal; // LastPos " + 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; + 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); + else + T1 := Length(Value); {//Next - T2 := PosEx('-', Value, LastPos + 1);} @@ -136,16 +137,16 @@ var //Get Nearest Pos NextPos := min(T1, T3{min(T2, T3)}); - if (LastPos = Length(Value)) then + if (LastPos = cardinal(Length(Value))) then NextPos := 0; - isBreak := (NextPos = T3) AND (NextPos <> Length(Value)); + isBreak := (NextPos = T3) and (NextPos <> cardinal(Length(Value))); Result := (NextPos <> 0); end; - procedure AddBreak(const From, bTo: Cardinal); + procedure AddBreak(const From, bTo: cardinal); begin - if (isBreak) OR (bTo - From >= 1) then + if (isBreak) or (bTo - From >= 1) then begin Inc(Len); SetLength (TextTiles, Len); @@ -259,7 +260,7 @@ procedure TText.Draw; var X2, Y2: real; Text2: string; - I: integer; + I: cardinal; begin if Visible then begin @@ -310,7 +311,7 @@ begin Y2 := Y + MoveY; for I := 0 to high(TextTiles) do begin - if (not (SelectBool and SelectBlink)) or (I <> high(TextTiles)) then + if (not (SelectBool and SelectBlink)) or (I <> cardinal(high(TextTiles))) then Text2 := TextTiles[I] else Text2 := TextTiles[I] + '|'; -- cgit v1.2.3 From 13bff3dc29108cde5ec88d6e9ce656ce377b4694 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Fri, 24 Apr 2009 18:43:12 +0000 Subject: cosmetics. No code change git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1692 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 94 ++++++++++----------- src/menu/UMenu.pas | 81 +++++++++--------- src/menu/UMenuBackgroundFade.pas | 20 +++-- src/menu/UMenuButtonCollection.pas | 32 ++++---- src/menu/UMenuEqualizer.pas | 145 ++++++++++++++++---------------- src/menu/UMenuInteract.pas | 4 +- src/menu/UMenuSelectSlide.pas | 164 +++++++++++++++++++------------------ src/menu/UMenuStatic.pas | 11 +-- 8 files changed, 283 insertions(+), 268 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 3e653183..58c416db 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -45,39 +45,39 @@ 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.) - FadeState: integer; // fading state, 0 means that the fade texture must be initialized - LastFadeTime: Cardinal; // last fade update time + FadeEnabled: boolean; // true if fading is enabled + FadeFailed: boolean; // true if fading is possible (enough memory, etc.) + FadeState: integer; // fading state, 0 means that the fade texture must be initialized + LastFadeTime: cardinal; // last fade update time - FadeTex: array[1..2] of GLuint; + FadeTex: array[1..2] of GLuint; + + FPSCounter: cardinal; + LastFPS: cardinal; + NextFPSSwap: cardinal; - FPSCounter : Cardinal; - LastFPS : Cardinal; - NextFPSSwap : Cardinal; - - OSD_LastError : String; + OSD_LastError: string; procedure DrawDebugInformation; public - NextScreen : PMenu; - CurrentScreen : PMenu; + NextScreen: PMenu; + CurrentScreen: PMenu; //popup data NextScreenWithCheck: Pmenu; - CheckOK : Boolean; + CheckOK: boolean; // FIXME: Fade is set to 0 in UMain and other files but not used here anymore. - Fade : Real; + Fade: real; constructor Create; destructor Destroy; override; procedure SaveScreenShot; - function Draw: Boolean; + function Draw: boolean; end; var @@ -104,10 +104,10 @@ begin inherited Create; //popup hack - CheckOK := False; + CheckOK := false; NextScreen := nil; NextScreenWithCheck := nil; - BlackScreen := False; + BlackScreen := false; // fade mod FadeState := 0; @@ -133,14 +133,14 @@ begin inherited Destroy; end; -function TDisplay.Draw: Boolean; +function TDisplay.Draw: boolean; var - S: integer; - FadeStateSquare: Real; - currentTime: Cardinal; - glError: glEnum; + S: integer; + FadeStateSquare: real; + currentTime: cardinal; + glError: glEnum; begin - Result := True; + Result := true; //We don't need this here anymore, //Because the background care about cleaning the buffers @@ -166,12 +166,12 @@ begin begin NextScreen := NextScreenWithCheck; NextScreenWithCheck := nil; - CheckOk := False; + CheckOk := false; end else begin // on end of game fade to black before exit - BlackScreen := True; + BlackScreen := true; end; end; @@ -188,16 +188,16 @@ begin // fade mod FadeState := 0; if ((Ini.ScreenFade = 1) and (not FadeFailed)) then - FadeEnabled := True + FadeEnabled := true else if (Ini.ScreenFade = 0) then - FadeEnabled := False; + FadeEnabled := false; end else begin // disable fading if initialization failed if (FadeEnabled and FadeFailed) then begin - FadeEnabled := False; + FadeEnabled := false; end; if (FadeEnabled and not FadeFailed) then @@ -275,7 +275,7 @@ begin glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); end - // blackscreen hack +// blackscreen hack else if not BlackScreen then begin NextScreen.OnShow; @@ -286,7 +286,7 @@ begin // fade out complete... FadeState := 0; CurrentScreen.onHide; - CurrentScreen.ShowFinish := False; + CurrentScreen.ShowFinish := false; CurrentScreen := NextScreen; NextScreen := nil; if not BlackScreen then @@ -296,13 +296,13 @@ begin end else begin - Result := False; + Result := false; Break; end; end; end; // if - //Draw OSD only on first Screen if Debug Mode is enabled +// Draw OSD only on first Screen if Debug Mode is enabled if ((Ini.Debug = 1) or (Params.Debug)) and (S = 1) then DrawDebugInformation; end; // for @@ -318,7 +318,7 @@ var Align: integer; RowSize: integer; begin - // Exit if Screenshot-path does not exist or read-only +// Exit if Screenshot-path does not exist or read-only if (ScreenshotsPath = '') then Exit; @@ -332,9 +332,9 @@ begin break end; - // we must take the row-alignment (4byte by default) into account +// we must take the row-alignment (4byte by default) into account glGetIntegerv(GL_PACK_ALIGNMENT, @Align); - // calc aligned row-size +// calc aligned row-size RowSize := ((ScreenW*3 + (Align-1)) div Align) * Align; GetMem(ScreenData, RowSize * ScreenH); @@ -347,8 +347,8 @@ begin ScreenData, ScreenW, ScreenH, 24, RowSize, $0000FF, $00FF00, $FF0000, 0); - //Success := WriteJPGImage(FileName, Surface, 95); - //Success := WriteBMPImage(FileName, Surface); +// Success := WriteJPGImage(FileName, Surface, 95); +// Success := WriteBMPImage(FileName, Surface); Success := WritePNGImage(FileName, Surface); if Success then ScreenPopupError.ShowPopup('Screenshot saved: ' + ExtractFileName(FileName)) @@ -363,9 +363,9 @@ end; // 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 +// Some White Background for information glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glColor4f(1, 1, 1, 0.5); @@ -377,13 +377,13 @@ begin glEnd; glDisable(GL_BLEND); - //Set Font Specs +// Set Font Specs SetFontStyle(0); SetFontSize(21); - SetFontItalic(False); + SetFontItalic(false); glColor4f(0, 0, 0, 1); - //Calculate FPS +// Calculate FPS Ticks := SDL_GetTicks(); if (Ticks >= NextFPSSwap) then begin @@ -394,17 +394,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); diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 16ecc658..f86746ed 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -54,15 +54,15 @@ type PMenu = ^TMenu; TMenu = class protected - Background: TMenuBackground; + Background: TMenuBackground; - Interactions: array of TInteract; - SelInteraction: integer; + Interactions: array of TInteract; + SelInteraction: integer; - ButtonPos: integer; - Button: array of TButton; + ButtonPos: integer; + Button: array of TButton; - SelectsS: array of TSelectSlide; + SelectsS: array of TSelectSlide; ButtonCollection: array of TButtonCollection; public Text: array of TText; @@ -111,7 +111,7 @@ type function AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; const Text_: string; 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 + 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 Name: string): integer; overload; function AddButton(X, Y, W, H: real; const Name: string; Typ: TTextureType; Reflection: boolean): integer; overload; @@ -167,13 +167,13 @@ type end; const - pmMove = 1; - pmClick = 2; + pmMove = 1; + pmClick = 2; pmUnClick = 3; - iButton = 0; // interaction type - iText = 2; - iSelectS = 3; + iButton = 0; // interaction type + iText = 2; + iSelectS = 3; iBCollectionChild = 5; // fBlack = 0; // fade type @@ -181,21 +181,22 @@ const implementation -uses UCommon, - ULog, - UMain, - UDrawTexture, - UGraphic, - UDisplay, - UCovers, - UTime, - USkins, - //Background types - UMenuBackgroundNone, - UMenuBackgroundColor, - UMenuBackgroundTexture, - UMenuBackgroundVideo, - UMenuBackgroundFade; +uses + UCommon, + ULog, + UMain, + UDrawTexture, + UGraphic, + UDisplay, + UCovers, + UTime, + USkins, + //Background types + UMenuBackgroundNone, + UMenuBackgroundColor, + UMenuBackgroundTexture, + UMenuBackgroundVideo, + UMenuBackgroundFade; destructor TMenu.Destroy; begin @@ -339,8 +340,9 @@ procedure TMenu.AddBackground(ThemedSettings: TThemeBackground); var FileExt: string; - Function IsInArray(const Piece: string; const A: array of string): boolean; - var I: integer; + function IsInArray(const Piece: string; const A: array of string): boolean; + var + I: integer; begin Result := false; @@ -352,7 +354,7 @@ procedure TMenu.AddBackground(ThemedSettings: TThemeBackground); end; end; - Function TryBGCreate(Typ: cMenuBackground): boolean; + function TryBGCreate(Typ: cMenuBackground): boolean; begin Result := true; @@ -374,7 +376,7 @@ begin Background := nil; end; - Case ThemedSettings.BGType of + case ThemedSettings.BGType of bgtAuto: begin //Automaticly choose one out of BGT_Texture, BGT_Video or BGT_Color if (Length(ThemedSettings.Tex) > 0) then @@ -491,7 +493,7 @@ end; //---------------------- procedure TMenu.AddButtonCollection(const ThemeCollection: TThemeButtonCollection; const Num: byte); var - BT, BTLen: integer; + BT, BTLen: integer; TempCol, TempDCol: cardinal; begin @@ -711,9 +713,9 @@ begin end; //Function that Set Length of Button boolean in one Step instead of register new Memory for every Button -Procedure TMenu.SetButtonLength(Length: cardinal); +procedure TMenu.SetButtonLength(Length: cardinal); begin - if (ButtonPos = -1) AND (Length > 0) then + if (ButtonPos = -1) and (Length > 0) then begin //Set Length of Button SetLength(Button, Length); @@ -920,9 +922,9 @@ end; } { -function TMenu.AddWidget(X, Y : UInt16; WidgetSrc : PSDL_Surface): Int16; +function TMenu.AddWidget(X, Y: UInt16; WidgetSrc: PSDL_Surface): Int16; var - WidgetNum : Int16; + WidgetNum: Int16; begin if (Assigned(WidgetSrc)) then begin @@ -946,9 +948,9 @@ end; } { -procedure TMenu.ClearWidgets(MinNumber : Int16); +procedure TMenu.ClearWidgets(MinNumber: Int16); var - J : Int16; + J: Int16; begin for J := MinNumber to (Length(WidgetsSrc) - 1) do begin @@ -1252,6 +1254,7 @@ begin SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp, RGBFloatToInt(SBGColR, SBGColG, SBGColB)) else SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp); + SelectsS[S].TextureSBG.X := X + W + SkipX; SelectsS[S].TextureSBG.Y := Y; //SelectsS[S].TextureSBG.W := 450; @@ -1460,7 +1463,7 @@ begin 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 + 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 diff --git a/src/menu/UMenuBackgroundFade.pas b/src/menu/UMenuBackgroundFade.pas index dc37da45..b61a4542 100644 --- a/src/menu/UMenuBackgroundFade.pas +++ b/src/menu/UMenuBackgroundFade.pas @@ -62,15 +62,17 @@ const FADEINTIME = 1500; //Time the bg fades in implementation -uses sdl, - gl, - glext, - USkins, - UCommon, - UGraphic; +uses + sdl, + gl, + glext, + USkins, + UCommon, + UGraphic; constructor TMenuBackgroundFade.Create(const ThemedSettings: TThemeBackground); -var texFilename: string; +var + texFilename: string; begin inherited; FadeTime := 0; @@ -122,7 +124,7 @@ begin if (UseTexture) then begin //Draw Texture to Screen - If (ScreenAct = 1) then //Clear just once when in dual screen mode + if (ScreenAct = 1) then //Clear just once when in dual screen mode glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); @@ -151,7 +153,7 @@ begin end else begin //Clear Screen w/ progress Alpha + Color - If (ScreenAct = 1) then //Clear just once when in dual screen mode + if (ScreenAct = 1) then //Clear just once when in dual screen mode glClear(GL_DEPTH_BUFFER_BIT); glDisable(GL_TEXTURE_2D); diff --git a/src/menu/UMenuButtonCollection.pas b/src/menu/UMenuButtonCollection.pas index c6c6dd81..8b7a1c3f 100644 --- a/src/menu/UMenuButtonCollection.pas +++ b/src/menu/UMenuButtonCollection.pas @@ -41,61 +41,61 @@ type //TButtonCollection //No Extra Attributes or Functions ATM //---------------- - AButton = Array of TButton; + AButton = array of TButton; PAButton = ^AButton; TButtonCollection = class(TButton) //num of the First Button, that can be Selected - FirstChild: Byte; - CountChilds: Byte; + FirstChild: byte; + CountChilds: byte; ScreenButton: PAButton; - procedure SetSelect(Value : Boolean); override; + procedure SetSelect(Value : boolean); override; procedure Draw; override; end; implementation -procedure TButtonCollection.SetSelect(Value : Boolean); -var I: Integer; +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 I := 0 to High(ScreenButton^) do - if (ScreenButton^[I].Parent = Parent) then - ScreenButton^[I].Visible := Value; + 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; +var + I, J: integer; begin inherited; //If fading is activated, Fade Child Buttons if (Fade) then begin - For I := 0 to High(ScreenButton^) do + 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 + 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 + 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 index 6d77721c..8f57e44a 100644 --- a/src/menu/UMenuEqualizer.pas +++ b/src/menu/UMenuEqualizer.pas @@ -45,69 +45,71 @@ type Tms_Equalizer = class(TObject) private FFTData: TFFTData; // moved here to avoid stack overflows - BandData: array of Byte; - RefreshTime: Cardinal; + BandData: array of byte; + RefreshTime: cardinal; Source: IAudioPlayback; - Procedure Analyse; + procedure Analyse; public - X: Integer; - Y: Integer; - Z: Real; + X: integer; + Y: integer; + Z: real; - W: Integer; - H: Integer; - Space: Integer; + W: integer; + H: integer; + Space: integer; - Visible: Boolean; - Alpha: real; - Color: TRGB; + Visible: boolean; + Alpha: real; + Color: TRGB; - Direction: Boolean; + Direction: boolean; + BandLength: integer; - BandLength: Integer; - - Reflection: boolean; - Reflectionspacing: Real; + 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 SetBands(Value: byte); + function GetBands: byte; + property Bands: byte read GetBands write SetBands; procedure SetSource(newSource: IAudioPlayback); end; implementation -uses math, SDL, gl, glext; - +uses + math, + SDL, + gl, + glext; constructor Tms_Equalizer.Create(Source: IAudioPlayback; mySkin: TThemeEqualizer); -var I: Integer; +var + I: integer; begin - If (Source <> nil) then + if (Source <> nil) then begin - X := mySkin.X; - Y := mySkin.Y; - W := mySkin.W; - H := mySkin.H; - Z := mySkin.Z; + X := mySkin.X; + Y := mySkin.Y; + W := mySkin.W; + H := mySkin.H; + Z := mySkin.Z; - Space := mySkin.Space; + Space := mySkin.Space; - Visible := mySkin.Visible; - Alpha := mySkin.Alpha; - Color.R := mySkin.ColR; - Color.G := mySkin.ColG; - Color.B := mySkin.ColB; + 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; + Direction := mySkin.Direction; + Bands := mySkin.Bands; + BandLength := mySkin.Length; Reflection := mySkin.Reflection; Reflectionspacing := mySkin.Reflectionspacing; @@ -116,31 +118,31 @@ begin //Check if Visible - If (Bands <= 0) OR - (BandLength <= 0) OR - (W <= 0) OR - (H <= 0) OR + if (Bands <= 0) or + (BandLength <= 0) or + (W <= 0) or + (H <= 0) or (Alpha <= 0) then - Visible := False; + Visible := false; //ClearArray - For I := low(BandData) to high(BandData) do + for I := low(BandData) to high(BandData) do BandData[I] := 3; end else - Visible := False; + Visible := false; end; //-------- // evaluate FFT-Data //-------- -Procedure Tms_Equalizer.Analyse; - var - I: Integer; - ChansPerBand: byte; // channels per band - MaxChannel: Integer; - Pos: Real; - CurBand: Integer; +procedure Tms_Equalizer.Analyse; +var + I: integer; + ChansPerBand: byte; // channels per band + MaxChannel: integer; + Pos: real; + CurBand: integer; begin Source.GetFFTData(FFTData); @@ -188,25 +190,26 @@ end; // Draw SpectrumAnalyser, Call Analyse //-------- procedure Tms_Equalizer.Draw; - var - CurTime: Cardinal; - PosX, PosY: Real; - I, J: Integer; - Diff: Real; +var + CurTime: cardinal; + PosX, PosY: real; + I, J: integer; + Diff: real; - Function GetAlpha(Diff: Single): Single; + function GetAlpha(Diff: single): single; begin - If Direction then - Result := (Alpha * 0.6) *(0.5 - Diff/(BandLength * (H + Space))) + if Direction then + Result := (Alpha * 0.6) * (0.5 - Diff/(BandLength * (H + Space))) else - Result := (Alpha * 0.6) *(0.5 - Diff/(Bands * (H + Space))); + Result := (Alpha * 0.6) * (0.5 - Diff/(Bands * (H + Space))); end; + begin - If (Visible) AND not (AudioPlayback.Finished) then + if (Visible) and not (AudioPlayback.Finished) then begin //Call Analyse if necessary CurTime := SDL_GetTicks(); - If (CurTime > RefreshTime) then + if (CurTime > RefreshTime) then begin Analyse; @@ -244,12 +247,12 @@ begin glVertex3f(PosX+W, PosY, Z); glEnd; - If (Reflection) AND (J <= BandLength div 2) then + if (Reflection) and (J <= BandLength div 2) then begin Diff := (Y-PosY) + H; //Draw Reflection - If Direction then + if Direction then begin glBegin(GL_QUADS); glColorRGB(Color, GetAlpha(Diff)); @@ -298,22 +301,20 @@ begin end; end; -Procedure Tms_Equalizer.SetBands(Value: Byte); +procedure Tms_Equalizer.SetBands(Value: byte); begin SetLength(BandData, Value); end; -Function Tms_Equalizer.GetBands: Byte; +function Tms_Equalizer.GetBands: byte; begin Result := Length(BandData); end; -Procedure Tms_Equalizer.SetSource(newSource: IAudioPlayback); +procedure Tms_Equalizer.SetSource(newSource: IAudioPlayback); begin - If (newSource <> nil) then + 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 index 4c2d4e86..beb6bcef 100644 --- a/src/menu/UMenuInteract.pas +++ b/src/menu/UMenuInteract.pas @@ -35,8 +35,8 @@ interface 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 + 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; implementation diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 1a0fa725..a7133492 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -61,10 +61,10 @@ type PData: ^integer; //For automatically Setting LineCount - Lines: Byte; + Lines: byte; //Visibility - Visible: Boolean; + Visible: boolean; // for selection and deselection // main static @@ -121,7 +121,7 @@ type // procedures procedure SetSelect(Value: boolean); - property Selected: Boolean read SelectBool write SetSelect; + property Selected: boolean read SelectBool write SetSelect; procedure SetSelectOpt(Value: integer); property SelectedOption: integer read SelectOptInt write SetSelectOpt; procedure Draw; @@ -132,7 +132,11 @@ type end; implementation -uses UDrawTexture, math, ULog, SysUtils; +uses + UDrawTexture, + math, + ULog, + SysUtils; // ------------ Select constructor TSelectSlide.Create; @@ -145,7 +149,7 @@ begin //Set Standard Width for Selections Background SBGW := 450; - Visible := True; + Visible := true; {SetLength(TextOpt, 3); TextOpt[0] := TText.Create; TextOpt[1] := TText.Create; @@ -154,11 +158,12 @@ end; procedure TSelectSlide.SetSelect(Value: boolean); {var - SO: integer; - I: integer;} + SO: integer; + I: integer;} begin SelectBool := Value; - if Value then begin + if Value then + begin Texture.ColR := ColR; Texture.ColG := ColG; Texture.ColB := ColB; @@ -181,7 +186,9 @@ begin TextOpt[I].Int := STInt; end;} - end else begin + end + else + begin Texture.ColR := DColR; Texture.ColG := DColG; Texture.ColB := DColB; @@ -208,12 +215,13 @@ end; procedure TSelectSlide.SetSelectOpt(Value: integer); var - SO: integer; - HalfL: integer; - HalfR: integer; + SO: integer; + HalfL: integer; + HalfR: integer; -procedure DoSelection(Sel: Cardinal); - var I: Integer; +procedure DoSelection(Sel: cardinal); + var + I: integer; begin for I := low(TextOpt) to high(TextOpt) do begin @@ -244,7 +252,7 @@ begin for SO := low (TextOpt) to high(TextOpt) do begin - TextOpt[SO].Text := TextOptT[SO]; + TextOpt[SO].Text := TextOptT[SO]; end; DoSelection(0); @@ -255,50 +263,50 @@ begin for SO := high(TextOpt) downto low (TextOpt) do begin - TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; end; DoSelection(Lines-1); end else begin - HalfL := Ceil((Lines-1)/2); - HalfR := Lines-1-HalfL; - - if (Value <= HalfL) then - begin //Selected Option is near to the left side - {HalfL := Value; - HalfR := Lines-1-HalfL;} - //Change Texts - for SO := low (TextOpt) to high(TextOpt) do + HalfL := Ceil((Lines-1)/2); + HalfR := Lines-1-HalfL; + + if (Value <= HalfL) then + begin //Selected Option is near to the left side + {HalfL := Value; + HalfR := Lines-1-HalfL;} + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(Value); + end + else if (Value > High(TextOptT)-HalfR) then + begin //Selected is too near to the right border + HalfR := high(TextOptT) - Value; + HalfL := Lines-1-HalfR; + //Change Texts + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + end; + + DoSelection (HalfL); + end + else begin - TextOpt[SO].Text := TextOptT[SO]; - end; + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; + end; - DoSelection(Value); - end - else if (Value > High(TextOptT)-HalfR) then - begin //Selected is too near to the right border - HalfR := high(TextOptT) - Value; - HalfL := Lines-1-HalfR; - //Change Texts - for SO := high(TextOpt) downto low (TextOpt) do - begin - TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + DoSelection(HalfL); end; - DoSelection (HalfL); - end - else - begin - //Change Texts - for SO := low (TextOpt) to high(TextOpt) do - begin - TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; - end; - - DoSelection(HalfL); - end; - end; end; @@ -307,7 +315,7 @@ end; procedure TSelectSlide.Draw; var - SO: integer; + SO: integer; begin if Visible then begin @@ -323,8 +331,8 @@ end; procedure TSelectSlide.GenLines; var -maxlength: Real; -I: Integer; + maxlength: real; + I: integer; begin SetFontStyle(0{Text.Style}); SetFontSize(Text.Size); @@ -344,37 +352,37 @@ begin Lines := 1; //Free old Space used by Texts - For I := low(TextOpt) to high(TextOpt) do + 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].Align := 1; - TextOpt[I].Align := 0; - TextOpt[I].Visible := True; - - TextOpt[I].ColR := STDColR; - TextOpt[I].ColG := STDColG; - TextOpt[I].ColB := STDColB; - TextOpt[I].Int := STDInt; - - //Generate Positions - //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); - if (I <> High(TextOpt)) OR (High(TextOpt) = 0) OR (Length(TextOptT) = Lines) then - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I - else - TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; + for I := low(TextOpt) to high(TextOpt) do + begin + TextOpt[I] := TText.Create; + TextOpt[I].Size := Text.Size; + //TextOpt[I].Align := 1; + TextOpt[I].Align := 0; + TextOpt[I].Visible := true; + + TextOpt[I].ColR := STDColR; + TextOpt[I].ColG := STDColG; + TextOpt[I].ColB := STDColB; + TextOpt[I].Int := STDInt; + + //Generate Positions + //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); + if (I <> High(TextOpt)) OR (High(TextOpt) = 0) OR (Length(TextOptT) = Lines) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I + else + TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; - TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H - Text.Size) / 2; + TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H - Text.Size) / 2; - //Better Look with 2 Options - if (Lines=2) AND (Length(TextOptT)= 2) then - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(TextOptT[1])) * I; - end; + //Better Look with 2 Options + if (Lines=2) AND (Length(TextOptT)= 2) then + TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(TextOptT[1])) * I; + end; end; end. diff --git a/src/menu/UMenuStatic.pas b/src/menu/UMenuStatic.pas index 9a10fade..72f4eb36 100644 --- a/src/menu/UMenuStatic.pas +++ b/src/menu/UMenuStatic.pas @@ -40,19 +40,20 @@ uses type TStatic = class public - Texture: TTexture; // Button Screen position and size - Visible: boolean; + Texture: TTexture; // Button Screen position and size + Visible: boolean; //Reflection Mod - Reflection: boolean; - Reflectionspacing: Real; + Reflection: boolean; + Reflectionspacing: real; procedure Draw; constructor Create(Textura: TTexture); overload; end; implementation -uses UDrawTexture; +uses + UDrawTexture; procedure TStatic.Draw; begin -- cgit v1.2.3 From 353fb6f537d3cbccc5cad6b5cfa7fa6e7c899510 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Fri, 22 May 2009 14:58:41 +0000 Subject: cosmetics and buildbot trigger git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1760 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuText.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/menu') diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index 6cf53200..0f9c753f 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -48,7 +48,7 @@ type TextString: string; TextTiles: array of string; - STicks: Cardinal; + STicks: cardinal; SelectBlink: boolean; public X: real; -- cgit v1.2.3 From 69d651dd5933520713ac0ecb4875f0e6702ba002 Mon Sep 17 00:00:00 2001 From: mogguh Date: Tue, 26 May 2009 23:01:19 +0000 Subject: Statics defined in theme don't necessarily need a width or height set, if omitted the the values from the texture itself will be used SelectSlides may now have arrows and only one item set, default is off - view UScreenOptionsGame.pas as example on how to set this git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1783 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 32 +++++++++++++++++++++++---- src/menu/UMenuSelectSlide.pas | 50 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 11 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index f86746ed..ceb4ac77 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -652,12 +652,22 @@ begin begin Static[StatNum] := TStatic.Create(Texture.GetTexture(Name, Typ, Color)); // new skin end; - + // configures static Static[StatNum].Texture.X := X; Static[StatNum].Texture.Y := Y; - Static[StatNum].Texture.W := W; - Static[StatNum].Texture.H := H; + + //Set height and width via sprite size if omitted + if(H = 0) then + Static[StatNum].Texture.H := Static[StatNum].Texture.H + else + Static[StatNum].Texture.H := H; + + if(W = 0) then + Static[StatNum].Texture.W := Static[StatNum].Texture.W + else + Static[StatNum].Texture.W := W; + Static[StatNum].Texture.Z := Z; if (Typ <> TEXTURE_TYPE_COLORIZED) then begin @@ -1212,6 +1222,9 @@ begin SelectsS[High(SelectsS)].Texture.Z := ThemeSelectS.Z; SelectsS[High(SelectsS)].TextureSBG.Z := ThemeSelectS.Z; + SelectsS[High(SelectsS)].showArrows := ThemeSelectS.showArrows; + SelectsS[High(SelectsS)].oneItemOnly := ThemeSelectS.oneItemOnly; + //Generate Lines SelectsS[High(SelectsS)].GenLines; @@ -1255,9 +1268,20 @@ begin else SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp); + 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; + 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; + 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].TextureSBG.W := 450; SelectsS[S].SBGW := SBGW; SelectsS[S].TextureSBG.H := H; SelectsS[S].SBGColR := SBGColR; diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index a7133492..81870ab8 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -54,8 +54,8 @@ type TextureSBG: TTexture; // Background Selections Texture // TextureS: array of TTexture; // Selections Texture (not used) -// TextureArrowL: TTexture; // Texture for left arrow (not used yet) -// TextureArrowR: TTexture; // Texture for right arrow (not used yet) + Tex_SelectS_ArrowL: TTexture; // Texture for left arrow + Tex_SelectS_ArrowR: TTexture; // Texture for right arrow SelectOptInt: integer; PData: ^integer; @@ -63,6 +63,12 @@ type //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; @@ -147,7 +153,7 @@ begin TextOpt[0] := TText.Create; //Set Standard Width for Selections Background - SBGW := 450; +// SBGW := 400; Visible := true; {SetLength(TextOpt, 3); @@ -250,6 +256,8 @@ begin begin //First Option Selected Value := 0; + Tex_SelectS_ArrowL.alpha := 0; + for SO := low (TextOpt) to high(TextOpt) do begin TextOpt[SO].Text := TextOptT[SO]; @@ -261,6 +269,8 @@ begin begin //Last Option Selected Value := high(TextOptT); + Tex_SelectS_ArrowR.alpha := 0; + for SO := high(TextOpt) downto low (TextOpt) do begin TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; @@ -269,6 +279,9 @@ begin end else begin + Tex_SelectS_ArrowL.alpha := 1; + Tex_SelectS_ArrowR.alpha := 1; + HalfL := Ceil((Lines-1)/2); HalfR := Lines-1-HalfL; @@ -322,6 +335,11 @@ begin DrawTexture(Texture); DrawTexture(TextureSBG); + if(showArrows) then begin + DrawTexture(Tex_SelectS_ArrowL); + DrawTexture(Tex_SelectS_ArrowR); + end; + Text.Draw; for SO := low(TextOpt) to high(TextOpt) do @@ -329,6 +347,8 @@ begin end; end; + + procedure TSelectSlide.GenLines; var maxlength: real; @@ -344,12 +364,22 @@ begin maxlength := glTextWidth(TextOptT[I]); end; - Lines := floor((TextureSBG.W-40) / (maxlength+7)); - if (Lines > Length(TextOptT)) then - Lines := Length(TextOptT); - if (Lines <= 0) then + if(oneItemOnly = false) then + begin + //show all items + Lines := floor((TextureSBG.W-40) / (maxlength+7)); + 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 @@ -382,6 +412,12 @@ begin //Better Look with 2 Options if (Lines=2) AND (Length(TextOptT)= 2) then TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(TextOptT[1])) * I; + + if (Lines=1) then + begin + TextOpt[I].Align := 1; //center text + TextOpt[I].X := TextureSBG.X + (TextureSBG.W / 2); + end; end; end; -- cgit v1.2.3 From bee4da886058f54ec7e1901951b5c1bf05f8ea34 Mon Sep 17 00:00:00 2001 From: mogguh Date: Wed, 27 May 2009 22:09:26 +0000 Subject: All options do have one option visible now FIXED: SelectSlides with only two options did not show arrows on reelection ENHANCEMENT: Beautified some portions of UMenuSelectSlide.pas code git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1784 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuSelectSlide.pas | 102 ++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 59 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 81870ab8..e416c357 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -151,15 +151,7 @@ begin Text := TText.Create; SetLength(TextOpt, 1); TextOpt[0] := TText.Create; - - //Set Standard Width for Selections Background -// SBGW := 400; - Visible := true; - {SetLength(TextOpt, 3); - TextOpt[0] := TText.Create; - TextOpt[1] := TText.Create; - TextOpt[2] := TText.Create;} end; procedure TSelectSlide.SetSelect(Value: boolean); @@ -184,14 +176,6 @@ begin TextureSBG.ColG := SBGColG; TextureSBG.ColB := SBGColB; TextureSBG.Int := SBGInt; - -{ for I := 0 to High(TextOpt) do begin - TextOpt[I].ColR := STColR; - TextOpt[I].ColG := STColG; - TextOpt[I].ColB := STColB; - TextOpt[I].Int := STInt; - end;} - end else begin @@ -209,13 +193,6 @@ begin TextureSBG.ColG := SBGDColG; TextureSBG.ColB := SBGDColB; TextureSBG.Int := SBGDInt; - -{ for I := 0 to High(TextOpt) do begin - TextOpt[I].ColR := STDColR; - TextOpt[I].ColG := STDColG; - TextOpt[I].ColB := STDColB; - TextOpt[I].Int := STDInt; - end;} end; end; @@ -225,7 +202,7 @@ var HalfL: integer; HalfR: integer; -procedure DoSelection(Sel: cardinal); + procedure DoSelection(Sel: cardinal); var I: integer; begin @@ -236,39 +213,45 @@ procedure DoSelection(Sel: cardinal); 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; - end; + begin SelectOptInt := Value; PData^ := Value; -// SetSelect(true); // reset all colors if (Length(TextOpt)>0) AND (Length(TextOptT)>0) then begin + //First option selected if (Value <= 0) then - begin //First Option Selected + begin Value := 0; Tex_SelectS_ArrowL.alpha := 0; + Tex_SelectS_ArrowR.alpha := 1; - for SO := low (TextOpt) to high(TextOpt) do + for SO := low(TextOpt) to high(TextOpt) do begin TextOpt[SO].Text := TextOptT[SO]; end; DoSelection(0); end + + //Last option selected else if (Value >= high(TextOptT)) then - begin //Last Option Selected + begin Value := high(TextOptT); + Tex_SelectS_ArrowL.alpha := 1; Tex_SelectS_ArrowR.alpha := 0; for SO := high(TextOpt) downto low (TextOpt) do @@ -277,6 +260,8 @@ begin end; DoSelection(Lines-1); end + + //in between first and last else begin Tex_SelectS_ArrowL.alpha := 1; @@ -285,45 +270,44 @@ begin HalfL := Ceil((Lines-1)/2); HalfR := Lines-1-HalfL; + //Selected option is near to the left side if (Value <= HalfL) then - begin //Selected Option is near to the left side - {HalfL := Value; - HalfR := Lines-1-HalfL;} - //Change Texts - for SO := low (TextOpt) to high(TextOpt) do - begin - TextOpt[SO].Text := TextOptT[SO]; - end; - - DoSelection(Value); + begin + //Change texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[SO]; + end; + + DoSelection(Value); end + + //Selected option is near to the right side else if (Value > High(TextOptT)-HalfR) then - begin //Selected is too near to the right border - HalfR := high(TextOptT) - Value; - HalfL := Lines-1-HalfR; - //Change Texts - for SO := high(TextOpt) downto low (TextOpt) do - begin - TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; - end; - - DoSelection (HalfL); + begin + HalfR := high(TextOptT) - Value; + HalfL := Lines-1-HalfR; + //Change texts + for SO := high(TextOpt) downto low (TextOpt) do + begin + TextOpt[SO].Text := 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 := TextOptT[Value - HalfL + SO]; - end; + //Change Texts + for SO := low (TextOpt) to high(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; + end; - DoSelection(HalfL); + DoSelection(HalfL); end; - end; - end; - end; procedure TSelectSlide.Draw; @@ -335,7 +319,7 @@ begin DrawTexture(Texture); DrawTexture(TextureSBG); - if(showArrows) then begin + if(showArrows && ) then begin DrawTexture(Tex_SelectS_ArrowL); DrawTexture(Tex_SelectS_ArrowR); end; -- cgit v1.2.3 From 4e661804e87a9614ca16d6d83acbb736d8315c5a Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Thu, 28 May 2009 11:13:17 +0000 Subject: cosmetical removal of Warning: Constructor should be public git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1785 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuButton.pas | 74 ++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuButton.pas b/src/menu/UMenuButton.pas index c6ff8ab7..923f0b14 100644 --- a/src/menu/UMenuButton.pas +++ b/src/menu/UMenuButton.pas @@ -55,7 +55,6 @@ type PosX, PosY: real; - constructor Create(); overload; public Text: array of TText; @@ -113,6 +112,7 @@ type procedure Draw; virtual; + constructor Create(); overload; constructor Create(Textura: TTexture); overload; constructor Create(Textura, DSTexture: TTexture); overload; destructor Destroy; override; @@ -252,42 +252,6 @@ begin end; 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; - // ***** Public methods ****** // procedure TButton.Draw; @@ -571,6 +535,42 @@ 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(); -- cgit v1.2.3 From 80d95a1ba9cd147310ffda7a6c9cd8c0c04f801f Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Thu, 28 May 2009 17:44:59 +0000 Subject: fix the bug from rev. 1784. mog has to review this! git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1787 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuSelectSlide.pas | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index e416c357..63ec8698 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -319,7 +319,11 @@ begin DrawTexture(Texture); DrawTexture(TextureSBG); - if(showArrows && ) then begin +// if(showArrows && ) then begin +// The line above is from mog but with an error. +// The line below fixes the syntax, but what did mog actually wanted to do? + if (showArrows) then + begin DrawTexture(Tex_SelectS_ArrowL); DrawTexture(Tex_SelectS_ArrowR); end; @@ -331,8 +335,6 @@ begin end; end; - - procedure TSelectSlide.GenLines; var maxlength: real; -- cgit v1.2.3 From 1d3a28457fb5ff32d55435e31a5697fd383366d4 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Thu, 28 May 2009 18:19:32 +0000 Subject: comment removed. Successful review from mog. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1788 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuSelectSlide.pas | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 63ec8698..a5929a3e 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -319,9 +319,6 @@ begin DrawTexture(Texture); DrawTexture(TextureSBG); -// if(showArrows && ) then begin -// The line above is from mog but with an error. -// The line below fixes the syntax, but what did mog actually wanted to do? if (showArrows) then begin DrawTexture(Tex_SelectS_ArrowL); -- cgit v1.2.3 From 257854c587f0876a912cfbeb4fe0a30970d25a9b Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 31 May 2009 14:10:42 +0000 Subject: merged (experimental) mouse support patch by d0ccrazy some changes to patch - implemented software cursor (texturable) - option to turn of mouse support or switch between hardware and software cursor - hide software cursor if there is no mouse activity for 5 seconds - soft fade in and out for software cursor - some test cursor-textures for deluxe theme (mog pls change these horible looking images) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1789 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/menu/UMenu.pas | 119 +++++++++++++++++++++++++++++-- 2 files changed, 303 insertions(+), 7 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 58c416db..10a80c00 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -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,11 +89,28 @@ 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; +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 uses @@ -125,6 +153,15 @@ begin //Set LastError for OSD to No Error OSD_LastError := 'No Errors'; + + // software cursor default values + Cursor_LastMove := SDL_GetTicks; + 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,160 @@ 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; + + if not Cursor_Visible 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; diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index ceb4ac77..7d8bdce8 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -35,6 +35,7 @@ interface uses gl, + SDL, SysUtils, UTexture, UMenuStatic, @@ -61,7 +62,7 @@ type ButtonPos: integer; Button: array of TButton; - + SelectsS: array of TSelectSlide; ButtonCollection: array of TButtonCollection; public @@ -72,6 +73,7 @@ type 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; @@ -82,7 +84,7 @@ type function WideCharUpperCase(wchar: WideChar) : WideString; function WideStringUpperCase(wstring: WideString) : WideString; procedure AddInteraction(Typ, Num: integer); - procedure SetInteraction(Num: integer); + procedure SetInteraction(Num: integer); virtual; property Interaction: integer read SelInteraction write SetInteraction; //Procedure Load BG, Texts, Statics and Button Collections from ThemeBasic @@ -145,9 +147,10 @@ type function DrawFG: boolean; virtual; function Draw: boolean; virtual; function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown : boolean): boolean; virtual; - // FIXME: ParseMouse is not implemented in any subclass and not even used anywhere in the code - // -> do this before activation of this method - //function ParseMouse(Typ: integer; X: integer; Y: integer): boolean; virtual; abstract; + function ParseMouse(MouseButton: Integer; BtnDown: Boolean; X, Y: integer): boolean; virtual; + function InRegion(X1, Y1, W, H, X, Y: real): Boolean; + function InteractAt(X, Y: real): Integer; + function CollectionAt(X, Y: real): Integer; procedure onShow; virtual; procedure onShowFinish; virtual; procedure onHide; virtual; @@ -167,8 +170,11 @@ type end; const - pmMove = 1; - pmClick = 2; + MENU_MDOWN = 8; + MENU_MUP = 0; + + pmMove = 1; + pmClick = 2; pmUnClick = 3; iButton = 0; // interaction type @@ -221,6 +227,8 @@ begin ButtonPos := -1; Background := nil; + + RightMbESC := True; end; { constructor TMenu.Create(Back: string); @@ -1595,6 +1603,103 @@ begin Result := true; end; +function TMenu.ParseMouse(MouseButton: Integer; BtnDown: Boolean; X, Y: integer): boolean; +var + nBut: Integer; +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; + + nBut := InteractAt(X, Y); + if nBut >= 0 then begin + //select on mouse-over + if nBut <> Interaction then + SetInteraction(nBut); + if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then begin + //click button + Result:=ParseInput(SDLK_RETURN, #0, True); + end; + if (Interactions[nBut].Typ = iSelectS) then begin + //forward/backward in select slide with mousewheel + if (MouseButton = SDL_BUTTON_WHEELDOWN) and BtnDown then begin + ParseInput(SDLK_RIGHT, #0, true); + end; + if (MouseButton = SDL_BUTTON_WHEELUP) and BtnDown then begin + ParseInput(SDLK_LEFT, #0, true); + end; + end; + end + else begin + nBut := CollectionAt(X, Y); + if nBut >= 0 then begin + //if over button collection, select first child but don't allow click + nBut := ButtonCollection[nBut].FirstChild - 1; + if nBut <> Interaction then + SetInteraction(nBut); + end; + end; +end; + +function TMenu.InRegion(X1, Y1, W, H, X, Y: real): Boolean; +begin + Result:=False; + X1 := X1 * Screen.w/800; + W := W * Screen.w/800; + Y1 := Y1 * Screen.h/600; + H := H * Screen.h/600; + if (X >= X1) and (X <= X1+W) and (Y >= Y1) and (Y <= Y1+H) then + Result := true; +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(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) and + Button[Interactions[i].Num].Visible then begin + Result:=i; + exit; + end; + iBCollectionChild:if InRegion(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) then begin + Result:=i; + exit; + end; + iSelectS:if InRegion(SelectSs[Interactions[i].Num].X, SelectSs[Interactions[i].Num].Y, SelectSs[Interactions[i].Num].W, SelectSs[Interactions[i].Num].H, X, Y) or + InRegion(SelectSs[Interactions[i].Num].TextureSBG.X, SelectSs[Interactions[i].Num].TextureSBG.Y, SelectSs[Interactions[i].Num].TextureSBG.W, SelectSs[Interactions[i].Num].TextureSBG.H, X, Y) 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(ButtonCollection[i].X, ButtonCollection[i].Y, ButtonCollection[i].W, ButtonCollection[i].H, X, Y) and + ButtonCollection[i].Visible then begin + Result:=i; + exit; + end; + end; +end; + procedure TMenu.SetAnimationProgress(Progress: real); begin // nothing -- cgit v1.2.3 From c966985d9af377f4c146d5ab0f241f31d5984676 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 31 May 2009 14:34:02 +0000 Subject: fixed a bug in UMenuText that causes (some of) the crashs in USongJumpTo some bad coding style by myself also fixed thx to AlexanderS git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1790 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuText.pas | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index 0f9c753f..b000cc73 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -260,7 +260,8 @@ procedure TText.Draw; var X2, Y2: real; Text2: string; - I: cardinal; + I: Integer; + Ticks: Cardinal; begin if Visible then begin @@ -279,10 +280,10 @@ begin //if selected set blink... if SelectBool then begin - I := SDL_GetTicks() div 550; - if I <> STicks then + Ticks := SDL_GetTicks() div 550; + if Ticks <> STicks then begin //Change Visability - STicks := I; + STicks := Ticks; SelectBlink := Not SelectBlink; end; end; @@ -309,17 +310,17 @@ begin //now use allways: //draw text as many strings Y2 := Y + MoveY; - for I := 0 to high(TextTiles) do + for I := 0 to High(TextTiles) do begin - if (not (SelectBool and SelectBlink)) or (I <> cardinal(high(TextTiles))) then + if (not (SelectBool and SelectBlink)) or (I <> High(TextTiles)) then Text2 := TextTiles[I] else Text2 := TextTiles[I] + '|'; case Align of - 0: X2 := X + MoveX; - 1: X2 := X + MoveX - glTextWidth(Text2)/2; - 2: X2 := X + MoveX - glTextWidth(Text2); + 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); -- cgit v1.2.3 From fc31c286841cf746cc791ce436d54ed224cd1d52 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 31 May 2009 20:44:00 +0000 Subject: software cursor is now hidden on startup git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1791 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 10a80c00..e4e2839d 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -155,7 +155,7 @@ begin OSD_LastError := 'No Errors'; // software cursor default values - Cursor_LastMove := SDL_GetTicks; + Cursor_LastMove := 0; Cursor_Visible := false; Cursor_Pressed := false; Cursor_X := -1; @@ -405,7 +405,8 @@ begin Ticks := SDL_GetTicks; - if not Cursor_Visible then + { 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)) -- cgit v1.2.3 From 133f0b4ebcc3b731e680a72ced52d00638791bf7 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Thu, 4 Jun 2009 21:31:23 +0000 Subject: cosmetics git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1800 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 76 +++++++------- src/menu/UMenu.pas | 239 ++++++++++++++++++++++++++---------------- src/menu/UMenuSelectSlide.pas | 75 ++++++------- src/menu/UMenuText.pas | 152 ++++++++++++++------------- 4 files changed, 304 insertions(+), 238 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index e4e2839d..f2eb2ced 100644 --- a/src/menu/UDisplay.pas +++ b/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.) @@ -61,15 +61,15 @@ 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 + 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; + Cursor_Visible: boolean; + Cursor_LastMove: cardinal; + Cursor_Fade: boolean; procedure DrawDebugInformation; public @@ -94,7 +94,7 @@ type procedure SetCursor; { called when cursor moves, positioning of software cursor } - procedure MoveCursor(X, Y: Double; Pressed: Boolean); + procedure MoveCursor(X, Y: double; Pressed: boolean); { draws software cursor } @@ -102,7 +102,7 @@ type end; var - Display: TDisplay; + Display: TDisplay; const { constants for software cursor effects @@ -138,9 +138,9 @@ begin BlackScreen := false; // fade mod - FadeState := 0; + FadeState := 0; FadeEnabled := (Ini.ScreenFade = 1); - FadeFailed:= false; + FadeFailed := false; glGenTextures(2, @FadeTex); @@ -350,8 +350,8 @@ end; { sets SDL_ShowCursor depending on options set in Ini } procedure TDisplay.SetCursor; - var - Cursor: Integer; +var + Cursor: Integer; begin Cursor := 0; @@ -393,11 +393,12 @@ begin end; { called when cursor moves, positioning of software cursor } -procedure TDisplay.MoveCursor(X, Y: Double; Pressed: Boolean); +procedure TDisplay.MoveCursor(X, Y: double; Pressed: boolean); var - Ticks: Cardinal; + Ticks: cardinal; begin - if (Ini.Mouse = 2) and ((X <> Cursor_X) or (Y <> Cursor_Y) or (Pressed <> Cursor_Pressed)) then + if (Ini.Mouse = 2) and + ((X <> Cursor_X) or (Y <> Cursor_Y) or (Pressed <> Cursor_Pressed)) then begin Cursor_X := X; Cursor_Y := Y; @@ -408,13 +409,13 @@ begin { 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 + 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; + Cursor_Visible := true; + Cursor_Fade := true; end else if not Cursor_Fade then begin @@ -425,9 +426,9 @@ end; { draws software cursor } procedure TDisplay.DrawCursor; - var - Alpha: Single; - Ticks: Cardinal; +var + Alpha: single; + Ticks: cardinal; begin if (Ini.Mouse = 2) then begin // draw software cursor @@ -435,25 +436,25 @@ begin 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_Visible := false; Cursor_LastMove := Ticks; - Cursor_Fade := True; + Cursor_Fade := true; end; // fading - if (Cursor_Fade) then + if Cursor_Fade then begin - if (Cursor_Visible) then + if Cursor_Visible then begin // fade in if (Cursor_LastMove + Cursor_FadeIn_Time <= Ticks) then - Cursor_Fade := False + 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 + Cursor_Fade := false else Alpha := cos((Ticks - Cursor_LastMove) * 0.5 * pi / Cursor_FadeOut_Time) * 0.7; end; @@ -552,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); @@ -569,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 @@ -586,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); diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 7d8bdce8..a3f47b3d 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -34,20 +34,20 @@ interface {$I switches.inc} uses + SysUtils, + Math, gl, SDL, - SysUtils, - UTexture, - UMenuStatic, - UMenuText, - UMenuButton, - UMenuSelectSlide, - UMenuInteract, UMenuBackground, - UThemes, + UMenuButton, UMenuButtonCollection, - Math, - UMusic; + UMenuInteract, + UMenuSelectSlide, + UMenuStatic, + UMenuText, + UMusic, + UTexture, + UThemes; type { Int16 = SmallInt;} @@ -87,7 +87,7 @@ type procedure SetInteraction(Num: integer); virtual; property Interaction: integer read SelInteraction write SetInteraction; - //Procedure Load BG, Texts, Statics and Button Collections from ThemeBasic + // procedure load bg, texts, statics and button collections from themebasic procedure LoadFromTheme(const ThemeBasic: TThemeBasic); procedure PrepareButtonCollections(const Collections: AThemeButtonCollection); @@ -147,10 +147,10 @@ type function DrawFG: boolean; virtual; function Draw: boolean; virtual; function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown : boolean): boolean; virtual; - function ParseMouse(MouseButton: Integer; BtnDown: Boolean; X, Y: integer): boolean; virtual; - function InRegion(X1, Y1, W, H, X, Y: real): Boolean; - function InteractAt(X, Y: real): Integer; - function CollectionAt(X, Y: real): Integer; + function ParseMouse(MouseButton: integer; BtnDown: boolean; X, Y: integer): boolean; virtual; + function InRegion(X1, Y1, W, H, X, Y: real): boolean; + function InteractAt(X, Y: real): integer; + function CollectionAt(X, Y: real): integer; procedure onShow; virtual; procedure onShowFinish; virtual; procedure onHide; virtual; @@ -171,10 +171,10 @@ type const MENU_MDOWN = 8; - MENU_MUP = 0; + MENU_MUP = 0; - pmMove = 1; - pmClick = 2; + pmMove = 1; + pmClick = 2; pmUnClick = 3; iButton = 0; // interaction type @@ -189,14 +189,14 @@ implementation uses UCommon, - ULog, - UMain, + UCovers, + UDisplay, UDrawTexture, UGraphic, - UDisplay, - UCovers, - UTime, + ULog, + UMain, USkins, + UTime, //Background types UMenuBackgroundNone, UMenuBackgroundColor, @@ -228,7 +228,7 @@ begin Background := nil; - RightMbESC := True; + RightMbESC := true; end; { constructor TMenu.Create(Back: string); @@ -260,7 +260,7 @@ begin BackH := H; end; } -function RGBFloatToInt(R, G, B: Double): cardinal; +function RGBFloatToInt(R, G, B: double): cardinal; begin Result := (Trunc(255 * R) shl 16) or (Trunc(255 * G) shl 8) or @@ -299,8 +299,8 @@ begin 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 + // 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; @@ -604,17 +604,25 @@ begin Result := AddStatic(X, Y, W, H, Name, TEXTURE_TYPE_PLAIN); end; -function TMenu.AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; +function TMenu.AddStatic(X, Y, W, H: real; + ColR, ColG, ColB: real; + const Name: string; + Typ: TTextureType): integer; begin Result := AddStatic(X, Y, W, H, ColR, ColG, ColB, Name, Typ, $FFFFFF); end; -function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; +function TMenu.AddStatic(X, Y, W, H, Z: real; + ColR, ColG, ColB: real; + const Name: string; + Typ: TTextureType): integer; begin Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, Name, Typ, $FFFFFF); end; -function TMenu.AddStatic(X, Y, W, H: real; const Name: string; Typ: TTextureType): integer; +function TMenu.AddStatic(X, Y, W, H: real; + const Name: string; + Typ: TTextureType): integer; var StatNum: integer; begin @@ -632,17 +640,32 @@ begin Result := StatNum; end; -function TMenu.AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; +function TMenu.AddStatic(X, Y, W, H: real; + ColR, ColG, ColB: real; + const Name: string; + Typ: TTextureType; + Color: integer): integer; begin Result := AddStatic(X, Y, W, H, 0, ColR, ColG, ColB, Name, Typ, Color); end; -function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; +function TMenu.AddStatic(X, Y, W, H, Z: real; + ColR, ColG, ColB: real; + const Name: string; + Typ: TTextureType; + Color: integer): integer; begin Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, 0, 0, 1, 1, Name, Typ, Color, false, 0); end; -function TMenu.AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: boolean; ReflectionSpacing: real): integer; +function TMenu.AddStatic(X, Y, W, H, Z: real; + ColR, ColG, ColB: real; + TexX1, TexY1, TexX2, TexY2: real; + const Name: string; + Typ: TTextureType; + Color: integer; + Reflection: boolean; + ReflectionSpacing: real): integer; var StatNum: integer; begin @@ -714,12 +737,22 @@ begin Result := TextNum; end; -function TMenu.AddText(X, Y: real; Style: integer; Size, ColR, ColG, ColB: real; const Text: string): integer; +function TMenu.AddText(X, Y: real; + Style: integer; + Size, ColR, ColG, ColB: real + ; const Text: string): 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_: string; Reflection_: boolean; ReflectionSpacing_: real; Z : real): integer; +function TMenu.AddText(X, Y, W: real; + Style: integer; + Size, ColR, ColG, ColB: real; + Align: integer; + const Text_: string; + Reflection_: boolean; + ReflectionSpacing_: real; + Z : real): integer; var TextNum: integer; begin @@ -789,10 +822,10 @@ begin ThemeButton.Text[BT].Text); end; - //BAutton Collection Mod + // bautton collection mod if (ThemeButton.Parent <> 0) then begin - //If Collection Exists then Change Interaction to Child Button + // if collection exists then change interaction to child button if (@ButtonCollection[ThemeButton.Parent-1] <> nil) then begin Interactions[High(Interactions)].Typ := iBCollectionChild; @@ -821,8 +854,10 @@ begin end; function TMenu.AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; - const Name: string; Typ: TTextureType; - Reflection: boolean; ReflectionSpacing, DeSelectReflectionSpacing: real): integer; + const Name: string; + Typ: TTextureType; + Reflection: boolean; + ReflectionSpacing, DeSelectReflectionSpacing: real): integer; begin // adds button //SetLength is used once to reduce Memory usement @@ -875,7 +910,7 @@ begin Button[Result].Reflectionspacing := ReflectionSpacing; Button[Result].DeSelectReflectionspacing := DeSelectReflectionSpacing; - //Button Collection Mod + // button collection mod Button[Result].Parent := 0; // adds interaction @@ -888,11 +923,10 @@ begin Setlength(Button, 0); end; -// Method to draw our TMenu and all his child buttons +// method to draw our tmenu and all his child buttons function TMenu.DrawBG: boolean; begin Background.Draw; - Result := true; end; @@ -1011,9 +1045,10 @@ begin Int := Int - ceil(Length(Interactions) / 2); //Set Interaction - if ((Int < 0) or (Int > Length(Interactions) - 1)) - then Int := Interaction //nonvalid button, keep current one - else Interaction := Int; //select row above + 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; @@ -1025,9 +1060,10 @@ begin Int := Int + ceil(Length(Interactions) / 2); //Set Interaction - if ((Int < 0) or (Int > Length(Interactions) - 1)) - then Int := Interaction //nonvalid button, keep current one - else Interaction := Int; //select row above + 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; @@ -1041,7 +1077,8 @@ begin Int := (Int + 1) mod Length(Interactions); //If no Interaction is Selectable Simply Select Next - if (Int = Interaction) then Break; + if (Int = Interaction) then + Break; until IsSelectable(Int); @@ -1058,10 +1095,12 @@ begin // change interaction as long as it's needed repeat Int := Int - 1; - if Int = -1 then Int := High(Interactions); + if Int = -1 then + Int := High(Interactions); //If no Interaction is Selectable Simply Select Next - if (Int = Interaction) then Break; + if (Int = Interaction) then + Break; until IsSelectable(Int); //Set Interaction @@ -1086,7 +1125,8 @@ begin while (Again = true) do begin Num := SelInteraction - CustomSwitch; - if Num = -1 then Num := High(Interactions); + if Num = -1 then + Num := High(Interactions); Interaction := Num; Again := false; // reset, default to accept changing interaction @@ -1387,10 +1427,12 @@ begin SetLength(SelectsS[SelectNo].TextOptT, SO + 1); SelectsS[SelectNo].TextOptT[SO] := AddText; +{ + SelectsS[S].SelectedOption := SelectsS[S].SelectOptInt; // refresh - //SelectsS[S].SelectedOption := SelectsS[S].SelectOptInt; // refresh - - //if SO = Selects[S].PData^ then Selects[S].SelectedOption := SO; + if SO = Selects[S].PData^ then + Selects[S].SelectedOption := SO; +} end; procedure TMenu.UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; SelectNum: integer; Values: array of string; var Data: integer); @@ -1490,11 +1532,11 @@ begin end; end; end; - //interact Prev if there is Nothing to Change + // interact prev if there is nothing to change else begin InteractPrev; - //If ButtonCollection with more than 1 Entry then Select Last Entry + // 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 @@ -1603,43 +1645,51 @@ begin Result := true; end; -function TMenu.ParseMouse(MouseButton: Integer; BtnDown: Boolean; X, Y: integer): boolean; +function TMenu.ParseMouse(MouseButton: integer; BtnDown: boolean; X, Y: integer): boolean; var - nBut: Integer; + nBut: integer; 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 and (MouseButton = SDL_BUTTON_RIGHT) and BtnDown then + begin //if RightMbESC is set, send ESC keypress - Result:=ParseInput(SDLK_ESCAPE, #0, True); + Result:=ParseInput(SDLK_ESCAPE, #0, true); end; nBut := InteractAt(X, Y); - if nBut >= 0 then begin + if nBut >= 0 then + begin //select on mouse-over if nBut <> Interaction then SetInteraction(nBut); - if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then begin + if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then + begin //click button - Result:=ParseInput(SDLK_RETURN, #0, True); + Result:=ParseInput(SDLK_RETURN, #0, true); end; - if (Interactions[nBut].Typ = iSelectS) then begin + if (Interactions[nBut].Typ = iSelectS) then + begin //forward/backward in select slide with mousewheel - if (MouseButton = SDL_BUTTON_WHEELDOWN) and BtnDown then begin + if (MouseButton = SDL_BUTTON_WHEELDOWN) and BtnDown then + begin ParseInput(SDLK_RIGHT, #0, true); end; - if (MouseButton = SDL_BUTTON_WHEELUP) and BtnDown then begin + if (MouseButton = SDL_BUTTON_WHEELUP) and BtnDown then + begin ParseInput(SDLK_LEFT, #0, true); end; end; end - else begin + else + begin nBut := CollectionAt(X, Y); - if nBut >= 0 then begin - //if over button collection, select first child but don't allow click + if nBut >= 0 then + begin + // if over button collection, select first child but don't allow click nBut := ButtonCollection[nBut].FirstChild - 1; if nBut <> Interaction then SetInteraction(nBut); @@ -1647,37 +1697,41 @@ begin end; end; -function TMenu.InRegion(X1, Y1, W, H, X, Y: real): Boolean; +function TMenu.InRegion(X1, Y1, W, H, X, Y: real): boolean; begin - Result:=False; - X1 := X1 * Screen.w/800; - W := W * Screen.w/800; - Y1 := Y1 * Screen.h/600; - H := H * Screen.h/600; - if (X >= X1) and (X <= X1+W) and (Y >= Y1) and (Y <= Y1+H) then + Result := false; + X1 := X1 * Screen.w / 800; + W := W * Screen.w / 800; + Y1 := Y1 * Screen.h / 600; + H := H * Screen.h / 600; + if (X >= X1) and (X <= X1 + W) and (Y >= Y1) and (Y <= Y1 + H) then Result := true; end; //takes x,y coordinates and returns the interaction number //of the control at this position -function TMenu.InteractAt(X, Y: real): Integer; +function TMenu.InteractAt(X, Y: real): integer; var - i, nBut: Integer; + i, nBut: integer; begin - Result:=-1; - for i:=Low(Interactions) to High(Interactions) do begin + Result := -1; + for i := Low(Interactions) to High(Interactions) do + begin case Interactions[i].Typ of - iButton:if InRegion(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) and - Button[Interactions[i].Num].Visible then begin + iButton: if InRegion(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) and + Button[Interactions[i].Num].Visible then + begin Result:=i; exit; end; - iBCollectionChild:if InRegion(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) then begin + iBCollectionChild: if InRegion(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) then + begin Result:=i; exit; end; - iSelectS:if InRegion(SelectSs[Interactions[i].Num].X, SelectSs[Interactions[i].Num].Y, SelectSs[Interactions[i].Num].W, SelectSs[Interactions[i].Num].H, X, Y) or - InRegion(SelectSs[Interactions[i].Num].TextureSBG.X, SelectSs[Interactions[i].Num].TextureSBG.Y, SelectSs[Interactions[i].Num].TextureSBG.W, SelectSs[Interactions[i].Num].TextureSBG.H, X, Y) then begin + iSelectS: if InRegion(SelectSs[Interactions[i].Num].X, SelectSs[Interactions[i].Num].Y, SelectSs[Interactions[i].Num].W, SelectSs[Interactions[i].Num].H, X, Y) or + InRegion(SelectSs[Interactions[i].Num].TextureSBG.X, SelectSs[Interactions[i].Num].TextureSBG.Y, SelectSs[Interactions[i].Num].TextureSBG.W, SelectSs[Interactions[i].Num].TextureSBG.H, X, Y) then + begin Result:=i; exit; end; @@ -1686,14 +1740,16 @@ begin end; //takes x,y coordinates and returns the button collection id -function TMenu.CollectionAt(X, Y: real): Integer; +function TMenu.CollectionAt(X, Y: real): integer; var - i, nBut: Integer; + i, nBut: integer; begin - Result:=-1; - for i:=Low(ButtonCollection) to High(ButtonCollection) do begin + Result := -1; + for i:= Low(ButtonCollection) to High(ButtonCollection) do + begin if InRegion(ButtonCollection[i].X, ButtonCollection[i].Y, ButtonCollection[i].W, ButtonCollection[i].H, X, Y) and - ButtonCollection[i].Visible then begin + ButtonCollection[i].Visible then + begin Result:=i; exit; end; @@ -1706,4 +1762,3 @@ begin end; end. - diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index a5929a3e..f9f6bbae 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -34,10 +34,10 @@ interface {$I switches.inc} uses - TextGL, - UTexture, gl, - UMenuText; + TextGL, + UMenuText, + UTexture; type PSelectSlide = ^TSelectSlide; @@ -64,10 +64,10 @@ type Lines: byte; //Arrows on/off - showArrows: Boolean; //default is false + showArrows: boolean; //default is false //whether to show one item or all that fit into the select - oneItemOnly:Boolean; //default is false + oneItemOnly: boolean; //default is false //Visibility Visible: boolean; @@ -138,11 +138,12 @@ type end; implementation + uses - UDrawTexture, math, - ULog, - SysUtils; + SysUtils, + UDrawTexture, + ULog; // ------------ Select constructor TSelectSlide.Create; @@ -206,7 +207,7 @@ var var I: integer; begin - for I := low(TextOpt) to high(TextOpt) do + for I := Low(TextOpt) to High(TextOpt) do begin TextOpt[I].ColR := STDColR; TextOpt[I].ColG := STDColG; @@ -214,7 +215,7 @@ var TextOpt[I].Int := STDInt; end; - if (integer(Sel) <= high(TextOpt)) then + if (integer(Sel) <= High(TextOpt)) then begin TextOpt[Sel].ColR := STColR; TextOpt[Sel].ColG := STColG; @@ -227,7 +228,7 @@ begin SelectOptInt := Value; PData^ := Value; - if (Length(TextOpt)>0) AND (Length(TextOptT)>0) then + if (Length(TextOpt) > 0) and (Length(TextOptT) > 0) then begin //First option selected @@ -238,7 +239,7 @@ begin Tex_SelectS_ArrowL.alpha := 0; Tex_SelectS_ArrowR.alpha := 1; - for SO := low(TextOpt) to high(TextOpt) do + for SO := Low(TextOpt) to High(TextOpt) do begin TextOpt[SO].Text := TextOptT[SO]; end; @@ -247,18 +248,18 @@ begin end //Last option selected - else if (Value >= high(TextOptT)) then + else if (Value >= High(TextOptT)) then begin - Value := high(TextOptT); + Value := High(TextOptT); Tex_SelectS_ArrowL.alpha := 1; Tex_SelectS_ArrowR.alpha := 0; - for SO := high(TextOpt) downto low (TextOpt) do + for SO := High(TextOpt) downto Low(TextOpt) do begin - TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + TextOpt[SO].Text := TextOptT[High(TextOptT) - (Lines - SO - 1)]; end; - DoSelection(Lines-1); + DoSelection(Lines - 1); end //in between first and last @@ -267,14 +268,14 @@ begin Tex_SelectS_ArrowL.alpha := 1; Tex_SelectS_ArrowR.alpha := 1; - HalfL := Ceil((Lines-1)/2); - HalfR := Lines-1-HalfL; + 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 + for SO := Low(TextOpt) to High(TextOpt) do begin TextOpt[SO].Text := TextOptT[SO]; end; @@ -283,25 +284,25 @@ begin end //Selected option is near to the right side - else if (Value > High(TextOptT)-HalfR) then + else if (Value > High(TextOptT) - HalfR) then begin - HalfR := high(TextOptT) - Value; - HalfL := Lines-1-HalfR; + HalfR := High(TextOptT) - Value; + HalfL := Lines - 1 - HalfR; //Change texts - for SO := high(TextOpt) downto low (TextOpt) do + for SO := High(TextOpt) downto Low(TextOpt) do begin - TextOpt[SO].Text := TextOptT[high(TextOptT)-(Lines-SO-1)]; + TextOpt[SO].Text := TextOptT[High(TextOptT) - (Lines - SO - 1)]; end; - DoSelection (HalfL); + DoSelection (HalfL); end else begin //Change Texts - for SO := low (TextOpt) to high(TextOpt) do + for SO := Low(TextOpt) to High(TextOpt) do begin - TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; + TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; end; DoSelection(HalfL); @@ -319,7 +320,7 @@ begin DrawTexture(Texture); DrawTexture(TextureSBG); - if (showArrows) then + if showArrows then begin DrawTexture(Tex_SelectS_ArrowL); DrawTexture(Tex_SelectS_ArrowR); @@ -327,7 +328,7 @@ begin Text.Draw; - for SO := low(TextOpt) to high(TextOpt) do + for SO := Low(TextOpt) to High(TextOpt) do TextOpt[SO].Draw; end; end; @@ -341,14 +342,14 @@ begin SetFontSize(Text.Size); maxlength := 0; - for I := low(TextOptT) to high (TextOptT) do + for I := Low(TextOptT) to High(TextOptT) do begin if (glTextWidth(TextOptT[I]) > maxlength) then maxlength := glTextWidth(TextOptT[I]); end; - if(oneItemOnly = false) then + if (oneItemOnly = false) then begin //show all items Lines := floor((TextureSBG.W-40) / (maxlength+7)); @@ -365,12 +366,12 @@ begin end; //Free old Space used by Texts - for I := low(TextOpt) to high(TextOpt) do + for I := Low(TextOpt) to High(TextOpt) do TextOpt[I].Free; setLength (TextOpt, Lines); - for I := low(TextOpt) to high(TextOpt) do + for I := Low(TextOpt) to High(TextOpt) do begin TextOpt[I] := TText.Create; TextOpt[I].Size := Text.Size; @@ -385,7 +386,7 @@ begin //Generate Positions //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); - if (I <> High(TextOpt)) OR (High(TextOpt) = 0) OR (Length(TextOptT) = Lines) then + if (I <> High(TextOpt)) or (High(TextOpt) = 0) or (Length(TextOptT) = Lines) then TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I else TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; @@ -393,10 +394,10 @@ begin TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H - Text.Size) / 2; //Better Look with 2 Options - if (Lines=2) AND (Length(TextOptT)= 2) then + if (Lines = 2) and (Length(TextOptT) = 2) then TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W -40 - glTextWidth(TextOptT[1])) * I; - if (Lines=1) then + if (Lines = 1) then begin TextOpt[I].Align := 1; //center text TextOpt[I].X := TextureSBG.X + (TextureSBG.W / 2); diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index b000cc73..b5507327 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -34,29 +34,29 @@ interface {$I switches.inc} uses - TextGL, - UTexture, - gl, math, SysUtils, - SDL; + gl, + SDL, + TextGL, + UTexture; type TText = class private - SelectBool: boolean; - TextString: string; - TextTiles: array of string; + SelectBool: boolean; + TextString: string; + TextTiles: array of string; - STicks: cardinal; - SelectBlink: boolean; + 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 + 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; @@ -64,13 +64,13 @@ type ColB: real; Alpha: real; Int: real; - Style: integer; - Visible: boolean; - Align: integer; // 0 = left, 1 = center, 2 = right + Style: integer; + Visible: boolean; + Align: integer; // 0 = left, 1 = center, 2 = right - //Reflection - Reflection: boolean; - ReflectionSpacing: real; + // reflection + Reflection: boolean; + ReflectionSpacing: real; procedure SetSelect(Value: boolean); property Selected: boolean read SelectBool write SetSelect; @@ -78,7 +78,7 @@ type procedure SetText(Value: string); property Text: string read TextString write SetText; - procedure DeleteLastL; //Procedure to Delete Last Letter + procedure DeleteLastL; // procedure to delete last letter procedure Draw; constructor Create; overload; @@ -88,26 +88,27 @@ type implementation -uses UGraphic, - StrUtils; +uses + StrUtils, + UGraphic; procedure TText.SetSelect(Value: boolean); begin SelectBool := Value; - //Set Cursor Visible - SelectBlink := True; + // set cursor visible + SelectBlink := true; STicks := SDL_GetTicks() div 550; end; procedure TText.SetText(Value: string); var - NextPos: cardinal; // NextPos of a Space etc. - LastPos: cardinal; // LastPos " - 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 + 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 @@ -115,16 +116,16 @@ var begin LastPos := NextPos; - //Next Space (If Width is given) + // next space (if width is given) if (W > 0) then T1 := PosEx(' ', Value, LastPos + 1) else T1 := Length(Value); - {//Next - + {// next - T2 := PosEx('-', Value, LastPos + 1);} - //Next Break + // next break T3 := PosEx('\n', Value, LastPos + 1); if T1 = 0 then @@ -134,7 +135,7 @@ var if T3 = 0 then T3 := Length(Value); - //Get Nearest Pos + // get nearest pos NextPos := min(T1, T3{min(T2, T3)}); if (LastPos = cardinal(Length(Value))) then @@ -161,14 +162,14 @@ var end; begin - //Set TExtstring + // set TextString TextString := Value; - //Set Cursor Visible - SelectBlink := True; + // set cursor visible + SelectBlink := true; STicks := SDL_GetTicks() div 550; - //Exit if there is no Need to Create Tiles + // exit if there is no need to create tiles if (W <= 0) and (Pos('\n', Value) = 0) then begin SetLength (TextTiles, 1); @@ -176,12 +177,12 @@ begin Exit; end; - //Create Tiles - //Reset Text Array + // create tiles + // reset text array SetLength (TextTiles, 0); Len := 0; - //Reset Counter Vars + // reset counter vars LastPos := 1; NextPos := 1; LastBreak := 1; @@ -189,57 +190,57 @@ begin if (W > 0) then begin - //Set Font Properties + // set font properties SetFontStyle(Style); SetFontSize(Size); end; - //go Through Text + // go through text while (GetNextPos) do begin - //Break in Text + // break in text if isBreak then begin - //Look for Break before the Break + // 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 + 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 + // 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 + else // first word after break break within the word begin - //ToDo - //AddBreak(LastBreak, LastBreak + 155); + // to do + // AddBreak(LastBreak, LastBreak + 155); end; end; - isBreak := True; - //Add Break from Text + isBreak := true; + // add break from text AddBreak(LastBreak, NextPos); end - //Text comes out of the Text Area -> CreateBreak + // 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 + // 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 + // 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 + else // first word after break -> break within the word begin - //ToDo - //AddBreak(LastBreak, LastBreak + 155); + // to do + // AddBreak(LastBreak, LastBreak + 155); end; end; //end; Inc(FirstWord) end; - //Add Ending + // add ending AddBreak(LastBreak, Length(Value)+1); end; @@ -260,35 +261,35 @@ procedure TText.Draw; var X2, Y2: real; Text2: string; - I: Integer; - Ticks: Cardinal; + I: integer; + Ticks: cardinal; begin if Visible then begin SetFontStyle(Style); SetFontSize(Size); - SetFontItalic(False); + SetFontItalic(false); glColor4f(ColR*Int, ColG*Int, ColB*Int, Alpha); - //Reflection - if Reflection = true then + // reflection + if Reflection then SetFontReflection(true, ReflectionSpacing) else SetFontReflection(false,0); - //if selected set blink... + // if selected set blink... if SelectBool then begin Ticks := SDL_GetTicks() div 550; if Ticks <> STicks then - begin //Change Visability + begin // change visability STicks := Ticks; SelectBlink := Not SelectBlink; end; end; - {if (False) then //no width set draw as one long string + {if (false) then // no width set draw as one long string begin if not (SelectBool AND SelectBlink) then Text2 := Text @@ -307,8 +308,8 @@ begin end else begin} - //now use allways: - //draw text as many strings + // now use always: + // draw text as many strings Y2 := Y + MoveY; for I := 0 to High(TextTiles) do begin @@ -353,7 +354,14 @@ begin Create(X, Y, 0, 0, 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; ParText: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ:real); +constructor TText.Create(ParX, ParY, ParW: real; + ParStyle: integer; + ParSize, ParColR, ParColG, ParColB: real; + ParAlign: integer; + ParText: string; + ParReflection: boolean; + ParReflectionSpacing: real; + ParZ: real); begin inherited Create; Alpha := 1; @@ -371,8 +379,8 @@ begin Align := ParAlign; SelectBool := false; Visible := true; - Reflection:= ParReflection; - ReflectionSpacing:= ParReflectionSpacing; + Reflection := ParReflection; + ReflectionSpacing := ParReflectionSpacing; end; end. -- cgit v1.2.3 From 917901e8e33438c425aef50a0a7417f32d77b760 Mon Sep 17 00:00:00 2001 From: s_alexander Date: Mon, 9 Nov 2009 00:27:55 +0000 Subject: merged unicode branch (r1931) into trunk git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1939 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 66 +++--- src/menu/UMenu.pas | 241 ++++++++++----------- src/menu/UMenuBackground.pas | 166 +++++++-------- src/menu/UMenuBackgroundColor.pas | 144 ++++++------- src/menu/UMenuBackgroundFade.pas | 352 +++++++++++++++---------------- src/menu/UMenuBackgroundNone.pas | 138 ++++++------ src/menu/UMenuBackgroundTexture.pas | 251 +++++++++++----------- src/menu/UMenuBackgroundVideo.pas | 407 ++++++++++++++++++------------------ src/menu/UMenuSelectSlide.pas | 2 +- src/menu/UMenuText.pas | 49 ++--- 10 files changed, 897 insertions(+), 919 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index f2eb2ced..6f29d2e1 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -36,10 +36,11 @@ interface uses UCommon, SDL, - UMenu, gl, glu, - SysUtils; + SysUtils, + UMenu, + UPath; type TDisplay = class @@ -123,7 +124,8 @@ uses UMain, UTexture, UTime, - UPath; + ULanguage, + UPathUtils; constructor TDisplay.Create; var @@ -219,6 +221,8 @@ begin //popup mod 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; @@ -268,7 +272,7 @@ begin // blackscreen-hack if not BlackScreen then - NextScreen.onShow; + NextScreen.OnShow; // update fade state LastFadeTime := SDL_GetTicks(); @@ -328,7 +332,7 @@ begin NextScreen := nil; if not BlackScreen then begin - CurrentScreen.onShowFinish; + CurrentScreen.OnShowFinish; CurrentScreen.ShowFinish := true; end else @@ -504,49 +508,49 @@ end; procedure TDisplay.SaveScreenShot; var Num: integer; - FileName: string; + 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 = '') then + // Exit if Screenshot-path does not exist or read-only + if (ScreenshotsPath.IsUnset) then Exit; for Num := 1 to 9999 do begin - FileName := IntToStr(Num); - while Length(FileName) < 4 do - FileName := '0' + FileName; - FileName := ScreenshotsPath + 'screenshot' + FileName + '.png'; - if not FileExists(FileName) then - break + // 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 + // we must take the row-alignment (4byte by default) into account glGetIntegerv(GL_PACK_ALIGNMENT, @Align); -// calc aligned row-size + // 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); + // 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 := WriteJPGImage(FileName, Surface, 95); + // Success := WriteBMPImage(FileName, Surface); Success := WritePNGImage(FileName, Surface); if Success then - ScreenPopupError.ShowPopup('Screenshot saved: ' + ExtractFileName(FileName)) + ScreenPopupInfo.ShowPopup(Format(Language.Translate('SCREENSHOT_SAVED'), [FileName.GetName.ToUTF8()])) else - ScreenPopupError.ShowPopup('Screenshot failed'); + ScreenPopupError.ShowPopup(Language.Translate('SCREENSHOT_FAILED')); SDL_FreeSurface(Surface); FreeMem(ScreenData); @@ -559,7 +563,7 @@ procedure TDisplay.DrawDebugInformation; var Ticks: cardinal; begin -// Some White Background for information + // Some White Background for information glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glColor4f(1, 1, 1, 0.5); @@ -571,13 +575,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 @@ -588,17 +592,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); diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index a3f47b3d..7979e28e 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -38,6 +38,7 @@ uses Math, gl, SDL, + UPath, UMenuBackground, UMenuButton, UMenuButtonCollection, @@ -81,8 +82,6 @@ type //constructor Create(Back: string; W, H: integer); overload; virtual; // W and H are the number of overlaps // interaction - function WideCharUpperCase(wchar: WideChar) : WideString; - function WideStringUpperCase(wstring: WideString) : WideString; procedure AddInteraction(Typ, Num: integer); procedure SetInteraction(Num: integer); virtual; property Interaction: integer read SelInteraction write SetInteraction; @@ -98,62 +97,62 @@ type // static function AddStatic(ThemeStatic: TThemeStatic): integer; overload; - function AddStatic(X, Y, W, H: real; const Name: string): integer; overload; - function AddStatic(X, Y, W, H: real; const Name: string; Typ: TTextureType): integer; overload; - function AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; overload; - function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType): integer; overload; - function AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; overload; - function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; const Name: string; Typ: TTextureType; Color: integer): integer; overload; - function AddStatic(X, Y, W, H, Z: real; ColR, ColG, ColB: real; TexX1, TexY1, TexX2, TexY2: real; const Name: string; Typ: TTextureType; Color: integer; Reflection: boolean; ReflectionSpacing: real): 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_: string): integer; overload; - function AddText(X, Y: real; Style: integer; Size, ColR, ColG, ColB: real; const Text: string): integer; overload; - function AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; const Text_: string; Reflection_: boolean; ReflectionSpacing_: real; Z : real): 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 Name: string): integer; overload; - function AddButton(X, Y, W, H: real; const Name: string; Typ: TTextureType; Reflection: boolean): integer; overload; - function AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; const Name: string; Typ: TTextureType; Reflection: boolean; ReflectionSpacing, DeSelectReflectionSpacing: real): 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: string); overload; - procedure AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: string); overload; - procedure AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); overload; - procedure AddButtonText(CustomButton: TButton; AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); overload; + 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; Values: array of string): integer; overload; + 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 Name: string; Typ: TTextureType; const SBGName: string; SBGTyp: TTextureType; - const Caption: string; var Data: integer): integer; overload; - procedure AddSelectSlideOption(const AddText: string); overload; - procedure AddSelectSlideOption(SelectNo: cardinal; const AddText: string); overload; - procedure UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; SelectNum: integer; Values: array of string; var Data: integer); + 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: string); + procedure CheckFadeTo(Screen: PMenu; Msg: UTF8String); function DrawBG: boolean; virtual; function DrawFG: boolean; virtual; function Draw: boolean; virtual; - function ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown : boolean): 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(X1, Y1, W, H, X, Y: real): boolean; function InteractAt(X, Y: real): integer; function CollectionAt(X, Y: real): integer; - procedure onShow; virtual; - procedure onShowFinish; virtual; - procedure onHide; virtual; + procedure OnShow; virtual; + procedure OnShowFinish; virtual; + procedure OnHide; virtual; procedure SetAnimationProgress(Progress: real); virtual; @@ -391,7 +390,7 @@ begin begin //At first some intelligent try to decide which BG to load - FileExt := lowercase(ExtractFileExt(Skin.GetTextureFileName(ThemedSettings.Tex))); + FileExt := LowerCase(Skin.GetTextureFileName(ThemedSettings.Tex).GetExtension.ToUTF8); if IsInArray(FileExt, SUPPORTED_EXTS_BACKGROUNDTEXTURE) then TryBGCreate(TMenuBackgroundTexture) @@ -599,29 +598,29 @@ begin ThemeStatic.Typ, $FFFFFF, ThemeStatic.Reflection, ThemeStatic.Reflectionspacing); end; -function TMenu.AddStatic(X, Y, W, H: real; const Name: string): integer; +function TMenu.AddStatic(X, Y, W, H: real; const TexName: IPath): integer; begin - Result := AddStatic(X, Y, W, H, Name, TEXTURE_TYPE_PLAIN); + Result := AddStatic(X, Y, W, H, TexName, TEXTURE_TYPE_PLAIN); end; function TMenu.AddStatic(X, Y, W, H: real; - ColR, ColG, ColB: real; - const Name: string; + ColR, ColG, ColB: real; + const TexName: IPath; Typ: TTextureType): integer; begin - Result := AddStatic(X, Y, W, H, ColR, ColG, ColB, Name, Typ, $FFFFFF); + 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 Name: string; + ColR, ColG, ColB: real; + const TexName: IPath; Typ: TTextureType): integer; begin - Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, Name, Typ, $FFFFFF); + Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, TexName, Typ, $FFFFFF); end; function TMenu.AddStatic(X, Y, W, H: real; - const Name: string; + const TexName: IPath; Typ: TTextureType): integer; var StatNum: integer; @@ -629,7 +628,7 @@ begin // adds static StatNum := Length(Static); SetLength(Static, StatNum + 1); - Static[StatNum] := TStatic.Create(Texture.GetTexture(Name, Typ, $FF00FF)); // new skin + Static[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, $FF00FF)); // new skin // configures static Static[StatNum].Texture.X := X; @@ -642,26 +641,26 @@ end; function TMenu.AddStatic(X, Y, W, H: real; ColR, ColG, ColB: real; - const Name: string; + const TexName: IPath; Typ: TTextureType; Color: integer): integer; begin - Result := AddStatic(X, Y, W, H, 0, ColR, ColG, ColB, Name, Typ, Color); + 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 Name: string; + const TexName: IPath; Typ: TTextureType; Color: integer): integer; begin - Result := AddStatic(X, Y, W, H, Z, ColR, ColG, ColB, 0, 0, 1, 1, Name, Typ, Color, false, 0); + 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 Name: string; + const TexName: IPath; Typ: TTextureType; Color: integer; Reflection: boolean; @@ -677,11 +676,11 @@ begin if (Typ = TEXTURE_TYPE_COLORIZED) then begin // give encoded color to GetTexture() - Static[StatNum] := TStatic.Create(Texture.GetTexture(Name, Typ, RGBFloatToInt(ColR, ColG, ColB))); + Static[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB))); end else begin - Static[StatNum] := TStatic.Create(Texture.GetTexture(Name, Typ, Color)); // new skin + Static[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, Color)); // new skin end; // configures static @@ -726,7 +725,7 @@ begin 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_: string): integer; +function TMenu.AddText(X, Y: real; const Text_: UTF8String): integer; var TextNum: integer; begin @@ -739,20 +738,20 @@ end; function TMenu.AddText(X, Y: real; Style: integer; - Size, ColR, ColG, ColB: real - ; const Text: string): 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_: string; - Reflection_: boolean; - ReflectionSpacing_: real; - Z : real): integer; + Size, ColR, ColG, ColB: real; + Align: integer; + const Text_: UTF8String; + Reflection_: boolean; + ReflectionSpacing_: real; + Z : real): integer; var TextNum: integer; begin @@ -843,18 +842,18 @@ begin Log.LogBenchmark('====> Screen Options32', 6); end; -function TMenu.AddButton(X, Y, W, H: real; const Name: string): integer; +function TMenu.AddButton(X, Y, W, H: real; const TexName: IPath): integer; begin - Result := AddButton(X, Y, W, H, Name, TEXTURE_TYPE_PLAIN, false); + Result := AddButton(X, Y, W, H, TexName, TEXTURE_TYPE_PLAIN, false); end; -function TMenu.AddButton(X, Y, W, H: real; const Name: string; Typ: TTextureType; Reflection: boolean): integer; +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, Name, TEXTURE_TYPE_PLAIN, Reflection, 15, 15); + 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 Name: string; + const TexName: IPath; Typ: TTextureType; Reflection: boolean; ReflectionSpacing, DeSelectReflectionSpacing: real): integer; @@ -876,12 +875,12 @@ begin if (Typ = TEXTURE_TYPE_COLORIZED) then begin // give encoded color to GetTexture() - Button[Result] := TButton.Create(Texture.GetTexture(Name, Typ, RGBFloatToInt(ColR, ColG, ColB)), - Texture.GetTexture(Name, Typ, RGBFloatToInt(DColR, DColG, DColB))); + 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(Name, Typ)); + Button[Result] := TButton.Create(Texture.GetTexture(TexName, Typ)); end; // configures button @@ -935,11 +934,11 @@ var J: integer; begin // We don't forget about newly implemented static for nice skin ... - for J := 0 to Length(Static) - 1 do + for J := 0 to High(Static) do Static[J].Draw; // ... and slightly implemented menutext unit - for J := 0 to Length(Text) - 1 do + for J := 0 to High(Text) do Text[J].Draw; // Draw all ButtonCollections @@ -947,10 +946,10 @@ begin ButtonCollection[J].Draw; // Second, we draw all of our buttons - for J := 0 to Length(Button) - 1 do + for J := 0 to High(Button) do Button[J].Draw; - for J := 0 to Length(SelectsS) - 1 do + for J := 0 to High(SelectsS) do SelectsS[J].Draw; // Third, we draw all our widgets @@ -1178,21 +1177,41 @@ begin 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: string); +procedure TMenu.CheckFadeTo(Screen: PMenu; Msg: UTF8String); begin Display.Fade := 0; Display.NextScreenWithCheck := Screen; Display.CheckOK := false; - ScreenPopupCheck.ShowPopup(msg); + ScreenPopupCheck.ShowPopup(msg, OnSaveEncodingError, nil, false); end; -procedure TMenu.AddButtonText(AddX, AddY: real; const AddText: string); +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: string); +procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; const AddText: UTF8String); var Il: integer; begin @@ -1208,7 +1227,7 @@ begin end; end; -procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); +procedure TMenu.AddButtonText(AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: UTF8String); var Il: integer; begin @@ -1227,7 +1246,7 @@ begin end; end; -procedure TMenu.AddButtonText(CustomButton: TButton; AddX, AddY: real; ColR, ColG, ColB: real; Font: integer; Size: integer; Align: integer; const AddText: string); +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 @@ -1246,7 +1265,7 @@ begin end; end; -function TMenu.AddSelectSlide(ThemeSelectS: TThemeSelectSlide; var Data: integer; Values: array of string): integer; +function TMenu.AddSelectSlide(ThemeSelectS: TThemeSelectSlide; var Data: integer; const Values: array of UTF8String): integer; var SO: integer; begin @@ -1283,8 +1302,8 @@ function TMenu.AddSelectSlide(X, Y, W, H, SkipX, SBGW, ColR, ColG, ColB, Int, DC 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 Name: string; Typ: TTextureType; const SBGName: string; SBGTyp: TTextureType; - const Caption: string; var Data: integer): integer; + const TexName: IPath; Typ: TTextureType; const SBGName: IPath; SBGTyp: TTextureType; + const Caption: UTF8String; var Data: integer): integer; var S: integer; I: integer; @@ -1294,9 +1313,9 @@ begin SelectsS[S] := TSelectSlide.Create; if (Typ = TEXTURE_TYPE_COLORIZED) then - SelectsS[S].Texture := Texture.GetTexture(Name, Typ, RGBFloatToInt(ColR, ColG, ColB)) + SelectsS[S].Texture := Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB)) else - SelectsS[S].Texture := Texture.GetTexture(Name, Typ); + SelectsS[S].Texture := Texture.GetTexture(TexName, Typ); SelectsS[S].X := X; SelectsS[S].Y := Y; SelectsS[S].W := W; @@ -1414,12 +1433,12 @@ begin Result := S; end; -procedure TMenu.AddSelectSlideOption(const AddText: string); +procedure TMenu.AddSelectSlideOption(const AddText: UTF8String); begin AddSelectSlideOption(High(SelectsS), AddText); end; -procedure TMenu.AddSelectSlideOption(SelectNo: cardinal; const AddText: string); +procedure TMenu.AddSelectSlideOption(SelectNo: cardinal; const AddText: UTF8String); var SO: integer; begin @@ -1435,7 +1454,8 @@ begin } end; -procedure TMenu.UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; SelectNum: integer; Values: array of string; var Data: integer); +procedure TMenu.UpdateSelectSlideOptions(ThemeSelectSlide: TThemeSelectSlide; + SelectNum: integer; const Values: array of UTF8String; var Data: integer); var SO: integer; begin @@ -1560,7 +1580,7 @@ begin AddStatic(X+2, Y+2, W-4, H-4, 1, 1, 1, Skin.GetTextureFileName('MainBar'), TEXTURE_TYPE_COLORIZED); end; -procedure TMenu.onShow; +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. @@ -1589,57 +1609,18 @@ begin Background.OnShow; end; -procedure TMenu.onShowFinish; +procedure TMenu.OnShowFinish; begin // nothing end; -(* - * Wrapper for WideUpperCase. Needed because some plattforms have problems with - * unicode support. - *) -function TMenu.WideCharUpperCase(wchar: WideChar) : WideString; -begin - // On Linux and MacOSX the cwstring unit is necessary for Unicode function-calls. - // Otherwise you will get an EIntOverflow exception (thrown by unimplementedwidestring()). - // The Unicode manager cwstring does not work with MacOSX at the moment because - // of missing references to iconv. So we have to use Ansi... for the moment. - - // cwstring crashes in FPC 2.2.2 so do not use the cwstring stuff - {.$IFNDEF DARWIN} - {$IFDEF NOIGNORE} - // The FPC implementation of WideUpperCase returns nil if wchar is #0 (e.g. if an arrow key is pressed) - if (wchar <> #0) then - Result := WideUpperCase(wchar) - else - Result := #0; - {$ELSE} - Result := AnsiUpperCase(wchar) - {$ENDIF} -end; - -(* - * Wrapper for WideUpperCase. Needed because some plattforms have problems with - * unicode support. - *) -function TMenu.WideStringUpperCase(wstring: WideString) : WideString; -begin - // cwstring crashes in FPC 2.2.2 so do not use the cwstring stuff - {.$IFNDEF DARWIN} - {$IFDEF NOIGNORE} - Result := WideUpperCase(wstring) - {$ELSE} - Result := AnsiUpperCase(wstring); - {$ENDIF} -end; - -procedure TMenu.onHide; +procedure TMenu.OnHide; begin // nothing Background.OnFinish; end; -function TMenu.ParseInput(PressedKey: cardinal; CharCode: WideChar; PressedDown: boolean): boolean; +function TMenu.ParseInput(PressedKey: Cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; begin // nothing Result := true; @@ -1657,7 +1638,7 @@ begin if RightMbESC and (MouseButton = SDL_BUTTON_RIGHT) and BtnDown then begin //if RightMbESC is set, send ESC keypress - Result:=ParseInput(SDLK_ESCAPE, #0, true); + Result:=ParseInput(SDLK_ESCAPE, 0, true); end; nBut := InteractAt(X, Y); @@ -1669,18 +1650,18 @@ begin if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then begin //click button - Result:=ParseInput(SDLK_RETURN, #0, true); + Result:=ParseInput(SDLK_RETURN, 0, true); end; if (Interactions[nBut].Typ = iSelectS) then begin //forward/backward in select slide with mousewheel if (MouseButton = SDL_BUTTON_WHEELDOWN) and BtnDown then begin - ParseInput(SDLK_RIGHT, #0, true); + ParseInput(SDLK_RIGHT, 0, true); end; if (MouseButton = SDL_BUTTON_WHEELUP) and BtnDown then begin - ParseInput(SDLK_LEFT, #0, true); + ParseInput(SDLK_LEFT, 0, true); end; end; end diff --git a/src/menu/UMenuBackground.pas b/src/menu/UMenuBackground.pas index c85f0806..0e2e63a6 100644 --- a/src/menu/UMenuBackground.pas +++ b/src/menu/UMenuBackground.pas @@ -1,83 +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. +{* 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 index a5c2a70a..45b58c1e 100644 --- a/src/menu/UMenuBackgroundColor.pas +++ b/src/menu/UMenuBackgroundColor.pas @@ -1,73 +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; - +{* 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 index b61a4542..6d877baa 100644 --- a/src/menu/UMenuBackgroundFade.pas +++ b/src/menu/UMenuBackgroundFade.pas @@ -1,176 +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; - -//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: string; -begin - inherited; - FadeTime := 0; - - Color := ThemedSettings.Color; - Alpha := ThemedSettings.Alpha; - if (Length(ThemedSettings.Tex) > 0) then - begin - texFilename := Skin.GetTextureFileName(ThemedSettings.Tex); - texFilename := AdaptFilePaths(texFilename); - 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. +{* 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 index 1fccc007..c64f3023 100644 --- a/src/menu/UMenuBackgroundNone.pas +++ b/src/menu/UMenuBackgroundNone.pas @@ -1,70 +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; - +{* 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 index a1b9e88a..f71637ff 100644 --- a/src/menu/UMenuBackgroundTexture.pas +++ b/src/menu/UMenuBackgroundTexture.pas @@ -1,125 +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; - -//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: string; -begin - inherited; - - if (Length(ThemedSettings.Tex) = 0) then - raise EMenuBackgroundError.Create('TMenuBackgroundTexture: No texture filename present'); - - Color := ThemedSettings.Color; - - texFilename := Skin.GetTextureFileName(ThemedSettings.Tex); - texFilename := AdaptFilePaths(texFilename); - 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. +{* 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 index d1ce0f09..9d265764 100644 --- a/src/menu/UMenuBackgroundVideo.pas +++ b/src/menu/UMenuBackgroundVideo.pas @@ -1,204 +1,203 @@ -{* 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, - UVideo; - -//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: string): TBGVideo; - procedure RemoveItem( - procedure FreeAllItems; - - destructor Destroy; - end; - -type } - TMenuBackgroundVideo = class (TMenuBackground) - private - fFilename: string; - 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, - UMusic, - 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); - fFileName := AdaptFilePaths( fFileName ); - - if fileexists(fFilename) AND VideoPlayback.Open( fFileName ) then - begin - VideoBGTimer.SetTime(0); - VideoPlayback.Play; - end - else - raise EMenuBackgroundError.Create('TMenuBackgroundVideo: Can''t load background video: ' + fFilename); -end; - -destructor TMenuBackgroundVideo.Destroy; -begin - -end; - -procedure TMenuBackgroundVideo.OnShow; -begin - if VideoPlayback.Open( fFileName ) then - begin - VideoBGTimer.SetTime(0); - VideoPlayback.Play; - end; -end; - -procedure TMenuBackgroundVideo.OnFinish; -begin - -end; - -procedure TMenuBackgroundVideo.Draw; -begin - If (ScreenAct = 1) then //Clear just once when in dual screen mode - glClear(GL_DEPTH_BUFFER_BIT); - - VideoPlayback.GetFrame(VideoBGTimer.GetTime()); - // FIXME: why do we draw on screen 2? Seems to be wrong. - VideoPlayback.DrawGL(2); -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: string): TBGVideo; -begin - -end; - -procedure TBGVideoPool.FreeAllItems; -begin - -end; } - -end. +{* 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, + 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; + 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, + UMusic, + 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 fFilename.IsFile and VideoPlayback.Open(fFileName) then + begin + VideoBGTimer.SetTime(0); + VideoPlayback.Play; + end + else + raise EMenuBackgroundError.Create('TMenuBackgroundVideo: Can''t load background video: ' + fFilename.ToNative); +end; + +destructor TMenuBackgroundVideo.Destroy; +begin + +end; + +procedure TMenuBackgroundVideo.OnShow; +begin + if VideoPlayback.Open( fFileName ) then + begin + VideoBGTimer.SetTime(0); + VideoPlayback.Play; + end; +end; + +procedure TMenuBackgroundVideo.OnFinish; +begin + +end; + +procedure TMenuBackgroundVideo.Draw; +begin + If (ScreenAct = 1) then //Clear just once when in dual screen mode + glClear(GL_DEPTH_BUFFER_BIT); + + VideoPlayback.GetFrame(VideoBGTimer.GetTime()); + // FIXME: why do we draw on screen 2? Seems to be wrong. + VideoPlayback.DrawGL(2); +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/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index f9f6bbae..6bc824f4 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -48,7 +48,7 @@ type // objects Text: TText; // Main text describing option TextOpt: array of TText; // 3 texts in the position of possible options - TextOptT: array of string; // array of names for possible options + TextOptT: array of UTF8String; // array of names for possible options Texture: TTexture; // Select Texture TextureSBG: TTexture; // Background Selections Texture diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index b5507327..276f961b 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -45,8 +45,8 @@ type TText = class private SelectBool: boolean; - TextString: string; - TextTiles: array of string; + TextString: UTF8String; + TextTiles: array of UTF8String; STicks: cardinal; SelectBlink: boolean; @@ -75,22 +75,23 @@ type procedure SetSelect(Value: boolean); property Selected: boolean read SelectBool write SetSelect; - procedure SetText(Value: string); - property Text: string read TextString write SetText; + procedure SetText(Value: UTF8String); + property Text: UTF8String read TextString write SetText; - procedure DeleteLastL; // procedure to delete last letter + procedure DeleteLastLetter; //< Deletes the rightmost letter procedure Draw; constructor Create; overload; - constructor Create(X, Y: real; Text: string); overload; - constructor Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParText: string; ParReflection: boolean; ParReflectionSpacing: real; ParZ: real); 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 - StrUtils, - UGraphic; + UGraphic, + UUnicodeUtils, + StrUtils; procedure TText.SetSelect(Value: boolean); begin @@ -101,7 +102,7 @@ begin STicks := SDL_GetTicks() div 550; end; -procedure TText.SetText(Value: string); +procedure TText.SetText(Value: UTF8String); var NextPos: cardinal; // next pos of a space etc. LastPos: cardinal; // last pos " @@ -244,23 +245,15 @@ begin AddBreak(LastBreak, Length(Value)+1); end; -procedure TText.DeleteLastL; -var - S: string; - L: integer; +procedure TText.DeleteLastLetter; begin - S := TextString; - L := Length(S); - if (L > 0) then - SetLength(S, L-1); - - SetText(S); + SetText(UTF8Copy(TextString, 1, LengthUTF8(TextString)-1)); end; procedure TText.Draw; var X2, Y2: real; - Text2: string; + Text2: UTF8String; I: integer; Ticks: cardinal; begin @@ -349,19 +342,19 @@ begin Create(0, 0, ''); end; -constructor TText.Create(X, Y: real; Text: string); +constructor TText.Create(X, Y: real; const Text: UTF8String); begin Create(X, Y, 0, 0, 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; - ParText: string; - ParReflection: boolean; - ParReflectionSpacing: real; - ParZ: real); + ParSize, ParColR, ParColG, ParColB: real; + ParAlign: integer; + const ParText: UTF8String; + ParReflection: boolean; + ParReflectionSpacing: real; + ParZ: real); begin inherited Create; Alpha := 1; -- cgit v1.2.3 From 4a0804396809345423d596b079aed51261b8612f Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Tue, 17 Nov 2009 17:35:07 +0000 Subject: prevent key input from being sent to the screen that is fading out, send it to the screen that is fading in instead. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1946 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 6f29d2e1..81056c13 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -91,6 +91,9 @@ type 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; @@ -505,6 +508,16 @@ begin 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; + procedure TDisplay.SaveScreenShot; var Num: integer; -- cgit v1.2.3 From 9975f56cded5f6251d0110238fd97b7ee7ccae31 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 18 Nov 2009 14:42:34 +0000 Subject: some changes on mousesupport - you can click on the whole area of a button after fading - options on selects can be changed by clicking on the arrows - fix mouse parsing at the screensong extensions git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1950 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 79 ++++++++++++++++++++++++++----------------- src/menu/UMenuButton.pas | 48 +++++++++++++++++++++++++- src/menu/UMenuInteract.pas | 9 +++++ src/menu/UMenuSelectSlide.pas | 33 +++++++++++++++++- 4 files changed, 136 insertions(+), 33 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 7979e28e..659d4213 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -147,7 +147,7 @@ type 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(X1, Y1, W, H, X, Y: real): boolean; + function InRegion(X, Y: real; A: TMouseOverRect): boolean; function InteractAt(X, Y: real): integer; function CollectionAt(X, Y: real): integer; procedure OnShow; virtual; @@ -1629,6 +1629,7 @@ 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 @@ -1647,30 +1648,45 @@ begin //select on mouse-over if nBut <> Interaction then SetInteraction(nBut); - if (MouseButton = SDL_BUTTON_LEFT) and BtnDown then - begin - //click button - Result:=ParseInput(SDLK_RETURN, 0, true); - end; - if (Interactions[nBut].Typ = iSelectS) then + + Action := maNone; + + if (BtnDown) then begin - //forward/backward in select slide with mousewheel - if (MouseButton = SDL_BUTTON_WHEELDOWN) and BtnDown then - begin - ParseInput(SDLK_RIGHT, 0, true); - end; - if (MouseButton = SDL_BUTTON_WHEELUP) and BtnDown then + if (MouseButton = SDL_BUTTON_LEFT) then begin - ParseInput(SDLK_LEFT, 0, true); + //click button or SelectS + if (Interactions[nBut].Typ = iSelectS) then + Action := SelectsS[Interactions[nBut].Num].OnClick((X / Screen.w) * RenderW, (Y / Screen.h) * RenderH) + 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 then + if (nBut >= 0) and (not ButtonCollection[nBut].Selected) then begin - // if over button collection, select first child but don't allow click + // 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); @@ -1678,15 +1694,14 @@ begin end; end; -function TMenu.InRegion(X1, Y1, W, H, X, Y: real): boolean; +function TMenu.InRegion(X, Y: real; A: TMouseOverRect): boolean; begin - Result := false; - X1 := X1 * Screen.w / 800; - W := W * Screen.w / 800; - Y1 := Y1 * Screen.h / 600; - H := H * Screen.h / 600; - if (X >= X1) and (X <= X1 + W) and (Y >= Y1) and (Y <= Y1 + H) then - Result := true; + // transfer mousecords to the 800x600 raster we use to draw + X := (X / Screen.w) * RenderW; + Y := (Y / Screen.h) * RenderH; + + // 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 @@ -1699,20 +1714,22 @@ begin for i := Low(Interactions) to High(Interactions) do begin case Interactions[i].Typ of - iButton: if InRegion(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) and + iButton: + if InRegion(X, Y, Button[Interactions[i].Num].GetMouseOverArea) and Button[Interactions[i].Num].Visible then - begin + begin Result:=i; exit; end; - iBCollectionChild: if InRegion(Button[Interactions[i].Num].X, Button[Interactions[i].Num].Y, Button[Interactions[i].Num].W, Button[Interactions[i].Num].H, X, Y) then + iBCollectionChild: + if InRegion(X, Y, Button[Interactions[i].Num].GetMouseOverArea) then begin Result:=i; exit; end; - iSelectS: if InRegion(SelectSs[Interactions[i].Num].X, SelectSs[Interactions[i].Num].Y, SelectSs[Interactions[i].Num].W, SelectSs[Interactions[i].Num].H, X, Y) or - InRegion(SelectSs[Interactions[i].Num].TextureSBG.X, SelectSs[Interactions[i].Num].TextureSBG.Y, SelectSs[Interactions[i].Num].TextureSBG.W, SelectSs[Interactions[i].Num].TextureSBG.H, X, Y) then - begin + iSelectS: + if InRegion(X, Y, SelectSs[Interactions[i].Num].GetMouseOverArea) then + begin Result:=i; exit; end; @@ -1728,7 +1745,7 @@ begin Result := -1; for i:= Low(ButtonCollection) to High(ButtonCollection) do begin - if InRegion(ButtonCollection[i].X, ButtonCollection[i].Y, ButtonCollection[i].W, ButtonCollection[i].H, X, Y) and + if InRegion(X, Y, ButtonCollection[i].GetMouseOverArea) and ButtonCollection[i].Visible then begin Result:=i; diff --git a/src/menu/UMenuButton.pas b/src/menu/UMenuButton.pas index 923f0b14..868a86f3 100644 --- a/src/menu/UMenuButton.pas +++ b/src/menu/UMenuButton.pas @@ -38,7 +38,8 @@ uses UTexture, gl, UMenuText, - SDL; + SDL, + UMenuInteract; type CButton = class of TButton; @@ -116,6 +117,8 @@ type constructor Create(Textura: TTexture); overload; constructor Create(Textura, DSTexture: TTexture); overload; destructor Destroy; override; + + function GetMouseOverArea: TMouseOverRect; end; implementation @@ -529,6 +532,49 @@ begin 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 diff --git a/src/menu/UMenuInteract.pas b/src/menu/UMenuInteract.pas index beb6bcef..7cb92025 100644 --- a/src/menu/UMenuInteract.pas +++ b/src/menu/UMenuInteract.pas @@ -39,6 +39,15 @@ type 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. diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 6bc824f4..11be4c2a 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -37,7 +37,8 @@ uses gl, TextGL, UMenuText, - UTexture; + UTexture, + UMenuInteract; type PSelectSlide = ^TSelectSlide; @@ -135,6 +136,9 @@ type //Automatically Generate Lines (Texts) procedure genLines; + + function GetMouseOverArea: TMouseOverRect; + function OnClick(X, Y: Real): TMouseClickAction; end; implementation @@ -405,4 +409,31 @@ begin 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. -- cgit v1.2.3 From a5d9ada4b5b19e774ee47f45f673233592ae6939 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Tue, 24 Nov 2009 17:53:08 +0000 Subject: handling mouse input a better way in UDisplay git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1957 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 66 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 81056c13..927a1256 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -73,6 +73,9 @@ type 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; @@ -98,9 +101,12 @@ type procedure SetCursor; { called when cursor moves, positioning of software cursor } - procedure MoveCursor(X, Y: double; Pressed: boolean); + procedure MoveCursor(X, Y: double); + + { called when left or right mousebutton is pressed or released } + procedure OnMouseButton(Pressed: boolean); + - { draws software cursor } procedure DrawCursor; end; @@ -399,35 +405,51 @@ begin end; end; -{ called when cursor moves, positioning of software cursor } -procedure TDisplay.MoveCursor(X, Y: double; Pressed: boolean); +{ called by MoveCursor and OnMouseButton to update last move and start fade in } +procedure TDisplay.UpdateCursorFade; var Ticks: cardinal; begin - if (Ini.Mouse = 2) and - ((X <> Cursor_X) or (Y <> Cursor_Y) or (Pressed <> Cursor_Pressed)) then + 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; + +{ 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; - Cursor_Pressed := Pressed; - Ticks := SDL_GetTicks; + UpdateCursorFade; + end; +end; - { 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; +{ 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; - Cursor_Visible := true; - Cursor_Fade := true; - end - else if not Cursor_Fade then - begin - Cursor_LastMove := Ticks; - end; + UpdateCursorFade; end; end; -- cgit v1.2.3 From 4711217f127aa0c10fa52755fd567c570277a1a1 Mon Sep 17 00:00:00 2001 From: s_alexander Date: Tue, 12 Jan 2010 17:42:41 +0000 Subject: merged lua into trunk git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2071 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/menu/UMenu.pas | 4 ++-- 2 files changed, 66 insertions(+), 4 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 927a1256..f8f9c43f 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -40,11 +40,16 @@ uses glu, SysUtils, UMenu, - UPath; + UPath, + UMusic, + UHookableEvent; type TDisplay = class private + ePreDraw: THookableEvent; + eDraw: THookableEvent; + //fade-to-black-hack BlackScreen: boolean; @@ -105,7 +110,11 @@ type { 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; @@ -142,6 +151,10 @@ var begin inherited Create; + // create events for plugins + ePreDraw := THookableEvent.Create('Display.PreDraw'); + eDraw := THookableEvent.Create('Display.Draw'); + //popup hack CheckOK := false; NextScreen := nil; @@ -225,6 +238,7 @@ begin if (not assigned(NextScreen)) and (not BlackScreen) then begin + ePreDraw.CallHookChain(false); CurrentScreen.Draw; //popup mod @@ -241,6 +255,8 @@ begin FadeEnabled := true else if (Ini.ScreenFade = 0) then FadeEnabled := false; + + eDraw.CallHookChain(false); end else begin @@ -259,8 +275,11 @@ begin glPushAttrib(GL_VIEWPORT_BIT); glViewPort(0, 0, 512, 512); + // 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. @@ -299,7 +318,11 @@ begin // blackscreen-hack if not BlackScreen then - NextScreen.Draw // draw next screen + begin + ePreDraw.CallHookChain(false); + NextScreen.Draw; // draw next screen + eDraw.CallHookChain(false); + end else if ScreenAct = 1 then begin glClearColor(0, 0, 0 , 0); @@ -540,6 +563,45 @@ begin 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; diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 659d4213..3ac487de 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1187,8 +1187,8 @@ begin begin if (Display.CurrentScreen = @ScreenSing) then ScreenSing.Finish - else if (Display.CurrentScreen = @ScreenSingModi) then - ScreenSingModi.Finish; + {else if (Display.CurrentScreen = @ScreenSingModi) then + ScreenSingModi.Finish;} end; end else -- cgit v1.2.3 From 8a5aebdd230d32c453292f480be693b08028e619 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Mon, 25 Jan 2010 20:50:39 +0000 Subject: fix software cursor w/ screens = 2 git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2096 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 22 +++++++++++++--------- src/menu/UMenu.pas | 12 +++++++----- 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index f8f9c43f..fe29e438 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -377,11 +377,11 @@ begin // Draw OSD only on first Screen if Debug Mode is enabled if ((Ini.Debug = 1) or (Params.Debug)) and (S = 1) then - DrawDebugInformation; - end; // for + DrawDebugInformation; - if not BlackScreen then - DrawCursor; + if not BlackScreen then + DrawCursor; + end; // for end; { sets SDL_ShowCursor depending on options set in Ini } @@ -481,8 +481,9 @@ procedure TDisplay.DrawCursor; var Alpha: single; Ticks: cardinal; + DrawX: double; begin - if (Ini.Mouse = 2) then + if (Ini.Mouse = 2) and ((Screens = 1) or ((ScreenAct - 1) = (Round(Cursor_X+16) div 800))) then begin // draw software cursor Ticks := SDL_GetTicks; @@ -523,6 +524,9 @@ begin 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); @@ -535,16 +539,16 @@ begin glBegin(GL_QUADS); glTexCoord2f(0, 0); - glVertex2f(Cursor_X, Cursor_Y); + glVertex2f(DrawX, Cursor_Y); glTexCoord2f(0, 1); - glVertex2f(Cursor_X, Cursor_Y + 32); + glVertex2f(DrawX, Cursor_Y + 32); glTexCoord2f(1, 1); - glVertex2f(Cursor_X + 32, Cursor_Y + 32); + glVertex2f(DrawX + 32, Cursor_Y + 32); glTexCoord2f(1, 0); - glVertex2f(Cursor_X + 32, Cursor_Y); + glVertex2f(DrawX + 32, Cursor_Y); glEnd; glDisable(GL_BLEND); diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 3ac487de..b928a612 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1642,6 +1642,12 @@ begin Result:=ParseInput(SDLK_ESCAPE, 0, true); end; + // transfer mousecords to the 800x600 raster we use to draw + X := Round((X / (Screen.w / Screens)) * RenderW); + if (X > RenderW) then + X := X - RenderW; + Y := Round((Y / Screen.h) * RenderH); + nBut := InteractAt(X, Y); if nBut >= 0 then begin @@ -1657,7 +1663,7 @@ begin begin //click button or SelectS if (Interactions[nBut].Typ = iSelectS) then - Action := SelectsS[Interactions[nBut].Num].OnClick((X / Screen.w) * RenderW, (Y / Screen.h) * RenderH) + Action := SelectsS[Interactions[nBut].Num].OnClick(X, Y) else Action := maReturn; end @@ -1696,10 +1702,6 @@ end; function TMenu.InRegion(X, Y: real; A: TMouseOverRect): boolean; begin - // transfer mousecords to the 800x600 raster we use to draw - X := (X / Screen.w) * RenderW; - Y := (Y / Screen.h) * RenderH; - // 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; -- cgit v1.2.3 From b269f8442cea0b6376fcf83c1f057dc2074b072c Mon Sep 17 00:00:00 2001 From: brunzelchen Date: Sun, 14 Mar 2010 16:15:28 +0000 Subject: improved fade effect; better compatibility for two-screens-mode git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2193 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 61 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index fe29e438..b26c6896 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -35,6 +35,7 @@ interface uses UCommon, + Math, SDL, gl, glu, @@ -57,8 +58,10 @@ type FadeFailed: boolean; // true if fading is possible (enough memory, etc.) FadeState: integer; // fading state, 0 means that the fade texture must be initialized LastFadeTime: cardinal; // last fade update time + DoneOnShow: boolean; // true if passed onShow after fading FadeTex: array[1..2] of GLuint; + TexW, TexH: Cardinal; FPSCounter: cardinal; LastFPS: cardinal; @@ -165,12 +168,17 @@ begin FadeState := 0; FadeEnabled := (Ini.ScreenFade = 1); FadeFailed := false; - - glGenTextures(2, @FadeTex); + DoneOnShow := false; for i := 1 to 2 do begin + TexW := Round(Power(2, Ceil(Log2(ScreenW div Screens)))); + TexH := Round(Power(2, Ceil(Log2(ScreenH)))); + + glGenTextures(1, PglUint(@FadeTex[i])); glBindTexture(GL_TEXTURE_2D, FadeTex[i]); + glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexImage2D(GL_TEXTURE_2D, 0, 3, TexW, TexH, 0, GL_RGB, GL_UNSIGNED_BYTE, nil); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); end; @@ -198,8 +206,10 @@ function TDisplay.Draw: boolean; var S: integer; FadeStateSquare: real; + FadeW, FadeH: real; currentTime: cardinal; glError: glEnum; + begin Result := true; @@ -271,11 +281,6 @@ begin //Create Fading texture if we're just starting if FadeState = 0 then begin - // save old viewport and resize to fit texture - glPushAttrib(GL_VIEWPORT_BIT); - glViewPort(0, 0, 512, 512); - - // draw screen that will be faded ePreDraw.CallHookChain(false); CurrentScreen.Draw; @@ -287,20 +292,22 @@ begin // copy screen to texture glBindTexture(GL_TEXTURE_2D, FadeTex[S]); - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (S-1) * ScreenW div Screens, 0, + ScreenW div Screens, ScreenH); + glError := glGetError(); if (glError <> GL_NO_ERROR) then begin FadeFailed := true; - Log.LogWarn('Fading disabled: ' + gluErrorString(glError), 'TDisplay.Draw'); + Log.LogError('Fading disabled: ' + gluErrorString(glError), 'TDisplay.Draw'); end; - // restore viewport - glPopAttrib(); - // blackscreen-hack - if not BlackScreen then + if not BlackScreen and (S = 1) and not DoneOnShow then + begin NextScreen.OnShow; + DoneOnShow := true; + end; // update fade state LastFadeTime := SDL_GetTicks(); @@ -312,7 +319,7 @@ begin currentTime := SDL_GetTicks(); if (currentTime > LastFadeTime+30) and (S = 1) then begin - FadeState := FadeState + 4; + FadeState := FadeState + 5; LastFadeTime := currentTime; end; @@ -325,25 +332,34 @@ begin end else if ScreenAct = 1 then begin - glClearColor(0, 0, 0 , 0); + glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); end; // and draw old screen over it... slowly fading out FadeStateSquare := (FadeState*FadeState)/10000; + FadeW := (ScreenW div Screens)/TexW; + FadeH := ScreenH/TexH; glBindTexture(GL_TEXTURE_2D, FadeTex[S]); - glColor4f(1, 1, 1, 1-FadeStateSquare); + glColor4f(1, 1, 1, 1-FadeStateSquare*1.5); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBegin(GL_QUADS); - glTexCoord2f(0+FadeStateSquare, 0+FadeStateSquare); glVertex2f(0, 600); - glTexCoord2f(0+FadeStateSquare, 1-FadeStateSquare); glVertex2f(0, 0); - glTexCoord2f(1-FadeStateSquare, 1-FadeStateSquare); glVertex2f(800, 0); - glTexCoord2f(1-FadeStateSquare, 0+FadeStateSquare); glVertex2f(800, 600); + glTexCoord2f((0+FadeStateSquare)*FadeW, (0+FadeStateSquare)*FadeH); + glVertex2f(0, RenderH); + + glTexCoord2f((0+FadeStateSquare)*FadeW, (1-FadeStateSquare)*FadeH); + glVertex2f(0, 0); + + glTexCoord2f((1-FadeStateSquare)*FadeW, (1-FadeStateSquare)*FadeH); + glVertex2f(RenderW, 0); + + glTexCoord2f((1-FadeStateSquare)*FadeW, (0+FadeStateSquare)*FadeH); + glVertex2f(RenderW, RenderH); glEnd; glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); @@ -354,10 +370,11 @@ begin NextScreen.OnShow; end; - if ((FadeState > 40) or (not FadeEnabled) or FadeFailed) and (S = 1) then + if ((FadeState > 44) or (not FadeEnabled) or FadeFailed) and (S = 1) then begin // fade out complete... FadeState := 0; + DoneOnShow := false; CurrentScreen.onHide; CurrentScreen.ShowFinish := false; CurrentScreen := NextScreen; @@ -483,7 +500,7 @@ var Ticks: cardinal; DrawX: double; begin - if (Ini.Mouse = 2) and ((Screens = 1) or ((ScreenAct - 1) = (Round(Cursor_X+16) div 800))) then + if (Ini.Mouse = 2) and ((Screens = 1) or ((ScreenAct - 1) = (Round(Cursor_X+16) div RenderW))) then begin // draw software cursor Ticks := SDL_GetTicks; -- cgit v1.2.3 From cbb3570263fb93e4bbcb9bd4c7e7d20fd4f77bb0 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 14 Mar 2010 19:54:42 +0000 Subject: removed old benchmark call git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2195 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index b928a612..2e3016ed 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -838,8 +838,6 @@ begin Button[Result].Texture.Alpha := 0; end; end; - Log.BenchmarkEnd(6); - Log.LogBenchmark('====> Screen Options32', 6); end; function TMenu.AddButton(X, Y, W, H: real; const TexName: IPath): integer; -- cgit v1.2.3 From 517d37a95f797204758f54607969a56761b4a0db Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 18 Mar 2010 17:56:04 +0000 Subject: some changes to "Select Slides" - read ShowArrows and OneItemOnly from theme - use constants for arrows alpha value - fix arrows if select has only one possible option - draw colorized selects like colorized buttons (2nd "deselect" texture) => a uniform look for option menus is possible again option screens that need some theme editing: sound, lyrics, themes, record, advanced git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2205 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 61 ++++++++++++++++++--------- src/menu/UMenuSelectSlide.pas | 98 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 122 insertions(+), 37 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 2e3016ed..a56b7c7f 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1311,28 +1311,57 @@ begin SelectsS[S] := TSelectSlide.Create; if (Typ = TEXTURE_TYPE_COLORIZED) then - SelectsS[S].Texture := Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB)) + 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; - - SelectsS[S].ColR := ColR; - SelectsS[S].ColG := ColG; - SelectsS[S].ColB := ColB; - SelectsS[S].Int := Int; - SelectsS[S].DColR := DColR; - SelectsS[S].DColG := DColG; - SelectsS[S].DColB := DColB; - SelectsS[S].DInt := DInt; + SelectsS[S].H := H; if (SBGTyp = TEXTURE_TYPE_COLORIZED) then - SelectsS[S].TextureSBG := Texture.GetTexture(SBGName, SBGTyp, RGBFloatToInt(SBGColR, SBGColG, SBGColB)) + 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; @@ -1349,14 +1378,6 @@ begin SelectsS[S].TextureSBG.Y := Y; SelectsS[S].SBGW := SBGW; SelectsS[S].TextureSBG.H := H; - SelectsS[S].SBGColR := SBGColR; - SelectsS[S].SBGColG := SBGColG; - SelectsS[S].SBGColB := SBGColB; - SelectsS[S].SBGInt := SBGInt; - SelectsS[S].SBGDColR := SBGDColR; - SelectsS[S].SBGDColG := SBGDColG; - SelectsS[S].SBGDColB := SBGDColB; - SelectsS[S].SBGDInt := SBGDInt; SelectsS[S].Text.X := X + 20; SelectsS[S].Text.Y := Y + (SelectsS[S].TextureSBG.H / 2) - 15; diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 11be4c2a..86458005 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -53,7 +53,11 @@ type Texture: TTexture; // Select Texture TextureSBG: TTexture; // Background Selections Texture -// TextureS: array of TTexture; // Selections Texture (not used) + + 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 @@ -141,6 +145,10 @@ type function OnClick(X, Y: Real): TMouseClickAction; end; +const + ArrowAlphaOptionsLeft = 1; + ArrowAlphaNoOptionsLeft = 0; + implementation uses @@ -157,6 +165,26 @@ begin 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); @@ -184,20 +212,30 @@ begin end else begin - Texture.ColR := DColR; - Texture.ColG := DColG; - Texture.ColB := DColB; - Texture.Int := DInt; + 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; - TextureSBG.ColR := SBGDColR; - TextureSBG.ColG := SBGDColG; - TextureSBG.ColB := SBGDColB; - TextureSBG.Int := SBGDInt; + if (ColorizedSBG) then + DeselectTextureSBG.Int := SBGDInt + else + begin + TextureSBG.ColR := SBGDColR; + TextureSBG.ColG := SBGDColG; + TextureSBG.ColB := SBGDColB; + TextureSBG.Int := SBGDInt; + end; end; end; @@ -240,8 +278,11 @@ begin begin Value := 0; - Tex_SelectS_ArrowL.alpha := 0; - Tex_SelectS_ArrowR.alpha := 1; + 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 @@ -256,8 +297,8 @@ begin begin Value := High(TextOptT); - Tex_SelectS_ArrowL.alpha := 1; - Tex_SelectS_ArrowR.alpha := 0; + Tex_SelectS_ArrowL.alpha := ArrowAlphaOptionsLeft; + Tex_SelectS_ArrowR.alpha := ArrowAlphaNoOptionsLeft; for SO := High(TextOpt) downto Low(TextOpt) do begin @@ -269,8 +310,8 @@ begin //in between first and last else begin - Tex_SelectS_ArrowL.alpha := 1; - Tex_SelectS_ArrowR.alpha := 1; + Tex_SelectS_ArrowL.alpha := ArrowAlphaOptionsLeft; + Tex_SelectS_ArrowR.alpha := ArrowAlphaOptionsLeft; HalfL := Ceil((Lines - 1) / 2); HalfR := Lines - 1 - HalfL; @@ -321,8 +362,31 @@ var begin if Visible then begin - DrawTexture(Texture); - DrawTexture(TextureSBG); + 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 -- cgit v1.2.3 From d290102f779675f6ceabcb5f0c6d5df6e209c2a4 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 18 Mar 2010 18:08:41 +0000 Subject: vertically center select arrows set correct z value for arrows git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2206 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index a56b7c7f..30cd9d4d 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1286,6 +1286,8 @@ begin 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; @@ -1364,13 +1366,14 @@ begin 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; + 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; + 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; -- cgit v1.2.3 From 5ccfc5107ed4006fad3253dfd9041a42049a90d4 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 7 Apr 2010 11:49:45 +0000 Subject: swap textures of statics colorized to playercolor in score screen so ticket #1 should finally be fixed git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2221 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 30cd9d4d..d30efaa7 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -168,6 +168,8 @@ type procedure AddBox(X, Y, W, H: real); end; +function RGBFloatToInt(R, G, B: double): cardinal; + const MENU_MDOWN = 8; MENU_MUP = 0; -- cgit v1.2.3 From d119e6f390a66f5ec10fa55b2ab01a005d526715 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Tue, 13 Apr 2010 14:11:07 +0000 Subject: some code cleanup git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2232 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuSelectSlide.pas | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 86458005..7fa9aca7 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -405,6 +405,9 @@ procedure TSelectSlide.GenLines; var maxlength: real; I: integer; +const + MinItemSpacing = 5; + MinSideSpacing = 24; begin SetFontStyle(0{Text.Style}); SetFontSize(Text.Size); @@ -420,7 +423,7 @@ begin if (oneItemOnly = false) then begin //show all items - Lines := floor((TextureSBG.W-40) / (maxlength+7)); + Lines := floor((TextureSBG.W - MinSideSpacing * 2) / (maxlength + MinItemSpacing)); if (Lines > Length(TextOptT)) then Lines := Length(TextOptT); @@ -437,14 +440,12 @@ begin for I := Low(TextOpt) to High(TextOpt) do TextOpt[I].Free; - setLength (TextOpt, Lines); + SetLength (TextOpt, Lines); for I := Low(TextOpt) to High(TextOpt) do begin TextOpt[I] := TText.Create; TextOpt[I].Size := Text.Size; - //TextOpt[I].Align := 1; - TextOpt[I].Align := 0; TextOpt[I].Visible := true; TextOpt[I].ColR := STDColR; @@ -452,23 +453,24 @@ begin TextOpt[I].ColB := STDColB; TextOpt[I].Int := STDInt; - //Generate Positions - //TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * (I + 0.5); - if (I <> High(TextOpt)) or (High(TextOpt) = 0) or (Length(TextOptT) = Lines) then - TextOpt[I].X := TextureSBG.X + 20 + (TextureSBG.W / Lines) * I - else - TextOpt[I].X := TextureSBG.X + TextureSBG.W - maxlength; - + // generate positions TextOpt[I].Y := TextureSBG.Y + (TextureSBG.H - Text.Size) / 2; - //Better Look with 2 Options - if (Lines = 2) and (Length(TextOptT) = 2) then + // 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; - - if (Lines = 1) then + TextOpt[I].Align := 0; + end + else if (Lines = 1) then begin - TextOpt[I].Align := 1; //center text 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; -- cgit v1.2.3 From 189d127196a855ca6a79793ba0bbe548bd415049 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Tue, 13 Apr 2010 16:20:14 +0000 Subject: cut text of select options to fit to selects bg git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2233 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuSelectSlide.pas | 54 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 7fa9aca7..17c5a7a8 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -45,6 +45,8 @@ type TSelectSlide = class private SelectBool: boolean; + + function AdjustOptionTextToFit(OptText: UTF8String): UTF8String; public // objects Text: TText; // Main text describing option @@ -148,6 +150,8 @@ type const ArrowAlphaOptionsLeft = 1; ArrowAlphaNoOptionsLeft = 0; + MinItemSpacing = 5; + MinSideSpacing = 24; implementation @@ -286,7 +290,7 @@ begin for SO := Low(TextOpt) to High(TextOpt) do begin - TextOpt[SO].Text := TextOptT[SO]; + TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[SO]); end; DoSelection(0); @@ -302,7 +306,7 @@ begin for SO := High(TextOpt) downto Low(TextOpt) do begin - TextOpt[SO].Text := TextOptT[High(TextOptT) - (Lines - SO - 1)]; + TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[High(TextOptT) - (Lines - SO - 1)]); end; DoSelection(Lines - 1); end @@ -322,7 +326,7 @@ begin //Change texts for SO := Low(TextOpt) to High(TextOpt) do begin - TextOpt[SO].Text := TextOptT[SO]; + TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[SO]); end; DoSelection(Value); @@ -336,10 +340,10 @@ begin //Change texts for SO := High(TextOpt) downto Low(TextOpt) do begin - TextOpt[SO].Text := TextOptT[High(TextOptT) - (Lines - SO - 1)]; + TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[High(TextOptT) - (Lines - SO - 1)]); end; - DoSelection (HalfL); + DoSelection (HalfL); end else @@ -347,7 +351,7 @@ begin //Change Texts for SO := Low(TextOpt) to High(TextOpt) do begin - TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; + TextOpt[SO].Text := AdjustOptionTextToFit(TextOptT[Value - HalfL + SO]); end; DoSelection(HalfL); @@ -356,6 +360,40 @@ begin 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(0); + 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; @@ -405,9 +443,6 @@ procedure TSelectSlide.GenLines; var maxlength: real; I: integer; -const - MinItemSpacing = 5; - MinSideSpacing = 24; begin SetFontStyle(0{Text.Style}); SetFontSize(Text.Size); @@ -447,6 +482,7 @@ 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; -- cgit v1.2.3 From ca12fbb41e2886ee23e95617f434742bb8be2dd1 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Tue, 13 Apr 2010 17:16:32 +0000 Subject: load type and typesbg from theme ini for selects added type definitions to deluxe themes selects git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2235 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index d30efaa7..b4ea3d00 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1278,8 +1278,8 @@ begin 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), TEXTURE_TYPE_COLORIZED, - Skin.GetTextureFileName(ThemeSelectS.TexSBG), TEXTURE_TYPE_COLORIZED, + 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]); -- cgit v1.2.3 From 65f817b9434cb60468d940bb1c23585e52800ea7 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 17 Apr 2010 15:23:18 +0000 Subject: minor screen transition improvements git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2244 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 87 ++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 39 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index b26c6896..f813220e 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -56,8 +56,7 @@ type FadeEnabled: boolean; // true if fading is enabled FadeFailed: boolean; // true if fading is possible (enough memory, etc.) - FadeState: integer; // fading state, 0 means that the fade texture must be initialized - LastFadeTime: cardinal; // last fade update time + FadeTime: cardinal; // time when fading starts, 0 means that the fade texture must be initialized DoneOnShow: boolean; // true if passed onShow after fading FadeTex: array[1..2] of GLuint; @@ -127,6 +126,9 @@ var Display: TDisplay; const + { constants for screen transition + time in milliseconds } + Transition_Fade_Time = 400; { constants for software cursor effects time in milliseconds } Cursor_FadeIn_Time = 500; // seconds the fade in effect lasts @@ -165,7 +167,7 @@ begin BlackScreen := false; // fade mod - FadeState := 0; + FadeTime := 0; FadeEnabled := (Ini.ScreenFade = 1); FadeFailed := false; DoneOnShow := false; @@ -260,7 +262,7 @@ begin ScreenPopupCheck.Draw; // fade mod - FadeState := 0; + FadeTime := 0; if ((Ini.ScreenFade = 1) and (not FadeFailed)) then FadeEnabled := true else if (Ini.ScreenFade = 0) then @@ -279,7 +281,7 @@ begin if (FadeEnabled and not FadeFailed) then begin //Create Fading texture if we're just starting - if FadeState = 0 then + if FadeTime = 0 then begin // draw screen that will be faded ePreDraw.CallHookChain(false); @@ -309,19 +311,19 @@ begin DoneOnShow := true; end; - // update fade state - LastFadeTime := SDL_GetTicks(); - if (S = 2) or (Screens = 1) then - FadeState := FadeState + 1; + + // set fade time once on second screen (or first if screens = 1) + if (Screens = 1) or (S = 2) then + FadeTime := SDL_GetTicks; end; // end texture creation in first fading step - //do some time-based fading + {//do some time-based fading currentTime := SDL_GetTicks(); if (currentTime > LastFadeTime+30) and (S = 1) then begin FadeState := FadeState + 5; LastFadeTime := currentTime; - end; + end; } // blackscreen-hack if not BlackScreen then @@ -332,48 +334,55 @@ begin end else if ScreenAct = 1 then begin - glClearColor(0, 0, 0, 0); + 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 (FadeTime = 0) then + FadeStateSquare := 0 // for first screen if screens = 2 + else + FadeStateSquare := sqr((SDL_GetTicks - FadeTime) / Transition_Fade_Time); - FadeStateSquare := (FadeState*FadeState)/10000; - FadeW := (ScreenW div Screens)/TexW; - FadeH := ScreenH/TexH; - - glBindTexture(GL_TEXTURE_2D, FadeTex[S]); - glColor4f(1, 1, 1, 1-FadeStateSquare*1.5); - - glEnable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - glBegin(GL_QUADS); - glTexCoord2f((0+FadeStateSquare)*FadeW, (0+FadeStateSquare)*FadeH); - glVertex2f(0, RenderH); - - glTexCoord2f((0+FadeStateSquare)*FadeW, (1-FadeStateSquare)*FadeH); - glVertex2f(0, 0); - - glTexCoord2f((1-FadeStateSquare)*FadeW, (1-FadeStateSquare)*FadeH); - glVertex2f(RenderW, 0); + if (FadeStateSquare < 1) then + begin + FadeW := (ScreenW div Screens)/TexW; + FadeH := ScreenH/TexH; - glTexCoord2f((1-FadeStateSquare)*FadeW, (0+FadeStateSquare)*FadeH); - glVertex2f(RenderW, RenderH); - glEnd; - glDisable(GL_BLEND); - glDisable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, FadeTex[S]); + 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); + end; end -// blackscreen hack + + // blackscreen hack else if not BlackScreen then begin NextScreen.OnShow; end; - if ((FadeState > 44) or (not FadeEnabled) or FadeFailed) and (S = 1) then + if ((FadeTime + Transition_Fade_Time < SDL_GetTicks) or (not FadeEnabled) or FadeFailed) and ((Screens = 1) or (S = 2)) then begin // fade out complete... - FadeState := 0; + FadeTime := 0; DoneOnShow := false; CurrentScreen.onHide; CurrentScreen.ShowFinish := false; -- cgit v1.2.3 From f761eb20ce8d3b5ef718be4a305b78712641248d Mon Sep 17 00:00:00 2001 From: tobigun Date: Sun, 18 Apr 2010 13:43:36 +0000 Subject: change variable names "static" to "statics" - "static" is a reserved name and should not be used - code-completion in lazarus does not work as it is not able to cope with variables that are named "static" git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2246 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 72 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index b4ea3d00..a05c667f 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -68,7 +68,7 @@ type ButtonCollection: array of TButtonCollection; public Text: array of TText; - Static: array of TStatic; + Statics: array of TStatic; mX: integer; // mouse X mY: integer; // mouse Y @@ -221,7 +221,7 @@ begin Fade := 0;//fWhite; - SetLength(Static, 0); + SetLength(Statics, 0); SetLength(Button, 0); //Set ButtonPos to Autoset Length @@ -338,8 +338,8 @@ begin AddBackground(ThemeBasic.Background); //Add Statics and Texts - for I := 0 to High(ThemeBasic.Static) do - AddStatic(ThemeBasic.Static[I]); + for I := 0 to High(ThemeBasic.Statics) do + AddStatic(ThemeBasic.Statics[I]); for I := 0 to High(ThemeBasic.Text) do AddText(ThemeBasic.Text[I]); @@ -628,16 +628,16 @@ var StatNum: integer; begin // adds static - StatNum := Length(Static); - SetLength(Static, StatNum + 1); - Static[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, $FF00FF)); // new skin + StatNum := Length(Statics); + SetLength(Statics, StatNum + 1); + Statics[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, $FF00FF)); // new skin // configures static - Static[StatNum].Texture.X := X; - Static[StatNum].Texture.Y := Y; - Static[StatNum].Texture.W := W; - Static[StatNum].Texture.H := H; - Static[StatNum].Visible := true; + 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; @@ -671,52 +671,52 @@ var StatNum: integer; begin // adds static - StatNum := Length(Static); - SetLength(Static, StatNum + 1); + StatNum := Length(Statics); + SetLength(Statics, StatNum + 1); // colorize hack if (Typ = TEXTURE_TYPE_COLORIZED) then begin // give encoded color to GetTexture() - Static[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB))); + Statics[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, RGBFloatToInt(ColR, ColG, ColB))); end else begin - Static[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, Color)); // new skin + Statics[StatNum] := TStatic.Create(Texture.GetTexture(TexName, Typ, Color)); // new skin end; // configures static - Static[StatNum].Texture.X := X; - Static[StatNum].Texture.Y := Y; + Statics[StatNum].Texture.X := X; + Statics[StatNum].Texture.Y := Y; //Set height and width via sprite size if omitted if(H = 0) then - Static[StatNum].Texture.H := Static[StatNum].Texture.H + Statics[StatNum].Texture.H := Statics[StatNum].Texture.H else - Static[StatNum].Texture.H := H; + Statics[StatNum].Texture.H := H; if(W = 0) then - Static[StatNum].Texture.W := Static[StatNum].Texture.W + Statics[StatNum].Texture.W := Statics[StatNum].Texture.W else - Static[StatNum].Texture.W := W; + Statics[StatNum].Texture.W := W; - Static[StatNum].Texture.Z := Z; + Statics[StatNum].Texture.Z := Z; if (Typ <> TEXTURE_TYPE_COLORIZED) then begin - Static[StatNum].Texture.ColR := ColR; - Static[StatNum].Texture.ColG := ColG; - Static[StatNum].Texture.ColB := ColB; + Statics[StatNum].Texture.ColR := ColR; + Statics[StatNum].Texture.ColG := ColG; + Statics[StatNum].Texture.ColB := ColB; end; - Static[StatNum].Texture.TexX1 := TexX1; - Static[StatNum].Texture.TexY1 := TexY1; - Static[StatNum].Texture.TexX2 := TexX2; - Static[StatNum].Texture.TexY2 := TexY2; - Static[StatNum].Texture.Alpha := 1; - Static[StatNum].Visible := true; + 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 - Static[StatNum].Reflection := Reflection; - Static[StatNum].ReflectionSpacing := ReflectionSpacing; + Statics[StatNum].Reflection := Reflection; + Statics[StatNum].ReflectionSpacing := ReflectionSpacing; Result := StatNum; end; @@ -934,8 +934,8 @@ var J: integer; begin // We don't forget about newly implemented static for nice skin ... - for J := 0 to High(Static) do - Static[J].Draw; + for J := 0 to High(Statics) do + Statics[J].Draw; // ... and slightly implemented menutext unit for J := 0 to High(Text) do -- cgit v1.2.3 From 868ce765441473e7d1fec9b3ad22a707f121a637 Mon Sep 17 00:00:00 2001 From: tobigun Date: Wed, 21 Apr 2010 18:27:36 +0000 Subject: - add video loop option - allow multiple instances of a video git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2260 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuBackgroundVideo.pas | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuBackgroundVideo.pas b/src/menu/UMenuBackgroundVideo.pas index 9d265764..006c45e0 100644 --- a/src/menu/UMenuBackgroundVideo.pas +++ b/src/menu/UMenuBackgroundVideo.pas @@ -36,6 +36,7 @@ interface uses UThemes, UMenuBackground, + UMusic, UVideo, UPath; @@ -84,6 +85,7 @@ type } TMenuBackgroundVideo = class (TMenuBackground) private fFilename: IPath; + fBgVideo: IVideo; public constructor Create(const ThemedSettings: TThemeBackground); override; procedure OnShow; override; @@ -102,7 +104,6 @@ implementation uses gl, glext, - UMusic, SysUtils, UTime, USkins, @@ -116,42 +117,48 @@ begin raise EMenuBackgroundError.Create('TMenuBackgroundVideo: No video filename present'); fFileName := Skin.GetTextureFileName(ThemedSettings.Tex); - if fFilename.IsFile and VideoPlayback.Open(fFileName) then - begin - VideoBGTimer.SetTime(0); - VideoPlayback.Play; - end - else + 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; +procedure TMenuBackgroundVideo.OnShow; begin - if VideoPlayback.Open( fFileName ) then + fBgVideo := VideoPlayback.Open(fFileName); + if (fBgVideo <> nil) then begin VideoBGTimer.SetTime(0); - VideoPlayback.Play; + fBgVideo.Loop := true; + fBgVideo.Play; end; end; procedure TMenuBackgroundVideo.OnFinish; begin - + // unload video + fBgVideo := nil; end; -procedure TMenuBackgroundVideo.Draw; +procedure TMenuBackgroundVideo.Draw; begin - If (ScreenAct = 1) then //Clear just once when in dual screen mode + // 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; - VideoPlayback.GetFrame(VideoBGTimer.GetTime()); + if (fBgVideo <> nil) then + begin + fBgVideo.GetFrame(VideoBGTimer.GetTime()); // FIXME: why do we draw on screen 2? Seems to be wrong. - VideoPlayback.DrawGL(2); + fBgVideo.DrawGL(2); + end; end; // Implementation of TBGVideo -- cgit v1.2.3 From edfc692c991e08af0163aa6812e5972478d7191b Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 22 Apr 2010 01:04:24 +0000 Subject: - now it is possible to sync lyrics to audio - ini option SyncTo added - lyric to audio is default now (instead of sync audio to lyrics) - modified RelativeTimer (hopefully easier to use and more self-explanatory) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2273 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuBackgroundVideo.pas | 1 + 1 file changed, 1 insertion(+) (limited to 'src/menu') diff --git a/src/menu/UMenuBackgroundVideo.pas b/src/menu/UMenuBackgroundVideo.pas index 006c45e0..bfaee702 100644 --- a/src/menu/UMenuBackgroundVideo.pas +++ b/src/menu/UMenuBackgroundVideo.pas @@ -131,6 +131,7 @@ begin if (fBgVideo <> nil) then begin VideoBGTimer.SetTime(0); + VideoBGTimer.Start(); fBgVideo.Loop := true; fBgVideo.Play; end; -- cgit v1.2.3 From 69cf82185e7f559d8858b44fa76379c771acc6b6 Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 23 Apr 2010 22:39:26 +0000 Subject: - font fallback added - more configurable fonts.ini - ftNormal/ftBold/ftOutline1/2 added git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2293 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 2 +- src/menu/UMenuSelectSlide.pas | 4 ++-- src/menu/UMenuText.pas | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index f813220e..02fda099 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -703,7 +703,7 @@ begin glDisable(GL_BLEND); // set font specs - SetFontStyle(0); + SetFontStyle(ftNormal); SetFontSize(21); SetFontItalic(false); glColor4f(0, 0, 0, 1); diff --git a/src/menu/UMenuSelectSlide.pas b/src/menu/UMenuSelectSlide.pas index 17c5a7a8..09ce3b9f 100644 --- a/src/menu/UMenuSelectSlide.pas +++ b/src/menu/UMenuSelectSlide.pas @@ -372,7 +372,7 @@ begin begin MaxLen := TextureSBG.W - MinSideSpacing * 2; - SetFontStyle(0); + SetFontStyle(ftNormal); SetFontSize(Text.Size); // we will remove min. 2 letters by default and replace them w/ points @@ -444,7 +444,7 @@ var maxlength: real; I: integer; begin - SetFontStyle(0{Text.Style}); + SetFontStyle(ftNormal{Text.Style}); SetFontSize(Text.Size); maxlength := 0; diff --git a/src/menu/UMenuText.pas b/src/menu/UMenuText.pas index 276f961b..ab180b77 100644 --- a/src/menu/UMenuText.pas +++ b/src/menu/UMenuText.pas @@ -297,7 +297,7 @@ begin SetFontPos(X2, Y); glPrint(Text2); - SetFontStyle(0); // reset to default + SetFontStyle(ftNormal); // reset to default end else begin} @@ -326,12 +326,12 @@ begin {if Size >= 10 then Y2 := Y2 + Size * 0.93 else} - if (Style = 1) then + if (Style = ftBold) then Y2 := Y2 + Size * 0.93 else Y2 := Y2 + Size * 0.72; end; - SetFontStyle(0); // reset to default + SetFontStyle(ftNormal); // reset to default //end; end; @@ -344,7 +344,7 @@ end; constructor TText.Create(X, Y: real; const Text: UTF8String); begin - Create(X, Y, 0, 0, 30, 0, 0, 0, 0, Text, false, 0, 0); + Create(X, Y, 0, ftNormal, 30, 0, 0, 0, 0, Text, false, 0, 0); end; constructor TText.Create(ParX, ParY, ParW: real; -- cgit v1.2.3 From 666189bdf771731b25ade3eaf4db82dac2343a64 Mon Sep 17 00:00:00 2001 From: tobigun Date: Sun, 25 Apr 2010 16:45:48 +0000 Subject: - fix: fade texture needs to be resized if the window was resized - Previously the texture could have been too small (window initialized with 800x600 pixels -> fadeTex size 1024x1024. Then resize window to 1400x1050 and the texture will be too small) and an opengl error at glCopyTexSubImage2D() will occur. Due to the error fading was disabled then. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2308 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 54 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 19 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 02fda099..0b32c6cd 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -59,7 +59,7 @@ type FadeTime: cardinal; // time when fading starts, 0 means that the fade texture must be initialized DoneOnShow: boolean; // true if passed onShow after fading - FadeTex: array[1..2] of GLuint; + FadeTex: array[0..1] of GLuint; TexW, TexH: Cardinal; FPSCounter: cardinal; @@ -97,6 +97,8 @@ type constructor Create; destructor Destroy; override; + procedure InitFadeTextures(); + procedure SaveScreenShot; function Draw: boolean; @@ -151,8 +153,6 @@ uses UPathUtils; constructor TDisplay.Create; -var - i: integer; begin inherited Create; @@ -172,18 +172,8 @@ begin FadeFailed := false; DoneOnShow := false; - for i := 1 to 2 do - begin - TexW := Round(Power(2, Ceil(Log2(ScreenW div Screens)))); - TexH := Round(Power(2, Ceil(Log2(ScreenH)))); - - glGenTextures(1, PglUint(@FadeTex[i])); - glBindTexture(GL_TEXTURE_2D, FadeTex[i]); - glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexImage2D(GL_TEXTURE_2D, 0, 3, TexW, TexH, 0, GL_RGB, GL_UNSIGNED_BYTE, nil); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - end; + glGenTextures(2, PGLuint(@FadeTex)); + InitFadeTextures(); //Set LastError for OSD to No Error OSD_LastError := 'No Errors'; @@ -200,15 +190,33 @@ end; destructor TDisplay.Destroy; begin - glDeleteTextures(2, @FadeTex); + 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]); + //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexImage2D(GL_TEXTURE_2D, 0, 3, TexW, TexH, 0, GL_RGB, GL_UNSIGNED_BYTE, nil); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + end; +end; + function TDisplay.Draw: boolean; var S: integer; FadeStateSquare: real; FadeW, FadeH: real; + FadeCopyW, FadeCopyH: integer; currentTime: cardinal; glError: glEnum; @@ -292,10 +300,18 @@ begin // 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]); + glBindTexture(GL_TEXTURE_2D, FadeTex[S-1]); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (S-1) * ScreenW div Screens, 0, - ScreenW div Screens, ScreenH); + FadeCopyW, FadeCopyH); glError := glGetError(); if (glError <> GL_NO_ERROR) then @@ -349,7 +365,7 @@ begin FadeW := (ScreenW div Screens)/TexW; FadeH := ScreenH/TexH; - glBindTexture(GL_TEXTURE_2D, FadeTex[S]); + glBindTexture(GL_TEXTURE_2D, FadeTex[S-1]); glColor4f(1, 1, 1, 1-FadeStateSquare); glEnable(GL_TEXTURE_2D); -- cgit v1.2.3 From d142fd8700057ad284e2620076d6716387f3cd63 Mon Sep 17 00:00:00 2001 From: tobigun Date: Sun, 25 Apr 2010 17:14:14 +0000 Subject: wrong usage of glTexEnvi fixed - the environment must be GL_TEXTURE_ENV and not GL_TEXTURE_2D - it must be set before a draw function (glBegin(), ...) and not before glTexImage2D() as the current texture will not store this setting (the setting is global for all textures). - the setting must be set to the default (GL_MODULATE) after usage, otherwise later opengl drawing calls will be unwantedly affected too. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2309 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index 0b32c6cd..e3ec272a 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -204,10 +204,9 @@ begin for i := 0 to 1 do begin glBindTexture(GL_TEXTURE_2D, FadeTex[i]); - //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexImage2D(GL_TEXTURE_2D, 0, 3, TexW, TexH, 0, GL_RGB, GL_UNSIGNED_BYTE, nil); 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; @@ -366,6 +365,8 @@ begin 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); @@ -386,6 +387,9 @@ begin glEnd; glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); + + // reset to default + //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); end; end -- cgit v1.2.3 From 9256b21515b03d1d39013930cce4401b4dd3f8a0 Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 3 May 2010 16:32:25 +0000 Subject: - Replaced another usage of Screen.w/Screen.h with ScreenW/ScreenH - This fixes the detection of the mouse position on non 4:3 displays git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2333 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index a05c667f..dd4f257e 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1667,10 +1667,10 @@ begin end; // transfer mousecords to the 800x600 raster we use to draw - X := Round((X / (Screen.w / Screens)) * RenderW); + X := Round((X / (ScreenW / Screens)) * RenderW); if (X > RenderW) then X := X - RenderW; - Y := Round((Y / Screen.h) * RenderH); + Y := Round((Y / ScreenH) * RenderH); nBut := InteractAt(X, Y); if nBut >= 0 then -- cgit v1.2.3 From cb9c992abfc5c003b020f97f1384bc7c0e346534 Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 3 May 2010 16:36:52 +0000 Subject: - Free Statics/Buttons/Texts if a screen is destroyed (Textures used by those components are not unloaded yet) - Use Free() instead of Destroy() as it checks for nil by default git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2334 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index dd4f257e..6bceef62 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -206,11 +206,22 @@ uses UMenuBackgroundFade; destructor TMenu.Destroy; +var + I: integer; begin - if (Background <> nil) then - begin - Background.Destroy; - end; + 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; @@ -379,11 +390,7 @@ procedure TMenu.AddBackground(ThemedSettings: TThemeBackground); end; begin - if (Background <> nil) then - begin - Background.Destroy; - Background := nil; - end; + FreeAndNil(Background); case ThemedSettings.BGType of bgtAuto: begin //Automaticly choose one out of BGT_Texture, BGT_Video or BGT_Color -- cgit v1.2.3 From dcdbbe0e9b320c4a0d83ae3c57fba1b5dd4c233a Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Tue, 18 May 2010 17:03:04 +0000 Subject: fix mouse in ScreenPartyNewRound git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2382 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenu.pas | 91 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 41 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenu.pas b/src/menu/UMenu.pas index 6bceef62..b011eddf 100644 --- a/src/menu/UMenu.pas +++ b/src/menu/UMenu.pas @@ -1679,54 +1679,63 @@ begin X := X - RenderW; Y := Round((Y / ScreenH) * RenderH); - nBut := InteractAt(X, Y); - if nBut >= 0 then + // allways go to next screen if we don't have any interactions + if Length(Interactions) = 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; + if (BtnDown) and (MouseButton = SDL_BUTTON_LEFT) then + Result := ParseInput(SDLK_RETURN, 0, true); end else begin - nBut := CollectionAt(X, Y); - if (nBut >= 0) and (not ButtonCollection[nBut].Selected) then + nBut := InteractAt(X, Y); + if nBut >= 0 then begin - // if over button collection, that is not already selected - // -> select first child but don't allow click - nBut := ButtonCollection[nBut].FirstChild - 1; + //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; -- cgit v1.2.3 From 99f1a940f702c1b1096e87c11a7e8887d6f025fc Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 3 Jun 2010 07:54:29 +0000 Subject: cleanup: - FadeTime -> FadeStartTime - constants upper-case git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2433 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 55 +++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index e3ec272a..d393937c 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -56,7 +56,7 @@ type FadeEnabled: boolean; // true if fading is enabled FadeFailed: boolean; // true if fading is possible (enough memory, etc.) - FadeTime: cardinal; // time when fading starts, 0 means that the fade texture must be initialized + 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; @@ -130,12 +130,12 @@ var const { constants for screen transition time in milliseconds } - Transition_Fade_Time = 400; + FADE_DURATION = 400; { 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 + 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 @@ -167,7 +167,7 @@ begin BlackScreen := false; // fade mod - FadeTime := 0; + FadeStartTime := 0; FadeEnabled := (Ini.ScreenFade = 1); FadeFailed := false; DoneOnShow := false; @@ -222,11 +222,6 @@ var begin Result := true; - //We don't need this here anymore, - //Because the background care about cleaning the buffers - //glClearColor(1, 1, 1 , 0); - //glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); - for S := 1 to Screens do begin ScreenAct := S; @@ -269,7 +264,7 @@ begin ScreenPopupCheck.Draw; // fade mod - FadeTime := 0; + FadeStartTime := 0; if ((Ini.ScreenFade = 1) and (not FadeFailed)) then FadeEnabled := true else if (Ini.ScreenFade = 0) then @@ -288,7 +283,7 @@ begin if (FadeEnabled and not FadeFailed) then begin //Create Fading texture if we're just starting - if FadeTime = 0 then + if FadeStartTime = 0 then begin // draw screen that will be faded ePreDraw.CallHookChain(false); @@ -329,17 +324,9 @@ begin // set fade time once on second screen (or first if screens = 1) if (Screens = 1) or (S = 2) then - FadeTime := SDL_GetTicks; + FadeStartTime := SDL_GetTicks; end; // end texture creation in first fading step - {//do some time-based fading - currentTime := SDL_GetTicks(); - if (currentTime > LastFadeTime+30) and (S = 1) then - begin - FadeState := FadeState + 5; - LastFadeTime := currentTime; - end; } - // blackscreen-hack if not BlackScreen then begin @@ -354,10 +341,10 @@ begin end; // and draw old screen over it... slowly fading out - if (FadeTime = 0) then + if (FadeStartTime = 0) then FadeStateSquare := 0 // for first screen if screens = 2 else - FadeStateSquare := sqr((SDL_GetTicks - FadeTime) / Transition_Fade_Time); + FadeStateSquare := sqr((SDL_GetTicks - FadeStartTime) / FADE_DURATION); if (FadeStateSquare < 1) then begin @@ -399,10 +386,12 @@ begin NextScreen.OnShow; end; - if ((FadeTime + Transition_Fade_Time < SDL_GetTicks) or (not FadeEnabled) or FadeFailed) and ((Screens = 1) or (S = 2)) then + if ((FadeStartTime + FADE_DURATION < SDL_GetTicks) or + (not FadeEnabled) or FadeFailed) and + ((Screens = 1) or (S = 2)) then begin // fade out complete... - FadeTime := 0; + FadeStartTime := 0; DoneOnShow := false; CurrentScreen.onHide; CurrentScreen.ShowFinish := false; @@ -421,7 +410,7 @@ begin end; end; // if -// Draw OSD only on first Screen if Debug Mode is enabled + // Draw OSD only on first Screen if Debug Mode is enabled if ((Ini.Debug = 1) or (Params.Debug)) and (S = 1) then DrawDebugInformation; @@ -485,7 +474,7 @@ begin 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)) + Cursor_LastMove := Ticks - round(CURSOR_FADE_IN_TIME * (1 - (Ticks - Cursor_LastMove)/CURSOR_FADE_OUT_TIME)) else Cursor_LastMove := Ticks; @@ -533,7 +522,7 @@ begin begin // draw software cursor Ticks := SDL_GetTicks; - if (Cursor_Visible) and (Cursor_LastMove + Cursor_AutoHide_Time <= Ticks) then + 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; @@ -545,17 +534,17 @@ begin begin if Cursor_Visible then begin // fade in - if (Cursor_LastMove + Cursor_FadeIn_Time <= Ticks) then + if (Cursor_LastMove + CURSOR_FADE_IN_TIME <= Ticks) then Cursor_Fade := false else - Alpha := sin((Ticks - Cursor_LastMove) * 0.5 * pi / Cursor_FadeIn_Time) * 0.7; + Alpha := sin((Ticks - Cursor_LastMove) * 0.5 * pi / CURSOR_FADE_IN_TIME) * 0.7; end else begin //fade out - if (Cursor_LastMove + Cursor_FadeOut_Time <= Ticks) then + if (Cursor_LastMove + CURSOR_FADE_OUT_TIME <= Ticks) then Cursor_Fade := false else - Alpha := cos((Ticks - Cursor_LastMove) * 0.5 * pi / Cursor_FadeOut_Time) * 0.7; + Alpha := cos((Ticks - Cursor_LastMove) * 0.5 * pi / CURSOR_FADE_OUT_TIME) * 0.7; end; end; -- cgit v1.2.3 From f3258fca8a0980bad3b2a1a505a0b03c44dbc36b Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 3 Jun 2010 08:00:19 +0000 Subject: cleanup git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2434 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index d393937c..ed66836d 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -233,8 +233,7 @@ begin glViewPort((S-1) * ScreenW div Screens, 0, ScreenW div Screens, ScreenH); - // popup hack - // check was successful... move on + // popup check was successful... move on if CheckOK then begin if assigned(NextScreenWithCheck) then @@ -255,7 +254,7 @@ begin ePreDraw.CallHookChain(false); CurrentScreen.Draw; - //popup mod + // popup if (ScreenPopupError <> nil) and ScreenPopupError.Visible then ScreenPopupError.Draw else if (ScreenPopupInfo <> nil) and ScreenPopupInfo.Visible then @@ -263,7 +262,7 @@ begin else if (ScreenPopupCheck <> nil) and ScreenPopupCheck.Visible then ScreenPopupCheck.Draw; - // fade mod + // fade FadeStartTime := 0; if ((Ini.ScreenFade = 1) and (not FadeFailed)) then FadeEnabled := true -- cgit v1.2.3 From bd7f987e26bf8d2308f14d219434c25b13d37c6f Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 3 Jun 2010 08:11:58 +0000 Subject: cleanup git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2435 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index ed66836d..fbe469a5 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -51,7 +51,7 @@ type ePreDraw: THookableEvent; eDraw: THookableEvent; - //fade-to-black-hack + // fade-to-black BlackScreen: boolean; FadeEnabled: boolean; // true if fading is enabled @@ -87,7 +87,7 @@ type NextScreen: PMenu; CurrentScreen: PMenu; - //popup data + // popup data NextScreenWithCheck: Pmenu; CheckOK: boolean; @@ -160,13 +160,13 @@ begin ePreDraw := THookableEvent.Create('Display.PreDraw'); eDraw := THookableEvent.Create('Display.Draw'); - //popup hack + // init popup CheckOK := false; NextScreen := nil; NextScreenWithCheck := nil; BlackScreen := false; - // fade mod + // init fade FadeStartTime := 0; FadeEnabled := (Ini.ScreenFade = 1); FadeFailed := false; @@ -175,7 +175,7 @@ begin glGenTextures(2, PGLuint(@FadeTex)); InitFadeTextures(); - //Set LastError for OSD to No Error + // set LastError for OSD to No Error OSD_LastError := 'No Errors'; // software cursor default values @@ -281,7 +281,7 @@ begin if (FadeEnabled and not FadeFailed) then begin - //Create Fading texture if we're just starting + // create fading texture if we're just starting if FadeStartTime = 0 then begin // draw screen that will be faded @@ -313,7 +313,6 @@ begin Log.LogError('Fading disabled: ' + gluErrorString(glError), 'TDisplay.Draw'); end; - // blackscreen-hack if not BlackScreen and (S = 1) and not DoneOnShow then begin NextScreen.OnShow; @@ -326,7 +325,6 @@ begin FadeStartTime := SDL_GetTicks; end; // end texture creation in first fading step - // blackscreen-hack if not BlackScreen then begin ePreDraw.CallHookChain(false); @@ -335,6 +333,7 @@ begin 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; @@ -378,8 +377,8 @@ begin //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); end; end - - // blackscreen hack + + // there is no need to init next screen if it is a black screen else if not BlackScreen then begin NextScreen.OnShow; -- cgit v1.2.3 From 821733e30e78e05862ce73b0031d767099ef23cf Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 3 Jun 2010 08:19:24 +0000 Subject: fix: FadeEnabled was not initialized correctly. The case ((Ini.ScreenFade = 1) and FadeFailed) was not handled git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2436 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UDisplay.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/menu') diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas index fbe469a5..6ec8e2ed 100644 --- a/src/menu/UDisplay.pas +++ b/src/menu/UDisplay.pas @@ -266,7 +266,7 @@ begin FadeStartTime := 0; if ((Ini.ScreenFade = 1) and (not FadeFailed)) then FadeEnabled := true - else if (Ini.ScreenFade = 0) then + else FadeEnabled := false; eDraw.CallHookChain(false); -- cgit v1.2.3 From f261cd24db299daee8a0d8e470ff7d173f1a1c75 Mon Sep 17 00:00:00 2001 From: brunzelchen Date: Thu, 10 Jun 2010 18:27:53 +0000 Subject: merge of VideoPreview branch into trunk git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2475 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/menu/UMenuBackgroundVideo.pas | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/menu') diff --git a/src/menu/UMenuBackgroundVideo.pas b/src/menu/UMenuBackgroundVideo.pas index bfaee702..9a33e721 100644 --- a/src/menu/UMenuBackgroundVideo.pas +++ b/src/menu/UMenuBackgroundVideo.pas @@ -151,14 +151,14 @@ begin glClear(GL_DEPTH_BUFFER_BIT); // video failure -> draw blank background if (fBgVideo = nil) then - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); end; if (fBgVideo <> nil) then begin fBgVideo.GetFrame(VideoBGTimer.GetTime()); - // FIXME: why do we draw on screen 2? Seems to be wrong. - fBgVideo.DrawGL(2); + fBgVideo.SetScreen(ScreenAct); + fBgVideo.Draw(); end; end; -- cgit v1.2.3