From 5ed6620bad808381fce94f2cd67ee911b4d45bff Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 21 Mar 2007 19:19:04 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Game/Code/Menu/UMenuText.pas (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas new file mode 100644 index 00000000..5c435a18 --- /dev/null +++ b/Game/Code/Menu/UMenuText.pas @@ -0,0 +1,96 @@ +unit UMenuText; + +interface +uses TextGL, UTexture, OpenGL12, SysUtils; + +type + TText = class + private + SelectBool: boolean; + public + X: real; + Y: real; +// W: real; // if text is wider than W then it is streched (not yet implemented) +// H: real; + Size: real; + Text: string; + ColR: real; + ColG: real; + ColB: real; + Int: real; + Style: integer; + Visible: boolean; + Align: integer; // 0 = left, 1 = center, 2 = right + + procedure SetSelect(Value: Boolean); + property Selected: Boolean read SelectBool write SetSelect; + + procedure Draw; + constructor Create; overload; + constructor Create(X, Y: real; Tekst: string); overload; + constructor Create(ParX, ParY: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); overload; + end; + +implementation +uses UGraphic; + +procedure TText.SetSelect(Value: Boolean); +begin + SelectBool := Value; +end; + +procedure TText.Draw; +var + X2: real; + Text2: string; +begin + if Visible then begin + SetFontStyle(Style); + SetFontSize(Size); + glColor3f(ColR*Int, ColG*Int, ColB*Int); + if not SelectBool 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; +end; + +constructor TText.Create; +begin + Create(0, 0, ''); +end; + +constructor TText.Create(X, Y: real; Tekst: string); +begin + Create(X, Y, 0, 10, 0, 0, 0, 0, Tekst); +end; + +constructor TText.Create(ParX, ParY: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); +begin + inherited Create; + X := ParX; + Y := ParY; + Style := ParStyle; + Size := ParSize; + Text := ParTekst; + ColR := ParColR; + ColG := ParColG; + ColB := ParColB; + Int := 1; + Align := ParAlign; + SelectBool := false; + Visible := true; +end; + + +end. -- cgit v1.2.3 From e0e16a3b1d28cf51fecf669d42465cf2a65728f3 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 29 Mar 2007 16:54:52 +0000 Subject: Added SBGW to TSelectSlide: Defining the Width of the Selections BG Added W to TText + Pagebreaks. If Width is given the Text breaks at the given width. Breaks are not generated perfect yet, needs some tuning. Changed all affected Screens to fit the new TText Component git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@49 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 141 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 18 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 5c435a18..4a5356d8 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -7,13 +7,14 @@ type TText = class private SelectBool: boolean; + TextString: String; + TextTiles: Array of String; public X: real; Y: real; -// W: real; // if text is wider than W then it is streched (not yet implemented) + W: real; // if text is wider than W then it is breaked // H: real; Size: real; - Text: string; ColR: real; ColG: real; ColB: real; @@ -25,43 +26,146 @@ type 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: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); overload; + constructor Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); overload; end; implementation -uses UGraphic; +uses UGraphic, StrUtils; procedure TText.SetSelect(Value: Boolean); begin SelectBool := Value; end; +procedure TText.SetText(Value: String); +var + I: Integer; + L: Integer; + LastPos: Integer; + LastBreak: Integer; +begin + TextString := Value; + + if (W > 0) then + begin + //Set Font Propertys + SetFontStyle(Style); + SetFontSize(Size); + + //Create New TextTiles Array + SetLength (TextTiles, 0); + L := 0; + + LastPos := 1; + LastBreak := 0; + I := Pos (' ', Value); + While (I <> 0) do + begin + if (glTextWidth(PChar(Copy (Value,LastBreak + 1,I))) > W) AND (LastPos <> 1) then + begin + //new Break + SetLength (TextTiles, L+1); + TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); + + Inc(L); + LastBreak := LastPos; + end; + + LastPos := I; + I := PosEx (' ', Value, I+1); + end; + + //Last Break + if (glTextWidth(PChar(Copy (Value,LastBreak + 1,Length(Value) - LastBreak))) > W) AND (LastPos <> 1) then + begin + //new Break + SetLength (TextTiles, L+1); + TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); + + Inc(L); + LastBreak := LastPos; + end; + + //last Part + SetLength (TextTiles, L+1); + TextTiles[L] := Copy (Value, LastBreak + 1, Length(Value) - LastBreak); + + end; +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: real; + X2, Y2: real; Text2: string; + I: Integer; begin if Visible then begin SetFontStyle(Style); SetFontSize(Size); + SetFontItalic(False); glColor3f(ColR*Int, ColG*Int, ColB*Int); - if not SelectBool then - Text2 := Text + if (W <= 0) then //No Width set Draw as one Long String + begin + if not SelectBool 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 - Text2 := Text + '|'; + begin //Draw Text as Many Strings + Y2 := Y; + for I := 0 to high(TextTiles) do + begin + if (not SelectBool) OR (I <> high(TextTiles)) then + Text2 := TextTiles[I] + else + Text2 := TextTiles[I] + '|'; - case Align of - 0: X2 := X; - 1: X2 := X - glTextWidth(pchar(Text2))/2; - 2: X2 := X - glTextWidth(pchar(Text2)); - end; + 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 + SetFontPos(X2, Y2); + glPrint(PChar(Text2)); + + Y2 := Y2 + Size * 1.7; + end; + SetFontStyle(0); // reset to default + + end; end; end; @@ -72,14 +176,15 @@ end; constructor TText.Create(X, Y: real; Tekst: string); begin - Create(X, Y, 0, 10, 0, 0, 0, 0, Tekst); + Create(X, Y, 0, 0, 10, 0, 0, 0, 0, Tekst); end; -constructor TText.Create(ParX, ParY: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); +constructor TText.Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); begin inherited Create; X := ParX; Y := ParY; + W := ParW; Style := ParStyle; Size := ParSize; Text := ParTekst; -- cgit v1.2.3 From eb7df4c30c7e119ad56eb3ba8506ff3e3afce4a4 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Fri, 30 Mar 2007 19:18:27 +0000 Subject: Added Cursor Blink to TText git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@56 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 4a5356d8..4b8ea391 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -9,6 +9,9 @@ type SelectBool: boolean; TextString: String; TextTiles: Array of String; + + STicks: Cardinal; + SelectBlink: Boolean; public X: real; Y: real; @@ -38,11 +41,15 @@ type end; implementation -uses UGraphic, StrUtils; +uses UGraphic, StrUtils, Windows; procedure TText.SetSelect(Value: Boolean); begin SelectBool := Value; + + //Set Cursor Visible + SelectBlink := True; + STicks := GettickCount div 550; end; procedure TText.SetText(Value: String); @@ -99,6 +106,10 @@ begin TextTiles[L] := Copy (Value, LastBreak + 1, Length(Value) - LastBreak); end; + + //Set Cursor Visible + SelectBlink := True; + STicks := GettickCount div 550; end; Procedure TText.DeleteLastL; @@ -125,9 +136,21 @@ begin SetFontSize(Size); SetFontItalic(False); glColor3f(ColR*Int, ColG*Int, ColB*Int); + + //If Selected Set Blink... + if SelectBool then + begin + I := Gettickcount div 550; + if I <> STicks then + begin //Change Visability + STicks := I; + SelectBlink := Not SelectBlink; + end; + end; + if (W <= 0) then //No Width set Draw as one Long String begin - if not SelectBool then + if not (SelectBool AND SelectBlink) then Text2 := Text else Text2 := Text + '|'; @@ -147,7 +170,7 @@ begin Y2 := Y; for I := 0 to high(TextTiles) do begin - if (not SelectBool) OR (I <> high(TextTiles)) then + if (not (SelectBool AND SelectBlink)) OR (I <> high(TextTiles)) then Text2 := TextTiles[I] else Text2 := TextTiles[I] + '|'; -- cgit v1.2.3 From e7650e739e84b47ce6384767e39115adb5d3211a Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 19 Apr 2007 15:30:51 +0000 Subject: Fixed a Bug in PageBreak generation for Text Added support for /n Tag in Texts git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@117 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 4b8ea391..55f84bf8 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -61,6 +61,7 @@ var begin TextString := Value; + //Create Page Breaks if width is given if (W > 0) then begin //Set Font Propertys @@ -76,7 +77,7 @@ begin I := Pos (' ', Value); While (I <> 0) do begin - if (glTextWidth(PChar(Copy (Value,LastBreak + 1,I))) > W) AND (LastPos <> 1) then + if (glTextWidth(PChar(Copy (Value,LastBreak + 1,I - LastBreak))) > W) AND (LastPos <> 1) then begin //new Break SetLength (TextTiles, L+1); @@ -105,6 +106,39 @@ begin SetLength (TextTiles, L+1); TextTiles[L] := Copy (Value, LastBreak + 1, Length(Value) - LastBreak); + end + else + begin + SetLength (TextTiles, 1); + TextTiles[0] := Value; + end; + + I := 0; + // /n Hack + While (I <= High(TextTiles)) do + begin + LastPos := Pos ('/n', TextTiles[I]); + if (LastPos = 0) then //No /n Tags -> Search in next Tile + Inc(I) + else //Found /n Tag -> Create a Break + begin + //Add a new Tile and move all Tiles behind actual Tile to the right + L := Length(TextTiles); + SetLength(TextTiles, L+1); + For L := L-1 downto I + 1 do + begin + TextTiles[L+1] := TextTiles[L]; + end; + + //Write Text to new Tile + TextTiles[I+1] := Trim(Copy(TextTiles[I], LastPos + 2, Length(TextTiles[I]) - LastPos - 1)); + //Delete Text that now is in new Tile from cur. Tile + Delete(TextTiles[I], LastPos, Length(TextTiles[I]) - LastPos + 1); + TextTiles[I] := Trim (TextTiles[I]); + + //Goto next Tile because cur. Tile can not have another /n Tag + Inc(I) + end; end; //Set Cursor Visible @@ -148,7 +182,7 @@ begin end; end; - if (W <= 0) 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 -- cgit v1.2.3 From 6cdcfb402ce738dfc77b008fcb98fd1cda691eb5 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 19 Apr 2007 18:53:22 +0000 Subject: Added Statistic Screens to C0de and to Theme Moved some Translated Strings from UScreenPartyOptions to UTheme to use it with the Statistic Screens, too. Fixed use of /n Tag istead of the correct \n git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@118 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 55f84bf8..65034f1d 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -114,13 +114,13 @@ begin end; I := 0; - // /n Hack + // \n Hack While (I <= High(TextTiles)) do begin - LastPos := Pos ('/n', TextTiles[I]); + LastPos := Pos ('\n', TextTiles[I]); if (LastPos = 0) then //No /n Tags -> Search in next Tile Inc(I) - else //Found /n Tag -> Create a Break + else //Found \n Tag -> Create a Break begin //Add a new Tile and move all Tiles behind actual Tile to the right L := Length(TextTiles); -- cgit v1.2.3 From 3d1f2a49bbffd8568916a41a131213198f408bef Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Fri, 27 Apr 2007 20:02:41 +0000 Subject: PageBreak Code Rewritten Now there is more structur in Code Also some Bugs are fixed that appears when \n Tags and Textwidth is used in one Text. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@145 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 283 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 233 insertions(+), 50 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 65034f1d..adf58840 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -15,6 +15,8 @@ type public X: real; Y: 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; // if text is wider than W then it is breaked // H: real; Size: real; @@ -54,66 +56,139 @@ end; procedure TText.SetText(Value: String); var - I: Integer; - L: Integer; - LastPos: Integer; - LastBreak: Integer; + 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 Smallest(const A, B: Cardinal):Cardinal; + begin + if (A < B) then + Result := A + else + Result := B; + end; + + 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 := Smallest(T1, T3{Smallest(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; - //Create Page Breaks if width is given + //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 Propertys SetFontStyle(Style); SetFontSize(Size); + end; - //Create New TextTiles Array - SetLength (TextTiles, 0); - L := 0; - LastPos := 1; - LastBreak := 0; - I := Pos (' ', Value); - While (I <> 0) do - begin - if (glTextWidth(PChar(Copy (Value,LastBreak + 1,I - LastBreak))) > W) AND (LastPos <> 1) then + //go Through Text + While (GetNextPos) do + begin + //Break in Text + if isBreak then begin - //new Break - SetLength (TextTiles, L+1); - TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); - - Inc(L); - LastBreak := LastPos; - end; - - LastPos := I; - I := PosEx (' ', Value, I+1); - end; + //Look for Break before the Break + if (glTextWidth(PChar(Copy(Value, LastBreak, NextPos - LastBreak + 1))) > W) AND (NextPos-LastPos > 1) 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; - //Last Break - if (glTextWidth(PChar(Copy (Value,LastBreak + 1,Length(Value) - LastBreak))) > W) AND (LastPos <> 1) then + //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 - //new Break - SetLength (TextTiles, L+1); - TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); - - Inc(L); - LastBreak := LastPos; + //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; - - //last Part - SetLength (TextTiles, L+1); - TextTiles[L] := Copy (Value, LastBreak + 1, Length(Value) - LastBreak); - - end - else - begin - SetLength (TextTiles, 1); - TextTiles[0] := Value; + //end; + Inc(FirstWord) end; + //Add Ending + AddBreak(LastBreak, Length(Value)+1); + - I := 0; + {I := 0; // \n Hack While (I <= High(TextTiles)) do begin @@ -135,12 +210,120 @@ begin //Delete Text that now is in new Tile from cur. Tile Delete(TextTiles[I], LastPos, Length(TextTiles[I]) - LastPos + 1); TextTiles[I] := Trim (TextTiles[I]); - + //Goto next Tile because cur. Tile can not have another /n Tag - Inc(I) + Inc(I) end; end; + //Create Page Breaks if width is given and the Text overlapps the width + if (W > 0) then + begin + //Set Font Propertys + SetFontStyle(Style); + SetFontSize(Size); + + {//Create New TextTiles Array + SetLength (TextTiles, 0);}{ + I := 0; + + //Go Through all Tiles + While (I <= High(TextTiles)) do + begin + LastPos := 0; + CurPos := Pos (' ', TextTiles[I]); + + //Go through all Spaces + While (CurPos <> 0) do + begin + //Text is too long for given Width and not the First Word(That means that the Given Word don't Fit the given Width + if (glTextWidth(PChar(Copy (TextTiles[I],1,CurPos-1))) > W) AND (LastPos <> 1) then + begin + //Add a new Tile and move all Tiles behind actual Tile to the right + L := Length(TextTiles); + SetLength(TextTiles, L+1); + For L := L-1 downto I + 1 do + begin + TextTiles[L+1] := TextTiles[L]; + end; + + //Write Text to new Tile + TextTiles[I+1] := Trim(Copy(TextTiles[I], LastPos + 1, Length(TextTiles[I]) - LastPos)); + //Delete Text that now is in new Tile from cur. Tile + Delete(TextTiles[I], LastPos, Length(TextTiles[I]) - LastPos + 1); + TextTiles[I] := Trim (TextTiles[I]); + + //Goto next Tile because cur. Tile can not have another Space + Inc(I) + end; + //Set LastPos and Cur Pos + LastPos := CurPos; + CurPos := PosEx (' ', TextTiles[I], LastPos+1); + end; + + //Look for PageBreak in Last Part of the Tile + CurPos := Length(TextTiles[I]); + if (glTextWidth(PChar(Copy (TextTiles[I],1,CurPos))) > W) AND (LastPos <> 1) then + begin + //Add a new Tile and move all Tiles behind actual Tile to the right + L := Length(TextTiles); + SetLength(TextTiles, L+1); + For L := L-1 downto I + 1 do + begin + TextTiles[L+1] := TextTiles[L]; + end; + + //Write Text to new Tile + TextTiles[I+1] := Trim(Copy(TextTiles[I], LastPos + 1, CurPos - LastPos)); + //Delete Text from cur. Tile that now is in new Tile + Delete(TextTiles[I], LastPos, CurPos - LastPos + 1); + TextTiles[I] := Trim (TextTiles[I]); + //Goto next Tile because cur. Tile can not have another Space + Inc(I) + end; + + //Inc I if Current Tile has no more Spaces + Inc(I) + end; + + I := high(TextTiles); + + {LastPos := 1; + LastBreak := 0; + I := Pos (' ', Value); + While (I <> 0) do + begin + if (glTextWidth(PChar(Copy (Value,LastBreak + 1,I - LastBreak))) > W) AND (LastPos <> 1) then + begin + //new Break + SetLength (TextTiles, L+1); + TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); + + Inc(L); + LastBreak := LastPos; + end; + + LastPos := I; + I := PosEx (' ', Value, I+1); + end; + + //Last Break + if (glTextWidth(PChar(Copy (Value,LastBreak + 1,Length(Value) - LastBreak))) > W) AND (LastPos <> 1) then + begin + //new Break + SetLength (TextTiles, L+1); + TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); + + Inc(L); + LastBreak := LastPos; + end; + + //last Part + SetLength (TextTiles, L+1); + TextTiles[L] := Copy (Value, LastBreak + 1, Length(Value) - LastBreak); + + end; } + //Set Cursor Visible SelectBlink := True; STicks := GettickCount div 550; @@ -201,7 +384,7 @@ begin end else begin //Draw Text as Many Strings - Y2 := Y; + Y2 := Y + MoveY; for I := 0 to high(TextTiles) do begin if (not (SelectBool AND SelectBlink)) OR (I <> high(TextTiles)) then @@ -210,9 +393,9 @@ begin Text2 := TextTiles[I] + '|'; case Align of - 0: X2 := X; - 1: X2 := X - glTextWidth(pchar(Text2))/2; - 2: X2 := X - glTextWidth(pchar(Text2)); + 0: X2 := X + MoveX; + 1: X2 := X + MoveX - glTextWidth(pchar(Text2))/2; + 2: X2 := X + MoveX - glTextWidth(pchar(Text2)); end; SetFontPos(X2, Y2); -- cgit v1.2.3 From 5c8ba0055244ca316dc9957fec02d6f151df0d2e Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Fri, 27 Apr 2007 20:04:56 +0000 Subject: Some Code Cleanup in UMenuText git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@146 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 145 ++----------------------------------------- 1 file changed, 5 insertions(+), 140 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index adf58840..0ebaede2 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -187,143 +187,6 @@ begin //Add Ending AddBreak(LastBreak, Length(Value)+1); - - {I := 0; - // \n Hack - While (I <= High(TextTiles)) do - begin - LastPos := Pos ('\n', TextTiles[I]); - if (LastPos = 0) then //No /n Tags -> Search in next Tile - Inc(I) - else //Found \n Tag -> Create a Break - begin - //Add a new Tile and move all Tiles behind actual Tile to the right - L := Length(TextTiles); - SetLength(TextTiles, L+1); - For L := L-1 downto I + 1 do - begin - TextTiles[L+1] := TextTiles[L]; - end; - - //Write Text to new Tile - TextTiles[I+1] := Trim(Copy(TextTiles[I], LastPos + 2, Length(TextTiles[I]) - LastPos - 1)); - //Delete Text that now is in new Tile from cur. Tile - Delete(TextTiles[I], LastPos, Length(TextTiles[I]) - LastPos + 1); - TextTiles[I] := Trim (TextTiles[I]); - - //Goto next Tile because cur. Tile can not have another /n Tag - Inc(I) - end; - end; - - //Create Page Breaks if width is given and the Text overlapps the width - if (W > 0) then - begin - //Set Font Propertys - SetFontStyle(Style); - SetFontSize(Size); - - {//Create New TextTiles Array - SetLength (TextTiles, 0);}{ - I := 0; - - //Go Through all Tiles - While (I <= High(TextTiles)) do - begin - LastPos := 0; - CurPos := Pos (' ', TextTiles[I]); - - //Go through all Spaces - While (CurPos <> 0) do - begin - //Text is too long for given Width and not the First Word(That means that the Given Word don't Fit the given Width - if (glTextWidth(PChar(Copy (TextTiles[I],1,CurPos-1))) > W) AND (LastPos <> 1) then - begin - //Add a new Tile and move all Tiles behind actual Tile to the right - L := Length(TextTiles); - SetLength(TextTiles, L+1); - For L := L-1 downto I + 1 do - begin - TextTiles[L+1] := TextTiles[L]; - end; - - //Write Text to new Tile - TextTiles[I+1] := Trim(Copy(TextTiles[I], LastPos + 1, Length(TextTiles[I]) - LastPos)); - //Delete Text that now is in new Tile from cur. Tile - Delete(TextTiles[I], LastPos, Length(TextTiles[I]) - LastPos + 1); - TextTiles[I] := Trim (TextTiles[I]); - - //Goto next Tile because cur. Tile can not have another Space - Inc(I) - end; - //Set LastPos and Cur Pos - LastPos := CurPos; - CurPos := PosEx (' ', TextTiles[I], LastPos+1); - end; - - //Look for PageBreak in Last Part of the Tile - CurPos := Length(TextTiles[I]); - if (glTextWidth(PChar(Copy (TextTiles[I],1,CurPos))) > W) AND (LastPos <> 1) then - begin - //Add a new Tile and move all Tiles behind actual Tile to the right - L := Length(TextTiles); - SetLength(TextTiles, L+1); - For L := L-1 downto I + 1 do - begin - TextTiles[L+1] := TextTiles[L]; - end; - - //Write Text to new Tile - TextTiles[I+1] := Trim(Copy(TextTiles[I], LastPos + 1, CurPos - LastPos)); - //Delete Text from cur. Tile that now is in new Tile - Delete(TextTiles[I], LastPos, CurPos - LastPos + 1); - TextTiles[I] := Trim (TextTiles[I]); - //Goto next Tile because cur. Tile can not have another Space - Inc(I) - end; - - //Inc I if Current Tile has no more Spaces - Inc(I) - end; - - I := high(TextTiles); - - {LastPos := 1; - LastBreak := 0; - I := Pos (' ', Value); - While (I <> 0) do - begin - if (glTextWidth(PChar(Copy (Value,LastBreak + 1,I - LastBreak))) > W) AND (LastPos <> 1) then - begin - //new Break - SetLength (TextTiles, L+1); - TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); - - Inc(L); - LastBreak := LastPos; - end; - - LastPos := I; - I := PosEx (' ', Value, I+1); - end; - - //Last Break - if (glTextWidth(PChar(Copy (Value,LastBreak + 1,Length(Value) - LastBreak))) > W) AND (LastPos <> 1) then - begin - //new Break - SetLength (TextTiles, L+1); - TextTiles[L] := Copy (Value, LastBreak + 1, LastPos - LastBreak); - - Inc(L); - LastBreak := LastPos; - end; - - //last Part - SetLength (TextTiles, L+1); - TextTiles[L] := Copy (Value, LastBreak + 1, Length(Value) - LastBreak); - - end; } - //Set Cursor Visible SelectBlink := True; STicks := GettickCount div 550; @@ -365,7 +228,7 @@ begin 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 @@ -383,7 +246,9 @@ begin SetFontStyle(0); // reset to default end else - begin //Draw Text as Many Strings + begin} + //Now Use allways: + //Draw Text as Many Strings Y2 := Y + MoveY; for I := 0 to high(TextTiles) do begin @@ -405,7 +270,7 @@ begin end; SetFontStyle(0); // reset to default - end; + //end; end; end; -- cgit v1.2.3 From 23e4d293dc19ce496da33b3929c9b71952148e86 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sat, 28 Apr 2007 15:25:11 +0000 Subject: Fixed a Bug in UMenuText that causes that Text with only one Char is not displayed git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@148 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 0ebaede2..abf3784c 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -105,7 +105,7 @@ var end; 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); @@ -122,6 +122,18 @@ begin //Set TExtstring TextString := Value; + //Set Cursor Visible + SelectBlink := True; + STicks := GettickCount 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); @@ -133,6 +145,7 @@ begin LastBreak := 1; FirstWord := 1; + if (W > 0) then begin //Set Font Propertys @@ -140,7 +153,6 @@ begin SetFontSize(Size); end; - //go Through Text While (GetNextPos) do begin @@ -186,10 +198,6 @@ begin end; //Add Ending AddBreak(LastBreak, Length(Value)+1); - - //Set Cursor Visible - SelectBlink := True; - STicks := GettickCount div 550; end; Procedure TText.DeleteLastL; -- cgit v1.2.3 From bda4fa8e57ca63a1d591433f120b4226d6a5d327 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 29 Apr 2007 17:50:29 +0000 Subject: Added 2 new Buttons to ScreenMain: Multi and Stats Updated Language Fiels to Fit with new Buttons Some CodeClean Up in Menu Class and in Screens Some minor Bug fixes I forgot about Added ability to group Buttons within a Screen New Theme Object: ButtonCollection: Same Attributes as a Button Plus FirstChild: Defining the First Button in the Group. For Example: SingSolo is 1, SingMulti Button is 2, in ScreenMain Added Attribute to Theme Button: Parent: Number of the assigned Group, 0 for no Group Used new Abilitys in MainScreen git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@149 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index abf3784c..4cb48cad 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -162,6 +162,7 @@ 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 @@ -175,6 +176,7 @@ begin end; end; + isBreak := True; //Add Break from Text AddBreak(LastBreak, NextPos); end -- cgit v1.2.3 From 7ee656d31524f4820b362a31fc6bc1fe0988c0dc Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Mon, 28 May 2007 18:58:08 +0000 Subject: Changed Text Spacing for a better look SelectLoadingAnimation in ScreenAdvanced hidden, because it is useless atm Changed Theme to fit the new Textspacing Fixed some Language entrys git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@232 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 4cb48cad..5b035f51 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -276,7 +276,10 @@ begin SetFontPos(X2, Y2); glPrint(PChar(Text2)); - Y2 := Y2 + Size * 1.7; + {if Size >= 10 then + Y2 := Y2 + Size * 2.8 + else} + Y2 := Y2 + Size * 2.15; end; SetFontStyle(0); // reset to default -- cgit v1.2.3 From 0bb302b56187c6435ae78bee7901765dbf72e89d Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Mon, 28 May 2007 19:58:06 +0000 Subject: New spacing for Font type 1 git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@236 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 5b035f51..69ece02f 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -279,6 +279,9 @@ begin {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 -- cgit v1.2.3 From 5f45fd926da919d8057dfcca4101dc305bd230df Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Thu, 14 Jun 2007 13:08:54 +0000 Subject: Added Text Fading to ButtonCollection git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@262 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 69ece02f..4713962e 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -23,6 +23,7 @@ type ColR: real; ColG: real; ColB: real; + Alpha: real; Int: real; Style: integer; Visible: boolean; @@ -225,7 +226,7 @@ begin SetFontStyle(Style); SetFontSize(Size); SetFontItalic(False); - glColor3f(ColR*Int, ColG*Int, ColB*Int); + glColor4f(ColR*Int, ColG*Int, ColB*Int, Alpha); //If Selected Set Blink... if SelectBool then @@ -303,6 +304,7 @@ end; constructor TText.Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); begin inherited Create; + Alpha := 1; X := ParX; Y := ParY; W := ParW; -- cgit v1.2.3 From 433a1b7339e2bf96f3b0bb4c98b8c799c6540027 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Tue, 18 Sep 2007 13:19:20 +0000 Subject: changes in order to compile in lazarus... minor tidy ups and removal of big old comment blocks.. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@394 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 4713962e..cba237b8 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -1,6 +1,11 @@ unit UMenuText; interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + uses TextGL, UTexture, OpenGL12, SysUtils; type -- cgit v1.2.3 From db82b7e30a1b58b56fdb4bfc6089b47200ca1da1 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 20 Sep 2007 06:36:58 +0000 Subject: Ultrastar-DX now compiles in linux (using lazarus) Bass etc is commented out.. but it compiles, and im working through the runtime errors. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@408 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 668 ++++++++++++++++++++++--------------------- 1 file changed, 339 insertions(+), 329 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index cba237b8..d1c8b7b1 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -1,329 +1,339 @@ -unit UMenuText; - -interface - -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} - -uses TextGL, UTexture, OpenGL12, SysUtils; - -type - TText = class - private - SelectBool: boolean; - TextString: String; - TextTiles: Array of String; - - STicks: Cardinal; - SelectBlink: Boolean; - public - X: real; - Y: 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; // if text is wider than W then it is breaked -// 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 - - 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); overload; - end; - -implementation -uses UGraphic, StrUtils, Windows; - -procedure TText.SetSelect(Value: Boolean); -begin - SelectBool := Value; - - //Set Cursor Visible - SelectBlink := True; - STicks := GettickCount 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 Smallest(const A, B: Cardinal):Cardinal; - begin - if (A < B) then - Result := A - else - Result := B; - end; - - 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 := Smallest(T1, T3{Smallest(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 := GettickCount 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 Propertys - 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); - - //If Selected Set Blink... - if SelectBool then - begin - I := Gettickcount 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); - 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); -end; - -constructor TText.Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); -begin - inherited Create; - Alpha := 1; - X := ParX; - Y := ParY; - W := ParW; - Style := ParStyle; - Size := ParSize; - Text := ParTekst; - ColR := ParColR; - ColG := ParColG; - ColB := ParColB; - Int := 1; - Align := ParAlign; - SelectBool := false; - Visible := true; -end; - - -end. +unit UMenuText; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +uses TextGL, + UTexture, + OpenGL12, + SysUtils; + +type + TText = class + private + SelectBool: boolean; + TextString: String; + TextTiles: Array of String; + + STicks: Cardinal; + SelectBlink: Boolean; + public + X: real; + Y: 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; // if text is wider than W then it is breaked +// 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 + + 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); overload; + end; + +implementation + +uses UGraphic, + {$IFDEF win32} + windows, + {$ELSE} + lclintf, + {$ENDIF} + StrUtils; + +procedure TText.SetSelect(Value: Boolean); +begin + SelectBool := Value; + + //Set Cursor Visible + SelectBlink := True; + STicks := GettickCount 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 Smallest(const A, B: Cardinal):Cardinal; + begin + if (A < B) then + Result := A + else + Result := B; + end; + + 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 := Smallest(T1, T3{Smallest(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 := GettickCount 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 Propertys + 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); + + //If Selected Set Blink... + if SelectBool then + begin + I := Gettickcount 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); + 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); +end; + +constructor TText.Create(ParX, ParY, ParW: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); +begin + inherited Create; + Alpha := 1; + X := ParX; + Y := ParY; + W := ParW; + Style := ParStyle; + Size := ParSize; + Text := ParTekst; + ColR := ParColR; + ColG := ParColG; + ColB := ParColB; + Int := 1; + Align := ParAlign; + SelectBool := false; + Visible := true; +end; + + +end. -- cgit v1.2.3 From 739ad9a6dee57375f05dcd20dc59ba2d619f11fa Mon Sep 17 00:00:00 2001 From: jaybinks Date: Mon, 24 Sep 2007 13:31:43 +0000 Subject: fixed song loading in Lazarus.. cant assume variables are initialized as 0 :) in UFile "Done: byte;" was no initialized on lazarus compiler. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@431 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index d1c8b7b1..19adef03 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -237,10 +237,12 @@ var Text2: string; I: Integer; begin - if Visible then begin + if Visible then + begin SetFontStyle(Style); SetFontSize(Size); SetFontItalic(False); + glColor4f(ColR*Int, ColG*Int, ColB*Int, Alpha); //If Selected Set Blink... -- cgit v1.2.3 From 391d30716d48dc709f6444b19c008e82311623b9 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 1 Nov 2007 19:34:40 +0000 Subject: Mac OS X version compiles and links. I hope I didn't break too many files on windows/linux. Added switches.inc to all files. Changed many IFDEFs. For Windows-only code please use MSWINDOWS instead of WIN32 now. WIN32 is also used by the Mac port. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@546 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 19adef03..350c28de 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -2,9 +2,7 @@ unit UMenuText; interface -{$IFDEF FPC} - {$MODE Delphi} -{$ENDIF} +{$I switches.inc} uses TextGL, UTexture, @@ -61,6 +59,39 @@ uses UGraphic, {$ENDIF} StrUtils; +{$IFDEF DARWIN} +function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer; +var + I,X: Integer; + Len, LenSubStr: Integer; +begin + if Offset = 1 then + Result := Pos(SubStr, S) + else + begin + I := Offset; + LenSubStr := Length(SubStr); + Len := Length(S) - LenSubStr + 1; + while I <= Len do + begin + if S[I] = SubStr[1] then + begin + X := 1; + while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) do + Inc(X); + if (X = LenSubStr) then + begin + Result := I; + exit; + end; + end; + Inc(I); + end; + Result := 0; + end; +end; +{$ENDIF} + procedure TText.SetSelect(Value: Boolean); begin SelectBool := Value; -- cgit v1.2.3 From 99955c78f63d1cb0d8bec666bc33953590a74c8a Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 1 Nov 2007 23:22:01 +0000 Subject: fixed failed builds build:USDX-LAZLIN-75 build:USDX-LAZLIN-76 for some reason we can not use {$MODE Delphi} in an included file. ( Probably because of the way the compier scopes this switch to each pas file ) ive had to revert this part of eddies changes. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@548 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Menu/UMenuText.pas | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Game/Code/Menu/UMenuText.pas') diff --git a/Game/Code/Menu/UMenuText.pas b/Game/Code/Menu/UMenuText.pas index 350c28de..f180a41b 100644 --- a/Game/Code/Menu/UMenuText.pas +++ b/Game/Code/Menu/UMenuText.pas @@ -2,6 +2,10 @@ unit UMenuText; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + {$I switches.inc} uses TextGL, -- cgit v1.2.3