1 |
elmex |
1.6 |
package Crossfire::Client::Widget; |
2 |
root |
1.8 |
|
3 |
elmex |
1.1 |
use strict; |
4 |
elmex |
1.11 |
use SDL::OpenGL; |
5 |
|
|
use SDL::OpenGL::Constants; |
6 |
elmex |
1.1 |
|
7 |
|
|
our $FOCUS; # the widget with current focus |
8 |
elmex |
1.13 |
our @ACTIVE_WIDGETS; |
9 |
elmex |
1.1 |
|
10 |
|
|
# class methods for events |
11 |
|
|
sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
12 |
|
|
sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
13 |
|
|
sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } |
14 |
|
|
sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } |
15 |
|
|
|
16 |
|
|
sub new { |
17 |
|
|
my $class = shift; |
18 |
root |
1.10 |
|
19 |
|
|
bless { @_ }, $class |
20 |
elmex |
1.1 |
} |
21 |
|
|
|
22 |
elmex |
1.2 |
sub activate { |
23 |
elmex |
1.13 |
push @ACTIVE_WIDGETS, $_[0]; |
24 |
elmex |
1.2 |
} |
25 |
root |
1.4 |
|
26 |
elmex |
1.2 |
sub deactivate { |
27 |
elmex |
1.13 |
@ACTIVE_WIDGETS = |
28 |
|
|
sort { $a->{z} <=> $b->{z} } |
29 |
|
|
grep { $_ != $_[0] } |
30 |
|
|
@ACTIVE_WIDGETS; |
31 |
elmex |
1.2 |
} |
32 |
|
|
|
33 |
root |
1.14 |
sub size_request { |
34 |
|
|
die "size_request is abtract"; |
35 |
|
|
} |
36 |
|
|
|
37 |
elmex |
1.1 |
sub focus_in { |
38 |
|
|
my ($widget) = @_; |
39 |
|
|
$FOCUS = $widget; |
40 |
|
|
} |
41 |
root |
1.4 |
|
42 |
elmex |
1.1 |
sub focus_out { |
43 |
|
|
my ($widget) = @_; |
44 |
|
|
} |
45 |
root |
1.4 |
|
46 |
elmex |
1.1 |
sub key_down { |
47 |
|
|
my ($widget, $sdlev) = @_; |
48 |
|
|
} |
49 |
root |
1.4 |
|
50 |
elmex |
1.1 |
sub key_up { |
51 |
|
|
my ($widget, $sdlev) = @_; |
52 |
|
|
} |
53 |
root |
1.4 |
|
54 |
elmex |
1.1 |
sub button_down { |
55 |
|
|
my ($widget, $sdlev) = @_; |
56 |
|
|
} |
57 |
root |
1.4 |
|
58 |
elmex |
1.1 |
sub button_up { |
59 |
|
|
my ($widget, $sdlev) = @_; |
60 |
|
|
} |
61 |
root |
1.4 |
|
62 |
elmex |
1.11 |
sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } |
63 |
|
|
sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } |
64 |
elmex |
1.13 |
sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } |
65 |
elmex |
1.11 |
|
66 |
elmex |
1.1 |
sub draw { |
67 |
elmex |
1.11 |
my ($self) = @_; |
68 |
|
|
|
69 |
|
|
glPushMatrix; |
70 |
root |
1.12 |
glTranslate $self->{x}, $self->{y}, 0; |
71 |
elmex |
1.11 |
$self->_draw; |
72 |
|
|
glPopMatrix; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
sub _draw { |
76 |
elmex |
1.1 |
my ($widget) = @_; |
77 |
|
|
} |
78 |
root |
1.4 |
|
79 |
elmex |
1.1 |
sub bbox { |
80 |
|
|
my ($widget) = @_; |
81 |
|
|
} |
82 |
elmex |
1.2 |
|
83 |
root |
1.10 |
package Crossfire::Client::Widget::Label; |
84 |
|
|
|
85 |
root |
1.12 |
our @ISA = Crossfire::Client::Widget::; |
86 |
|
|
|
87 |
root |
1.10 |
use SDL::OpenGL; |
88 |
|
|
|
89 |
|
|
sub new { |
90 |
root |
1.12 |
my ($class, $x, $y, $z, $ttf, $text) = @_; |
91 |
root |
1.10 |
|
92 |
root |
1.12 |
my $self = $class->SUPER::new (x => $x, y => $y, z => $z); |
93 |
root |
1.10 |
|
94 |
|
|
$self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text; |
95 |
|
|
|
96 |
|
|
$self |
97 |
|
|
} |
98 |
|
|
|
99 |
root |
1.14 |
sub size_request { |
100 |
|
|
my ($self) = @_; |
101 |
|
|
|
102 |
|
|
( |
103 |
|
|
$self->{texture}{width}, |
104 |
|
|
$self->{texture}{height}, |
105 |
|
|
) |
106 |
|
|
} |
107 |
|
|
|
108 |
elmex |
1.11 |
sub _draw { |
109 |
root |
1.10 |
my ($self) = @_; |
110 |
|
|
|
111 |
|
|
my $tex = $self->{texture}; |
112 |
|
|
|
113 |
root |
1.12 |
$self->{x}--; |
114 |
|
|
|
115 |
|
|
glEnable GL_BLEND; |
116 |
root |
1.10 |
glEnable GL_TEXTURE_2D; |
117 |
root |
1.12 |
glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
118 |
root |
1.10 |
glBindTexture GL_TEXTURE_2D, $tex->{name}; |
119 |
|
|
|
120 |
root |
1.12 |
glColor 1, 1, 1; |
121 |
|
|
|
122 |
root |
1.10 |
glBegin GL_QUADS; |
123 |
|
|
glTexCoord 0, 0; glVertex 0 , 0; |
124 |
|
|
glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
125 |
|
|
glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
126 |
|
|
glTexCoord 1, 0; glVertex $tex->{width}, 0; |
127 |
|
|
glEnd; |
128 |
|
|
|
129 |
root |
1.12 |
glDisable GL_BLEND; |
130 |
root |
1.10 |
glDisable GL_TEXTURE_2D; |
131 |
|
|
} |
132 |
|
|
|
133 |
elmex |
1.9 |
package Crossfire::Client::Widget::TextView; |
134 |
root |
1.4 |
|
135 |
elmex |
1.3 |
use strict; |
136 |
root |
1.10 |
|
137 |
elmex |
1.9 |
our @ISA = qw/Crossfire::Client::Widget/; |
138 |
elmex |
1.3 |
|
139 |
|
|
use SDL::OpenGL; |
140 |
|
|
use SDL::OpenGL::Constants; |
141 |
|
|
|
142 |
|
|
sub add_line { |
143 |
|
|
my ($self, $line) = @_; |
144 |
|
|
push @{$self->{lines}}, $line; |
145 |
|
|
} |
146 |
|
|
|
147 |
elmex |
1.11 |
sub _draw { |
148 |
elmex |
1.3 |
my ($self) = @_; |
149 |
|
|
|
150 |
|
|
} |
151 |
|
|
|
152 |
elmex |
1.9 |
package Crossfire::Client::Widget::MapWidget; |
153 |
root |
1.4 |
|
154 |
elmex |
1.2 |
use strict; |
155 |
elmex |
1.7 |
|
156 |
elmex |
1.9 |
our @ISA = qw/Crossfire::Client::Widget/; |
157 |
elmex |
1.2 |
|
158 |
|
|
use SDL::OpenGL; |
159 |
|
|
use SDL::OpenGL::Constants; |
160 |
|
|
|
161 |
|
|
sub key_down { |
162 |
|
|
print "MAPKEYDOWN\n"; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
sub key_up { |
166 |
|
|
} |
167 |
|
|
|
168 |
elmex |
1.11 |
sub _draw { |
169 |
elmex |
1.2 |
glEnable GL_TEXTURE_2D; |
170 |
|
|
glEnable GL_BLEND; |
171 |
root |
1.12 |
glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
172 |
elmex |
1.2 |
|
173 |
|
|
my $map = $::CONN->{map}; |
174 |
|
|
|
175 |
|
|
for my $x (0 .. $::CONN->{mapw} - 1) { |
176 |
|
|
for my $y (0 .. $::CONN->{maph} - 1) { |
177 |
|
|
|
178 |
|
|
my $cell = $map->[$x][$y] |
179 |
|
|
or next; |
180 |
|
|
|
181 |
|
|
my $darkness = $cell->[3] * (1 / 255); |
182 |
|
|
glColor $darkness, $darkness, $darkness; |
183 |
|
|
|
184 |
|
|
for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
185 |
root |
1.4 |
my $tex = $::CONN->{face}[$num]{texture} || next; |
186 |
elmex |
1.2 |
|
187 |
root |
1.4 |
glBindTexture GL_TEXTURE_2D, $tex->{name}; |
188 |
elmex |
1.2 |
|
189 |
|
|
glBegin GL_QUADS; |
190 |
root |
1.10 |
glTexCoord 0, 0; glVertex $x * 32 , $y * 32; |
191 |
|
|
glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32; |
192 |
|
|
glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32; |
193 |
|
|
glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32; |
194 |
elmex |
1.2 |
glEnd; |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
glDisable GL_TEXTURE_2D; |
200 |
|
|
glDisable GL_BLEND; |
201 |
|
|
} |
202 |
|
|
|
203 |
elmex |
1.1 |
1; |
204 |
root |
1.5 |
|