author | unc0rr |
Sat, 24 May 2008 17:34:06 +0000 | |
changeset 945 | 4ead9cde4e14 |
parent 942 | b41af014d85e |
child 946 | 42c5cc87cbd1 |
permissions | -rw-r--r-- |
942 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
19 |
unit uChat; |
|
20 |
||
21 |
interface |
|
22 |
||
23 |
procedure AddChatString(s: shortstring); |
|
24 |
procedure DrawChat; |
|
25 |
||
26 |
implementation |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
27 |
uses uMisc, uStore, uConsts, SDLh; |
942 | 28 |
|
29 |
const MaxStrIndex = 7; |
|
30 |
||
31 |
type TStr = record |
|
32 |
Time: Longword; |
|
33 |
Tex: PTexture; |
|
34 |
end; |
|
35 |
||
36 |
var Strs: array[0 .. MaxStrIndex] of TStr; |
|
37 |
lastStr: Longword = 0; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
38 |
visibleCount: Longword = 0; |
942 | 39 |
|
40 |
procedure AddChatString(s: shortstring); |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
41 |
var strSurface, resSurface: PSDL_Surface; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
42 |
r: TSDL_Rect; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
43 |
w, h: LongInt; |
942 | 44 |
begin |
45 |
lastStr:= (lastStr + 1) mod (MaxStrIndex + 1); |
|
46 |
||
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
47 |
TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(s), w, h); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
48 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
49 |
resSurface:= SDL_CreateRGBSurface(0, |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
50 |
toPowerOf2(w + 2), |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
51 |
toPowerOf2(h + 2), |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
52 |
32, |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
53 |
RMask, GMask, BMask, AMask); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
54 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
55 |
strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $202020); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
56 |
r.x:= 1; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
57 |
r.y:= 1; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
58 |
SDL_UpperBlit(strSurface, nil, resSurface, @r); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
59 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
60 |
strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
61 |
SDL_UpperBlit(strSurface, nil, resSurface, nil); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
62 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
63 |
SDL_FreeSurface(strSurface); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
64 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
65 |
|
942 | 66 |
Strs[lastStr].Time:= RealTicks + 7500; |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
67 |
Strs[lastStr].Tex:= Surface2Tex(resSurface); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
68 |
SDL_FreeSurface(resSurface); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
69 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
70 |
inc(visibleCount) |
942 | 71 |
end; |
72 |
||
73 |
procedure DrawChat; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
74 |
var i, t, cnt: Longword; |
942 | 75 |
begin |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
76 |
cnt:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
77 |
t:= 0; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
78 |
i:= lastStr; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
79 |
while (t <= MaxStrIndex) |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
80 |
and (Strs[i].Tex <> nil) |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
81 |
and (Strs[i].Time > RealTicks) do |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
82 |
begin |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
83 |
DrawTexture(8, (visibleCount - t) * 16 - 8, Strs[i].Tex); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
84 |
if i = 0 then i:= MaxStrIndex else dec(i); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
85 |
inc(cnt); |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
86 |
inc(t) |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
87 |
end; |
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
88 |
|
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
942
diff
changeset
|
89 |
visibleCount:= cnt |
942 | 90 |
end; |
91 |
||
92 |
end. |