… | |
… | |
6 | |
6 | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
9 | |
9 | |
10 | our $FOCUS; # the widget with current focus |
10 | our $FOCUS; # the widget with current focus |
11 | our @ACTIVE_WIDGETS; |
11 | #our @ACTIVE_WIDGETS; |
12 | |
12 | |
13 | # class methods for events |
13 | # class methods for events |
14 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
14 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
15 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
15 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
16 | sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } |
16 | sub feed_sdl_button_down_event { } |
17 | sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } |
17 | sub feed_sdl_button_up_event { } |
18 | |
18 | |
19 | sub new { |
19 | sub new { |
20 | my $class = shift; |
20 | my $class = shift; |
21 | |
21 | |
22 | bless { @_ }, $class |
22 | bless { @_ }, $class |
23 | } |
23 | } |
24 | |
24 | |
25 | sub activate { |
25 | #sub activate { |
26 | push @ACTIVE_WIDGETS, $_[0]; |
26 | # push @ACTIVE_WIDGETS, $_[0]; |
27 | Scalar::Util::weaken $ACTIVE_WIDGETS[-1]; |
27 | # Scalar::Util::weaken $ACTIVE_WIDGETS[-1]; |
28 | } |
28 | #} |
29 | |
29 | |
30 | sub deactivate { |
30 | #sub deactivate { |
31 | @ACTIVE_WIDGETS = |
31 | # @ACTIVE_WIDGETS = |
32 | sort { $a->{z} <=> $b->{z} } |
32 | # sort { $a->{z} <=> $b->{z} } |
33 | grep { $_ && $_ != $_[0] } |
33 | # grep { $_ && $_ != $_[0] } |
34 | @ACTIVE_WIDGETS; |
34 | # @ACTIVE_WIDGETS; |
35 | } |
35 | #} |
36 | |
36 | |
37 | sub move { |
37 | sub move { |
38 | my ($self, $x, $y, $z) = @_; |
38 | my ($self, $x, $y, $z) = @_; |
39 | $self->{x} = $x; |
39 | $self->{x} = $x; |
40 | $self->{y} = $y; |
40 | $self->{y} = $y; |
… | |
… | |
92 | sub _draw { |
92 | sub _draw { |
93 | my ($widget) = @_; |
93 | my ($widget) = @_; |
94 | } |
94 | } |
95 | |
95 | |
96 | sub bbox { |
96 | sub bbox { |
97 | my ($widget) = @_; |
97 | my ($self) = @_; |
|
|
98 | my ($w, $h) = $self->size_request; |
|
|
99 | ( |
|
|
100 | $self->{x}, |
|
|
101 | $self->{y}, |
|
|
102 | $self->{x} = $w, |
|
|
103 | $self->{y} = $h |
|
|
104 | ) |
|
|
105 | } |
|
|
106 | |
|
|
107 | sub del_parent { $_[0]->{parent} = undef } |
|
|
108 | |
|
|
109 | sub set_parent { |
|
|
110 | my ($self, $par) = @_; |
|
|
111 | |
|
|
112 | $self->{parent} = $par; |
|
|
113 | Scalar::Util::weaken $self->{parent}; |
|
|
114 | } |
|
|
115 | |
|
|
116 | sub get_parent { |
|
|
117 | $_[0]->{parent} |
|
|
118 | } |
|
|
119 | |
|
|
120 | sub update { |
|
|
121 | my ($self) = @_; |
|
|
122 | |
|
|
123 | $self->{parent}->update |
|
|
124 | if $self->{parent}; |
98 | } |
125 | } |
99 | |
126 | |
100 | sub DESTROY { |
127 | sub DESTROY { |
101 | my ($self) = @_; |
128 | my ($self) = @_; |
102 | |
129 | |
103 | $self->deactivate; |
130 | #$self->deactivate; |
104 | } |
131 | } |
105 | |
132 | |
106 | package Crossfire::Client::Widget::Container; |
133 | package Crossfire::Client::Widget::Container; |
107 | |
134 | |
108 | our @ISA = Crossfire::Client::Widget::; |
135 | our @ISA = Crossfire::Client::Widget::; |
109 | |
136 | |
110 | use SDL::OpenGL; |
137 | use SDL::OpenGL; |
111 | |
138 | |
112 | sub add { $_[0]->{child} = $_[1] } |
139 | sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->update } |
113 | sub get { $_[0]->{child} } |
140 | sub get { $_[0]->{child} } |
|
|
141 | sub remove { |
|
|
142 | my ($self, $chld) = @_; |
|
|
143 | delete $self->{child} |
|
|
144 | if $self->{child} == $chld; |
|
|
145 | } |
114 | |
146 | |
115 | sub size_request { $_[0]->{child}->size_request if $_[0]->{child} } |
147 | sub size_request { $_[0]->{child}->size_request if $_[0]->{child} } |
116 | |
148 | |
117 | sub _draw { die "Containers can't be drawn!" } |
149 | sub _draw { die "Containers can't be drawn!" } |
|
|
150 | |
|
|
151 | package Crossfire::Client::Widget::Toplevel; |
|
|
152 | |
|
|
153 | our @ISA = Crossfire::Client::Widget::; |
|
|
154 | |
|
|
155 | use SDL::OpenGL; |
|
|
156 | |
|
|
157 | sub add { |
|
|
158 | my ($self, $chld) = @_; |
|
|
159 | |
|
|
160 | push @{$self->{childs}}, $chld; |
|
|
161 | @{$self->{childs}} = |
|
|
162 | sort { $a->{z} <=> $b->{z} } |
|
|
163 | @{$self->{childs}}; |
|
|
164 | |
|
|
165 | $chld->set_parent ($self); |
|
|
166 | } |
|
|
167 | |
|
|
168 | sub remove { |
|
|
169 | my ($self, $chld) = @_; |
|
|
170 | @{$self->{childs}} = |
|
|
171 | sort { $a->{z} <=> $b->{z} } |
|
|
172 | grep { $_ && $_ != $_[0] } |
|
|
173 | @{$self->{childs}} |
|
|
174 | } |
|
|
175 | |
|
|
176 | sub update { |
|
|
177 | my ($self) = @_; |
|
|
178 | ::refresh (); |
|
|
179 | } |
|
|
180 | |
|
|
181 | sub _draw { |
|
|
182 | my ($self) = @_; |
|
|
183 | |
|
|
184 | $_->draw for @{$self->{childs}}; |
|
|
185 | } |
118 | |
186 | |
119 | package Crossfire::Client::Widget::Window; |
187 | package Crossfire::Client::Widget::Window; |
120 | |
188 | |
121 | our @ISA = Crossfire::Client::Widget::Container::; |
189 | our @ISA = Crossfire::Client::Widget::Container::; |
122 | |
190 | |
123 | use SDL::OpenGL; |
191 | use SDL::OpenGL; |
124 | |
192 | |
125 | sub add { |
193 | sub add { |
126 | my ($self, $chld) = @_; |
194 | my ($self, $chld) = @_; |
127 | $self->SUPER::add ($chld); |
195 | $self->SUPER::add ($chld); |
|
|
196 | $chld->set_parent ($self); |
128 | $self->render_chld; #TODO: Move this to the size_request event propably? |
197 | $self->update; #TODO: Move this to the size_request event propably? |
|
|
198 | } |
|
|
199 | |
|
|
200 | sub remove { |
|
|
201 | my ($self) = @_; |
|
|
202 | # TODO FIXME: removing a child from a window will crash, see render_chld |
|
|
203 | $self->update; |
|
|
204 | } |
|
|
205 | |
|
|
206 | sub update { |
|
|
207 | my ($self) = @_; |
|
|
208 | $self->render_chld; |
129 | } |
209 | } |
130 | |
210 | |
131 | sub render_chld { |
211 | sub render_chld { |
132 | my ($self) = @_; |
212 | my ($self) = @_; |
133 | my $chld = $self->get; |
213 | my $chld = $self->get; |
… | |
… | |
148 | } |
228 | } |
149 | |
229 | |
150 | sub _draw { |
230 | sub _draw { |
151 | my ($self) = @_; |
231 | my ($self) = @_; |
152 | |
232 | |
153 | my ($w, $h) = $self->size_request;#TODO# use widht/height of texture |
233 | my ($w, $h) = $self->size_request;#TODO# use width/height of texture |
|
|
234 | |
154 | my $tex = $self->{texture} |
235 | my $tex = $self->{texture} |
155 | or return; |
236 | or return; |
156 | |
237 | |
157 | glEnable GL_BLEND; |
238 | glEnable GL_BLEND; |
158 | glEnable GL_TEXTURE_2D; |
239 | glEnable GL_TEXTURE_2D; |
159 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
240 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
160 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
241 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
161 | |
242 | |
162 | glColor 1, 1, 1; |
243 | glColor 1, 0, 1; |
163 | |
244 | |
164 | glBegin GL_QUADS; |
245 | glBegin GL_QUADS; |
165 | glTexCoord 0, 0; glVertex 0, 0; |
246 | glTexCoord 0, 0; glVertex 0, 0; |
166 | glTexCoord 0, 1; glVertex 0, $h; |
247 | glTexCoord 0, 1; glVertex 0, $h; |
167 | glTexCoord 1, 1; glVertex $w, $h; |
248 | glTexCoord 1, 1; glVertex $w, $h; |
… | |
… | |
180 | |
261 | |
181 | sub size_request { |
262 | sub size_request { |
182 | my ($self) = @_; |
263 | my ($self) = @_; |
183 | my $chld = $self->get |
264 | my $chld = $self->get |
184 | or return (0, 0); |
265 | or return (0, 0); |
|
|
266 | |
|
|
267 | $chld->move (2, 2); |
|
|
268 | |
185 | map { $_ + 4 } $chld->size_request; |
269 | map { $_ + 4 } $chld->size_request; |
186 | } |
270 | } |
187 | |
271 | |
188 | sub _draw { |
272 | sub _draw { |
189 | my ($self) = @_; |
273 | my ($self) = @_; |
190 | |
274 | |
191 | my $chld = $self->get; |
275 | my $chld = $self->get; |
192 | |
276 | |
193 | $chld->move (2, 2, 0); #TODO:move to size_request |
|
|
194 | |
|
|
195 | my ($w, $h) = $chld->size_request; |
277 | my ($w, $h) = $chld->size_request; |
196 | |
278 | |
197 | glColor 1, 0, 0; |
|
|
198 | glBegin GL_QUADS; |
279 | glBegin GL_QUADS; |
|
|
280 | glColor 0, 0, 0; |
199 | glTexCoord 0, 0; glVertex 0 , 0; |
281 | glTexCoord 0, 0; glVertex 0 , 0; |
200 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
282 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
201 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
283 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
202 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
284 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
203 | glEnd; |
285 | glEnd; |
204 | |
286 | |
205 | $chld->draw; |
287 | $chld->draw; |
206 | } |
288 | } |
207 | |
289 | |
|
|
290 | package Crossfire::Client::Widget::FancyFrame; |
|
|
291 | |
|
|
292 | our @ISA = Crossfire::Client::Widget::Frame::; |
|
|
293 | |
|
|
294 | use SDL::OpenGL; |
|
|
295 | |
|
|
296 | sub new { |
|
|
297 | my ($self, $theme) = @_; |
|
|
298 | $self = $self->SUPER::new; |
|
|
299 | |
|
|
300 | $self->{txts} = [ |
|
|
301 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
|
|
302 | qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ |
|
|
303 | ]; |
|
|
304 | $self |
|
|
305 | |
|
|
306 | } |
|
|
307 | |
|
|
308 | sub size_request { |
|
|
309 | my ($self) = @_; |
|
|
310 | my ($w, $h) = $self->get->size_request; |
|
|
311 | |
|
|
312 | $h += $self->{txts}->[1]->{height}; |
|
|
313 | $h += $self->{txts}->[4]->{height}; |
|
|
314 | $w += $self->{txts}->[2]->{width}; |
|
|
315 | $w += $self->{txts}->[3]->{width}; |
|
|
316 | |
|
|
317 | $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
|
|
318 | |
|
|
319 | ($w, $h) |
|
|
320 | } |
|
|
321 | |
|
|
322 | sub _draw { |
|
|
323 | my ($self) = @_; |
|
|
324 | |
|
|
325 | my ($w, $h) = $self->size_request; |
|
|
326 | my ($cw, $ch) = $self->get->size_request; |
|
|
327 | |
|
|
328 | glEnable GL_BLEND; |
|
|
329 | glEnable GL_TEXTURE_2D; |
|
|
330 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
331 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
332 | |
|
|
333 | |
|
|
334 | my $top = $self->{txts}->[1]; |
|
|
335 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
|
|
336 | |
|
|
337 | glColor 1, 1, 1, 0.8; |
|
|
338 | |
|
|
339 | glBegin GL_QUADS; |
|
|
340 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
341 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
|
|
342 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
|
|
343 | glTexCoord 1, 0; glVertex $w , 0; |
|
|
344 | glEnd; |
|
|
345 | |
|
|
346 | my $left = $self->{txts}->[3]; |
|
|
347 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
|
|
348 | |
|
|
349 | glColor 1, 1, 1, 0.8; |
|
|
350 | |
|
|
351 | glBegin GL_QUADS; |
|
|
352 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
|
|
353 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
|
|
354 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
|
|
355 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
|
|
356 | glEnd; |
|
|
357 | |
|
|
358 | my $right = $self->{txts}->[2]; |
|
|
359 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
|
|
360 | |
|
|
361 | glColor 1, 1, 1, 0.8; |
|
|
362 | |
|
|
363 | glBegin GL_QUADS; |
|
|
364 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
|
|
365 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
|
|
366 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
|
|
367 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
|
|
368 | glEnd; |
|
|
369 | |
|
|
370 | my $bottom = $self->{txts}->[4]; |
|
|
371 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
|
|
372 | |
|
|
373 | glColor 1, 1, 1, 0.8; |
|
|
374 | |
|
|
375 | glBegin GL_QUADS; |
|
|
376 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
|
|
377 | glTexCoord 0, 1; glVertex 0 , $h; |
|
|
378 | glTexCoord 1, 1; glVertex $w , $h; |
|
|
379 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
|
|
380 | glEnd; |
|
|
381 | |
|
|
382 | my $bg = $self->{txts}->[0]; |
|
|
383 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
|
|
384 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
|
|
385 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
|
|
386 | |
|
|
387 | glColor 1, 1, 1, 0.8; |
|
|
388 | |
|
|
389 | my $rep_x = $cw / $bg->{width}; |
|
|
390 | my $rep_y = $ch / $bg->{height}; |
|
|
391 | |
|
|
392 | glBegin GL_QUADS; |
|
|
393 | glTexCoord 0, 0; glVertex $left->{width}, $top->{height}; |
|
|
394 | glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch; |
|
|
395 | glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch; |
|
|
396 | glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height}; |
|
|
397 | glEnd; |
|
|
398 | |
|
|
399 | $self->get->draw; |
|
|
400 | |
|
|
401 | glDisable GL_BLEND; |
|
|
402 | glDisable GL_TEXTURE_2D; |
|
|
403 | } |
|
|
404 | |
208 | package Crossfire::Client::Widget::Table; |
405 | package Crossfire::Client::Widget::Table; |
209 | |
406 | |
210 | our @ISA = Crossfire::Client::Widget::Container::; |
407 | our @ISA = Crossfire::Client::Widget::Container::; |
211 | |
408 | |
212 | use SDL::OpenGL; |
409 | use SDL::OpenGL; |
213 | |
410 | |
214 | sub add { |
411 | sub add { |
215 | my ($self, $x, $y, $chld) = @_; |
412 | my ($self, $x, $y, $chld) = @_; |
|
|
413 | my $old_chld = $self->{childs}[$y][$x]; |
|
|
414 | |
216 | $self->{childs}[$y][$x] = $chld; |
415 | $self->{childs}[$y][$x] = $chld; |
|
|
416 | $chld->set_parent ($self); |
|
|
417 | $self->update; |
217 | } |
418 | } |
218 | |
419 | |
219 | sub max_row_height { |
420 | sub max_row_height { |
220 | my ($self, $row) = @_; |
421 | my ($self, $row) = @_; |
221 | |
422 | |
… | |
… | |
293 | use SDL::OpenGL; |
494 | use SDL::OpenGL; |
294 | |
495 | |
295 | sub add { |
496 | sub add { |
296 | my ($self, $chld) = @_; |
497 | my ($self, $chld) = @_; |
297 | push @{$self->{childs}}, $chld; |
498 | push @{$self->{childs}}, $chld; |
|
|
499 | $chld->set_parent ($self); |
|
|
500 | $self->update; |
298 | } |
501 | } |
299 | |
502 | |
300 | sub size_request { |
503 | sub size_request { |
301 | my ($self) = @_; |
504 | my ($self) = @_; |
302 | |
505 | |
… | |
… | |
329 | use SDL::OpenGL; |
532 | use SDL::OpenGL; |
330 | |
533 | |
331 | sub new { |
534 | sub new { |
332 | my ($class, $x, $y, $z, $height, $text) = @_; |
535 | my ($class, $x, $y, $z, $height, $text) = @_; |
333 | |
536 | |
|
|
537 | # TODO: color, and make height, xyz etc. optional |
334 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
538 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
335 | |
539 | |
336 | $self->set_text ($text); |
540 | $self->set_text ($text); |
337 | |
541 | |
338 | $self |
542 | $self |
… | |
… | |
340 | |
544 | |
341 | sub set_text { |
545 | sub set_text { |
342 | my ($self, $text) = @_; |
546 | my ($self, $text) = @_; |
343 | |
547 | |
344 | $self->{text} = $text; |
548 | $self->{text} = $text; |
345 | |
|
|
346 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
549 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
|
|
550 | |
|
|
551 | $self->update; |
347 | } |
552 | } |
348 | |
553 | |
349 | sub get_text { |
554 | sub get_text { |
350 | my ($self, $text) = @_; |
555 | my ($self, $text) = @_; |
351 | |
556 | |
… | |
… | |
366 | |
571 | |
367 | my $tex = $self->{texture}; |
572 | my $tex = $self->{texture}; |
368 | |
573 | |
369 | glEnable GL_BLEND; |
574 | glEnable GL_BLEND; |
370 | glEnable GL_TEXTURE_2D; |
575 | glEnable GL_TEXTURE_2D; |
|
|
576 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
371 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
577 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
372 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
578 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
373 | |
579 | |
374 | glColor 1, 0, 1; |
580 | glColor 1, 1, 1, 0.6; # TODO color |
375 | |
581 | |
376 | glBegin GL_QUADS; |
582 | glBegin GL_QUADS; |
377 | glTexCoord 0, 0; glVertex 0 , 0; |
583 | glTexCoord 0, 0; glVertex 0 , 0; |
378 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
584 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
379 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
585 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
… | |
… | |
382 | |
588 | |
383 | glDisable GL_BLEND; |
589 | glDisable GL_BLEND; |
384 | glDisable GL_TEXTURE_2D; |
590 | glDisable GL_TEXTURE_2D; |
385 | } |
591 | } |
386 | |
592 | |
|
|
593 | package Crossfire::Client::Widget::TextEntry; |
|
|
594 | |
|
|
595 | our @ISA = Crossfire::Client::Widget::Label::; |
|
|
596 | |
|
|
597 | use SDL; |
|
|
598 | use SDL::OpenGL; |
|
|
599 | |
|
|
600 | sub key_down { |
|
|
601 | my ($self, $ev) = @_; |
|
|
602 | |
|
|
603 | my $mod = $ev->key_mod; |
|
|
604 | my $sym = $ev->key_sym; |
|
|
605 | |
|
|
606 | $ev->set_unicode (1); |
|
|
607 | my $uni = $ev->key_unicode; |
|
|
608 | |
|
|
609 | my $text = $self->get_text; |
|
|
610 | |
|
|
611 | if ($sym == SDLK_BACKSPACE) { |
|
|
612 | substr $text, -1, 1, ''; |
|
|
613 | |
|
|
614 | } elsif ($uni) { |
|
|
615 | $text .= chr $uni; |
|
|
616 | } |
|
|
617 | $self->set_text ($text); |
|
|
618 | } |
|
|
619 | |
|
|
620 | |
|
|
621 | # XXX: TextView isn't neccessary with pango multiline text rendering |
387 | package Crossfire::Client::Widget::TextView; |
622 | package Crossfire::Client::Widget::TextView; |
388 | |
623 | |
389 | use strict; |
624 | use strict; |
390 | |
625 | |
391 | our @ISA = qw/Crossfire::Client::Widget/; |
626 | our @ISA = qw/Crossfire::Client::Widget/; |
392 | |
627 | |
393 | use SDL::OpenGL; |
628 | use SDL::OpenGL; |
394 | use SDL::OpenGL::Constants; |
629 | use SDL::OpenGL::Constants; |
|
|
630 | |
|
|
631 | sub new { |
|
|
632 | my ($class, $text, $h) = @_; |
|
|
633 | my $self = $class->SUPER::new (); |
|
|
634 | |
|
|
635 | $self->{txt_height} = $h; |
|
|
636 | @{$self->{lines}} = split /\r?\n/, $text; |
|
|
637 | |
|
|
638 | for (split /\r?\n/, $text) { |
|
|
639 | $self->add_line ($_); |
|
|
640 | } |
|
|
641 | $self |
|
|
642 | } |
|
|
643 | |
|
|
644 | #sub render_lines { |
|
|
645 | # my ($self) = @_; |
|
|
646 | # |
|
|
647 | # $self->{txt_lines} = []; |
|
|
648 | # |
|
|
649 | # for (@{$self->{lines}}) { |
|
|
650 | # push @{$self->{txt_lines}}, |
|
|
651 | # new_from_ttf Crossfire::Client::Texture $self->{ttf}, $_; |
|
|
652 | # } |
|
|
653 | #} |
395 | |
654 | |
396 | sub add_line { |
655 | sub add_line { |
397 | my ($self, $line) = @_; |
656 | my ($self, $line) = @_; |
398 | push @{$self->{lines}}, $line; |
657 | push @{$self->{lines}}, $line; |
399 | } |
|
|
400 | |
658 | |
|
|
659 | push @{$self->{txt_lines}}, |
|
|
660 | new_from_text Crossfire::Client::Texture $line, $self->{txt_height}; |
|
|
661 | } |
|
|
662 | |
|
|
663 | sub size_request { |
|
|
664 | my ($self) = @_; |
|
|
665 | |
|
|
666 | my $w = 0; |
|
|
667 | my $h = 0; |
|
|
668 | |
|
|
669 | for (@{$self->{txt_lines}}) { |
|
|
670 | if ($w < $_->{width}) { $w = $_->{width} } |
|
|
671 | $h += $_->{height}; |
|
|
672 | } |
|
|
673 | |
|
|
674 | return ($w, $h); |
|
|
675 | } |
|
|
676 | |
401 | sub _draw { |
677 | sub draw_line { |
402 | my ($self) = @_; |
678 | my ($self, $tex, $y) = @_; |
403 | |
679 | |
|
|
680 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
681 | |
|
|
682 | glColor 1, 0, 1; |
|
|
683 | |
|
|
684 | glBegin GL_QUADS; |
|
|
685 | glTexCoord 0, 0; glVertex 0 , $y; |
|
|
686 | glTexCoord 0, 1; glVertex 0 , $y + $tex->{height}; |
|
|
687 | glTexCoord 1, 1; glVertex $tex->{width}, $y + $tex->{height}; |
|
|
688 | glTexCoord 1, 0; glVertex $tex->{width}, $y; |
|
|
689 | glEnd; |
|
|
690 | } |
|
|
691 | |
|
|
692 | sub _draw { |
|
|
693 | my ($self) = @_; |
|
|
694 | |
|
|
695 | glEnable GL_BLEND; |
|
|
696 | glEnable GL_TEXTURE_2D; |
|
|
697 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;#DECAL; |
|
|
698 | |
|
|
699 | my $l = 0; |
|
|
700 | for (@{$self->{txt_lines}}) { |
|
|
701 | $self->draw_line ($_, $l); |
|
|
702 | $l += $_->{height}; |
|
|
703 | } |
|
|
704 | |
|
|
705 | glDisable GL_BLEND; |
|
|
706 | glDisable GL_TEXTURE_2D; |
404 | } |
707 | } |
405 | |
708 | |
406 | package Crossfire::Client::Widget::MapWidget; |
709 | package Crossfire::Client::Widget::MapWidget; |
407 | |
710 | |
408 | use strict; |
711 | use strict; |