aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Menu/UMenuText.pas
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-03-29 16:54:52 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-03-29 16:54:52 +0000
commite0e16a3b1d28cf51fecf669d42465cf2a65728f3 (patch)
treead80058b83e11b1bf42210d8e49922b44745ca98 /Game/Code/Menu/UMenuText.pas
parent8d591b8344e0cb87e1a987961b3790fa26d323a6 (diff)
downloadusdx-e0e16a3b1d28cf51fecf669d42465cf2a65728f3.tar.gz
usdx-e0e16a3b1d28cf51fecf669d42465cf2a65728f3.tar.xz
usdx-e0e16a3b1d28cf51fecf669d42465cf2a65728f3.zip
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
Diffstat (limited to '')
-rw-r--r--Game/Code/Menu/UMenuText.pas141
1 files changed, 123 insertions, 18 deletions
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;