… | |
… | |
272 | |
272 | |
273 | return unless $self->{visible}; |
273 | return unless $self->{visible}; |
274 | |
274 | |
275 | $_->set_invisible for $self->children; |
275 | $_->set_invisible for $self->children; |
276 | |
276 | |
|
|
277 | delete $self->{visible}; |
277 | delete $self->{root}; |
278 | delete $self->{root}; |
278 | delete $self->{visible}; |
|
|
279 | |
279 | |
280 | undef $GRAB if $GRAB == $self; |
280 | undef $GRAB if $GRAB == $self; |
281 | undef $HOVER if $HOVER == $self; |
281 | undef $HOVER if $HOVER == $self; |
282 | |
282 | |
283 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
283 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
… | |
… | |
315 | } |
315 | } |
316 | |
316 | |
317 | sub move_abs { |
317 | sub move_abs { |
318 | my ($self, $x, $y, $z) = @_; |
318 | my ($self, $x, $y, $z) = @_; |
319 | |
319 | |
320 | $self->{x} = List::Util::max 0, int $x; |
320 | $self->{x} = List::Util::max 0, List::Util::min $self->{root}{w} - $self->{w}, int $x; |
321 | $self->{y} = List::Util::max 0, int $y; |
321 | $self->{y} = List::Util::max 0, List::Util::min $self->{root}{h} - $self->{h}, int $y; |
322 | $self->{z} = $z if defined $z; |
322 | $self->{z} = $z if defined $z; |
323 | |
323 | |
324 | $self->update; |
324 | $self->update; |
325 | } |
325 | } |
326 | |
326 | |
… | |
… | |
593 | |
593 | |
594 | sub DESTROY { |
594 | sub DESTROY { |
595 | my ($self) = @_; |
595 | my ($self) = @_; |
596 | |
596 | |
597 | delete $WIDGET{$self+0}; |
597 | delete $WIDGET{$self+0}; |
598 | #$self->deactivate; |
598 | |
|
|
599 | eval { $self->destroy }; |
|
|
600 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
599 | } |
601 | } |
600 | |
602 | |
601 | ############################################################################# |
603 | ############################################################################# |
602 | |
604 | |
603 | package CFClient::UI::DrawBG; |
605 | package CFClient::UI::DrawBG; |
… | |
… | |
768 | } |
770 | } |
769 | |
771 | |
770 | sub add { |
772 | sub add { |
771 | my ($self, $child) = @_; |
773 | my ($self, $child) = @_; |
772 | |
774 | |
773 | $self->{children} = []; |
775 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
774 | |
|
|
775 | $self->SUPER::add ($child); |
776 | $self->SUPER::add ($child); |
776 | } |
777 | } |
777 | |
778 | |
778 | sub remove { |
779 | sub remove { |
779 | my ($self, $widget) = @_; |
780 | my ($self, $widget) = @_; |
… | |
… | |
1071 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1072 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1072 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1073 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1073 | |
1074 | |
1074 | sub new { |
1075 | sub new { |
1075 | my ($class, %arg) = @_; |
1076 | my ($class, %arg) = @_; |
1076 | |
|
|
1077 | my $title = delete $arg{title}; |
|
|
1078 | |
1077 | |
1079 | my $self = $class->SUPER::new ( |
1078 | my $self = $class->SUPER::new ( |
1080 | bg => [1, 1, 1, 1], |
1079 | bg => [1, 1, 1, 1], |
1081 | border_bg => [1, 1, 1, 1], |
1080 | border_bg => [1, 1, 1, 1], |
1082 | border => 0.6, |
1081 | border => 0.6, |
… | |
… | |
1084 | min_w => 16, |
1083 | min_w => 16, |
1085 | min_h => 16, |
1084 | min_h => 16, |
1086 | %arg, |
1085 | %arg, |
1087 | ); |
1086 | ); |
1088 | |
1087 | |
1089 | $self->{title} = new CFClient::UI::Label |
1088 | $self->{title_widget} = new CFClient::UI::Label |
1090 | align => 0, |
1089 | align => 0, |
1091 | valign => 1, |
1090 | valign => 1, |
1092 | text => $title, |
1091 | text => $self->{title}, |
1093 | fontsize => $self->{border} |
1092 | fontsize => $self->{border}, |
1094 | if defined $title; |
1093 | if exists $self->{title}; |
|
|
1094 | |
|
|
1095 | unless ($self->{no_close_button}) { |
|
|
1096 | $self->{close_btn} = |
|
|
1097 | new CFClient::UI::ImageButton |
|
|
1098 | image => 'x1_close.png', |
|
|
1099 | on_activate => sub { $self->hide }; |
|
|
1100 | |
|
|
1101 | $self->CFClient::UI::Container::add ($self->{close_btn}); |
|
|
1102 | } |
1095 | |
1103 | |
1096 | $self |
1104 | $self |
1097 | } |
1105 | } |
1098 | |
1106 | |
1099 | sub add { |
1107 | sub add { |
1100 | my ($self, @widgets) = @_; |
1108 | my ($self, @widgets) = @_; |
1101 | |
1109 | |
1102 | $self->SUPER::add (@widgets); |
1110 | $self->SUPER::add (@widgets); |
|
|
1111 | $self->CFClient::UI::Container::add ($self->{close_btn}) if $self->{close_btn}; |
1103 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1112 | $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1104 | } |
1113 | } |
1105 | |
1114 | |
1106 | sub border { |
1115 | sub border { |
1107 | int $_[0]{border} * $::FONTSIZE |
1116 | int $_[0]{border} * $::FONTSIZE |
1108 | } |
1117 | } |
1109 | |
1118 | |
1110 | sub size_request { |
1119 | sub size_request { |
1111 | my ($self) = @_; |
1120 | my ($self) = @_; |
1112 | |
1121 | |
1113 | $self->{title}->size_request |
1122 | $self->{title_widget}->size_request |
1114 | if $self->{title}; |
1123 | if $self->{title_widget}; |
|
|
1124 | |
|
|
1125 | $self->{close_btn}->size_request |
|
|
1126 | if $self->{close_btn}; |
1115 | |
1127 | |
1116 | my ($w, $h) = $self->SUPER::size_request; |
1128 | my ($w, $h) = $self->SUPER::size_request; |
1117 | |
1129 | |
1118 | ( |
1130 | ( |
1119 | $w + $self->border * 2, |
1131 | $w + $self->border * 2, |
… | |
… | |
1122 | } |
1134 | } |
1123 | |
1135 | |
1124 | sub size_allocate { |
1136 | sub size_allocate { |
1125 | my ($self, $w, $h) = @_; |
1137 | my ($self, $w, $h) = @_; |
1126 | |
1138 | |
1127 | if ($self->{title}) { |
1139 | if ($self->{title_widget}) { |
1128 | $self->{title}{w} = $w; |
1140 | $self->{title_widget}{w} = $w; |
1129 | $self->{title}{h} = $h; |
1141 | $self->{title_widget}{h} = $h; |
1130 | $self->{title}->size_allocate ($w, $h); |
1142 | $self->{title_widget}->size_allocate ($w, $h); |
1131 | } |
1143 | } |
1132 | |
1144 | |
1133 | my $border = $self->border; |
1145 | my $border = $self->border; |
1134 | |
1146 | |
1135 | $h -= List::Util::max 0, $border * 2; |
1147 | $h -= List::Util::max 0, $border * 2; |
1136 | $w -= List::Util::max 0, $border * 2; |
1148 | $w -= List::Util::max 0, $border * 2; |
1137 | |
1149 | |
1138 | $self->child->configure ($border, $border, $w, $h); |
1150 | $self->child->configure ($border, $border, $w, $h); |
|
|
1151 | |
|
|
1152 | $self->{close_btn}->configure ($self->{w} - (2 * $border), 0, $border, $border) |
|
|
1153 | if $self->{close_btn}; |
1139 | } |
1154 | } |
1140 | |
1155 | |
1141 | sub button_down { |
1156 | sub button_down { |
1142 | my ($self, $ev, $x, $y) = @_; |
1157 | my ($self, $ev, $x, $y) = @_; |
1143 | |
1158 | |
… | |
… | |
1189 | } |
1204 | } |
1190 | |
1205 | |
1191 | sub button_up { |
1206 | sub button_up { |
1192 | my ($self, $ev, $x, $y) = @_; |
1207 | my ($self, $ev, $x, $y) = @_; |
1193 | |
1208 | |
|
|
1209 | $self->{close_btn}->button_up ($ev, $x, $y) |
|
|
1210 | if $self->{close_btn}; |
|
|
1211 | |
1194 | !!delete $self->{motion} |
1212 | !!delete $self->{motion} |
1195 | } |
1213 | } |
1196 | |
1214 | |
1197 | sub mouse_motion { |
1215 | sub mouse_motion { |
1198 | my ($self, $ev, $x, $y) = @_; |
1216 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
1233 | |
1251 | |
1234 | glDisable GL_TEXTURE_2D; |
1252 | glDisable GL_TEXTURE_2D; |
1235 | |
1253 | |
1236 | $child->draw; |
1254 | $child->draw; |
1237 | |
1255 | |
1238 | if ($self->{title}) { |
1256 | if ($self->{title_widget}) { |
1239 | glTranslate 0, $border - $self->{h}; |
1257 | glTranslate 0, $border - $self->{h}; |
1240 | $self->{title}->_draw; |
1258 | $self->{title_widget}->_draw; |
|
|
1259 | |
|
|
1260 | glTranslate 0, - ($border - $self->{h}); |
1241 | } |
1261 | } |
|
|
1262 | |
|
|
1263 | $self->{close_btn}->draw |
|
|
1264 | if $self->{close_btn}; |
1242 | } |
1265 | } |
1243 | |
1266 | |
1244 | ############################################################################# |
1267 | ############################################################################# |
1245 | |
1268 | |
1246 | package CFClient::UI::Table; |
1269 | package CFClient::UI::Table; |
… | |
… | |
1269 | |
1292 | |
1270 | $child->set_parent ($self); |
1293 | $child->set_parent ($self); |
1271 | $self->{children}[$y][$x] = $child; |
1294 | $self->{children}[$y][$x] = $child; |
1272 | |
1295 | |
1273 | $self->realloc; |
1296 | $self->realloc; |
|
|
1297 | } |
|
|
1298 | |
|
|
1299 | sub remove { |
|
|
1300 | my ($self, $child) = @_; |
|
|
1301 | |
|
|
1302 | # TODO: not yet implemented |
1274 | } |
1303 | } |
1275 | |
1304 | |
1276 | # TODO: move to container class maybe? send children a signal on removal? |
1305 | # TODO: move to container class maybe? send children a signal on removal? |
1277 | sub clear { |
1306 | sub clear { |
1278 | my ($self) = @_; |
1307 | my ($self) = @_; |
… | |
… | |
1554 | return if $self->{text} eq "T$text"; |
1583 | return if $self->{text} eq "T$text"; |
1555 | $self->{text} = "T$text"; |
1584 | $self->{text} = "T$text"; |
1556 | |
1585 | |
1557 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1586 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1558 | $self->{layout}->set_text ($text); |
1587 | $self->{layout}->set_text ($text); |
|
|
1588 | |
1559 | delete $self->{req_h}; |
1589 | delete $self->{size_req}; |
1560 | |
|
|
1561 | $self->realloc; |
1590 | $self->realloc; |
1562 | $self->update; |
1591 | $self->update; |
1563 | } |
1592 | } |
1564 | |
1593 | |
1565 | sub set_markup { |
1594 | sub set_markup { |
… | |
… | |
1570 | |
1599 | |
1571 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1600 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1572 | |
1601 | |
1573 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1602 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1574 | $self->{layout}->set_markup ($markup); |
1603 | $self->{layout}->set_markup ($markup); |
|
|
1604 | |
1575 | delete $self->{req_h}; |
1605 | delete $self->{size_req}; |
1576 | |
|
|
1577 | $self->realloc; |
1606 | $self->realloc; |
1578 | $self->update; |
1607 | $self->update; |
1579 | } |
1608 | } |
1580 | |
1609 | |
1581 | sub size_request { |
1610 | sub size_request { |
1582 | my ($self) = @_; |
1611 | my ($self) = @_; |
1583 | |
1612 | |
1584 | if (exists $self->{req_h}) { |
1613 | $self->{size_req} ||= do { |
1585 | @$self{qw(req_w req_h)} |
|
|
1586 | } else { |
|
|
1587 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1614 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1588 | $self->{layout}->set_width ($self->{max_w} || -1); |
1615 | $self->{layout}->set_width ($self->{max_w} || -1); |
1589 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1616 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1590 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1617 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1591 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1618 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
… | |
… | |
1600 | |
1627 | |
1601 | $w = List::Util::max $w, $w2; |
1628 | $w = List::Util::max $w, $w2; |
1602 | $h = List::Util::max $h, $h2; |
1629 | $h = List::Util::max $h, $h2; |
1603 | } |
1630 | } |
1604 | |
1631 | |
1605 | ($w, $h) |
1632 | [$w, $h] |
1606 | } |
1633 | }; |
|
|
1634 | |
|
|
1635 | @{ $self->{size_req} } |
1607 | } |
1636 | } |
1608 | |
1637 | |
1609 | sub size_allocate { |
1638 | sub size_allocate { |
1610 | my ($self, $w, $h) = @_; |
1639 | my ($self, $w, $h) = @_; |
1611 | |
1640 | |
… | |
… | |
1620 | |
1649 | |
1621 | $self->{fontsize} = $fontsize; |
1650 | $self->{fontsize} = $fontsize; |
1622 | delete $self->{texture}; |
1651 | delete $self->{texture}; |
1623 | |
1652 | |
1624 | $self->realloc; |
1653 | $self->realloc; |
|
|
1654 | } |
|
|
1655 | |
|
|
1656 | sub reconfigure { |
|
|
1657 | my ($self) = @_; |
|
|
1658 | |
|
|
1659 | delete $self->{size_req}; |
|
|
1660 | |
|
|
1661 | $self->SUPER::reconfigure; |
1625 | } |
1662 | } |
1626 | |
1663 | |
1627 | sub _draw { |
1664 | sub _draw { |
1628 | my ($self) = @_; |
1665 | my ($self) = @_; |
1629 | |
1666 | |
… | |
… | |
1649 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1686 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1650 | : ($self->{h} - $tex->{h}) * 0.5); |
1687 | : ($self->{h} - $tex->{h}) * 0.5); |
1651 | }; |
1688 | }; |
1652 | |
1689 | |
1653 | glEnable GL_TEXTURE_2D; |
1690 | glEnable GL_TEXTURE_2D; |
1654 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1691 | |
|
|
1692 | my $w = List::Util::min $self->{w} + 4, $tex->{w}; |
|
|
1693 | my $h = List::Util::min $self->{h} + 2, $tex->{h}; |
1655 | |
1694 | |
1656 | if ($tex->{format} == GL_ALPHA) { |
1695 | if ($tex->{format} == GL_ALPHA) { |
|
|
1696 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1657 | glColor @{$self->{fg}}; |
1697 | glColor @{$self->{fg}}; |
1658 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1698 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h); |
1659 | } else { |
1699 | } else { |
|
|
1700 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1660 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1701 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h); |
1661 | } |
1702 | } |
1662 | |
1703 | |
1663 | glDisable GL_TEXTURE_2D; |
1704 | glDisable GL_TEXTURE_2D; |
1664 | } |
1705 | } |
1665 | |
1706 | |
… | |
… | |
1682 | can_hover => 1, |
1723 | can_hover => 1, |
1683 | can_focus => 1, |
1724 | can_focus => 1, |
1684 | valign => 0, |
1725 | valign => 0, |
1685 | can_events => 1, |
1726 | can_events => 1, |
1686 | #text => ... |
1727 | #text => ... |
|
|
1728 | #hidden => "*", |
1687 | @_ |
1729 | @_ |
1688 | ) |
1730 | ) |
1689 | } |
1731 | } |
1690 | |
1732 | |
1691 | sub _set_text { |
1733 | sub _set_text { |
… | |
… | |
1698 | $self->{last_activity} = $::NOW; |
1740 | $self->{last_activity} = $::NOW; |
1699 | $self->{text} = $text; |
1741 | $self->{text} = $text; |
1700 | |
1742 | |
1701 | $text =~ s/./*/g if $self->{hidden}; |
1743 | $text =~ s/./*/g if $self->{hidden}; |
1702 | $self->{layout}->set_text ("$text "); |
1744 | $self->{layout}->set_text ("$text "); |
1703 | delete $self->{req_h}; |
1745 | delete $self->{size_req}; |
1704 | |
1746 | |
1705 | $self->_emit (changed => $self->{text}); |
1747 | $self->_emit (changed => $self->{text}); |
1706 | |
1748 | |
1707 | $self->realloc; |
1749 | $self->realloc; |
1708 | $self->update; |
1750 | $self->update; |
… | |
… | |
1942 | $self->SUPER::_draw; |
1984 | $self->SUPER::_draw; |
1943 | } |
1985 | } |
1944 | |
1986 | |
1945 | ############################################################################# |
1987 | ############################################################################# |
1946 | |
1988 | |
|
|
1989 | package CFClient::UI::ImageButton; |
|
|
1990 | |
|
|
1991 | our @ISA = CFClient::UI::Image::; |
|
|
1992 | |
|
|
1993 | use CFClient::OpenGL; |
|
|
1994 | |
|
|
1995 | my %textures; |
|
|
1996 | |
|
|
1997 | sub new { |
|
|
1998 | my $class = shift; |
|
|
1999 | |
|
|
2000 | my $self = $class->SUPER::new ( |
|
|
2001 | padding_x => 4, |
|
|
2002 | padding_y => 4, |
|
|
2003 | fg => [1, 1, 1], |
|
|
2004 | active_fg => [0, 0, 1], |
|
|
2005 | can_hover => 1, |
|
|
2006 | align => 0, |
|
|
2007 | valign => 0, |
|
|
2008 | can_events => 1, |
|
|
2009 | @_ |
|
|
2010 | ); |
|
|
2011 | } |
|
|
2012 | |
|
|
2013 | sub activate { } |
|
|
2014 | |
|
|
2015 | sub button_up { |
|
|
2016 | my ($self, $ev, $x, $y) = @_; |
|
|
2017 | |
|
|
2018 | $self->emit ("activate") |
|
|
2019 | if $x >= 0 && $x < $self->{w} |
|
|
2020 | && $y >= 0 && $y < $self->{h}; |
|
|
2021 | |
|
|
2022 | 1 |
|
|
2023 | } |
|
|
2024 | |
|
|
2025 | ############################################################################# |
|
|
2026 | |
1947 | package CFClient::UI::CheckBox; |
2027 | package CFClient::UI::CheckBox; |
1948 | |
2028 | |
1949 | our @ISA = CFClient::UI::DrawBG::; |
2029 | our @ISA = CFClient::UI::DrawBG::; |
1950 | |
2030 | |
1951 | my @tex = |
2031 | my @tex = |
… | |
… | |
2294 | sub set_range { |
2374 | sub set_range { |
2295 | my ($self, $range) = @_; |
2375 | my ($self, $range) = @_; |
2296 | |
2376 | |
2297 | ($range, $self->{range}) = ($self->{range}, $range); |
2377 | ($range, $self->{range}) = ($self->{range}, $range); |
2298 | |
2378 | |
2299 | $self->update |
|
|
2300 | if "@$range" ne "@{$self->{range}}"; |
2379 | if ("@$range" ne "@{$self->{range}}") { |
|
|
2380 | $self->update; |
|
|
2381 | $self->set_value ($self->{range}[0]); |
|
|
2382 | } |
2301 | } |
2383 | } |
2302 | |
2384 | |
2303 | sub set_value { |
2385 | sub set_value { |
2304 | my ($self, $value) = @_; |
2386 | my ($self, $value) = @_; |
2305 | |
2387 | |
… | |
… | |
2452 | sub set_range { shift->{slider}->set_range (@_) } |
2534 | sub set_range { shift->{slider}->set_range (@_) } |
2453 | sub set_value { shift->{slider}->set_value (@_) } |
2535 | sub set_value { shift->{slider}->set_value (@_) } |
2454 | |
2536 | |
2455 | ############################################################################# |
2537 | ############################################################################# |
2456 | |
2538 | |
2457 | package CFClient::UI::TextView; |
2539 | package CFClient::UI::TextScroller; |
2458 | |
2540 | |
2459 | our @ISA = CFClient::UI::HBox::; |
2541 | our @ISA = CFClient::UI::HBox::; |
2460 | |
2542 | |
2461 | use CFClient::OpenGL; |
2543 | use CFClient::OpenGL; |
2462 | |
2544 | |
… | |
… | |
2464 | my $class = shift; |
2546 | my $class = shift; |
2465 | |
2547 | |
2466 | my $self = $class->SUPER::new ( |
2548 | my $self = $class->SUPER::new ( |
2467 | fontsize => 1, |
2549 | fontsize => 1, |
2468 | can_events => 0, |
2550 | can_events => 0, |
|
|
2551 | indent => 0, |
2469 | #font => default_font |
2552 | #font => default_font |
2470 | @_, |
2553 | @_, |
2471 | |
2554 | |
2472 | layout => (new CFClient::Layout 1), |
2555 | layout => (new CFClient::Layout 1), |
2473 | par => [], |
2556 | par => [], |
… | |
… | |
2496 | $self->SUPER::size_allocate ($w, $h); |
2579 | $self->SUPER::size_allocate ($w, $h); |
2497 | |
2580 | |
2498 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2581 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2499 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2582 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2500 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2583 | $self->{layout}->set_width ($self->{children}[0]{w}); |
|
|
2584 | $self->{layout}->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2501 | |
2585 | |
2502 | $self->reflow; |
2586 | $self->reflow; |
2503 | } |
2587 | } |
2504 | |
2588 | |
2505 | sub text_size { |
2589 | sub text_size { |
… | |
… | |
2507 | |
2591 | |
2508 | my $layout = $self->{layout}; |
2592 | my $layout = $self->{layout}; |
2509 | |
2593 | |
2510 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2594 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2511 | $layout->set_width ($self->{children}[0]{w} - $indent); |
2595 | $layout->set_width ($self->{children}[0]{w} - $indent); |
|
|
2596 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2512 | $layout->set_markup ($text); |
2597 | $layout->set_markup ($text); |
2513 | |
2598 | |
2514 | $layout->size |
2599 | $layout->size |
2515 | } |
2600 | } |
2516 | |
2601 | |
… | |
… | |
2555 | |
2640 | |
2556 | return unless $self->{h} > 0; |
2641 | return unless $self->{h} > 0; |
2557 | |
2642 | |
2558 | delete $self->{texture}; |
2643 | delete $self->{texture}; |
2559 | |
2644 | |
2560 | $ROOT->on_post_alloc ($self, sub { |
2645 | $ROOT->on_post_alloc ($self => sub { |
2561 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2646 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2562 | |
2647 | |
2563 | if (delete $self->{need_reflow}) { |
2648 | if (delete $self->{need_reflow}) { |
2564 | my $height = 0; |
2649 | my $height = 0; |
2565 | |
2650 | |
… | |
… | |
2568 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2653 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2569 | |
2654 | |
2570 | for (@{$self->{par}}) { |
2655 | for (@{$self->{par}}) { |
2571 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
2656 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
2572 | $layout->set_width ($W - $_->[3]); |
2657 | $layout->set_width ($W - $_->[3]); |
|
|
2658 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2573 | $layout->set_markup ($_->[4]); |
2659 | $layout->set_markup ($_->[4]); |
2574 | my ($w, $h) = $layout->size; |
2660 | my ($w, $h) = $layout->size; |
2575 | $_->[0] = $w + $_->[3]; |
2661 | $_->[0] = $w + $_->[3]; |
2576 | $_->[1] = $h; |
2662 | $_->[1] = $h; |
2577 | } |
2663 | } |
… | |
… | |
2580 | } |
2666 | } |
2581 | |
2667 | |
2582 | $self->{height} = $height; |
2668 | $self->{height} = $height; |
2583 | |
2669 | |
2584 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2670 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2585 | |
2671 | |
2586 | delete $self->{texture}; |
2672 | delete $self->{texture}; |
2587 | } |
2673 | } |
2588 | |
2674 | |
2589 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2675 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2590 | glClearColor 0, 0, 0, 0; |
2676 | glClearColor 0, 0, 0, 0; |
… | |
… | |
2609 | my $h = $par->[1]; |
2695 | my $h = $par->[1]; |
2610 | |
2696 | |
2611 | if ($y0 < $y + $h && $y < $y1) { |
2697 | if ($y0 < $y + $h && $y < $y1) { |
2612 | $layout->set_foreground (@{ $par->[2] }); |
2698 | $layout->set_foreground (@{ $par->[2] }); |
2613 | $layout->set_width ($W - $par->[3]); |
2699 | $layout->set_width ($W - $par->[3]); |
|
|
2700 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2614 | $layout->set_markup ($par->[4]); |
2701 | $layout->set_markup ($par->[4]); |
2615 | |
2702 | |
2616 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2703 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2617 | |
2704 | |
2618 | glRasterPos $par->[3], $y - $y0; |
2705 | glRasterPos $par->[3], $y - $y0; |
… | |
… | |
2732 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2819 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2733 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2820 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2734 | . "req $widget->{req_w} $widget->{req_h}\n" |
2821 | . "req $widget->{req_w} $widget->{req_h}\n" |
2735 | . "visible $widget->{visible}"; |
2822 | . "visible $widget->{visible}"; |
2736 | } |
2823 | } |
|
|
2824 | |
|
|
2825 | $tooltip =~ s/^\n+//; |
|
|
2826 | $tooltip =~ s/\n+$//; |
2737 | |
2827 | |
2738 | $self->add (new CFClient::UI::Label |
2828 | $self->add (new CFClient::UI::Label |
2739 | markup => $tooltip, |
2829 | markup => $tooltip, |
2740 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2830 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2741 | fontsize => 0.8, |
2831 | fontsize => 0.8, |
… | |
… | |
2769 | or return; |
2859 | or return; |
2770 | |
2860 | |
2771 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2861 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2772 | |
2862 | |
2773 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2863 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2774 | if $x + $self->{w} > $::WIDTH; |
2864 | if $x + $self->{w} > $self->{root}{w}; |
2775 | |
2865 | |
2776 | $self->move_abs ($x, $y); |
2866 | $self->move_abs ($x, $y); |
2777 | }); |
2867 | }); |
2778 | } |
2868 | } |
2779 | |
2869 | |
… | |
… | |
2874 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2964 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2875 | glDisable GL_TEXTURE_2D; |
2965 | glDisable GL_TEXTURE_2D; |
2876 | } |
2966 | } |
2877 | } |
2967 | } |
2878 | |
2968 | |
2879 | sub DESTROY { |
2969 | sub destroy { |
2880 | my ($self) = @_; |
2970 | my ($self) = @_; |
2881 | |
2971 | |
2882 | $self->{timer}->cancel |
2972 | $self->{timer}->cancel |
2883 | if $self->{timer}; |
2973 | if $self->{timer}; |
2884 | |
2974 | |
2885 | $self->SUPER::DESTROY; |
2975 | $self->SUPER::destroy; |
2886 | } |
2976 | } |
2887 | |
2977 | |
2888 | ############################################################################# |
2978 | ############################################################################# |
2889 | |
2979 | |
2890 | package CFClient::UI::Buttonbar; |
2980 | package CFClient::UI::Buttonbar; |
… | |
… | |
2911 | ); |
3001 | ); |
2912 | |
3002 | |
2913 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
3003 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
2914 | |
3004 | |
2915 | for my $item (@{ $self->{items} }) { |
3005 | for my $item (@{ $self->{items} }) { |
2916 | my ($widget, $cb) = @$item; |
3006 | my ($widget, $cb, $tooltip) = @$item; |
2917 | |
3007 | |
2918 | # handle various types of items, only text for now |
3008 | # handle various types of items, only text for now |
2919 | if (!ref $widget) { |
3009 | if (!ref $widget) { |
2920 | $widget = new CFClient::UI::Label |
3010 | $widget = new CFClient::UI::Label |
2921 | can_hover => 1, |
3011 | can_hover => 1, |
2922 | can_events => 1, |
3012 | can_events => 1, |
2923 | text => $widget; |
3013 | markup => $widget, |
|
|
3014 | tooltip => $tooltip |
2924 | } |
3015 | } |
2925 | |
3016 | |
2926 | $self->{item}{$widget} = $item; |
3017 | $self->{item}{$widget} = $item; |
2927 | |
3018 | |
2928 | $self->{vbox}->add ($widget); |
3019 | $self->{vbox}->add ($widget); |
… | |
… | |
3075 | sub set_current_page { |
3166 | sub set_current_page { |
3076 | my ($self, $page) = @_; |
3167 | my ($self, $page) = @_; |
3077 | |
3168 | |
3078 | $self->{multiplexer}->set_current_page ($page); |
3169 | $self->{multiplexer}->set_current_page ($page); |
3079 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
3170 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
|
|
3171 | } |
|
|
3172 | |
|
|
3173 | ############################################################################# |
|
|
3174 | |
|
|
3175 | package CFClient::UI::Combobox; |
|
|
3176 | |
|
|
3177 | use utf8; |
|
|
3178 | |
|
|
3179 | our @ISA = CFClient::UI::Button::; |
|
|
3180 | |
|
|
3181 | sub new { |
|
|
3182 | my $class = shift; |
|
|
3183 | |
|
|
3184 | my $self = $class->SUPER::new ( |
|
|
3185 | options => [], # [value, title, longdesc], ... |
|
|
3186 | value => undef, |
|
|
3187 | @_, |
|
|
3188 | ); |
|
|
3189 | |
|
|
3190 | $self->_set_value ($self->{value}); |
|
|
3191 | |
|
|
3192 | $self |
|
|
3193 | } |
|
|
3194 | |
|
|
3195 | sub button_down { |
|
|
3196 | my ($self, $ev) = @_; |
|
|
3197 | |
|
|
3198 | my @menu_items; |
|
|
3199 | |
|
|
3200 | for (@{ $self->{options} }) { |
|
|
3201 | my ($value, $title, $tooltip) = @$_; |
|
|
3202 | |
|
|
3203 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
|
|
3204 | } |
|
|
3205 | |
|
|
3206 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
|
|
3207 | } |
|
|
3208 | |
|
|
3209 | sub _set_value { |
|
|
3210 | my ($self, $value) = @_; |
|
|
3211 | |
|
|
3212 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
|
|
3213 | or return; |
|
|
3214 | |
|
|
3215 | $self->{value} = $item->[0]; |
|
|
3216 | $self->set_markup ("$item->[1] ⇓"); |
|
|
3217 | $self->set_tooltip ($item->[2]); |
|
|
3218 | } |
|
|
3219 | |
|
|
3220 | sub set_value { |
|
|
3221 | my ($self, $value) = @_; |
|
|
3222 | |
|
|
3223 | return unless $self->{value} ne $value; |
|
|
3224 | |
|
|
3225 | $self->_set_value ($value); |
|
|
3226 | $self->_emit (changed => $value); |
3080 | } |
3227 | } |
3081 | |
3228 | |
3082 | ############################################################################# |
3229 | ############################################################################# |
3083 | |
3230 | |
3084 | package CFClient::UI::Statusbox; |
3231 | package CFClient::UI::Statusbox; |
… | |
… | |
3183 | $item->{count}++; |
3330 | $item->{count}++; |
3184 | } else { |
3331 | } else { |
3185 | $item->{count} = 1; |
3332 | $item->{count} = 1; |
3186 | $item->{text} = $item->{tooltip} = $text; |
3333 | $item->{text} = $item->{tooltip} = $text; |
3187 | } |
3334 | } |
3188 | $item->{id} = ++$self->{id}; |
3335 | $item->{id} += 0.2;#d# |
3189 | $item->{timeout} = $timeout; |
3336 | $item->{timeout} = $timeout; |
3190 | delete $item->{label}; |
3337 | delete $item->{label}; |
3191 | } else { |
3338 | } else { |
3192 | $self->{item}{$group} = { |
3339 | $self->{item}{$group} = { |
3193 | id => ++$self->{id}, |
3340 | id => ++$self->{id}, |
… | |
… | |
3212 | |
3359 | |
3213 | $self->reorder; |
3360 | $self->reorder; |
3214 | $self->SUPER::reconfigure; |
3361 | $self->SUPER::reconfigure; |
3215 | } |
3362 | } |
3216 | |
3363 | |
3217 | sub DESTROY { |
3364 | sub destroy { |
3218 | my ($self) = @_; |
3365 | my ($self) = @_; |
3219 | |
3366 | |
3220 | $self->{timer}->cancel; |
3367 | $self->{timer}->cancel; |
3221 | |
3368 | |
3222 | $self->SUPER::DESTROY; |
3369 | $self->SUPER::destroy; |
3223 | } |
3370 | } |
3224 | |
3371 | |
3225 | ############################################################################# |
3372 | ############################################################################# |
3226 | |
3373 | |
3227 | package CFClient::UI::Inventory; |
3374 | package CFClient::UI::Inventory; |
… | |
… | |
3475 | commands => [], |
3622 | commands => [], |
3476 | @_, |
3623 | @_, |
3477 | ) |
3624 | ) |
3478 | } |
3625 | } |
3479 | |
3626 | |
3480 | # XXX: Do sorting? Argl... |
3627 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3628 | |
|
|
3629 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3630 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3631 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3632 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3633 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3634 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3635 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3636 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
|
|
3637 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3638 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
|
|
3639 | |
|
|
3640 | sub rebuild_spell_list { |
|
|
3641 | my ($self) = @_; |
|
|
3642 | |
|
|
3643 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
|
|
3644 | $self->clear; |
|
|
3645 | |
|
|
3646 | return unless $::CONN; |
|
|
3647 | |
|
|
3648 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3649 | $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL); |
|
|
3650 | $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
|
|
3651 | $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
|
|
3652 | $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
|
|
3653 | |
|
|
3654 | my $row = 0; |
|
|
3655 | |
|
|
3656 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
|
|
3657 | my $spell = $self->{spell}{$_}; |
|
|
3658 | |
|
|
3659 | $row++; |
|
|
3660 | |
|
|
3661 | my $spell_cb = sub { |
|
|
3662 | my ($widget, $ev) = @_; |
|
|
3663 | |
|
|
3664 | if ($ev->{button} == 1) { |
|
|
3665 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3666 | } elsif ($ev->{button} == 2) { |
|
|
3667 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3668 | } elsif ($ev->{button} == 3) { |
|
|
3669 | (new CFClient::UI::Menu |
|
|
3670 | items => [ |
|
|
3671 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3672 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3673 | ], |
|
|
3674 | )->popup ($ev); |
|
|
3675 | } else { |
|
|
3676 | return 0; |
|
|
3677 | } |
|
|
3678 | |
|
|
3679 | 1 |
|
|
3680 | }; |
|
|
3681 | |
|
|
3682 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3683 | |
|
|
3684 | #TODO: add path info to tooltip |
|
|
3685 | #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); |
|
|
3686 | |
|
|
3687 | $self->add (0, $row, new CFClient::UI::Face |
|
|
3688 | face => $spell->{face}, |
|
|
3689 | can_hover => 1, |
|
|
3690 | can_events => 1, |
|
|
3691 | tooltip => $tooltip, |
|
|
3692 | on_button_down => $spell_cb, |
|
|
3693 | ); |
|
|
3694 | |
|
|
3695 | $self->add (1, $row, new CFClient::UI::Label |
|
|
3696 | expand => 1, |
|
|
3697 | text => $spell->{name}, |
|
|
3698 | can_hover => 1, |
|
|
3699 | can_events => 1, |
|
|
3700 | tooltip => $tooltip, |
|
|
3701 | on_button_down => $spell_cb, |
|
|
3702 | ); |
|
|
3703 | |
|
|
3704 | $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
|
|
3705 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
|
|
3706 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
|
|
3707 | $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
|
|
3708 | } |
|
|
3709 | }); |
|
|
3710 | } |
|
|
3711 | |
3481 | sub add_spell { |
3712 | sub add_spell { |
3482 | my ($self, $spell) = @_; |
3713 | my ($self, $spell) = @_; |
|
|
3714 | |
3483 | $self->{spells}->{$spell->{name}} = $spell; |
3715 | $self->{spell}->{$spell->{name}} = $spell; |
3484 | |
3716 | $self->rebuild_spell_list; |
3485 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
|
|
3486 | face => $spell->{face}, |
|
|
3487 | can_hover => 1, |
|
|
3488 | can_events => 1, |
|
|
3489 | tooltip => $spell->{message}); |
|
|
3490 | |
|
|
3491 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3492 | text => $spell->{name}, |
|
|
3493 | can_hover => 1, |
|
|
3494 | can_events => 1, |
|
|
3495 | tooltip => $spell->{message}, |
|
|
3496 | expand => 1); |
|
|
3497 | |
|
|
3498 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3499 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
|
|
3500 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
|
|
3501 | expand => 1); |
|
|
3502 | |
|
|
3503 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
|
|
3504 | text => "bind to key", |
|
|
3505 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
|
|
3506 | } |
|
|
3507 | |
|
|
3508 | sub rebuild_spell_list { |
|
|
3509 | my ($self) = @_; |
|
|
3510 | $self->{tbl_idx} = 0; |
|
|
3511 | $self->add_spell ($_) for values %{$self->{spells}}; |
|
|
3512 | } |
3717 | } |
3513 | |
3718 | |
3514 | sub remove_spell { |
3719 | sub remove_spell { |
3515 | my ($self, $spell) = @_; |
3720 | my ($self, $spell) = @_; |
|
|
3721 | |
3516 | delete $self->{spells}->{$spell->{name}}; |
3722 | delete $self->{spell}->{$spell->{name}}; |
|
|
3723 | $self->rebuild_spell_list; |
|
|
3724 | } |
|
|
3725 | |
|
|
3726 | sub clear_spells { |
|
|
3727 | my ($self) = @_; |
|
|
3728 | |
|
|
3729 | $self->{spell} = {}; |
3517 | $self->rebuild_spell_list; |
3730 | $self->rebuild_spell_list; |
3518 | } |
3731 | } |
3519 | |
3732 | |
3520 | ############################################################################# |
3733 | ############################################################################# |
3521 | |
3734 | |