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.319 by root, Sun Jul 2 21:07:26 2006 UTC vs.
Revision 1.329 by root, Sun Jul 23 02:44:06 2006 UTC

452 452
453 $FOCUS->emit ("focus_out") if $FOCUS; 453 $FOCUS->emit ("focus_out") if $FOCUS;
454 $self->emit ("focus_in"); 454 $self->emit ("focus_in");
455} 455}
456 456
457sub invoke_mouse_motion { 1 } 457sub invoke_mouse_motion { 0 }
458sub invoke_button_up { 1 } 458sub invoke_button_up { 0 }
459sub invoke_key_down { 1 } 459sub invoke_key_down { 0 }
460sub invoke_key_up { 1 } 460sub invoke_key_up { 0 }
461 461
462sub invoke_button_down { 462sub invoke_button_down {
463 my ($self, $ev, $x, $y) = @_; 463 my ($self, $ev, $x, $y) = @_;
464 464
465 $self->grab_focus; 465 $self->grab_focus;
466 466
467 1 467 0
468} 468}
469 469
470sub connect { 470sub connect {
471 my ($self, $signal, $cb) = @_; 471 my ($self, $signal, $cb) = @_;
472 472
473 push @{ $self->{signal_cb}{$signal} }, $cb; 473 push @{ $self->{signal_cb}{$signal} }, $cb;
474} 474}
475 475
476sub emit { 476sub emit {
477 my ($self, $signal, @args) = @_; 477 my ($self, $signal, @args) = @_;
478
479 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
478 480
479 #d##TODO# stop propagating at first true, do not use sum 481 #d##TODO# stop propagating at first true, do not use sum
480 (List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}) # before 482 (List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}) # before
481 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args) # closure 483 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args) # closure
482 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent 484 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent
587} 589}
588 590
589sub DESTROY { 591sub DESTROY {
590 my ($self) = @_; 592 my ($self) = @_;
591 593
594 return if CFClient::in_destruct;
595
592 delete $WIDGET{$self+0}; 596 delete $WIDGET{$self+0};
593 597
594 eval { $self->destroy }; 598 eval { $self->destroy };
595 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 599 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
596} 600}
994 my ($self, $widget) = @_; 998 my ($self, $widget) = @_;
995 999
996 $self->{vp}->add ($self->{child} = $widget); 1000 $self->{vp}->add ($self->{child} = $widget);
997} 1001}
998 1002
1003sub invoke_button_up {
1004 my ($self, $ev) = @_;
1005
1006 warn "button up $ev->{button}\n";#d#
1007
1008 0
1009}
1010
999sub update_slider { 1011sub update_slider {
1000 my ($self) = @_; 1012 my ($self) = @_;
1001 1013
1002 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); 1014 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]);
1003} 1015}
1080 my $self = $class->SUPER::new ( 1092 my $self = $class->SUPER::new (
1081 bg => [1, 1, 1, 1], 1093 bg => [1, 1, 1, 1],
1082 border_bg => [1, 1, 1, 1], 1094 border_bg => [1, 1, 1, 1],
1083 border => 0.6, 1095 border => 0.6,
1084 can_events => 1, 1096 can_events => 1,
1085 min_w => 16, 1097 min_w => 64,
1086 min_h => 16, 1098 min_h => 32,
1087 %arg, 1099 %arg,
1088 ); 1100 );
1089 1101
1090 $self->{title_widget} = new CFClient::UI::Label 1102 $self->{title_widget} = new CFClient::UI::Label
1091 align => 0, 1103 align => 0,
1591 my ($self, $text) = @_; 1603 my ($self, $text) = @_;
1592 1604
1593 return if $self->{text} eq "T$text"; 1605 return if $self->{text} eq "T$text";
1594 $self->{text} = "T$text"; 1606 $self->{text} = "T$text";
1595 1607
1596 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1597 $self->{layout}->set_text ($text); 1608 $self->{layout}->set_text ($text);
1598 1609
1599 delete $self->{size_req}; 1610 delete $self->{size_req};
1600 $self->realloc; 1611 $self->realloc;
1601 $self->update; 1612 $self->update;
1607 return if $self->{text} eq "M$markup"; 1618 return if $self->{text} eq "M$markup";
1608 $self->{text} = "M$markup"; 1619 $self->{text} = "M$markup";
1609 1620
1610 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1621 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1611 1622
1612 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1613 $self->{layout}->set_markup ($markup); 1623 $self->{layout}->set_markup ($markup);
1614 1624
1615 delete $self->{size_req}; 1625 delete $self->{size_req};
1616 $self->realloc; 1626 $self->realloc;
1617 $self->update; 1627 $self->update;
1629 1639
1630 my ($w, $h) = $self->{layout}->size; 1640 my ($w, $h) = $self->{layout}->size;
1631 1641
1632 if (exists $self->{template}) { 1642 if (exists $self->{template}) {
1633 $self->{template}->set_font ($self->{font}) if $self->{font}; 1643 $self->{template}->set_font ($self->{font}) if $self->{font};
1644 $self->{template}->set_width ($self->{max_w} || -1);
1634 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1645 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1635 1646
1636 my ($w2, $h2) = $self->{template}->size; 1647 my ($w2, $h2) = $self->{template}->size;
1637 1648
1638 $w = List::Util::max $w, $w2; 1649 $w = List::Util::max $w, $w2;
1672 1683
1673sub reconfigure { 1684sub reconfigure {
1674 my ($self) = @_; 1685 my ($self) = @_;
1675 1686
1676 delete $self->{size_req}; 1687 delete $self->{size_req};
1688 delete $self->{texture};
1677 1689
1678 $self->SUPER::reconfigure; 1690 $self->SUPER::reconfigure;
1679} 1691}
1680 1692
1681sub _draw { 1693sub _draw {
1682 my ($self) = @_; 1694 my ($self) = @_;
1683 1695
1684 $self->SUPER::_draw; # draw background, if applicable 1696 $self->SUPER::_draw; # draw background, if applicable
1685 1697
1686 my $tex = $self->{texture} ||= do { 1698 my $size = $self->{texture} ||= do {
1687 $self->{layout}->set_foreground (@{$self->{fg}}); 1699 $self->{layout}->set_foreground (@{$self->{fg}});
1688 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1700 $self->{layout}->set_font ($self->{font}) if $self->{font};
1689 $self->{layout}->set_width ($self->{w}); 1701 $self->{layout}->set_width ($self->{w});
1690 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1702 $self->{layout}->set_ellipsise ($self->{ellipsise});
1691 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1703 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1692 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1704 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1693 1705
1694 new_from_layout CFClient::Texture $self->{layout} 1706 [$self->{layout}->size]
1695 }; 1707 };
1696 1708
1697 unless (exists $self->{ox}) { 1709 unless (exists $self->{ox}) {
1698 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1710 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1699 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1711 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x}
1700 : ($self->{w} - $tex->{w}) * 0.5); 1712 : ($self->{w} - $size->[0]) * 0.5);
1701 1713
1702 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1714 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1703 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1715 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
1704 : ($self->{h} - $tex->{h}) * 0.5); 1716 : ($self->{h} - $size->[1]) * 0.5);
1705 }; 1717 };
1706 1718
1707 glEnable GL_TEXTURE_2D;
1708
1709 my $w = List::Util::min $self->{w} + 4, $tex->{w}; 1719 my $w = List::Util::min $self->{w} + 4, $size->[0];
1710 my $h = List::Util::min $self->{h} + 2, $tex->{h}; 1720 my $h = List::Util::min $self->{h} + 2, $size->[1];
1711 1721
1712 if ($tex->{format} == GL_ALPHA) { 1722 $self->{layout}->render ($self->{ox}, $self->{oy});
1713 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1714 glColor @{$self->{fg}};
1715 $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h);
1716 } else {
1717 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1718 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h);
1719 }
1720
1721 glDisable GL_TEXTURE_2D;
1722} 1723}
1723 1724
1724############################################################################# 1725#############################################################################
1725 1726
1726package CFClient::UI::EntryBase; 1727package CFClient::UI::EntryBase;
1837 1838
1838 my $idx = $self->{layout}->xy_to_index ($x, $y); 1839 my $idx = $self->{layout}->xy_to_index ($x, $y);
1839 1840
1840 # byte-index to char-index 1841 # byte-index to char-index
1841 my $text = $self->{text}; 1842 my $text = $self->{text};
1842 utf8::encode $text; 1843 utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text;
1843 $self->{cursor} = length substr $text, 0, $idx; 1844 $self->{cursor} = length $text;
1844 1845
1845 $self->_set_text ($self->{text}); 1846 $self->_set_text ($self->{text});
1846 $self->update; 1847 $self->update;
1847 1848
1848 1 1849 1
2127 my $self = $class->SUPER::new ( 2128 my $self = $class->SUPER::new (
2128 can_events => 0, 2129 can_events => 0,
2129 @_, 2130 @_,
2130 ); 2131 );
2131 2132
2132 $self->{path} 2133 $self->{path} || $self->{tex}
2133 or Carp::croak "required attribute 'path' not set"; 2134 or Carp::croak "'path' or 'tex' attributes required";
2134 2135
2135 $self->{tex} = $texture_cache{$self->{path}} ||= 2136 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2136 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; 2137 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2137 2138
2138 Scalar::Util::weaken $texture_cache{$self->{path}}; 2139 Scalar::Util::weaken $texture_cache{$self->{path}};
2139 2140
2140 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2141 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2573 can_events => 0, 2574 can_events => 0,
2574 indent => 0, 2575 indent => 0,
2575 #font => default_font 2576 #font => default_font
2576 @_, 2577 @_,
2577 2578
2578 layout => (new CFClient::Layout 1), 2579 layout => (new CFClient::Layout),
2579 par => [], 2580 par => [],
2580 height => 0, 2581 height => 0,
2581 children => [ 2582 children => [
2582 (new CFClient::UI::Empty expand => 1), 2583 (new CFClient::UI::Empty expand => 1),
2583 (new CFClient::UI::Slider vertical => 1), 2584 (new CFClient::UI::Slider vertical => 1),
2744 my $y0 = $top; 2745 my $y0 = $top;
2745 my $y1 = $top + $H; 2746 my $y1 = $top + $H;
2746 2747
2747 my $y = 0; 2748 my $y = 0;
2748 2749
2749 glEnable GL_BLEND;
2750 #TODO# not correct in windows where rgba is forced off
2751 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2752
2753 for my $para (@{$self->{par}}) { 2750 for my $para (@{$self->{par}}) {
2754 my $h = $para->{h}; 2751 my $h = $para->{h};
2755 2752
2756 if ($y0 < $y + $h && $y < $y1) { 2753 if ($y0 < $y + $h && $y < $y1) {
2757 2754
2758 my $layout = $self->get_layout ($para); 2755 my $layout = $self->get_layout ($para);
2759 2756
2760 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2761
2762 glRasterPos $para->{indent}, $y - $y0; 2757 $layout->render ($para->{indent}, $y - $y0);
2763 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2764 2758
2765 if (my @w = @{ $para->{widget} }) { 2759 if (my @w = @{ $para->{widget} }) {
2766 my @s = $layout->get_shapes; 2760 my @s = $layout->get_shapes;
2767 2761
2768 glDisable GL_BLEND;
2769 for (@w) { 2762 for (@w) {
2770 my ($dx, $dy) = splice @s, 0, 2, (); 2763 my ($dx, $dy) = splice @s, 0, 2, ();
2771 2764
2772 $_->{x} = $dx + $para->{indent}; 2765 $_->{x} = $dx + $para->{indent};
2773 $_->{y} = $dy + $y - $y0; 2766 $_->{y} = $dy + $y - $y0;
2774 2767
2775 $_->draw; 2768 $_->draw;
2776 } 2769 }
2777 glEnable GL_BLEND;
2778 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2779 } 2770 }
2780 } 2771 }
2781 2772
2782 $y += $h; 2773 $y += $h;
2783 } 2774 }
2784
2785 glDisable GL_BLEND;
2786 }; 2775 };
2787 }); 2776 });
2788} 2777}
2789 2778
2790sub reconfigure { 2779sub reconfigure {
3086 for my $item (@{ $self->{items} }) { 3075 for my $item (@{ $self->{items} }) {
3087 my ($widget, $cb, $tooltip) = @$item; 3076 my ($widget, $cb, $tooltip) = @$item;
3088 3077
3089 # handle various types of items, only text for now 3078 # handle various types of items, only text for now
3090 if (!ref $widget) { 3079 if (!ref $widget) {
3080 if ($widget =~ /\t/) {
3081 my ($left, $right) = split /\t/, $widget, 2;
3082
3083 $widget = new CFClient::UI::HBox
3084 can_hover => 1,
3085 can_events => 1,
3086 tooltip => $tooltip,
3087 children => [
3088 (new CFClient::UI::Label markup => $left, expand => 1),
3089 (new CFClient::UI::Label markup => $right, align => +1),
3090 ],
3091 ;
3092
3093 } else {
3091 $widget = new CFClient::UI::Label 3094 $widget = new CFClient::UI::Label
3092 can_hover => 1, 3095 can_hover => 1,
3093 can_events => 1, 3096 can_events => 1,
3094 markup => $widget, 3097 markup => $widget,
3095 tooltip => $tooltip 3098 tooltip => $tooltip;
3099 }
3096 } 3100 }
3097 3101
3098 $self->{item}{$widget} = $item; 3102 $self->{item}{$widget} = $item;
3099 3103
3100 $self->{vbox}->add ($widget); 3104 $self->{vbox}->add ($widget);
3822 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 3826 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
3823 3827
3824 $w = 0 if $w < 0; 3828 $w = 0 if $w < 0;
3825 $h = 0 if $h < 0; 3829 $h = 0 if $h < 0;
3826 3830
3831 $w = max $widget->{min_w}, $w;
3832 $h = max $widget->{min_h}, $h;
3833
3834 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3835 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3836
3827 $w = int $w + 0.5; 3837 $w = int $w + 0.5;
3828 $h = int $h + 0.5; 3838 $h = int $h + 0.5;
3829 3839
3830 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 3840 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
3831 $widget->{old_w} = $widget->{w}; 3841 $widget->{old_w} = $widget->{w};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines