… | |
… | |
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 | |
… | |
… | |
525 | if $self->{parent}; |
525 | if $self->{parent}; |
526 | } |
526 | } |
527 | |
527 | |
528 | sub reconfigure { |
528 | sub reconfigure { |
529 | my ($self) = @_; |
529 | my ($self) = @_; |
530 | |
|
|
531 | # some widgets cache req_w and req_h |
|
|
532 | delete $self->{req_w}; |
|
|
533 | delete $self->{req_h}; |
|
|
534 | |
530 | |
535 | $self->realloc; |
531 | $self->realloc; |
536 | $self->update; |
532 | $self->update; |
537 | } |
533 | } |
538 | |
534 | |
… | |
… | |
597 | |
593 | |
598 | sub DESTROY { |
594 | sub DESTROY { |
599 | my ($self) = @_; |
595 | my ($self) = @_; |
600 | |
596 | |
601 | delete $WIDGET{$self+0}; |
597 | delete $WIDGET{$self+0}; |
602 | #$self->deactivate; |
598 | |
|
|
599 | eval { $self->destroy }; |
|
|
600 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
603 | } |
601 | } |
604 | |
602 | |
605 | ############################################################################# |
603 | ############################################################################# |
606 | |
604 | |
607 | package CFClient::UI::DrawBG; |
605 | package CFClient::UI::DrawBG; |
… | |
… | |
772 | } |
770 | } |
773 | |
771 | |
774 | sub add { |
772 | sub add { |
775 | my ($self, $child) = @_; |
773 | my ($self, $child) = @_; |
776 | |
774 | |
777 | $self->{children} = []; |
775 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
778 | |
|
|
779 | $self->SUPER::add ($child); |
776 | $self->SUPER::add ($child); |
780 | } |
777 | } |
781 | |
778 | |
782 | sub remove { |
779 | sub remove { |
783 | my ($self, $widget) = @_; |
780 | my ($self, $widget) = @_; |
… | |
… | |
1075 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1072 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1076 | 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); |
1077 | |
1074 | |
1078 | sub new { |
1075 | sub new { |
1079 | my ($class, %arg) = @_; |
1076 | my ($class, %arg) = @_; |
1080 | |
|
|
1081 | my $title = delete $arg{title}; |
|
|
1082 | |
1077 | |
1083 | my $self = $class->SUPER::new ( |
1078 | my $self = $class->SUPER::new ( |
1084 | bg => [1, 1, 1, 1], |
1079 | bg => [1, 1, 1, 1], |
1085 | border_bg => [1, 1, 1, 1], |
1080 | border_bg => [1, 1, 1, 1], |
1086 | border => 0.6, |
1081 | border => 0.6, |
… | |
… | |
1088 | min_w => 16, |
1083 | min_w => 16, |
1089 | min_h => 16, |
1084 | min_h => 16, |
1090 | %arg, |
1085 | %arg, |
1091 | ); |
1086 | ); |
1092 | |
1087 | |
1093 | $self->{title} = new CFClient::UI::Label |
1088 | $self->{title_widget} = new CFClient::UI::Label |
1094 | align => 0, |
1089 | align => 0, |
1095 | valign => 1, |
1090 | valign => 1, |
1096 | text => $title, |
1091 | text => $self->{title}, |
1097 | fontsize => $self->{border} |
1092 | fontsize => $self->{border}, |
1098 | 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 | } |
1099 | |
1103 | |
1100 | $self |
1104 | $self |
1101 | } |
1105 | } |
1102 | |
1106 | |
1103 | sub add { |
1107 | sub add { |
1104 | my ($self, @widgets) = @_; |
1108 | my ($self, @widgets) = @_; |
1105 | |
1109 | |
1106 | $self->SUPER::add (@widgets); |
1110 | $self->SUPER::add (@widgets); |
|
|
1111 | $self->CFClient::UI::Container::add ($self->{close_btn}) if $self->{close_btn}; |
1107 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1112 | $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1108 | } |
1113 | } |
1109 | |
1114 | |
1110 | sub border { |
1115 | sub border { |
1111 | int $_[0]{border} * $::FONTSIZE |
1116 | int $_[0]{border} * $::FONTSIZE |
1112 | } |
1117 | } |
1113 | |
1118 | |
1114 | sub size_request { |
1119 | sub size_request { |
1115 | my ($self) = @_; |
1120 | my ($self) = @_; |
1116 | |
1121 | |
1117 | $self->{title}->size_request |
1122 | $self->{title_widget}->size_request |
1118 | if $self->{title}; |
1123 | if $self->{title_widget}; |
|
|
1124 | |
|
|
1125 | $self->{close_btn}->size_request |
|
|
1126 | if $self->{close_btn}; |
1119 | |
1127 | |
1120 | my ($w, $h) = $self->SUPER::size_request; |
1128 | my ($w, $h) = $self->SUPER::size_request; |
1121 | |
1129 | |
1122 | ( |
1130 | ( |
1123 | $w + $self->border * 2, |
1131 | $w + $self->border * 2, |
… | |
… | |
1126 | } |
1134 | } |
1127 | |
1135 | |
1128 | sub size_allocate { |
1136 | sub size_allocate { |
1129 | my ($self, $w, $h) = @_; |
1137 | my ($self, $w, $h) = @_; |
1130 | |
1138 | |
1131 | if ($self->{title}) { |
1139 | if ($self->{title_widget}) { |
1132 | $self->{title}{w} = $w; |
1140 | $self->{title_widget}{w} = $w; |
1133 | $self->{title}{h} = $h; |
1141 | $self->{title_widget}{h} = $h; |
1134 | $self->{title}->size_allocate ($w, $h); |
1142 | $self->{title_widget}->size_allocate ($w, $h); |
1135 | } |
1143 | } |
1136 | |
1144 | |
1137 | my $border = $self->border; |
1145 | my $border = $self->border; |
1138 | |
1146 | |
1139 | $h -= List::Util::max 0, $border * 2; |
1147 | $h -= List::Util::max 0, $border * 2; |
1140 | $w -= List::Util::max 0, $border * 2; |
1148 | $w -= List::Util::max 0, $border * 2; |
1141 | |
1149 | |
1142 | $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}; |
1143 | } |
1154 | } |
1144 | |
1155 | |
1145 | sub button_down { |
1156 | sub button_down { |
1146 | my ($self, $ev, $x, $y) = @_; |
1157 | my ($self, $ev, $x, $y) = @_; |
1147 | |
1158 | |
… | |
… | |
1193 | } |
1204 | } |
1194 | |
1205 | |
1195 | sub button_up { |
1206 | sub button_up { |
1196 | my ($self, $ev, $x, $y) = @_; |
1207 | my ($self, $ev, $x, $y) = @_; |
1197 | |
1208 | |
|
|
1209 | $self->{close_btn}->button_up ($ev, $x, $y) |
|
|
1210 | if $self->{close_btn}; |
|
|
1211 | |
1198 | !!delete $self->{motion} |
1212 | !!delete $self->{motion} |
1199 | } |
1213 | } |
1200 | |
1214 | |
1201 | sub mouse_motion { |
1215 | sub mouse_motion { |
1202 | my ($self, $ev, $x, $y) = @_; |
1216 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
1237 | |
1251 | |
1238 | glDisable GL_TEXTURE_2D; |
1252 | glDisable GL_TEXTURE_2D; |
1239 | |
1253 | |
1240 | $child->draw; |
1254 | $child->draw; |
1241 | |
1255 | |
1242 | if ($self->{title}) { |
1256 | if ($self->{title_widget}) { |
1243 | glTranslate 0, $border - $self->{h}; |
1257 | glTranslate 0, $border - $self->{h}; |
1244 | $self->{title}->_draw; |
1258 | $self->{title_widget}->_draw; |
|
|
1259 | |
|
|
1260 | glTranslate 0, - ($border - $self->{h}); |
1245 | } |
1261 | } |
|
|
1262 | |
|
|
1263 | $self->{close_btn}->draw |
|
|
1264 | if $self->{close_btn}; |
1246 | } |
1265 | } |
1247 | |
1266 | |
1248 | ############################################################################# |
1267 | ############################################################################# |
1249 | |
1268 | |
1250 | package CFClient::UI::Table; |
1269 | package CFClient::UI::Table; |
… | |
… | |
1273 | |
1292 | |
1274 | $child->set_parent ($self); |
1293 | $child->set_parent ($self); |
1275 | $self->{children}[$y][$x] = $child; |
1294 | $self->{children}[$y][$x] = $child; |
1276 | |
1295 | |
1277 | $self->realloc; |
1296 | $self->realloc; |
|
|
1297 | } |
|
|
1298 | |
|
|
1299 | sub remove { |
|
|
1300 | my ($self, $child) = @_; |
|
|
1301 | |
|
|
1302 | # TODO: not yet implemented |
1278 | } |
1303 | } |
1279 | |
1304 | |
1280 | # 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? |
1281 | sub clear { |
1306 | sub clear { |
1282 | my ($self) = @_; |
1307 | my ($self) = @_; |
… | |
… | |
1559 | $self->{text} = "T$text"; |
1584 | $self->{text} = "T$text"; |
1560 | |
1585 | |
1561 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1586 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1562 | $self->{layout}->set_text ($text); |
1587 | $self->{layout}->set_text ($text); |
1563 | |
1588 | |
1564 | delete $self->{req_h}; |
1589 | delete $self->{size_req}; |
1565 | $self->realloc; |
1590 | $self->realloc; |
1566 | $self->update; |
1591 | $self->update; |
1567 | } |
1592 | } |
1568 | |
1593 | |
1569 | sub set_markup { |
1594 | sub set_markup { |
… | |
… | |
1575 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1600 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1576 | |
1601 | |
1577 | $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; |
1578 | $self->{layout}->set_markup ($markup); |
1603 | $self->{layout}->set_markup ($markup); |
1579 | |
1604 | |
1580 | delete $self->{req_h}; |
1605 | delete $self->{size_req}; |
1581 | $self->realloc; |
1606 | $self->realloc; |
1582 | $self->update; |
1607 | $self->update; |
1583 | } |
1608 | } |
1584 | |
1609 | |
1585 | sub size_request { |
1610 | sub size_request { |
1586 | my ($self) = @_; |
1611 | my ($self) = @_; |
1587 | |
1612 | |
1588 | if (exists $self->{req_h}) { |
1613 | $self->{size_req} ||= do { |
1589 | @$self{qw(req_w req_h)} |
|
|
1590 | } else { |
|
|
1591 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1614 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1592 | $self->{layout}->set_width ($self->{max_w} || -1); |
1615 | $self->{layout}->set_width ($self->{max_w} || -1); |
1593 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1616 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1594 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1617 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1595 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1618 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
… | |
… | |
1604 | |
1627 | |
1605 | $w = List::Util::max $w, $w2; |
1628 | $w = List::Util::max $w, $w2; |
1606 | $h = List::Util::max $h, $h2; |
1629 | $h = List::Util::max $h, $h2; |
1607 | } |
1630 | } |
1608 | |
1631 | |
1609 | ($w, $h) |
1632 | [$w, $h] |
1610 | } |
1633 | }; |
|
|
1634 | |
|
|
1635 | @{ $self->{size_req} } |
1611 | } |
1636 | } |
1612 | |
1637 | |
1613 | sub size_allocate { |
1638 | sub size_allocate { |
1614 | my ($self, $w, $h) = @_; |
1639 | my ($self, $w, $h) = @_; |
1615 | |
1640 | |
… | |
… | |
1624 | |
1649 | |
1625 | $self->{fontsize} = $fontsize; |
1650 | $self->{fontsize} = $fontsize; |
1626 | delete $self->{texture}; |
1651 | delete $self->{texture}; |
1627 | |
1652 | |
1628 | $self->realloc; |
1653 | $self->realloc; |
|
|
1654 | } |
|
|
1655 | |
|
|
1656 | sub reconfigure { |
|
|
1657 | my ($self) = @_; |
|
|
1658 | |
|
|
1659 | delete $self->{size_req}; |
|
|
1660 | |
|
|
1661 | $self->SUPER::reconfigure; |
1629 | } |
1662 | } |
1630 | |
1663 | |
1631 | sub _draw { |
1664 | sub _draw { |
1632 | my ($self) = @_; |
1665 | my ($self) = @_; |
1633 | |
1666 | |
… | |
… | |
1654 | : ($self->{h} - $tex->{h}) * 0.5); |
1687 | : ($self->{h} - $tex->{h}) * 0.5); |
1655 | }; |
1688 | }; |
1656 | |
1689 | |
1657 | glEnable GL_TEXTURE_2D; |
1690 | glEnable GL_TEXTURE_2D; |
1658 | |
1691 | |
|
|
1692 | my $w = List::Util::min $self->{w} + 4, $tex->{w}; |
|
|
1693 | my $h = List::Util::min $self->{h} + 2, $tex->{h}; |
|
|
1694 | |
1659 | if ($tex->{format} == GL_ALPHA) { |
1695 | if ($tex->{format} == GL_ALPHA) { |
1660 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1696 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1661 | glColor @{$self->{fg}}; |
1697 | glColor @{$self->{fg}}; |
1662 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1698 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h); |
1663 | } else { |
1699 | } else { |
1664 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1700 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1665 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1701 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h); |
1666 | } |
1702 | } |
1667 | |
1703 | |
1668 | glDisable GL_TEXTURE_2D; |
1704 | glDisable GL_TEXTURE_2D; |
1669 | } |
1705 | } |
1670 | |
1706 | |
… | |
… | |
1687 | can_hover => 1, |
1723 | can_hover => 1, |
1688 | can_focus => 1, |
1724 | can_focus => 1, |
1689 | valign => 0, |
1725 | valign => 0, |
1690 | can_events => 1, |
1726 | can_events => 1, |
1691 | #text => ... |
1727 | #text => ... |
|
|
1728 | #hidden => "*", |
1692 | @_ |
1729 | @_ |
1693 | ) |
1730 | ) |
1694 | } |
1731 | } |
1695 | |
1732 | |
1696 | sub _set_text { |
1733 | sub _set_text { |
… | |
… | |
1703 | $self->{last_activity} = $::NOW; |
1740 | $self->{last_activity} = $::NOW; |
1704 | $self->{text} = $text; |
1741 | $self->{text} = $text; |
1705 | |
1742 | |
1706 | $text =~ s/./*/g if $self->{hidden}; |
1743 | $text =~ s/./*/g if $self->{hidden}; |
1707 | $self->{layout}->set_text ("$text "); |
1744 | $self->{layout}->set_text ("$text "); |
1708 | delete $self->{req_h}; |
1745 | delete $self->{size_req}; |
1709 | |
1746 | |
1710 | $self->_emit (changed => $self->{text}); |
1747 | $self->_emit (changed => $self->{text}); |
1711 | |
1748 | |
1712 | $self->realloc; |
1749 | $self->realloc; |
1713 | $self->update; |
1750 | $self->update; |
… | |
… | |
1947 | $self->SUPER::_draw; |
1984 | $self->SUPER::_draw; |
1948 | } |
1985 | } |
1949 | |
1986 | |
1950 | ############################################################################# |
1987 | ############################################################################# |
1951 | |
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 | |
1952 | package CFClient::UI::CheckBox; |
2027 | package CFClient::UI::CheckBox; |
1953 | |
2028 | |
1954 | our @ISA = CFClient::UI::DrawBG::; |
2029 | our @ISA = CFClient::UI::DrawBG::; |
1955 | |
2030 | |
1956 | my @tex = |
2031 | my @tex = |
… | |
… | |
2299 | sub set_range { |
2374 | sub set_range { |
2300 | my ($self, $range) = @_; |
2375 | my ($self, $range) = @_; |
2301 | |
2376 | |
2302 | ($range, $self->{range}) = ($self->{range}, $range); |
2377 | ($range, $self->{range}) = ($self->{range}, $range); |
2303 | |
2378 | |
2304 | $self->update |
|
|
2305 | if "@$range" ne "@{$self->{range}}"; |
2379 | if ("@$range" ne "@{$self->{range}}") { |
|
|
2380 | $self->update; |
|
|
2381 | $self->set_value ($self->{range}[0]); |
|
|
2382 | } |
2306 | } |
2383 | } |
2307 | |
2384 | |
2308 | sub set_value { |
2385 | sub set_value { |
2309 | my ($self, $value) = @_; |
2386 | my ($self, $value) = @_; |
2310 | |
2387 | |
… | |
… | |
2457 | sub set_range { shift->{slider}->set_range (@_) } |
2534 | sub set_range { shift->{slider}->set_range (@_) } |
2458 | sub set_value { shift->{slider}->set_value (@_) } |
2535 | sub set_value { shift->{slider}->set_value (@_) } |
2459 | |
2536 | |
2460 | ############################################################################# |
2537 | ############################################################################# |
2461 | |
2538 | |
2462 | package CFClient::UI::TextView; |
2539 | package CFClient::UI::TextScroller; |
2463 | |
2540 | |
2464 | our @ISA = CFClient::UI::HBox::; |
2541 | our @ISA = CFClient::UI::HBox::; |
2465 | |
2542 | |
2466 | use CFClient::OpenGL; |
2543 | use CFClient::OpenGL; |
2467 | |
2544 | |
… | |
… | |
2469 | my $class = shift; |
2546 | my $class = shift; |
2470 | |
2547 | |
2471 | my $self = $class->SUPER::new ( |
2548 | my $self = $class->SUPER::new ( |
2472 | fontsize => 1, |
2549 | fontsize => 1, |
2473 | can_events => 0, |
2550 | can_events => 0, |
|
|
2551 | indent => 0, |
2474 | #font => default_font |
2552 | #font => default_font |
2475 | @_, |
2553 | @_, |
2476 | |
2554 | |
2477 | layout => (new CFClient::Layout 1), |
2555 | layout => (new CFClient::Layout 1), |
2478 | par => [], |
2556 | par => [], |
… | |
… | |
2501 | $self->SUPER::size_allocate ($w, $h); |
2579 | $self->SUPER::size_allocate ($w, $h); |
2502 | |
2580 | |
2503 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2581 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2504 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2582 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2505 | $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}); |
2506 | |
2585 | |
2507 | $self->reflow; |
2586 | $self->reflow; |
2508 | } |
2587 | } |
2509 | |
2588 | |
2510 | sub text_size { |
2589 | sub text_size { |
… | |
… | |
2512 | |
2591 | |
2513 | my $layout = $self->{layout}; |
2592 | my $layout = $self->{layout}; |
2514 | |
2593 | |
2515 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2594 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2516 | $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}); |
2517 | $layout->set_markup ($text); |
2597 | $layout->set_markup ($text); |
2518 | |
2598 | |
2519 | $layout->size |
2599 | $layout->size |
2520 | } |
2600 | } |
2521 | |
2601 | |
… | |
… | |
2560 | |
2640 | |
2561 | return unless $self->{h} > 0; |
2641 | return unless $self->{h} > 0; |
2562 | |
2642 | |
2563 | delete $self->{texture}; |
2643 | delete $self->{texture}; |
2564 | |
2644 | |
2565 | $ROOT->on_post_alloc ($self, sub { |
2645 | $ROOT->on_post_alloc ($self => sub { |
2566 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2646 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2567 | |
2647 | |
2568 | if (delete $self->{need_reflow}) { |
2648 | if (delete $self->{need_reflow}) { |
2569 | my $height = 0; |
2649 | my $height = 0; |
2570 | |
2650 | |
… | |
… | |
2573 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2653 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2574 | |
2654 | |
2575 | for (@{$self->{par}}) { |
2655 | for (@{$self->{par}}) { |
2576 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
2656 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
2577 | $layout->set_width ($W - $_->[3]); |
2657 | $layout->set_width ($W - $_->[3]); |
|
|
2658 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2578 | $layout->set_markup ($_->[4]); |
2659 | $layout->set_markup ($_->[4]); |
2579 | my ($w, $h) = $layout->size; |
2660 | my ($w, $h) = $layout->size; |
2580 | $_->[0] = $w + $_->[3]; |
2661 | $_->[0] = $w + $_->[3]; |
2581 | $_->[1] = $h; |
2662 | $_->[1] = $h; |
2582 | } |
2663 | } |
… | |
… | |
2585 | } |
2666 | } |
2586 | |
2667 | |
2587 | $self->{height} = $height; |
2668 | $self->{height} = $height; |
2588 | |
2669 | |
2589 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2670 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2590 | |
2671 | |
2591 | delete $self->{texture}; |
2672 | delete $self->{texture}; |
2592 | } |
2673 | } |
2593 | |
2674 | |
2594 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2675 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2595 | glClearColor 0, 0, 0, 0; |
2676 | glClearColor 0, 0, 0, 0; |
… | |
… | |
2614 | my $h = $par->[1]; |
2695 | my $h = $par->[1]; |
2615 | |
2696 | |
2616 | if ($y0 < $y + $h && $y < $y1) { |
2697 | if ($y0 < $y + $h && $y < $y1) { |
2617 | $layout->set_foreground (@{ $par->[2] }); |
2698 | $layout->set_foreground (@{ $par->[2] }); |
2618 | $layout->set_width ($W - $par->[3]); |
2699 | $layout->set_width ($W - $par->[3]); |
|
|
2700 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2619 | $layout->set_markup ($par->[4]); |
2701 | $layout->set_markup ($par->[4]); |
2620 | |
2702 | |
2621 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2703 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2622 | |
2704 | |
2623 | glRasterPos $par->[3], $y - $y0; |
2705 | glRasterPos $par->[3], $y - $y0; |
… | |
… | |
2737 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2819 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2738 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2820 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2739 | . "req $widget->{req_w} $widget->{req_h}\n" |
2821 | . "req $widget->{req_w} $widget->{req_h}\n" |
2740 | . "visible $widget->{visible}"; |
2822 | . "visible $widget->{visible}"; |
2741 | } |
2823 | } |
|
|
2824 | |
|
|
2825 | $tooltip =~ s/^\n+//; |
|
|
2826 | $tooltip =~ s/\n+$//; |
2742 | |
2827 | |
2743 | $self->add (new CFClient::UI::Label |
2828 | $self->add (new CFClient::UI::Label |
2744 | markup => $tooltip, |
2829 | markup => $tooltip, |
2745 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2830 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2746 | fontsize => 0.8, |
2831 | fontsize => 0.8, |
… | |
… | |
2774 | or return; |
2859 | or return; |
2775 | |
2860 | |
2776 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2861 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2777 | |
2862 | |
2778 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2863 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2779 | if $x + $self->{w} > $::WIDTH; |
2864 | if $x + $self->{w} > $self->{root}{w}; |
2780 | |
2865 | |
2781 | $self->move_abs ($x, $y); |
2866 | $self->move_abs ($x, $y); |
2782 | }); |
2867 | }); |
2783 | } |
2868 | } |
2784 | |
2869 | |
… | |
… | |
2879 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2964 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2880 | glDisable GL_TEXTURE_2D; |
2965 | glDisable GL_TEXTURE_2D; |
2881 | } |
2966 | } |
2882 | } |
2967 | } |
2883 | |
2968 | |
2884 | sub DESTROY { |
2969 | sub destroy { |
2885 | my ($self) = @_; |
2970 | my ($self) = @_; |
2886 | |
2971 | |
2887 | $self->{timer}->cancel |
2972 | $self->{timer}->cancel |
2888 | if $self->{timer}; |
2973 | if $self->{timer}; |
2889 | |
2974 | |
2890 | $self->SUPER::DESTROY; |
2975 | $self->SUPER::destroy; |
2891 | } |
2976 | } |
2892 | |
2977 | |
2893 | ############################################################################# |
2978 | ############################################################################# |
2894 | |
2979 | |
2895 | package CFClient::UI::Buttonbar; |
2980 | package CFClient::UI::Buttonbar; |
… | |
… | |
2916 | ); |
3001 | ); |
2917 | |
3002 | |
2918 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
3003 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
2919 | |
3004 | |
2920 | for my $item (@{ $self->{items} }) { |
3005 | for my $item (@{ $self->{items} }) { |
2921 | my ($widget, $cb) = @$item; |
3006 | my ($widget, $cb, $tooltip) = @$item; |
2922 | |
3007 | |
2923 | # handle various types of items, only text for now |
3008 | # handle various types of items, only text for now |
2924 | if (!ref $widget) { |
3009 | if (!ref $widget) { |
2925 | $widget = new CFClient::UI::Label |
3010 | $widget = new CFClient::UI::Label |
2926 | can_hover => 1, |
3011 | can_hover => 1, |
2927 | can_events => 1, |
3012 | can_events => 1, |
2928 | text => $widget; |
3013 | markup => $widget, |
|
|
3014 | tooltip => $tooltip |
2929 | } |
3015 | } |
2930 | |
3016 | |
2931 | $self->{item}{$widget} = $item; |
3017 | $self->{item}{$widget} = $item; |
2932 | |
3018 | |
2933 | $self->{vbox}->add ($widget); |
3019 | $self->{vbox}->add ($widget); |
… | |
… | |
3080 | sub set_current_page { |
3166 | sub set_current_page { |
3081 | my ($self, $page) = @_; |
3167 | my ($self, $page) = @_; |
3082 | |
3168 | |
3083 | $self->{multiplexer}->set_current_page ($page); |
3169 | $self->{multiplexer}->set_current_page ($page); |
3084 | $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); |
3085 | } |
3227 | } |
3086 | |
3228 | |
3087 | ############################################################################# |
3229 | ############################################################################# |
3088 | |
3230 | |
3089 | package CFClient::UI::Statusbox; |
3231 | package CFClient::UI::Statusbox; |
… | |
… | |
3188 | $item->{count}++; |
3330 | $item->{count}++; |
3189 | } else { |
3331 | } else { |
3190 | $item->{count} = 1; |
3332 | $item->{count} = 1; |
3191 | $item->{text} = $item->{tooltip} = $text; |
3333 | $item->{text} = $item->{tooltip} = $text; |
3192 | } |
3334 | } |
3193 | $item->{id} = ++$self->{id}; |
3335 | $item->{id} += 0.2;#d# |
3194 | $item->{timeout} = $timeout; |
3336 | $item->{timeout} = $timeout; |
3195 | delete $item->{label}; |
3337 | delete $item->{label}; |
3196 | } else { |
3338 | } else { |
3197 | $self->{item}{$group} = { |
3339 | $self->{item}{$group} = { |
3198 | id => ++$self->{id}, |
3340 | id => ++$self->{id}, |
… | |
… | |
3217 | |
3359 | |
3218 | $self->reorder; |
3360 | $self->reorder; |
3219 | $self->SUPER::reconfigure; |
3361 | $self->SUPER::reconfigure; |
3220 | } |
3362 | } |
3221 | |
3363 | |
3222 | sub DESTROY { |
3364 | sub destroy { |
3223 | my ($self) = @_; |
3365 | my ($self) = @_; |
3224 | |
3366 | |
3225 | $self->{timer}->cancel; |
3367 | $self->{timer}->cancel; |
3226 | |
3368 | |
3227 | $self->SUPER::DESTROY; |
3369 | $self->SUPER::destroy; |
3228 | } |
3370 | } |
3229 | |
3371 | |
3230 | ############################################################################# |
3372 | ############################################################################# |
3231 | |
3373 | |
3232 | package CFClient::UI::Inventory; |
3374 | package CFClient::UI::Inventory; |
… | |
… | |
3480 | commands => [], |
3622 | commands => [], |
3481 | @_, |
3623 | @_, |
3482 | ) |
3624 | ) |
3483 | } |
3625 | } |
3484 | |
3626 | |
3485 | # 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 | |
3486 | sub add_spell { |
3712 | sub add_spell { |
3487 | my ($self, $spell) = @_; |
3713 | my ($self, $spell) = @_; |
|
|
3714 | |
3488 | $self->{spells}->{$spell->{name}} = $spell; |
3715 | $self->{spell}->{$spell->{name}} = $spell; |
3489 | |
3716 | $self->rebuild_spell_list; |
3490 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
|
|
3491 | face => $spell->{face}, |
|
|
3492 | can_hover => 1, |
|
|
3493 | can_events => 1, |
|
|
3494 | tooltip => $spell->{message}); |
|
|
3495 | |
|
|
3496 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3497 | text => $spell->{name}, |
|
|
3498 | can_hover => 1, |
|
|
3499 | can_events => 1, |
|
|
3500 | tooltip => $spell->{message}, |
|
|
3501 | expand => 1); |
|
|
3502 | |
|
|
3503 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3504 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
|
|
3505 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
|
|
3506 | expand => 1); |
|
|
3507 | |
|
|
3508 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
|
|
3509 | text => "bind to key", |
|
|
3510 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
|
|
3511 | } |
|
|
3512 | |
|
|
3513 | sub rebuild_spell_list { |
|
|
3514 | my ($self) = @_; |
|
|
3515 | $self->{tbl_idx} = 0; |
|
|
3516 | $self->add_spell ($_) for values %{$self->{spells}}; |
|
|
3517 | } |
3717 | } |
3518 | |
3718 | |
3519 | sub remove_spell { |
3719 | sub remove_spell { |
3520 | my ($self, $spell) = @_; |
3720 | my ($self, $spell) = @_; |
|
|
3721 | |
3521 | 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} = {}; |
3522 | $self->rebuild_spell_list; |
3730 | $self->rebuild_spell_list; |
3523 | } |
3731 | } |
3524 | |
3732 | |
3525 | ############################################################################# |
3733 | ############################################################################# |
3526 | |
3734 | |