DEADSOFTWARE

4cd4f3851360aabde5f7b2dcaca416bd1171df86
[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_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: DWORD; NW, NH: Word;
56 begin
57 with p do
58 begin
59 if {Enabled and} (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
60 begin
61 Panel_Lerp(p, gLerpFactor, tx, ty, tw, th);
62 if TextureIDs[FCurTexture].Anim then
63 begin
64 if TextureIDs[FCurTexture].AnTex = nil then
65 Exit;
66 for xx := 0 to tw div TextureWidth - 1 do
67 for yy := 0 to th div TextureHeight - 1 do
68 r_Animation_Draw(TextureIDs[FCurTexture].AnTex, tx + xx * TextureWidth, ty + yy * TextureHeight, TMirrorType.None);
69 end
70 else
71 begin
72 case TextureIDs[FCurTexture].Tex of
73 LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 0, 255, 0, TBlending.Filter);
74 LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 230, 0, 0, TBlending.Filter);
75 LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 230, 0, 0, 0, TBlending.Filter);
76 LongWord(TEXTURE_NONE):
77 if g_Texture_Get('NOTEXTURE', NoTextureID) then
78 begin
79 e_GetTextureSize(NoTextureID, @NW, @NH);
80 e_DrawFill(NoTextureID, tx, ty, tw div NW, th div NH, 0, False, False);
81 end
82 else
83 begin
84 xx := tx + (tw div 2);
85 yy := ty + (th div 2);
86 e_DrawFillQuad(tx, ty, xx, yy, 255, 0, 255, 0);
87 e_DrawFillQuad(xx, ty, tx + tw - 1, yy, 255, 255, 0, 0);
88 e_DrawFillQuad(X, yy, xx, ty + th - 1, 255, 255, 0, 0);
89 e_DrawFillQuad(xx, yy, tx + tw - 1, ty + th - 1, 255, 0, 255, 0);
90 end;
91 else
92 begin
93 if not movingActive then
94 e_DrawFill(TextureIDs[FCurTexture].Tex, tx, ty, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending, hasAmbient)
95 else
96 e_DrawFillX(TextureIDs[FCurTexture].Tex, tx, ty, tw, th, Alpha, True, Blending, g_dbg_scale, hasAmbient);
97 if hasAmbient then
98 e_AmbientQuad(tx, ty, tw, th, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
99 end
100 end
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;
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 with p do
129 begin
130 if radius < 4 then exit;
131 if Enabled and (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (Alpha < 255) {and g_Collide(X, Y, tw, th, sX, sY, sWidth, sHeight)} then
132 begin
133 Panel_Lerp(p, gLerpFactor, tx, ty, tw, th);
134 if not TextureIDs[FCurTexture].Anim then
135 begin
136 case TextureIDs[FCurTexture].Tex of
137 LongWord(TEXTURE_SPECIAL_WATER): exit;
138 LongWord(TEXTURE_SPECIAL_ACID1): exit;
139 LongWord(TEXTURE_SPECIAL_ACID2): exit;
140 LongWord(TEXTURE_NONE): exit;
141 end;
142 end;
143 if (tx + tw < lightX - radius) then exit;
144 if (ty + th < lightY - radius) then exit;
145 if (tx > lightX + radius) then exit;
146 if (ty > lightY + radius) then exit;
147 //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending);
148 glBegin(GL_QUADS);
149 drawLine(tx, ty, tx + tw, ty); // top
150 drawLine(tx + tw, ty, tx + tw, ty + th); // right
151 drawLine(tx + tw, ty + th, tx, ty + th); // bottom
152 drawLine(tx, ty + th, tx, ty); // left
153 glEnd;
154 end
155 end
156 end;
158 end.