DEADSOFTWARE

de73d72de726c4ebabb72aafbb6572618e5255f6
[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 r_graphics, g_options, r_animations, r_textures,
31 g_base, g_basic, g_map
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, TextureID, FramesID: DWORD; NW, NH: Word; Texture: Cardinal; IsAnim: Boolean;
38 begin
39 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
40 begin
41 Texture := p.TextureIDs[p.FCurTexture].Texture;
42 IsAnim := p.TextureIDs[p.FCurTexture].Anim;
43 if IsAnim then
44 begin
45 if p.TextureIDs[p.FCurTexture].AnTex <> nil then
46 begin
47 FramesID := Textures[Texture].FramesID;
48 for xx := 0 to p.Width div p.TextureWidth - 1 do
49 for yy := 0 to p.Height div p.TextureHeight - 1 do
50 r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, p.X + xx * p.TextureWidth, p.Y + yy * p.TextureHeight, TMirrorType.None);
51 end
52 end
53 else
54 begin
55 TextureID := Textures[Texture].TextureID; // GL texture
56 case TextureID of
57 LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 0, 255, 0, TBlending.Filter);
58 LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 230, 0, 0, TBlending.Filter);
59 LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 230, 0, 0, 0, TBlending.Filter);
60 LongWord(TEXTURE_NONE):
61 if g_Texture_Get('NOTEXTURE', NoTextureID) then
62 begin
63 e_GetTextureSize(NoTextureID, @NW, @NH);
64 e_DrawFill(NoTextureID, p.X, p.Y, p.Width div NW, p.Height div NH, 0, False, False);
65 end
66 else
67 begin
68 xx := p.X + (p.Width div 2);
69 yy := p.Y + (p.Height div 2);
70 e_DrawFillQuad(p.X, p.Y, xx, yy, 255, 0, 255, 0);
71 e_DrawFillQuad(xx, p.Y, p.X + p.Width - 1, yy, 255, 255, 0, 0);
72 e_DrawFillQuad(p.X, yy, xx, p.Y + p.Height - 1, 255, 255, 0, 0);
73 e_DrawFillQuad(xx, yy, p.X + p.Width - 1, p.Y + p.Height - 1, 255, 0, 255, 0);
74 end;
75 else
76 if not p.movingActive then
77 e_DrawFill(TextureID, p.X, p.Y, p.Width div p.TextureWidth, p.Height div p.TextureHeight, p.Alpha, True, p.Blending, hasAmbient)
78 else
79 e_DrawFillX(TextureID, p.X, p.Y, p.Width, p.Height, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient);
80 if hasAmbient then
81 e_AmbientQuad(p.X, p.Y, p.Width, p.Height, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
82 end
83 end
84 end
85 end;
87 procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
88 var Texture: Cardinal;
90 procedure extrude (x: Integer; y: Integer);
91 begin
92 glVertex2i(x + (x - lightX) * 500, y + (y - lightY) * 500);
93 //e_WriteLog(Format(' : (%d,%d)', [x + (x - lightX) * 300, y + (y - lightY) * 300]), MSG_WARNING);
94 end;
96 procedure drawLine (x0: Integer; y0: Integer; x1: Integer; y1: Integer);
97 begin
98 // does this side facing the light?
99 if ((x1 - x0) * (lightY - y0) - (lightX - x0) * (y1 - y0) >= 0) then exit;
100 //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
101 // this edge is facing the light, extrude and draw it
102 glVertex2i(x0, y0);
103 glVertex2i(x1, y1);
104 extrude(x1, y1);
105 extrude(x0, y0);
106 end;
108 begin
109 if radius < 4 then exit;
110 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
111 begin
112 if not p.TextureIDs[p.FCurTexture].Anim then
113 begin
114 Texture := p.TextureIDs[p.FCurTexture].Texture;
115 case Textures[Texture].TextureID 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 (p.X + p.Width < lightX - radius) then exit;
123 if (p.Y + p.Height < lightY - radius) then exit;
124 if (p.X > lightX + radius) then exit;
125 if (p.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(p.x, p.y, p.x + p.width, p.y); // top
129 drawLine(p.x + p.width, p.y, p.x + p.width, p.y + p.height); // right
130 drawLine(p.x + p.width, p.y + p.height, p.x, p.y + p.height); // bottom
131 drawLine(p.x, p.y + p.height, p.x, p.y); // left
132 glEnd;
133 end
134 end;
136 end.