… | |
… | |
268 | $self->hide; |
268 | $self->hide; |
269 | $self->emit ("destroy"); |
269 | $self->emit ("destroy"); |
270 | %$self = (); |
270 | %$self = (); |
271 | } |
271 | } |
272 | |
272 | |
|
|
273 | sub TO_JSON { |
|
|
274 | { __widget_ref__ => $_[0]{s_id} } |
|
|
275 | } |
|
|
276 | |
273 | sub show { |
277 | sub show { |
274 | my ($self) = @_; |
278 | my ($self) = @_; |
275 | |
279 | |
276 | return if $self->{parent}; |
280 | return if $self->{parent}; |
277 | |
281 | |
… | |
… | |
316 | sub set_visibility { |
320 | sub set_visibility { |
317 | my ($self, $visible) = @_; |
321 | my ($self, $visible) = @_; |
318 | |
322 | |
319 | return if $self->{visible} == $visible; |
323 | return if $self->{visible} == $visible; |
320 | |
324 | |
321 | $visible ? $self->hide |
325 | $visible ? $self->show |
322 | : $self->show; |
326 | : $self->hide; |
323 | } |
327 | } |
324 | |
328 | |
325 | sub toggle_visibility { |
329 | sub toggle_visibility { |
326 | my ($self) = @_; |
330 | my ($self) = @_; |
327 | |
331 | |
… | |
… | |
543 | |
547 | |
544 | # parent |
548 | # parent |
545 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
549 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
546 | } |
550 | } |
547 | |
551 | |
548 | sub find_widget { |
552 | #sub find_widget { |
549 | my ($self, $x, $y) = @_; |
553 | # in .xs |
550 | |
|
|
551 | return () unless $self->{can_events}; |
|
|
552 | |
|
|
553 | return $self |
|
|
554 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
555 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
556 | |
|
|
557 | () |
|
|
558 | } |
|
|
559 | |
554 | |
560 | sub set_parent { |
555 | sub set_parent { |
561 | my ($self, $parent) = @_; |
556 | my ($self, $parent) = @_; |
562 | |
557 | |
563 | CFPlus::weaken ($self->{parent} = $parent); |
558 | CFPlus::weaken ($self->{parent} = $parent); |
… | |
… | |
940 | |
935 | |
941 | ############################################################################# |
936 | ############################################################################# |
942 | |
937 | |
943 | package CFPlus::UI::ViewPort; |
938 | package CFPlus::UI::ViewPort; |
944 | |
939 | |
|
|
940 | use List::Util qw(min max); |
|
|
941 | |
945 | our @ISA = CFPlus::UI::Window::; |
942 | our @ISA = CFPlus::UI::Window::; |
946 | |
943 | |
947 | sub new { |
944 | sub new { |
948 | my $class = shift; |
945 | my $class = shift; |
949 | |
946 | |
… | |
… | |
980 | } |
977 | } |
981 | |
978 | |
982 | sub set_offset { |
979 | sub set_offset { |
983 | my ($self, $x, $y) = @_; |
980 | my ($self, $x, $y) = @_; |
984 | |
981 | |
|
|
982 | my $x = max 0, min $self->child->{w} - $self->{w}, int $x; |
|
|
983 | my $y = max 0, min $self->child->{h} - $self->{h}, int $y; |
|
|
984 | |
|
|
985 | if ($x != $self->{view_x} or $y != $self->{view_y}) { |
985 | $self->{view_x} = int $x; |
986 | $self->{view_x} = $x; |
986 | $self->{view_y} = int $y; |
987 | $self->{view_y} = $y; |
987 | |
988 | |
|
|
989 | $self->emit (changed => $x, $y); |
988 | $self->update; |
990 | $self->update; |
|
|
991 | } |
989 | } |
992 | } |
990 | |
993 | |
991 | # hmm, this does not work for topleft of $self... but we should not ask for that |
994 | # hmm, this does not work for topleft of $self... but we should not ask for that |
992 | sub coord2local { |
995 | sub coord2local { |
993 | my ($self, $x, $y) = @_; |
996 | my ($self, $x, $y) = @_; |
… | |
… | |
1008 | my ($self, $x, $y) = @_; |
1011 | my ($self, $x, $y) = @_; |
1009 | |
1012 | |
1010 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1013 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1011 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1014 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1012 | ) { |
1015 | ) { |
1013 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1016 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1014 | } else { |
1017 | } else { |
1015 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1018 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1016 | } |
1019 | } |
1017 | } |
1020 | } |
1018 | |
1021 | |
… | |
… | |
1029 | |
1032 | |
1030 | ############################################################################# |
1033 | ############################################################################# |
1031 | |
1034 | |
1032 | package CFPlus::UI::ScrolledWindow; |
1035 | package CFPlus::UI::ScrolledWindow; |
1033 | |
1036 | |
1034 | our @ISA = CFPlus::UI::HBox::; |
1037 | our @ISA = CFPlus::UI::Table::; |
1035 | |
1038 | |
1036 | sub new { |
1039 | sub new { |
1037 | my ($class, %arg) = @_; |
1040 | my ($class, %arg) = @_; |
1038 | |
1041 | |
1039 | my $child = delete $arg{child}; |
1042 | my $child = delete $arg{child}; |
1040 | |
1043 | |
1041 | my $self; |
1044 | my $self; |
1042 | |
1045 | |
1043 | my $slider = new CFPlus::UI::Slider |
1046 | my $hslider = new CFPlus::UI::Slider |
|
|
1047 | vertical => 0, |
|
|
1048 | range => [0, 0, 1, 0.01], # HACK fix |
|
|
1049 | on_changed => sub { |
|
|
1050 | $self->{hpos} = $_[1]; |
|
|
1051 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
|
|
1052 | }, |
|
|
1053 | ; |
|
|
1054 | |
|
|
1055 | my $vslider = new CFPlus::UI::Slider |
1044 | vertical => 1, |
1056 | vertical => 1, |
1045 | range => [0, 0, 1, 0.01], # HACK fix |
1057 | range => [0, 0, 1, 0.01], # HACK fix |
1046 | on_changed => sub { |
1058 | on_changed => sub { |
1047 | $self->{vp}->set_offset (0, $_[1]); |
1059 | $self->{vpos} = $_[1]; |
|
|
1060 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1048 | }, |
1061 | }, |
1049 | ; |
1062 | ; |
1050 | |
1063 | |
1051 | $self = $class->SUPER::new ( |
1064 | $self = $class->SUPER::new ( |
1052 | vp => (new CFPlus::UI::ViewPort expand => 1), |
1065 | scroll_x => 0, |
|
|
1066 | scroll_y => 1, |
1053 | can_events => 1, |
1067 | can_events => 1, |
1054 | slider => $slider, |
1068 | hslider => $hslider, |
|
|
1069 | vslider => $vslider, |
|
|
1070 | col_expand => [1, 0], |
|
|
1071 | row_expand => [1, 0], |
1055 | %arg, |
1072 | %arg, |
1056 | ); |
1073 | ); |
1057 | |
1074 | |
1058 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
1075 | $self->{vp} = new CFPlus::UI::ViewPort |
|
|
1076 | expand => 1, |
|
|
1077 | scroll_x => $self->{scroll_x}, |
|
|
1078 | scroll_y => $self->{scroll_y}, |
|
|
1079 | on_changed => sub { |
|
|
1080 | my ($vp, $x, $y) = @_; |
|
|
1081 | |
|
|
1082 | $vp->{parent}{hslider}->set_value ($x); |
|
|
1083 | $vp->{parent}{vslider}->set_value ($y); |
|
|
1084 | |
|
|
1085 | 0 |
|
|
1086 | }, |
|
|
1087 | ; |
|
|
1088 | |
|
|
1089 | $self->SUPER::add_at (0, 0, $self->{vp}); |
|
|
1090 | |
1059 | $self->add ($child) if $child; |
1091 | $self->add ($child) if $child; |
1060 | |
1092 | |
1061 | $self |
1093 | $self |
1062 | } |
1094 | } |
1063 | |
1095 | |
… | |
… | |
1067 | my ($self, $widget) = @_; |
1099 | my ($self, $widget) = @_; |
1068 | |
1100 | |
1069 | $self->{vp}->add ($self->{child} = $widget); |
1101 | $self->{vp}->add ($self->{child} = $widget); |
1070 | } |
1102 | } |
1071 | |
1103 | |
|
|
1104 | sub update_slider { |
|
|
1105 | my ($self) = @_; |
|
|
1106 | |
|
|
1107 | my $child = ($self->{vp} or return)->child; |
|
|
1108 | |
|
|
1109 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
|
|
1110 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
|
|
1111 | |
|
|
1112 | my $visible = $w1 > $w2; |
|
|
1113 | if ($visible != $self->{hslider}{visible}) { |
|
|
1114 | $visible ? $self->SUPER::add_at (0, 1, $self->{hslider}) |
|
|
1115 | : $self->{hslider}->hide; |
|
|
1116 | } |
|
|
1117 | |
|
|
1118 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
|
|
1119 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
|
|
1120 | |
|
|
1121 | my $visible = $h1 > $h2; |
|
|
1122 | if ($visible != $self->{vslider}{visible}) { |
|
|
1123 | $visible ? $self->SUPER::add_at (1, 0, $self->{vslider}) |
|
|
1124 | : $self->{vslider}->hide; |
|
|
1125 | } |
|
|
1126 | } |
|
|
1127 | |
|
|
1128 | sub update { |
|
|
1129 | my ($self) = @_; |
|
|
1130 | |
|
|
1131 | $self->update_slider; |
|
|
1132 | $self->SUPER::update; |
|
|
1133 | } |
|
|
1134 | |
1072 | sub invoke_mouse_wheel { |
1135 | sub invoke_mouse_wheel { |
1073 | my ($self, $ev) = @_; |
1136 | my ($self, $ev) = @_; |
1074 | |
1137 | |
1075 | return 0 unless $ev->{dy}; # only vertical movements |
1138 | return 0 unless $ev->{dy}; # only vertical movements for now |
1076 | |
1139 | |
1077 | $self->{slider}->emit (mouse_wheel => $ev); |
1140 | $self->{vslider}->emit (mouse_wheel => $ev); |
1078 | |
1141 | |
1079 | 1 |
1142 | 1 |
1080 | } |
1143 | } |
1081 | |
1144 | |
1082 | sub update_slider { |
1145 | sub invoke_button_down { |
1083 | my ($self) = @_; |
1146 | my ($self, $ev, $x, $y) = @_; |
1084 | |
1147 | |
1085 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); |
1148 | if ($ev->{button} == 2) { |
1086 | } |
1149 | $self->grab_focus; |
1087 | |
1150 | |
1088 | sub update { |
1151 | my $ox = $self->{vp}{view_x} + $ev->{x}; |
1089 | my ($self) = @_; |
1152 | my $oy = $self->{vp}{view_y} + $ev->{y}; |
|
|
1153 | |
|
|
1154 | $self->{motion} = sub { |
|
|
1155 | my ($ev, $x, $y) = @_; |
1090 | |
1156 | |
1091 | $self->SUPER::update; |
1157 | $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); |
|
|
1158 | $self->update; |
|
|
1159 | }; |
1092 | |
1160 | |
1093 | $self->update_slider; |
1161 | return 1; |
|
|
1162 | } |
|
|
1163 | |
|
|
1164 | 0 |
|
|
1165 | } |
|
|
1166 | |
|
|
1167 | sub invoke_button_up { |
|
|
1168 | my ($self, $ev, $x, $y) = @_; |
|
|
1169 | |
|
|
1170 | if (delete $self->{motion}) { |
|
|
1171 | return 1; |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | 0 |
|
|
1175 | } |
|
|
1176 | |
|
|
1177 | sub invoke_mouse_motion { |
|
|
1178 | my ($self, $ev, $x, $y) = @_; |
|
|
1179 | |
|
|
1180 | if ($self->{motion}) { |
|
|
1181 | $self->{motion}->($ev, $x, $y); |
|
|
1182 | return 1; |
|
|
1183 | } |
|
|
1184 | |
|
|
1185 | 0 |
1094 | } |
1186 | } |
1095 | |
1187 | |
1096 | sub invoke_size_allocate { |
1188 | sub invoke_size_allocate { |
1097 | my ($self, $w, $h) = @_; |
1189 | my ($self, $w, $h) = @_; |
1098 | |
1190 | |
1099 | $self->update_slider; |
1191 | $self->update_slider; |
1100 | |
|
|
1101 | $self->SUPER::invoke_size_allocate ($w, $h) |
1192 | $self->SUPER::invoke_size_allocate ($w, $h) |
1102 | } |
1193 | } |
1103 | |
1194 | |
1104 | ############################################################################# |
1195 | ############################################################################# |
1105 | |
1196 | |
… | |
… | |
1255 | |
1346 | |
1256 | my @border = |
1347 | my @border = |
1257 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1348 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1258 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1349 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1259 | |
1350 | |
|
|
1351 | my @icon = |
|
|
1352 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
1353 | qw(x1_move.png x1_resize.png); |
|
|
1354 | |
1260 | sub new { |
1355 | sub new { |
1261 | my ($class, %arg) = @_; |
1356 | my ($class, %arg) = @_; |
1262 | |
1357 | |
1263 | my $self = $class->SUPER::new ( |
1358 | my $self = $class->SUPER::new ( |
1264 | bg => [1, 1, 1, 1], |
1359 | bg => [1, 1, 1, 1], |
… | |
… | |
1432 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1527 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1433 | |
1528 | |
1434 | my $border = $self->border; |
1529 | my $border = $self->border; |
1435 | |
1530 | |
1436 | glColor @{ $self->{border_bg} }; |
1531 | glColor @{ $self->{border_bg} }; |
1437 | $border[0]->draw_quad_alpha (0, 0, $w, $border); |
1532 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1438 | $border[1]->draw_quad_alpha (0, $border, $border, $ch); |
1533 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1439 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1534 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1440 | $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); |
1535 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
|
|
1536 | |
|
|
1537 | # move |
|
|
1538 | my $w2 = ($w - $border) * .5; |
|
|
1539 | my $h2 = ($h - $border) * .5; |
|
|
1540 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
|
|
1541 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
|
|
1542 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
|
|
1543 | |
|
|
1544 | # resize |
|
|
1545 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
|
|
1546 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
|
|
1547 | unless $self->{has_close_button}; |
|
|
1548 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
|
|
1549 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
1441 | |
1550 | |
1442 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1551 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1443 | glColor @{ $self->{bg} }; |
1552 | glColor @{ $self->{bg} }; |
1444 | |
1553 | |
1445 | # TODO: repeat texture not scale |
1554 | # TODO: repeat texture not scale |
… | |
… | |
1476 | |
1585 | |
1477 | sub new { |
1586 | sub new { |
1478 | my $class = shift; |
1587 | my $class = shift; |
1479 | |
1588 | |
1480 | $class->SUPER::new ( |
1589 | $class->SUPER::new ( |
|
|
1590 | children => [], |
1481 | col_expand => [], |
1591 | col_expand => [], |
|
|
1592 | row_expand => [], |
1482 | @_, |
1593 | @_, |
1483 | ) |
1594 | ) |
1484 | } |
1595 | } |
1485 | |
1596 | |
1486 | sub children { |
1597 | sub children { |
1487 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1598 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1488 | } |
1599 | } |
1489 | |
1600 | |
|
|
1601 | # TODO: store row/col info in child widget and use standard add/del |
1490 | sub add { |
1602 | sub add { |
1491 | my ($self) = shift; |
1603 | my $self = shift; |
|
|
1604 | |
|
|
1605 | Carp::cluck "please use the add_at method instead of calling add, thank you.\n";#d# |
|
|
1606 | $self->add_at (@_); |
|
|
1607 | } |
|
|
1608 | |
|
|
1609 | sub add_at { |
|
|
1610 | my $self = shift; |
1492 | |
1611 | |
1493 | while (@_) { |
1612 | while (@_) { |
1494 | my ($x, $y, $child) = splice @_, 0, 3, (); |
1613 | my ($col, $row, $child) = splice @_, 0, 3, (); |
|
|
1614 | |
1495 | $child->set_parent ($self); |
1615 | $child->set_parent ($self); |
1496 | $self->{children}[$y][$x] = $child; |
1616 | $self->{children}[$row][$col] = $child; |
1497 | } |
1617 | } |
1498 | |
1618 | |
1499 | $self->{force_realloc} = 1; |
1619 | $self->{force_realloc} = 1; |
1500 | $self->{force_size_alloc} = 1; |
1620 | $self->{force_size_alloc} = 1; |
1501 | $self->realloc; |
1621 | $self->realloc; |
1502 | } |
1622 | } |
1503 | |
1623 | |
1504 | sub remove { |
1624 | sub remove { |
1505 | my ($self, $child) = @_; |
1625 | my ($self, $child) = @_; |
1506 | |
1626 | |
1507 | # TODO: not yet implemented |
1627 | for (@{ $self->{children} }) { |
|
|
1628 | for (@{ $_ || [] }) { |
|
|
1629 | $_ = undef if $_ == $child; |
|
|
1630 | } |
|
|
1631 | } |
1508 | } |
1632 | } |
1509 | |
1633 | |
1510 | # TODO: move to container class maybe? send children a signal on removal? |
1634 | # TODO: move to container class maybe? send children a signal on removal? |
1511 | sub clear { |
1635 | sub clear { |
1512 | my ($self) = @_; |
1636 | my ($self) = @_; |
… | |
… | |
1561 | my ($ws, $hs) = $self->get_wh; |
1685 | my ($ws, $hs) = $self->get_wh; |
1562 | |
1686 | |
1563 | my $req_w = (sum @$ws) || 1; |
1687 | my $req_w = (sum @$ws) || 1; |
1564 | my $req_h = (sum @$hs) || 1; |
1688 | my $req_h = (sum @$hs) || 1; |
1565 | |
1689 | |
1566 | # TODO: nicer code && do row_expand |
1690 | # TODO: nicer code |
1567 | my @col_expand = @{$self->{col_expand}}; |
1691 | my @col_expand = @{$self->{col_expand}}; |
1568 | @col_expand = (1) x @$ws unless @col_expand; |
1692 | @col_expand = (1) x @$ws unless @col_expand; |
1569 | my $col_expand = (sum @col_expand) || 1; |
1693 | my $col_expand = (sum @col_expand) || 1; |
1570 | |
1694 | |
1571 | # linearly scale sizes |
|
|
1572 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1695 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1573 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
|
|
1574 | |
1696 | |
1575 | CFPlus::UI::harmonize $ws; |
1697 | CFPlus::UI::harmonize $ws; |
|
|
1698 | |
|
|
1699 | my @row_expand = @{$self->{row_expand}}; |
|
|
1700 | @row_expand = (1) x @$ws unless @row_expand; |
|
|
1701 | my $row_expand = (sum @row_expand) || 1; |
|
|
1702 | |
|
|
1703 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
|
|
1704 | |
1576 | CFPlus::UI::harmonize $hs; |
1705 | CFPlus::UI::harmonize $hs; |
1577 | |
1706 | |
1578 | my $y; |
1707 | my $y; |
1579 | |
1708 | |
1580 | for my $r (0 .. $#{$self->{children}}) { |
1709 | for my $r (0 .. $#{$self->{children}}) { |
… | |
… | |
1620 | my ($self) = @_; |
1749 | my ($self) = @_; |
1621 | |
1750 | |
1622 | for (grep $_, @{$self->{children}}) { |
1751 | for (grep $_, @{$self->{children}}) { |
1623 | $_->draw for grep $_, @$_; |
1752 | $_->draw for grep $_, @$_; |
1624 | } |
1753 | } |
|
|
1754 | } |
|
|
1755 | |
|
|
1756 | ############################################################################# |
|
|
1757 | |
|
|
1758 | package CFPlus::UI::Fixed; |
|
|
1759 | |
|
|
1760 | use List::Util qw(min max); |
|
|
1761 | |
|
|
1762 | our @ISA = CFPlus::UI::Container::; |
|
|
1763 | |
|
|
1764 | sub add { |
|
|
1765 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1766 | |
|
|
1767 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1768 | $self->SUPER::add ($child); |
|
|
1769 | } |
|
|
1770 | |
|
|
1771 | sub _scale($$$) { |
|
|
1772 | my ($mode, $val, $max) = @_; |
|
|
1773 | |
|
|
1774 | $mode eq "abs" ? $val |
|
|
1775 | : $mode eq "rel" ? $val * $max |
|
|
1776 | : 0 |
|
|
1777 | } |
|
|
1778 | |
|
|
1779 | sub size_request { |
|
|
1780 | my ($self) = @_; |
|
|
1781 | |
|
|
1782 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
|
|
1783 | |
|
|
1784 | # determine overall size by querying abs widgets |
|
|
1785 | for my $child ($self->visible_children) { |
|
|
1786 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
|
|
1787 | |
|
|
1788 | if ($pos eq "abs") { |
|
|
1789 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1790 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1791 | |
|
|
1792 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
|
|
1793 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
|
|
1794 | } |
|
|
1795 | } |
|
|
1796 | |
|
|
1797 | my $W = $x2 - $x1; |
|
|
1798 | my $H = $y2 - $y1; |
|
|
1799 | |
|
|
1800 | # now layout remaining widgets |
|
|
1801 | for my $child ($self->visible_children) { |
|
|
1802 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
|
|
1803 | |
|
|
1804 | if ($pos ne "abs") { |
|
|
1805 | $x = _scale $pos, $x, $W; |
|
|
1806 | $y = _scale $pos, $x, $H; |
|
|
1807 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1808 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1809 | |
|
|
1810 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
|
|
1811 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
|
|
1812 | } |
|
|
1813 | } |
|
|
1814 | |
|
|
1815 | my $W = $x2 - $x1; |
|
|
1816 | my $H = $y2 - $y1; |
|
|
1817 | |
|
|
1818 | ($W, $H) |
|
|
1819 | } |
|
|
1820 | |
|
|
1821 | sub invoke_size_allocate { |
|
|
1822 | my ($self, $W, $H) = @_; |
|
|
1823 | |
|
|
1824 | for my $child ($self->visible_children) { |
|
|
1825 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
|
|
1826 | |
|
|
1827 | $x = _scale $pos, $x, $W; |
|
|
1828 | $y = _scale $pos, $x, $H; |
|
|
1829 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1830 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1831 | |
|
|
1832 | $child->configure ($x, $y, $w, $h); |
|
|
1833 | } |
|
|
1834 | |
|
|
1835 | 1 |
1625 | } |
1836 | } |
1626 | |
1837 | |
1627 | ############################################################################# |
1838 | ############################################################################# |
1628 | |
1839 | |
1629 | package CFPlus::UI::Box; |
1840 | package CFPlus::UI::Box; |
… | |
… | |
1969 | my $mod = $ev->{mod}; |
2180 | my $mod = $ev->{mod}; |
1970 | my $sym = $ev->{sym}; |
2181 | my $sym = $ev->{sym}; |
1971 | my $uni = $ev->{unicode}; |
2182 | my $uni = $ev->{unicode}; |
1972 | |
2183 | |
1973 | my $text = $self->get_text; |
2184 | my $text = $self->get_text; |
|
|
2185 | |
|
|
2186 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
1974 | |
2187 | |
1975 | if ($uni == 8) { |
2188 | if ($uni == 8) { |
1976 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2189 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1977 | } elsif ($uni == 127) { |
2190 | } elsif ($uni == 127) { |
1978 | substr $text, $self->{cursor}, 1, ""; |
2191 | substr $text, $self->{cursor}, 1, ""; |
… | |
… | |
2185 | |
2398 | |
2186 | use CFPlus::OpenGL; |
2399 | use CFPlus::OpenGL; |
2187 | |
2400 | |
2188 | my @tex = |
2401 | my @tex = |
2189 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2402 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2190 | qw(b1_button_active.png); |
2403 | qw(b1_button_inactive.png b1_button_active.png); |
2191 | |
2404 | |
2192 | sub new { |
2405 | sub new { |
2193 | my $class = shift; |
2406 | my $class = shift; |
2194 | |
2407 | |
2195 | $class->SUPER::new ( |
2408 | $class->SUPER::new ( |
2196 | padding_x => 4, |
2409 | padding_x => 4, |
2197 | padding_y => 4, |
2410 | padding_y => 4, |
2198 | fg => [1, 1, 1], |
2411 | fg => [1.0, 1.0, 1.0], |
2199 | active_fg => [0, 0, 1], |
2412 | active_fg => [0.8, 0.8, 0.8], |
2200 | can_hover => 1, |
2413 | can_hover => 1, |
2201 | align => 0, |
2414 | align => 0, |
2202 | valign => 0, |
2415 | valign => 0, |
2203 | can_events => 1, |
2416 | can_events => 1, |
2204 | @_ |
2417 | @_ |
… | |
… | |
2222 | |
2435 | |
2223 | glEnable GL_TEXTURE_2D; |
2436 | glEnable GL_TEXTURE_2D; |
2224 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2437 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2225 | glColor 0, 0, 0, 1; |
2438 | glColor 0, 0, 0, 1; |
2226 | |
2439 | |
|
|
2440 | my $tex = $tex[$GRAB == $self]; |
2227 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2441 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2228 | |
2442 | |
2229 | glDisable GL_TEXTURE_2D; |
2443 | glDisable GL_TEXTURE_2D; |
2230 | |
2444 | |
2231 | $self->SUPER::_draw; |
2445 | $self->SUPER::_draw; |
2232 | } |
2446 | } |
… | |
… | |
3287 | |
3501 | |
3288 | sub new { |
3502 | sub new { |
3289 | my $class = shift; |
3503 | my $class = shift; |
3290 | |
3504 | |
3291 | my $self = $class->SUPER::new ( |
3505 | my $self = $class->SUPER::new ( |
|
|
3506 | size_w => 32, |
|
|
3507 | size_h => 8, |
3292 | aspect => 1, |
3508 | aspect => 1, |
3293 | can_events => 0, |
3509 | can_events => 0, |
3294 | @_, |
3510 | @_, |
3295 | ); |
3511 | ); |
3296 | |
3512 | |
3297 | if ($self->{anim} && $self->{animspeed}) { |
3513 | if ($self->{anim} && $self->{animspeed}) { |
3298 | CFPlus::weaken (my $widget = $self); |
3514 | CFPlus::weaken (my $widget = $self); |
3299 | |
3515 | |
|
|
3516 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
|
|
3517 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3300 | $self->{timer} = Event->timer ( |
3518 | $self->{timer} = Event->timer ( |
3301 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
3302 | hard => 1, |
3519 | parked => 1, |
3303 | interval => $self->{animspeed}, |
|
|
3304 | cb => sub { |
3520 | cb => sub { |
|
|
3521 | return unless $::CONN && $widget; |
|
|
3522 | |
3305 | ++$widget->{frame}; |
3523 | ++$widget->{frame}; |
|
|
3524 | $widget->update_face; |
3306 | $widget->update; |
3525 | $widget->update; |
|
|
3526 | |
|
|
3527 | $widget->update_timer; |
3307 | }, |
3528 | }, |
3308 | ); |
3529 | ); |
|
|
3530 | |
|
|
3531 | $self->update_face; |
|
|
3532 | $self->update_timer; |
3309 | } |
3533 | } |
3310 | |
3534 | |
3311 | $self |
3535 | $self |
3312 | } |
3536 | } |
3313 | |
3537 | |
|
|
3538 | sub update_timer { |
|
|
3539 | my ($self) = @_; |
|
|
3540 | |
|
|
3541 | return unless $self->{timer}; |
|
|
3542 | |
|
|
3543 | if ($self->{visible}) { |
|
|
3544 | $self->{timer}->at ( |
|
|
3545 | $self->{anim_start} |
|
|
3546 | + $self->{animspeed} |
|
|
3547 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
|
|
3548 | ); |
|
|
3549 | $self->{timer}->start; |
|
|
3550 | } else { |
|
|
3551 | $self->{timer}->stop; |
|
|
3552 | } |
|
|
3553 | } |
|
|
3554 | |
|
|
3555 | sub update_face { |
|
|
3556 | my ($self) = @_; |
|
|
3557 | |
|
|
3558 | return unless $::CONN; |
|
|
3559 | |
|
|
3560 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
|
|
3561 | if ($anim && @$anim) { |
|
|
3562 | delete $self->{wait_face}; |
|
|
3563 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3564 | } |
|
|
3565 | } |
|
|
3566 | } |
|
|
3567 | |
3314 | sub size_request { |
3568 | sub size_request { |
3315 | (32, 8) |
3569 | my ($self) = @_; |
|
|
3570 | |
|
|
3571 | if ($::CONN) { |
|
|
3572 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
|
|
3573 | if (my $tex = $::CONN->{texture}[$faceid]) { |
|
|
3574 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
|
|
3575 | } else { |
|
|
3576 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
|
|
3577 | $self->realloc; |
|
|
3578 | }); |
|
|
3579 | } |
|
|
3580 | } |
|
|
3581 | } |
|
|
3582 | |
|
|
3583 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3316 | } |
3584 | } |
3317 | |
3585 | |
3318 | sub update { |
3586 | sub update { |
3319 | my ($self) = @_; |
3587 | my ($self) = @_; |
3320 | |
3588 | |
3321 | return unless $self->{visible}; |
3589 | return unless $self->{visible}; |
3322 | |
3590 | |
3323 | $self->SUPER::update; |
3591 | $self->SUPER::update; |
3324 | } |
3592 | } |
3325 | |
3593 | |
|
|
3594 | sub invoke_visibility_change { |
|
|
3595 | my ($self) = @_; |
|
|
3596 | |
|
|
3597 | $self->update_timer; |
|
|
3598 | |
|
|
3599 | 0 |
|
|
3600 | } |
|
|
3601 | |
3326 | sub _draw { |
3602 | sub _draw { |
3327 | my ($self) = @_; |
3603 | my ($self) = @_; |
3328 | |
3604 | |
3329 | return unless $::CONN; |
3605 | return unless $::CONN; |
3330 | |
3606 | |
3331 | $self->SUPER::_draw; |
3607 | $self->SUPER::_draw; |
3332 | |
3608 | |
3333 | my $face; |
|
|
3334 | |
|
|
3335 | if ($self->{frame}) { |
|
|
3336 | my $anim = $::CONN->{anim}[$self->{anim}]; |
3609 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3337 | |
3610 | or return; |
3338 | $face = $anim->[ $self->{frame} % @$anim ] |
|
|
3339 | if $anim && @$anim; |
|
|
3340 | } |
|
|
3341 | |
3611 | |
3342 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
3612 | my $tex = $::CONN->{texture}[$faceid]; |
3343 | |
3613 | |
3344 | if ($tex) { |
3614 | if ($tex) { |
3345 | glEnable GL_TEXTURE_2D; |
3615 | glEnable GL_TEXTURE_2D; |
3346 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3616 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3347 | glColor 0, 0, 0, 1; |
3617 | glColor 0, 0, 0, 1; |
… | |
… | |
3351 | } |
3621 | } |
3352 | |
3622 | |
3353 | sub destroy { |
3623 | sub destroy { |
3354 | my ($self) = @_; |
3624 | my ($self) = @_; |
3355 | |
3625 | |
3356 | $self->{timer}->cancel |
3626 | (delete $self->{timer})->cancel |
3357 | if $self->{timer}; |
3627 | if $self->{timer}; |
3358 | |
3628 | |
3359 | $self->SUPER::destroy; |
3629 | $self->SUPER::destroy; |
3360 | } |
3630 | } |
3361 | |
3631 | |
… | |
… | |
4005 | while ($self->{post_alloc_hook}) { |
4275 | while ($self->{post_alloc_hook}) { |
4006 | $_->() |
4276 | $_->() |
4007 | for values %{delete $self->{post_alloc_hook}}; |
4277 | for values %{delete $self->{post_alloc_hook}}; |
4008 | } |
4278 | } |
4009 | |
4279 | |
4010 | |
|
|
4011 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
4280 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
4012 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
4281 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
4013 | glClear GL_COLOR_BUFFER_BIT; |
4282 | glClear GL_COLOR_BUFFER_BIT; |
4014 | |
4283 | |
4015 | glMatrixMode GL_PROJECTION; |
4284 | glMatrixMode GL_PROJECTION; |