… | |
… | |
237 | $self->{w} = $w; |
237 | $self->{w} = $w; |
238 | $self->{h} = $h; |
238 | $self->{h} = $h; |
239 | |
239 | |
240 | $self->size_allocate ($w, $h); |
240 | $self->size_allocate ($w, $h); |
241 | $self->update; |
241 | $self->update; |
|
|
242 | $self->emit (size_allocate => $w, $h); |
242 | } |
243 | } |
243 | } |
244 | } |
244 | |
245 | |
245 | sub size_allocate { |
246 | sub size_allocate { |
246 | # nothing to be done |
247 | # nothing to be done |
247 | } |
248 | } |
248 | |
249 | |
249 | sub children { |
250 | sub children { |
250 | } |
251 | } |
251 | |
252 | |
252 | # call when resoltuion changes etc. |
253 | # call when resolution changes etc. |
253 | sub reconfigure { |
254 | sub reconfigure { |
254 | my ($self) = @_; |
255 | my ($self) = @_; |
255 | |
256 | |
256 | $_->reconfigure |
257 | $_->reconfigure |
257 | for $self->children; |
258 | for $self->children; |
258 | |
259 | |
259 | $_->check_size; |
260 | $self->check_size; |
|
|
261 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
262 | $self->update; |
260 | } |
263 | } |
261 | |
264 | |
262 | sub set_max_size { |
265 | sub set_max_size { |
263 | my ($self, $w, $h) = @_; |
266 | my ($self, $w, $h) = @_; |
264 | |
267 | |
… | |
… | |
539 | sort { $a->{z} <=> $b->{z} } |
542 | sort { $a->{z} <=> $b->{z} } |
540 | @{$self->{children}}, $child |
543 | @{$self->{children}}, $child |
541 | ]; |
544 | ]; |
542 | |
545 | |
543 | $child->check_size; |
546 | $child->check_size; |
|
|
547 | $self->update; |
544 | } |
548 | } |
545 | |
549 | |
546 | sub children { |
550 | sub children { |
547 | @{ $_[0]{children} } |
551 | @{ $_[0]{children} } |
548 | } |
552 | } |
… | |
… | |
567 | |
571 | |
568 | for (@$children) { |
572 | for (@$children) { |
569 | delete $_->{parent}; |
573 | delete $_->{parent}; |
570 | $_->hide; |
574 | $_->hide; |
571 | } |
575 | } |
|
|
576 | |
|
|
577 | $self->check_size; |
|
|
578 | $self->update; |
572 | } |
579 | } |
573 | |
580 | |
574 | sub find_widget { |
581 | sub find_widget { |
575 | my ($self, $x, $y) = @_; |
582 | my ($self, $x, $y) = @_; |
576 | |
583 | |
… | |
… | |
662 | |
669 | |
663 | $self->SUPER::size_allocate ($w, $h); |
670 | $self->SUPER::size_allocate ($w, $h); |
664 | $self->update; |
671 | $self->update; |
665 | } |
672 | } |
666 | |
673 | |
|
|
674 | sub _render { |
|
|
675 | $_[0]{children}[0]->draw; |
|
|
676 | } |
|
|
677 | |
667 | sub render_child { |
678 | sub render_child { |
668 | my ($self) = @_; |
679 | my ($self) = @_; |
669 | |
680 | |
670 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
681 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
671 | glClearColor 0, 0, 0, 0; |
682 | glClearColor 0, 0, 0, 0; |
672 | glClear GL_COLOR_BUFFER_BIT; |
683 | glClear GL_COLOR_BUFFER_BIT; |
673 | $self->child->draw; |
684 | |
|
|
685 | $self->_render; |
674 | # glColorMask 1, 1, 1, 0; |
686 | # glColorMask 1, 1, 1, 0; |
675 | # glEnable GL_BLEND; |
687 | # glEnable GL_BLEND; |
676 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
688 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
677 | # glRasterPos 0, 0; |
689 | # glRasterPos 0, 0; |
678 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
690 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
… | |
… | |
705 | |
717 | |
706 | package CFClient::UI::ViewPort; |
718 | package CFClient::UI::ViewPort; |
707 | |
719 | |
708 | our @ISA = CFClient::UI::Window::; |
720 | our @ISA = CFClient::UI::Window::; |
709 | |
721 | |
710 | sub new { die } |
|
|
711 | |
|
|
712 | sub size_request { |
722 | sub size_request { |
713 | my ($self) = @_; |
723 | my ($self) = @_; |
714 | |
724 | |
715 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
725 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
716 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
726 | $self->child->configure (0, 0, @$self{qw(child_w child_h)}); |
717 | |
727 | |
718 | @$self{qw(child_w child_h)} |
728 | @$self{qw(child_w child_h)} |
719 | } |
729 | } |
720 | |
730 | |
721 | sub _draw { |
731 | sub size_allocate { |
722 | my ($self) = @_; |
732 | my ($self, $w, $h) = @_; |
723 | |
733 | |
724 | $self->{children}[1]->draw; |
734 | $self->update; |
725 | } |
735 | } |
726 | |
736 | |
|
|
737 | sub set_offset { |
|
|
738 | my ($self, $x, $y) = @_; |
|
|
739 | |
|
|
740 | $self->{view_x} = int $x; |
|
|
741 | $self->{view_y} = int $y; |
|
|
742 | |
|
|
743 | $self->update; |
|
|
744 | } |
|
|
745 | |
|
|
746 | # hmm, this does not work for topleft of $self... but we should not aks for that |
|
|
747 | sub _topleft { |
|
|
748 | my ($self, $x, $y) = @_; |
|
|
749 | |
|
|
750 | $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y}) |
|
|
751 | } |
|
|
752 | |
|
|
753 | sub find_widget { |
|
|
754 | my ($self, $x, $y) = @_; |
|
|
755 | |
|
|
756 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
757 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
|
|
758 | ) { |
|
|
759 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
|
|
760 | } else { |
|
|
761 | $self->CFClient::UI::Base::find_widget ($x, $y) |
|
|
762 | } |
|
|
763 | } |
|
|
764 | |
|
|
765 | sub _render { |
|
|
766 | my ($self) = @_; |
|
|
767 | |
|
|
768 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
|
|
769 | |
|
|
770 | $self->SUPER::_render; |
|
|
771 | } |
|
|
772 | |
|
|
773 | ############################################################################# |
|
|
774 | |
|
|
775 | package CFClient::UI::ScrolledWindow; |
|
|
776 | |
|
|
777 | our @ISA = CFClient::UI::HBox::; |
|
|
778 | |
|
|
779 | sub new { |
|
|
780 | my $class = shift; |
|
|
781 | |
|
|
782 | my $self; |
|
|
783 | |
|
|
784 | my $slider = new CFClient::UI::Slider |
|
|
785 | vertical => 1, |
|
|
786 | range => [0, 0, 1, 0.01], # HACK fix |
|
|
787 | connect_changed => sub { |
|
|
788 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
|
|
789 | }, |
|
|
790 | ; |
|
|
791 | |
|
|
792 | $self = $class->SUPER::new ( |
|
|
793 | vp => (new CFClient::UI::ViewPort), |
|
|
794 | slider => $slider, |
|
|
795 | @_, |
|
|
796 | ); |
|
|
797 | |
|
|
798 | $self->{vp}->add ($self->{scrolled}); |
|
|
799 | $self->add ($self->{vp}); |
|
|
800 | $self->add ($self->{slider}); |
|
|
801 | |
|
|
802 | $self |
|
|
803 | } |
|
|
804 | |
|
|
805 | #TODO# update range on size_allocate depeneing on child |
|
|
806 | # update viewport offset on scroll |
727 | |
807 | |
728 | ############################################################################# |
808 | ############################################################################# |
729 | |
809 | |
730 | package CFClient::UI::Frame; |
810 | package CFClient::UI::Frame; |
731 | |
811 | |
… | |
… | |
1244 | |
1324 | |
1245 | delete $self->{texture}; |
1325 | delete $self->{texture}; |
1246 | $self->SUPER::update; |
1326 | $self->SUPER::update; |
1247 | } |
1327 | } |
1248 | |
1328 | |
1249 | sub reconfigure { |
|
|
1250 | my ($self) = @_; |
|
|
1251 | |
|
|
1252 | delete $self->{texture}; |
|
|
1253 | } |
|
|
1254 | |
|
|
1255 | sub set_text { |
1329 | sub set_text { |
1256 | my ($self, $text) = @_; |
1330 | my ($self, $text) = @_; |
1257 | |
1331 | |
1258 | return if $self->{text} eq "T$text"; |
1332 | return if $self->{text} eq "T$text"; |
1259 | $self->{text} = "T$text"; |
1333 | $self->{text} = "T$text"; |
… | |
… | |
1312 | sub set_fontsize { |
1386 | sub set_fontsize { |
1313 | my ($self, $fontsize) = @_; |
1387 | my ($self, $fontsize) = @_; |
1314 | |
1388 | |
1315 | $self->{fontsize} = $fontsize; |
1389 | $self->{fontsize} = $fontsize; |
1316 | delete $self->{texture}; |
1390 | delete $self->{texture}; |
|
|
1391 | |
|
|
1392 | $self->update; |
1317 | $self->check_size; |
1393 | $self->check_size; |
1318 | $self->update; |
|
|
1319 | } |
1394 | } |
1320 | |
1395 | |
1321 | sub _draw { |
1396 | sub _draw { |
1322 | my ($self) = @_; |
1397 | my ($self) = @_; |
1323 | |
1398 | |
… | |
… | |
1957 | # TODO: calculations are off |
2032 | # TODO: calculations are off |
1958 | my $self = $class->SUPER::new ( |
2033 | my $self = $class->SUPER::new ( |
1959 | fg => [1, 1, 1], |
2034 | fg => [1, 1, 1], |
1960 | active_fg => [0, 0, 0], |
2035 | active_fg => [0, 0, 0], |
1961 | range => [0, 0, 100, 10], |
2036 | range => [0, 0, 100, 10], |
1962 | req_w => 20, |
2037 | req_w => $::WIDTH / 80, |
1963 | req_h => 20, |
2038 | req_h => $::WIDTH / 80, |
1964 | vertical => 0, |
2039 | vertical => 0, |
1965 | can_hover => 1, |
2040 | can_hover => 1, |
1966 | inner_pad => 5, |
2041 | inner_pad => 5, |
1967 | @_ |
2042 | @_ |
1968 | ); |
2043 | ); |
… | |
… | |
2405 | } |
2480 | } |
2406 | |
2481 | |
2407 | sub _draw { |
2482 | sub _draw { |
2408 | my ($self) = @_; |
2483 | my ($self) = @_; |
2409 | |
2484 | |
|
|
2485 | return unless $::CONN;#d# manage and cache textures differently |
2410 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2486 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2411 | |
2487 | |
2412 | # TODO animation |
2488 | # TODO animation |
2413 | if ($tex) { |
2489 | if ($tex) { |
2414 | glEnable GL_BLEND; |
2490 | glEnable GL_BLEND; |
… | |
… | |
2422 | } |
2498 | } |
2423 | } |
2499 | } |
2424 | |
2500 | |
2425 | ############################################################################# |
2501 | ############################################################################# |
2426 | |
2502 | |
|
|
2503 | package CFClient::UI::InventoryItem; |
|
|
2504 | |
|
|
2505 | our @ISA = CFClient::UI::HBox::; |
|
|
2506 | |
|
|
2507 | sub new { |
|
|
2508 | my $class = shift; |
|
|
2509 | |
|
|
2510 | my %args = @_; |
|
|
2511 | |
|
|
2512 | my $item = $args{item}; |
|
|
2513 | |
|
|
2514 | my $desc = $item->{nrof} < 2 |
|
|
2515 | ? $item->{name} |
|
|
2516 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2517 | |
|
|
2518 | |
|
|
2519 | my $self = $class->SUPER::new ( |
|
|
2520 | can_hover => 1, |
|
|
2521 | can_events => 1, |
|
|
2522 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
2523 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2524 | connect_button_down => sub { |
|
|
2525 | my ($self, $ev, $x, $y) = @_; |
|
|
2526 | |
|
|
2527 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2528 | if ($ev->{button} == 1) { |
|
|
2529 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
|
|
2530 | } elsif ($ev->{button} == 2) { |
|
|
2531 | $::CONN->send ("apply $item->{tag}"); |
|
|
2532 | } elsif ($ev->{button} == 3) { |
|
|
2533 | CFClient::UI::Menu->new ( |
|
|
2534 | items => [ |
|
|
2535 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2536 | [ |
|
|
2537 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2538 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2539 | ], |
|
|
2540 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
|
|
2541 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2542 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
|
|
2543 | ], |
|
|
2544 | )->popup ($ev); |
|
|
2545 | } |
|
|
2546 | |
|
|
2547 | 1 |
|
|
2548 | }, |
|
|
2549 | %args |
|
|
2550 | ); |
|
|
2551 | $self->add(new CFClient::UI::Face |
|
|
2552 | can_events => 0, |
|
|
2553 | face => $item->{face}, |
|
|
2554 | anim => $item->{anim}, |
|
|
2555 | animspeed => $item->{animspeed}); |
|
|
2556 | $self->add(new CFClient::UI::Label |
|
|
2557 | can_events => 0, |
|
|
2558 | text => $desc); |
|
|
2559 | |
|
|
2560 | $self |
|
|
2561 | } |
|
|
2562 | |
|
|
2563 | ############################################################################# |
|
|
2564 | |
|
|
2565 | package CFClient::UI::Inventory; |
|
|
2566 | |
|
|
2567 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2568 | |
|
|
2569 | sub new { |
|
|
2570 | my $class = shift; |
|
|
2571 | |
|
|
2572 | my $self = $class->SUPER::new ( |
|
|
2573 | scrolled => (new CFClient::UI::VBox), |
|
|
2574 | @_, |
|
|
2575 | ); |
|
|
2576 | |
|
|
2577 | $self |
|
|
2578 | } |
|
|
2579 | |
|
|
2580 | sub set_items { |
|
|
2581 | my ($self, $items) = @_; |
|
|
2582 | |
|
|
2583 | $self->{scrolled}->clear; |
|
|
2584 | return unless $items; |
|
|
2585 | |
|
|
2586 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
|
|
2587 | |
|
|
2588 | $self->{real_items} = \@items; |
|
|
2589 | |
|
|
2590 | for my $item (@items) { |
|
|
2591 | my $desc = $item->{nrof} < 2 |
|
|
2592 | ? $item->{name} |
|
|
2593 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2594 | |
|
|
2595 | $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); |
|
|
2596 | } |
|
|
2597 | |
|
|
2598 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2599 | } |
|
|
2600 | |
|
|
2601 | sub size_request { |
|
|
2602 | my ($self) = @_; |
|
|
2603 | ($self->{req_w}, $self->{req_h}); |
|
|
2604 | } |
|
|
2605 | |
|
|
2606 | ############################################################################# |
|
|
2607 | |
2427 | package CFClient::UI::Menu; |
2608 | package CFClient::UI::Menu; |
2428 | |
2609 | |
2429 | our @ISA = CFClient::UI::FancyFrame::; |
2610 | our @ISA = CFClient::UI::FancyFrame::; |
2430 | |
2611 | |
2431 | use CFClient::OpenGL; |
2612 | use CFClient::OpenGL; |
… | |
… | |
2475 | } |
2656 | } |
2476 | |
2657 | |
2477 | sub mouse_motion { |
2658 | sub mouse_motion { |
2478 | my ($self, $ev, $x, $y) = @_; |
2659 | my ($self, $ev, $x, $y) = @_; |
2479 | |
2660 | |
2480 | # TODO: should use vbox->fdind_widget or so |
2661 | # TODO: should use vbox->find_widget or so |
2481 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2662 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2482 | $self->{hover} = $self->{item}{$HOVER}; |
2663 | $self->{hover} = $self->{item}{$HOVER}; |
2483 | } |
2664 | } |
2484 | |
2665 | |
2485 | sub button_up { |
2666 | sub button_up { |
… | |
… | |
2503 | use CFClient::OpenGL; |
2684 | use CFClient::OpenGL; |
2504 | |
2685 | |
2505 | sub check_size { |
2686 | sub check_size { |
2506 | my ($self) = @_; |
2687 | my ($self) = @_; |
2507 | |
2688 | |
2508 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2689 | $self->configure (0, 0, $self->{w}, $self->{h}); |
2509 | } |
2690 | } |
2510 | |
2691 | |
2511 | sub size_request { |
2692 | sub size_request { |
2512 | ($::WIDTH, $::HEIGHT) |
2693 | my ($self) = @_; |
|
|
2694 | |
|
|
2695 | ($self->{w}, $self->{h}) |
|
|
2696 | } |
|
|
2697 | |
|
|
2698 | sub size_allocate { |
|
|
2699 | my ($self, $w, $h) = @_; |
|
|
2700 | |
|
|
2701 | my $old_w = $self->{old_w}; |
|
|
2702 | my $old_h = $self->{old_h}; |
|
|
2703 | |
|
|
2704 | if ($old_w && $old_h) { |
|
|
2705 | for my $child ($self->children) { |
|
|
2706 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2707 | $child->{w} = int 0.5 + $child->{req_w} * $w / $old_w; |
|
|
2708 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2709 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2710 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2711 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2712 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2713 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2714 | } |
|
|
2715 | } |
|
|
2716 | |
|
|
2717 | $self->{old_w} = $w; |
|
|
2718 | $self->{old_h} = $h; |
2513 | } |
2719 | } |
2514 | |
2720 | |
2515 | sub configure { |
2721 | sub configure { |
2516 | my ($self, $x, $y, $w, $h) = @_; |
2722 | my ($self, $x, $y, $w, $h) = @_; |
2517 | |
2723 | |
2518 | $self->SUPER::configure ($x, $y, $w, $h); |
2724 | $self->SUPER::configure ($x, $y, $w, $h); |
2519 | |
2725 | |
2520 | for my $child (@{$self->{children}}) { |
2726 | for my $child ($self->children) { |
2521 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2727 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2522 | |
2728 | |
2523 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2729 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2524 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2730 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2525 | $child->configure ($X, $Y, $W,$H); |
2731 | $child->configure ($X, $Y, $W, $H); |
2526 | } |
2732 | } |
2527 | } |
2733 | } |
2528 | |
2734 | |
2529 | sub _topleft { |
2735 | sub _topleft { |
2530 | my ($self, $x, $y) = @_; |
2736 | my ($self, $x, $y) = @_; |
… | |
… | |
2575 | $self->_draw; |
2781 | $self->_draw; |
2576 | } |
2782 | } |
2577 | |
2783 | |
2578 | ############################################################################# |
2784 | ############################################################################# |
2579 | |
2785 | |
2580 | package CFClient::UI::Inventory; |
|
|
2581 | |
|
|
2582 | our @ISA = CFClient::UI::Container::; |
|
|
2583 | |
|
|
2584 | use CFClient::OpenGL; |
|
|
2585 | |
|
|
2586 | sub new { |
|
|
2587 | my $class = shift; |
|
|
2588 | |
|
|
2589 | my $self = $class->SUPER::new (@_); |
|
|
2590 | |
|
|
2591 | $self |
|
|
2592 | } |
|
|
2593 | |
|
|
2594 | sub size_allocate { |
|
|
2595 | my ($self, $w, $h) = @_; |
|
|
2596 | |
|
|
2597 | $self->{w} = $w; |
|
|
2598 | $self->{h} = $h; |
|
|
2599 | |
|
|
2600 | $self->check_size; |
|
|
2601 | } |
|
|
2602 | |
|
|
2603 | sub set_items { |
|
|
2604 | my ($self, $items) = @_; |
|
|
2605 | my @items = values %{$items}; |
|
|
2606 | @items = sort { $a->{type} <=> $b->{type} } @items; |
|
|
2607 | |
|
|
2608 | $self->{real_items} = \@items; |
|
|
2609 | |
|
|
2610 | for my $item (@items) { |
|
|
2611 | my $desc = $item->{nrof} < 2 |
|
|
2612 | ? $item->{name} |
|
|
2613 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2614 | |
|
|
2615 | $self->add (my $hb = new CFClient::UI::HBox); |
|
|
2616 | |
|
|
2617 | $hb->add (my $f = new CFClient::UI::Face |
|
|
2618 | can_events => 0, |
|
|
2619 | face => $item->{face}, |
|
|
2620 | anim => $item->{anim}, |
|
|
2621 | animspeed => $item->{animspeed}, |
|
|
2622 | expand => 1, |
|
|
2623 | ); |
|
|
2624 | $hb->add (new CFClient::UI::Label text => $desc, expand => 1); |
|
|
2625 | } |
|
|
2626 | |
|
|
2627 | $self->{max_pos} = (scalar @items) - 1; |
|
|
2628 | |
|
|
2629 | my $range = $self->{range}; |
|
|
2630 | my $page = $self->{h} / 32; # what information source to use for face size? |
|
|
2631 | # it should be configurable I guess... |
|
|
2632 | $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2633 | $range->update; |
|
|
2634 | } |
|
|
2635 | |
|
|
2636 | sub size_request { |
|
|
2637 | my ($self) = @_; |
|
|
2638 | (100, 200) |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | sub set_range { |
|
|
2642 | my ($self, $range) = @_; |
|
|
2643 | |
|
|
2644 | $self->{range} = $range; |
|
|
2645 | $range->connect (changed => sub { $self->update }); |
|
|
2646 | |
|
|
2647 | my $page = $self->{h} / 32; # waht information souce to use for face size? |
|
|
2648 | # it should be configurable i guess... |
|
|
2649 | |
|
|
2650 | $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2651 | $range->update; |
|
|
2652 | |
|
|
2653 | $self->update; |
|
|
2654 | } |
|
|
2655 | |
|
|
2656 | sub _draw { |
|
|
2657 | my ($self) = @_; |
|
|
2658 | |
|
|
2659 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
2660 | |
|
|
2661 | $self->{pos} = int $self->{range}{range}[0]; |
|
|
2662 | |
|
|
2663 | my $y = 0; |
|
|
2664 | my $cnt = 0; |
|
|
2665 | my $hrem = $self->{h}; # horiz. remaining space |
|
|
2666 | |
|
|
2667 | for (my $i = $self->{pos}; $i < @{$self->{children} || []}; $i++) { |
|
|
2668 | my $chld = $self->{children}->[$i]; |
|
|
2669 | |
|
|
2670 | if ($hrem >= $chld->{h}) { |
|
|
2671 | $chld->configure (0, $y, $chld->{w}, $chld->{h}); |
|
|
2672 | |
|
|
2673 | $chld->draw; |
|
|
2674 | |
|
|
2675 | $hrem -= $chld->{h}; |
|
|
2676 | $y += $chld->{h}; |
|
|
2677 | } else { |
|
|
2678 | last |
|
|
2679 | } |
|
|
2680 | } |
|
|
2681 | } |
|
|
2682 | |
|
|
2683 | |
|
|
2684 | ############################################################################# |
|
|
2685 | |
|
|
2686 | package CFClient::UI; |
2786 | package CFClient::UI; |
2687 | |
2787 | |
2688 | $ROOT = new CFClient::UI::Root; |
2788 | $ROOT = new CFClient::UI::Root; |
2689 | $TOOLTIP = new CFClient::UI::Tooltip; |
2789 | $TOOLTIP = new CFClient::UI::Tooltip; |
2690 | |
2790 | |