… | |
… | |
371 | sub size_allocate { |
371 | sub size_allocate { |
372 | # nothing to be done |
372 | # nothing to be done |
373 | } |
373 | } |
374 | |
374 | |
375 | sub children { |
375 | sub children { |
|
|
376 | # nop |
|
|
377 | } |
|
|
378 | |
|
|
379 | sub visible_children { |
|
|
380 | $_[0]->children |
376 | } |
381 | } |
377 | |
382 | |
378 | sub set_max_size { |
383 | sub 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 | |
444 | sub mouse_motion { } |
449 | sub mouse_motion { 0 } |
445 | sub button_up { } |
450 | sub button_up { 0 } |
446 | sub key_down { } |
451 | sub key_down { 0 } |
447 | sub key_up { } |
452 | sub key_up { 0 } |
448 | |
453 | |
449 | sub button_down { |
454 | sub button_down { |
450 | my ($self, $ev, $x, $y) = @_; |
455 | my ($self, $ev, $x, $y) = @_; |
451 | |
456 | |
452 | $self->focus_in; |
457 | $self->focus_in; |
|
|
458 | |
|
|
459 | 0 |
453 | } |
460 | } |
454 | |
461 | |
455 | sub find_widget { |
462 | sub find_widget { |
456 | my ($self, $x, $y) = @_; |
463 | my ($self, $x, $y) = @_; |
457 | |
464 | |
… | |
… | |
661 | our @ISA = CFClient::UI::Base::; |
668 | our @ISA = CFClient::UI::Base::; |
662 | |
669 | |
663 | sub new { |
670 | sub new { |
664 | my ($class, %arg) = @_; |
671 | my ($class, %arg) = @_; |
665 | |
672 | |
666 | my $children = delete $arg{children} || []; |
673 | my $children = delete $arg{children}; |
667 | |
674 | |
668 | my $self = $class->SUPER::new ( |
675 | my $self = $class->SUPER::new ( |
669 | children => [], |
676 | children => [], |
670 | can_events => 0, |
677 | can_events => 0, |
671 | %arg, |
678 | %arg, |
672 | ); |
679 | ); |
|
|
680 | |
673 | $self->add ($_) for @$children; |
681 | $self->add (@$children) |
|
|
682 | if $children; |
674 | |
683 | |
675 | $self |
684 | $self |
676 | } |
685 | } |
677 | |
686 | |
678 | sub add { |
687 | sub add { |
… | |
… | |
726 | $x -= $self->{x}; |
735 | $x -= $self->{x}; |
727 | $y -= $self->{y}; |
736 | $y -= $self->{y}; |
728 | |
737 | |
729 | my $res; |
738 | my $res; |
730 | |
739 | |
731 | for (reverse @{ $self->{children} }) { |
740 | for (reverse $self->visible_children) { |
732 | $res = $_->find_widget ($x, $y) |
741 | $res = $_->find_widget ($x, $y) |
733 | and return $res; |
742 | and return $res; |
734 | } |
743 | } |
735 | |
744 | |
736 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
745 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
… | |
… | |
1050 | my @border = |
1059 | my @border = |
1051 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1060 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1052 | 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); |
1053 | |
1062 | |
1054 | sub new { |
1063 | sub new { |
1055 | my $class = shift; |
1064 | my ($class, %arg) = @_; |
|
|
1065 | |
|
|
1066 | my $title = delete $arg{title}; |
1056 | |
1067 | |
1057 | my $self = $class->SUPER::new ( |
1068 | my $self = $class->SUPER::new ( |
1058 | bg => [1, 1, 1, 1], |
1069 | bg => [1, 1, 1, 1], |
1059 | border_bg => [1, 1, 1, 1], |
1070 | border_bg => [1, 1, 1, 1], |
1060 | border => 0.6, |
1071 | border => 0.6, |
1061 | can_events => 1, |
1072 | can_events => 1, |
1062 | min_w => 16, |
1073 | min_w => 16, |
1063 | min_h => 16, |
1074 | min_h => 16, |
1064 | @_ |
1075 | %arg, |
1065 | ); |
1076 | ); |
1066 | |
1077 | |
1067 | $self->{title} &&= new CFClient::UI::Label |
1078 | $self->{title} = new CFClient::UI::Label |
1068 | align => 0, |
1079 | align => 0, |
1069 | valign => 1, |
1080 | valign => 1, |
1070 | text => $self->{title}, |
1081 | text => $title, |
1071 | fontsize => $self->{border}; |
1082 | fontsize => $self->{border} |
|
|
1083 | if defined $title; |
1072 | |
1084 | |
1073 | $self |
1085 | $self |
|
|
1086 | } |
|
|
1087 | |
|
|
1088 | sub add { |
|
|
1089 | my ($self, @widgets) = @_; |
|
|
1090 | |
|
|
1091 | $self->SUPER::add (@widgets); |
|
|
1092 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1074 | } |
1093 | } |
1075 | |
1094 | |
1076 | sub border { |
1095 | sub border { |
1077 | int $_[0]{border} * $::FONTSIZE |
1096 | int $_[0]{border} * $::FONTSIZE |
1078 | } |
1097 | } |
1079 | |
1098 | |
1080 | sub size_request { |
1099 | sub size_request { |
1081 | my ($self) = @_; |
1100 | my ($self) = @_; |
|
|
1101 | |
|
|
1102 | $self->{title}->size_request |
|
|
1103 | if $self->{title}; |
1082 | |
1104 | |
1083 | my ($w, $h) = $self->SUPER::size_request; |
1105 | my ($w, $h) = $self->SUPER::size_request; |
1084 | |
1106 | |
1085 | ( |
1107 | ( |
1086 | $w + $self->border * 2, |
1108 | $w + $self->border * 2, |
… | |
… | |
1089 | } |
1111 | } |
1090 | |
1112 | |
1091 | sub size_allocate { |
1113 | sub size_allocate { |
1092 | my ($self, $w, $h) = @_; |
1114 | my ($self, $w, $h) = @_; |
1093 | |
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 | |
1094 | $h -= List::Util::max 0, $self->border * 2; |
1124 | $h -= List::Util::max 0, $border * 2; |
1095 | $w -= List::Util::max 0, $self->border * 2; |
1125 | $w -= List::Util::max 0, $border * 2; |
1096 | |
1126 | |
1097 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
|
|
1098 | if $self->{title}; |
|
|
1099 | |
|
|
1100 | $self->child->configure ($self->border, $self->border, $w, $h); |
1127 | $self->child->configure ($border, $border, $w, $h); |
1101 | } |
1128 | } |
1102 | |
1129 | |
1103 | sub button_down { |
1130 | sub button_down { |
1104 | my ($self, $ev, $x, $y) = @_; |
1131 | my ($self, $ev, $x, $y) = @_; |
1105 | |
1132 | |
… | |
… | |
1139 | |
1166 | |
1140 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1167 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1141 | |
1168 | |
1142 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1169 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1143 | }; |
1170 | }; |
|
|
1171 | } else { |
|
|
1172 | return 0; |
|
|
1173 | } |
|
|
1174 | |
1144 | } |
1175 | 1 |
1145 | } |
1176 | } |
1146 | |
1177 | |
1147 | sub button_up { |
1178 | sub button_up { |
1148 | my ($self, $ev, $x, $y) = @_; |
1179 | my ($self, $ev, $x, $y) = @_; |
1149 | |
1180 | |
1150 | delete $self->{motion}; |
1181 | !!delete $self->{motion} |
1151 | } |
1182 | } |
1152 | |
1183 | |
1153 | sub mouse_motion { |
1184 | sub mouse_motion { |
1154 | my ($self, $ev, $x, $y) = @_; |
1185 | my ($self, $ev, $x, $y) = @_; |
1155 | |
1186 | |
1156 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1187 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1188 | |
|
|
1189 | !!$self->{motion} |
1157 | } |
1190 | } |
1158 | |
1191 | |
1159 | sub _draw { |
1192 | sub _draw { |
1160 | my ($self) = @_; |
1193 | my ($self) = @_; |
1161 | |
1194 | |
|
|
1195 | my $child = $self->{children}[0]; |
|
|
1196 | |
1162 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1197 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1163 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
1198 | my ($cw, $ch) = ($child->{w}, $child->{h}); |
1164 | |
1199 | |
1165 | glEnable GL_TEXTURE_2D; |
1200 | glEnable GL_TEXTURE_2D; |
1166 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1201 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1167 | |
1202 | |
1168 | my $border = $self->border; |
1203 | my $border = $self->border; |
… | |
… | |
1183 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1218 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1184 | } |
1219 | } |
1185 | |
1220 | |
1186 | glDisable GL_TEXTURE_2D; |
1221 | glDisable GL_TEXTURE_2D; |
1187 | |
1222 | |
1188 | $self->{title}->draw if $self->{title}; |
|
|
1189 | |
|
|
1190 | $self->child->draw; |
1223 | $child->draw; |
|
|
1224 | |
|
|
1225 | if ($self->{title}) { |
|
|
1226 | glTranslate 0, $border - $self->{h}; |
|
|
1227 | $self->{title}->_draw; |
|
|
1228 | } |
1191 | } |
1229 | } |
1192 | |
1230 | |
1193 | ############################################################################# |
1231 | ############################################################################# |
1194 | |
1232 | |
1195 | package CFClient::UI::Table; |
1233 | package CFClient::UI::Table; |
… | |
… | |
1543 | } |
1581 | } |
1544 | |
1582 | |
1545 | sub size_allocate { |
1583 | sub size_allocate { |
1546 | my ($self, $w, $h) = @_; |
1584 | my ($self, $w, $h) = @_; |
1547 | |
1585 | |
|
|
1586 | delete $self->{ox}; |
|
|
1587 | |
1548 | delete $self->{texture} |
1588 | delete $self->{texture} |
1549 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1589 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1550 | } |
1590 | } |
1551 | |
1591 | |
1552 | sub set_fontsize { |
1592 | sub set_fontsize { |
… | |
… | |
1569 | $self->{layout}->set_width ($self->{w}); |
1609 | $self->{layout}->set_width ($self->{w}); |
1570 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1610 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1571 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1611 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1572 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1612 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1573 | |
1613 | |
1574 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1614 | new_from_layout CFClient::Texture $self->{layout} |
|
|
1615 | }; |
1575 | |
1616 | |
|
|
1617 | unless (exists $self->{ox}) { |
1576 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1618 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1577 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1619 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1578 | : ($self->{w} - $tex->{w}) * 0.5); |
1620 | : ($self->{w} - $tex->{w}) * 0.5); |
1579 | |
1621 | |
1580 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1622 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1581 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1623 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1582 | : ($self->{h} - $tex->{h}) * 0.5); |
1624 | : ($self->{h} - $tex->{h}) * 0.5); |
1583 | |
|
|
1584 | $tex |
|
|
1585 | }; |
1625 | }; |
1586 | |
1626 | |
1587 | glEnable GL_TEXTURE_2D; |
1627 | glEnable GL_TEXTURE_2D; |
1588 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1628 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1589 | |
1629 | |
… | |
… | |
1684 | $self->{cursor} = length $text; |
1724 | $self->{cursor} = length $text; |
1685 | } elsif ($uni == 27) { |
1725 | } elsif ($uni == 27) { |
1686 | $self->_emit ('escape'); |
1726 | $self->_emit ('escape'); |
1687 | } elsif ($uni) { |
1727 | } elsif ($uni) { |
1688 | substr $text, $self->{cursor}++, 0, chr $uni; |
1728 | substr $text, $self->{cursor}++, 0, chr $uni; |
|
|
1729 | } else { |
|
|
1730 | return 0; |
1689 | } |
1731 | } |
1690 | |
1732 | |
1691 | $self->_set_text ($text); |
1733 | $self->_set_text ($text); |
1692 | |
1734 | |
1693 | $self->realloc; |
1735 | $self->realloc; |
|
|
1736 | |
|
|
1737 | 1 |
1694 | } |
1738 | } |
1695 | |
1739 | |
1696 | sub focus_in { |
1740 | sub focus_in { |
1697 | my ($self) = @_; |
1741 | my ($self) = @_; |
1698 | |
1742 | |
… | |
… | |
1713 | utf8::encode $text; |
1757 | utf8::encode $text; |
1714 | $self->{cursor} = length substr $text, 0, $idx; |
1758 | $self->{cursor} = length substr $text, 0, $idx; |
1715 | |
1759 | |
1716 | $self->_set_text ($self->{text}); |
1760 | $self->_set_text ($self->{text}); |
1717 | $self->update; |
1761 | $self->update; |
|
|
1762 | |
|
|
1763 | 1 |
1718 | } |
1764 | } |
1719 | |
1765 | |
1720 | sub mouse_motion { |
1766 | sub mouse_motion { |
1721 | my ($self, $ev, $x, $y) = @_; |
1767 | my ($self, $ev, $x, $y) = @_; |
1722 | # 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 |
1723 | } |
1771 | } |
1724 | |
1772 | |
1725 | sub _draw { |
1773 | sub _draw { |
1726 | my ($self) = @_; |
1774 | my ($self) = @_; |
1727 | |
1775 | |
… | |
… | |
1804 | } else { |
1852 | } else { |
1805 | $self->set_text ($self->{history_saveback}); |
1853 | $self->set_text ($self->{history_saveback}); |
1806 | } |
1854 | } |
1807 | |
1855 | |
1808 | } else { |
1856 | } else { |
1809 | $self->SUPER::key_down ($ev); |
1857 | return $self->SUPER::key_down ($ev) |
|
|
1858 | } |
|
|
1859 | |
1810 | } |
1860 | 1 |
1811 | |
|
|
1812 | } |
1861 | } |
1813 | |
1862 | |
1814 | ############################################################################# |
1863 | ############################################################################# |
1815 | |
1864 | |
1816 | package CFClient::UI::Button; |
1865 | package CFClient::UI::Button; |
… | |
… | |
1845 | my ($self, $ev, $x, $y) = @_; |
1894 | my ($self, $ev, $x, $y) = @_; |
1846 | |
1895 | |
1847 | $self->emit ("activate") |
1896 | $self->emit ("activate") |
1848 | if $x >= 0 && $x < $self->{w} |
1897 | if $x >= 0 && $x < $self->{w} |
1849 | && $y >= 0 && $y < $self->{h}; |
1898 | && $y >= 0 && $y < $self->{h}; |
|
|
1899 | |
|
|
1900 | 1 |
1850 | } |
1901 | } |
1851 | |
1902 | |
1852 | sub _draw { |
1903 | sub _draw { |
1853 | my ($self) = @_; |
1904 | my ($self) = @_; |
1854 | |
1905 | |
… | |
… | |
1908 | |
1959 | |
1909 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1960 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1910 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1961 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1911 | $self->{state} = !$self->{state}; |
1962 | $self->{state} = !$self->{state}; |
1912 | $self->_emit (changed => $self->{state}); |
1963 | $self->_emit (changed => $self->{state}); |
|
|
1964 | } else { |
|
|
1965 | return 0 |
|
|
1966 | } |
|
|
1967 | |
1913 | } |
1968 | 1 |
1914 | } |
1969 | } |
1915 | |
1970 | |
1916 | sub _draw { |
1971 | sub _draw { |
1917 | my ($self) = @_; |
1972 | my ($self) = @_; |
1918 | |
1973 | |
… | |
… | |
2256 | |
2311 | |
2257 | $self->SUPER::button_down ($ev, $x, $y); |
2312 | $self->SUPER::button_down ($ev, $x, $y); |
2258 | |
2313 | |
2259 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2314 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2260 | |
2315 | |
2261 | $self->mouse_motion ($ev, $x, $y); |
2316 | $self->mouse_motion ($ev, $x, $y) |
2262 | } |
2317 | } |
2263 | |
2318 | |
2264 | sub mouse_motion { |
2319 | sub mouse_motion { |
2265 | my ($self, $ev, $x, $y) = @_; |
2320 | my ($self, $ev, $x, $y) = @_; |
2266 | |
2321 | |
… | |
… | |
2270 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2325 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2271 | |
2326 | |
2272 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2327 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2273 | |
2328 | |
2274 | $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 | |
2275 | } |
2334 | 1 |
2276 | } |
2335 | } |
2277 | |
2336 | |
2278 | sub update { |
2337 | sub update { |
2279 | my ($self) = @_; |
2338 | my ($self) = @_; |
2280 | |
2339 | |
… | |
… | |
2802 | $self->SUPER::DESTROY; |
2861 | $self->SUPER::DESTROY; |
2803 | } |
2862 | } |
2804 | |
2863 | |
2805 | ############################################################################# |
2864 | ############################################################################# |
2806 | |
2865 | |
|
|
2866 | package CFClient::UI::Buttonbar; |
|
|
2867 | |
|
|
2868 | our @ISA = CFClient::UI::HBox::; |
|
|
2869 | |
|
|
2870 | # TODO: should actualyl wrap buttons and other goodies. |
|
|
2871 | |
|
|
2872 | ############################################################################# |
|
|
2873 | |
2807 | package CFClient::UI::Menu; |
2874 | package CFClient::UI::Menu; |
2808 | |
2875 | |
2809 | our @ISA = CFClient::UI::FancyFrame::; |
2876 | our @ISA = CFClient::UI::FancyFrame::; |
2810 | |
2877 | |
2811 | use CFClient::OpenGL; |
2878 | use CFClient::OpenGL; |
… | |
… | |
2858 | my ($self, $ev, $x, $y) = @_; |
2925 | my ($self, $ev, $x, $y) = @_; |
2859 | |
2926 | |
2860 | # TODO: should use vbox->find_widget or so |
2927 | # TODO: should use vbox->find_widget or so |
2861 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2928 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2862 | $self->{hover} = $self->{item}{$HOVER}; |
2929 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2930 | |
|
|
2931 | 0 |
2863 | } |
2932 | } |
2864 | |
2933 | |
2865 | sub button_up { |
2934 | sub button_up { |
2866 | my ($self, $ev, $x, $y) = @_; |
2935 | my ($self, $ev, $x, $y) = @_; |
2867 | |
2936 | |
… | |
… | |
2869 | undef $GRAB; |
2938 | undef $GRAB; |
2870 | $self->hide; |
2939 | $self->hide; |
2871 | |
2940 | |
2872 | $self->_emit ("popdown"); |
2941 | $self->_emit ("popdown"); |
2873 | $self->{hover}[1]->() if $self->{hover}; |
2942 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2943 | } else { |
|
|
2944 | return 0 |
|
|
2945 | } |
|
|
2946 | |
2874 | } |
2947 | 1 |
|
|
2948 | } |
|
|
2949 | |
|
|
2950 | ############################################################################# |
|
|
2951 | |
|
|
2952 | package CFClient::UI::Multiplexer; |
|
|
2953 | |
|
|
2954 | our @ISA = CFClient::UI::Container::; |
|
|
2955 | |
|
|
2956 | sub 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 | |
|
|
2969 | sub add { |
|
|
2970 | my ($self, @widgets) = @_; |
|
|
2971 | |
|
|
2972 | $self->SUPER::add (@widgets); |
|
|
2973 | |
|
|
2974 | $self->{current} = $self->{children}[0] |
|
|
2975 | if @{ $self->{children} }; |
|
|
2976 | } |
|
|
2977 | |
|
|
2978 | sub 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 | |
|
|
2993 | sub visible_children { |
|
|
2994 | $_[0]{current} |
|
|
2995 | } |
|
|
2996 | |
|
|
2997 | sub size_request { |
|
|
2998 | my ($self) = @_; |
|
|
2999 | |
|
|
3000 | $self->{current}->size_request |
|
|
3001 | } |
|
|
3002 | |
|
|
3003 | sub size_allocate { |
|
|
3004 | my ($self, $w, $h) = @_; |
|
|
3005 | |
|
|
3006 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3007 | } |
|
|
3008 | |
|
|
3009 | sub _draw { |
|
|
3010 | my ($self) = @_; |
|
|
3011 | |
|
|
3012 | $self->{current}->draw; |
|
|
3013 | } |
|
|
3014 | |
|
|
3015 | ############################################################################# |
|
|
3016 | |
|
|
3017 | package CFClient::UI::Notebook; |
|
|
3018 | |
|
|
3019 | our @ISA = CFClient::UI::VBox::; |
|
|
3020 | |
|
|
3021 | sub 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 | |
|
|
3035 | sub 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 | |
|
|
3049 | sub set_current_page { |
|
|
3050 | my ($self, $page) = @_; |
|
|
3051 | |
|
|
3052 | $self->{multiplexer}->set_current_page ($page); |
|
|
3053 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
2875 | } |
3054 | } |
2876 | |
3055 | |
2877 | ############################################################################# |
3056 | ############################################################################# |
2878 | |
3057 | |
2879 | package CFClient::UI::Statusbox; |
3058 | package CFClient::UI::Statusbox; |
… | |
… | |
3126 | $rec = $::CONN->stop_record if $::CONN; |
3305 | $rec = $::CONN->stop_record if $::CONN; |
3127 | return unless ref $rec eq 'ARRAY'; |
3306 | return unless ref $rec eq 'ARRAY'; |
3128 | $self->set_command_list ($rec); |
3307 | $self->set_command_list ($rec); |
3129 | } |
3308 | } |
3130 | |
3309 | |
3131 | # if $commit is true, the binding will be set after the user entered a key combo |
3310 | |
|
|
3311 | sub ask_for_bind_and_commit { |
|
|
3312 | my ($self) = @_; |
|
|
3313 | $self->ask_for_bind (1); |
|
|
3314 | } |
|
|
3315 | |
3132 | sub ask_for_bind { |
3316 | sub ask_for_bind { |
3133 | my ($self, $commit) = @_; |
3317 | my ($self, $commit) = @_; |
3134 | |
3318 | |
3135 | CFClient::Binder::open_binding_dialog (sub { |
3319 | CFClient::Binder::open_binding_dialog (sub { |
3136 | my ($mod, $sym) = @_; |
3320 | my ($mod, $sym) = @_; |
… | |
… | |
3220 | |
3404 | |
3221 | ############################################################################# |
3405 | ############################################################################# |
3222 | |
3406 | |
3223 | package CFClient::UI::SpellList; |
3407 | package CFClient::UI::SpellList; |
3224 | |
3408 | |
3225 | our @ISA = CFClient::UI::FancyFrame::; |
3409 | our @ISA = CFClient::UI::ScrolledWindow::; |
3226 | |
3410 | |
3227 | sub new { |
3411 | sub new { |
3228 | my $class = shift; |
3412 | my $class = shift; |
3229 | |
3413 | |
3230 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3414 | my $self = $class->SUPER::new ( |
3231 | |
3415 | binding => [], |
3232 | $self->add (new CFClient::UI::ScrolledWindow |
3416 | commands => [], |
3233 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3417 | scrolled => (new CFClient::UI::Table), |
3234 | |
3418 | @_, |
3235 | $self; |
3419 | ) |
3236 | } |
3420 | } |
3237 | |
3421 | |
3238 | # XXX: Do sorting? Argl... |
3422 | # XXX: Do sorting? Argl... |
3239 | sub add_spell { |
3423 | sub add_spell { |
3240 | my ($self, $spell) = @_; |
3424 | my ($self, $spell) = @_; |
3241 | $self->{spells}->{$spell->{name}} = $spell; |
3425 | $self->{spells}->{$spell->{name}} = $spell; |
3242 | |
3426 | |
3243 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3427 | $self->{scrolled}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3244 | face => $spell->{face}, |
3428 | face => $spell->{face}, |
3245 | can_hover => 1, |
3429 | can_hover => 1, |
3246 | can_events => 1, |
3430 | can_events => 1, |
3247 | tooltip => $spell->{message}); |
3431 | tooltip => $spell->{message}); |
3248 | |
3432 | |
3249 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3433 | $self->{scrolled}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3250 | text => $spell->{name}, |
3434 | text => $spell->{name}, |
3251 | can_hover => 1, |
3435 | can_hover => 1, |
3252 | can_events => 1, |
3436 | can_events => 1, |
3253 | tooltip => $spell->{message}, |
3437 | tooltip => $spell->{message}, |
3254 | expand => 1); |
3438 | expand => 1); |
3255 | |
3439 | |
3256 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3440 | $self->{scrolled}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3257 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3441 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3258 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3442 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3259 | expand => 1); |
3443 | expand => 1); |
3260 | |
3444 | |
3261 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3445 | $self->{scrolled}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3262 | text => "bind to key", |
3446 | text => "bind to key", |
3263 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3447 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3264 | } |
3448 | } |
3265 | |
3449 | |
3266 | sub rebuild_spell_list { |
3450 | sub rebuild_spell_list { |