… | |
… | |
371 | sub size_allocate { |
371 | sub size_allocate { |
372 | # nothing to be done |
372 | # nothing to be done |
373 | } |
373 | } |
374 | |
374 | |
375 | sub children { |
375 | sub children { |
|
|
376 | # nop |
|
|
377 | } |
|
|
378 | |
|
|
379 | sub visible_children { |
|
|
380 | $_[0]->children |
376 | } |
381 | } |
377 | |
382 | |
378 | sub set_max_size { |
383 | sub set_max_size { |
379 | my ($self, $w, $h) = @_; |
384 | my ($self, $w, $h) = @_; |
380 | |
385 | |
381 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
386 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
382 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
387 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
|
|
388 | |
|
|
389 | $self->realloc; |
383 | } |
390 | } |
384 | |
391 | |
385 | sub set_tooltip { |
392 | sub set_tooltip { |
386 | my ($self, $tooltip) = @_; |
393 | my ($self, $tooltip) = @_; |
387 | |
394 | |
… | |
… | |
543 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
550 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
544 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
551 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
545 | |
552 | |
546 | glPushMatrix; |
553 | glPushMatrix; |
547 | glTranslate $self->{x}, $self->{y}, 0; |
554 | glTranslate $self->{x}, $self->{y}, 0; |
548 | $self->_draw; |
|
|
549 | glPopMatrix; |
|
|
550 | |
555 | |
551 | if ($self == $HOVER && $self->{can_hover}) { |
556 | if ($self == $HOVER && $self->{can_hover}) { |
552 | my ($x, $y) = @$self{qw(x y)}; |
|
|
553 | |
|
|
554 | glColor 1, 0.8, 0.5, 0.2; |
557 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
555 | glEnable GL_BLEND; |
558 | glEnable GL_BLEND; |
556 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
559 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
557 | glBegin GL_QUADS; |
560 | glBegin GL_QUADS; |
558 | glVertex $x , $y; |
561 | glVertex 0 , 0; |
559 | glVertex $x + $self->{w}, $y; |
562 | glVertex $self->{w}, 0; |
560 | glVertex $x + $self->{w}, $y + $self->{h}; |
563 | glVertex $self->{w}, $self->{h}; |
561 | glVertex $x , $y + $self->{h}; |
564 | glVertex 0 , $self->{h}; |
562 | glEnd; |
565 | glEnd; |
563 | glDisable GL_BLEND; |
566 | glDisable GL_BLEND; |
564 | } |
567 | } |
565 | |
568 | |
566 | if ($ENV{CFPLUS_DEBUG} & 1) { |
569 | if ($ENV{CFPLUS_DEBUG} & 1) { |
567 | glPushMatrix; |
570 | glPushMatrix; |
568 | glColor 1, 1, 0, 1; |
571 | glColor 1, 1, 0, 1; |
569 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
572 | glTranslate 0.375, 0.375; |
570 | glBegin GL_LINE_LOOP; |
573 | glBegin GL_LINE_LOOP; |
571 | glVertex 0 , 0; |
574 | glVertex 0 , 0; |
572 | glVertex $self->{w} - 1, 0; |
575 | glVertex $self->{w} - 1, 0; |
573 | glVertex $self->{w} - 1, $self->{h} - 1; |
576 | glVertex $self->{w} - 1, $self->{h} - 1; |
574 | glVertex 0 , $self->{h} - 1; |
577 | glVertex 0 , $self->{h} - 1; |
575 | glEnd; |
578 | glEnd; |
576 | glPopMatrix; |
579 | glPopMatrix; |
577 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
580 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
578 | } |
581 | } |
|
|
582 | |
|
|
583 | $self->_draw; |
|
|
584 | glPopMatrix; |
579 | } |
585 | } |
580 | |
586 | |
581 | sub _draw { |
587 | sub _draw { |
582 | my ($self) = @_; |
588 | my ($self) = @_; |
583 | |
589 | |
… | |
… | |
621 | |
627 | |
622 | if ($color && (@$color < 4 || $color->[3])) { |
628 | if ($color && (@$color < 4 || $color->[3])) { |
623 | my ($w, $h) = @$self{qw(w h)}; |
629 | my ($w, $h) = @$self{qw(w h)}; |
624 | |
630 | |
625 | glEnable GL_BLEND; |
631 | glEnable GL_BLEND; |
626 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
632 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
627 | glColor @$color; |
633 | glColor_premultiply @$color; |
628 | |
634 | |
629 | glBegin GL_QUADS; |
635 | glBegin GL_QUADS; |
630 | glVertex 0 , 0; |
636 | glVertex 0 , 0; |
631 | glVertex 0 , $h; |
637 | glVertex 0 , $h; |
632 | glVertex $w, $h; |
638 | glVertex $w, $h; |
… | |
… | |
663 | our @ISA = CFClient::UI::Base::; |
669 | our @ISA = CFClient::UI::Base::; |
664 | |
670 | |
665 | sub new { |
671 | sub new { |
666 | my ($class, %arg) = @_; |
672 | my ($class, %arg) = @_; |
667 | |
673 | |
668 | my $children = delete $arg{children} || []; |
674 | my $children = delete $arg{children}; |
669 | |
675 | |
670 | my $self = $class->SUPER::new ( |
676 | my $self = $class->SUPER::new ( |
671 | children => [], |
677 | children => [], |
672 | can_events => 0, |
678 | can_events => 0, |
673 | %arg, |
679 | %arg, |
674 | ); |
680 | ); |
|
|
681 | |
675 | $self->add ($_) for @$children; |
682 | $self->add (@$children) |
|
|
683 | if $children; |
676 | |
684 | |
677 | $self |
685 | $self |
678 | } |
686 | } |
679 | |
687 | |
680 | sub add { |
688 | sub add { |
… | |
… | |
728 | $x -= $self->{x}; |
736 | $x -= $self->{x}; |
729 | $y -= $self->{y}; |
737 | $y -= $self->{y}; |
730 | |
738 | |
731 | my $res; |
739 | my $res; |
732 | |
740 | |
733 | for (reverse @{ $self->{children} }) { |
741 | for (reverse $self->visible_children) { |
734 | $res = $_->find_widget ($x, $y) |
742 | $res = $_->find_widget ($x, $y) |
735 | and return $res; |
743 | and return $res; |
736 | } |
744 | } |
737 | |
745 | |
738 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
746 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
… | |
… | |
787 | $self->{children}[0]->configure (0, 0, $w, $h); |
795 | $self->{children}[0]->configure (0, 0, $w, $h); |
788 | } |
796 | } |
789 | |
797 | |
790 | ############################################################################# |
798 | ############################################################################# |
791 | |
799 | |
|
|
800 | # back-buffered drawing area |
|
|
801 | |
792 | package CFClient::UI::Window; |
802 | package CFClient::UI::Window; |
793 | |
803 | |
794 | our @ISA = CFClient::UI::Bin::; |
804 | our @ISA = CFClient::UI::Bin::; |
795 | |
805 | |
796 | use CFClient::OpenGL; |
806 | use CFClient::OpenGL; |
… | |
… | |
847 | my $tex = $self->{texture} |
857 | my $tex = $self->{texture} |
848 | or return; |
858 | or return; |
849 | |
859 | |
850 | glEnable GL_TEXTURE_2D; |
860 | glEnable GL_TEXTURE_2D; |
851 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
861 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
852 | glColor 1, 1, 1, 1; |
862 | glColor 0, 0, 0, 1; |
853 | |
863 | |
854 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
864 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
855 | |
865 | |
856 | glDisable GL_TEXTURE_2D; |
866 | glDisable GL_TEXTURE_2D; |
857 | } |
867 | } |
… | |
… | |
948 | package CFClient::UI::ScrolledWindow; |
958 | package CFClient::UI::ScrolledWindow; |
949 | |
959 | |
950 | our @ISA = CFClient::UI::HBox::; |
960 | our @ISA = CFClient::UI::HBox::; |
951 | |
961 | |
952 | sub new { |
962 | sub new { |
953 | my $class = shift; |
963 | my ($class, %arg) = @_; |
|
|
964 | |
|
|
965 | my $child = delete $arg{child}; |
954 | |
966 | |
955 | my $self; |
967 | my $self; |
956 | |
968 | |
957 | my $slider = new CFClient::UI::Slider |
969 | my $slider = new CFClient::UI::Slider |
958 | vertical => 1, |
970 | vertical => 1, |
… | |
… | |
963 | ; |
975 | ; |
964 | |
976 | |
965 | $self = $class->SUPER::new ( |
977 | $self = $class->SUPER::new ( |
966 | vp => (new CFClient::UI::ViewPort expand => 1), |
978 | vp => (new CFClient::UI::ViewPort expand => 1), |
967 | slider => $slider, |
979 | slider => $slider, |
968 | @_, |
980 | %arg, |
969 | ); |
981 | ); |
970 | |
982 | |
971 | $self->{vp}->add ($self->{scrolled}); |
|
|
972 | $self->add ($self->{vp}); |
|
|
973 | $self->add ($self->{slider}); |
983 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
|
|
984 | $self->add ($child) if $child; |
974 | |
985 | |
975 | $self |
986 | $self |
|
|
987 | } |
|
|
988 | |
|
|
989 | sub add { |
|
|
990 | my ($self, $widget) = @_; |
|
|
991 | |
|
|
992 | $self->{vp}->add ($self->{child} = $widget); |
976 | } |
993 | } |
977 | |
994 | |
978 | sub update { |
995 | sub update { |
979 | my ($self) = @_; |
996 | my ($self) = @_; |
980 | |
997 | |
… | |
… | |
1019 | |
1036 | |
1020 | if ($self->{bg}) { |
1037 | if ($self->{bg}) { |
1021 | my ($w, $h) = @$self{qw(w h)}; |
1038 | my ($w, $h) = @$self{qw(w h)}; |
1022 | |
1039 | |
1023 | glEnable GL_BLEND; |
1040 | glEnable GL_BLEND; |
1024 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1041 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1025 | glColor @{ $self->{bg} }; |
1042 | glColor_premultiply @{ $self->{bg} }; |
1026 | |
1043 | |
1027 | glBegin GL_QUADS; |
1044 | glBegin GL_QUADS; |
1028 | glVertex 0 , 0; |
1045 | glVertex 0 , 0; |
1029 | glVertex 0 , $h; |
1046 | glVertex 0 , $h; |
1030 | glVertex $w, $h; |
1047 | glVertex $w, $h; |
… | |
… | |
1144 | my $dy = $ev->{y} - $oy; |
1161 | my $dy = $ev->{y} - $oy; |
1145 | |
1162 | |
1146 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1163 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1147 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1164 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1148 | |
1165 | |
|
|
1166 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
1149 | $self->realloc; |
1167 | $self->realloc; |
1150 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
|
|
1151 | }; |
1168 | }; |
1152 | |
1169 | |
1153 | } elsif ($lr ^ $td) { |
1170 | } elsif ($lr ^ $td) { |
1154 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1171 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1155 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1172 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1158 | my ($ev, $x, $y) = @_; |
1175 | my ($ev, $x, $y) = @_; |
1159 | |
1176 | |
1160 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1177 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1161 | |
1178 | |
1162 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1179 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
|
|
1180 | # HACK: the next line is required to enforce placement |
|
|
1181 | $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h}); |
1163 | }; |
1182 | }; |
1164 | } else { |
1183 | } else { |
1165 | return 0; |
1184 | return 0; |
1166 | } |
1185 | } |
1167 | |
1186 | |
… | |
… | |
1618 | }; |
1637 | }; |
1619 | |
1638 | |
1620 | glEnable GL_TEXTURE_2D; |
1639 | glEnable GL_TEXTURE_2D; |
1621 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1640 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1622 | |
1641 | |
|
|
1642 | glColor_premultiply @{$self->{fg}} |
1623 | if ($tex->{format} == GL_ALPHA) { |
1643 | if $tex->{format} == GL_ALPHA; |
1624 | glColor @{$self->{fg}}; |
1644 | |
1625 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
|
|
1626 | } else { |
|
|
1627 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1645 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1628 | } |
|
|
1629 | |
1646 | |
1630 | glDisable GL_TEXTURE_2D; |
1647 | glDisable GL_TEXTURE_2D; |
1631 | } |
1648 | } |
1632 | |
1649 | |
1633 | ############################################################################# |
1650 | ############################################################################# |
… | |
… | |
1660 | |
1677 | |
1661 | delete $self->{cur_h}; |
1678 | delete $self->{cur_h}; |
1662 | |
1679 | |
1663 | return if $self->{text} eq $text; |
1680 | return if $self->{text} eq $text; |
1664 | |
1681 | |
1665 | delete $self->{texture}; |
|
|
1666 | |
|
|
1667 | $self->{last_activity} = $::NOW; |
1682 | $self->{last_activity} = $::NOW; |
1668 | $self->{text} = $text; |
1683 | $self->{text} = $text; |
1669 | |
1684 | |
1670 | $text =~ s/./*/g if $self->{hidden}; |
1685 | $text =~ s/./*/g if $self->{hidden}; |
1671 | $self->{layout}->set_text ("$text "); |
1686 | $self->{layout}->set_text ("$text "); |
1672 | |
1687 | |
1673 | $self->_emit (changed => $self->{text}); |
1688 | $self->_emit (changed => $self->{text}); |
|
|
1689 | $self->update; |
1674 | } |
1690 | } |
1675 | |
1691 | |
1676 | sub set_text { |
1692 | sub set_text { |
1677 | my ($self, $text) = @_; |
1693 | my ($self, $text) = @_; |
1678 | |
1694 | |
… | |
… | |
1767 | my ($self) = @_; |
1783 | my ($self) = @_; |
1768 | |
1784 | |
1769 | local $self->{fg} = $self->{fg}; |
1785 | local $self->{fg} = $self->{fg}; |
1770 | |
1786 | |
1771 | if ($FOCUS == $self) { |
1787 | if ($FOCUS == $self) { |
1772 | glColor @{$self->{active_bg}}; |
1788 | glColor_premultiply @{$self->{active_bg}}; |
1773 | $self->{fg} = $self->{active_fg}; |
1789 | $self->{fg} = $self->{active_fg}; |
1774 | } else { |
1790 | } else { |
1775 | glColor @{$self->{bg}}; |
1791 | glColor_premultiply @{$self->{bg}}; |
1776 | } |
1792 | } |
1777 | |
1793 | |
1778 | glEnable GL_BLEND; |
1794 | glEnable GL_BLEND; |
1779 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1795 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1780 | glBegin GL_QUADS; |
1796 | glBegin GL_QUADS; |
1781 | glVertex 0 , 0; |
1797 | glVertex 0 , 0; |
1782 | glVertex 0 , $self->{h}; |
1798 | glVertex 0 , $self->{h}; |
1783 | glVertex $self->{w}, $self->{h}; |
1799 | glVertex $self->{w}, $self->{h}; |
1784 | glVertex $self->{w}, 0; |
1800 | glVertex $self->{w}, 0; |
… | |
… | |
1894 | } |
1910 | } |
1895 | |
1911 | |
1896 | sub _draw { |
1912 | sub _draw { |
1897 | my ($self) = @_; |
1913 | my ($self) = @_; |
1898 | |
1914 | |
1899 | local $self->{fg} = $self->{fg}; |
1915 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
1900 | |
|
|
1901 | if ($GRAB == $self) { |
|
|
1902 | $self->{fg} = $self->{active_fg}; |
|
|
1903 | } |
|
|
1904 | |
1916 | |
1905 | glEnable GL_TEXTURE_2D; |
1917 | glEnable GL_TEXTURE_2D; |
1906 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1918 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1907 | glColor 0, 0, 0, 1; |
1919 | glColor 0, 0, 0, 1; |
1908 | |
1920 | |
… | |
… | |
2133 | |
2145 | |
2134 | my $h1 = $self->{h} * (1 - $ycut1); |
2146 | my $h1 = $self->{h} * (1 - $ycut1); |
2135 | my $h2 = $self->{h} * (1 - $ycut2); |
2147 | my $h2 = $self->{h} * (1 - $ycut2); |
2136 | |
2148 | |
2137 | glEnable GL_BLEND; |
2149 | glEnable GL_BLEND; |
2138 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2150 | glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
2151 | GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2139 | glEnable GL_TEXTURE_2D; |
2152 | glEnable GL_TEXTURE_2D; |
2140 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2153 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2141 | |
2154 | |
2142 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
2155 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
2143 | glBegin GL_QUADS; |
2156 | glBegin GL_QUADS; |
… | |
… | |
2328 | } |
2341 | } |
2329 | |
2342 | |
2330 | sub update { |
2343 | sub update { |
2331 | my ($self) = @_; |
2344 | my ($self) = @_; |
2332 | |
2345 | |
2333 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2346 | delete $self->{knob_w}; |
|
|
2347 | $self->SUPER::update; |
|
|
2348 | } |
|
|
2349 | |
|
|
2350 | sub _draw { |
|
|
2351 | my ($self) = @_; |
|
|
2352 | |
|
|
2353 | unless ($self->{knob_w}) { |
2334 | $self->set_value ($self->{range}[0]); |
2354 | $self->set_value ($self->{range}[0]); |
2335 | |
2355 | |
2336 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2356 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2337 | my $range = ($hi - $page - $lo) || 1e-100; |
2357 | my $range = ($hi - $page - $lo) || 1e-100; |
2338 | |
2358 | |
… | |
… | |
2344 | $value = ($value - $lo) / $range; |
2364 | $value = ($value - $lo) / $range; |
2345 | $value = $value * $self->{scale} + $self->{offset}; |
2365 | $value = $value * $self->{scale} + $self->{offset}; |
2346 | |
2366 | |
2347 | $self->{knob_x} = $value - $knob_w * 0.5; |
2367 | $self->{knob_x} = $value - $knob_w * 0.5; |
2348 | $self->{knob_w} = $knob_w; |
2368 | $self->{knob_w} = $knob_w; |
2349 | }); |
2369 | } |
2350 | |
|
|
2351 | $self->SUPER::update; |
|
|
2352 | } |
|
|
2353 | |
|
|
2354 | sub _draw { |
|
|
2355 | my ($self) = @_; |
|
|
2356 | |
2370 | |
2357 | $self->SUPER::_draw (); |
2371 | $self->SUPER::_draw (); |
2358 | |
2372 | |
2359 | glScale $self->{w}, $self->{h}; |
2373 | glScale $self->{w}, $self->{h}; |
2360 | |
2374 | |
… | |
… | |
2554 | |
2568 | |
2555 | delete $self->{texture}; |
2569 | delete $self->{texture}; |
2556 | } |
2570 | } |
2557 | |
2571 | |
2558 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2572 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2559 | glClearColor 0.5, 0.5, 0.5, 0; |
2573 | glClearColor 0, 0, 0, 0; |
2560 | glClear GL_COLOR_BUFFER_BIT; |
2574 | glClear GL_COLOR_BUFFER_BIT; |
2561 | |
2575 | |
2562 | my $top = int $self->{children}[1]{range}[0]; |
2576 | my $top = int $self->{children}[1]{range}[0]; |
2563 | |
2577 | |
2564 | my $y0 = $top; |
2578 | my $y0 = $top; |
… | |
… | |
2599 | sub _draw { |
2613 | sub _draw { |
2600 | my ($self) = @_; |
2614 | my ($self) = @_; |
2601 | |
2615 | |
2602 | glEnable GL_TEXTURE_2D; |
2616 | glEnable GL_TEXTURE_2D; |
2603 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2617 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2604 | glColor 1, 1, 1, 1; |
2618 | glColor 0, 0, 0, 1; |
2605 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2619 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2606 | glDisable GL_TEXTURE_2D; |
2620 | glDisable GL_TEXTURE_2D; |
2607 | |
2621 | |
2608 | $self->{children}[1]->draw; |
2622 | $self->{children}[1]->draw; |
2609 | |
2623 | |
2610 | } |
2624 | } |
… | |
… | |
2837 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2851 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2838 | |
2852 | |
2839 | if ($tex) { |
2853 | if ($tex) { |
2840 | glEnable GL_TEXTURE_2D; |
2854 | glEnable GL_TEXTURE_2D; |
2841 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2855 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2842 | glColor 1, 1, 1, 1; |
2856 | glColor 0, 0, 0, 1; |
2843 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2857 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2844 | glDisable GL_TEXTURE_2D; |
2858 | glDisable GL_TEXTURE_2D; |
2845 | } |
2859 | } |
2846 | } |
2860 | } |
2847 | |
2861 | |
… | |
… | |
2851 | $self->{timer}->cancel |
2865 | $self->{timer}->cancel |
2852 | if $self->{timer}; |
2866 | if $self->{timer}; |
2853 | |
2867 | |
2854 | $self->SUPER::DESTROY; |
2868 | $self->SUPER::DESTROY; |
2855 | } |
2869 | } |
|
|
2870 | |
|
|
2871 | ############################################################################# |
|
|
2872 | |
|
|
2873 | package CFClient::UI::Buttonbar; |
|
|
2874 | |
|
|
2875 | our @ISA = CFClient::UI::HBox::; |
|
|
2876 | |
|
|
2877 | # TODO: should actualyl wrap buttons and other goodies. |
2856 | |
2878 | |
2857 | ############################################################################# |
2879 | ############################################################################# |
2858 | |
2880 | |
2859 | package CFClient::UI::Menu; |
2881 | package CFClient::UI::Menu; |
2860 | |
2882 | |
… | |
… | |
2932 | 1 |
2954 | 1 |
2933 | } |
2955 | } |
2934 | |
2956 | |
2935 | ############################################################################# |
2957 | ############################################################################# |
2936 | |
2958 | |
2937 | package CFClient::UI::Statusbox; |
2959 | package CFClient::UI::Multiplexer; |
2938 | |
2960 | |
2939 | our @ISA = CFClient::UI::VBox::; |
2961 | our @ISA = CFClient::UI::Container::; |
2940 | |
2962 | |
2941 | sub new { |
2963 | sub new { |
2942 | my $class = shift; |
2964 | my $class = shift; |
2943 | |
2965 | |
2944 | $class->SUPER::new ( |
2966 | my $self = $class->SUPER::new ( |
|
|
2967 | @_, |
|
|
2968 | ); |
|
|
2969 | |
|
|
2970 | $self->{current} = $self->{children}[0] |
|
|
2971 | if @{ $self->{children} }; |
|
|
2972 | |
|
|
2973 | $self |
|
|
2974 | } |
|
|
2975 | |
|
|
2976 | sub add { |
|
|
2977 | my ($self, @widgets) = @_; |
|
|
2978 | |
|
|
2979 | $self->SUPER::add (@widgets); |
|
|
2980 | |
|
|
2981 | $self->{current} = $self->{children}[0] |
|
|
2982 | if @{ $self->{children} }; |
|
|
2983 | } |
|
|
2984 | |
|
|
2985 | sub set_current_page { |
|
|
2986 | my ($self, $page_or_widget) = @_; |
|
|
2987 | |
|
|
2988 | my $widget = ref $page_or_widget |
|
|
2989 | ? $page_or_widget |
|
|
2990 | : $self->{children}[$page_or_widget]; |
|
|
2991 | |
|
|
2992 | $self->{current} = $widget; |
|
|
2993 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
2994 | |
|
|
2995 | $self->_emit (page_changed => $self->{current}); |
|
|
2996 | |
|
|
2997 | $self->realloc; |
|
|
2998 | } |
|
|
2999 | |
|
|
3000 | sub visible_children { |
|
|
3001 | $_[0]{current} |
|
|
3002 | } |
|
|
3003 | |
|
|
3004 | sub size_request { |
|
|
3005 | my ($self) = @_; |
|
|
3006 | |
|
|
3007 | $self->{current}->size_request |
|
|
3008 | } |
|
|
3009 | |
|
|
3010 | sub size_allocate { |
|
|
3011 | my ($self, $w, $h) = @_; |
|
|
3012 | |
|
|
3013 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3014 | } |
|
|
3015 | |
|
|
3016 | sub _draw { |
|
|
3017 | my ($self) = @_; |
|
|
3018 | |
|
|
3019 | $self->{current}->draw; |
|
|
3020 | } |
|
|
3021 | |
|
|
3022 | ############################################################################# |
|
|
3023 | |
|
|
3024 | package CFClient::UI::Notebook; |
|
|
3025 | |
|
|
3026 | our @ISA = CFClient::UI::VBox::; |
|
|
3027 | |
|
|
3028 | sub new { |
|
|
3029 | my $class = shift; |
|
|
3030 | |
|
|
3031 | my $self = $class->SUPER::new ( |
|
|
3032 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3033 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3034 | # filter => # will be put between multiplexer and $self |
|
|
3035 | @_, |
|
|
3036 | ); |
|
|
3037 | |
|
|
3038 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
|
|
3039 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
|
|
3040 | |
|
|
3041 | $self |
|
|
3042 | } |
|
|
3043 | |
|
|
3044 | sub add { |
|
|
3045 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3046 | |
|
|
3047 | Scalar::Util::weaken $self; |
|
|
3048 | |
|
|
3049 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3050 | markup => $title, |
|
|
3051 | tooltip => $tooltip, |
|
|
3052 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3053 | ); |
|
|
3054 | |
|
|
3055 | $self->{multiplexer}->add ($widget); |
|
|
3056 | } |
|
|
3057 | |
|
|
3058 | sub set_current_page { |
|
|
3059 | my ($self, $page) = @_; |
|
|
3060 | |
|
|
3061 | $self->{multiplexer}->set_current_page ($page); |
|
|
3062 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
|
|
3063 | } |
|
|
3064 | |
|
|
3065 | ############################################################################# |
|
|
3066 | |
|
|
3067 | package CFClient::UI::Statusbox; |
|
|
3068 | |
|
|
3069 | our @ISA = CFClient::UI::VBox::; |
|
|
3070 | |
|
|
3071 | sub new { |
|
|
3072 | my $class = shift; |
|
|
3073 | |
|
|
3074 | my $self = $class->SUPER::new ( |
2945 | fontsize => 0.8, |
3075 | fontsize => 0.8, |
2946 | @_, |
3076 | @_, |
2947 | ) |
3077 | ); |
|
|
3078 | |
|
|
3079 | Scalar::Util::weaken (my $this = $self); |
|
|
3080 | |
|
|
3081 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { |
|
|
3082 | $this->reorder; |
|
|
3083 | $this->update; |
|
|
3084 | }); |
|
|
3085 | |
|
|
3086 | $self |
2948 | } |
3087 | } |
2949 | |
3088 | |
2950 | sub reorder { |
3089 | sub reorder { |
2951 | my ($self) = @_; |
3090 | my ($self) = @_; |
2952 | my $NOW = time; |
3091 | my $NOW = Time::HiRes::time; |
2953 | |
3092 | |
2954 | while (my ($k, $v) = each %{ $self->{item} }) { |
3093 | while (my ($k, $v) = each %{ $self->{item} }) { |
2955 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3094 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
2956 | } |
3095 | } |
2957 | |
3096 | |
… | |
… | |
2959 | |
3098 | |
2960 | my @items = sort { |
3099 | my @items = sort { |
2961 | $a->{pri} <=> $b->{pri} |
3100 | $a->{pri} <=> $b->{pri} |
2962 | or $b->{id} <=> $a->{id} |
3101 | or $b->{id} <=> $a->{id} |
2963 | } values %{ $self->{item} }; |
3102 | } values %{ $self->{item} }; |
|
|
3103 | |
|
|
3104 | $self->{timer}->interval (1); |
2964 | |
3105 | |
2965 | my $count = 10 + 1; |
3106 | my $count = 10 + 1; |
2966 | for my $item (@items) { |
3107 | for my $item (@items) { |
2967 | last unless --$count; |
3108 | last unless --$count; |
2968 | |
3109 | |
… | |
… | |
2983 | tooltip_font => $::FONT_PROP, |
3124 | tooltip_font => $::FONT_PROP, |
2984 | tooltip_width => 0.67, |
3125 | tooltip_width => 0.67, |
2985 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3126 | fontsize => $item->{fontsize} || $self->{fontsize}, |
2986 | max_w => $::WIDTH * 0.44, |
3127 | max_w => $::WIDTH * 0.44, |
2987 | fg => $item->{fg}, |
3128 | fg => $item->{fg}, |
|
|
3129 | orig_alpha => $item->{fg}[3] || 1, |
2988 | can_events => 1, |
3130 | can_events => 1, |
2989 | can_hover => 1 |
3131 | can_hover => 1 |
2990 | }; |
3132 | }; |
|
|
3133 | |
|
|
3134 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
|
|
3135 | $item->{label}{fg}[3] = $item->{label}{orig_alpha} * $diff / 2; |
|
|
3136 | if ($diff < 1) { |
|
|
3137 | $item->{label}{max_h} = $item->{label}{req_h} * $diff; |
|
|
3138 | $item->{label}->realloc; |
|
|
3139 | } |
|
|
3140 | $item->{label}->update; |
|
|
3141 | $self->{timer}->interval (1/30); |
|
|
3142 | } |
2991 | } |
3143 | } |
2992 | |
3144 | |
2993 | $self->clear; |
3145 | $self->clear; |
2994 | $self->SUPER::add (reverse @widgets); |
3146 | $self->SUPER::add (reverse @widgets); |
2995 | } |
3147 | } |
… | |
… | |
3000 | $text =~ s/^\s+//; |
3152 | $text =~ s/^\s+//; |
3001 | $text =~ s/\s+$//; |
3153 | $text =~ s/\s+$//; |
3002 | |
3154 | |
3003 | return unless $text; |
3155 | return unless $text; |
3004 | |
3156 | |
3005 | my $timeout = time + ((delete $arg{timeout}) || 60); |
3157 | my $timeout = (int time) + ((delete $arg{timeout}) || 60); |
3006 | |
3158 | |
3007 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3159 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3008 | |
3160 | |
3009 | if (my $item = $self->{item}{$group}) { |
3161 | if (my $item = $self->{item}{$group}) { |
3010 | if ($item->{text} eq $text) { |
3162 | if ($item->{text} eq $text) { |
… | |
… | |
3040 | |
3192 | |
3041 | $self->reorder; |
3193 | $self->reorder; |
3042 | $self->SUPER::reconfigure; |
3194 | $self->SUPER::reconfigure; |
3043 | } |
3195 | } |
3044 | |
3196 | |
|
|
3197 | sub DESTROY { |
|
|
3198 | my ($self) = @_; |
|
|
3199 | |
|
|
3200 | $self->{timer}->cancel; |
|
|
3201 | |
|
|
3202 | $self->SUPER::DESTROY; |
|
|
3203 | } |
|
|
3204 | |
3045 | ############################################################################# |
3205 | ############################################################################# |
3046 | |
3206 | |
3047 | package CFClient::UI::Inventory; |
3207 | package CFClient::UI::Inventory; |
3048 | |
3208 | |
3049 | our @ISA = CFClient::UI::ScrolledWindow::; |
3209 | our @ISA = CFClient::UI::ScrolledWindow::; |
3050 | |
3210 | |
3051 | sub new { |
3211 | sub new { |
3052 | my $class = shift; |
3212 | my $class = shift; |
3053 | |
3213 | |
3054 | my $self = $class->SUPER::new ( |
3214 | my $self = $class->SUPER::new ( |
3055 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3215 | child => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3056 | @_, |
3216 | @_, |
3057 | ); |
3217 | ); |
3058 | |
3218 | |
3059 | $self |
3219 | $self |
3060 | } |
3220 | } |
3061 | |
3221 | |
3062 | sub set_items { |
3222 | sub set_items { |
3063 | my ($self, $items) = @_; |
3223 | my ($self, $items) = @_; |
3064 | |
3224 | |
3065 | $self->{scrolled}->clear; |
3225 | $self->{child}->clear; |
3066 | return unless $items; |
3226 | return unless $items; |
3067 | |
3227 | |
3068 | my @items = sort { |
3228 | my @items = sort { |
3069 | ($a->{type} <=> $b->{type}) |
3229 | ($a->{type} <=> $b->{type}) |
3070 | or ($a->{name} cmp $b->{name}) |
3230 | or ($a->{name} cmp $b->{name}) |
… | |
… | |
3074 | |
3234 | |
3075 | my $row = 0; |
3235 | my $row = 0; |
3076 | for my $item (@items) { |
3236 | for my $item (@items) { |
3077 | CFClient::Item::update_widgets $item; |
3237 | CFClient::Item::update_widgets $item; |
3078 | |
3238 | |
3079 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
3239 | $self->{child}->add (0, $row, $item->{face_widget}); |
3080 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
3240 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3081 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
3241 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3082 | |
3242 | |
3083 | $row++; |
3243 | $row++; |
3084 | } |
3244 | } |
3085 | } |
3245 | } |
3086 | |
3246 | |
… | |
… | |
3283 | |
3443 | |
3284 | ############################################################################# |
3444 | ############################################################################# |
3285 | |
3445 | |
3286 | package CFClient::UI::SpellList; |
3446 | package CFClient::UI::SpellList; |
3287 | |
3447 | |
3288 | our @ISA = CFClient::UI::FancyFrame::; |
3448 | our @ISA = CFClient::UI::Table::; |
3289 | |
3449 | |
3290 | sub new { |
3450 | sub new { |
3291 | my $class = shift; |
3451 | my $class = shift; |
3292 | |
3452 | |
3293 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3453 | my $self = $class->SUPER::new ( |
3294 | |
3454 | binding => [], |
3295 | $self->add (new CFClient::UI::ScrolledWindow |
3455 | commands => [], |
3296 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3456 | @_, |
3297 | |
3457 | ) |
3298 | $self; |
|
|
3299 | } |
3458 | } |
3300 | |
3459 | |
3301 | # XXX: Do sorting? Argl... |
3460 | # XXX: Do sorting? Argl... |
3302 | sub add_spell { |
3461 | sub add_spell { |
3303 | my ($self, $spell) = @_; |
3462 | my ($self, $spell) = @_; |
3304 | $self->{spells}->{$spell->{name}} = $spell; |
3463 | $self->{spells}->{$spell->{name}} = $spell; |
3305 | |
3464 | |
3306 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3465 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3307 | face => $spell->{face}, |
3466 | face => $spell->{face}, |
3308 | can_hover => 1, |
3467 | can_hover => 1, |
3309 | can_events => 1, |
3468 | can_events => 1, |
3310 | tooltip => $spell->{message}); |
3469 | tooltip => $spell->{message}); |
3311 | |
3470 | |
3312 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3471 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3313 | text => $spell->{name}, |
3472 | text => $spell->{name}, |
3314 | can_hover => 1, |
3473 | can_hover => 1, |
3315 | can_events => 1, |
3474 | can_events => 1, |
3316 | tooltip => $spell->{message}, |
3475 | tooltip => $spell->{message}, |
3317 | expand => 1); |
3476 | expand => 1); |
3318 | |
3477 | |
3319 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3478 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3320 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3479 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3321 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3480 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3322 | expand => 1); |
3481 | expand => 1); |
3323 | |
3482 | |
3324 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3483 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3325 | text => "bind to key", |
3484 | text => "bind to key", |
3326 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3485 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3327 | } |
3486 | } |
3328 | |
3487 | |
3329 | sub rebuild_spell_list { |
3488 | sub rebuild_spell_list { |
… | |
… | |
3341 | ############################################################################# |
3500 | ############################################################################# |
3342 | |
3501 | |
3343 | package CFClient::UI::Root; |
3502 | package CFClient::UI::Root; |
3344 | |
3503 | |
3345 | our @ISA = CFClient::UI::Container::; |
3504 | our @ISA = CFClient::UI::Container::; |
|
|
3505 | |
|
|
3506 | use List::Util qw(min max); |
3346 | |
3507 | |
3347 | use CFClient::OpenGL; |
3508 | use CFClient::OpenGL; |
3348 | |
3509 | |
3349 | sub new { |
3510 | sub new { |
3350 | my $class = shift; |
3511 | my $class = shift; |
… | |
… | |
3485 | |
3646 | |
3486 | delete $queue{$widget+0}; |
3647 | delete $queue{$widget+0}; |
3487 | |
3648 | |
3488 | my ($w, $h) = $widget->size_request; |
3649 | my ($w, $h) = $widget->size_request; |
3489 | |
3650 | |
3490 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3651 | $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3491 | $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
3652 | $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
|
|
3653 | |
|
|
3654 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
|
|
3655 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
3492 | |
3656 | |
3493 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3657 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3494 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3658 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3495 | |
3659 | |
3496 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |
3660 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |