… | |
… | |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
22 | } |
22 | } |
23 | |
23 | |
24 | sub feed_sdl_button_down_event { |
24 | sub feed_sdl_button_down_event { |
25 | my ($ev) = @_; |
25 | my ($ev) = @_; |
26 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
26 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
27 | |
27 | |
28 | if (!$BUTTON_STATE) { |
28 | if (!$BUTTON_STATE) { |
29 | my $widget = $ROOT->find_widget ($x, $y); |
29 | my $widget = $ROOT->find_widget ($x, $y); |
30 | |
30 | |
31 | $GRAB = $widget; |
31 | $GRAB = $widget; |
32 | $GRAB->update if $GRAB; |
32 | $GRAB->update if $GRAB; |
33 | } |
33 | } |
34 | |
34 | |
35 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
35 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
36 | |
36 | |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
38 | } |
38 | } |
39 | |
39 | |
40 | sub feed_sdl_button_up_event { |
40 | sub feed_sdl_button_up_event { |
41 | my ($ev) = @_; |
41 | my ($ev) = @_; |
42 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
42 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
43 | |
43 | |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
45 | |
45 | |
46 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
46 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
47 | |
47 | |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
49 | |
49 | |
50 | if (!$BUTTON_STATE) { |
50 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
51 | my $grab = $GRAB; undef $GRAB; |
… | |
… | |
54 | } |
54 | } |
55 | } |
55 | } |
56 | |
56 | |
57 | sub feed_sdl_motion_event { |
57 | sub feed_sdl_motion_event { |
58 | my ($ev) = @_; |
58 | my ($ev) = @_; |
59 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
59 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
60 | |
60 | |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
62 | |
62 | |
63 | if ($widget != $HOVER) { |
63 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
64 | my $hover = $HOVER; $HOVER = $widget; |
… | |
… | |
87 | |
87 | |
88 | package CFClient::UI::Base; |
88 | package CFClient::UI::Base; |
89 | |
89 | |
90 | use strict; |
90 | use strict; |
91 | |
91 | |
92 | use SDL::OpenGL; |
92 | use CFClient::OpenGL; |
93 | |
93 | |
94 | sub new { |
94 | sub new { |
95 | my $class = shift; |
95 | my $class = shift; |
96 | |
96 | |
97 | my $self = bless { |
97 | my $self = bless { |
98 | x => 0, |
98 | x => 0, |
99 | y => 0, |
99 | y => 0, |
100 | z => 0, |
100 | z => 0, |
101 | w => -1, |
|
|
102 | h => -1, |
|
|
103 | @_ |
101 | @_ |
104 | }, $class; |
102 | }, $class; |
105 | |
103 | |
106 | for (keys %$self) { |
104 | for (keys %$self) { |
107 | if (/^connect_(.*)$/) { |
105 | if (/^connect_(.*)$/) { |
… | |
… | |
110 | } |
108 | } |
111 | |
109 | |
112 | $self |
110 | $self |
113 | } |
111 | } |
114 | |
112 | |
|
|
113 | sub show { |
|
|
114 | my ($self) = @_; |
|
|
115 | |
|
|
116 | return if $self->{parent}; |
|
|
117 | |
|
|
118 | $CFClient::UI::ROOT->add ($self); |
|
|
119 | } |
|
|
120 | |
|
|
121 | sub hide { |
|
|
122 | my ($self) = @_; |
|
|
123 | |
|
|
124 | return unless $self->{parent}; |
|
|
125 | |
|
|
126 | $self->{parent}->remove ($self); |
|
|
127 | } |
|
|
128 | |
115 | sub move { |
129 | sub move { |
116 | my ($self, $x, $y, $z) = @_; |
130 | my ($self, $x, $y, $z) = @_; |
|
|
131 | |
117 | $self->{x} = int $x; |
132 | $self->{x} = int $x; |
118 | $self->{y} = int $y; |
133 | $self->{y} = int $y; |
119 | $self->{z} = $z if defined $z; |
134 | $self->{z} = $z if defined $z; |
|
|
135 | |
|
|
136 | $self->update; |
120 | } |
137 | } |
121 | |
138 | |
122 | sub needs_redraw { |
139 | sub needs_redraw { |
123 | 0 |
140 | 0 |
124 | } |
141 | } |
… | |
… | |
126 | sub size_request { |
143 | sub size_request { |
127 | require Carp; |
144 | require Carp; |
128 | Carp::confess "size_request is abtract"; |
145 | Carp::confess "size_request is abtract"; |
129 | } |
146 | } |
130 | |
147 | |
131 | sub _size_allocate { |
148 | sub configure { |
132 | my ($self, $x, $y, $w, $h) = @_; |
149 | my ($self, $x, $y, $w, $h) = @_; |
133 | |
150 | |
134 | $self->{x} = $x; |
151 | $self->{x} = $x; |
135 | $self->{y} = $y; |
152 | $self->{y} = $y; |
136 | |
153 | |
|
|
154 | if ($self->{aspect}) { |
|
|
155 | $w = List::Util::min $w, int $h * $self->{aspect}; |
|
|
156 | $h = List::Util::min $h, int $w / $self->{aspect}; |
|
|
157 | } |
|
|
158 | |
137 | return unless $self->{w} != $w || $self->{h} != $h; |
159 | return unless $self->{w} != $w || $self->{h} != $h; |
138 | |
160 | |
139 | $self->{w} = $w; |
161 | $self->{w} = $w; |
140 | $self->{h} = $h; |
162 | $self->{h} = $h; |
141 | |
163 | |
142 | 1 |
164 | $self->size_allocate ($w, $h); |
|
|
165 | $self->update; |
143 | } |
166 | } |
144 | |
167 | |
145 | sub size_allocate { |
168 | sub size_allocate { |
146 | my ($self, $x, $y, $w, $h) = @_; |
169 | # nothing to be done |
147 | |
|
|
148 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
149 | } |
170 | } |
150 | |
171 | |
151 | # return top left coordinates |
172 | # return top left coordinates |
152 | sub _topleft { |
173 | sub _topleft { |
153 | my ($self, $x, $y) = @_; |
174 | my ($self, $x, $y) = @_; |
… | |
… | |
176 | |
197 | |
177 | return if $FOCUS == $self; |
198 | return if $FOCUS == $self; |
178 | return unless $self->{can_focus}; |
199 | return unless $self->{can_focus}; |
179 | |
200 | |
180 | my $focus = $FOCUS; $FOCUS = $self; |
201 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
202 | |
|
|
203 | $self->emit (focus_in => $focus); |
|
|
204 | |
181 | $focus->update if $focus; |
205 | $focus->update if $focus; |
182 | $FOCUS->update; |
206 | $FOCUS->update; |
183 | } |
207 | } |
184 | |
208 | |
185 | sub focus_out { |
209 | sub focus_out { |
186 | my ($self) = @_; |
210 | my ($self) = @_; |
187 | |
211 | |
188 | return unless $FOCUS == $self; |
212 | return unless $FOCUS == $self; |
189 | |
213 | |
190 | my $focus = $FOCUS; undef $FOCUS; |
214 | my $focus = $FOCUS; undef $FOCUS; |
|
|
215 | |
|
|
216 | $self->emit (focus_out => $focus); |
|
|
217 | |
191 | $focus->update if $focus; #? |
218 | $focus->update if $focus; #? |
192 | } |
219 | } |
193 | |
220 | |
194 | sub mouse_motion { } |
221 | sub mouse_motion { } |
195 | sub button_up { } |
222 | sub button_up { } |
… | |
… | |
219 | glPopMatrix; |
246 | glPopMatrix; |
220 | |
247 | |
221 | if ($self == $HOVER && $self->{can_hover}) { |
248 | if ($self == $HOVER && $self->{can_hover}) { |
222 | my ($x, $y) = @$self{qw(x y)}; |
249 | my ($x, $y) = @$self{qw(x y)}; |
223 | |
250 | |
224 | glColor 0, 0, 1, 0.2; |
251 | glColor 1, 0.8, 0.5, 0.2; |
225 | glEnable GL_BLEND; |
252 | glEnable GL_BLEND; |
226 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
253 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
227 | glBegin GL_QUADS; |
254 | glBegin GL_QUADS; |
228 | glVertex $x , $y; |
255 | glVertex $x , $y; |
229 | glVertex $x + $self->{w}, $y; |
256 | glVertex $x + $self->{w}, $y; |
… | |
… | |
254 | my ($self, $parent) = @_; |
281 | my ($self, $parent) = @_; |
255 | |
282 | |
256 | Scalar::Util::weaken ($self->{parent} = $parent); |
283 | Scalar::Util::weaken ($self->{parent} = $parent); |
257 | } |
284 | } |
258 | |
285 | |
|
|
286 | sub check_size { |
|
|
287 | my ($self) = @_; |
|
|
288 | |
|
|
289 | my ($w, $h) = $self->size_request; |
|
|
290 | |
|
|
291 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
|
|
292 | $self->{req_w} = $w; |
|
|
293 | $self->{req_h} = $h; |
|
|
294 | |
|
|
295 | $self->{parent}->check_size |
|
|
296 | if $self->{parent}; |
|
|
297 | } |
|
|
298 | } |
|
|
299 | |
259 | sub update { |
300 | sub update { |
260 | my ($self) = @_; |
301 | my ($self) = @_; |
261 | |
302 | |
262 | $self->{parent}->update |
303 | $self->{parent}->update |
263 | if $self->{parent}; |
304 | if $self->{parent}; |
264 | } |
305 | } |
265 | |
306 | |
266 | sub connect { |
307 | sub connect { |
267 | my ($self, $signal, $cb) = @_; |
308 | my ($self, $signal, $cb) = @_; |
268 | |
309 | |
269 | push @{ $self->{cb}{$signal} }, $cb; |
310 | push @{ $self->{signal_cb}{$signal} }, $cb; |
270 | } |
311 | } |
271 | |
312 | |
272 | sub emit { |
313 | sub emit { |
273 | my ($self, $signal, @args) = @_; |
314 | my ($self, $signal, @args) = @_; |
274 | |
315 | |
|
|
316 | for my $cb (@{$self->{signal_cb}{$signal} || []}) { |
275 | $_->($self, @args) |
317 | $cb->($self, @args); |
276 | for @{$self->{cb}{$signal} || []}; |
318 | } |
277 | } |
319 | } |
278 | |
320 | |
279 | sub DESTROY { |
321 | sub DESTROY { |
280 | my ($self) = @_; |
322 | my ($self) = @_; |
281 | |
323 | |
… | |
… | |
287 | package CFClient::UI::DrawBG; |
329 | package CFClient::UI::DrawBG; |
288 | |
330 | |
289 | our @ISA = CFClient::UI::Base::; |
331 | our @ISA = CFClient::UI::Base::; |
290 | |
332 | |
291 | use strict; |
333 | use strict; |
292 | use SDL::OpenGL; |
334 | use CFClient::OpenGL; |
293 | |
335 | |
294 | sub new { |
336 | sub new { |
295 | my $class = shift; |
337 | my $class = shift; |
296 | |
338 | |
297 | # range [value, low, high, page] |
339 | # range [value, low, high, page] |
… | |
… | |
361 | $self->{children} = [ |
403 | $self->{children} = [ |
362 | sort { $a->{z} <=> $b->{z} } |
404 | sort { $a->{z} <=> $b->{z} } |
363 | @{$self->{children}}, $child |
405 | @{$self->{children}}, $child |
364 | ]; |
406 | ]; |
365 | |
407 | |
366 | $self->{w} = $self->{h} = -1; |
408 | $child->check_size; |
367 | $self->update; |
|
|
368 | } |
409 | } |
369 | |
410 | |
370 | sub remove { |
411 | sub remove { |
371 | my ($self, $widget) = @_; |
412 | my ($self, $child) = @_; |
372 | |
413 | |
|
|
414 | delete $child->{parent}; |
|
|
415 | |
373 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
416 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
374 | |
417 | |
375 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
418 | $self->check_size; |
376 | } |
419 | } |
377 | |
420 | |
378 | sub find_widget { |
421 | sub find_widget { |
379 | my ($self, $x, $y) = @_; |
422 | my ($self, $x, $y) = @_; |
380 | |
423 | |
… | |
… | |
410 | |
453 | |
411 | $class->SUPER::new (children => [$child], %arg) |
454 | $class->SUPER::new (children => [$child], %arg) |
412 | } |
455 | } |
413 | |
456 | |
414 | sub add { |
457 | sub add { |
415 | my ($self, $widget) = @_; |
458 | my ($self, $child) = @_; |
416 | |
459 | |
417 | $self->{children} = []; |
460 | $self->{children} = []; |
418 | |
461 | |
419 | $self->SUPER::add ($widget); |
462 | $self->SUPER::add ($child); |
420 | } |
463 | } |
421 | |
464 | |
422 | sub remove { |
465 | sub remove { |
423 | my ($self, $widget) = @_; |
466 | my ($self, $widget) = @_; |
424 | |
467 | |
… | |
… | |
433 | sub size_request { |
476 | sub size_request { |
434 | $_[0]{children}[0]->size_request |
477 | $_[0]{children}[0]->size_request |
435 | } |
478 | } |
436 | |
479 | |
437 | sub size_allocate { |
480 | sub size_allocate { |
438 | my ($self, $x, $y, $w, $h) = @_; |
481 | my ($self, $w, $h) = @_; |
439 | |
482 | |
440 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
441 | |
|
|
442 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
483 | $self->{children}[0]->configure (0, 0, $w, $h); |
443 | } |
484 | } |
444 | |
485 | |
445 | ############################################################################# |
486 | ############################################################################# |
446 | |
487 | |
447 | package CFClient::UI::Window; |
488 | package CFClient::UI::Window; |
448 | |
489 | |
449 | our @ISA = CFClient::UI::Bin::; |
490 | our @ISA = CFClient::UI::Bin::; |
450 | |
491 | |
451 | use SDL::OpenGL; |
492 | use CFClient::OpenGL; |
452 | |
493 | |
453 | sub new { |
494 | sub new { |
454 | my ($class, %arg) = @_; |
495 | my ($class, %arg) = @_; |
455 | |
496 | |
456 | my $self = $class->SUPER::new (%arg); |
497 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
473 | $self->child->draw; |
514 | $self->child->draw; |
474 | }; |
515 | }; |
475 | } |
516 | } |
476 | |
517 | |
477 | sub size_allocate { |
518 | sub size_allocate { |
478 | my ($self, $x, $y, $w, $h) = @_; |
519 | my ($self, $w, $h) = @_; |
479 | |
520 | |
480 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
481 | |
|
|
482 | $self->child->size_allocate (0, 0, $w, $h); |
521 | $self->child->configure (0, 0, $w, $h); |
483 | |
522 | |
484 | $self->render_chld; |
523 | $self->render_chld; |
485 | } |
524 | } |
486 | |
525 | |
487 | sub _draw { |
526 | sub _draw { |
… | |
… | |
503 | glDisable GL_TEXTURE_2D; |
542 | glDisable GL_TEXTURE_2D; |
504 | } |
543 | } |
505 | |
544 | |
506 | ############################################################################# |
545 | ############################################################################# |
507 | |
546 | |
|
|
547 | package CFClient::UI::ViewPort; |
|
|
548 | |
|
|
549 | our @ISA = CFClient::UI::Window::; |
|
|
550 | |
|
|
551 | sub new { die } |
|
|
552 | |
|
|
553 | sub size_request { |
|
|
554 | my ($self) = @_; |
|
|
555 | |
|
|
556 | @$self{qw(child_w child_h)} = $self->child->size_request; |
|
|
557 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
|
|
558 | |
|
|
559 | @$self{qw(child_w child_h)} |
|
|
560 | } |
|
|
561 | |
|
|
562 | sub _draw { |
|
|
563 | my ($self) = @_; |
|
|
564 | |
|
|
565 | $self->{children}[1]->draw; |
|
|
566 | } |
|
|
567 | |
|
|
568 | |
|
|
569 | ############################################################################# |
|
|
570 | |
508 | package CFClient::UI::Frame; |
571 | package CFClient::UI::Frame; |
509 | |
572 | |
510 | our @ISA = CFClient::UI::Bin::; |
573 | our @ISA = CFClient::UI::Bin::; |
511 | |
574 | |
512 | use SDL::OpenGL; |
575 | use CFClient::OpenGL; |
513 | |
576 | |
514 | sub size_request { |
577 | sub size_request { |
515 | my ($self) = @_; |
578 | my ($self) = @_; |
516 | my $chld = $self->child |
579 | my $chld = $self->child |
517 | or return (0, 0); |
580 | or return (0, 0); |
… | |
… | |
522 | } |
585 | } |
523 | |
586 | |
524 | sub size_allocate { |
587 | sub size_allocate { |
525 | my ($self, $x, $y, $w, $h) = @_; |
588 | my ($self, $x, $y, $w, $h) = @_; |
526 | |
589 | |
527 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
528 | |
|
|
529 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
590 | $self->child->configure (2, 2, $w - 4, $h - 4); |
530 | } |
591 | } |
531 | |
592 | |
532 | sub _draw { |
593 | sub _draw { |
533 | my ($self) = @_; |
594 | my ($self) = @_; |
534 | |
595 | |
… | |
… | |
551 | |
612 | |
552 | package CFClient::UI::FancyFrame; |
613 | package CFClient::UI::FancyFrame; |
553 | |
614 | |
554 | our @ISA = CFClient::UI::Bin::; |
615 | our @ISA = CFClient::UI::Bin::; |
555 | |
616 | |
556 | use SDL::OpenGL; |
617 | use CFClient::OpenGL; |
557 | |
618 | |
558 | my @tex = |
619 | my @tex = |
559 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
620 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
560 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
621 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
561 | |
622 | |
… | |
… | |
565 | # TODO: user_x, user_y, overwrite moveto? |
626 | # TODO: user_x, user_y, overwrite moveto? |
566 | |
627 | |
567 | $class->SUPER::new ( |
628 | $class->SUPER::new ( |
568 | bg => [1, 1, 1, 1], |
629 | bg => [1, 1, 1, 1], |
569 | border_bg => [1, 1, 1, 1], |
630 | border_bg => [1, 1, 1, 1], |
570 | border => int $::FONTSIZE * 0.8, |
631 | border => 0.8, |
571 | @_ |
632 | @_ |
572 | ) |
633 | ) |
573 | } |
634 | } |
574 | |
635 | |
|
|
636 | sub border { |
|
|
637 | int $_[0]{border} * $::FONTSIZE |
|
|
638 | } |
|
|
639 | |
575 | sub size_request { |
640 | sub size_request { |
576 | my ($self) = @_; |
641 | my ($self) = @_; |
577 | |
642 | |
578 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
643 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
579 | |
644 | |
580 | my ($w, $h) = $self->SUPER::size_request; |
645 | my ($w, $h) = $self->SUPER::size_request; |
581 | |
646 | |
582 | ( |
647 | ( |
583 | $w + $self->{border} * 2, |
648 | $w + $self->border * 2, |
584 | $h + $self->{border} * 2, |
649 | $h + $self->border * 2, |
585 | ) |
650 | ) |
586 | } |
651 | } |
587 | |
652 | |
588 | sub size_allocate { |
653 | sub size_allocate { |
589 | my ($self, $x, $y, $w, $h) = @_; |
654 | my ($self, $w, $h) = @_; |
590 | |
655 | |
591 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
592 | |
|
|
593 | $h -= List::Util::max 0, $self->{border} * 2; |
656 | $h -= List::Util::max 0, $self->border * 2; |
594 | $w -= List::Util::max 0, $self->{border} * 2; |
657 | $w -= List::Util::max 0, $self->border * 2; |
595 | |
658 | |
596 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
659 | $self->child->configure ($self->border, $self->border, $w, $h); |
597 | } |
660 | } |
598 | |
661 | |
599 | sub button_down { |
662 | sub button_down { |
600 | my ($self, $ev, $x, $y) = @_; |
663 | my ($self, $ev, $x, $y) = @_; |
601 | |
664 | |
|
|
665 | my $border = $self->border; |
|
|
666 | |
602 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
667 | if ($x < $self->{w} && $x >= $self->{w} - $border |
603 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
668 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
604 | |
669 | |
605 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
670 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
606 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
671 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
607 | |
672 | |
608 | $self->{motion} = sub { |
673 | $self->{motion} = sub { |
609 | my ($ev, $x, $y) = @_; |
674 | my ($ev, $x, $y) = @_; |
610 | |
675 | |
611 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
676 | ($x, $y) = ($ev->{x}, $ev->{y}); |
612 | |
677 | |
613 | $self->{user_w} = $bw + $x - $ox; |
678 | $self->{user_w} = $bw + $x - $ox; |
614 | $self->{user_h} = $bh + $y - $oy; |
679 | $self->{user_h} = $bh + $y - $oy; |
615 | $self->update; |
680 | $self->check_size; |
616 | }; |
681 | }; |
617 | |
682 | |
618 | } elsif ($x >= 0 && $x < $self->{w} |
683 | } elsif ($x >= 0 && $x < $self->{w} |
619 | && $y >= 0 && $y < $self->{border}) { |
684 | && $y >= 0 && $y < $border) { |
620 | |
685 | |
621 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
686 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
622 | my ($bx, $by) = ($self->{x}, $self->{y}); |
687 | my ($bx, $by) = ($self->{x}, $self->{y}); |
623 | |
688 | |
624 | $self->{motion} = sub { |
689 | $self->{motion} = sub { |
625 | my ($ev, $x, $y) = @_; |
690 | my ($ev, $x, $y) = @_; |
626 | |
691 | |
627 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
692 | ($x, $y) = ($ev->{x}, $ev->{y}); |
628 | |
693 | |
629 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
694 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
630 | $self->update; |
695 | $self->update; |
631 | }; |
696 | }; |
632 | } |
697 | } |
… | |
… | |
653 | glEnable GL_BLEND; |
718 | glEnable GL_BLEND; |
654 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
719 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
655 | glEnable GL_TEXTURE_2D; |
720 | glEnable GL_TEXTURE_2D; |
656 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
721 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
657 | |
722 | |
|
|
723 | my $border = $self->border; |
|
|
724 | |
658 | glColor @{ $self->{border_bg} }; |
725 | glColor @{ $self->{border_bg} }; |
659 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
726 | $tex[1]->draw_quad (0, 0, $w, $border); |
660 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
727 | $tex[3]->draw_quad (0, $border, $border, $ch); |
661 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
728 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
662 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
729 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
663 | |
730 | |
664 | my $bg = $tex[0]; |
731 | my $bg = $tex[0]; |
665 | |
732 | |
666 | # TODO: repeat texture not scale |
733 | # TODO: repeat texture not scale |
667 | my $rep_x = $cw / $bg->{w}; |
734 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
670 | glColor @{ $self->{bg} }; |
737 | glColor @{ $self->{bg} }; |
671 | |
738 | |
672 | $bg->{s} = $rep_x; |
739 | $bg->{s} = $rep_x; |
673 | $bg->{t} = $rep_y; |
740 | $bg->{t} = $rep_y; |
674 | $bg->{wrap_mode} = 1; |
741 | $bg->{wrap_mode} = 1; |
675 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
742 | $bg->draw_quad ($border, $border, $cw, $ch); |
676 | |
743 | |
677 | glDisable GL_TEXTURE_2D; |
744 | glDisable GL_TEXTURE_2D; |
678 | glDisable GL_BLEND; |
745 | glDisable GL_BLEND; |
679 | |
746 | |
680 | $self->child->draw; |
747 | $self->child->draw; |
… | |
… | |
686 | |
753 | |
687 | our @ISA = CFClient::UI::Base::; |
754 | our @ISA = CFClient::UI::Base::; |
688 | |
755 | |
689 | use List::Util qw(max sum); |
756 | use List::Util qw(max sum); |
690 | |
757 | |
691 | use SDL::OpenGL; |
758 | use CFClient::OpenGL; |
692 | |
759 | |
693 | sub new { |
760 | sub new { |
694 | my $class = shift; |
761 | my $class = shift; |
695 | |
762 | |
696 | $class->SUPER::new ( |
763 | $class->SUPER::new ( |
… | |
… | |
703 | my ($self, $x, $y, $child) = @_; |
770 | my ($self, $x, $y, $child) = @_; |
704 | |
771 | |
705 | $child->set_parent ($self); |
772 | $child->set_parent ($self); |
706 | $self->{children}[$y][$x] = $child; |
773 | $self->{children}[$y][$x] = $child; |
707 | |
774 | |
708 | $self->{w} = $self->{h} = -1; |
775 | $child->check_size; |
709 | $self->update; |
|
|
710 | } |
776 | } |
711 | |
777 | |
712 | # TODO: move to container class maybe? send childs a signal on removal? |
778 | # TODO: move to container class maybe? send childs a signal on removal? |
713 | sub clear { |
779 | sub clear { |
714 | my ($self) = @_; |
780 | my ($self) = @_; |
… | |
… | |
749 | (sum @$hs), |
815 | (sum @$hs), |
750 | ) |
816 | ) |
751 | } |
817 | } |
752 | |
818 | |
753 | sub size_allocate { |
819 | sub size_allocate { |
754 | my ($self, $x, $y, $w, $h) = @_; |
820 | my ($self, $w, $h) = @_; |
755 | |
|
|
756 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
757 | |
821 | |
758 | my ($ws, $hs) = $self->get_wh; |
822 | my ($ws, $hs) = $self->get_wh; |
759 | |
823 | |
760 | my $req_w = sum @$ws; |
824 | my $req_w = sum @$ws; |
761 | my $req_h = sum @$hs; |
825 | my $req_h = sum @$hs; |
… | |
… | |
783 | |
847 | |
784 | for my $c (0 .. $#$row) { |
848 | for my $c (0 .. $#$row) { |
785 | my $col_w = $ws->[$c]; |
849 | my $col_w = $ws->[$c]; |
786 | |
850 | |
787 | if (my $widget = $row->[$c]) { |
851 | if (my $widget = $row->[$c]) { |
788 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
852 | $widget->configure ($x, $y, $col_w, $row_h); |
789 | } |
853 | } |
790 | |
854 | |
791 | $x += $col_w; |
855 | $x += $col_w; |
792 | } |
856 | } |
793 | |
857 | |
… | |
… | |
838 | (List::Util::max map $_->[1], @alloc), |
902 | (List::Util::max map $_->[1], @alloc), |
839 | ) |
903 | ) |
840 | } |
904 | } |
841 | |
905 | |
842 | sub size_allocate { |
906 | sub size_allocate { |
843 | my ($self, $x, $y, $w, $h) = @_; |
907 | my ($self, $w, $h) = @_; |
844 | |
|
|
845 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
846 | |
908 | |
847 | ($h, $w) = ($w, $h); |
909 | ($h, $w) = ($w, $h); |
848 | |
910 | |
849 | my $children = $self->{children}; |
911 | my $children = $self->{children}; |
850 | |
912 | |
… | |
… | |
872 | |
934 | |
873 | my $y = 0; |
935 | my $y = 0; |
874 | for (0 .. $#$children) { |
936 | for (0 .. $#$children) { |
875 | my $child = $children->[$_]; |
937 | my $child = $children->[$_]; |
876 | my $h = $h[$_]; |
938 | my $h = $h[$_]; |
877 | $child->size_allocate ($y, 0, $h, $w); |
939 | $child->configure ($y, 0, $h, $w); |
878 | |
940 | |
879 | $y += $h; |
941 | $y += $h; |
880 | } |
942 | } |
|
|
943 | |
|
|
944 | 1 |
881 | } |
945 | } |
882 | |
946 | |
883 | ############################################################################# |
947 | ############################################################################# |
884 | |
948 | |
885 | package CFClient::UI::VBox; |
949 | package CFClient::UI::VBox; |
… | |
… | |
898 | (List::Util::sum map $_->[1], @alloc), |
962 | (List::Util::sum map $_->[1], @alloc), |
899 | ) |
963 | ) |
900 | } |
964 | } |
901 | |
965 | |
902 | sub size_allocate { |
966 | sub size_allocate { |
903 | my ($self, $x, $y, $w, $h) = @_; |
967 | my ($self, $w, $h) = @_; |
904 | |
|
|
905 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
906 | |
968 | |
907 | my $children = $self->{children}; |
969 | my $children = $self->{children}; |
908 | |
970 | |
909 | my @h = map +($_->size_request)[1], @$children; |
971 | my @h = map +($_->size_request)[1], @$children; |
910 | |
972 | |
… | |
… | |
928 | |
990 | |
929 | my $y = 0; |
991 | my $y = 0; |
930 | for (0 .. $#$children) { |
992 | for (0 .. $#$children) { |
931 | my $child = $children->[$_]; |
993 | my $child = $children->[$_]; |
932 | my $h = $h[$_]; |
994 | my $h = $h[$_]; |
933 | $child->size_allocate (0, $y, $w, $h); |
995 | $child->configure (0, $y, $w, $h); |
934 | |
996 | |
935 | $y += $h; |
997 | $y += $h; |
936 | } |
998 | } |
|
|
999 | |
|
|
1000 | 1 |
937 | } |
1001 | } |
938 | |
1002 | |
939 | ############################################################################# |
1003 | ############################################################################# |
940 | |
1004 | |
941 | package CFClient::UI::Label; |
1005 | package CFClient::UI::Label; |
942 | |
1006 | |
943 | our @ISA = CFClient::UI::Base::; |
1007 | our @ISA = CFClient::UI::Base::; |
944 | |
1008 | |
945 | use SDL::OpenGL; |
1009 | use CFClient::OpenGL; |
946 | |
1010 | |
947 | sub new { |
1011 | sub new { |
948 | my ($class, %arg) = @_; |
1012 | my ($class, %arg) = @_; |
949 | |
1013 | |
950 | my $self = $class->SUPER::new ( |
1014 | my $self = $class->SUPER::new ( |
951 | fg => [1, 1, 1], |
1015 | fg => [1, 1, 1], |
952 | fontsize => $::FONTSIZE, |
1016 | fontsize => 1, |
953 | text => "", |
1017 | text => "", |
954 | align => -1, |
1018 | align => -1, |
955 | valign => -1, |
1019 | valign => -1, |
956 | padding => 2, |
1020 | padding => 2, |
957 | layout => new CFClient::Layout, |
1021 | layout => new CFClient::Layout, |
958 | %arg |
1022 | %arg |
959 | ); |
1023 | ); |
960 | |
1024 | |
961 | $self->set_text ($self->{text}); |
1025 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
|
|
1026 | |
|
|
1027 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
|
|
1028 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
962 | |
1029 | |
963 | $self |
1030 | $self |
964 | } |
1031 | } |
965 | |
1032 | |
966 | sub escape_text { |
1033 | sub escape_text { |
… | |
… | |
974 | } |
1041 | } |
975 | |
1042 | |
976 | sub set_text { |
1043 | sub set_text { |
977 | my ($self, $text) = @_; |
1044 | my ($self, $text) = @_; |
978 | |
1045 | |
979 | $self->{text} = $text; |
|
|
980 | $self->{layout}->set_markup ($text); |
1046 | $self->{layout}->set_text ($text); |
981 | |
1047 | |
982 | delete $self->{texture}; |
1048 | delete $self->{texture}; |
983 | # $self->{w} = $self->{h} = -1; |
|
|
984 | $self->update; |
1049 | $self->update; |
985 | } |
1050 | } |
986 | |
1051 | |
987 | sub get_text { |
1052 | sub set_markup { |
988 | my ($self, $text) = @_; |
1053 | my ($self, $markup) = @_; |
989 | |
1054 | |
990 | $self->{text} |
1055 | $self->{layout}->set_markup ($markup); |
|
|
1056 | |
|
|
1057 | delete $self->{texture}; |
|
|
1058 | $self->update; |
991 | } |
1059 | } |
992 | |
1060 | |
993 | sub size_request { |
1061 | sub size_request { |
994 | my ($self) = @_; |
1062 | my ($self) = @_; |
995 | |
1063 | |
996 | $self->{layout}->set_width; |
1064 | $self->{layout}->set_width; |
997 | $self->{layout}->set_height ($self->{fontsize}); |
1065 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1066 | |
998 | my ($w, $h) = $self->{layout}->size; |
1067 | my ($w, $h) = $self->{layout}->size; |
999 | |
1068 | |
1000 | ( |
1069 | ( |
1001 | $w + $self->{padding} * 2, |
1070 | $w + $self->{padding} * 2, |
1002 | $h + $self->{padding} * 2, |
1071 | $h + $self->{padding} * 2, |
1003 | ) |
1072 | ) |
1004 | } |
1073 | } |
1005 | |
1074 | |
1006 | sub size_allocate { |
1075 | sub size_allocate { |
1007 | my ($self, $x, $y, $w, $h) = @_; |
1076 | my ($self, $w, $h) = @_; |
1008 | |
|
|
1009 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1010 | |
1077 | |
1011 | delete $self->{texture}; |
1078 | delete $self->{texture}; |
1012 | } |
|
|
1013 | |
|
|
1014 | sub update { |
|
|
1015 | my ($self) = @_; |
|
|
1016 | |
|
|
1017 | delete $self->{texture}; |
|
|
1018 | $self->SUPER::update; |
|
|
1019 | } |
1079 | } |
1020 | |
1080 | |
1021 | sub _draw { |
1081 | sub _draw { |
1022 | my ($self) = @_; |
1082 | my ($self) = @_; |
1023 | |
1083 | |
1024 | my $tex = $self->{texture} ||= do { |
1084 | my $tex = $self->{texture} ||= do { |
1025 | $self->{layout}->set_width ($self->{w}); |
1085 | $self->{layout}->set_width ($self->{w}); |
1026 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
1086 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1027 | new_from_layout CFClient::Texture $self->{layout} |
1087 | new_from_layout CFClient::Texture $self->{layout} |
1028 | }; |
1088 | }; |
1029 | |
1089 | |
1030 | glEnable GL_BLEND; |
1090 | glEnable GL_BLEND; |
1031 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1091 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1032 | glEnable GL_TEXTURE_2D; |
1092 | glEnable GL_TEXTURE_2D; |
1033 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1093 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1034 | |
1094 | |
1035 | glColor @{$self->{fg}}; |
1095 | glColor @{$self->{fg}}; |
1036 | |
1096 | |
1037 | my $x = |
1097 | $self->{ox} = int ( |
1038 | $self->{align} < 0 ? $self->{padding} |
1098 | $self->{align} < 0 ? $self->{padding} |
1039 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1099 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1040 | : ($self->{w} - $tex->{w}) * 0.5; |
1100 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1101 | ); |
1041 | |
1102 | |
1042 | my $y = |
1103 | $self->{oy} = int ( |
1043 | $self->{valign} < 0 ? $self->{padding} |
1104 | $self->{valign} < 0 ? $self->{padding} |
1044 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1105 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1045 | : ($self->{h} - $tex->{h}) * 0.5; |
1106 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1107 | ); |
1046 | |
1108 | |
1047 | $tex->draw_quad (int $x, int $y); |
1109 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1048 | |
1110 | |
1049 | glDisable GL_TEXTURE_2D; |
1111 | glDisable GL_TEXTURE_2D; |
1050 | glDisable GL_BLEND; |
1112 | glDisable GL_BLEND; |
1051 | } |
1113 | } |
1052 | |
1114 | |
1053 | ############################################################################# |
1115 | ############################################################################# |
1054 | |
1116 | |
1055 | package CFClient::UI::Entry; |
1117 | package CFClient::UI::EntryBase; |
1056 | |
1118 | |
1057 | our @ISA = CFClient::UI::Label::; |
1119 | our @ISA = CFClient::UI::Label::; |
1058 | |
1120 | |
1059 | use SDL; |
1121 | use CFClient::OpenGL; |
1060 | use SDL::OpenGL; |
|
|
1061 | |
1122 | |
1062 | sub new { |
1123 | sub new { |
1063 | my $class = shift; |
1124 | my $class = shift; |
1064 | |
1125 | |
1065 | $class->SUPER::new ( |
1126 | $class->SUPER::new ( |
… | |
… | |
1075 | } |
1136 | } |
1076 | |
1137 | |
1077 | sub _set_text { |
1138 | sub _set_text { |
1078 | my ($self, $text) = @_; |
1139 | my ($self, $text) = @_; |
1079 | |
1140 | |
1080 | my $old_text = $self->{text}; |
1141 | delete $self->{cur_h}; |
|
|
1142 | |
|
|
1143 | return if $self->{text} eq $text; |
|
|
1144 | |
|
|
1145 | delete $self->{texture}; |
1081 | |
1146 | |
1082 | $self->{last_activity} = $::NOW; |
1147 | $self->{last_activity} = $::NOW; |
1083 | |
|
|
1084 | $self->{text} = $text; |
1148 | $self->{text} = $text; |
1085 | $self->{layout}->set_width ($self->{w}); |
|
|
1086 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
|
|
1087 | |
1149 | |
1088 | $text =~ s/./*/g if $self->{hidden}; |
1150 | $text =~ s/./*/g if $self->{hidden}; |
|
|
1151 | $self->{layout}->set_text ("$text "); |
1089 | |
1152 | |
1090 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1153 | $self->emit (changed => $self->{text}); |
|
|
1154 | } |
1091 | |
1155 | |
1092 | $text = substr $text, 0, $self->{cursor}; |
1156 | sub get_text { |
1093 | utf8::encode $text; |
1157 | $_[0]{text} |
1094 | |
|
|
1095 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1096 | |
|
|
1097 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1098 | if $old_text ne $self->{text}; |
|
|
1099 | } |
1158 | } |
1100 | |
1159 | |
1101 | sub size_request { |
1160 | sub size_request { |
1102 | my ($self) = @_; |
1161 | my ($self) = @_; |
1103 | |
1162 | |
… | |
… | |
1105 | |
1164 | |
1106 | ($w + 1, $h) # add 1 for cursor |
1165 | ($w + 1, $h) # add 1 for cursor |
1107 | } |
1166 | } |
1108 | |
1167 | |
1109 | sub size_allocate { |
1168 | sub size_allocate { |
1110 | my ($self, $x, $y, $w, $h) = @_; |
1169 | my ($self, $w, $h) = @_; |
1111 | |
|
|
1112 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
|
|
1113 | |
1170 | |
1114 | $self->_set_text ($self->{text}); |
1171 | $self->_set_text ($self->{text}); |
1115 | } |
1172 | } |
1116 | |
1173 | |
1117 | sub set_text { |
1174 | sub set_text { |
… | |
… | |
1123 | } |
1180 | } |
1124 | |
1181 | |
1125 | sub key_down { |
1182 | sub key_down { |
1126 | my ($self, $ev) = @_; |
1183 | my ($self, $ev) = @_; |
1127 | |
1184 | |
1128 | my $mod = $ev->key_mod; |
1185 | my $mod = $ev->{mod}; |
1129 | my $sym = $ev->key_sym; |
1186 | my $sym = $ev->{sym}; |
1130 | |
|
|
1131 | my $uni = $ev->key_unicode; |
1187 | my $uni = $ev->{unicode}; |
1132 | |
1188 | |
1133 | my $text = $self->get_text; |
1189 | my $text = $self->get_text; |
1134 | |
1190 | |
1135 | if ($sym == SDLK_BACKSPACE) { |
1191 | if ($sym == 8) { |
1136 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1192 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1137 | } elsif ($sym == SDLK_DELETE) { |
1193 | } elsif ($sym == 127) { |
1138 | substr $text, $self->{cursor}, 1, ""; |
1194 | substr $text, $self->{cursor}, 1, ""; |
1139 | } elsif ($sym == SDLK_LEFT) { |
1195 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1140 | --$self->{cursor} if $self->{cursor}; |
1196 | --$self->{cursor} if $self->{cursor}; |
1141 | } elsif ($sym == SDLK_RIGHT) { |
1197 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1142 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1198 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1143 | } elsif ($sym == SDLK_HOME) { |
1199 | } elsif ($sym == CFClient::SDLK_HOME) { |
1144 | $self->{cursor} = 0; |
1200 | $self->{cursor} = 0; |
1145 | } elsif ($sym == SDLK_END) { |
1201 | } elsif ($sym == CFClient::SDLK_END) { |
1146 | $self->{cursor} = length $text; |
1202 | $self->{cursor} = length $text; |
1147 | } elsif ($sym == SDLK_ESCAPE) { |
1203 | } elsif ($sym == 27) { |
1148 | $self->emit ('escape'); |
1204 | $self->emit ('escape'); |
1149 | } elsif ($uni) { |
1205 | } elsif ($uni) { |
1150 | substr $text, $self->{cursor}++, 0, chr $uni; |
1206 | substr $text, $self->{cursor}++, 0, chr $uni; |
1151 | } |
1207 | } |
1152 | |
1208 | |
… | |
… | |
1207 | |
1263 | |
1208 | $self->SUPER::_draw; |
1264 | $self->SUPER::_draw; |
1209 | |
1265 | |
1210 | #TODO: force update every cursor change :( |
1266 | #TODO: force update every cursor change :( |
1211 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
1267 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
|
|
1268 | |
|
|
1269 | unless (exists $self->{cur_h}) { |
|
|
1270 | my $text = substr $self->{text}, 0, $self->{cursor}; |
|
|
1271 | utf8::encode $text; |
|
|
1272 | |
|
|
1273 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
|
|
1274 | } |
|
|
1275 | |
1212 | glColor @{$self->{fg}}; |
1276 | glColor @{$self->{fg}}; |
1213 | glBegin GL_LINES; |
1277 | glBegin GL_LINES; |
1214 | glVertex $self->{cur_x}, $self->{cur_y}; |
|
|
1215 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1278 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
|
|
1279 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1216 | glEnd; |
1280 | glEnd; |
1217 | } |
1281 | } |
1218 | } |
1282 | } |
1219 | |
1283 | |
1220 | package CFClient::UI::LineEntry; |
1284 | package CFClient::UI::Entry; |
1221 | |
1285 | |
1222 | our @ISA = CFClient::UI::Entry::; |
1286 | our @ISA = CFClient::UI::EntryBase::; |
1223 | |
1287 | |
1224 | use SDL; |
1288 | use CFClient::OpenGL; |
1225 | use SDL::OpenGL; |
|
|
1226 | |
1289 | |
1227 | sub key_down { |
1290 | sub key_down { |
1228 | my ($self, $ev) = @_; |
1291 | my ($self, $ev) = @_; |
1229 | |
1292 | |
1230 | my $sym = $ev->key_sym; |
1293 | my $sym = $ev->{sym}; |
1231 | |
1294 | |
1232 | if ($sym == SDLK_RETURN) { |
1295 | if ($sym == 13) { |
1233 | $self->emit (activate => $self->get_text); |
1296 | $self->emit (activate => $self->get_text); |
1234 | $self->update; |
1297 | $self->update; |
1235 | |
1298 | |
1236 | } else { |
1299 | } else { |
1237 | $self->SUPER::key_down ($ev); |
1300 | $self->SUPER::key_down ($ev); |
… | |
… | |
1243 | |
1306 | |
1244 | package CFClient::UI::Button; |
1307 | package CFClient::UI::Button; |
1245 | |
1308 | |
1246 | our @ISA = CFClient::UI::Label::; |
1309 | our @ISA = CFClient::UI::Label::; |
1247 | |
1310 | |
1248 | use SDL; |
1311 | use CFClient::OpenGL; |
1249 | use SDL::OpenGL; |
|
|
1250 | |
1312 | |
1251 | my @tex = |
1313 | my @tex = |
1252 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1314 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1253 | qw(b1_button_active.png); |
1315 | qw(b1_button_active.png); |
1254 | |
1316 | |
… | |
… | |
1257 | |
1319 | |
1258 | $class->SUPER::new ( |
1320 | $class->SUPER::new ( |
1259 | padding => 4, |
1321 | padding => 4, |
1260 | fg => [1, 1, 1], |
1322 | fg => [1, 1, 1], |
1261 | bg => [1, 1, 1, 0.2], |
1323 | bg => [1, 1, 1, 0.2], |
1262 | active_fg => [1, 1, 0], |
1324 | active_fg => [0, 0, 1], |
1263 | can_hover => 1, |
1325 | can_hover => 1, |
|
|
1326 | align => 0, |
|
|
1327 | valign => 0, |
1264 | @_ |
1328 | @_ |
1265 | ) |
1329 | ) |
1266 | } |
1330 | } |
1267 | |
1331 | |
1268 | sub button_up { |
1332 | sub button_up { |
… | |
… | |
1305 | |
1369 | |
1306 | my @tex = |
1370 | my @tex = |
1307 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1371 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1308 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1372 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1309 | |
1373 | |
1310 | use SDL; |
1374 | use CFClient::OpenGL; |
1311 | use SDL::OpenGL; |
|
|
1312 | |
1375 | |
1313 | sub new { |
1376 | sub new { |
1314 | my $class = shift; |
1377 | my $class = shift; |
1315 | |
1378 | |
1316 | $class->SUPER::new ( |
1379 | $class->SUPER::new ( |
… | |
… | |
1327 | my ($self) = @_; |
1390 | my ($self) = @_; |
1328 | |
1391 | |
1329 | ($self->{padding} * 2 + 6) x 2 |
1392 | ($self->{padding} * 2 + 6) x 2 |
1330 | } |
1393 | } |
1331 | |
1394 | |
1332 | sub size_allocate { |
|
|
1333 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1334 | |
|
|
1335 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1336 | } |
|
|
1337 | |
|
|
1338 | sub button_down { |
1395 | sub button_down { |
1339 | my ($self, $ev, $x, $y) = @_; |
1396 | my ($self, $ev, $x, $y) = @_; |
1340 | |
1397 | |
1341 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1398 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1342 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1399 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
… | |
… | |
1368 | glDisable GL_BLEND; |
1425 | glDisable GL_BLEND; |
1369 | } |
1426 | } |
1370 | |
1427 | |
1371 | ############################################################################# |
1428 | ############################################################################# |
1372 | |
1429 | |
|
|
1430 | package CFClient::UI::VGauge; |
|
|
1431 | |
|
|
1432 | our @ISA = CFClient::UI::Base::; |
|
|
1433 | |
|
|
1434 | use CFClient::OpenGL; |
|
|
1435 | |
|
|
1436 | my %tex = ( |
|
|
1437 | food => [ |
|
|
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1439 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1440 | ], |
|
|
1441 | grace => [ |
|
|
1442 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1443 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1444 | ], |
|
|
1445 | hp => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | mana => [ |
|
|
1450 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1451 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1452 | ], |
|
|
1453 | ); |
|
|
1454 | |
|
|
1455 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1456 | sub new { |
|
|
1457 | my $class = shift; |
|
|
1458 | |
|
|
1459 | my $self = $class->SUPER::new ( |
|
|
1460 | gauge => 'food', |
|
|
1461 | @_ |
|
|
1462 | ); |
|
|
1463 | |
|
|
1464 | $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h}; |
|
|
1465 | |
|
|
1466 | $self |
|
|
1467 | } |
|
|
1468 | |
|
|
1469 | sub size_request { |
|
|
1470 | my ($self) = @_; |
|
|
1471 | |
|
|
1472 | my $tex = $tex{$self->{gauge}}[0]; |
|
|
1473 | |
|
|
1474 | @$tex{qw(w h)} |
|
|
1475 | } |
|
|
1476 | |
|
|
1477 | sub set_max { |
|
|
1478 | my ($self, $max) = @_; |
|
|
1479 | |
|
|
1480 | $self->{max_val} = $max; |
|
|
1481 | } |
|
|
1482 | |
|
|
1483 | sub set_value { |
|
|
1484 | my ($self, $val, $max) = @_; |
|
|
1485 | |
|
|
1486 | $self->set_max ($max) |
|
|
1487 | if defined $max; |
|
|
1488 | |
|
|
1489 | $max = $self->{max_val}; |
|
|
1490 | $self->{val} = $val; |
|
|
1491 | |
|
|
1492 | $self->update; |
|
|
1493 | } |
|
|
1494 | |
|
|
1495 | sub _draw { |
|
|
1496 | my ($self) = @_; |
|
|
1497 | |
|
|
1498 | my $tex = $tex{$self->{gauge}}; |
|
|
1499 | |
|
|
1500 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1501 | |
|
|
1502 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1503 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1504 | |
|
|
1505 | my $t1 = $tex->[0]; |
|
|
1506 | my $t2 = $tex->[1]; |
|
|
1507 | |
|
|
1508 | glEnable GL_BLEND; |
|
|
1509 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1510 | glEnable GL_TEXTURE_2D; |
|
|
1511 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1512 | |
|
|
1513 | my $h1 = $self->{h} - $ycut * $self->{h}; |
|
|
1514 | my $h2 = $ycut * $self->{h}; |
|
|
1515 | |
|
|
1516 | my $yp = 0; |
|
|
1517 | |
|
|
1518 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
|
|
1519 | glBegin GL_QUADS; |
|
|
1520 | glTexCoord 0 , 0; glVertex 0 , $yp; |
|
|
1521 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
|
|
1522 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
|
|
1523 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
|
|
1524 | glEnd; |
|
|
1525 | |
|
|
1526 | $yp += $h1; |
|
|
1527 | |
|
|
1528 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
|
|
1529 | glBegin GL_QUADS; |
|
|
1530 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
|
|
1531 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
|
|
1532 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
|
|
1533 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
|
|
1534 | glEnd; |
|
|
1535 | |
|
|
1536 | glDisable GL_BLEND; |
|
|
1537 | glDisable GL_TEXTURE_2D; |
|
|
1538 | } |
|
|
1539 | |
|
|
1540 | ############################################################################# |
|
|
1541 | |
1373 | package CFClient::UI::Slider; |
1542 | package CFClient::UI::Slider; |
1374 | |
1543 | |
1375 | use strict; |
1544 | use strict; |
1376 | |
1545 | |
1377 | use SDL::OpenGL; |
1546 | use CFClient::OpenGL; |
1378 | |
1547 | |
1379 | our @ISA = CFClient::UI::DrawBG::; |
1548 | our @ISA = CFClient::UI::DrawBG::; |
1380 | |
1549 | |
1381 | my @tex = |
1550 | my @tex = |
1382 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1551 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1392 | # TODO: calculations are off |
1561 | # TODO: calculations are off |
1393 | my $self = $class->SUPER::new ( |
1562 | my $self = $class->SUPER::new ( |
1394 | fg => [1, 1, 1], |
1563 | fg => [1, 1, 1], |
1395 | active_fg => [0, 0, 0], |
1564 | active_fg => [0, 0, 0], |
1396 | range => [0, 0, 100, 10], |
1565 | range => [0, 0, 100, 10], |
1397 | req_w => 40, |
1566 | req_w => 20, |
1398 | req_h => 13, |
1567 | req_h => 20, |
1399 | vertical => 0, |
1568 | vertical => 0, |
1400 | can_hover => 1, |
1569 | can_hover => 1, |
1401 | inner_pad => 5, |
1570 | inner_pad => 5, |
1402 | @_ |
1571 | @_ |
1403 | ); |
1572 | ); |
… | |
… | |
1507 | |
1676 | |
1508 | package CFClient::UI::TextView; |
1677 | package CFClient::UI::TextView; |
1509 | |
1678 | |
1510 | our @ISA = CFClient::UI::HBox::; |
1679 | our @ISA = CFClient::UI::HBox::; |
1511 | |
1680 | |
1512 | use SDL::OpenGL; |
1681 | use CFClient::OpenGL; |
1513 | |
1682 | |
1514 | sub new { |
1683 | sub new { |
1515 | my $class = shift; |
1684 | my $class = shift; |
1516 | |
1685 | |
1517 | my $self = $class->SUPER::new ( |
1686 | my $self = $class->SUPER::new ( |
1518 | req_w => $::WIDTH / 6, |
|
|
1519 | req_h => $::HEIGHT / 6, |
|
|
1520 | fontsize => $::FONTSIZE, |
1687 | fontsize => 1, |
1521 | @_, |
1688 | @_, |
1522 | |
1689 | |
1523 | layout => (new CFClient::Layout), |
1690 | layout => (new CFClient::Layout), |
1524 | par => [], |
1691 | par => [], |
1525 | height => 0, |
1692 | height => 0, |
… | |
… | |
1546 | sub text_height { |
1713 | sub text_height { |
1547 | my ($self, $text) = @_; |
1714 | my ($self, $text) = @_; |
1548 | |
1715 | |
1549 | my $layout = $self->{layout}; |
1716 | my $layout = $self->{layout}; |
1550 | |
1717 | |
1551 | $layout->set_height ($self->{fontsize}); |
1718 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1552 | $layout->set_width ($self->{w}); |
1719 | $layout->set_width ($self->{w}); |
1553 | $layout->set_text ($text); |
1720 | $layout->set_text ($text); |
1554 | |
1721 | |
1555 | ($layout->size)[1] |
1722 | ($layout->size)[1] |
1556 | } |
1723 | } |
… | |
… | |
1560 | |
1727 | |
1561 | $self->{need_reflow}++; |
1728 | $self->{need_reflow}++; |
1562 | $self->update; |
1729 | $self->update; |
1563 | } |
1730 | } |
1564 | |
1731 | |
1565 | sub size_request { |
|
|
1566 | my ($self) = @_; |
|
|
1567 | |
|
|
1568 | ($self->{req_w}, $self->{req_h}) |
|
|
1569 | } |
|
|
1570 | |
|
|
1571 | sub size_allocate { |
1732 | sub size_allocate { |
1572 | my ($self, $x, $y, $w, $h) = @_; |
1733 | my ($self, $w, $h) = @_; |
1573 | |
1734 | |
1574 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1735 | $self->SUPER::size_allocate ($w, $h); |
1575 | |
1736 | |
1576 | $self->{layout}->set_height ($self->{fontsize}); |
1737 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1577 | $self->{layout}->set_width ($self->{w}); |
1738 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1578 | |
1739 | |
1579 | $self->reflow; |
1740 | $self->reflow; |
1580 | } |
1741 | } |
1581 | |
1742 | |
1582 | sub add_paragraph { |
1743 | sub add_paragraph { |
… | |
… | |
1669 | |
1830 | |
1670 | } |
1831 | } |
1671 | |
1832 | |
1672 | ############################################################################# |
1833 | ############################################################################# |
1673 | |
1834 | |
1674 | package CFClient::UI::MapWidget; |
|
|
1675 | |
|
|
1676 | use strict; |
|
|
1677 | |
|
|
1678 | use List::Util qw(min max); |
|
|
1679 | |
|
|
1680 | use SDL; |
|
|
1681 | use SDL::OpenGL; |
|
|
1682 | |
|
|
1683 | our @ISA = CFClient::UI::Base::; |
|
|
1684 | |
|
|
1685 | sub new { |
|
|
1686 | my $class = shift; |
|
|
1687 | |
|
|
1688 | $class->SUPER::new ( |
|
|
1689 | z => -1, |
|
|
1690 | can_focus => 1, |
|
|
1691 | list => (glGenLists 1), |
|
|
1692 | @_ |
|
|
1693 | ) |
|
|
1694 | } |
|
|
1695 | |
|
|
1696 | sub key_down { |
|
|
1697 | print "MAPKEYDOWN\n"; |
|
|
1698 | } |
|
|
1699 | |
|
|
1700 | sub key_up { |
|
|
1701 | } |
|
|
1702 | |
|
|
1703 | sub button_down { |
|
|
1704 | my ($self, $ev, $x, $y) = @_; |
|
|
1705 | |
|
|
1706 | $self->focus_in; |
|
|
1707 | |
|
|
1708 | if ($ev->button == 2) { |
|
|
1709 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1710 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1711 | |
|
|
1712 | $self->{motion} = sub { |
|
|
1713 | my ($ev, $x, $y) = @_; |
|
|
1714 | |
|
|
1715 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1716 | |
|
|
1717 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1718 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1719 | |
|
|
1720 | $self->update; |
|
|
1721 | }; |
|
|
1722 | } |
|
|
1723 | } |
|
|
1724 | |
|
|
1725 | sub button_up { |
|
|
1726 | my ($self, $ev, $x, $y) = @_; |
|
|
1727 | |
|
|
1728 | delete $self->{motion}; |
|
|
1729 | } |
|
|
1730 | |
|
|
1731 | sub mouse_motion { |
|
|
1732 | my ($self, $ev, $x, $y) = @_; |
|
|
1733 | |
|
|
1734 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1735 | } |
|
|
1736 | |
|
|
1737 | sub size_request { |
|
|
1738 | ( |
|
|
1739 | 1 + 32 * int $::WIDTH / 32, |
|
|
1740 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1741 | ) |
|
|
1742 | } |
|
|
1743 | |
|
|
1744 | sub update { |
|
|
1745 | my ($self) = @_; |
|
|
1746 | |
|
|
1747 | $self->{need_update} = 1; |
|
|
1748 | $self->SUPER::update; |
|
|
1749 | } |
|
|
1750 | |
|
|
1751 | sub draw { |
|
|
1752 | my ($self) = @_; |
|
|
1753 | |
|
|
1754 | if (delete $self->{need_update}) { |
|
|
1755 | glNewList $self->{list}, GL_COMPILE; |
|
|
1756 | |
|
|
1757 | if ($::MAP) { |
|
|
1758 | my $sw = int $::WIDTH / 32; |
|
|
1759 | my $sh = int $::HEIGHT / 32; |
|
|
1760 | |
|
|
1761 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1762 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1763 | |
|
|
1764 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1765 | |
|
|
1766 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1767 | |
|
|
1768 | if ($::CFG->{fow_enable}) { |
|
|
1769 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1770 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1771 | glConvolutionFilter2D |
|
|
1772 | GL_CONVOLUTION_2D, |
|
|
1773 | GL_ALPHA, |
|
|
1774 | 3, 3, |
|
|
1775 | GL_ALPHA, GL_FLOAT, |
|
|
1776 | pack "f*", |
|
|
1777 | 0.1, 0.1, 0.1, |
|
|
1778 | 0.1, 0.2, 0.1, |
|
|
1779 | 0.1, 0.1, 0.1, |
|
|
1780 | ; |
|
|
1781 | glEnable GL_CONVOLUTION_2D; |
|
|
1782 | } |
|
|
1783 | |
|
|
1784 | $self->{fow_texture} = new CFClient::Texture |
|
|
1785 | w => $w, |
|
|
1786 | h => $h, |
|
|
1787 | data => $data, |
|
|
1788 | internalformat => GL_ALPHA, |
|
|
1789 | format => GL_ALPHA; |
|
|
1790 | |
|
|
1791 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1792 | |
|
|
1793 | glEnable GL_BLEND; |
|
|
1794 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1795 | glEnable GL_TEXTURE_2D; |
|
|
1796 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1797 | |
|
|
1798 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1799 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1800 | |
|
|
1801 | glDisable GL_TEXTURE_2D; |
|
|
1802 | glDisable GL_BLEND; |
|
|
1803 | } |
|
|
1804 | |
|
|
1805 | # HACK BEGIN |
|
|
1806 | { |
|
|
1807 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1808 | my ($w, $h) = (250, 250); |
|
|
1809 | |
|
|
1810 | glEnable GL_BLEND; |
|
|
1811 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1812 | glEnable GL_TEXTURE_2D; |
|
|
1813 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1814 | |
|
|
1815 | $self->{mapmap_texture} = |
|
|
1816 | new CFClient::Texture |
|
|
1817 | w => $w, |
|
|
1818 | h => $h, |
|
|
1819 | data => $::MAP->mapmap ($w, $h), |
|
|
1820 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
|
|
1821 | |
|
|
1822 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
1823 | |
|
|
1824 | glDisable GL_TEXTURE_2D; |
|
|
1825 | glDisable GL_BLEND; |
|
|
1826 | } |
|
|
1827 | # HACK END |
|
|
1828 | } |
|
|
1829 | |
|
|
1830 | glEndList; |
|
|
1831 | } |
|
|
1832 | |
|
|
1833 | glPushMatrix; |
|
|
1834 | glCallList $self->{list}; |
|
|
1835 | glPopMatrix; |
|
|
1836 | |
|
|
1837 | if ($FOCUS != $self) { |
|
|
1838 | glColor 64/255, 64/255, 64/255; |
|
|
1839 | glLogicOp GL_AND; |
|
|
1840 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1841 | glBegin GL_QUADS; |
|
|
1842 | glVertex 0, 0; |
|
|
1843 | glVertex 0, $::HEIGHT; |
|
|
1844 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1845 | glVertex $::WIDTH, 0; |
|
|
1846 | glEnd; |
|
|
1847 | glDisable GL_COLOR_LOGIC_OP; |
|
|
1848 | } |
|
|
1849 | } |
|
|
1850 | |
|
|
1851 | my %DIR = ( |
|
|
1852 | SDLK_KP8, [1, "north"], |
|
|
1853 | SDLK_KP9, [2, "northeast"], |
|
|
1854 | SDLK_KP6, [3, "east"], |
|
|
1855 | SDLK_KP3, [4, "southeast"], |
|
|
1856 | SDLK_KP2, [5, "south"], |
|
|
1857 | SDLK_KP1, [6, "southwest"], |
|
|
1858 | SDLK_KP4, [7, "west"], |
|
|
1859 | SDLK_KP7, [8, "northwest"], |
|
|
1860 | |
|
|
1861 | SDLK_UP, [1, "north"], |
|
|
1862 | SDLK_RIGHT, [3, "east"], |
|
|
1863 | SDLK_DOWN, [5, "south"], |
|
|
1864 | SDLK_LEFT, [7, "west"], |
|
|
1865 | ); |
|
|
1866 | |
|
|
1867 | sub key_down { |
|
|
1868 | my ($self, $ev) = @_; |
|
|
1869 | |
|
|
1870 | my $mod = $ev->key_mod; |
|
|
1871 | my $sym = $ev->key_sym; |
|
|
1872 | |
|
|
1873 | if ($sym == SDLK_KP5) { |
|
|
1874 | $::CONN->user_send ("command stay fire"); |
|
|
1875 | } elsif ($sym == SDLK_a) { |
|
|
1876 | $::CONN->user_send ("command apply"); |
|
|
1877 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1878 | $self->emit ('activate_console'); |
|
|
1879 | } elsif ($sym == SDLK_SLASH) { |
|
|
1880 | $self->emit ('activate_console' => '/'); |
|
|
1881 | } elsif (exists $DIR{$sym}) { |
|
|
1882 | if ($mod & KMOD_SHIFT) { |
|
|
1883 | $self->{shft}++; |
|
|
1884 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
|
|
1885 | } elsif ($mod & KMOD_CTRL) { |
|
|
1886 | $self->{ctrl}++; |
|
|
1887 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
|
|
1888 | } else { |
|
|
1889 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
|
|
1890 | } |
|
|
1891 | } |
|
|
1892 | } |
|
|
1893 | |
|
|
1894 | sub key_up { |
|
|
1895 | my ($self, $ev) = @_; |
|
|
1896 | |
|
|
1897 | my $mod = $ev->key_mod; |
|
|
1898 | my $sym = $ev->key_sym; |
|
|
1899 | |
|
|
1900 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
1901 | $::CONN->user_send ("command fire_stop"); |
|
|
1902 | } |
|
|
1903 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
1904 | $::CONN->user_send ("command run_stop"); |
|
|
1905 | } |
|
|
1906 | } |
|
|
1907 | |
|
|
1908 | ############################################################################# |
|
|
1909 | |
|
|
1910 | package CFClient::UI::Animator; |
1835 | package CFClient::UI::Animator; |
1911 | |
1836 | |
1912 | use SDL::OpenGL; |
1837 | use CFClient::OpenGL; |
1913 | |
1838 | |
1914 | our @ISA = CFClient::UI::Bin::; |
1839 | our @ISA = CFClient::UI::Bin::; |
1915 | |
1840 | |
1916 | sub moveto { |
1841 | sub moveto { |
1917 | my ($self, $x, $y) = @_; |
1842 | my ($self, $x, $y) = @_; |
… | |
… | |
1990 | |
1915 | |
1991 | package CFClient::UI::Root; |
1916 | package CFClient::UI::Root; |
1992 | |
1917 | |
1993 | our @ISA = CFClient::UI::Container::; |
1918 | our @ISA = CFClient::UI::Container::; |
1994 | |
1919 | |
1995 | use SDL::OpenGL; |
1920 | use CFClient::OpenGL; |
|
|
1921 | |
|
|
1922 | sub check_size { |
|
|
1923 | my ($self) = @_; |
|
|
1924 | |
|
|
1925 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
|
|
1926 | } |
1996 | |
1927 | |
1997 | sub size_request { |
1928 | sub size_request { |
1998 | ($::WIDTH, $::HEIGHT) |
1929 | ($::WIDTH, $::HEIGHT) |
1999 | } |
1930 | } |
2000 | |
1931 | |
2001 | sub size_allocate { |
1932 | sub configure { |
2002 | my ($self, $x, $y, $w, $h) = @_; |
1933 | my ($self, $x, $y, $w, $h) = @_; |
2003 | |
1934 | |
2004 | $self->_size_allocate ($x, $y, $w, $h); |
1935 | $self->SUPER::configure ($x, $y, $w, $h); |
2005 | |
1936 | |
2006 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
1937 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2007 | for @{$self->{children}}; |
1938 | for @{$self->{children}}; |
2008 | } |
1939 | } |
2009 | |
1940 | |
2010 | sub _topleft { |
1941 | sub _topleft { |
2011 | my ($self, $x, $y) = @_; |
1942 | my ($self, $x, $y) = @_; |
… | |
… | |
2014 | } |
1945 | } |
2015 | |
1946 | |
2016 | sub update { |
1947 | sub update { |
2017 | my ($self) = @_; |
1948 | my ($self) = @_; |
2018 | |
1949 | |
2019 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
1950 | $self->check_size; |
2020 | ::refresh (); |
1951 | ::refresh (); |
2021 | } |
1952 | } |
2022 | |
1953 | |
2023 | sub add { |
1954 | sub add { |
2024 | my ($self, $widget) = @_; |
1955 | my ($self, $child) = @_; |
2025 | |
1956 | |
2026 | $self->SUPER::add ($widget); |
1957 | $self->SUPER::add ($child); |
2027 | |
|
|
2028 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
|
|
2029 | } |
1958 | } |
2030 | |
1959 | |
2031 | sub on_refresh { |
1960 | sub on_refresh { |
2032 | my ($self, $id, $cb) = @_; |
1961 | my ($self, $id, $cb) = @_; |
2033 | |
1962 | |