From 1ed2c76ecb3f7351b9194356623bbad2f1313aa8 Mon Sep 17 00:00:00 2001 From: s_alexander Date: Mon, 29 Jun 2009 01:02:40 +0000 Subject: merged svn trunk r1837 into cmake branche git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1838 b956fd51-792f-4845-bead-9b4dfca2ff2c --- cmake/src/menu/UMenuSelectSlide.pas | 192 ++++++++++++++++++++---------------- 1 file changed, 106 insertions(+), 86 deletions(-) (limited to 'cmake/src/menu/UMenuSelectSlide.pas') diff --git a/cmake/src/menu/UMenuSelectSlide.pas b/cmake/src/menu/UMenuSelectSlide.pas index a7133492..f9f6bbae 100644 --- a/cmake/src/menu/UMenuSelectSlide.pas +++ b/cmake/src/menu/UMenuSelectSlide.pas @@ -34,10 +34,10 @@ interface {$I switches.inc} uses - TextGL, - UTexture, gl, - UMenuText; + TextGL, + UMenuText, + UTexture; type PSelectSlide = ^TSelectSlide; @@ -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; @@ -132,11 +138,12 @@ type end; implementation + uses - UDrawTexture, math, - ULog, - SysUtils; + SysUtils, + UDrawTexture, + ULog; // ------------ Select constructor TSelectSlide.Create; @@ -145,15 +152,7 @@ begin 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); @@ -178,14 +177,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 @@ -203,13 +194,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; @@ -219,98 +203,112 @@ var HalfL: integer; HalfR: integer; -procedure DoSelection(Sel: cardinal); + procedure DoSelection(Sel: cardinal); 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; TextOpt[I].ColB := STDColB; 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; 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 + if (Length(TextOpt) > 0) and (Length(TextOptT) > 0) then begin + //First option selected if (Value <= 0) then - begin //First Option Selected + begin Value := 0; - for SO := low (TextOpt) to high(TextOpt) do + Tex_SelectS_ArrowL.alpha := 0; + Tex_SelectS_ArrowR.alpha := 1; + + 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 + //Last option selected + else if (Value >= High(TextOptT)) then + begin + Value := High(TextOptT); + + Tex_SelectS_ArrowL.alpha := 1; + Tex_SelectS_ArrowR.alpha := 0; + + 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 else begin - HalfL := Ceil((Lines-1)/2); - HalfR := Lines-1-HalfL; + Tex_SelectS_ArrowL.alpha := 1; + Tex_SelectS_ArrowR.alpha := 1; + 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 - 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); + + //Selected option is near to the right side + else if (Value > High(TextOptT) - HalfR) then + begin + HalfR := High(TextOptT) - Value; + HalfL := Lines - 1 - HalfR; + //Change texts + for SO := High(TextOpt) downto Low(TextOpt) do + begin + TextOpt[SO].Text := TextOptT[High(TextOptT) - (Lines - SO - 1)]; + end; + + DoSelection (HalfL); end + else begin - //Change Texts - for SO := low (TextOpt) to high(TextOpt) do - begin + //Change Texts + for SO := Low(TextOpt) to High(TextOpt) do + begin TextOpt[SO].Text := TextOptT[Value - HalfL + SO]; - end; + end; - DoSelection(HalfL); + DoSelection(HalfL); end; - end; - end; - end; procedure TSelectSlide.Draw; @@ -322,9 +320,15 @@ 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 + for SO := Low(TextOpt) to High(TextOpt) do TextOpt[SO].Draw; end; end; @@ -338,26 +342,36 @@ 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; - 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 + 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; @@ -372,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; @@ -380,8 +394,14 @@ 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 + begin + TextOpt[I].Align := 1; //center text + TextOpt[I].X := TextureSBG.X + (TextureSBG.W / 2); + end; end; end; -- cgit v1.2.3