aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
authorb1indy <b1indy@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-09-02 23:45:33 +0000
committerb1indy <b1indy@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-09-02 23:45:33 +0000
commitd5ebad3a661194459da1b134978ed353e46c9b72 (patch)
tree05d2c42c7b7bcd6f77a81a1a392be048bbafcaad /Game/Code
parentacc0eaf235f55cf2d75692395fe65b928c43d3fa (diff)
downloadusdx-d5ebad3a661194459da1b134978ed353e46c9b72.tar.gz
usdx-d5ebad3a661194459da1b134978ed353e46c9b72.tar.xz
usdx-d5ebad3a661194459da1b134978ed353e46c9b72.zip
now buttons can also have transparent colorized textures
POC-Pic: http://imageshock.eu/img/colorizedbuttons-ao81.jpg git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@365 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Game/Code/Classes/UTexture.pas4
-rw-r--r--Game/Code/Menu/UMenu.pas83
-rw-r--r--Game/Code/Menu/UMenuButton.pas88
3 files changed, 149 insertions, 26 deletions
diff --git a/Game/Code/Classes/UTexture.pas b/Game/Code/Classes/UTexture.pas
index 3314f494..ab21d44c 100644
--- a/Game/Code/Classes/UTexture.pas
+++ b/Game/Code/Classes/UTexture.pas
@@ -38,10 +38,6 @@ type
TexY2: real;
Alpha: real;
Name: string; // 0.5.0: experimental for handling cache images. maybe it's useful for dynamic skins
- // colorize hack
- Colorized: Boolean;
-// Colors: array of Cardinal;
-// Texnums: array of Integer;
end;
TTextureEntry = record
diff --git a/Game/Code/Menu/UMenu.pas b/Game/Code/Menu/UMenu.pas
index 24af3e1d..0fb1614f 100644
--- a/Game/Code/Menu/UMenu.pas
+++ b/Game/Code/Menu/UMenu.pas
@@ -309,10 +309,28 @@ end;
procedure TMenu.AddButtonCollection(const ThemeCollection: TThemeButtonCollection; Const Num: Byte);
var
BT, BTLen: Integer;
+ TempR, TempG, TempB, TempR2, TempG2, TempB2: Cardinal;
+
begin
if (Num > High(ButtonCollection)) then
exit;
+// colorize hack
+if ThemeCollection.Style.Typ='Colorized' then
+begin
+ TempR:=floor(255*ThemeCollection.Style.ColR);
+ TempG:=floor(255*ThemeCollection.Style.ColG);
+ TempB:=floor(255*ThemeCollection.Style.ColB);
+ TempR2:=floor(255*ThemeCollection.Style.DColR);
+ TempG2:=floor(255*ThemeCollection.Style.DColG);
+ TempB2:=floor(255*ThemeCollection.Style.DColB);
+ // give encoded color to loadtexture
+ ButtonCollection[Num] := TButtonCollection.Create(Texture.LoadTexture(PChar(Skin.GetTextureFileName(ThemeCollection.Style.Tex)), 'JPG', 'Colorized', ((((TempR shl 8) or TempG) shl 8)or TempB)),
+ Texture.LoadTexture(PChar(Skin.GetTextureFileName(ThemeCollection.Style.Tex)), 'JPG', 'Colorized', ((((TempR2 shl 8) or TempG2) shl 8)or TempB2)));
+
+// Button[Result] := TButton.Create(Texture.LoadTexture(PChar(Name), PChar(Format), PChar(Typ), ((((TempR2 shl 8) or TempG2) shl 8)or TempB2))); // use cache texture
+end
+else
ButtonCollection[Num] := TButtonCollection.Create(Texture.GetTexture(Skin.GetTextureFileName(ThemeCollection.Style.Tex), ThemeCollection.Style.Typ, true)); // use cache texture
//Set Parent menu
@@ -328,13 +346,15 @@ begin
ButtonCollection[Num].Y := ThemeCollection.Style.Y;
ButtonCollection[Num].W := ThemeCollection.Style.W;
ButtonCollection[Num].H := ThemeCollection.Style.H;
- ButtonCollection[Num].SelectColR := ThemeCollection.Style.ColR;
- ButtonCollection[Num].SelectColG := ThemeCollection.Style.ColG;
- ButtonCollection[Num].SelectColB := ThemeCollection.Style.ColB;
+ if ThemeCollection.Style.Typ <> '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].DeselectColR := ThemeCollection.Style.DColR;
- ButtonCollection[Num].DeselectColG := ThemeCollection.Style.DColG;
- ButtonCollection[Num].DeselectColB := ThemeCollection.Style.DColB;
ButtonCollection[Num].DeselectInt := ThemeCollection.Style.DInt;
ButtonCollection[Num].Texture.TexX1 := 0;
ButtonCollection[Num].Texture.TexY1 := 0;
@@ -354,13 +374,16 @@ begin
ButtonCollection[Num].Fade := ThemeCollection.Style.Fade;
ButtonCollection[Num].FadeText := ThemeCollection.Style.FadeText;
- ButtonCollection[Num].FadeTex := Texture.GetTexture(Skin.GetTextureFileName(ThemeCollection.Style.FadeTex), ThemeCollection.Style.Typ, true);
+ if ThemeCollection.Style.Typ='Colorized' then
+ ButtonCollection[Num].FadeTex := Texture.LoadTexture(PChar(Skin.GetTextureFileName(ThemeCollection.Style.FadeTex)), 'JPG', 'Colorized', ((((TempR shl 8) or TempG) shl 8)or TempB))
+ else
+ ButtonCollection[Num].FadeTex := Texture.GetTexture(Skin.GetTextureFileName(ThemeCollection.Style.FadeTex), ThemeCollection.Style.Typ, true);
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,
+ 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);
@@ -532,6 +555,7 @@ var
BT: integer;
BTLen: integer;
temp: integer;
+ TempR, TempG, TempB, TempR2, TempG2, TempB2: Cardinal;
begin
{ Result := AddButton(ThemeButton.X, ThemeButton.Y, ThemeButton.W, ThemeButton.H,
ThemeButton.ColR, ThemeButton.ColG, ThemeButton.ColB, ThemeButton.Int,
@@ -554,7 +578,14 @@ begin
Button[Result].Fade := ThemeButton.Fade;
Button[Result].FadeText := ThemeButton.FadeText;
- Button[Result].FadeTex := Texture.GetTexture(Skin.GetTextureFileName(ThemeButton.FadeTex), ThemeButton.Typ, true);
+ if ThemeButton.Typ='Colorized' then begin
+ TempR:=floor(255*ThemeButton.ColR);
+ TempG:=floor(255*ThemeButton.ColG);
+ TempB:=floor(255*ThemeButton.ColB);
+ Button[Result].FadeTex := Texture.LoadTexture(PChar(Skin.GetTextureFileName(ThemeButton.FadeTex)), 'JPG', 'Colorized', ((((TempR shl 8) or TempG) shl 8)or TempB));
+ end
+ else
+ Button[Result].FadeTex := Texture.GetTexture(Skin.GetTextureFileName(ThemeButton.FadeTex), ThemeButton.Typ, true);
Button[Result].FadeTexPos := ThemeButton.FadeTexPos;
@@ -596,6 +627,7 @@ begin
end;
function TMenu.AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; Name, Format, Typ: String; Reflection: Boolean; ReflectionSpacing, DeSelectReflectionSpacing: Real): integer;
+var TempR, TempG, TempB, TempR2, TempG2, TempB2: Cardinal;
begin
// adds button
//SetLength is used once to reduce Memory usement
@@ -604,7 +636,7 @@ begin
Result := ButtonPos;
Inc(ButtonPos)
end
- else //Old Method -> Reserve new Memory for every Button
+ else //Old Method -> Reserve new Memory for every Button
begin
Result := Length(Button);
SetLength(Button, Result + 1);
@@ -614,6 +646,23 @@ begin
// check here for cache
// Texture.GetTexture(Name, Typ, false); // preloads textures and creates cahce mipmap when needed
// if Covers.CoverExists(Name) then
+// colorize hack
+if Typ='Colorized' then
+begin
+ TempR:=floor(255*ColR);
+ TempG:=floor(255*ColG);
+ TempB:=floor(255*ColB);
+ TempR2:=floor(255*DColR);
+ TempG2:=floor(255*DColG);
+ TempB2:=floor(255*DColB);
+ // give encoded color to loadtexture
+ Button[Result] := TButton.Create(Texture.LoadTexture(PChar(Name), PChar(Format), PChar(Typ), ((((TempR shl 8) or TempG) shl 8)or TempB)),
+ Texture.LoadTexture(PChar(Name), PChar(Format), PChar(Typ), ((((TempR2 shl 8) or TempG2) shl 8)or TempB2)));
+
+// Button[Result] := TButton.Create(Texture.LoadTexture(PChar(Name), PChar(Format), PChar(Typ), ((((TempR2 shl 8) or TempG2) shl 8)or TempB2))); // use cache texture
+end
+else
+
Button[Result] := TButton.Create(Texture.GetTexture(Name, Typ, true)); // use cache texture
// else
// Button[Result] := TButton.Create(Texture.GetTexture(Name, Typ, false)); // don't use cache texture}
@@ -623,13 +672,15 @@ begin
Button[Result].Y := Y;
Button[Result].W := W;
Button[Result].H := H;
- Button[Result].SelectColR := ColR;
- Button[Result].SelectColG := ColG;
- Button[Result].SelectColB := ColB;
+ if Typ <> '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].DeselectColR := DColR;
- Button[Result].DeselectColG := DColG;
- Button[Result].DeselectColB := DColB;
Button[Result].DeselectInt := DInt;
Button[Result].Texture.TexX1 := 0;
Button[Result].Texture.TexY1 := 0;
diff --git a/Game/Code/Menu/UMenuButton.pas b/Game/Code/Menu/UMenuButton.pas
index 919a18c9..51c746fe 100644
--- a/Game/Code/Menu/UMenuButton.pas
+++ b/Game/Code/Menu/UMenuButton.pas
@@ -11,18 +11,21 @@ type
FadeProgress: Real;
FadeLastTick: Cardinal;
-
+
DeSelectW: Real;
DeSelectH: Real;
PosX: Real;
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 hack
+ 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)
@@ -76,6 +79,7 @@ type
procedure Draw; virtual;
constructor Create(Textura: TTexture); overload;
+ constructor Create(Textura, DSTexture: TTexture); overload;
destructor Destroy; override;
end;
@@ -110,7 +114,7 @@ begin
for T := 0 to High(Text) do
Text[T].Y := Text[T].Y + dY;}
-
+
PosY := Value;
if (FadeTex.TexNum = -1) then
Texture.y := Value;
@@ -149,7 +153,7 @@ begin
end;
procedure TButton.SetSelect(Value : Boolean);
-var
+var
T: integer;
begin
SelectBool := Value;
@@ -217,6 +221,9 @@ begin
//Reflection Mod
Reflection := true;
+ //colorized hack
+ Colorized:=False;
+
// Default
// SelectInt := 1;
// DeselectInt := 0.5;
@@ -297,11 +304,15 @@ begin
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;
@@ -322,6 +333,8 @@ 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;
@@ -336,6 +349,8 @@ 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;
@@ -350,6 +365,8 @@ 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;;
@@ -364,6 +381,8 @@ 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;
@@ -382,7 +401,10 @@ begin
Text[T].MoveY := (SelectH - DeSelectH);
end;
- DrawTexture(Texture);
+ if SelectBool or not Colorized then
+ DrawTexture(Texture)
+ else
+ DrawTexture(DeselectTexture);
//Draw FadeTex
if (FadeTex.TexNum <> -1) then
@@ -419,6 +441,7 @@ begin
else
Spacing := DeSelectReflectionspacing;
+ if SelectBool or not Colorized then
with Texture do
begin
//Bind Tex and GL Attributes
@@ -456,7 +479,47 @@ begin
glEnd;
glDisable(GL_TEXTURE_2D);
- glDisable(GL_DEPTH_TEST);
+ 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;
@@ -478,11 +541,24 @@ 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;
+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.