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.321 by root, Tue Jul 4 23:44:23 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,
1536 #font => default_font 1538 #font => default_font
1537 #text => initial text 1539 #text => initial text
1538 #markup => initial narkup 1540 #markup => initial narkup
1539 #max_w => maximum pixel width 1541 #max_w => maximum pixel width
1540 ellipsise => 3, # end 1542 ellipsise => 3, # end
1541 layout => (new CFClient::Layout 2), 1543 layout => (new CFClient::Layout),
1542 fontsize => 1, 1544 fontsize => 1,
1543 align => -1, 1545 align => -1,
1544 valign => -1, 1546 valign => -1,
1545 padding_x => 2, 1547 padding_x => 2,
1546 padding_y => 2, 1548 padding_y => 2,
1547 can_events => 0, 1549 can_events => 0,
1548 %arg 1550 %arg
1549 ); 1551 );
1550 1552
1551 if (exists $self->{template}) { 1553 if (exists $self->{template}) {
1552 my $layout = new CFClient::Layout 2; 1554 my $layout = new CFClient::Layout;
1553 $layout->set_text (delete $self->{template}); 1555 $layout->set_text (delete $self->{template});
1554 $self->{template} = $layout; 1556 $self->{template} = $layout;
1555 } 1557 }
1556 1558
1557 if (exists $self->{markup}) { 1559 if (exists $self->{markup}) {
1627 1629
1628 my ($w, $h) = $self->{layout}->size; 1630 my ($w, $h) = $self->{layout}->size;
1629 1631
1630 if (exists $self->{template}) { 1632 if (exists $self->{template}) {
1631 $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);
1632 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1635 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1633 1636
1634 my ($w2, $h2) = $self->{template}->size; 1637 my ($w2, $h2) = $self->{template}->size;
1635 1638
1636 $w = List::Util::max $w, $w2; 1639 $w = List::Util::max $w, $w2;
1688 $self->{layout}->set_width ($self->{w}); 1691 $self->{layout}->set_width ($self->{w});
1689 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1692 $self->{layout}->set_ellipsise ($self->{ellipsise});
1690 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1693 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1691 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1694 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1692 1695
1693 $self->{size_req} 1696 [$self->{layout}->size]
1694 }; 1697 };
1695 1698
1696 unless (exists $self->{ox}) { 1699 unless (exists $self->{ox}) {
1697 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1700 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1698 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} 1701 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x}
1825 1828
1826 my $idx = $self->{layout}->xy_to_index ($x, $y); 1829 my $idx = $self->{layout}->xy_to_index ($x, $y);
1827 1830
1828 # byte-index to char-index 1831 # byte-index to char-index
1829 my $text = $self->{text}; 1832 my $text = $self->{text};
1830 utf8::encode $text; 1833 utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text;
1831 $self->{cursor} = length substr $text, 0, $idx; 1834 $self->{cursor} = length $text;
1832 1835
1833 $self->_set_text ($self->{text}); 1836 $self->_set_text ($self->{text});
1834 $self->update; 1837 $self->update;
1835 1838
1836 1 1839 1
2115 my $self = $class->SUPER::new ( 2118 my $self = $class->SUPER::new (
2116 can_events => 0, 2119 can_events => 0,
2117 @_, 2120 @_,
2118 ); 2121 );
2119 2122
2120 $self->{path} 2123 $self->{path} || $self->{tex}
2121 or Carp::croak "required attribute 'path' not set"; 2124 or Carp::croak "'path' or 'tex' attributes required";
2122 2125
2123 $self->{tex} = $texture_cache{$self->{path}} ||= 2126 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2124 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;
2125 2128
2126 Scalar::Util::weaken $texture_cache{$self->{path}}; 2129 Scalar::Util::weaken $texture_cache{$self->{path}};
2127 2130
2128 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2131 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2561 can_events => 0, 2564 can_events => 0,
2562 indent => 0, 2565 indent => 0,
2563 #font => default_font 2566 #font => default_font
2564 @_, 2567 @_,
2565 2568
2566 layout => (new CFClient::Layout 2), 2569 layout => (new CFClient::Layout),
2567 par => [], 2570 par => [],
2568 height => 0, 2571 height => 0,
2569 children => [ 2572 children => [
2570 (new CFClient::UI::Empty expand => 1), 2573 (new CFClient::UI::Empty expand => 1),
2571 (new CFClient::UI::Slider vertical => 1), 2574 (new CFClient::UI::Slider vertical => 1),
3062 for my $item (@{ $self->{items} }) { 3065 for my $item (@{ $self->{items} }) {
3063 my ($widget, $cb, $tooltip) = @$item; 3066 my ($widget, $cb, $tooltip) = @$item;
3064 3067
3065 # handle various types of items, only text for now 3068 # handle various types of items, only text for now
3066 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 {
3067 $widget = new CFClient::UI::Label 3084 $widget = new CFClient::UI::Label
3068 can_hover => 1, 3085 can_hover => 1,
3069 can_events => 1, 3086 can_events => 1,
3070 markup => $widget, 3087 markup => $widget,
3071 tooltip => $tooltip 3088 tooltip => $tooltip;
3089 }
3072 } 3090 }
3073 3091
3074 $self->{item}{$widget} = $item; 3092 $self->{item}{$widget} = $item;
3075 3093
3076 $self->{vbox}->add ($widget); 3094 $self->{vbox}->add ($widget);
3798 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 3816 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
3799 3817
3800 $w = 0 if $w < 0; 3818 $w = 0 if $w < 0;
3801 $h = 0 if $h < 0; 3819 $h = 0 if $h < 0;
3802 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
3803 $w = int $w + 0.5; 3827 $w = int $w + 0.5;
3804 $h = int $h + 0.5; 3828 $h = int $h + 0.5;
3805 3829
3806 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}) {
3807 $widget->{old_w} = $widget->{w}; 3831 $widget->{old_w} = $widget->{w};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines