DEADSOFTWARE

render: separate panel logic and drawing
[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,
30 e_graphics,
31 g_basic, g_textures
32 ;
34 // TODO: remove WITH operator
36 procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
37 var xx, yy: Integer; NoTextureID: DWORD; NW, NH: Word;
38 begin
39 with p do
40 begin
41 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
42 begin
43 if TextureIDs[FCurTexture].Anim then
44 begin
45 if TextureIDs[FCurTexture].AnTex = nil then
46 Exit;
47 for xx := 0 to Width div TextureWidth - 1 do
48 for yy := 0 to Height div TextureHeight - 1 do
49 TextureIDs[FCurTexture].AnTex.Draw(X + xx * TextureWidth, Y + yy * TextureHeight, TMirrorType.None);
50 end
51 else
52 begin
53 case TextureIDs[FCurTexture].Tex of
54 LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 0, 0, 255, 0, TBlending.Filter);
55 LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 0, 230, 0, 0, TBlending.Filter);
56 LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 230, 0, 0, 0, TBlending.Filter);
57 LongWord(TEXTURE_NONE):
58 if g_Texture_Get('NOTEXTURE', NoTextureID) then
59 begin
60 e_GetTextureSize(NoTextureID, @NW, @NH);
61 e_DrawFill(NoTextureID, X, Y, Width div NW, Height div NH, 0, False, False);
62 end
63 else
64 begin
65 xx := X + (Width div 2);
66 yy := Y + (Height div 2);
67 e_DrawFillQuad(X, Y, xx, yy, 255, 0, 255, 0);
68 e_DrawFillQuad(xx, Y, X + Width - 1, yy, 255, 255, 0, 0);
69 e_DrawFillQuad(X, yy, xx, Y + Height - 1, 255, 255, 0, 0);
70 e_DrawFillQuad(xx, yy, X + Width - 1, Y + Height - 1, 255, 0, 255, 0);
71 end;
72 else
73 begin
74 if not movingActive then
75 e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending, hasAmbient)
76 else
77 e_DrawFillX(TextureIDs[FCurTexture].Tex, X, Y, Width, Height, Alpha, True, Blending, g_dbg_scale, hasAmbient);
78 if hasAmbient then
79 e_AmbientQuad(X, Y, Width, Height, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
80 end
81 end
82 end
83 end
84 end
85 end;
87 procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
89 procedure extrude (x: Integer; y: Integer);
90 begin
91 glVertex2i(x + (x - lightX) * 500, y + (y - lightY) * 500);
92 //e_WriteLog(Format(' : (%d,%d)', [x + (x - lightX) * 300, y + (y - lightY) * 300]), MSG_WARNING);
93 end;
95 procedure drawLine (x0: Integer; y0: Integer; x1: Integer; y1: Integer);
96 begin
97 // does this side facing the light?
98 if ((x1 - x0) * (lightY - y0) - (lightX - x0) * (y1 - y0) >= 0) then exit;
99 //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
100 // this edge is facing the light, extrude and draw it
101 glVertex2i(x0, y0);
102 glVertex2i(x1, y1);
103 extrude(x1, y1);
104 extrude(x0, y0);
105 end;
107 begin
108 with p do
109 begin
110 if radius < 4 then exit;
111 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
112 begin
113 if not TextureIDs[FCurTexture].Anim then
114 begin
115 case TextureIDs[FCurTexture].Tex of
116 LongWord(TEXTURE_SPECIAL_WATER): exit;
117 LongWord(TEXTURE_SPECIAL_ACID1): exit;
118 LongWord(TEXTURE_SPECIAL_ACID2): exit;
119 LongWord(TEXTURE_NONE): exit;
120 end;
121 end;
122 if (X + Width < lightX - radius) then exit;
123 if (Y + Height < lightY - radius) then exit;
124 if (X > lightX + radius) then exit;
125 if (Y > lightY + radius) then exit;
126 //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending);
127 glBegin(GL_QUADS);
128 drawLine(x, y, x + width, y); // top
129 drawLine(x + width, y, x + width, y + height); // right
130 drawLine(x + width, y + height, x, y + height); // bottom
131 drawLine(x, y + height, x, y); // left
132 glEnd;
133 end
134 end
135 end;
137 end.