… | |
… | |
1536 | #font => default_font |
1536 | #font => default_font |
1537 | #text => initial text |
1537 | #text => initial text |
1538 | #markup => initial narkup |
1538 | #markup => initial narkup |
1539 | #max_w => maximum pixel width |
1539 | #max_w => maximum pixel width |
1540 | ellipsise => 3, # end |
1540 | ellipsise => 3, # end |
1541 | layout => (new CFClient::Layout), |
1541 | layout => (new CFClient::Layout 2), |
1542 | fontsize => 1, |
1542 | fontsize => 1, |
1543 | align => -1, |
1543 | align => -1, |
1544 | valign => -1, |
1544 | valign => -1, |
1545 | padding_x => 2, |
1545 | padding_x => 2, |
1546 | padding_y => 2, |
1546 | padding_y => 2, |
1547 | can_events => 0, |
1547 | can_events => 0, |
1548 | %arg |
1548 | %arg |
1549 | ); |
1549 | ); |
1550 | |
1550 | |
1551 | if (exists $self->{template}) { |
1551 | if (exists $self->{template}) { |
1552 | my $layout = new CFClient::Layout; |
1552 | my $layout = new CFClient::Layout 2; |
1553 | $layout->set_text (delete $self->{template}); |
1553 | $layout->set_text (delete $self->{template}); |
1554 | $self->{template} = $layout; |
1554 | $self->{template} = $layout; |
1555 | } |
1555 | } |
1556 | |
1556 | |
1557 | if (exists $self->{markup}) { |
1557 | if (exists $self->{markup}) { |
… | |
… | |
1591 | my ($self, $text) = @_; |
1591 | my ($self, $text) = @_; |
1592 | |
1592 | |
1593 | return if $self->{text} eq "T$text"; |
1593 | return if $self->{text} eq "T$text"; |
1594 | $self->{text} = "T$text"; |
1594 | $self->{text} = "T$text"; |
1595 | |
1595 | |
1596 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
|
|
1597 | $self->{layout}->set_text ($text); |
1596 | $self->{layout}->set_text ($text); |
1598 | |
1597 | |
1599 | delete $self->{size_req}; |
1598 | delete $self->{size_req}; |
1600 | $self->realloc; |
1599 | $self->realloc; |
1601 | $self->update; |
1600 | $self->update; |
… | |
… | |
1607 | return if $self->{text} eq "M$markup"; |
1606 | return if $self->{text} eq "M$markup"; |
1608 | $self->{text} = "M$markup"; |
1607 | $self->{text} = "M$markup"; |
1609 | |
1608 | |
1610 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1609 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1611 | |
1610 | |
1612 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
|
|
1613 | $self->{layout}->set_markup ($markup); |
1611 | $self->{layout}->set_markup ($markup); |
1614 | |
1612 | |
1615 | delete $self->{size_req}; |
1613 | delete $self->{size_req}; |
1616 | $self->realloc; |
1614 | $self->realloc; |
1617 | $self->update; |
1615 | $self->update; |
… | |
… | |
1672 | |
1670 | |
1673 | sub reconfigure { |
1671 | sub reconfigure { |
1674 | my ($self) = @_; |
1672 | my ($self) = @_; |
1675 | |
1673 | |
1676 | delete $self->{size_req}; |
1674 | delete $self->{size_req}; |
|
|
1675 | delete $self->{texture}; |
1677 | |
1676 | |
1678 | $self->SUPER::reconfigure; |
1677 | $self->SUPER::reconfigure; |
1679 | } |
1678 | } |
1680 | |
1679 | |
1681 | sub _draw { |
1680 | sub _draw { |
1682 | my ($self) = @_; |
1681 | my ($self) = @_; |
1683 | |
1682 | |
1684 | $self->SUPER::_draw; # draw background, if applicable |
1683 | $self->SUPER::_draw; # draw background, if applicable |
1685 | |
1684 | |
1686 | my $tex = $self->{texture} ||= do { |
1685 | my $size = $self->{texture} ||= do { |
1687 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1686 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1688 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1687 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1689 | $self->{layout}->set_width ($self->{w}); |
1688 | $self->{layout}->set_width ($self->{w}); |
1690 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1689 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1691 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1690 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1692 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1691 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1693 | |
1692 | |
1694 | new_from_layout CFClient::Texture $self->{layout} |
1693 | $self->{size_req} |
1695 | }; |
1694 | }; |
1696 | |
1695 | |
1697 | unless (exists $self->{ox}) { |
1696 | unless (exists $self->{ox}) { |
1698 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1697 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1699 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1698 | : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} |
1700 | : ($self->{w} - $tex->{w}) * 0.5); |
1699 | : ($self->{w} - $size->[0]) * 0.5); |
1701 | |
1700 | |
1702 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1701 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1703 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1702 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
1704 | : ($self->{h} - $tex->{h}) * 0.5); |
1703 | : ($self->{h} - $size->[1]) * 0.5); |
1705 | }; |
1704 | }; |
1706 | |
1705 | |
1707 | glEnable GL_TEXTURE_2D; |
|
|
1708 | |
|
|
1709 | my $w = List::Util::min $self->{w} + 4, $tex->{w}; |
1706 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
1710 | my $h = List::Util::min $self->{h} + 2, $tex->{h}; |
1707 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
1711 | |
1708 | |
1712 | if ($tex->{format} == GL_ALPHA) { |
1709 | $self->{layout}->render ($self->{ox}, $self->{oy}); |
1713 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1714 | glColor @{$self->{fg}}; |
|
|
1715 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h); |
|
|
1716 | } else { |
|
|
1717 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1718 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h); |
|
|
1719 | } |
|
|
1720 | |
|
|
1721 | glDisable GL_TEXTURE_2D; |
|
|
1722 | } |
1710 | } |
1723 | |
1711 | |
1724 | ############################################################################# |
1712 | ############################################################################# |
1725 | |
1713 | |
1726 | package CFClient::UI::EntryBase; |
1714 | package CFClient::UI::EntryBase; |
… | |
… | |
2573 | can_events => 0, |
2561 | can_events => 0, |
2574 | indent => 0, |
2562 | indent => 0, |
2575 | #font => default_font |
2563 | #font => default_font |
2576 | @_, |
2564 | @_, |
2577 | |
2565 | |
2578 | layout => (new CFClient::Layout 1), |
2566 | layout => (new CFClient::Layout 2), |
2579 | par => [], |
2567 | par => [], |
2580 | height => 0, |
2568 | height => 0, |
2581 | children => [ |
2569 | children => [ |
2582 | (new CFClient::UI::Empty expand => 1), |
2570 | (new CFClient::UI::Empty expand => 1), |
2583 | (new CFClient::UI::Slider vertical => 1), |
2571 | (new CFClient::UI::Slider vertical => 1), |
… | |
… | |
2744 | my $y0 = $top; |
2732 | my $y0 = $top; |
2745 | my $y1 = $top + $H; |
2733 | my $y1 = $top + $H; |
2746 | |
2734 | |
2747 | my $y = 0; |
2735 | my $y = 0; |
2748 | |
2736 | |
2749 | glEnable GL_BLEND; |
|
|
2750 | #TODO# not correct in windows where rgba is forced off |
|
|
2751 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2752 | |
|
|
2753 | for my $para (@{$self->{par}}) { |
2737 | for my $para (@{$self->{par}}) { |
2754 | my $h = $para->{h}; |
2738 | my $h = $para->{h}; |
2755 | |
2739 | |
2756 | if ($y0 < $y + $h && $y < $y1) { |
2740 | if ($y0 < $y + $h && $y < $y1) { |
2757 | |
2741 | |
2758 | my $layout = $self->get_layout ($para); |
2742 | my $layout = $self->get_layout ($para); |
2759 | |
2743 | |
2760 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
|
|
2761 | |
|
|
2762 | glRasterPos $para->{indent}, $y - $y0; |
2744 | $layout->render ($para->{indent}, $y - $y0); |
2763 | glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; |
|
|
2764 | |
2745 | |
2765 | if (my @w = @{ $para->{widget} }) { |
2746 | if (my @w = @{ $para->{widget} }) { |
2766 | my @s = $layout->get_shapes; |
2747 | my @s = $layout->get_shapes; |
2767 | |
2748 | |
2768 | glDisable GL_BLEND; |
|
|
2769 | for (@w) { |
2749 | for (@w) { |
2770 | my ($dx, $dy) = splice @s, 0, 2, (); |
2750 | my ($dx, $dy) = splice @s, 0, 2, (); |
2771 | |
2751 | |
2772 | $_->{x} = $dx + $para->{indent}; |
2752 | $_->{x} = $dx + $para->{indent}; |
2773 | $_->{y} = $dy + $y - $y0; |
2753 | $_->{y} = $dy + $y - $y0; |
2774 | |
2754 | |
2775 | $_->draw; |
2755 | $_->draw; |
2776 | } |
2756 | } |
2777 | glEnable GL_BLEND; |
|
|
2778 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2779 | } |
2757 | } |
2780 | } |
2758 | } |
2781 | |
2759 | |
2782 | $y += $h; |
2760 | $y += $h; |
2783 | } |
2761 | } |
2784 | |
|
|
2785 | glDisable GL_BLEND; |
|
|
2786 | }; |
2762 | }; |
2787 | }); |
2763 | }); |
2788 | } |
2764 | } |
2789 | |
2765 | |
2790 | sub reconfigure { |
2766 | sub reconfigure { |
… | |
… | |
3861 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
3837 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
3862 | (0, 0, $self->{w}, $self->{h}); |
3838 | (0, 0, $self->{w}, $self->{h}); |
3863 | } |
3839 | } |
3864 | |
3840 | |
3865 | $self->_draw; |
3841 | $self->_draw; |
|
|
3842 | |
|
|
3843 | #TODO#d# display texture cache |
|
|
3844 | { |
|
|
3845 | glEnable GL_TEXTURE_2D; |
|
|
3846 | glBindTexture GL_TEXTURE_2D, 41; |
|
|
3847 | glColor 1, 1, 1, 1; |
|
|
3848 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
3849 | glEnable GL_BLEND; |
|
|
3850 | glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
3851 | glBegin GL_QUADS; |
|
|
3852 | glTexCoord 0,1; glVertex 0,0; |
|
|
3853 | glTexCoord 1,1; glVertex 255,0; |
|
|
3854 | glTexCoord 1,0; glVertex 255,255; |
|
|
3855 | glTexCoord 0,0; glVertex 0,255; |
|
|
3856 | glEnd; |
|
|
3857 | glDisable GL_BLEND; |
|
|
3858 | glDisable GL_TEXTURE_2D; |
|
|
3859 | } |
|
|
3860 | |
3866 | } |
3861 | } |
3867 | |
3862 | |
3868 | ############################################################################# |
3863 | ############################################################################# |
3869 | |
3864 | |
3870 | package CFClient::UI; |
3865 | package CFClient::UI; |