… | |
… | |
593 | |
593 | |
594 | # using global variables seems a bit hacky, but passing through all drawing |
594 | # using global variables seems a bit hacky, but passing through all drawing |
595 | # functions seems pointless. |
595 | # functions seems pointless. |
596 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
596 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
597 | |
597 | |
598 | sub draw { |
598 | #sub draw { |
599 | my ($self) = @_; |
599 | #CFPlus.xs |
600 | |
|
|
601 | return unless $self->{h} && $self->{w}; |
|
|
602 | |
|
|
603 | # update screen rectangle |
|
|
604 | local $draw_x = $draw_x + $self->{x}; |
|
|
605 | local $draw_y = $draw_y + $self->{y}; |
|
|
606 | |
|
|
607 | # skip widgets that are entirely outside the drawing area |
|
|
608 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
609 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
|
|
610 | |
|
|
611 | glPushMatrix; |
|
|
612 | glTranslate $self->{x}, $self->{y}, 0; |
|
|
613 | |
|
|
614 | if ($self == $HOVER && $self->{can_hover}) { |
|
|
615 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
|
|
616 | glEnable GL_BLEND; |
|
|
617 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
618 | glBegin GL_QUADS; |
|
|
619 | glVertex 0 , 0; |
|
|
620 | glVertex $self->{w}, 0; |
|
|
621 | glVertex $self->{w}, $self->{h}; |
|
|
622 | glVertex 0 , $self->{h}; |
|
|
623 | glEnd; |
|
|
624 | glDisable GL_BLEND; |
|
|
625 | } |
|
|
626 | |
|
|
627 | if ($ENV{CFPLUS_DEBUG} & 1) { |
|
|
628 | glPushMatrix; |
|
|
629 | glColor 1, 1, 0, 1; |
|
|
630 | glTranslate 0.375, 0.375; |
|
|
631 | glBegin GL_LINE_LOOP; |
|
|
632 | glVertex 0 , 0; |
|
|
633 | glVertex $self->{w} - 1, 0; |
|
|
634 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
635 | glVertex 0 , $self->{h} - 1; |
|
|
636 | glEnd; |
|
|
637 | glPopMatrix; |
|
|
638 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
639 | } |
|
|
640 | |
|
|
641 | $self->_draw; |
|
|
642 | glPopMatrix; |
|
|
643 | } |
|
|
644 | |
600 | |
645 | sub _draw { |
601 | sub _draw { |
646 | my ($self) = @_; |
602 | my ($self) = @_; |
647 | |
603 | |
648 | warn "no draw defined for $self\n"; |
604 | warn "no draw defined for $self\n"; |
649 | } |
605 | } |
650 | |
606 | |
651 | my $cntx;#d# |
|
|
652 | sub DESTROY { |
607 | sub DESTROY { |
653 | my ($self) = @_; |
608 | my ($self) = @_; |
654 | |
609 | |
655 | return if CFPlus::in_destruct; |
610 | return if CFPlus::in_destruct; |
656 | |
611 | |
… | |
… | |
741 | can_events => 0, |
696 | can_events => 0, |
742 | %arg, |
697 | %arg, |
743 | ); |
698 | ); |
744 | |
699 | |
745 | $self->add (@$children) |
700 | $self->add (@$children) |
746 | if $children; |
701 | if $children && @$children; |
747 | |
702 | |
748 | $self |
703 | $self |
749 | } |
704 | } |
750 | |
705 | |
751 | sub realloc { |
706 | sub realloc { |
… | |
… | |
760 | my ($self, @widgets) = @_; |
715 | my ($self, @widgets) = @_; |
761 | |
716 | |
762 | $_->set_parent ($self) |
717 | $_->set_parent ($self) |
763 | for @widgets; |
718 | for @widgets; |
764 | |
719 | |
|
|
720 | # TODO: only do this in widgets that need it, e.g. root, fixed |
765 | use sort 'stable'; |
721 | use sort 'stable'; |
766 | |
722 | |
767 | $self->{children} = [ |
723 | $self->{children} = [ |
768 | sort { $a->{z} <=> $b->{z} } |
724 | sort { $a->{z} <=> $b->{z} } |
769 | @{$self->{children}}, @widgets |
725 | @{$self->{children}}, @widgets |
770 | ]; |
726 | ]; |
771 | |
727 | |
772 | $self->realloc; |
728 | $self->realloc; |
|
|
729 | |
|
|
730 | map $_+0, @widgets |
773 | } |
731 | } |
774 | |
732 | |
775 | sub children { |
733 | sub children { |
776 | @{ $_[0]{children} } |
734 | @{ $_[0]{children} } |
777 | } |
735 | } |
… | |
… | |
788 | } |
746 | } |
789 | |
747 | |
790 | sub clear { |
748 | sub clear { |
791 | my ($self) = @_; |
749 | my ($self) = @_; |
792 | |
750 | |
793 | my $children = delete $self->{children}; |
751 | my $children = $self->{children}; |
794 | $self->{children} = []; |
752 | $self->{children} = []; |
795 | |
753 | |
796 | for (@$children) { |
754 | for (@$children) { |
797 | delete $_->{parent}; |
755 | delete $_->{parent}; |
798 | $_->hide; |
756 | $_->hide; |
… | |
… | |
1046 | my $child = delete $arg{child}; |
1004 | my $child = delete $arg{child}; |
1047 | |
1005 | |
1048 | my $self; |
1006 | my $self; |
1049 | |
1007 | |
1050 | my $hslider = new CFPlus::UI::Slider |
1008 | my $hslider = new CFPlus::UI::Slider |
|
|
1009 | col => 0, |
|
|
1010 | row => 1, |
1051 | vertical => 0, |
1011 | vertical => 0, |
1052 | range => [0, 0, 1, 0.01], # HACK fix |
1012 | range => [0, 0, 1, 0.01], # HACK fix |
1053 | on_changed => sub { |
1013 | on_changed => sub { |
1054 | $self->{hpos} = $_[1]; |
1014 | $self->{hpos} = $_[1]; |
1055 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1015 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1056 | }, |
1016 | }, |
1057 | ; |
1017 | ; |
1058 | |
1018 | |
1059 | my $vslider = new CFPlus::UI::Slider |
1019 | my $vslider = new CFPlus::UI::Slider |
|
|
1020 | col => 1, |
|
|
1021 | row => 0, |
1060 | vertical => 1, |
1022 | vertical => 1, |
1061 | range => [0, 0, 1, 0.01], # HACK fix |
1023 | range => [0, 0, 1, 0.01], # HACK fix |
1062 | on_changed => sub { |
1024 | on_changed => sub { |
1063 | $self->{vpos} = $_[1]; |
1025 | $self->{vpos} = $_[1]; |
1064 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1026 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1075 | row_expand => [1, 0], |
1037 | row_expand => [1, 0], |
1076 | %arg, |
1038 | %arg, |
1077 | ); |
1039 | ); |
1078 | |
1040 | |
1079 | $self->{vp} = new CFPlus::UI::ViewPort |
1041 | $self->{vp} = new CFPlus::UI::ViewPort |
|
|
1042 | col => 0, |
|
|
1043 | row => 0, |
1080 | expand => 1, |
1044 | expand => 1, |
1081 | scroll_x => $self->{scroll_x}, |
1045 | scroll_x => $self->{scroll_x}, |
1082 | scroll_y => $self->{scroll_y}, |
1046 | scroll_y => $self->{scroll_y}, |
1083 | on_changed => sub { |
1047 | on_changed => sub { |
1084 | my ($vp, $x, $y) = @_; |
1048 | my ($vp, $x, $y) = @_; |
… | |
… | |
1086 | $vp->{parent}{hslider}->set_value ($x); |
1050 | $vp->{parent}{hslider}->set_value ($x); |
1087 | $vp->{parent}{vslider}->set_value ($y); |
1051 | $vp->{parent}{vslider}->set_value ($y); |
1088 | |
1052 | |
1089 | 0 |
1053 | 0 |
1090 | }, |
1054 | }, |
|
|
1055 | on_size_allocate => sub { |
|
|
1056 | my ($vp, $w, $h) = @_; |
|
|
1057 | $vp->{parent}->update_slider; |
|
|
1058 | 0 |
|
|
1059 | }, |
1091 | ; |
1060 | ; |
1092 | |
1061 | |
1093 | $self->SUPER::add_at (0, 0, $self->{vp}); |
1062 | $self->SUPER::add ($self->{vp}); |
1094 | |
1063 | |
1095 | $self->add ($child) if $child; |
1064 | $self->add ($child) if $child; |
1096 | |
1065 | |
1097 | $self |
1066 | $self |
1098 | } |
1067 | } |
1099 | |
|
|
1100 | #TODO# update range on size_allocate depending on child |
|
|
1101 | |
1068 | |
1102 | sub add { |
1069 | sub add { |
1103 | my ($self, $widget) = @_; |
1070 | my ($self, $widget) = @_; |
1104 | |
1071 | |
1105 | $self->{vp}->add ($self->{child} = $widget); |
1072 | $self->{vp}->add ($self->{child} = $widget); |
… | |
… | |
1108 | sub update_slider { |
1075 | sub update_slider { |
1109 | my ($self) = @_; |
1076 | my ($self) = @_; |
1110 | |
1077 | |
1111 | my $child = ($self->{vp} or return)->child; |
1078 | my $child = ($self->{vp} or return)->child; |
1112 | |
1079 | |
|
|
1080 | if ($self->{scroll_x}) { |
1113 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1081 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1114 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1082 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1115 | |
1083 | |
1116 | my $visible = $w1 > $w2; |
1084 | my $visible = $w1 > $w2; |
1117 | if ($visible != $self->{hslider}{visible}) { |
1085 | if ($visible != $self->{hslider_visible}) { |
|
|
1086 | $self->{hslider_visible} = $visible; |
1118 | $visible ? $self->SUPER::add_at (0, 1, $self->{hslider}) |
1087 | $visible ? $self->SUPER::add ($self->{hslider}) |
1119 | : $self->{hslider}->hide; |
1088 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1089 | } |
1120 | } |
1090 | } |
1121 | |
1091 | |
|
|
1092 | if ($self->{scroll_y}) { |
1122 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1093 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1123 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1094 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1124 | |
1095 | |
1125 | my $visible = $h1 > $h2; |
1096 | my $visible = $h1 > $h2; |
1126 | if ($visible != $self->{vslider}{visible}) { |
1097 | if ($visible != $self->{vslider_visible}) { |
|
|
1098 | $self->{vslider_visible} = $visible; |
1127 | $visible ? $self->SUPER::add_at (1, 0, $self->{vslider}) |
1099 | $visible ? $self->SUPER::add ($self->{vslider}) |
1128 | : $self->{vslider}->hide; |
1100 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1101 | } |
|
|
1102 | } |
|
|
1103 | } |
|
|
1104 | |
|
|
1105 | sub start_dragging { |
|
|
1106 | my ($self, $ev) = @_; |
|
|
1107 | |
|
|
1108 | $self->grab_focus; |
|
|
1109 | |
|
|
1110 | my $ox = $self->{vp}{view_x}; |
|
|
1111 | my $oy = $self->{vp}{view_y}; |
|
|
1112 | |
|
|
1113 | $self->{motion} = sub { |
|
|
1114 | my ($ev, $x, $y) = @_; |
|
|
1115 | |
|
|
1116 | $ox -= $ev->{xrel}; |
|
|
1117 | $oy -= $ev->{yrel}; |
|
|
1118 | |
|
|
1119 | $self->{vp}->set_offset ($ox, $oy); |
1129 | } |
1120 | }; |
1130 | } |
|
|
1131 | |
|
|
1132 | sub update { |
|
|
1133 | my ($self) = @_; |
|
|
1134 | |
|
|
1135 | $self->update_slider; |
|
|
1136 | $self->SUPER::update; |
|
|
1137 | } |
1121 | } |
1138 | |
1122 | |
1139 | sub invoke_mouse_wheel { |
1123 | sub invoke_mouse_wheel { |
1140 | my ($self, $ev) = @_; |
1124 | my ($self, $ev) = @_; |
1141 | |
1125 | |
1142 | $self->{vslider}->emit (mouse_wheel => $ev) |
1126 | $self->{vslider}->emit (mouse_wheel => $ev) if $self->{vslider_visible}; |
1143 | if $ev->{dy}; |
|
|
1144 | |
|
|
1145 | $self->{hslider}->emit (mouse_wheel => $ev) |
1127 | $self->{hslider}->emit (mouse_wheel => $ev) if $self->{hslider_visible}; |
1146 | if $ev->{dx}; |
|
|
1147 | |
1128 | |
1148 | 1 |
1129 | 1 |
1149 | } |
1130 | } |
1150 | |
1131 | |
1151 | sub invoke_button_down { |
1132 | sub invoke_button_down { |
1152 | my ($self, $ev, $x, $y) = @_; |
1133 | my ($self, $ev, $x, $y) = @_; |
1153 | |
1134 | |
1154 | if ($ev->{button} == 2) { |
1135 | if ($ev->{button} == 2) { |
1155 | $self->grab_focus; |
1136 | $self->start_dragging ($ev); |
1156 | |
|
|
1157 | my $ox = $self->{vp}{view_x} + $ev->{x}; |
|
|
1158 | my $oy = $self->{vp}{view_y} + $ev->{y}; |
|
|
1159 | |
|
|
1160 | $self->{motion} = sub { |
|
|
1161 | my ($ev, $x, $y) = @_; |
|
|
1162 | |
|
|
1163 | $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); |
|
|
1164 | $self->update; |
|
|
1165 | }; |
|
|
1166 | |
|
|
1167 | return 1; |
1137 | return 1; |
1168 | } |
1138 | } |
1169 | |
1139 | |
1170 | 0 |
1140 | 0 |
1171 | } |
1141 | } |
… | |
… | |
1581 | |
1551 | |
1582 | ############################################################################# |
1552 | ############################################################################# |
1583 | |
1553 | |
1584 | package CFPlus::UI::Table; |
1554 | package CFPlus::UI::Table; |
1585 | |
1555 | |
1586 | our @ISA = CFPlus::UI::Base::; |
1556 | our @ISA = CFPlus::UI::Container::; |
1587 | |
1557 | |
1588 | use List::Util qw(max sum); |
1558 | use List::Util qw(max sum); |
1589 | |
1559 | |
1590 | use CFPlus::OpenGL; |
1560 | use CFPlus::OpenGL; |
1591 | |
1561 | |
1592 | sub new { |
1562 | sub new { |
1593 | my $class = shift; |
1563 | my $class = shift; |
1594 | |
1564 | |
1595 | $class->SUPER::new ( |
1565 | $class->SUPER::new ( |
1596 | children => [], |
|
|
1597 | col_expand => [], |
1566 | col_expand => [], |
1598 | row_expand => [], |
1567 | row_expand => [], |
1599 | @_, |
1568 | @_, |
1600 | ) |
1569 | ) |
1601 | } |
1570 | } |
1602 | |
1571 | |
1603 | sub children { |
|
|
1604 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1605 | } |
|
|
1606 | |
|
|
1607 | # TODO: store row/col info in child widget and use standard add/del |
|
|
1608 | sub add { |
1572 | sub add { |
1609 | my $self = shift; |
1573 | my ($self, @widgets) = @_; |
1610 | |
1574 | |
1611 | Carp::cluck "please use the add_at method instead of calling add, thank you.\n";#d# |
1575 | for my $child (@widgets) { |
1612 | $self->add_at (@_); |
1576 | $child->{rowspan} ||= 1; |
|
|
1577 | $child->{colspan} ||= 1; |
|
|
1578 | } |
|
|
1579 | |
|
|
1580 | $self->SUPER::add (@widgets); |
1613 | } |
1581 | } |
1614 | |
1582 | |
1615 | sub add_at { |
1583 | sub add_at { |
1616 | my $self = shift; |
1584 | my $self = shift; |
1617 | |
1585 | |
|
|
1586 | my @widgets; |
|
|
1587 | |
1618 | while (@_) { |
1588 | while (@_) { |
1619 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1589 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1620 | |
1590 | |
1621 | $child->{row} = $row; |
1591 | $child->{row} = $row; |
1622 | $child->{col} = $col; |
1592 | $child->{col} = $col; |
1623 | |
1593 | |
1624 | $child->{rowspan} ||= 1; |
1594 | push @widgets, $child; |
1625 | $child->{colspan} ||= 1; |
|
|
1626 | |
|
|
1627 | $child->set_parent ($self); |
|
|
1628 | $self->{children}[$row][$col] = $child; |
|
|
1629 | } |
1595 | } |
1630 | |
1596 | |
1631 | $self->{force_realloc} = 1; |
1597 | $self->add (@widgets); |
1632 | $self->{force_size_alloc} = 1; |
|
|
1633 | $self->realloc; |
|
|
1634 | } |
1598 | } |
1635 | |
1599 | |
1636 | sub remove { |
1600 | sub get_wh { |
1637 | my ($self, $child) = @_; |
1601 | my ($self) = @_; |
1638 | |
1602 | |
1639 | for (@{ $self->{children} }) { |
1603 | my (@w, @h); |
1640 | for (@{ $_ || [] }) { |
1604 | |
1641 | $_ = undef if $_ == $child; |
1605 | my @children = $self->children; |
|
|
1606 | |
|
|
1607 | # first pass, columns |
|
|
1608 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
|
|
1609 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
|
|
1610 | |
|
|
1611 | my $sw = sum @w[$c .. $c + $cs - 1]; |
|
|
1612 | |
|
|
1613 | if ($w > $sw) { |
|
|
1614 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1642 | } |
1615 | } |
1643 | } |
1616 | } |
1644 | } |
|
|
1645 | |
1617 | |
1646 | # TODO: move to container class maybe? send children a signal on removal? |
1618 | # second pass, rows |
1647 | sub clear { |
1619 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1648 | my ($self) = @_; |
|
|
1649 | |
|
|
1650 | my @children = $self->children; |
|
|
1651 | delete $self->{children}; |
|
|
1652 | |
|
|
1653 | for (@children) { |
|
|
1654 | delete $_->{parent}; |
|
|
1655 | $_->hide; |
|
|
1656 | } |
|
|
1657 | |
|
|
1658 | $self->realloc; |
|
|
1659 | } |
|
|
1660 | |
|
|
1661 | sub get_wh { |
|
|
1662 | my ($self) = @_; |
|
|
1663 | |
|
|
1664 | my (@w, @h); |
|
|
1665 | |
|
|
1666 | my @children = $self->children; |
|
|
1667 | |
|
|
1668 | for my $widget (sort { $b->{rowspan} * $b->{colspan} <=> $a->{rowspan} * $a->{colspan} } @children) { |
|
|
1669 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1620 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1670 | |
1621 | |
1671 | my $sw = sum @w[$c .. $c + $cs - 1]; |
|
|
1672 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1622 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1673 | |
1623 | |
1674 | if ($w > $sw) { |
|
|
1675 | $_ += ($w - $sw) / $cs for @w[$c .. $c + $cs - 1]; |
|
|
1676 | } |
|
|
1677 | |
|
|
1678 | if ($h > $sh) { |
1624 | if ($h > $sh) { |
1679 | $_ += ($h - $sh) / $rs for @h[$r .. $r + $rs - 1]; |
1625 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1680 | } |
1626 | } |
1681 | } |
1627 | } |
1682 | |
1628 | |
1683 | (\@w, \@h) |
1629 | (\@w, \@h) |
1684 | } |
1630 | } |
… | |
… | |
1717 | |
1663 | |
1718 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1664 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1719 | |
1665 | |
1720 | CFPlus::UI::harmonize $hs; |
1666 | CFPlus::UI::harmonize $hs; |
1721 | |
1667 | |
1722 | my (@x, @y); |
|
|
1723 | |
|
|
1724 | for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1668 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1725 | for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1669 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1726 | |
1670 | |
1727 | for my $widget ($self->children) { |
1671 | for my $widget ($self->children) { |
1728 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1672 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1729 | |
1673 | |
1730 | $widget->configure ( |
1674 | $widget->configure ( |
… | |
… | |
1734 | } |
1678 | } |
1735 | |
1679 | |
1736 | 1 |
1680 | 1 |
1737 | } |
1681 | } |
1738 | |
1682 | |
1739 | sub find_widget { |
|
|
1740 | my ($self, $x, $y) = @_; |
|
|
1741 | |
|
|
1742 | $x -= $self->{x}; |
|
|
1743 | $y -= $self->{y}; |
|
|
1744 | |
|
|
1745 | my $res; |
|
|
1746 | |
|
|
1747 | for (grep $_, map @$_, grep $_, @{ $self->{children} }) { |
|
|
1748 | $res = $_->find_widget ($x, $y) |
|
|
1749 | and return $res; |
|
|
1750 | } |
|
|
1751 | |
|
|
1752 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
|
|
1753 | } |
|
|
1754 | |
|
|
1755 | sub _draw { |
|
|
1756 | my ($self) = @_; |
|
|
1757 | |
|
|
1758 | for (grep $_, @{$self->{children}}) { |
|
|
1759 | $_->draw for grep $_, @$_; |
|
|
1760 | } |
|
|
1761 | } |
|
|
1762 | |
|
|
1763 | ############################################################################# |
1683 | ############################################################################# |
1764 | |
1684 | |
1765 | package CFPlus::UI::Fixed; |
1685 | package CFPlus::UI::Fixed; |
1766 | |
1686 | |
1767 | use List::Util qw(min max); |
1687 | use List::Util qw(min max); |
1768 | |
1688 | |
1769 | our @ISA = CFPlus::UI::Container::; |
1689 | our @ISA = CFPlus::UI::Container::; |
1770 | |
1690 | |
1771 | sub add { |
1691 | sub add_fixed { |
1772 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
1692 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
1773 | |
1693 | |
1774 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
1694 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
1775 | $self->SUPER::add ($child); |
1695 | $self->SUPER::add ($child); |
1776 | } |
1696 | } |
… | |
… | |
1831 | for my $child ($self->visible_children) { |
1751 | for my $child ($self->visible_children) { |
1832 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1752 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1833 | |
1753 | |
1834 | $x = _scale $pos, $x, $W; |
1754 | $x = _scale $pos, $x, $W; |
1835 | $y = _scale $pos, $x, $H; |
1755 | $y = _scale $pos, $x, $H; |
1836 | $w = _scale $size, $w, $child->{req_w}; |
1756 | $w = _scale $size, $w, $W; |
1837 | $h = _scale $size, $h, $child->{req_h}; |
1757 | $h = _scale $size, $h, $H; |
1838 | |
1758 | |
1839 | $child->configure ($x, $y, $w, $h); |
1759 | $child->configure ($x, $y, $w, $h); |
1840 | } |
1760 | } |
1841 | |
1761 | |
1842 | 1 |
1762 | 1 |
… | |
… | |
2107 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2027 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2108 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2028 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2109 | : ($self->{h} - $size->[1]) * 0.5); |
2029 | : ($self->{h} - $size->[1]) * 0.5); |
2110 | }; |
2030 | }; |
2111 | |
2031 | |
2112 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2032 | # unless ($self->{list}) { |
2113 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2033 | # $self->{list} = CFPlus::OpenGL::glGenList; |
|
|
2034 | # CFPlus::OpenGL::glNewList $self->{list}; |
|
|
2035 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2036 | # CFPlus::OpenGL::glEndList; |
|
|
2037 | # } |
|
|
2038 | # |
|
|
2039 | # CFPlus::OpenGL::glCallList $self->{list}; |
2114 | |
2040 | |
2115 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2041 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2116 | } |
2042 | } |
|
|
2043 | |
|
|
2044 | #sub destroy { |
|
|
2045 | # my ($self) = @_; |
|
|
2046 | # |
|
|
2047 | # CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2048 | # |
|
|
2049 | # $self->SUPER::destroy; |
|
|
2050 | #} |
2117 | |
2051 | |
2118 | ############################################################################# |
2052 | ############################################################################# |
2119 | |
2053 | |
2120 | package CFPlus::UI::EntryBase; |
2054 | package CFPlus::UI::EntryBase; |
2121 | |
2055 | |
… | |
… | |
3519 | |
3453 | |
3520 | if ($self->{anim} && $self->{animspeed}) { |
3454 | if ($self->{anim} && $self->{animspeed}) { |
3521 | CFPlus::weaken (my $widget = $self); |
3455 | CFPlus::weaken (my $widget = $self); |
3522 | |
3456 | |
3523 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3457 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3524 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3458 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3525 | $self->{timer} = Event->timer ( |
3459 | $self->{timer} = Event->timer ( |
3526 | parked => 1, |
3460 | parked => 1, |
3527 | cb => sub { |
3461 | cb => sub { |
3528 | return unless $::CONN && $widget; |
3462 | return unless $::CONN && $widget; |
3529 | |
3463 | |
… | |
… | |
3566 | |
3500 | |
3567 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3501 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3568 | if ($anim && @$anim) { |
3502 | if ($anim && @$anim) { |
3569 | delete $self->{wait_face}; |
3503 | delete $self->{wait_face}; |
3570 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3504 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3505 | $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; |
3571 | } |
3506 | } |
3572 | } |
3507 | } |
3573 | } |
3508 | } |
3574 | |
3509 | |
3575 | sub size_request { |
3510 | sub size_request { |
3576 | my ($self) = @_; |
3511 | my ($self) = @_; |
3577 | |
3512 | |
3578 | if ($::CONN) { |
3513 | if ($::CONN) { |
3579 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3514 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3580 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3515 | if (my $tex = $::CONN->{texture}[$faceid]) { |
|
|
3516 | $self->{tex} = $tex; |
3581 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3517 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3582 | } else { |
3518 | } else { |
3583 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3519 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3584 | $self->realloc; |
3520 | $self->realloc; |
3585 | }); |
3521 | }); |
… | |
… | |
3607 | } |
3543 | } |
3608 | |
3544 | |
3609 | sub _draw { |
3545 | sub _draw { |
3610 | my ($self) = @_; |
3546 | my ($self) = @_; |
3611 | |
3547 | |
3612 | return unless $::CONN; |
|
|
3613 | |
|
|
3614 | $self->SUPER::_draw; |
3548 | $self->SUPER::_draw; |
3615 | |
3549 | |
3616 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3550 | if (my $tex = $self->{tex}) { |
3617 | or return; |
|
|
3618 | |
|
|
3619 | my $tex = $::CONN->{texture}[$faceid]; |
|
|
3620 | |
|
|
3621 | if ($tex) { |
|
|
3622 | glEnable GL_TEXTURE_2D; |
3551 | glEnable GL_TEXTURE_2D; |
3623 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3552 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3624 | glColor 0, 0, 0, 1; |
3553 | glColor 0, 0, 0, 1; |
3625 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3554 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3626 | glDisable GL_TEXTURE_2D; |
3555 | glDisable GL_TEXTURE_2D; |
… | |
… | |
3836 | sub add { |
3765 | sub add { |
3837 | my ($self, $title, $widget, $tooltip) = @_; |
3766 | my ($self, $title, $widget, $tooltip) = @_; |
3838 | |
3767 | |
3839 | CFPlus::weaken $self; |
3768 | CFPlus::weaken $self; |
3840 | |
3769 | |
3841 | $self->{buttonbar}->add (new CFPlus::UI::Button |
3770 | unless (ref $title) { |
|
|
3771 | $title = new CFPlus::UI::Button |
3842 | markup => $title, |
3772 | markup => $title, |
3843 | tooltip => $tooltip, |
3773 | tooltip => $tooltip, |
|
|
3774 | ); |
|
|
3775 | } |
|
|
3776 | |
3844 | on_activate => sub { $self->set_current_page ($widget) }, |
3777 | $title->connect (activate => sub { $self->set_current_page ($widget) }); |
3845 | ); |
3778 | $self->{buttonbar}->add ($title); |
3846 | |
3779 | |
3847 | $self->{multiplexer}->add ($widget); |
3780 | $self->{multiplexer}->add ($widget); |
3848 | } |
3781 | } |
3849 | |
3782 | |
3850 | sub get_current_page { |
3783 | sub get_current_page { |
… | |
… | |
4182 | while ($self->{refresh_hook}) { |
4115 | while ($self->{refresh_hook}) { |
4183 | $_->() |
4116 | $_->() |
4184 | for values %{delete $self->{refresh_hook}}; |
4117 | for values %{delete $self->{refresh_hook}}; |
4185 | } |
4118 | } |
4186 | |
4119 | |
4187 | if ($self->{realloc}) { |
4120 | while ($self->{realloc}) { |
4188 | my %queue; |
4121 | my %queue; |
4189 | my @queue; |
4122 | my @queue; |
4190 | my $widget; |
4123 | my $widget; |
4191 | |
4124 | |
4192 | outer: |
4125 | outer: |
… | |
… | |
4239 | } |
4172 | } |
4240 | } |
4173 | } |
4241 | |
4174 | |
4242 | delete $self->{realloc}{$widget+0}; |
4175 | delete $self->{realloc}{$widget+0}; |
4243 | } |
4176 | } |
4244 | } |
|
|
4245 | |
4177 | |
4246 | while (my $size_alloc = delete $self->{size_alloc}) { |
4178 | while (my $size_alloc = delete $self->{size_alloc}) { |
4247 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4179 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4248 | values %$size_alloc; |
4180 | values %$size_alloc; |
4249 | |
4181 | |
4250 | while () { |
4182 | while () { |
4251 | my $widget = pop @queue || last; |
4183 | my $widget = pop @queue || last; |
4252 | |
4184 | |
4253 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4185 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4254 | |
4186 | |
4255 | $w = 0 if $w < 0; |
|
|
4256 | $h = 0 if $h < 0; |
|
|
4257 | |
|
|
4258 | $w = max $widget->{min_w}, $w; |
4187 | $w = max $widget->{min_w}, $w; |
4259 | $h = max $widget->{min_h}, $h; |
4188 | $h = max $widget->{min_h}, $h; |
4260 | |
4189 | |
4261 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4190 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4262 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4191 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4263 | |
4192 | |
4264 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4193 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4265 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4194 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4266 | |
4195 | |
4267 | $w = int $w + 0.5; |
4196 | $w = int $w + 0.5; |
4268 | $h = int $h + 0.5; |
4197 | $h = int $h + 0.5; |
4269 | |
4198 | |
4270 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4199 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4271 | $widget->{old_w} = $widget->{w}; |
4200 | $widget->{old_w} = $widget->{w}; |
4272 | $widget->{old_h} = $widget->{h}; |
4201 | $widget->{old_h} = $widget->{h}; |
4273 | |
4202 | |
4274 | $widget->{w} = $w; |
4203 | $widget->{w} = $w; |
4275 | $widget->{h} = $h; |
4204 | $widget->{h} = $h; |
4276 | |
4205 | |
4277 | $widget->emit (size_allocate => $w, $h); |
4206 | $widget->emit (size_allocate => $w, $h); |
|
|
4207 | } |
4278 | } |
4208 | } |
4279 | } |
4209 | } |
4280 | } |
4210 | } |
4281 | |
4211 | |
4282 | while ($self->{post_alloc_hook}) { |
4212 | while ($self->{post_alloc_hook}) { |