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.170 by root, Mon Apr 24 11:45:17 2006 UTC vs.
Revision 1.179 by elmex, Fri Apr 28 05:17:21 2006 UTC

24 my $tip = $widget->{tooltip}; 24 my $tip = $widget->{tooltip};
25 25
26 $tip = $tip->($widget) if CODE:: eq ref $tip; 26 $tip = $tip->($widget) if CODE:: eq ref $tip;
27 27
28 $TOOLTIP->set_markup ($widget->{tooltip}); 28 $TOOLTIP->set_markup ($widget->{tooltip});
29 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); 29
30 $TOOLTIP->show; 30 $TOOLTIP->show;
31
32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
33
34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0);
36 }
37
38 $TOOLTIP->move ($x, $y);
31 } 39 }
32 40
33 return; 41 return;
34 } 42 }
35 } 43 }
234 } 242 }
235} 243}
236 244
237sub size_allocate { 245sub size_allocate {
238 # nothing to be done 246 # nothing to be done
247}
248
249sub children {
250}
251
252# call when resoltuion changes etc.
253sub reconfigure {
254 my ($self) = @_;
255
256 $_->reconfigure
257 for $self->children;
258
259 $_->check_size;
239} 260}
240 261
241sub set_max_size { 262sub set_max_size {
242 my ($self, $w, $h) = @_; 263 my ($self, $w, $h) = @_;
243 264
520 ]; 541 ];
521 542
522 $child->check_size; 543 $child->check_size;
523} 544}
524 545
546sub children {
547 @{ $_[0]{children} }
548}
549
525sub remove { 550sub remove {
526 my ($self, $child) = @_; 551 my ($self, $child) = @_;
527 552
528 delete $child->{parent}; 553 delete $child->{parent};
529 $child->hide; 554 $child->hide;
626} 651}
627 652
628sub update { 653sub update {
629 my ($self) = @_; 654 my ($self) = @_;
630 655
631 # we want to do this delayed... 656 $ROOT->on_refresh ($self => sub { $self->render_child });
632 $self->render_chld;
633 $self->SUPER::update; 657 $self->SUPER::update;
634} 658}
635 659
660sub size_allocate {
661 my ($self, $w, $h) = @_;
662
663 $self->SUPER::size_allocate ($w, $h);
664 $self->update;
665}
666
636sub render_chld { 667sub render_child {
637 my ($self) = @_; 668 my ($self) = @_;
638 669
639 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 670 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
640 glClearColor 0, 0, 0, 1; 671 glClearColor 0, 0, 0, 0;
641 glClear GL_COLOR_BUFFER_BIT; 672 glClear GL_COLOR_BUFFER_BIT;
642 $self->child->draw; 673 $self->child->draw;
674# glColorMask 1, 1, 1, 0;
675# glEnable GL_BLEND;
676# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
677# glRasterPos 0, 0;
678# glCopyPixels 0, 0, $self->{w}, $self->{h};
679# glDisable GL_BLEND;
680# glColorMask 1, 1, 1, 1;
643 }; 681 };
644}
645
646sub size_allocate {
647 my ($self, $w, $h) = @_;
648
649 $self->child->configure (0, 0, $w, $h);
650
651 $self->render_chld;
652} 682}
653 683
654sub _draw { 684sub _draw {
655 my ($self) = @_; 685 my ($self) = @_;
656 686
658 688
659 my $tex = $self->{texture} 689 my $tex = $self->{texture}
660 or return; 690 or return;
661 691
662 glEnable GL_BLEND; 692 glEnable GL_BLEND;
663 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 693 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
664 glEnable GL_TEXTURE_2D; 694 glEnable GL_TEXTURE_2D;
665 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 695 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
696 glColor 0, 0, 0, 1;
666 697
667 $tex->draw_quad (0, 0, $w, $h); 698 $tex->draw_quad (0, 0, $w, $h);
668 699
669 glDisable GL_BLEND; 700 glDisable GL_BLEND;
670 glDisable GL_TEXTURE_2D; 701 glDisable GL_TEXTURE_2D;
757 # TODO: user_x, user_y, overwrite moveto? 788 # TODO: user_x, user_y, overwrite moveto?
758 789
759 my $self = $class->SUPER::new ( 790 my $self = $class->SUPER::new (
760 bg => [1, 1, 1, 1], 791 bg => [1, 1, 1, 1],
761 border_bg => [1, 1, 1, 1], 792 border_bg => [1, 1, 1, 1],
762 border => 0.8, 793 border => 0.6,
763 can_events => 1, 794 can_events => 1,
764 @_ 795 @_
765 ); 796 );
766 797
767 $self->{title} &&= new CFClient::UI::Label 798 $self->{title} &&= new CFClient::UI::Label
768 align => 0, 799 align => 0,
769 valign => 1, 800 valign => 1,
770 text => $self->{title}, 801 text => $self->{title},
771 fontsize => 1; 802 fontsize => $self->{border};
772 803
773 $self 804 $self
774} 805}
775 806
776sub border { 807sub border {
801} 832}
802 833
803sub button_down { 834sub button_down {
804 my ($self, $ev, $x, $y) = @_; 835 my ($self, $ev, $x, $y) = @_;
805 836
837 my ($w, $h) = @$self{qw(w h)};
806 my $border = $self->border; 838 my $border = $self->border;
807 839
808 if ($x < $self->{w} && $x >= $self->{w} - $border 840 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w);
809 && $y < $self->{h} && $y >= $self->{h} - $border) { 841 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h);
810 842
843 if ($lr & $td) {
844 my ($wx, $wy) = ($self->{x}, $self->{y});
811 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 845 my ($ox, $oy) = ($ev->{x}, $ev->{y});
812 my ($bw, $bh) = ($self->{w}, $self->{h}); 846 my ($bw, $bh) = ($self->{w}, $self->{h});
813 847
848 my $mx = $x < $border;
849 my $my = $y < $border;
850
814 $self->{motion} = sub { 851 $self->{motion} = sub {
815 my ($ev, $x, $y) = @_; 852 my ($ev, $x, $y) = @_;
816 853
817 ($x, $y) = ($ev->{x}, $ev->{y}); 854 my $dx = $ev->{x} - $ox;
855 my $dy = $ev->{y} - $oy;
818 856
819 $self->{user_w} = $bw + $x - $ox; 857 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
820 $self->{user_h} = $bh + $y - $oy; 858 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
859 $self->move ($wx + $dx * $mx, $wy + $dy * $my);
821 $self->check_size; 860 $self->check_size;
822 }; 861 };
823 862
824 } elsif ($x >= 0 && $x < $self->{w} 863 } elsif ($lr ^ $td) {
825 && $y >= 0 && $y < $border) {
826
827 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 864 my ($ox, $oy) = ($ev->{x}, $ev->{y});
828 my ($bx, $by) = ($self->{x}, $self->{y}); 865 my ($bx, $by) = ($self->{x}, $self->{y});
829 866
830 $self->{motion} = sub { 867 $self->{motion} = sub {
831 my ($ev, $x, $y) = @_; 868 my ($ev, $x, $y) = @_;
867 $tex[1]->draw_quad (0, 0, $w, $border); 904 $tex[1]->draw_quad (0, 0, $w, $border);
868 $tex[3]->draw_quad (0, $border, $border, $ch); 905 $tex[3]->draw_quad (0, $border, $border, $ch);
869 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 906 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
870 $tex[4]->draw_quad (0, $h - $border, $w, $border); 907 $tex[4]->draw_quad (0, $h - $border, $w, $border);
871 908
909 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
872 my $bg = $tex[0]; 910 my $bg = $tex[0];
873 911
874 # TODO: repeat texture not scale 912 # TODO: repeat texture not scale
875 my $rep_x = $cw / $bg->{w}; 913 my $rep_x = $cw / $bg->{w};
876 my $rep_y = $ch / $bg->{h}; 914 my $rep_y = $ch / $bg->{h};
877 915
878 glColor @{ $self->{bg} }; 916 glColor @{ $self->{bg} };
879 917
880 $bg->{s} = $rep_x; 918 $bg->{s} = $rep_x;
881 $bg->{t} = $rep_y; 919 $bg->{t} = $rep_y;
882 $bg->{wrap_mode} = 1; 920 $bg->{wrap_mode} = 1;
883 $bg->draw_quad ($border, $border, $cw, $ch); 921 $bg->draw_quad ($border, $border, $cw, $ch);
884 922
885 glDisable GL_TEXTURE_2D; 923 glDisable GL_TEXTURE_2D;
886 glDisable GL_BLEND; 924 glDisable GL_BLEND;
925 }
887 926
888 $self->{title}->draw if $self->{title}; 927 $self->{title}->draw if $self->{title};
928
889 $self->child->draw; 929 $self->child->draw;
890} 930}
891 931
892############################################################################# 932#############################################################################
893 933
915 $self->{children}[$y][$x] = $child; 955 $self->{children}[$y][$x] = $child;
916 956
917 $child->check_size; 957 $child->check_size;
918} 958}
919 959
960sub children {
961 grep $_, map @$_, grep $_, @{ $_[0]{children} }
962}
963
920# TODO: move to container class maybe? send childs a signal on removal? 964# TODO: move to container class maybe? send childs a signal on removal?
921sub clear { 965sub clear {
922 my ($self) = @_; 966 my ($self) = @_;
923 967
924 my $children = delete $self->{children}; 968 my @children = $self->children;
969 delete $self->{children};
925 970
926 for (grep $_, map @$_, grep $_, @$children) { 971 for (@children) {
927 delete $_->{parent}; 972 delete $_->{parent};
928 $_->hide; 973 $_->hide;
929 } 974 }
930 975
931 $self->update; 976 $self->update;
1192 s/</&lt;/g; 1237 s/</&lt;/g;
1193 1238
1194 $_[1] 1239 $_[1]
1195} 1240}
1196 1241
1242sub update {
1243 my ($self) = @_;
1244
1245 delete $self->{texture};
1246 $self->SUPER::update;
1247}
1248
1249sub reconfigure {
1250 my ($self) = @_;
1251
1252 delete $self->{texture};
1253}
1254
1197sub set_text { 1255sub set_text {
1198 my ($self, $text) = @_; 1256 my ($self, $text) = @_;
1199 1257
1258 return if $self->{text} eq "T$text";
1259 $self->{text} = "T$text";
1260
1200 $self->{layout}->set_text ($text); 1261 $self->{layout}->set_text ($text);
1201 1262
1202 delete $self->{texture}; 1263 delete $self->{texture};
1264 $self->update;
1203 $self->check_size; 1265 $self->check_size;
1204 $self->update;
1205} 1266}
1206 1267
1207sub set_markup { 1268sub set_markup {
1208 my ($self, $markup) = @_; 1269 my ($self, $markup) = @_;
1209 1270
1271 return if $self->{text} eq "M$markup";
1272 $self->{text} = "M$markup";
1273
1210 $self->{layout}->set_markup ($markup); 1274 $self->{layout}->set_markup ($markup);
1211 1275
1212 delete $self->{texture}; 1276 delete $self->{texture};
1277 $self->update;
1213 $self->check_size; 1278 $self->check_size;
1214 $self->update;
1215} 1279}
1216 1280
1217sub size_request { 1281sub size_request {
1218 my ($self) = @_; 1282 my ($self) = @_;
1219 1283
1743} 1807}
1744 1808
1745sub set_max { 1809sub set_max {
1746 my ($self, $max) = @_; 1810 my ($self, $max) = @_;
1747 1811
1812 return if $self->{max_val} == $max;
1813
1748 $self->{max_val} = $max; 1814 $self->{max_val} = $max;
1815 $self->update;
1749} 1816}
1750 1817
1751sub set_value { 1818sub set_value {
1752 my ($self, $val, $max) = @_; 1819 my ($self, $val, $max) = @_;
1753 1820
1754 $self->set_max ($max) 1821 $self->set_max ($max)
1755 if defined $max; 1822 if defined $max;
1756 1823
1757 $max = $self->{max_val}; 1824 return if $self->{val} == $val;
1825
1758 $self->{val} = $val; 1826 $self->{val} = $val;
1759
1760 $self->update; 1827 $self->update;
1761} 1828}
1762 1829
1763sub _draw { 1830sub _draw {
1764 my ($self) = @_; 1831 my ($self) = @_;
1827 1894
1828sub new { 1895sub new {
1829 my ($class, %arg) = @_; 1896 my ($class, %arg) = @_;
1830 1897
1831 my $self = $class->SUPER::new ( 1898 my $self = $class->SUPER::new (
1832 tooltip => $arg{type}, 1899 tooltip => $arg{type},
1833 can_hover => 1, 1900 can_hover => 1,
1901 can_events => 1,
1834 %arg, 1902 %arg,
1835 ); 1903 );
1836 1904
1837 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1905 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1838 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 1906 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1846 1914
1847 $self->{value}->set_fontsize ($fsize); 1915 $self->{value}->set_fontsize ($fsize);
1848 $self->{max} ->set_fontsize ($fsize); 1916 $self->{max} ->set_fontsize ($fsize);
1849} 1917}
1850 1918
1919sub set_max {
1920 my ($self, $max) = @_;
1921
1922 $self->{gauge}->set_max ($max);
1923 $self->{max}->set_text ($max);
1924}
1925
1851sub set_value { 1926sub set_value {
1852 my ($self, $val, $max) = @_; 1927 my ($self, $val, $max) = @_;
1853 1928
1854 $self->set_max ($max) 1929 $self->set_max ($max)
1855 if defined $max; 1930 if defined $max;
1856 1931
1857 $self->{gauge}->set_value ($val, $max); 1932 $self->{gauge}->set_value ($val, $max);
1858 $self->{value}->set_text ($val); 1933 $self->{value}->set_text ($val);
1859}
1860
1861sub set_max {
1862 my ($self, $max) = @_;
1863
1864 $self->{gauge}->set_max ($max);
1865 $self->{max}->set_text ($max);
1866} 1934}
1867 1935
1868############################################################################# 1936#############################################################################
1869 1937
1870package CFClient::UI::Slider; 1938package CFClient::UI::Slider;
2024 (new CFClient::UI::Empty expand => 1), 2092 (new CFClient::UI::Empty expand => 1),
2025 (new CFClient::UI::Slider vertical => 1), 2093 (new CFClient::UI::Slider vertical => 1),
2026 ], 2094 ],
2027 ); 2095 );
2028 2096
2029 $self->{children}[1]->connect (changed => sub { 2097 $self->{children}[1]->connect (changed => sub { $self->update });
2030 $self->update;
2031 });
2032 2098
2033 $self 2099 $self
2034} 2100}
2035 2101
2036sub set_fontsize { 2102sub set_fontsize {
2044 my ($self, $text) = @_; 2110 my ($self, $text) = @_;
2045 2111
2046 my $layout = $self->{layout}; 2112 my $layout = $self->{layout};
2047 2113
2048 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2114 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2049 $layout->set_width ($self->{w}); 2115 $layout->set_width ($self->{children}[0]{w});
2050 $layout->set_text ($text); 2116 $layout->set_text ($text);
2051 2117
2052 ($layout->size)[1] 2118 ($layout->size)[1]
2053} 2119}
2054 2120
2107 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2173 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2108 2174
2109 delete $self->{texture}; 2175 delete $self->{texture};
2110 } 2176 }
2111 2177
2112 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 2178 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2113 glClearColor 0, 0, 0, 1; 2179 glClearColor 0, 0, 0, 0;
2114 glClear GL_COLOR_BUFFER_BIT; 2180 glClear GL_COLOR_BUFFER_BIT;
2115 2181
2116 glEnable GL_BLEND; 2182 glEnable GL_BLEND;
2117 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2183 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2118 glEnable GL_TEXTURE_2D; 2184 glEnable GL_TEXTURE_2D;
2150} 2216}
2151 2217
2152sub _draw { 2218sub _draw {
2153 my ($self) = @_; 2219 my ($self) = @_;
2154 2220
2155 if ($self->{texture}) { 2221 glEnable GL_BLEND;
2222 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2156 glEnable GL_TEXTURE_2D; 2223 glEnable GL_TEXTURE_2D;
2157 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2224 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2225 glColor 1, 1, 1, 1;
2158 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2226 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2159 glDisable GL_TEXTURE_2D; 2227 glDisable GL_TEXTURE_2D;
2160 } 2228 glDisable GL_BLEND;
2161 2229
2162 $self->{children}[1]->draw; 2230 $self->{children}[1]->draw;
2163 2231
2164} 2232}
2165 2233
2334 2402
2335sub size_request { 2403sub size_request {
2336 (32, 8) 2404 (32, 8)
2337} 2405}
2338 2406
2339sub draw { 2407sub _draw {
2340 my ($self) = @_; 2408 my ($self) = @_;
2341 2409
2342 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2410 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2343 2411
2412 # TODO animation
2344 if ($tex) { 2413 if ($tex) {
2345 glEnable GL_BLEND; 2414 glEnable GL_BLEND;
2346 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2415 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2347 glEnable GL_TEXTURE_2D; 2416 glEnable GL_TEXTURE_2D;
2348 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2417 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2353 } 2422 }
2354} 2423}
2355 2424
2356############################################################################# 2425#############################################################################
2357 2426
2427package CFClient::UI::Menu;
2428
2429our @ISA = CFClient::UI::FancyFrame::;
2430
2431use CFClient::OpenGL;
2432
2433sub new {
2434 my $class = shift;
2435
2436 my $self = $class->SUPER::new (
2437 items => [],
2438 z => 100,
2439 @_,
2440 );
2441
2442 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2443
2444 for my $item (@{ $self->{items} }) {
2445 my ($widget, $cb) = @$item;
2446
2447 # handle various types of items, only text for now
2448 if (!ref $widget) {
2449 $widget = new CFClient::UI::Label
2450 can_hover => 1,
2451 can_events => 1,
2452 text => $widget;
2453 }
2454
2455 $self->{item}{$widget} = $item;
2456
2457 $self->{vbox}->add ($widget);
2458 }
2459
2460 $self
2461}
2462
2463# popup given the event (must be a mouse button down event currently)
2464sub popup {
2465 my ($self, $ev) = @_;
2466
2467 $self->emit ("popdown");
2468
2469 # maybe save $GRAB? must be careful about events...
2470 $GRAB = $self;
2471 $self->{button} = $ev->{button};
2472
2473 $self->show;
2474 $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
2475}
2476
2477sub mouse_motion {
2478 my ($self, $ev, $x, $y) = @_;
2479
2480 # TODO: should use vbox->fdind_widget or so
2481 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2482 $self->{hover} = $self->{item}{$HOVER};
2483}
2484
2485sub button_up {
2486 my ($self, $ev, $x, $y) = @_;
2487
2488 if ($ev->{button} == $self->{button}) {
2489 undef $GRAB;
2490 $self->hide;
2491
2492 $self->emit ("popdown");
2493 $self->{hover}[1]->() if $self->{hover};
2494 }
2495}
2496
2497#############################################################################
2498
2358package CFClient::UI::Root; 2499package CFClient::UI::Root;
2359 2500
2360our @ISA = CFClient::UI::Container::; 2501our @ISA = CFClient::UI::Container::;
2361 2502
2362use CFClient::OpenGL; 2503use CFClient::OpenGL;
2434 $self->_draw; 2575 $self->_draw;
2435} 2576}
2436 2577
2437############################################################################# 2578#############################################################################
2438 2579
2580package CFClient::UI::Inventory;
2581
2582our @ISA = CFClient::UI::Container::;
2583
2584use CFClient::OpenGL;
2585
2586sub new {
2587 my $class = shift;
2588
2589 my $self = $class->SUPER::new (@_);
2590
2591 $self
2592}
2593
2594sub size_allocate {
2595 my ($self, $w, $h) = @_;
2596
2597 $self->{w} = $w;
2598 $self->{h} = $h;
2599
2600 $self->check_size;
2601}
2602
2603sub set_items {
2604 my ($self, $items) = @_;
2605 my @items = values %{$items};
2606 @items = sort { $a->{type} <=> $b->{type} } @items;
2607
2608 $self->{real_items} = \@items;
2609
2610 for my $item (@items) {
2611 my $desc = $item->{nrof} < 2
2612 ? $item->{name}
2613 : "$item->{nrof} $item->{name_pl}";
2614
2615 $self->add (my $hb = new CFClient::UI::HBox);
2616
2617 $hb->add (my $f = new CFClient::UI::Face
2618 can_events => 0,
2619 face => $item->{face},
2620 anim => $item->{anim},
2621 animspeed => $item->{animspeed},
2622 expand => 1
2623 );
2624 $hb->add (new CFClient::UI::Label text => $desc, expand => 1);
2625 }
2626
2627 $self->{max_pos} = (scalar @items) - 1;
2628
2629 my $range = $self->{range};
2630 my $page = $self->{h} / 32; # waht information souce to use for face size?
2631 # it should be configurable i guess...
2632 $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2633 $range->update;
2634}
2635
2636sub size_request {
2637 my ($self) = @_;
2638 (100, 200)
2639}
2640
2641sub set_range {
2642 my ($self, $range) = @_;
2643
2644 $self->{range} = $range;
2645 $range->connect (changed => sub { $self->update });
2646
2647 my $page = $self->{h} / 32; # waht information souce to use for face size?
2648 # it should be configurable i guess...
2649
2650 $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2651 $range->update;
2652
2653 $self->update;
2654}
2655
2656sub _draw {
2657 my ($self) = @_;
2658
2659 my ($w, $h) = ($self->{w}, $self->{h});
2660
2661 $self->{pos} = int $self->{range}{range}[0];
2662
2663 my $y = 0;
2664 my $cnt = 0;
2665 my $hrem = $self->{h}; # horiz. remaining space
2666
2667 for (my $i = $self->{pos}; $i < @{$self->{children} || []}; $i++) {
2668 my $chld = $self->{children}->[$i];
2669
2670 if ($hrem >= $chld->{h}) {
2671 $chld->configure (0, $y, $chld->{w}, $chld->{h});
2672
2673 $chld->show;
2674 $chld->draw;
2675
2676 $hrem -= $chld->{h};
2677 $y += $chld->{h};
2678 } else {
2679 last
2680 }
2681 }
2682}
2683
2684
2685#############################################################################
2686
2439package CFClient::UI; 2687package CFClient::UI;
2440 2688
2441$ROOT = new CFClient::UI::Root; 2689$ROOT = new CFClient::UI::Root;
2442$TOOLTIP = new CFClient::UI::Tooltip; 2690$TOOLTIP = new CFClient::UI::Tooltip;
2443 2691

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines