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.266 by root, Thu Jun 1 03:42:58 2006 UTC vs.
Revision 1.272 by root, Sat Jun 3 01:47:14 2006 UTC

171sub rescale_widgets { 171sub rescale_widgets {
172 my ($sx, $sy) = @_; 172 my ($sx, $sy) = @_;
173 173
174 for my $widget (values %WIDGET) { 174 for my $widget (values %WIDGET) {
175 if ($widget->{is_toplevel}) { 175 if ($widget->{is_toplevel}) {
176 $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 176 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
177 $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 177 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
178 178
179 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 179 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
180 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 180 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
181 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; 181 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w};
182 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; 182 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/;
183 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; 183 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
184 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; 184 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h};
185 185
186 $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 186 $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
187 $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 187 $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
188 188
189 } 189 }
190 } 190 }
191 191
192 reconfigure_widgets; 192 reconfigure_widgets;
371sub size_allocate { 371sub size_allocate {
372 # nothing to be done 372 # nothing to be done
373} 373}
374 374
375sub children { 375sub children {
376 # nop
377}
378
379sub visible_children {
380 $_[0]->children
376} 381}
377 382
378sub set_max_size { 383sub set_max_size {
379 my ($self, $w, $h) = @_; 384 my ($self, $w, $h) = @_;
380 385
439 444
440 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus 445 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
441 unless $FOCUS; 446 unless $FOCUS;
442} 447}
443 448
444sub mouse_motion { } 449sub mouse_motion { 0 }
445sub button_up { } 450sub button_up { 0 }
446sub key_down { } 451sub key_down { 0 }
447sub key_up { } 452sub key_up { 0 }
448 453
449sub button_down { 454sub button_down {
450 my ($self, $ev, $x, $y) = @_; 455 my ($self, $ev, $x, $y) = @_;
451 456
452 $self->focus_in; 457 $self->focus_in;
453}
454 458
455sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } 459 0
456sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } 460}
457sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
458sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
459sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
460 461
461sub find_widget { 462sub find_widget {
462 my ($self, $x, $y) = @_; 463 my ($self, $x, $y) = @_;
463 464
464 return () unless $self->{can_events}; 465 return () unless $self->{can_events};
526 527
527 $self->realloc; 528 $self->realloc;
528 $self->update; 529 $self->update;
529} 530}
530 531
532# using global variables seems a bit hacky, but passing through all drawing
533# functions seems pointless.
534our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn
535
531sub draw { 536sub draw {
532 my ($self) = @_; 537 my ($self) = @_;
533 538
534 return unless $self->{h} && $self->{w}; 539 return unless $self->{h} && $self->{w};
540
541 # update screen rectangle
542 local $draw_x = $draw_x + $self->{x};
543 local $draw_y = $draw_y + $self->{y};
544 local $draw_w = $draw_x + $self->{w};
545 local $draw_h = $draw_y + $self->{h};
546
547 # skip widgets that are entirely outside the drawing area
548 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
549 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
535 550
536 glPushMatrix; 551 glPushMatrix;
537 glTranslate $self->{x}, $self->{y}, 0; 552 glTranslate $self->{x}, $self->{y}, 0;
538 $self->_draw; 553 $self->_draw;
539 glPopMatrix; 554 glPopMatrix;
653our @ISA = CFClient::UI::Base::; 668our @ISA = CFClient::UI::Base::;
654 669
655sub new { 670sub new {
656 my ($class, %arg) = @_; 671 my ($class, %arg) = @_;
657 672
658 my $children = delete $arg{children} || []; 673 my $children = delete $arg{children};
659 674
660 my $self = $class->SUPER::new ( 675 my $self = $class->SUPER::new (
661 children => [], 676 children => [],
662 can_events => 0, 677 can_events => 0,
663 %arg, 678 %arg,
664 ); 679 );
680
665 $self->add ($_) for @$children; 681 $self->add (@$children)
682 if $children;
666 683
667 $self 684 $self
668} 685}
669 686
670sub add { 687sub add {
718 $x -= $self->{x}; 735 $x -= $self->{x};
719 $y -= $self->{y}; 736 $y -= $self->{y};
720 737
721 my $res; 738 my $res;
722 739
723 for (reverse @{ $self->{children} }) { 740 for (reverse $self->visible_children) {
724 $res = $_->find_widget ($x, $y) 741 $res = $_->find_widget ($x, $y)
725 and return $res; 742 and return $res;
726 } 743 }
727 744
728 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) 745 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
804 $self->SUPER::size_allocate ($w, $h); 821 $self->SUPER::size_allocate ($w, $h);
805 $self->update; 822 $self->update;
806} 823}
807 824
808sub _render { 825sub _render {
826 my ($self) = @_;
827
809 $_[0]{children}[0]->draw; 828 $self->{children}[0]->draw;
810} 829}
811 830
812sub render_child { 831sub render_child {
813 my ($self) = @_; 832 my ($self) = @_;
814 833
815 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 834 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
816 glClearColor 0, 0, 0, 0; 835 glClearColor 0, 0, 0, 0;
817 glClear GL_COLOR_BUFFER_BIT; 836 glClear GL_COLOR_BUFFER_BIT;
818 837
838 {
839 package CFClient::UI::Base;
840
841 ($draw_x, $draw_y, $draw_w, $draw_h) =
842 (0, 0, $self->{w}, $self->{h});
843 }
844
819 $self->_render; 845 $self->_render;
820 }; 846 };
821} 847}
822 848
823sub _draw { 849sub _draw {
824 my ($self) = @_; 850 my ($self) = @_;
825 851
826 my ($w, $h) = ($self->w, $self->h); 852 my ($w, $h) = @$self{qw(w h)};
827 853
828 my $tex = $self->{texture} 854 my $tex = $self->{texture}
829 or return; 855 or return;
830 856
831 glEnable GL_TEXTURE_2D; 857 glEnable GL_TEXTURE_2D;
913 } 939 }
914} 940}
915 941
916sub _render { 942sub _render {
917 my ($self) = @_; 943 my ($self) = @_;
944
945 local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x};
946 local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y};
918 947
919 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 948 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
920 949
921 $self->SUPER::_render; 950 $self->SUPER::_render;
922} 951}
1030my @border = 1059my @border =
1031 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1060 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1032 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1061 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1033 1062
1034sub new { 1063sub new {
1035 my $class = shift; 1064 my ($class, %arg) = @_;
1065
1066 my $title = delete $arg{title};
1036 1067
1037 my $self = $class->SUPER::new ( 1068 my $self = $class->SUPER::new (
1038 bg => [1, 1, 1, 1], 1069 bg => [1, 1, 1, 1],
1039 border_bg => [1, 1, 1, 1], 1070 border_bg => [1, 1, 1, 1],
1040 border => 0.6, 1071 border => 0.6,
1041 can_events => 1, 1072 can_events => 1,
1042 min_w => 16, 1073 min_w => 16,
1043 min_h => 16, 1074 min_h => 16,
1044 @_ 1075 %arg,
1045 ); 1076 );
1046 1077
1047 $self->{title} &&= new CFClient::UI::Label 1078 $self->{title} = new CFClient::UI::Label
1048 align => 0, 1079 align => 0,
1049 valign => 1, 1080 valign => 1,
1050 text => $self->{title}, 1081 text => $title,
1051 fontsize => $self->{border}; 1082 fontsize => $self->{border}
1083 if defined $title;
1052 1084
1053 $self 1085 $self
1086}
1087
1088sub add {
1089 my ($self, @widgets) = @_;
1090
1091 $self->SUPER::add (@widgets);
1092 $self->CFClient::UI::Container::add ($self->{title}) if $self->{title};
1054} 1093}
1055 1094
1056sub border { 1095sub border {
1057 int $_[0]{border} * $::FONTSIZE 1096 int $_[0]{border} * $::FONTSIZE
1058} 1097}
1059 1098
1060sub size_request { 1099sub size_request {
1061 my ($self) = @_; 1100 my ($self) = @_;
1101
1102 $self->{title}->size_request
1103 if $self->{title};
1062 1104
1063 my ($w, $h) = $self->SUPER::size_request; 1105 my ($w, $h) = $self->SUPER::size_request;
1064 1106
1065 ( 1107 (
1066 $w + $self->border * 2, 1108 $w + $self->border * 2,
1069} 1111}
1070 1112
1071sub size_allocate { 1113sub size_allocate {
1072 my ($self, $w, $h) = @_; 1114 my ($self, $w, $h) = @_;
1073 1115
1116 if ($self->{title}) {
1117 $self->{title}{w} = $w;
1118 $self->{title}{h} = $h;
1119 $self->{title}->size_allocate ($w, $h);
1120 }
1121
1122 my $border = $self->border;
1123
1074 $h -= List::Util::max 0, $self->border * 2; 1124 $h -= List::Util::max 0, $border * 2;
1075 $w -= List::Util::max 0, $self->border * 2; 1125 $w -= List::Util::max 0, $border * 2;
1076 1126
1077 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
1078 if $self->{title};
1079
1080 $self->child->configure ($self->border, $self->border, $w, $h); 1127 $self->child->configure ($border, $border, $w, $h);
1081} 1128}
1082 1129
1083sub button_down { 1130sub button_down {
1084 my ($self, $ev, $x, $y) = @_; 1131 my ($self, $ev, $x, $y) = @_;
1085 1132
1119 1166
1120 ($x, $y) = ($ev->{x}, $ev->{y}); 1167 ($x, $y) = ($ev->{x}, $ev->{y});
1121 1168
1122 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1169 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1123 }; 1170 };
1171 } else {
1172 return 0;
1173 }
1174
1124 } 1175 1
1125} 1176}
1126 1177
1127sub button_up { 1178sub button_up {
1128 my ($self, $ev, $x, $y) = @_; 1179 my ($self, $ev, $x, $y) = @_;
1129 1180
1130 delete $self->{motion}; 1181 !!delete $self->{motion}
1131} 1182}
1132 1183
1133sub mouse_motion { 1184sub mouse_motion {
1134 my ($self, $ev, $x, $y) = @_; 1185 my ($self, $ev, $x, $y) = @_;
1135 1186
1136 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1187 $self->{motion}->($ev, $x, $y) if $self->{motion};
1188
1189 !!$self->{motion}
1137} 1190}
1138 1191
1139sub _draw { 1192sub _draw {
1140 my ($self) = @_; 1193 my ($self) = @_;
1141 1194
1195 my $child = $self->{children}[0];
1196
1142 my ($w, $h ) = ($self->{w}, $self->{h}); 1197 my ($w, $h ) = ($self->{w}, $self->{h});
1143 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 1198 my ($cw, $ch) = ($child->{w}, $child->{h});
1144 1199
1145 glEnable GL_TEXTURE_2D; 1200 glEnable GL_TEXTURE_2D;
1146 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1201 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1147 1202
1148 my $border = $self->border; 1203 my $border = $self->border;
1163 $bg->draw_quad_alpha ($border, $border, $cw, $ch); 1218 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
1164 } 1219 }
1165 1220
1166 glDisable GL_TEXTURE_2D; 1221 glDisable GL_TEXTURE_2D;
1167 1222
1168 $self->{title}->draw if $self->{title};
1169
1170 $self->child->draw; 1223 $child->draw;
1224
1225 if ($self->{title}) {
1226 glTranslate 0, $border - $self->{h};
1227 $self->{title}->_draw;
1228 }
1171} 1229}
1172 1230
1173############################################################################# 1231#############################################################################
1174 1232
1175package CFClient::UI::Table; 1233package CFClient::UI::Table;
1523} 1581}
1524 1582
1525sub size_allocate { 1583sub size_allocate {
1526 my ($self, $w, $h) = @_; 1584 my ($self, $w, $h) = @_;
1527 1585
1586 delete $self->{ox};
1587
1528 delete $self->{texture} 1588 delete $self->{texture}
1529 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; 1589 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w};
1530} 1590}
1531 1591
1532sub set_fontsize { 1592sub set_fontsize {
1549 $self->{layout}->set_width ($self->{w}); 1609 $self->{layout}->set_width ($self->{w});
1550 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1610 $self->{layout}->set_ellipsise ($self->{ellipsise});
1551 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1611 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1552 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1612 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1553 1613
1554 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1614 new_from_layout CFClient::Texture $self->{layout}
1615 };
1555 1616
1617 unless (exists $self->{ox}) {
1556 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1618 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1557 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1619 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x}
1558 : ($self->{w} - $tex->{w}) * 0.5); 1620 : ($self->{w} - $tex->{w}) * 0.5);
1559 1621
1560 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1622 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1561 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1623 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1562 : ($self->{h} - $tex->{h}) * 0.5); 1624 : ($self->{h} - $tex->{h}) * 0.5);
1563
1564 $tex
1565 }; 1625 };
1566 1626
1567 glEnable GL_TEXTURE_2D; 1627 glEnable GL_TEXTURE_2D;
1568 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1628 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1569 1629
1664 $self->{cursor} = length $text; 1724 $self->{cursor} = length $text;
1665 } elsif ($uni == 27) { 1725 } elsif ($uni == 27) {
1666 $self->_emit ('escape'); 1726 $self->_emit ('escape');
1667 } elsif ($uni) { 1727 } elsif ($uni) {
1668 substr $text, $self->{cursor}++, 0, chr $uni; 1728 substr $text, $self->{cursor}++, 0, chr $uni;
1729 } else {
1730 return 0;
1669 } 1731 }
1670 1732
1671 $self->_set_text ($text); 1733 $self->_set_text ($text);
1672 1734
1673 $self->realloc; 1735 $self->realloc;
1736
1737 1
1674} 1738}
1675 1739
1676sub focus_in { 1740sub focus_in {
1677 my ($self) = @_; 1741 my ($self) = @_;
1678 1742
1693 utf8::encode $text; 1757 utf8::encode $text;
1694 $self->{cursor} = length substr $text, 0, $idx; 1758 $self->{cursor} = length substr $text, 0, $idx;
1695 1759
1696 $self->_set_text ($self->{text}); 1760 $self->_set_text ($self->{text});
1697 $self->update; 1761 $self->update;
1762
1763 1
1698} 1764}
1699 1765
1700sub mouse_motion { 1766sub mouse_motion {
1701 my ($self, $ev, $x, $y) = @_; 1767 my ($self, $ev, $x, $y) = @_;
1702# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# 1768# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
1769
1770 0
1703} 1771}
1704 1772
1705sub _draw { 1773sub _draw {
1706 my ($self) = @_; 1774 my ($self) = @_;
1707 1775
1784 } else { 1852 } else {
1785 $self->set_text ($self->{history_saveback}); 1853 $self->set_text ($self->{history_saveback});
1786 } 1854 }
1787 1855
1788 } else { 1856 } else {
1789 $self->SUPER::key_down ($ev); 1857 return $self->SUPER::key_down ($ev)
1858 }
1859
1790 } 1860 1
1791
1792} 1861}
1793 1862
1794############################################################################# 1863#############################################################################
1795 1864
1796package CFClient::UI::Button; 1865package CFClient::UI::Button;
1825 my ($self, $ev, $x, $y) = @_; 1894 my ($self, $ev, $x, $y) = @_;
1826 1895
1827 $self->emit ("activate") 1896 $self->emit ("activate")
1828 if $x >= 0 && $x < $self->{w} 1897 if $x >= 0 && $x < $self->{w}
1829 && $y >= 0 && $y < $self->{h}; 1898 && $y >= 0 && $y < $self->{h};
1899
1900 1
1830} 1901}
1831 1902
1832sub _draw { 1903sub _draw {
1833 my ($self) = @_; 1904 my ($self) = @_;
1834 1905
1888 1959
1889 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} 1960 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1890 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { 1961 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1891 $self->{state} = !$self->{state}; 1962 $self->{state} = !$self->{state};
1892 $self->_emit (changed => $self->{state}); 1963 $self->_emit (changed => $self->{state});
1964 } else {
1965 return 0
1966 }
1967
1893 } 1968 1
1894} 1969}
1895 1970
1896sub _draw { 1971sub _draw {
1897 my ($self) = @_; 1972 my ($self) = @_;
1898 1973
2236 2311
2237 $self->SUPER::button_down ($ev, $x, $y); 2312 $self->SUPER::button_down ($ev, $x, $y);
2238 2313
2239 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2314 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2240 2315
2241 $self->mouse_motion ($ev, $x, $y); 2316 $self->mouse_motion ($ev, $x, $y)
2242} 2317}
2243 2318
2244sub mouse_motion { 2319sub mouse_motion {
2245 my ($self, $ev, $x, $y) = @_; 2320 my ($self, $ev, $x, $y) = @_;
2246 2321
2250 my (undef, $lo, $hi, $page) = @{$self->{range}}; 2325 my (undef, $lo, $hi, $page) = @{$self->{range}};
2251 2326
2252 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 2327 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2253 2328
2254 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 2329 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2330 } else {
2331 return 0;
2332 }
2333
2255 } 2334 1
2256} 2335}
2257 2336
2258sub update { 2337sub update {
2259 my ($self) = @_; 2338 my ($self) = @_;
2260 2339
2782 $self->SUPER::DESTROY; 2861 $self->SUPER::DESTROY;
2783} 2862}
2784 2863
2785############################################################################# 2864#############################################################################
2786 2865
2866package CFClient::UI::Buttonbar;
2867
2868our @ISA = CFClient::UI::HBox::;
2869
2870# TODO: should actualyl wrap buttons and other goodies.
2871
2872#############################################################################
2873
2787package CFClient::UI::Menu; 2874package CFClient::UI::Menu;
2788 2875
2789our @ISA = CFClient::UI::FancyFrame::; 2876our @ISA = CFClient::UI::FancyFrame::;
2790 2877
2791use CFClient::OpenGL; 2878use CFClient::OpenGL;
2838 my ($self, $ev, $x, $y) = @_; 2925 my ($self, $ev, $x, $y) = @_;
2839 2926
2840 # TODO: should use vbox->find_widget or so 2927 # TODO: should use vbox->find_widget or so
2841 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); 2928 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2842 $self->{hover} = $self->{item}{$HOVER}; 2929 $self->{hover} = $self->{item}{$HOVER};
2930
2931 0
2843} 2932}
2844 2933
2845sub button_up { 2934sub button_up {
2846 my ($self, $ev, $x, $y) = @_; 2935 my ($self, $ev, $x, $y) = @_;
2847 2936
2849 undef $GRAB; 2938 undef $GRAB;
2850 $self->hide; 2939 $self->hide;
2851 2940
2852 $self->_emit ("popdown"); 2941 $self->_emit ("popdown");
2853 $self->{hover}[1]->() if $self->{hover}; 2942 $self->{hover}[1]->() if $self->{hover};
2943 } else {
2944 return 0
2945 }
2946
2854 } 2947 1
2948}
2949
2950#############################################################################
2951
2952package CFClient::UI::Multiplexer;
2953
2954our @ISA = CFClient::UI::Container::;
2955
2956sub new {
2957 my $class = shift;
2958
2959 my $self = $class->SUPER::new (
2960 @_,
2961 );
2962
2963 $self->{current} = $self->{children}[0]
2964 if @{ $self->{children} };
2965
2966 $self
2967}
2968
2969sub add {
2970 my ($self, @widgets) = @_;
2971
2972 $self->SUPER::add (@widgets);
2973
2974 $self->{current} = $self->{children}[0]
2975 if @{ $self->{children} };
2976}
2977
2978sub set_current_page {
2979 my ($self, $page_or_widget) = @_;
2980
2981 my $widget = ref $page_or_widget
2982 ? $page_or_widget
2983 : $self->{children}[$page_or_widget];
2984
2985 $self->{current} = $widget;
2986 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
2987
2988 $self->_emit (page_changed => $self->{current});
2989
2990 $self->realloc;
2991}
2992
2993sub visible_children {
2994 $_[0]{current}
2995}
2996
2997sub size_request {
2998 my ($self) = @_;
2999
3000 $self->{current}->size_request
3001}
3002
3003sub size_allocate {
3004 my ($self, $w, $h) = @_;
3005
3006 $self->{current}->configure (0, 0, $w, $h);
3007}
3008
3009sub _draw {
3010 my ($self) = @_;
3011
3012 $self->{current}->draw;
3013}
3014
3015#############################################################################
3016
3017package CFClient::UI::Notebook;
3018
3019our @ISA = CFClient::UI::VBox::;
3020
3021sub new {
3022 my $class = shift;
3023
3024 my $self = $class->SUPER::new (
3025 buttonbar => (new CFClient::UI::Buttonbar),
3026 multiplexer => (new CFClient::UI::Multiplexer expand => 1),
3027 @_,
3028 );
3029
3030 $self->SUPER::add ($self->{buttonbar}, $self->{multiplexer});
3031
3032 $self
3033}
3034
3035sub add {
3036 my ($self, $title, $widget, $tooltip) = @_;
3037
3038 Scalar::Util::weaken $self;
3039
3040 $self->{buttonbar}->add (new CFClient::UI::Button
3041 markup => $title,
3042 tooltip => $tooltip,
3043 on_activate => sub { $self->set_current_page ($widget) },
3044 );
3045
3046 $self->{multiplexer}->add ($widget);
3047}
3048
3049sub set_current_page {
3050 my ($self, $page) = @_;
3051
3052 $self->{multiplexer}->set_current_page ($page);
3053 $self->_emit (page_changed => $self->{multiplexer}{current});
2855} 3054}
2856 3055
2857############################################################################# 3056#############################################################################
2858 3057
2859package CFClient::UI::Statusbox; 3058package CFClient::UI::Statusbox;
3106 $rec = $::CONN->stop_record if $::CONN; 3305 $rec = $::CONN->stop_record if $::CONN;
3107 return unless ref $rec eq 'ARRAY'; 3306 return unless ref $rec eq 'ARRAY';
3108 $self->set_command_list ($rec); 3307 $self->set_command_list ($rec);
3109} 3308}
3110 3309
3111# if $commit is true, the binding will be set after the user entered a key combo 3310
3311sub ask_for_bind_and_commit {
3312 my ($self) = @_;
3313 $self->ask_for_bind (1);
3314}
3315
3112sub ask_for_bind { 3316sub ask_for_bind {
3113 my ($self, $commit) = @_; 3317 my ($self, $commit) = @_;
3114 3318
3115 CFClient::Binder::open_binding_dialog (sub { 3319 CFClient::Binder::open_binding_dialog (sub {
3116 my ($mod, $sym) = @_; 3320 my ($mod, $sym) = @_;
3200 3404
3201############################################################################# 3405#############################################################################
3202 3406
3203package CFClient::UI::SpellList; 3407package CFClient::UI::SpellList;
3204 3408
3205our @ISA = CFClient::UI::FancyFrame::; 3409our @ISA = CFClient::UI::ScrolledWindow::;
3206 3410
3207sub new { 3411sub new {
3208 my $class = shift; 3412 my $class = shift;
3209 3413
3210 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3414 my $self = $class->SUPER::new (
3211 3415 binding => [],
3212 $self->add (new CFClient::UI::ScrolledWindow 3416 commands => [],
3213 scrolled => $self->{spellbox} = new CFClient::UI::Table); 3417 scrolled => (new CFClient::UI::Table),
3214 3418 @_,
3215 $self; 3419 )
3216} 3420}
3217 3421
3218# XXX: Do sorting? Argl... 3422# XXX: Do sorting? Argl...
3219sub add_spell { 3423sub add_spell {
3220 my ($self, $spell) = @_; 3424 my ($self, $spell) = @_;
3221 $self->{spells}->{$spell->{name}} = $spell; 3425 $self->{spells}->{$spell->{name}} = $spell;
3222 3426
3223 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3427 $self->{scrolled}->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3224 face => $spell->{face}, 3428 face => $spell->{face},
3225 can_hover => 1, 3429 can_hover => 1,
3226 can_events => 1, 3430 can_events => 1,
3227 tooltip => $spell->{message}); 3431 tooltip => $spell->{message});
3228 3432
3229 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3433 $self->{scrolled}->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3230 text => $spell->{name}, 3434 text => $spell->{name},
3231 can_hover => 1, 3435 can_hover => 1,
3232 can_events => 1, 3436 can_events => 1,
3233 tooltip => $spell->{message}, 3437 tooltip => $spell->{message},
3234 expand => 1); 3438 expand => 1);
3235 3439
3236 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3440 $self->{scrolled}->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3237 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3441 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3238 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3442 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3239 expand => 1); 3443 expand => 1);
3240 3444
3241 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3445 $self->{scrolled}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3242 text => "bind to key", 3446 text => "bind to key",
3243 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3447 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3244} 3448}
3245 3449
3246sub rebuild_spell_list { 3450sub rebuild_spell_list {
3471 glLoadIdentity; 3675 glLoadIdentity;
3472 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3676 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3473 glMatrixMode GL_MODELVIEW; 3677 glMatrixMode GL_MODELVIEW;
3474 glLoadIdentity; 3678 glLoadIdentity;
3475 3679
3680 {
3681 package CFClient::UI::Base;
3682
3683 ($draw_x, $draw_y, $draw_w, $draw_h) =
3684 (0, 0, $self->{w}, $self->{h});
3685 }
3686
3476 $self->_draw; 3687 $self->_draw;
3477} 3688}
3478 3689
3479############################################################################# 3690#############################################################################
3480 3691

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines