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.200 by root, Sat May 13 00:27:09 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 # TODO: req_w _does_change after ->reconfigure
388 $self->check_size 389 $self->check_size
389 unless exists $self->{req_w}; 390 unless exists $self->{req_w};
390} 391}
391 392
392sub check_size { 393sub check_size {
393 my ($self) = @_; 394 my ($self, $forced) = @_;
394 395
396 $self->{force_alloc} = 1 if $forced;
395 $CFClient::UI::ROOT->{check_size}{$self} = $self; 397 $CFClient::UI::ROOT->{check_size}{$self} = $self;
396} 398}
397 399
398sub update { 400sub update {
399 my ($self) = @_; 401 my ($self) = @_;
509 $self->{children} = [ 511 $self->{children} = [
510 sort { $a->{z} <=> $b->{z} } 512 sort { $a->{z} <=> $b->{z} }
511 @{$self->{children}}, @widgets 513 @{$self->{children}}, @widgets
512 ]; 514 ];
513 515
514 $self->check_size; 516 $self->check_size (1);
515 $self->update; 517 $self->update;
516} 518}
517 519
518sub children { 520sub children {
519 @{ $_[0]{children} } 521 @{ $_[0]{children} }
626} 628}
627 629
628sub update { 630sub update {
629 my ($self) = @_; 631 my ($self) = @_;
630 632
631 $ROOT->on_refresh ($self => sub { $self->render_child }); 633 $ROOT->on_post_alloc ($self => sub { $self->render_child });
632 $self->SUPER::update; 634 $self->SUPER::update;
633} 635}
634 636
635sub size_allocate { 637sub size_allocate {
636 my ($self, $w, $h) = @_; 638 my ($self, $w, $h) = @_;
774 $self->add ($self->{slider}); 776 $self->add ($self->{slider});
775 777
776 $self 778 $self
777} 779}
778 780
779#TODO# update range on size_allocate depeneing on child 781#TODO# update range on size_allocate depending on child
780# update viewport offset on scroll 782# update viewport offset on scroll
781 783
782############################################################################# 784#############################################################################
783 785
784package CFClient::UI::Frame; 786package CFClient::UI::Frame;
788use CFClient::OpenGL; 790use CFClient::OpenGL;
789 791
790sub new { 792sub new {
791 my $class = shift; 793 my $class = shift;
792 794
793 my $self = $class->SUPER::new ( 795 $class->SUPER::new (
794 bg => [1, 1, 1, 1], 796 bg => undef,
795 border_bg => [1, 1, 1, 1],
796 border => 0.8,
797 @_ 797 @_,
798 ); 798 )
799
800 $self
801} 799}
802 800
803sub _draw { 801sub _draw {
804 my ($self) = @_; 802 my ($self) = @_;
805 803
806 my ($w, $h) = ($self->{w}, $self->{h}); 804 if ($self->{bg}) {
805 my ($w, $h) = @$self{qw(w h)};
807 806
808 glEnable GL_BLEND; 807 glEnable GL_BLEND;
809 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 808 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
810 glEnable GL_TEXTURE_2D; 809 glColor @{ $self->{bg} };
811 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
812 810
813# glBegin GL_QUADS; 811 glBegin GL_QUADS;
814# glColor 0, 0, 0, 0;
815# glVertex 0 , 0; 812 glVertex 0 , 0;
816# glVertex 0 , $h; 813 glVertex 0 , $h;
817# glVertex $w, $h; 814 glVertex $w, $h;
818# glVertex $w, 0; 815 glVertex $w, 0;
819# glEnd; 816 glEnd;
820 817
821
822 $self->child->draw;
823 glDisable GL_BLEND; 818 glDisable GL_BLEND;
824 glDisable GL_TEXTURE_2D; 819 }
820
821 $self->SUPER::_draw;
825} 822}
826 823
827############################################################################# 824#############################################################################
828 825
829package CFClient::UI::FancyFrame; 826package CFClient::UI::FancyFrame;
945 my ($self) = @_; 942 my ($self) = @_;
946 943
947 my ($w, $h ) = ($self->{w}, $self->{h}); 944 my ($w, $h ) = ($self->{w}, $self->{h});
948 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 945 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
949 946
950 glEnable GL_BLEND;
951 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
952 glEnable GL_TEXTURE_2D; 947 glEnable GL_TEXTURE_2D;
953 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 948 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
954 949
955 my $border = $self->border; 950 my $border = $self->border;
956 951
957 glColor @{ $self->{border_bg} }; 952 glColor @{ $self->{border_bg} };
958 $tex[1]->draw_quad (0, 0, $w, $border); 953 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
959 $tex[3]->draw_quad (0, $border, $border, $ch); 954 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
960 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 955 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
961 $tex[4]->draw_quad (0, $h - $border, $w, $border); 956 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
962 957
963 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 958 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
964 my $bg = $tex[0]; 959 my $bg = $tex[0];
965 960
966 # TODO: repeat texture not scale 961 # TODO: repeat texture not scale
970 glColor @{ $self->{bg} }; 965 glColor @{ $self->{bg} };
971 966
972 $bg->{s} = $rep_x; 967 $bg->{s} = $rep_x;
973 $bg->{t} = $rep_y; 968 $bg->{t} = $rep_y;
974 $bg->{wrap_mode} = 1; 969 $bg->{wrap_mode} = 1;
975 $bg->draw_quad ($border, $border, $cw, $ch); 970 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
971 }
976 972
977 glDisable GL_TEXTURE_2D; 973 glDisable GL_TEXTURE_2D;
978 glDisable GL_BLEND;
979 }
980 974
981 $self->{title}->draw if $self->{title}; 975 $self->{title}->draw if $self->{title};
982 976
983 $self->child->draw; 977 $self->child->draw;
984} 978}
1486 my $sym = $ev->{sym}; 1480 my $sym = $ev->{sym};
1487 my $uni = $ev->{unicode}; 1481 my $uni = $ev->{unicode};
1488 1482
1489 my $text = $self->get_text; 1483 my $text = $self->get_text;
1490 1484
1491 if ($sym == 8) { 1485 if ($uni == 8) {
1492 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1486 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1493 } elsif ($sym == 127) { 1487 } elsif ($uni == 127) {
1494 substr $text, $self->{cursor}, 1, ""; 1488 substr $text, $self->{cursor}, 1, "";
1495 } elsif ($sym == CFClient::SDLK_LEFT) { 1489 } elsif ($sym == CFClient::SDLK_LEFT) {
1496 --$self->{cursor} if $self->{cursor}; 1490 --$self->{cursor} if $self->{cursor};
1497 } elsif ($sym == CFClient::SDLK_RIGHT) { 1491 } elsif ($sym == CFClient::SDLK_RIGHT) {
1498 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1492 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1499 } elsif ($sym == CFClient::SDLK_HOME) { 1493 } elsif ($sym == CFClient::SDLK_HOME) {
1500 $self->{cursor} = 0; 1494 $self->{cursor} = 0;
1501 } elsif ($sym == CFClient::SDLK_END) { 1495 } elsif ($sym == CFClient::SDLK_END) {
1502 $self->{cursor} = length $text; 1496 $self->{cursor} = length $text;
1503 } elsif ($sym == 27) { 1497 } elsif ($uni == 27) {
1504 $self->emit ('escape'); 1498 $self->emit ('escape');
1505 } elsif ($uni) { 1499 } elsif ($uni) {
1506 substr $text, $self->{cursor}++, 0, chr $uni; 1500 substr $text, $self->{cursor}++, 0, chr $uni;
1507 } 1501 }
1508 1502
1672 1666
1673 if ($GRAB == $self) { 1667 if ($GRAB == $self) {
1674 $self->{fg} = $self->{active_fg}; 1668 $self->{fg} = $self->{active_fg};
1675 } 1669 }
1676 1670
1677 glEnable GL_BLEND;
1678 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1679 glEnable GL_TEXTURE_2D; 1671 glEnable GL_TEXTURE_2D;
1680 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1672 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1681 glColor 0, 0, 0, 1; 1673 glColor 0, 0, 0, 1;
1682 1674
1683 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); 1675 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
1684 1676
1685 glDisable GL_TEXTURE_2D; 1677 glDisable GL_TEXTURE_2D;
1686 glDisable GL_BLEND;
1687 1678
1688 $self->SUPER::_draw; 1679 $self->SUPER::_draw;
1689} 1680}
1690 1681
1691############################################################################# 1682#############################################################################
1738 1729
1739 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1730 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1740 1731
1741 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1732 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1742 1733
1743 glEnable GL_BLEND; 1734 my $tex = $self->{state} ? $tex[1] : $tex[0];
1735
1744 glEnable GL_TEXTURE_2D; 1736 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); 1737 $tex->draw_quad_alpha (0, 0, $s, $s);
1750
1751 glDisable GL_TEXTURE_2D; 1738 glDisable GL_TEXTURE_2D;
1752 glDisable GL_BLEND;
1753} 1739}
1754 1740
1755############################################################################# 1741#############################################################################
1756 1742
1757package CFClient::UI::Image; 1743package CFClient::UI::Image;
1800 glTranslate 0, -$self->{w}, 0; 1786 glTranslate 0, -$self->{w}, 0;
1801 1787
1802 ($w, $h) = ($h, $w); 1788 ($w, $h) = ($h, $w);
1803 } 1789 }
1804 1790
1805 glEnable GL_BLEND;
1806 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1807 glEnable GL_TEXTURE_2D; 1791 glEnable GL_TEXTURE_2D;
1808 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1792 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1809 1793
1810 $tex->draw_quad (0, 0, $w, $h); 1794 $tex->draw_quad_alpha (0, 0, $w, $h);
1811 1795
1812 glDisable GL_BLEND;
1813 glDisable GL_TEXTURE_2D; 1796 glDisable GL_TEXTURE_2D;
1814} 1797}
1815 1798
1816############################################################################# 1799#############################################################################
1817 1800
2109 $page ||= 2; 2092 $page ||= 2;
2110 2093
2111 my $knob_a = $inner_pad_px + ($value - $page * 0.5); 2094 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2112 my $knob_b = $inner_pad_px + ($value + $page * 0.5); 2095 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2113 2096
2114 glEnable GL_BLEND;
2115 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2116 glEnable GL_TEXTURE_2D; 2097 glEnable GL_TEXTURE_2D;
2117 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2098 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2118 2099
2119 # draw background 2100 # draw background
2120 $tex[1]->draw_quad (0, 0, $w, $h); 2101 $tex[1]->draw_quad_alpha (0, 0, $w, $h);
2121 2102
2122 # draw handle 2103 # draw handle
2123 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); 2104 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h);
2124 2105
2125 glDisable GL_BLEND;
2126 glDisable GL_TEXTURE_2D; 2106 glDisable GL_TEXTURE_2D;
2127} 2107}
2128 2108
2129############################################################################# 2109#############################################################################
2130 2110
2141 fontsize => 1, 2121 fontsize => 1,
2142 can_events => 0, 2122 can_events => 0,
2143 #font => default_font 2123 #font => default_font
2144 @_, 2124 @_,
2145 2125
2146 layout => (new CFClient::Layout), 2126 layout => (new CFClient::Layout 1),
2147 par => [], 2127 par => [],
2148 height => 0, 2128 height => 0,
2149 children => [ 2129 children => [
2150 (new CFClient::UI::Empty expand => 1), 2130 (new CFClient::UI::Empty expand => 1),
2151 (new CFClient::UI::Slider vertical => 1), 2131 (new CFClient::UI::Slider vertical => 1),
2169 2149
2170 my $layout = $self->{layout}; 2150 my $layout = $self->{layout};
2171 2151
2172 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2152 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2173 $layout->set_width ($self->{children}[0]{w}); 2153 $layout->set_width ($self->{children}[0]{w});
2174 $layout->set_text ($text); 2154 $layout->set_markup ($text);
2175 2155
2176 ($layout->size)[1] 2156 ($layout->size)[1]
2177} 2157}
2178 2158
2179sub reflow { 2159sub reflow {
2217 2197
2218 return unless $self->{h} > 0; 2198 return unless $self->{h} > 0;
2219 2199
2220 delete $self->{texture}; 2200 delete $self->{texture};
2221 2201
2222 $ROOT->on_refresh ($self, sub { 2202 $ROOT->on_post_alloc ($self, sub {
2223 if (delete $self->{need_reflow}) { 2203 if (delete $self->{need_reflow}) {
2224 my $height = 0; 2204 my $height = 0;
2225 2205
2226 $height += $_->[0] = $self->text_height ($_->[2]) 2206 $height += $_->[0] = $self->text_height ($_->[2])
2227 for @{$self->{par}}; 2207 for @{$self->{par}};
2235 2215
2236 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2216 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2237 glClearColor 0, 0, 0, 0; 2217 glClearColor 0, 0, 0, 0;
2238 glClear GL_COLOR_BUFFER_BIT; 2218 glClear GL_COLOR_BUFFER_BIT;
2239 2219
2240 glEnable GL_BLEND;
2241 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2242 glEnable GL_TEXTURE_2D; 2220 glEnable GL_TEXTURE_2D;
2243 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2221 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2244 2222
2245 my $top = int $self->{children}[1]{range}[0]; 2223 my $top = int $self->{children}[1]{range}[0];
2246 2224
2255 2233
2256 for my $par (@{$self->{par}}) { 2234 for my $par (@{$self->{par}}) {
2257 my $h = $par->[0]; 2235 my $h = $par->[0];
2258 2236
2259 if ($y0 < $y + $h && $y < $y1) { 2237 if ($y0 < $y + $h && $y < $y1) {
2238 $layout->set_foreground (@{ $par->[1] });
2260 $layout->set_text ($par->[2]); 2239 $layout->set_markup ($par->[2]);
2261 2240
2262 glColor @{ $par->[1] };
2263 my ($W, $H) = $layout->size; 2241 my ($W, $H) = $layout->size;
2264 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); 2242 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0);
2265 } 2243 }
2266 2244
2267 $y += $h; 2245 $y += $h;
2268 } 2246 }
2269 2247
2270 glDisable GL_TEXTURE_2D; 2248 glDisable GL_TEXTURE_2D;
2271 glDisable GL_BLEND;
2272 }; 2249 };
2273 }); 2250 });
2274} 2251}
2275 2252
2276sub _draw { 2253sub _draw {
2277 my ($self) = @_; 2254 my ($self) = @_;
2278 2255
2279 glEnable GL_BLEND;
2280 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2281 glEnable GL_TEXTURE_2D; 2256 glEnable GL_TEXTURE_2D;
2282 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2257 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2283 glColor 1, 1, 1, 1; 2258 glColor 1, 1, 1, 1;
2284 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2259 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2285 glDisable GL_TEXTURE_2D; 2260 glDisable GL_TEXTURE_2D;
2286 glDisable GL_BLEND;
2287 2261
2288 $self->{children}[1]->draw; 2262 $self->{children}[1]->draw;
2289 2263
2290} 2264}
2291 2265
2385 @_, 2359 @_,
2386 can_events => 0, 2360 can_events => 0,
2387 ) 2361 )
2388} 2362}
2389 2363
2390sub set_markup { 2364sub set_tooltip_from {
2391 my ($self, $text) = @_; 2365 my ($self, $widget) = @_;
2392 2366
2393 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; 2367 $self->add (new CFClient::UI::Label
2394 $self->{label}->set_markup ($text); 2368 markup => $widget->{tooltip},
2395 $self->add ($self->{label}); 2369 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2370 fontsize => 0.8,
2371 fg => [0, 0, 0, 1],
2372 font => ($widget->{tooltip_font} || $::FONT_PROP),
2373 );
2396} 2374}
2397 2375
2398sub size_request { 2376sub size_request {
2399 my ($self) = @_; 2377 my ($self) = @_;
2400
2401 $self->child->set_max_size ($::WIDTH * 0.3);
2402 2378
2403 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2379 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2404 2380
2405 ($w + 4, $h + 4) 2381 ($w + 4, $h + 4)
2406} 2382}
2412} 2388}
2413 2389
2414sub _draw { 2390sub _draw {
2415 my ($self) = @_; 2391 my ($self) = @_;
2416 2392
2417 glPushMatrix;
2418 glTranslate 0.375, 0.375; 2393 glTranslate 0.375, 0.375;
2419 2394
2420 my ($w, $h) = @$self{qw(w h)}; 2395 my ($w, $h) = @$self{qw(w h)};
2421 2396
2422 glColor 1, 0.8, 0.4; 2397 glColor 1, 0.8, 0.4;
2433 glVertex 0 , $h; 2408 glVertex 0 , $h;
2434 glVertex $w, $h; 2409 glVertex $w, $h;
2435 glVertex $w, 0; 2410 glVertex $w, 0;
2436 glEnd; 2411 glEnd;
2437 2412
2438 glPopMatrix; 2413 glTranslate 2 - 0.375, 2 - 0.375;
2439
2440 glTranslate 2, 2;
2441 $self->SUPER::_draw; 2414 $self->SUPER::_draw;
2442} 2415}
2443 2416
2444############################################################################# 2417#############################################################################
2445 2418
2468 return unless $::CONN;#d# manage and cache textures differently 2441 return unless $::CONN;#d# manage and cache textures differently
2469 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2442 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2470 2443
2471 # TODO animation 2444 # TODO animation
2472 if ($tex) { 2445 if ($tex) {
2473 glEnable GL_BLEND;
2474 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2475 glEnable GL_TEXTURE_2D; 2446 glEnable GL_TEXTURE_2D;
2476 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2447 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2477 glColor 1, 1, 1, 1; 2448 glColor 1, 1, 1, 1;
2478 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 2449 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2479 glDisable GL_TEXTURE_2D; 2450 glDisable GL_TEXTURE_2D;
2480 glDisable GL_BLEND;
2481 } 2451 }
2482} 2452}
2483 2453
2484############################################################################# 2454#############################################################################
2485 2455
2675 while (my ($k, $v) = each %{ $self->{item} }) { 2645 while (my ($k, $v) = each %{ $self->{item} }) {
2676 delete $self->{item}{$k} if $v->{timeout} < $NOW; 2646 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2677 } 2647 }
2678 2648
2679 my @widgets; 2649 my @widgets;
2680 my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; 2650
2651 my @items = sort {
2652 $a->{pri} <=> $b->{pri}
2653 or $b->{id} <=> $a->{id}
2654 } values %{ $self->{item} };
2655
2681 my $count = 10 + 1; 2656 my $count = 10 + 1;
2682 for my $item (@items) { 2657 for my $item (@items) {
2683 last unless --$count; 2658 last unless --$count;
2684 2659
2685 push @widgets, $item->{label} ||= do { 2660 push @widgets, $item->{label} ||= do {
2686 # TODO: doesn't handle markup well (read as: at all) 2661 # TODO: doesn't handle markup well (read as: at all)
2687 my $short = delete $item->{text}; 2662 my $short = $item->{count} > 1
2663 ? "<b>$item->{count} ×</b> $item->{text}"
2664 : $item->{text};
2665
2688 for ($short) { 2666 for ($short) {
2689 s/^\s+//; 2667 s/^\s+//;
2690 s/\012.*//s; 2668 s/\012.*//s;
2691 my $len = int 30 / $item->{fontsize}; 2669 my $len = int 40 / $item->{fontsize};
2692 substr $_, $len, length, "…" if $len < length; 2670 substr $_, $len, length, "…" if $len < length;
2693 } 2671 }
2694 2672
2695 new CFClient::UI::Label 2673 new CFClient::UI::Label
2696 markup => $short, 2674 markup => $short,
2697 tooltip => delete $item->{tooltip}, 2675 tooltip => $item->{tooltip},
2676 tooltip_font => $::FONT_PROP,
2677 tooltip_width => 0.67,
2698 fontsize => delete $item->{fontsize}, 2678 fontsize => $item->{fontsize},
2699 color => delete $item->{color}, 2679 color => $item->{color},
2700 can_events => 1, 2680 can_events => 1,
2701 can_hover => 1, 2681 can_hover => 1
2702 }; 2682 };
2703 } 2683 }
2704 2684
2705 $self->clear; 2685 $self->clear;
2706 $self->SUPER::add (@widgets); 2686 $self->SUPER::add (reverse @widgets);
2707} 2687}
2708 2688
2709sub add { 2689sub add {
2710 my ($self, $text, %arg) = @_; 2690 my ($self, $text, %arg) = @_;
2711 2691
2712 my $item = { 2692 $text =~ s/^\s+//;
2713 time => time, 2693 $text =~ s/\s+$//;
2694
2695 my $timeout = time + ((delete $arg{timeout}) || 60);
2696
2697 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2698
2699 if (my $item = $self->{item}{$group}) {
2700 if ($item->{text} eq $text) {
2701 $item->{count}++;
2702 } else {
2703 $item->{count} = 1;
2704 $item->{text} = $item->{tooltip} = $text;
2705 }
2706 $item->{id} = ++$self->{id};
2707 $item->{timeout} = $timeout;
2708 delete $item->{label};
2709 } else {
2710 $self->{item}{$group} = {
2711 id => ++$self->{id},
2714 text => $text, 2712 text => $text,
2715 timeout => 60, 2713 timeout => $timeout,
2716 tooltip => $text, 2714 tooltip => $text,
2717 fontsize => 0.8, 2715 fontsize => 0.8,
2718 color => [0.8, 0.8, 0.8, 0.8], 2716 color => [0.8, 0.8, 0.8, 0.8],
2717 pri => 0,
2718 count => 1,
2719 %arg, 2719 %arg,
2720 };
2720 }; 2721 }
2721
2722 $item->{timeout} += time;
2723 $item->{group} ||= $item+0;
2724
2725 $item = $self->{item}{$item->{group}} ||= $item;
2726 2722
2727 $self->reorder; 2723 $self->reorder;
2728} 2724}
2729 2725
2730############################################################################# 2726#############################################################################
2827 my ($self, $id, $cb) = @_; 2823 my ($self, $id, $cb) = @_;
2828 2824
2829 $self->{refresh_hook}{$id} = $cb; 2825 $self->{refresh_hook}{$id} = $cb;
2830} 2826}
2831 2827
2828sub on_post_alloc {
2829 my ($self, $id, $cb) = @_;
2830
2831 $self->{post_alloc_hook}{$id} = $cb;
2832}
2833
2832sub draw { 2834sub draw {
2833 my ($self) = @_; 2835 my ($self) = @_;
2836
2837 while ($self->{refresh_hook}) {
2838 $_->()
2839 for values %{delete $self->{refresh_hook}};
2840 }
2834 2841
2835 if ($self->{check_size}) { 2842 if ($self->{check_size}) {
2836 my @queue = ([], []); 2843 my @queue = ([], []);
2837 2844
2838 for (;;) { 2845 for (;;) {
2846 2853
2847 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 2854 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2848 ? @$widget{qw(user_w user_h)} 2855 ? @$widget{qw(user_w user_h)}
2849 : $widget->size_request; 2856 : $widget->size_request;
2850 2857
2858 if (delete $widget->{force_alloc}
2851 if ($w != $widget->{req_w} || $h != $widget->{req_h}) { 2859 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2852 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 2860 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2853 2861
2854 $widget->{req_w} = $w; 2862 $widget->{req_w} = $w;
2855 $widget->{req_h} = $h; 2863 $widget->{req_h} = $h;
2856 2864
2857 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 2865 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2858 2866
2859 $widget->{parent}->check_size 2867 $widget->{parent}->check_size
2860 if $widget->{parent}; 2868 if $widget->{parent};
2861 } 2869 }
2862 } 2870 }
2874 $widget->size_allocate ($w, $h); 2882 $widget->size_allocate ($w, $h);
2875 $widget->emit (size_allocate => $w, $h); 2883 $widget->emit (size_allocate => $w, $h);
2876 } 2884 }
2877 } 2885 }
2878 2886
2879 while ($self->{refresh_hook}) { 2887 while ($self->{post_alloc_hook}) {
2880 $_->() 2888 $_->()
2881 for values %{delete $self->{refresh_hook}}; 2889 for values %{delete $self->{post_alloc_hook}};
2882 } 2890 }
2883 2891
2884 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2892 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2885 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2893 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2886 glClear GL_COLOR_BUFFER_BIT; 2894 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines