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.285 by root, Mon Jun 5 03:07:01 2006 UTC vs.
Revision 1.296 by root, Wed Jun 7 05:48:53 2006 UTC

315} 315}
316 316
317sub move_abs { 317sub move_abs {
318 my ($self, $x, $y, $z) = @_; 318 my ($self, $x, $y, $z) = @_;
319 319
320 $self->{x} = List::Util::max 0, int $x; 320 $self->{x} = List::Util::max 0, List::Util::min $self->{root}{w} - $self->{w}, int $x;
321 $self->{y} = List::Util::max 0, int $y; 321 $self->{y} = List::Util::max 0, List::Util::min $self->{root}{h} - $self->{h}, int $y;
322 $self->{z} = $z if defined $z; 322 $self->{z} = $z if defined $z;
323 323
324 $self->update; 324 $self->update;
325} 325}
326 326
1554 return if $self->{text} eq "T$text"; 1554 return if $self->{text} eq "T$text";
1555 $self->{text} = "T$text"; 1555 $self->{text} = "T$text";
1556 1556
1557 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; 1557 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1558 $self->{layout}->set_text ($text); 1558 $self->{layout}->set_text ($text);
1559
1559 delete $self->{req_h}; 1560 delete $self->{size_req};
1560
1561 $self->realloc; 1561 $self->realloc;
1562 $self->update; 1562 $self->update;
1563} 1563}
1564 1564
1565sub set_markup { 1565sub set_markup {
1570 1570
1571 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1571 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1572 1572
1573 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; 1573 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1574 $self->{layout}->set_markup ($markup); 1574 $self->{layout}->set_markup ($markup);
1575
1575 delete $self->{req_h}; 1576 delete $self->{size_req};
1576
1577 $self->realloc; 1577 $self->realloc;
1578 $self->update; 1578 $self->update;
1579} 1579}
1580 1580
1581sub size_request { 1581sub size_request {
1582 my ($self) = @_; 1582 my ($self) = @_;
1583 1583
1584 if (exists $self->{req_h}) { 1584 $self->{size_req} ||= do {
1585 @$self{qw(req_w req_h)}
1586 } else {
1587 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1585 $self->{layout}->set_font ($self->{font}) if $self->{font};
1588 $self->{layout}->set_width ($self->{max_w} || -1); 1586 $self->{layout}->set_width ($self->{max_w} || -1);
1589 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1587 $self->{layout}->set_ellipsise ($self->{ellipsise});
1590 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1588 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1591 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1589 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1600 1598
1601 $w = List::Util::max $w, $w2; 1599 $w = List::Util::max $w, $w2;
1602 $h = List::Util::max $h, $h2; 1600 $h = List::Util::max $h, $h2;
1603 } 1601 }
1604 1602
1605 ($w, $h) 1603 [$w, $h]
1606 } 1604 };
1605
1606 @{ $self->{size_req} }
1607} 1607}
1608 1608
1609sub size_allocate { 1609sub size_allocate {
1610 my ($self, $w, $h) = @_; 1610 my ($self, $w, $h) = @_;
1611 1611
1620 1620
1621 $self->{fontsize} = $fontsize; 1621 $self->{fontsize} = $fontsize;
1622 delete $self->{texture}; 1622 delete $self->{texture};
1623 1623
1624 $self->realloc; 1624 $self->realloc;
1625}
1626
1627sub reconfigure {
1628 my ($self) = @_;
1629
1630 delete $self->{size_req};
1631
1632 $self->SUPER::reconfigure;
1625} 1633}
1626 1634
1627sub _draw { 1635sub _draw {
1628 my ($self) = @_; 1636 my ($self) = @_;
1629 1637
1649 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1657 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1650 : ($self->{h} - $tex->{h}) * 0.5); 1658 : ($self->{h} - $tex->{h}) * 0.5);
1651 }; 1659 };
1652 1660
1653 glEnable GL_TEXTURE_2D; 1661 glEnable GL_TEXTURE_2D;
1662
1663 my $w = List::Util::min $self->{w} + 4, $tex->{w};
1664 my $h = List::Util::min $self->{h} + 2, $tex->{h};
1665
1666 if ($tex->{format} == GL_ALPHA) {
1667 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1668 glColor @{$self->{fg}};
1669 $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h);
1670 } else {
1654 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1671 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1655
1656 glColor_premultiply @{$self->{fg}}
1657 if $tex->{format} == GL_ALPHA;
1658
1659 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); 1672 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h);
1673 }
1660 1674
1661 glDisable GL_TEXTURE_2D; 1675 glDisable GL_TEXTURE_2D;
1662} 1676}
1663 1677
1664############################################################################# 1678#############################################################################
1680 can_hover => 1, 1694 can_hover => 1,
1681 can_focus => 1, 1695 can_focus => 1,
1682 valign => 0, 1696 valign => 0,
1683 can_events => 1, 1697 can_events => 1,
1684 #text => ... 1698 #text => ...
1699 #hidden => "*",
1685 @_ 1700 @_
1686 ) 1701 )
1687} 1702}
1688 1703
1689sub _set_text { 1704sub _set_text {
1696 $self->{last_activity} = $::NOW; 1711 $self->{last_activity} = $::NOW;
1697 $self->{text} = $text; 1712 $self->{text} = $text;
1698 1713
1699 $text =~ s/./*/g if $self->{hidden}; 1714 $text =~ s/./*/g if $self->{hidden};
1700 $self->{layout}->set_text ("$text "); 1715 $self->{layout}->set_text ("$text ");
1701 delete $self->{req_h}; 1716 delete $self->{size_req};
1702 1717
1703 $self->_emit (changed => $self->{text}); 1718 $self->_emit (changed => $self->{text});
1704 1719
1705 $self->realloc; 1720 $self->realloc;
1706 $self->update; 1721 $self->update;
2292sub set_range { 2307sub set_range {
2293 my ($self, $range) = @_; 2308 my ($self, $range) = @_;
2294 2309
2295 ($range, $self->{range}) = ($self->{range}, $range); 2310 ($range, $self->{range}) = ($self->{range}, $range);
2296 2311
2297 $self->update
2298 if "@$range" ne "@{$self->{range}}"; 2312 if ("@$range" ne "@{$self->{range}}") {
2313 $self->update;
2314 $self->set_value ($self->{range}[0]);
2315 }
2299} 2316}
2300 2317
2301sub set_value { 2318sub set_value {
2302 my ($self, $value) = @_; 2319 my ($self, $value) = @_;
2303 2320
2462 my $class = shift; 2479 my $class = shift;
2463 2480
2464 my $self = $class->SUPER::new ( 2481 my $self = $class->SUPER::new (
2465 fontsize => 1, 2482 fontsize => 1,
2466 can_events => 0, 2483 can_events => 0,
2484 indent => 0,
2467 #font => default_font 2485 #font => default_font
2468 @_, 2486 @_,
2469 2487
2470 layout => (new CFClient::Layout 1), 2488 layout => (new CFClient::Layout 1),
2471 par => [], 2489 par => [],
2494 $self->SUPER::size_allocate ($w, $h); 2512 $self->SUPER::size_allocate ($w, $h);
2495 2513
2496 $self->{layout}->set_font ($self->{font}) if $self->{font}; 2514 $self->{layout}->set_font ($self->{font}) if $self->{font};
2497 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2515 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2498 $self->{layout}->set_width ($self->{children}[0]{w}); 2516 $self->{layout}->set_width ($self->{children}[0]{w});
2517 $self->{layout}->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2499 2518
2500 $self->reflow; 2519 $self->reflow;
2501} 2520}
2502 2521
2503sub text_size { 2522sub text_size {
2505 2524
2506 my $layout = $self->{layout}; 2525 my $layout = $self->{layout};
2507 2526
2508 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2527 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2509 $layout->set_width ($self->{children}[0]{w} - $indent); 2528 $layout->set_width ($self->{children}[0]{w} - $indent);
2529 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2510 $layout->set_markup ($text); 2530 $layout->set_markup ($text);
2511 2531
2512 $layout->size 2532 $layout->size
2513} 2533}
2514 2534
2553 2573
2554 return unless $self->{h} > 0; 2574 return unless $self->{h} > 0;
2555 2575
2556 delete $self->{texture}; 2576 delete $self->{texture};
2557 2577
2558 $ROOT->on_post_alloc ($self, sub { 2578 $ROOT->on_post_alloc ($self => sub {
2559 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2579 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2560 2580
2561 if (delete $self->{need_reflow}) { 2581 if (delete $self->{need_reflow}) {
2562 my $height = 0; 2582 my $height = 0;
2563 2583
2566 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2586 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2567 2587
2568 for (@{$self->{par}}) { 2588 for (@{$self->{par}}) {
2569 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support 2589 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support
2570 $layout->set_width ($W - $_->[3]); 2590 $layout->set_width ($W - $_->[3]);
2591 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2571 $layout->set_markup ($_->[4]); 2592 $layout->set_markup ($_->[4]);
2572 my ($w, $h) = $layout->size; 2593 my ($w, $h) = $layout->size;
2573 $_->[0] = $w + $_->[3]; 2594 $_->[0] = $w + $_->[3];
2574 $_->[1] = $h; 2595 $_->[1] = $h;
2575 } 2596 }
2578 } 2599 }
2579 2600
2580 $self->{height} = $height; 2601 $self->{height} = $height;
2581 2602
2582 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); 2603 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]);
2583 2604
2584 delete $self->{texture}; 2605 delete $self->{texture};
2585 } 2606 }
2586 2607
2587 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2608 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2588 glClearColor 0, 0, 0, 0; 2609 glClearColor 0, 0, 0, 0;
2607 my $h = $par->[1]; 2628 my $h = $par->[1];
2608 2629
2609 if ($y0 < $y + $h && $y < $y1) { 2630 if ($y0 < $y + $h && $y < $y1) {
2610 $layout->set_foreground (@{ $par->[2] }); 2631 $layout->set_foreground (@{ $par->[2] });
2611 $layout->set_width ($W - $par->[3]); 2632 $layout->set_width ($W - $par->[3]);
2633 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2612 $layout->set_markup ($par->[4]); 2634 $layout->set_markup ($par->[4]);
2613 2635
2614 my ($w, $h, $data, $format, $internalformat) = $layout->render; 2636 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2615 2637
2616 glRasterPos $par->[3], $y - $y0; 2638 glRasterPos $par->[3], $y - $y0;
2767 or return; 2789 or return;
2768 2790
2769 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 2791 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2770 2792
2771 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 2793 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2772 if $x + $self->{w} > $::WIDTH; 2794 if $x + $self->{w} > $self->{root}{w};
2773 2795
2774 $self->move_abs ($x, $y); 2796 $self->move_abs ($x, $y);
2775 }); 2797 });
2776} 2798}
2777 2799
2909 ); 2931 );
2910 2932
2911 $self->add ($self->{vbox} = new CFClient::UI::VBox); 2933 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2912 2934
2913 for my $item (@{ $self->{items} }) { 2935 for my $item (@{ $self->{items} }) {
2914 my ($widget, $cb) = @$item; 2936 my ($widget, $cb, $tooltip) = @$item;
2915 2937
2916 # handle various types of items, only text for now 2938 # handle various types of items, only text for now
2917 if (!ref $widget) { 2939 if (!ref $widget) {
2918 $widget = new CFClient::UI::Label 2940 $widget = new CFClient::UI::Label
2919 can_hover => 1, 2941 can_hover => 1,
2920 can_events => 1, 2942 can_events => 1,
2921 text => $widget; 2943 text => $widget,
2944 tooltip => $tooltip
2922 } 2945 }
2923 2946
2924 $self->{item}{$widget} = $item; 2947 $self->{item}{$widget} = $item;
2925 2948
2926 $self->{vbox}->add ($widget); 2949 $self->{vbox}->add ($widget);
3073sub set_current_page { 3096sub set_current_page {
3074 my ($self, $page) = @_; 3097 my ($self, $page) = @_;
3075 3098
3076 $self->{multiplexer}->set_current_page ($page); 3099 $self->{multiplexer}->set_current_page ($page);
3077 $self->_emit (page_changed => $self->{multiplexer}{current}); 3100 $self->_emit (page_changed => $self->{multiplexer}{current});
3101}
3102
3103#############################################################################
3104
3105package CFClient::UI::Combobox;
3106
3107use utf8;
3108
3109our @ISA = CFClient::UI::Button::;
3110
3111sub new {
3112 my $class = shift;
3113
3114 my $self = $class->SUPER::new (
3115 options => [], # [title, value, tooltip], ...
3116 value => undef,
3117 @_,
3118 );
3119
3120 $self->_set_value ($self->{value});
3121
3122 $self
3123}
3124
3125sub button_down {
3126 my ($self, $ev) = @_;
3127
3128 my @menu_items;
3129
3130 for (@{ $self->{options} }) {
3131 my ($title, $value, $tooltip) = @$_;
3132
3133 push @menu_items, [$tooltip, sub { $self->set_value ($value) }];
3134 }
3135
3136 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
3137}
3138
3139sub _set_value {
3140 my ($self, $value) = @_;
3141
3142 my ($item) = grep $_->[1] eq $value, @{ $self->{options} }
3143 or return;
3144
3145 $self->{value} = $item->[1];
3146 $self->set_markup ("$item->[0] ⇓");
3147 $self->set_tooltip ($item->[2]);
3148}
3149
3150sub set_value {
3151 my ($self, $value) = @_;
3152
3153 return unless $self->{value} ne $value;
3154
3155 $self->_set_value ($value);
3156 $self->_emit (changed => $value);
3078} 3157}
3079 3158
3080############################################################################# 3159#############################################################################
3081 3160
3082package CFClient::UI::Statusbox; 3161package CFClient::UI::Statusbox;
3473 commands => [], 3552 commands => [],
3474 @_, 3553 @_,
3475 ) 3554 )
3476} 3555}
3477 3556
3478# XXX: Do sorting? Argl... 3557my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3558 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.");
3559my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3560 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.");
3561my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3562 "<b>Damage</b>. The amount of damage the spell deals when it hits.");
3563
3564sub rebuild_spell_list {
3565 my ($self) = @_;
3566
3567 $CFClient::UI::ROOT->on_refresh ($self => sub {
3568 $self->clear;
3569
3570 $self->add (1, 0, new CFClient::UI::Label text => "Spell Name");
3571 $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3572 $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3573 $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3574
3575 my $row = 0;
3576
3577 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3578 my $spell = $self->{spell}{$_};
3579
3580 $row++;
3581
3582 $self->add (0, $row, new CFClient::UI::Face
3583 face => $spell->{face},
3584 can_hover => 1,
3585 can_events => 1,
3586 tooltip => $spell->{message},
3587 );
3588
3589 $self->add (1, $row, new CFClient::UI::Label
3590 expand => 1,
3591 text => $spell->{name},
3592 can_hover => 1,
3593 can_events => 1,
3594 tooltip => $spell->{message},
3595 );
3596
3597 $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3598 $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3599 $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3600
3601 # TODO: should be done via popup
3602 $self->add (5, $row, new CFClient::UI::Button
3603 text => "bind",
3604 tooltip => "bind spell readying (cast command) to key",
3605 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) },
3606 );
3607 }
3608 });
3609}
3610
3479sub add_spell { 3611sub add_spell {
3480 my ($self, $spell) = @_; 3612 my ($self, $spell) = @_;
3613
3481 $self->{spells}->{$spell->{name}} = $spell; 3614 $self->{spell}->{$spell->{name}} = $spell;
3482 3615 $self->rebuild_spell_list;
3483 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3484 face => $spell->{face},
3485 can_hover => 1,
3486 can_events => 1,
3487 tooltip => $spell->{message});
3488
3489 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3490 text => $spell->{name},
3491 can_hover => 1,
3492 can_events => 1,
3493 tooltip => $spell->{message},
3494 expand => 1);
3495
3496 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3497 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3498 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3499 expand => 1);
3500
3501 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3502 text => "bind to key",
3503 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3504}
3505
3506sub rebuild_spell_list {
3507 my ($self) = @_;
3508 $self->{tbl_idx} = 0;
3509 $self->add_spell ($_) for values %{$self->{spells}};
3510} 3616}
3511 3617
3512sub remove_spell { 3618sub remove_spell {
3513 my ($self, $spell) = @_; 3619 my ($self, $spell) = @_;
3620
3514 delete $self->{spells}->{$spell->{name}}; 3621 delete $self->{spell}->{$spell->{name}};
3515 $self->rebuild_spell_list; 3622 $self->rebuild_spell_list;
3516} 3623}
3517 3624
3518############################################################################# 3625#############################################################################
3519 3626

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines