ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.176 by root, Tue Apr 25 12:10:58 2006 UTC vs.
Revision 1.181 by root, Sat Apr 29 16:17:09 2006 UTC

904 $tex[1]->draw_quad (0, 0, $w, $border); 904 $tex[1]->draw_quad (0, 0, $w, $border);
905 $tex[3]->draw_quad (0, $border, $border, $ch); 905 $tex[3]->draw_quad (0, $border, $border, $ch);
906 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 906 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
907 $tex[4]->draw_quad (0, $h - $border, $w, $border); 907 $tex[4]->draw_quad (0, $h - $border, $w, $border);
908 908
909 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
909 my $bg = $tex[0]; 910 my $bg = $tex[0];
910 911
911 # TODO: repeat texture not scale 912 # TODO: repeat texture not scale
912 my $rep_x = $cw / $bg->{w}; 913 my $rep_x = $cw / $bg->{w};
913 my $rep_y = $ch / $bg->{h}; 914 my $rep_y = $ch / $bg->{h};
914 915
915 glColor @{ $self->{bg} }; 916 glColor @{ $self->{bg} };
916 917
917 $bg->{s} = $rep_x; 918 $bg->{s} = $rep_x;
918 $bg->{t} = $rep_y; 919 $bg->{t} = $rep_y;
919 $bg->{wrap_mode} = 1; 920 $bg->{wrap_mode} = 1;
920 $bg->draw_quad ($border, $border, $cw, $ch); 921 $bg->draw_quad ($border, $border, $cw, $ch);
921 922
922 glDisable GL_TEXTURE_2D; 923 glDisable GL_TEXTURE_2D;
923 glDisable GL_BLEND; 924 glDisable GL_BLEND;
925 }
924 926
925 $self->{title}->draw if $self->{title}; 927 $self->{title}->draw if $self->{title};
928
926 $self->child->draw; 929 $self->child->draw;
927} 930}
928 931
929############################################################################# 932#############################################################################
930 933
2399 2402
2400sub size_request { 2403sub size_request {
2401 (32, 8) 2404 (32, 8)
2402} 2405}
2403 2406
2404sub draw { 2407sub _draw {
2405 my ($self) = @_; 2408 my ($self) = @_;
2406 2409
2407 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2410 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2408 2411
2412 # TODO animation
2409 if ($tex) { 2413 if ($tex) {
2410 glEnable GL_BLEND; 2414 glEnable GL_BLEND;
2411 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2415 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2412 glEnable GL_TEXTURE_2D; 2416 glEnable GL_TEXTURE_2D;
2413 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2417 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2418 } 2422 }
2419} 2423}
2420 2424
2421############################################################################# 2425#############################################################################
2422 2426
2427package CFClient::UI::Menu;
2428
2429our @ISA = CFClient::UI::FancyFrame::;
2430
2431use CFClient::OpenGL;
2432
2433sub new {
2434 my $class = shift;
2435
2436 my $self = $class->SUPER::new (
2437 items => [],
2438 z => 100,
2439 @_,
2440 );
2441
2442 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2443
2444 for my $item (@{ $self->{items} }) {
2445 my ($widget, $cb) = @$item;
2446
2447 # handle various types of items, only text for now
2448 if (!ref $widget) {
2449 $widget = new CFClient::UI::Label
2450 can_hover => 1,
2451 can_events => 1,
2452 text => $widget;
2453 }
2454
2455 $self->{item}{$widget} = $item;
2456
2457 $self->{vbox}->add ($widget);
2458 }
2459
2460 $self
2461}
2462
2463# popup given the event (must be a mouse button down event currently)
2464sub popup {
2465 my ($self, $ev) = @_;
2466
2467 $self->emit ("popdown");
2468
2469 # maybe save $GRAB? must be careful about events...
2470 $GRAB = $self;
2471 $self->{button} = $ev->{button};
2472
2473 $self->show;
2474 $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
2475}
2476
2477sub mouse_motion {
2478 my ($self, $ev, $x, $y) = @_;
2479
2480 # TODO: should use vbox->fdind_widget or so
2481 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2482 $self->{hover} = $self->{item}{$HOVER};
2483}
2484
2485sub button_up {
2486 my ($self, $ev, $x, $y) = @_;
2487
2488 if ($ev->{button} == $self->{button}) {
2489 undef $GRAB;
2490 $self->hide;
2491
2492 $self->emit ("popdown");
2493 $self->{hover}[1]->() if $self->{hover};
2494 }
2495}
2496
2497#############################################################################
2498
2423package CFClient::UI::Root; 2499package CFClient::UI::Root;
2424 2500
2425our @ISA = CFClient::UI::Container::; 2501our @ISA = CFClient::UI::Container::;
2426 2502
2427use CFClient::OpenGL; 2503use CFClient::OpenGL;
2499 $self->_draw; 2575 $self->_draw;
2500} 2576}
2501 2577
2502############################################################################# 2578#############################################################################
2503 2579
2580package CFClient::UI::Inventory;
2581
2582our @ISA = CFClient::UI::Container::;
2583
2584use CFClient::OpenGL;
2585
2586sub new {
2587 my $class = shift;
2588
2589 my $self = $class->SUPER::new (@_);
2590
2591 $self
2592}
2593
2594sub size_allocate {
2595 my ($self, $w, $h) = @_;
2596
2597 $self->{w} = $w;
2598 $self->{h} = $h;
2599
2600 $self->check_size;
2601}
2602
2603sub set_items {
2604 my ($self, $items) = @_;
2605 my @items = sort { $a->{type} <=> $b->{type} } @$items;
2606
2607 $self->{real_items} = \@items;
2608
2609 for my $item (@items) {
2610 my $desc = $item->{nrof} < 2
2611 ? $item->{name}
2612 : "$item->{nrof} $item->{name_pl}";
2613
2614 $self->add (my $hb = new CFClient::UI::HBox);
2615
2616 $hb->add (my $f = new CFClient::UI::Face
2617 can_events => 0,
2618 face => $item->{face},
2619 anim => $item->{anim},
2620 animspeed => $item->{animspeed},
2621 expand => 1,
2622 );
2623 $hb->add (new CFClient::UI::Label text => $desc, expand => 1);
2624 }
2625
2626 $self->{max_pos} = (scalar @items) - 1;
2627
2628 my $range = $self->{range};
2629 my $page = $self->{h} / 32; # what information source to use for face size?
2630 # it should be configurable I guess...
2631 $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2632 $range->update;
2633}
2634
2635sub size_request {
2636 my ($self) = @_;
2637 (100, 200)
2638}
2639
2640sub set_range {
2641 my ($self, $range) = @_;
2642
2643 $self->{range} = $range;
2644 $range->connect (changed => sub { $self->update });
2645
2646 my $page = $self->{h} / 32; # waht information souce to use for face size?
2647 # it should be configurable i guess...
2648
2649 $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2650 $range->update;
2651
2652 $self->update;
2653}
2654
2655sub _draw {
2656 my ($self) = @_;
2657
2658 my ($w, $h) = ($self->{w}, $self->{h});
2659
2660 $self->{pos} = int $self->{range}{range}[0];
2661
2662 my $y = 0;
2663 my $cnt = 0;
2664 my $hrem = $self->{h}; # horiz. remaining space
2665
2666 for (my $i = $self->{pos}; $i < @{$self->{children} || []}; $i++) {
2667 my $chld = $self->{children}->[$i];
2668
2669 if ($hrem >= $chld->{h}) {
2670 $chld->configure (0, $y, $chld->{w}, $chld->{h});
2671
2672 $chld->draw;
2673
2674 $hrem -= $chld->{h};
2675 $y += $chld->{h};
2676 } else {
2677 last
2678 }
2679 }
2680}
2681
2682
2683#############################################################################
2684
2504package CFClient::UI; 2685package CFClient::UI;
2505 2686
2506$ROOT = new CFClient::UI::Root; 2687$ROOT = new CFClient::UI::Root;
2507$TOOLTIP = new CFClient::UI::Tooltip; 2688$TOOLTIP = new CFClient::UI::Tooltip;
2508 2689

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines