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.194 by root, Thu May 11 23:41:47 2006 UTC vs.
Revision 1.198 by root, Fri May 12 02:08:52 2006 UTC

24 24
25 my $tip = $widget->{tooltip}; 25 my $tip = $widget->{tooltip};
26 26
27 $tip = $tip->($widget) if CODE:: eq ref $tip; 27 $tip = $tip->($widget) if CODE:: eq ref $tip;
28 28
29 $TOOLTIP->set_markup ($widget->{tooltip}); 29 $TOOLTIP->set_tooltip_from ($widget);
30
31 $TOOLTIP->show; 30 $TOOLTIP->show;
32 31
33 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
34 33
35 if ($x + $TOOLTIP->{w} > $::WIDTH) { 34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
36 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0);
37 } 36 }
38 37
39 $TOOLTIP->move ($x, $y); 38 $TOOLTIP->move ($x, $y);
39 $TOOLTIP->check_size;
40 $TOOLTIP->update;
40 } 41 }
41 42
42 return; 43 return;
43 } 44 }
44 } 45 }
251 my ($self) = @_; 252 my ($self) = @_;
252 253
253 $_->reconfigure 254 $_->reconfigure
254 for $self->children; 255 for $self->children;
255 256
256 $self->check_size; 257 $self->check_size (1);
257 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
258 $self->update; 258 $self->update;
259} 259}
260 260
261sub set_max_size { 261sub set_max_size {
262 my ($self, $w, $h) = @_; 262 my ($self, $w, $h) = @_;
383sub set_parent { 383sub set_parent {
384 my ($self, $parent) = @_; 384 my ($self, $parent) = @_;
385 385
386 Scalar::Util::weaken ($self->{parent} = $parent); 386 Scalar::Util::weaken ($self->{parent} = $parent);
387 387
388
389 # TODO: req_w _does_change after ->reconfigure
388 $self->check_size 390 $self->check_size
389 unless exists $self->{req_w}; 391 unless exists $self->{req_w};
390} 392}
391 393
392sub check_size { 394sub check_size {
393 my ($self) = @_; 395 my ($self, $forced) = @_;
394 396
397 $self->{force_alloc} = 1 if $forced;
395 $CFClient::UI::ROOT->{check_size}{$self} = $self; 398 $CFClient::UI::ROOT->{check_size}{$self} = $self;
396} 399}
397 400
398sub update { 401sub update {
399 my ($self) = @_; 402 my ($self) = @_;
509 $self->{children} = [ 512 $self->{children} = [
510 sort { $a->{z} <=> $b->{z} } 513 sort { $a->{z} <=> $b->{z} }
511 @{$self->{children}}, @widgets 514 @{$self->{children}}, @widgets
512 ]; 515 ];
513 516
514 $self->check_size; 517 $self->check_size (1);
515 $self->update; 518 $self->update;
516} 519}
517 520
518sub children { 521sub children {
519 @{ $_[0]{children} } 522 @{ $_[0]{children} }
626} 629}
627 630
628sub update { 631sub update {
629 my ($self) = @_; 632 my ($self) = @_;
630 633
631 $ROOT->on_refresh ($self => sub { $self->render_child }); 634 $ROOT->on_post_alloc ($self => sub { $self->render_child });
632 $self->SUPER::update; 635 $self->SUPER::update;
633} 636}
634 637
635sub size_allocate { 638sub size_allocate {
636 my ($self, $w, $h) = @_; 639 my ($self, $w, $h) = @_;
785 788
786our @ISA = CFClient::UI::Bin::; 789our @ISA = CFClient::UI::Bin::;
787 790
788use CFClient::OpenGL; 791use CFClient::OpenGL;
789 792
790sub new {
791 my $class = shift;
792
793 my $self = $class->SUPER::new (
794 bg => [1, 1, 1, 1],
795 border_bg => [1, 1, 1, 1],
796 border => 0.8,
797 @_
798 );
799
800 $self
801}
802
803sub _draw {
804 my ($self) = @_;
805
806 my ($w, $h) = ($self->{w}, $self->{h});
807
808 glEnable GL_BLEND;
809 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
810 glEnable GL_TEXTURE_2D;
811 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
812
813# glBegin GL_QUADS;
814# glColor 0, 0, 0, 0;
815# glVertex 0 , 0;
816# glVertex 0 , $h;
817# glVertex $w, $h;
818# glVertex $w, 0;
819# glEnd;
820
821
822 $self->child->draw;
823 glDisable GL_BLEND;
824 glDisable GL_TEXTURE_2D;
825}
826
827############################################################################# 793#############################################################################
828 794
829package CFClient::UI::FancyFrame; 795package CFClient::UI::FancyFrame;
830 796
831our @ISA = CFClient::UI::Bin::; 797our @ISA = CFClient::UI::Bin::;
945 my ($self) = @_; 911 my ($self) = @_;
946 912
947 my ($w, $h ) = ($self->{w}, $self->{h}); 913 my ($w, $h ) = ($self->{w}, $self->{h});
948 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 914 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
949 915
950 glEnable GL_BLEND;
951 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
952 glEnable GL_TEXTURE_2D; 916 glEnable GL_TEXTURE_2D;
953 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 917 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
954 918
955 my $border = $self->border; 919 my $border = $self->border;
956 920
957 glColor @{ $self->{border_bg} }; 921 glColor @{ $self->{border_bg} };
958 $tex[1]->draw_quad (0, 0, $w, $border); 922 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
959 $tex[3]->draw_quad (0, $border, $border, $ch); 923 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
960 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 924 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
961 $tex[4]->draw_quad (0, $h - $border, $w, $border); 925 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
962 926
963 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 927 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
964 my $bg = $tex[0]; 928 my $bg = $tex[0];
965 929
966 # TODO: repeat texture not scale 930 # TODO: repeat texture not scale
970 glColor @{ $self->{bg} }; 934 glColor @{ $self->{bg} };
971 935
972 $bg->{s} = $rep_x; 936 $bg->{s} = $rep_x;
973 $bg->{t} = $rep_y; 937 $bg->{t} = $rep_y;
974 $bg->{wrap_mode} = 1; 938 $bg->{wrap_mode} = 1;
975 $bg->draw_quad ($border, $border, $cw, $ch); 939 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
940 }
976 941
977 glDisable GL_TEXTURE_2D; 942 glDisable GL_TEXTURE_2D;
978 glDisable GL_BLEND;
979 }
980 943
981 $self->{title}->draw if $self->{title}; 944 $self->{title}->draw if $self->{title};
982 945
983 $self->child->draw; 946 $self->child->draw;
984} 947}
1672 1635
1673 if ($GRAB == $self) { 1636 if ($GRAB == $self) {
1674 $self->{fg} = $self->{active_fg}; 1637 $self->{fg} = $self->{active_fg};
1675 } 1638 }
1676 1639
1677 glEnable GL_BLEND;
1678 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1679 glEnable GL_TEXTURE_2D; 1640 glEnable GL_TEXTURE_2D;
1680 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1641 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1681 glColor 0, 0, 0, 1; 1642 glColor 0, 0, 0, 1;
1682 1643
1683 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); 1644 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
1684 1645
1685 glDisable GL_TEXTURE_2D; 1646 glDisable GL_TEXTURE_2D;
1686 glDisable GL_BLEND;
1687 1647
1688 $self->SUPER::_draw; 1648 $self->SUPER::_draw;
1689} 1649}
1690 1650
1691############################################################################# 1651#############################################################################
1738 1698
1739 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1699 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1740 1700
1741 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1701 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1742 1702
1743 glEnable GL_BLEND; 1703 my $tex = $self->{state} ? $tex[1] : $tex[0];
1704
1744 glEnable GL_TEXTURE_2D; 1705 glEnable GL_TEXTURE_2D;
1745 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1746
1747 my $tex = $self->{state} ? $tex[1] : $tex[0];
1748
1749 $tex->draw_quad (0, 0, $s, $s); 1706 $tex->draw_quad_alpha (0, 0, $s, $s);
1750
1751 glDisable GL_TEXTURE_2D; 1707 glDisable GL_TEXTURE_2D;
1752 glDisable GL_BLEND;
1753} 1708}
1754 1709
1755############################################################################# 1710#############################################################################
1756 1711
1757package CFClient::UI::Image; 1712package CFClient::UI::Image;
1800 glTranslate 0, -$self->{w}, 0; 1755 glTranslate 0, -$self->{w}, 0;
1801 1756
1802 ($w, $h) = ($h, $w); 1757 ($w, $h) = ($h, $w);
1803 } 1758 }
1804 1759
1805 glEnable GL_BLEND;
1806 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1807 glEnable GL_TEXTURE_2D; 1760 glEnable GL_TEXTURE_2D;
1808 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1761 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1809 1762
1810 $tex->draw_quad (0, 0, $w, $h); 1763 $tex->draw_quad_alpha (0, 0, $w, $h);
1811 1764
1812 glDisable GL_BLEND;
1813 glDisable GL_TEXTURE_2D; 1765 glDisable GL_TEXTURE_2D;
1814} 1766}
1815 1767
1816############################################################################# 1768#############################################################################
1817 1769
2109 $page ||= 2; 2061 $page ||= 2;
2110 2062
2111 my $knob_a = $inner_pad_px + ($value - $page * 0.5); 2063 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2112 my $knob_b = $inner_pad_px + ($value + $page * 0.5); 2064 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2113 2065
2114 glEnable GL_BLEND;
2115 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2116 glEnable GL_TEXTURE_2D; 2066 glEnable GL_TEXTURE_2D;
2117 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2067 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2118 2068
2119 # draw background 2069 # draw background
2120 $tex[1]->draw_quad (0, 0, $w, $h); 2070 $tex[1]->draw_quad_alpha (0, 0, $w, $h);
2121 2071
2122 # draw handle 2072 # draw handle
2123 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); 2073 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h);
2124 2074
2125 glDisable GL_BLEND;
2126 glDisable GL_TEXTURE_2D; 2075 glDisable GL_TEXTURE_2D;
2127} 2076}
2128 2077
2129############################################################################# 2078#############################################################################
2130 2079
2141 fontsize => 1, 2090 fontsize => 1,
2142 can_events => 0, 2091 can_events => 0,
2143 #font => default_font 2092 #font => default_font
2144 @_, 2093 @_,
2145 2094
2146 layout => (new CFClient::Layout), 2095 layout => (new CFClient::Layout 1),
2147 par => [], 2096 par => [],
2148 height => 0, 2097 height => 0,
2149 children => [ 2098 children => [
2150 (new CFClient::UI::Empty expand => 1), 2099 (new CFClient::UI::Empty expand => 1),
2151 (new CFClient::UI::Slider vertical => 1), 2100 (new CFClient::UI::Slider vertical => 1),
2169 2118
2170 my $layout = $self->{layout}; 2119 my $layout = $self->{layout};
2171 2120
2172 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2121 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2173 $layout->set_width ($self->{children}[0]{w}); 2122 $layout->set_width ($self->{children}[0]{w});
2174 $layout->set_text ($text); 2123 $layout->set_markup ($text);
2175 2124
2176 ($layout->size)[1] 2125 ($layout->size)[1]
2177} 2126}
2178 2127
2179sub reflow { 2128sub reflow {
2217 2166
2218 return unless $self->{h} > 0; 2167 return unless $self->{h} > 0;
2219 2168
2220 delete $self->{texture}; 2169 delete $self->{texture};
2221 2170
2222 $ROOT->on_refresh ($self, sub { 2171 $ROOT->on_post_alloc ($self, sub {
2223 if (delete $self->{need_reflow}) { 2172 if (delete $self->{need_reflow}) {
2224 my $height = 0; 2173 my $height = 0;
2225 2174
2226 $height += $_->[0] = $self->text_height ($_->[2]) 2175 $height += $_->[0] = $self->text_height ($_->[2])
2227 for @{$self->{par}}; 2176 for @{$self->{par}};
2235 2184
2236 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2185 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2237 glClearColor 0, 0, 0, 0; 2186 glClearColor 0, 0, 0, 0;
2238 glClear GL_COLOR_BUFFER_BIT; 2187 glClear GL_COLOR_BUFFER_BIT;
2239 2188
2240 glEnable GL_BLEND;
2241 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2242 glEnable GL_TEXTURE_2D; 2189 glEnable GL_TEXTURE_2D;
2243 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2190 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2244 2191
2245 my $top = int $self->{children}[1]{range}[0]; 2192 my $top = int $self->{children}[1]{range}[0];
2246 2193
2255 2202
2256 for my $par (@{$self->{par}}) { 2203 for my $par (@{$self->{par}}) {
2257 my $h = $par->[0]; 2204 my $h = $par->[0];
2258 2205
2259 if ($y0 < $y + $h && $y < $y1) { 2206 if ($y0 < $y + $h && $y < $y1) {
2207 $layout->set_foreground (@{ $par->[1] });
2260 $layout->set_text ($par->[2]); 2208 $layout->set_markup ($par->[2]);
2261 2209
2262 glColor @{ $par->[1] };
2263 my ($W, $H) = $layout->size; 2210 my ($W, $H) = $layout->size;
2264 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); 2211 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0);
2265 } 2212 }
2266 2213
2267 $y += $h; 2214 $y += $h;
2268 } 2215 }
2269 2216
2270 glDisable GL_TEXTURE_2D; 2217 glDisable GL_TEXTURE_2D;
2271 glDisable GL_BLEND;
2272 }; 2218 };
2273 }); 2219 });
2274} 2220}
2275 2221
2276sub _draw { 2222sub _draw {
2277 my ($self) = @_; 2223 my ($self) = @_;
2278 2224
2279 glEnable GL_BLEND;
2280 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2281 glEnable GL_TEXTURE_2D; 2225 glEnable GL_TEXTURE_2D;
2282 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2226 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2283 glColor 1, 1, 1, 1; 2227 glColor 1, 1, 1, 1;
2284 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2228 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2285 glDisable GL_TEXTURE_2D; 2229 glDisable GL_TEXTURE_2D;
2286 glDisable GL_BLEND;
2287 2230
2288 $self->{children}[1]->draw; 2231 $self->{children}[1]->draw;
2289 2232
2290} 2233}
2291 2234
2385 @_, 2328 @_,
2386 can_events => 0, 2329 can_events => 0,
2387 ) 2330 )
2388} 2331}
2389 2332
2390sub set_markup { 2333sub set_tooltip_from {
2391 my ($self, $text) = @_; 2334 my ($self, $widget) = @_;
2392 2335
2393 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; 2336 $self->add (new CFClient::UI::Label
2394 $self->{label}->set_markup ($text); 2337 markup => $widget->{tooltip},
2395 $self->add ($self->{label}); 2338 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2339 fontsize => 0.8,
2340 fg => [0, 0, 0, 1],
2341 font => ($widget->{tooltip_font} || $::FONT_PROP),
2342 );
2396} 2343}
2397 2344
2398sub size_request { 2345sub size_request {
2399 my ($self) = @_; 2346 my ($self) = @_;
2400
2401 $self->child->set_max_size ($::WIDTH * 0.3);
2402 2347
2403 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2348 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2404 2349
2405 ($w + 4, $h + 4) 2350 ($w + 4, $h + 4)
2406} 2351}
2412} 2357}
2413 2358
2414sub _draw { 2359sub _draw {
2415 my ($self) = @_; 2360 my ($self) = @_;
2416 2361
2417 glPushMatrix;
2418 glTranslate 0.375, 0.375; 2362 glTranslate 0.375, 0.375;
2419 2363
2420 my ($w, $h) = @$self{qw(w h)}; 2364 my ($w, $h) = @$self{qw(w h)};
2421 2365
2422 glColor 1, 0.8, 0.4; 2366 glColor 1, 0.8, 0.4;
2433 glVertex 0 , $h; 2377 glVertex 0 , $h;
2434 glVertex $w, $h; 2378 glVertex $w, $h;
2435 glVertex $w, 0; 2379 glVertex $w, 0;
2436 glEnd; 2380 glEnd;
2437 2381
2438 glPopMatrix; 2382 glTranslate 2 - 0.375, 2 - 0.375;
2439
2440 glTranslate 2, 2;
2441 $self->SUPER::_draw; 2383 $self->SUPER::_draw;
2442} 2384}
2443 2385
2444############################################################################# 2386#############################################################################
2445 2387
2468 return unless $::CONN;#d# manage and cache textures differently 2410 return unless $::CONN;#d# manage and cache textures differently
2469 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2411 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2470 2412
2471 # TODO animation 2413 # TODO animation
2472 if ($tex) { 2414 if ($tex) {
2473 glEnable GL_BLEND;
2474 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2475 glEnable GL_TEXTURE_2D; 2415 glEnable GL_TEXTURE_2D;
2476 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2416 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2477 glColor 1, 1, 1, 1; 2417 glColor 1, 1, 1, 1;
2478 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 2418 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2479 glDisable GL_TEXTURE_2D; 2419 glDisable GL_TEXTURE_2D;
2480 glDisable GL_BLEND;
2481 } 2420 }
2482} 2421}
2483 2422
2484############################################################################# 2423#############################################################################
2485 2424
2675 while (my ($k, $v) = each %{ $self->{item} }) { 2614 while (my ($k, $v) = each %{ $self->{item} }) {
2676 delete $self->{item}{$k} if $v->{timeout} < $NOW; 2615 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2677 } 2616 }
2678 2617
2679 my @widgets; 2618 my @widgets;
2680 my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; 2619
2620 my @items = sort {
2621 $a->{pri} <=> $b->{pri}
2622 or $b->{id} <=> $a->{id}
2623 } values %{ $self->{item} };
2624
2681 my $count = 10 + 1; 2625 my $count = 10 + 1;
2682 for my $item (@items) { 2626 for my $item (@items) {
2683 last unless --$count; 2627 last unless --$count;
2684 2628
2685 push @widgets, $item->{label} ||= do { 2629 push @widgets, $item->{label} ||= do {
2686 # TODO: doesn't handle markup well (read as: at all) 2630 # TODO: doesn't handle markup well (read as: at all)
2687 my $short = delete $item->{text}; 2631 my $short = $item->{count} > 1
2632 ? "<b>$item->{count} ×</b> $item->{text}"
2633 : $item->{text};
2634
2688 for ($short) { 2635 for ($short) {
2689 s/^\s+//; 2636 s/^\s+//;
2690 s/\012.*//s; 2637 s/\012.*//s;
2691 my $len = int 30 / $item->{fontsize}; 2638 my $len = int 40 / $item->{fontsize};
2692 substr $_, $len, length, "…" if $len < length; 2639 substr $_, $len, length, "…" if $len < length;
2693 } 2640 }
2694 2641
2695 new CFClient::UI::Label 2642 new CFClient::UI::Label
2696 markup => $short, 2643 markup => $short,
2697 tooltip => delete $item->{tooltip}, 2644 tooltip => $item->{tooltip},
2645 tooltip_font => $::FONT_PROP,
2646 tooltip_width => 0.67,
2698 fontsize => delete $item->{fontsize}, 2647 fontsize => $item->{fontsize},
2699 color => delete $item->{color}, 2648 color => $item->{color},
2700 can_events => 1, 2649 can_events => 1,
2701 can_hover => 1, 2650 can_hover => 1
2702 }; 2651 };
2703 } 2652 }
2704 2653
2705 $self->clear; 2654 $self->clear;
2706 $self->SUPER::add (@widgets); 2655 $self->SUPER::add (reverse @widgets);
2707} 2656}
2708 2657
2709sub add { 2658sub add {
2710 my ($self, $text, %arg) = @_; 2659 my ($self, $text, %arg) = @_;
2711 2660
2712 my $item = { 2661 $text =~ s/^\s+//;
2713 time => time, 2662 $text =~ s/\s+$//;
2663
2664 my $timeout = time + ((delete $arg{timeout}) || 60);
2665
2666 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2667
2668 if (my $item = $self->{item}{$group}) {
2669 if ($item->{text} eq $text) {
2670 $item->{count}++;
2671 } else {
2672 $item->{count} = 1;
2673 $item->{text} = $item->{tooltip} = $text;
2674 }
2675 $item->{id} = ++$self->{id};
2676 $item->{timeout} = $timeout;
2677 delete $item->{label};
2678 } else {
2679 $self->{item}{$group} = {
2680 id => ++$self->{id},
2714 text => $text, 2681 text => $text,
2715 timeout => 60, 2682 timeout => $timeout,
2716 tooltip => $text, 2683 tooltip => $text,
2717 fontsize => 0.8, 2684 fontsize => 0.8,
2718 color => [0.8, 0.8, 0.8, 0.8], 2685 color => [0.8, 0.8, 0.8, 0.8],
2686 pri => 0,
2687 count => 1,
2719 %arg, 2688 %arg,
2689 };
2720 }; 2690 }
2721
2722 $item->{timeout} += time;
2723 $item->{group} ||= $item+0;
2724
2725 $item = $self->{item}{$item->{group}} ||= $item;
2726 2691
2727 $self->reorder; 2692 $self->reorder;
2728} 2693}
2729 2694
2730############################################################################# 2695#############################################################################
2827 my ($self, $id, $cb) = @_; 2792 my ($self, $id, $cb) = @_;
2828 2793
2829 $self->{refresh_hook}{$id} = $cb; 2794 $self->{refresh_hook}{$id} = $cb;
2830} 2795}
2831 2796
2797sub on_post_alloc {
2798 my ($self, $id, $cb) = @_;
2799
2800 $self->{post_alloc_hook}{$id} = $cb;
2801}
2802
2832sub draw { 2803sub draw {
2833 my ($self) = @_; 2804 my ($self) = @_;
2805
2806 while ($self->{refresh_hook}) {
2807 $_->()
2808 for values %{delete $self->{refresh_hook}};
2809 }
2834 2810
2835 if ($self->{check_size}) { 2811 if ($self->{check_size}) {
2836 my @queue = ([], []); 2812 my @queue = ([], []);
2837 2813
2838 for (;;) { 2814 for (;;) {
2846 2822
2847 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 2823 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2848 ? @$widget{qw(user_w user_h)} 2824 ? @$widget{qw(user_w user_h)}
2849 : $widget->size_request; 2825 : $widget->size_request;
2850 2826
2827 if (delete $widget->{force_alloc}
2851 if ($w != $widget->{req_w} || $h != $widget->{req_h}) { 2828 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2852 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 2829 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2853 2830
2854 $widget->{req_w} = $w; 2831 $widget->{req_w} = $w;
2855 $widget->{req_h} = $h; 2832 $widget->{req_h} = $h;
2856 2833
2857 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 2834 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2858 2835
2859 $widget->{parent}->check_size 2836 $widget->{parent}->check_size
2860 if $widget->{parent}; 2837 if $widget->{parent};
2861 } 2838 }
2862 } 2839 }
2874 $widget->size_allocate ($w, $h); 2851 $widget->size_allocate ($w, $h);
2875 $widget->emit (size_allocate => $w, $h); 2852 $widget->emit (size_allocate => $w, $h);
2876 } 2853 }
2877 } 2854 }
2878 2855
2879 while ($self->{refresh_hook}) { 2856 while ($self->{post_alloc_hook}) {
2880 $_->() 2857 $_->()
2881 for values %{delete $self->{refresh_hook}}; 2858 for values %{delete $self->{post_alloc_hook}};
2882 } 2859 }
2883 2860
2884 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2861 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2885 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2862 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2886 glClear GL_COLOR_BUFFER_BIT; 2863 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines