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.185 by root, Mon May 8 17:23:08 2006 UTC vs.
Revision 1.186 by root, Mon May 8 20:39:34 2006 UTC

255 my ($self) = @_; 255 my ($self) = @_;
256 256
257 $_->reconfigure 257 $_->reconfigure
258 for $self->children; 258 for $self->children;
259 259
260 $_->check_size; 260 $self->check_size;
261 $self->size_allocate ($self->{w}, $self->{h});
262 $self->update;
261} 263}
262 264
263sub set_max_size { 265sub set_max_size {
264 my ($self, $w, $h) = @_; 266 my ($self, $w, $h) = @_;
265 267
1322 1324
1323 delete $self->{texture}; 1325 delete $self->{texture};
1324 $self->SUPER::update; 1326 $self->SUPER::update;
1325} 1327}
1326 1328
1327sub reconfigure {
1328 my ($self) = @_;
1329
1330 delete $self->{texture};
1331}
1332
1333sub set_text { 1329sub set_text {
1334 my ($self, $text) = @_; 1330 my ($self, $text) = @_;
1335 1331
1336 return if $self->{text} eq "T$text"; 1332 return if $self->{text} eq "T$text";
1337 $self->{text} = "T$text"; 1333 $self->{text} = "T$text";
1390sub set_fontsize { 1386sub set_fontsize {
1391 my ($self, $fontsize) = @_; 1387 my ($self, $fontsize) = @_;
1392 1388
1393 $self->{fontsize} = $fontsize; 1389 $self->{fontsize} = $fontsize;
1394 delete $self->{texture}; 1390 delete $self->{texture};
1391
1392 $self->update;
1395 $self->check_size; 1393 $self->check_size;
1396 $self->update;
1397} 1394}
1398 1395
1399sub _draw { 1396sub _draw {
1400 my ($self) = @_; 1397 my ($self) = @_;
1401 1398
2497 glColor 1, 1, 1, 1; 2494 glColor 1, 1, 1, 1;
2498 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 2495 $tex->draw_quad (0, 0, $self->{w}, $self->{h});
2499 glDisable GL_TEXTURE_2D; 2496 glDisable GL_TEXTURE_2D;
2500 glDisable GL_BLEND; 2497 glDisable GL_BLEND;
2501 } 2498 }
2502}
2503
2504#############################################################################
2505
2506package CFClient::UI::Menu;
2507
2508our @ISA = CFClient::UI::FancyFrame::;
2509
2510use CFClient::OpenGL;
2511
2512sub new {
2513 my $class = shift;
2514
2515 my $self = $class->SUPER::new (
2516 items => [],
2517 z => 100,
2518 @_,
2519 );
2520
2521 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2522
2523 for my $item (@{ $self->{items} }) {
2524 my ($widget, $cb) = @$item;
2525
2526 # handle various types of items, only text for now
2527 if (!ref $widget) {
2528 $widget = new CFClient::UI::Label
2529 can_hover => 1,
2530 can_events => 1,
2531 text => $widget;
2532 }
2533
2534 $self->{item}{$widget} = $item;
2535
2536 $self->{vbox}->add ($widget);
2537 }
2538
2539 $self
2540}
2541
2542# popup given the event (must be a mouse button down event currently)
2543sub popup {
2544 my ($self, $ev) = @_;
2545
2546 $self->emit ("popdown");
2547
2548 # maybe save $GRAB? must be careful about events...
2549 $GRAB = $self;
2550 $self->{button} = $ev->{button};
2551
2552 $self->show;
2553 $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
2554}
2555
2556sub mouse_motion {
2557 my ($self, $ev, $x, $y) = @_;
2558
2559 # TODO: should use vbox->find_widget or so
2560 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2561 $self->{hover} = $self->{item}{$HOVER};
2562}
2563
2564sub button_up {
2565 my ($self, $ev, $x, $y) = @_;
2566
2567 if ($ev->{button} == $self->{button}) {
2568 undef $GRAB;
2569 $self->hide;
2570
2571 $self->emit ("popdown");
2572 $self->{hover}[1]->() if $self->{hover};
2573 }
2574}
2575
2576#############################################################################
2577
2578package CFClient::UI::Root;
2579
2580our @ISA = CFClient::UI::Container::;
2581
2582use CFClient::OpenGL;
2583
2584sub check_size {
2585 my ($self) = @_;
2586
2587 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2588}
2589
2590sub size_request {
2591 ($::WIDTH, $::HEIGHT)
2592}
2593
2594sub configure {
2595 my ($self, $x, $y, $w, $h) = @_;
2596
2597 $self->SUPER::configure ($x, $y, $w, $h);
2598
2599 for my $child (@{$self->{children}}) {
2600 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2601
2602 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2603 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2604 $child->configure ($X, $Y, $W,$H);
2605 }
2606}
2607
2608sub _topleft {
2609 my ($self, $x, $y) = @_;
2610
2611 ($x, $y)
2612}
2613
2614sub update {
2615 my ($self) = @_;
2616
2617 $self->check_size;
2618 ::refresh ();
2619}
2620
2621sub add {
2622 my ($self, $child) = @_;
2623
2624 # integerize window positions
2625 $child->{x} = int $child->{x};
2626 $child->{y} = int $child->{y};
2627
2628 $self->SUPER::add ($child);
2629}
2630
2631sub on_refresh {
2632 my ($self, $id, $cb) = @_;
2633
2634 $self->{refresh_hook}{$id} = $cb;
2635}
2636
2637sub draw {
2638 my ($self) = @_;
2639
2640 while (my $rcb = delete $self->{refresh_hook}) {
2641 $_->() for values %$rcb;
2642 }
2643
2644 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2645 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2646 glClear GL_COLOR_BUFFER_BIT;
2647
2648 glMatrixMode GL_PROJECTION;
2649 glLoadIdentity;
2650 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000;
2651 glMatrixMode GL_MODELVIEW;
2652 glLoadIdentity;
2653
2654 $self->_draw;
2655} 2499}
2656 2500
2657############################################################################# 2501#############################################################################
2658 2502
2659package CFClient::UI::InventoryItem; 2503package CFClient::UI::InventoryItem;
2759 ($self->{req_w}, $self->{req_h}); 2603 ($self->{req_w}, $self->{req_h});
2760} 2604}
2761 2605
2762############################################################################# 2606#############################################################################
2763 2607
2608package CFClient::UI::Menu;
2609
2610our @ISA = CFClient::UI::FancyFrame::;
2611
2612use CFClient::OpenGL;
2613
2614sub new {
2615 my $class = shift;
2616
2617 my $self = $class->SUPER::new (
2618 items => [],
2619 z => 100,
2620 @_,
2621 );
2622
2623 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2624
2625 for my $item (@{ $self->{items} }) {
2626 my ($widget, $cb) = @$item;
2627
2628 # handle various types of items, only text for now
2629 if (!ref $widget) {
2630 $widget = new CFClient::UI::Label
2631 can_hover => 1,
2632 can_events => 1,
2633 text => $widget;
2634 }
2635
2636 $self->{item}{$widget} = $item;
2637
2638 $self->{vbox}->add ($widget);
2639 }
2640
2641 $self
2642}
2643
2644# popup given the event (must be a mouse button down event currently)
2645sub popup {
2646 my ($self, $ev) = @_;
2647
2648 $self->emit ("popdown");
2649
2650 # maybe save $GRAB? must be careful about events...
2651 $GRAB = $self;
2652 $self->{button} = $ev->{button};
2653
2654 $self->show;
2655 $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
2656}
2657
2658sub mouse_motion {
2659 my ($self, $ev, $x, $y) = @_;
2660
2661 # TODO: should use vbox->find_widget or so
2662 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2663 $self->{hover} = $self->{item}{$HOVER};
2664}
2665
2666sub button_up {
2667 my ($self, $ev, $x, $y) = @_;
2668
2669 if ($ev->{button} == $self->{button}) {
2670 undef $GRAB;
2671 $self->hide;
2672
2673 $self->emit ("popdown");
2674 $self->{hover}[1]->() if $self->{hover};
2675 }
2676}
2677
2678#############################################################################
2679
2680package CFClient::UI::Root;
2681
2682our @ISA = CFClient::UI::Container::;
2683
2684use CFClient::OpenGL;
2685
2686sub check_size {
2687 my ($self) = @_;
2688
2689 $self->configure (0, 0, $self->{w}, $self->{h});
2690}
2691
2692sub size_request {
2693 my ($self) = @_;
2694
2695 ($self->{w}, $self->{h})
2696}
2697
2698sub 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;
2719}
2720
2721sub configure {
2722 my ($self, $x, $y, $w, $h) = @_;
2723
2724 $self->SUPER::configure ($x, $y, $w, $h);
2725
2726 for my $child ($self->children) {
2727 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2728
2729 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2730 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2731 $child->configure ($X, $Y, $W, $H);
2732 }
2733}
2734
2735sub _topleft {
2736 my ($self, $x, $y) = @_;
2737
2738 ($x, $y)
2739}
2740
2741sub update {
2742 my ($self) = @_;
2743
2744 $self->check_size;
2745 ::refresh ();
2746}
2747
2748sub add {
2749 my ($self, $child) = @_;
2750
2751 # integerize window positions
2752 $child->{x} = int $child->{x};
2753 $child->{y} = int $child->{y};
2754
2755 $self->SUPER::add ($child);
2756}
2757
2758sub on_refresh {
2759 my ($self, $id, $cb) = @_;
2760
2761 $self->{refresh_hook}{$id} = $cb;
2762}
2763
2764sub draw {
2765 my ($self) = @_;
2766
2767 while (my $rcb = delete $self->{refresh_hook}) {
2768 $_->() for values %$rcb;
2769 }
2770
2771 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2772 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2773 glClear GL_COLOR_BUFFER_BIT;
2774
2775 glMatrixMode GL_PROJECTION;
2776 glLoadIdentity;
2777 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000;
2778 glMatrixMode GL_MODELVIEW;
2779 glLoadIdentity;
2780
2781 $self->_draw;
2782}
2783
2784#############################################################################
2785
2764package CFClient::UI; 2786package CFClient::UI;
2765 2787
2766$ROOT = new CFClient::UI::Root; 2788$ROOT = new CFClient::UI::Root;
2767$TOOLTIP = new CFClient::UI::Tooltip; 2789$TOOLTIP = new CFClient::UI::Tooltip;
2768 2790

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines