DEADSOFTWARE

539c9a74ea26d803730cec010f07ac4528c08148
[d2df-sdl.git] / src / game / opengl / r_panel.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../shared/a_modes.inc}
16 unit r_panel;
18 interface
20 uses g_panel, MAPDEF; // TPanel + TDFColor
22 procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
23 procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
25 implementation
27 uses
28 {$INCLUDE ../nogl/noGLuses.inc}
29 SysUtils, Classes, Math, utils,
30 r_graphics, g_options, r_animations, r_textures,
31 g_base, g_basic, g_map, g_game
32 ;
34 procedure Panel_Lerp (p: TPanel; t: Single; out tX, tY, tW, tH: Integer);
35 begin
36 if p.movingActive then
37 begin
38 tX := nlerp(p.OldX, p.X, t);
39 tY := nlerp(p.OldY, p.Y, t);
40 tW := nlerp(p.OldWidth, p.Width, t);
41 tH := nlerp(p.OldHeight, p.Height, t);
42 end
43 else
44 begin
45 tX := p.X;
46 tY := p.Y;
47 tW := p.Width;
48 tH := p.Height;
49 end;
50 end;
52 // TODO: remove WITH operator
54 procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
55 var tx, ty, tw, th, xx, yy: Integer; NoTextureID, TextureID, FramesID: DWORD; NW, NH: Word; Texture: Cardinal; IsAnim: Boolean;
56 begin
57 if {p.Enabled and} (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
58 begin
59 Panel_Lerp(p, gLerpFactor, tx, ty, tw, th);
60 Texture := p.TextureIDs[p.FCurTexture].Texture;
61 IsAnim := p.TextureIDs[p.FCurTexture].Anim;
62 if IsAnim then
63 begin
64 if p.TextureIDs[p.FCurTexture].AnTex <> nil then
65 begin
66 FramesID := Textures[Texture].FramesID;
67 for xx := 0 to tw div p.TextureWidth - 1 do
68 for yy := 0 to th div p.TextureHeight - 1 do
69 r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, tx + xx * p.TextureWidth, ty + yy * p.TextureHeight, TMirrorType.None);
70 end
71 end
72 else
73 begin
74 TextureID := Textures[Texture].TextureID; // GL texture
75 case TextureID of
76 LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 0, 255, 0, TBlending.Filter);
77 LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 230, 0, 0, TBlending.Filter);
78 LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 230, 0, 0, 0, TBlending.Filter);
79 LongWord(TEXTURE_NONE):
80 if g_Texture_Get('NOTEXTURE', NoTextureID) then
81 begin
82 e_GetTextureSize(NoTextureID, @NW, @NH);
83 e_DrawFill(NoTextureID, tx, ty, tw div NW, th div NH, 0, False, False);
84 end
85 else
86 begin
87 xx := tx + (tw div 2);
88 yy := ty + (th div 2);
89 e_DrawFillQuad(tx, ty, xx, yy, 255, 0, 255, 0);
90 e_DrawFillQuad(xx, ty, tx + tw - 1, yy, 255, 255, 0, 0);
91 e_DrawFillQuad(tx, yy, xx, ty + th - 1, 255, 255, 0, 0);
92 e_DrawFillQuad(xx, yy, tx + tw - 1, ty + th - 1, 255, 0, 255, 0);
93 end;
94 else
95 if not p.movingActive then
96 e_DrawFill(TextureID, tx, ty, tw div p.TextureWidth, th div p.TextureHeight, p.Alpha, True, p.Blending, hasAmbient)
97 else
98 e_DrawFillX(TextureID, tx, ty, tw, th, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient);
99 if hasAmbient then
100 e_AmbientQuad(tx, ty, tw, th, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
101 end
102 end
103 end
104 end;
106 procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
107 var tx, ty, tw, th: Integer; Texture: Cardinal;
109 procedure extrude (x: Integer; y: Integer);
110 begin
111 glVertex2i(x + (x - lightX) * 500, y + (y - lightY) * 500);
112 //e_WriteLog(Format(' : (%d,%d)', [x + (x - lightX) * 300, y + (y - lightY) * 300]), MSG_WARNING);
113 end;
115 procedure drawLine (x0: Integer; y0: Integer; x1: Integer; y1: Integer);
116 begin
117 // does this side facing the light?
118 if ((x1 - x0) * (lightY - y0) - (lightX - x0) * (y1 - y0) >= 0) then exit;
119 //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
120 // this edge is facing the light, extrude and draw it
121 glVertex2i(x0, y0);
122 glVertex2i(x1, y1);
123 extrude(x1, y1);
124 extrude(x0, y0);
125 end;
127 begin
128 if radius < 4 then exit;
129 if p.Enabled and (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, tw, th, sX, sY, sWidth, sHeight)} then
130 begin
131 Panel_Lerp(p, gLerpFactor, tx, ty, tw, th);
132 if not p.TextureIDs[p.FCurTexture].Anim then
133 begin
134 Texture := p.TextureIDs[p.FCurTexture].Texture;
135 case Textures[Texture].TextureID of
136 LongWord(TEXTURE_SPECIAL_WATER): exit;
137 LongWord(TEXTURE_SPECIAL_ACID1): exit;
138 LongWord(TEXTURE_SPECIAL_ACID2): exit;
139 LongWord(TEXTURE_NONE): exit;
140 end;
141 end;
142 if (tx + tw < lightX - radius) then exit;
143 if (ty + th < lightY - radius) then exit;
144 if (tx > lightX + radius) then exit;
145 if (ty > lightY + radius) then exit;
146 //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending);
147 glBegin(GL_QUADS);
148 drawLine(tx, ty, tx + tw, ty); // top
149 drawLine(tx + tw, ty, tx + tw, ty + th); // right
150 drawLine(tx + tw, ty + th, tx, ty + th); // bottom
151 drawLine(tx, ty + th, tx, ty); // left
152 glEnd;
153 end
154 end;
156 end.