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.327 by root, Mon Jul 17 01:41:53 2006 UTC

587} 587}
588 588
589sub DESTROY { 589sub DESTROY {
590 my ($self) = @_; 590 my ($self) = @_;
591 591
592 return if CFClient::in_destruct;
593
592 delete $WIDGET{$self+0}; 594 delete $WIDGET{$self+0};
593 595
594 eval { $self->destroy }; 596 eval { $self->destroy };
595 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 597 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
596} 598}
1080 my $self = $class->SUPER::new ( 1082 my $self = $class->SUPER::new (
1081 bg => [1, 1, 1, 1], 1083 bg => [1, 1, 1, 1],
1082 border_bg => [1, 1, 1, 1], 1084 border_bg => [1, 1, 1, 1],
1083 border => 0.6, 1085 border => 0.6,
1084 can_events => 1, 1086 can_events => 1,
1085 min_w => 16, 1087 min_w => 64,
1086 min_h => 16, 1088 min_h => 32,
1087 %arg, 1089 %arg,
1088 ); 1090 );
1089 1091
1090 $self->{title_widget} = new CFClient::UI::Label 1092 $self->{title_widget} = new CFClient::UI::Label
1091 align => 0, 1093 align => 0,
1591 my ($self, $text) = @_; 1593 my ($self, $text) = @_;
1592 1594
1593 return if $self->{text} eq "T$text"; 1595 return if $self->{text} eq "T$text";
1594 $self->{text} = "T$text"; 1596 $self->{text} = "T$text";
1595 1597
1596 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1597 $self->{layout}->set_text ($text); 1598 $self->{layout}->set_text ($text);
1598 1599
1599 delete $self->{size_req}; 1600 delete $self->{size_req};
1600 $self->realloc; 1601 $self->realloc;
1601 $self->update; 1602 $self->update;
1607 return if $self->{text} eq "M$markup"; 1608 return if $self->{text} eq "M$markup";
1608 $self->{text} = "M$markup"; 1609 $self->{text} = "M$markup";
1609 1610
1610 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1611 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1611 1612
1612 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1613 $self->{layout}->set_markup ($markup); 1613 $self->{layout}->set_markup ($markup);
1614 1614
1615 delete $self->{size_req}; 1615 delete $self->{size_req};
1616 $self->realloc; 1616 $self->realloc;
1617 $self->update; 1617 $self->update;
1629 1629
1630 my ($w, $h) = $self->{layout}->size; 1630 my ($w, $h) = $self->{layout}->size;
1631 1631
1632 if (exists $self->{template}) { 1632 if (exists $self->{template}) {
1633 $self->{template}->set_font ($self->{font}) if $self->{font}; 1633 $self->{template}->set_font ($self->{font}) if $self->{font};
1634 $self->{template}->set_width ($self->{max_w} || -1);
1634 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1635 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1635 1636
1636 my ($w2, $h2) = $self->{template}->size; 1637 my ($w2, $h2) = $self->{template}->size;
1637 1638
1638 $w = List::Util::max $w, $w2; 1639 $w = List::Util::max $w, $w2;
1672 1673
1673sub reconfigure { 1674sub reconfigure {
1674 my ($self) = @_; 1675 my ($self) = @_;
1675 1676
1676 delete $self->{size_req}; 1677 delete $self->{size_req};
1678 delete $self->{texture};
1677 1679
1678 $self->SUPER::reconfigure; 1680 $self->SUPER::reconfigure;
1679} 1681}
1680 1682
1681sub _draw { 1683sub _draw {
1682 my ($self) = @_; 1684 my ($self) = @_;
1683 1685
1684 $self->SUPER::_draw; # draw background, if applicable 1686 $self->SUPER::_draw; # draw background, if applicable
1685 1687
1686 my $tex = $self->{texture} ||= do { 1688 my $size = $self->{texture} ||= do {
1687 $self->{layout}->set_foreground (@{$self->{fg}}); 1689 $self->{layout}->set_foreground (@{$self->{fg}});
1688 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1690 $self->{layout}->set_font ($self->{font}) if $self->{font};
1689 $self->{layout}->set_width ($self->{w}); 1691 $self->{layout}->set_width ($self->{w});
1690 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1692 $self->{layout}->set_ellipsise ($self->{ellipsise});
1691 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1693 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1692 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1694 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1693 1695
1694 new_from_layout CFClient::Texture $self->{layout} 1696 [$self->{layout}->size]
1695 }; 1697 };
1696 1698
1697 unless (exists $self->{ox}) { 1699 unless (exists $self->{ox}) {
1698 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1700 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1699 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1701 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x}
1700 : ($self->{w} - $tex->{w}) * 0.5); 1702 : ($self->{w} - $size->[0]) * 0.5);
1701 1703
1702 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1704 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1703 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1705 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
1704 : ($self->{h} - $tex->{h}) * 0.5); 1706 : ($self->{h} - $size->[1]) * 0.5);
1705 }; 1707 };
1706 1708
1707 glEnable GL_TEXTURE_2D;
1708
1709 my $w = List::Util::min $self->{w} + 4, $tex->{w}; 1709 my $w = List::Util::min $self->{w} + 4, $size->[0];
1710 my $h = List::Util::min $self->{h} + 2, $tex->{h}; 1710 my $h = List::Util::min $self->{h} + 2, $size->[1];
1711 1711
1712 if ($tex->{format} == GL_ALPHA) { 1712 $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} 1713}
1723 1714
1724############################################################################# 1715#############################################################################
1725 1716
1726package CFClient::UI::EntryBase; 1717package CFClient::UI::EntryBase;
1837 1828
1838 my $idx = $self->{layout}->xy_to_index ($x, $y); 1829 my $idx = $self->{layout}->xy_to_index ($x, $y);
1839 1830
1840 # byte-index to char-index 1831 # byte-index to char-index
1841 my $text = $self->{text}; 1832 my $text = $self->{text};
1842 utf8::encode $text; 1833 utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text;
1843 $self->{cursor} = length substr $text, 0, $idx; 1834 $self->{cursor} = length $text;
1844 1835
1845 $self->_set_text ($self->{text}); 1836 $self->_set_text ($self->{text});
1846 $self->update; 1837 $self->update;
1847 1838
1848 1 1839 1
2127 my $self = $class->SUPER::new ( 2118 my $self = $class->SUPER::new (
2128 can_events => 0, 2119 can_events => 0,
2129 @_, 2120 @_,
2130 ); 2121 );
2131 2122
2132 $self->{path} 2123 $self->{path} || $self->{tex}
2133 or Carp::croak "required attribute 'path' not set"; 2124 or Carp::croak "'path' or 'tex' attributes required";
2134 2125
2135 $self->{tex} = $texture_cache{$self->{path}} ||= 2126 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2136 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; 2127 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2137 2128
2138 Scalar::Util::weaken $texture_cache{$self->{path}}; 2129 Scalar::Util::weaken $texture_cache{$self->{path}};
2139 2130
2140 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2131 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2573 can_events => 0, 2564 can_events => 0,
2574 indent => 0, 2565 indent => 0,
2575 #font => default_font 2566 #font => default_font
2576 @_, 2567 @_,
2577 2568
2578 layout => (new CFClient::Layout 1), 2569 layout => (new CFClient::Layout),
2579 par => [], 2570 par => [],
2580 height => 0, 2571 height => 0,
2581 children => [ 2572 children => [
2582 (new CFClient::UI::Empty expand => 1), 2573 (new CFClient::UI::Empty expand => 1),
2583 (new CFClient::UI::Slider vertical => 1), 2574 (new CFClient::UI::Slider vertical => 1),
2744 my $y0 = $top; 2735 my $y0 = $top;
2745 my $y1 = $top + $H; 2736 my $y1 = $top + $H;
2746 2737
2747 my $y = 0; 2738 my $y = 0;
2748 2739
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}}) { 2740 for my $para (@{$self->{par}}) {
2754 my $h = $para->{h}; 2741 my $h = $para->{h};
2755 2742
2756 if ($y0 < $y + $h && $y < $y1) { 2743 if ($y0 < $y + $h && $y < $y1) {
2757 2744
2758 my $layout = $self->get_layout ($para); 2745 my $layout = $self->get_layout ($para);
2759 2746
2760 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2761
2762 glRasterPos $para->{indent}, $y - $y0; 2747 $layout->render ($para->{indent}, $y - $y0);
2763 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2764 2748
2765 if (my @w = @{ $para->{widget} }) { 2749 if (my @w = @{ $para->{widget} }) {
2766 my @s = $layout->get_shapes; 2750 my @s = $layout->get_shapes;
2767 2751
2768 glDisable GL_BLEND;
2769 for (@w) { 2752 for (@w) {
2770 my ($dx, $dy) = splice @s, 0, 2, (); 2753 my ($dx, $dy) = splice @s, 0, 2, ();
2771 2754
2772 $_->{x} = $dx + $para->{indent}; 2755 $_->{x} = $dx + $para->{indent};
2773 $_->{y} = $dy + $y - $y0; 2756 $_->{y} = $dy + $y - $y0;
2774 2757
2775 $_->draw; 2758 $_->draw;
2776 } 2759 }
2777 glEnable GL_BLEND;
2778 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2779 } 2760 }
2780 } 2761 }
2781 2762
2782 $y += $h; 2763 $y += $h;
2783 } 2764 }
2784
2785 glDisable GL_BLEND;
2786 }; 2765 };
2787 }); 2766 });
2788} 2767}
2789 2768
2790sub reconfigure { 2769sub reconfigure {
3086 for my $item (@{ $self->{items} }) { 3065 for my $item (@{ $self->{items} }) {
3087 my ($widget, $cb, $tooltip) = @$item; 3066 my ($widget, $cb, $tooltip) = @$item;
3088 3067
3089 # handle various types of items, only text for now 3068 # handle various types of items, only text for now
3090 if (!ref $widget) { 3069 if (!ref $widget) {
3070 if ($widget =~ /\t/) {
3071 my ($left, $right) = split /\t/, $widget, 2;
3072
3073 $widget = new CFClient::UI::HBox
3074 can_hover => 1,
3075 can_events => 1,
3076 tooltip => $tooltip,
3077 children => [
3078 (new CFClient::UI::Label markup => $left, expand => 1),
3079 (new CFClient::UI::Label markup => $right, align => +1),
3080 ],
3081 ;
3082
3083 } else {
3091 $widget = new CFClient::UI::Label 3084 $widget = new CFClient::UI::Label
3092 can_hover => 1, 3085 can_hover => 1,
3093 can_events => 1, 3086 can_events => 1,
3094 markup => $widget, 3087 markup => $widget,
3095 tooltip => $tooltip 3088 tooltip => $tooltip;
3089 }
3096 } 3090 }
3097 3091
3098 $self->{item}{$widget} = $item; 3092 $self->{item}{$widget} = $item;
3099 3093
3100 $self->{vbox}->add ($widget); 3094 $self->{vbox}->add ($widget);
3822 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 3816 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
3823 3817
3824 $w = 0 if $w < 0; 3818 $w = 0 if $w < 0;
3825 $h = 0 if $h < 0; 3819 $h = 0 if $h < 0;
3826 3820
3821 $w = max $widget->{min_w}, $w;
3822 $h = max $widget->{min_h}, $h;
3823
3824 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3825 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3826
3827 $w = int $w + 0.5; 3827 $w = int $w + 0.5;
3828 $h = int $h + 0.5; 3828 $h = int $h + 0.5;
3829 3829
3830 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 3830 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
3831 $widget->{old_w} = $widget->{w}; 3831 $widget->{old_w} = $widget->{w};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines