--- deliantra/Deliantra-Client/DC/UI.pm 2010/10/12 05:11:38 1.481 +++ deliantra/Deliantra-Client/DC/UI.pm 2012/11/21 13:23:10 1.486 @@ -4,6 +4,7 @@ use List::Util (); +use AnyEvent (); use Guard (); use DC; @@ -364,8 +365,8 @@ sub set_size { my ($self, $w, $h) = @_; - $self->{force_w} = $w; - $self->{force_h} = $h; + $self->{force_w} = List::Util::min $w, ($self->{max_w} || $::WIDTH ); + $self->{force_h} = List::Util::min $h, ($self->{max_h} || $::HEIGHT); $self->realloc; } @@ -1475,10 +1476,10 @@ my ($w, $h) = @$self{qw(w h)}; my $border = $self->border; - my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); - my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); + my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); # left-right + my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); # top-down - if ($lr & $td) { + if ($lr & $td) { # corners my ($wx, $wy) = ($self->{x}, $self->{y}); my ($ox, $oy) = ($ev->{x}, $ev->{y}); my ($bw, $bh) = ($self->{w}, $self->{h}); @@ -1492,14 +1493,16 @@ my $dx = $ev->{x} - $ox; my $dy = $ev->{y} - $oy; - $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); - $self->{force_h} = $bh + $dy * ($my ? -1 : 1); + $self->set_size ( + $bw + $dx * ($mx ? -1 : 1), + $bh + $dy * ($my ? -1 : 1), + ); $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); $self->realloc; }; - } elsif ($lr ^ $td) { + } elsif ($lr ^ $td) { # edges my ($ox, $oy) = ($ev->{x}, $ev->{y}); my ($bx, $by) = ($self->{x}, $self->{y}); @@ -3288,7 +3291,6 @@ @_, layout => (new DC::Layout), - par => [], max_par => 0, height => 0, children => [ @@ -3299,6 +3301,8 @@ $self->{children}[1]->connect (changed => sub { $self->update }); + $self->add_paragraph (@{ delete $self->{par} }) if @{ $self->{par} }; + $self } @@ -3640,28 +3644,66 @@ ) } -sub set_tooltip_from { - my ($self, $widget) = @_; +# expand, as good as possible +sub _expand_doclets { + my ($tip) = @_; + + $tip =~ s{#\(([^)]+)\)}{ + if ($::CONN) { + exists $::CONN->{doclet}{$1} + ? $::CONN->{doclet}{$1} + : "(waiting for server to show full text)" + } else { + "(unable to show full text without server connection)" + } + }ge; - my $tip = $widget->{tooltip}; - $tip = $tip->($widget) if "CODE" eq ref $tip; - + $tip =~ s/^\n+//; + $tip =~ s/\n+$//; + + $tip +} + +# expands a tooltip, potentially multiple times remotely +# and returns a guard. clals the clalback each time the text changes. +sub expand_tooltip { + my ($tip, $cb) = @_; + + # first expand #name tooltips from local pod $tip = DC::Pod::section_label tooltip => $1 - if $tip =~ /^#(.*)$/; + if $tip =~ /^#([^(].*)$/; + + my $active; # true if any remote requests outstanding - if ($ENV{CFPLUS_DEBUG} & 2) { - $tip .= "\n\n" . (ref $widget) . "\n" - . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" - . "req $widget->{req_w} $widget->{req_h}\n" - . "visible $widget->{visible}"; + if ($::CONN && $::CONN->{addme_success}) { + # now find all doclet references + for my $doclet ($tip =~ /#\(([^)]+)\)/g) { + unless (exists $::CONN->{doclet}{$doclet}) { + # need to ask the server + # we don't try to avoid duplicate requests + + $active = 1; + $::CONN->send_exti_req (doclet => (split /\//, $doclet, 2), sub { + $::CONN->{doclet}{$doclet} = DC::sanitise_cfxml $_[0]; + $cb->(_expand_doclets $tip) if $active; + }); + } + } } - $tip =~ s/^\n+//; - $tip =~ s/\n+$//; + $cb->(_expand_doclets $tip); + + $active and Guard::guard { undef $active } +} + +sub set_tooltip_from { + my ($self, $widget) = @_; + + my $tip = $widget->{tooltip}; + $tip = $tip->($widget) if "CODE" eq ref $tip; $self->add (new DC::UI::Label fg => $DC::THEME{tooltip_fg}, - markup => $tip, max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, align => 0, fontsize => 0.8, @@ -3669,6 +3711,19 @@ ellipsise => 0, font => ($widget->{tooltip_font} || $::FONT_PROP), ); + + $self->{tooltip_expand} = expand_tooltip $tip, sub { + my ($tip) = @_; + + if ($ENV{CFPLUS_DEBUG} & 2) { + $tip .= "\n\n" . (ref $widget) . "\n" + . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" + . "req $widget->{req_w} $widget->{req_h}\n" + . "visible $widget->{visible}"; + } + + $self->{children}[0]->set_markup ($tip); + }; } sub size_request { @@ -4294,7 +4349,7 @@ sub reorder { my ($self) = @_; - my $NOW = EV::time; + my $NOW = AE::time; # freeze display when hovering over any label return if $DC::UI::TOOLTIP->{owner} @@ -4403,6 +4458,16 @@ }); } +sub clr_group { + my ($self, $group) = @_; + + if (delete $self->{item}{$group}) { + $ROOT->on_refresh (reorder => sub { + $self->reorder; + }); + } +} + sub reconfigure { my ($self) = @_;