ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.319 by root, Sun Jul 2 21:07:26 2006 UTC vs.
Revision 1.328 by root, Sat Jul 22 13:43:05 2006 UTC

82} 82}
83 83
84sub feed_sdl_button_down_event { 84sub feed_sdl_button_down_event {
85 my ($ev) = @_; 85 my ($ev) = @_;
86 my ($x, $y) = ($ev->{x}, $ev->{y}); 86 my ($x, $y) = ($ev->{x}, $ev->{y});
87
88 warn "button down $ev->{button}\n";#d#
87 89
88 if (!$BUTTON_STATE) { 90 if (!$BUTTON_STATE) {
89 my $widget = $ROOT->find_widget ($x, $y); 91 my $widget = $ROOT->find_widget ($x, $y);
90 92
91 $GRAB = $widget; 93 $GRAB = $widget;
452 454
453 $FOCUS->emit ("focus_out") if $FOCUS; 455 $FOCUS->emit ("focus_out") if $FOCUS;
454 $self->emit ("focus_in"); 456 $self->emit ("focus_in");
455} 457}
456 458
457sub invoke_mouse_motion { 1 } 459sub invoke_mouse_motion { 0 }
458sub invoke_button_up { 1 } 460sub invoke_button_up { 0 }
459sub invoke_key_down { 1 } 461sub invoke_key_down { 0 }
460sub invoke_key_up { 1 } 462sub invoke_key_up { 0 }
461 463
462sub invoke_button_down { 464sub invoke_button_down {
463 my ($self, $ev, $x, $y) = @_; 465 my ($self, $ev, $x, $y) = @_;
464 466
465 $self->grab_focus; 467 $self->grab_focus;
466 468
469 warn "button down $ev->{button} $x $y\n";#d#
470
467 1 471 0
468} 472}
469 473
470sub connect { 474sub connect {
471 my ($self, $signal, $cb) = @_; 475 my ($self, $signal, $cb) = @_;
472 476
587} 591}
588 592
589sub DESTROY { 593sub DESTROY {
590 my ($self) = @_; 594 my ($self) = @_;
591 595
596 return if CFClient::in_destruct;
597
592 delete $WIDGET{$self+0}; 598 delete $WIDGET{$self+0};
593 599
594 eval { $self->destroy }; 600 eval { $self->destroy };
595 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 601 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
596} 602}
994 my ($self, $widget) = @_; 1000 my ($self, $widget) = @_;
995 1001
996 $self->{vp}->add ($self->{child} = $widget); 1002 $self->{vp}->add ($self->{child} = $widget);
997} 1003}
998 1004
1005sub invoke_button_down {
1006 my ($self, $ev) = @_;
1007
1008 warn "button down $ev->{button}\n";#d#
1009
1010 0
1011}
1012
999sub update_slider { 1013sub update_slider {
1000 my ($self) = @_; 1014 my ($self) = @_;
1001 1015
1002 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); 1016 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]);
1003} 1017}
1080 my $self = $class->SUPER::new ( 1094 my $self = $class->SUPER::new (
1081 bg => [1, 1, 1, 1], 1095 bg => [1, 1, 1, 1],
1082 border_bg => [1, 1, 1, 1], 1096 border_bg => [1, 1, 1, 1],
1083 border => 0.6, 1097 border => 0.6,
1084 can_events => 1, 1098 can_events => 1,
1085 min_w => 16, 1099 min_w => 64,
1086 min_h => 16, 1100 min_h => 32,
1087 %arg, 1101 %arg,
1088 ); 1102 );
1089 1103
1090 $self->{title_widget} = new CFClient::UI::Label 1104 $self->{title_widget} = new CFClient::UI::Label
1091 align => 0, 1105 align => 0,
1591 my ($self, $text) = @_; 1605 my ($self, $text) = @_;
1592 1606
1593 return if $self->{text} eq "T$text"; 1607 return if $self->{text} eq "T$text";
1594 $self->{text} = "T$text"; 1608 $self->{text} = "T$text";
1595 1609
1596 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1597 $self->{layout}->set_text ($text); 1610 $self->{layout}->set_text ($text);
1598 1611
1599 delete $self->{size_req}; 1612 delete $self->{size_req};
1600 $self->realloc; 1613 $self->realloc;
1601 $self->update; 1614 $self->update;
1607 return if $self->{text} eq "M$markup"; 1620 return if $self->{text} eq "M$markup";
1608 $self->{text} = "M$markup"; 1621 $self->{text} = "M$markup";
1609 1622
1610 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1623 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1611 1624
1612 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1613 $self->{layout}->set_markup ($markup); 1625 $self->{layout}->set_markup ($markup);
1614 1626
1615 delete $self->{size_req}; 1627 delete $self->{size_req};
1616 $self->realloc; 1628 $self->realloc;
1617 $self->update; 1629 $self->update;
1629 1641
1630 my ($w, $h) = $self->{layout}->size; 1642 my ($w, $h) = $self->{layout}->size;
1631 1643
1632 if (exists $self->{template}) { 1644 if (exists $self->{template}) {
1633 $self->{template}->set_font ($self->{font}) if $self->{font}; 1645 $self->{template}->set_font ($self->{font}) if $self->{font};
1646 $self->{template}->set_width ($self->{max_w} || -1);
1634 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1647 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1635 1648
1636 my ($w2, $h2) = $self->{template}->size; 1649 my ($w2, $h2) = $self->{template}->size;
1637 1650
1638 $w = List::Util::max $w, $w2; 1651 $w = List::Util::max $w, $w2;
1672 1685
1673sub reconfigure { 1686sub reconfigure {
1674 my ($self) = @_; 1687 my ($self) = @_;
1675 1688
1676 delete $self->{size_req}; 1689 delete $self->{size_req};
1690 delete $self->{texture};
1677 1691
1678 $self->SUPER::reconfigure; 1692 $self->SUPER::reconfigure;
1679} 1693}
1680 1694
1681sub _draw { 1695sub _draw {
1682 my ($self) = @_; 1696 my ($self) = @_;
1683 1697
1684 $self->SUPER::_draw; # draw background, if applicable 1698 $self->SUPER::_draw; # draw background, if applicable
1685 1699
1686 my $tex = $self->{texture} ||= do { 1700 my $size = $self->{texture} ||= do {
1687 $self->{layout}->set_foreground (@{$self->{fg}}); 1701 $self->{layout}->set_foreground (@{$self->{fg}});
1688 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1702 $self->{layout}->set_font ($self->{font}) if $self->{font};
1689 $self->{layout}->set_width ($self->{w}); 1703 $self->{layout}->set_width ($self->{w});
1690 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1704 $self->{layout}->set_ellipsise ($self->{ellipsise});
1691 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1705 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1692 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1706 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1693 1707
1694 new_from_layout CFClient::Texture $self->{layout} 1708 [$self->{layout}->size]
1695 }; 1709 };
1696 1710
1697 unless (exists $self->{ox}) { 1711 unless (exists $self->{ox}) {
1698 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1712 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1699 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1713 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x}
1700 : ($self->{w} - $tex->{w}) * 0.5); 1714 : ($self->{w} - $size->[0]) * 0.5);
1701 1715
1702 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1716 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1703 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1717 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
1704 : ($self->{h} - $tex->{h}) * 0.5); 1718 : ($self->{h} - $size->[1]) * 0.5);
1705 }; 1719 };
1706 1720
1707 glEnable GL_TEXTURE_2D;
1708
1709 my $w = List::Util::min $self->{w} + 4, $tex->{w}; 1721 my $w = List::Util::min $self->{w} + 4, $size->[0];
1710 my $h = List::Util::min $self->{h} + 2, $tex->{h}; 1722 my $h = List::Util::min $self->{h} + 2, $size->[1];
1711 1723
1712 if ($tex->{format} == GL_ALPHA) { 1724 $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} 1725}
1723 1726
1724############################################################################# 1727#############################################################################
1725 1728
1726package CFClient::UI::EntryBase; 1729package CFClient::UI::EntryBase;
1837 1840
1838 my $idx = $self->{layout}->xy_to_index ($x, $y); 1841 my $idx = $self->{layout}->xy_to_index ($x, $y);
1839 1842
1840 # byte-index to char-index 1843 # byte-index to char-index
1841 my $text = $self->{text}; 1844 my $text = $self->{text};
1842 utf8::encode $text; 1845 utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text;
1843 $self->{cursor} = length substr $text, 0, $idx; 1846 $self->{cursor} = length $text;
1844 1847
1845 $self->_set_text ($self->{text}); 1848 $self->_set_text ($self->{text});
1846 $self->update; 1849 $self->update;
1847 1850
1848 1 1851 1
2127 my $self = $class->SUPER::new ( 2130 my $self = $class->SUPER::new (
2128 can_events => 0, 2131 can_events => 0,
2129 @_, 2132 @_,
2130 ); 2133 );
2131 2134
2132 $self->{path} 2135 $self->{path} || $self->{tex}
2133 or Carp::croak "required attribute 'path' not set"; 2136 or Carp::croak "'path' or 'tex' attributes required";
2134 2137
2135 $self->{tex} = $texture_cache{$self->{path}} ||= 2138 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2136 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; 2139 new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1;
2137 2140
2138 Scalar::Util::weaken $texture_cache{$self->{path}}; 2141 Scalar::Util::weaken $texture_cache{$self->{path}};
2139 2142
2140 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2143 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2573 can_events => 0, 2576 can_events => 0,
2574 indent => 0, 2577 indent => 0,
2575 #font => default_font 2578 #font => default_font
2576 @_, 2579 @_,
2577 2580
2578 layout => (new CFClient::Layout 1), 2581 layout => (new CFClient::Layout),
2579 par => [], 2582 par => [],
2580 height => 0, 2583 height => 0,
2581 children => [ 2584 children => [
2582 (new CFClient::UI::Empty expand => 1), 2585 (new CFClient::UI::Empty expand => 1),
2583 (new CFClient::UI::Slider vertical => 1), 2586 (new CFClient::UI::Slider vertical => 1),
2744 my $y0 = $top; 2747 my $y0 = $top;
2745 my $y1 = $top + $H; 2748 my $y1 = $top + $H;
2746 2749
2747 my $y = 0; 2750 my $y = 0;
2748 2751
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}}) { 2752 for my $para (@{$self->{par}}) {
2754 my $h = $para->{h}; 2753 my $h = $para->{h};
2755 2754
2756 if ($y0 < $y + $h && $y < $y1) { 2755 if ($y0 < $y + $h && $y < $y1) {
2757 2756
2758 my $layout = $self->get_layout ($para); 2757 my $layout = $self->get_layout ($para);
2759 2758
2760 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2761
2762 glRasterPos $para->{indent}, $y - $y0; 2759 $layout->render ($para->{indent}, $y - $y0);
2763 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2764 2760
2765 if (my @w = @{ $para->{widget} }) { 2761 if (my @w = @{ $para->{widget} }) {
2766 my @s = $layout->get_shapes; 2762 my @s = $layout->get_shapes;
2767 2763
2768 glDisable GL_BLEND;
2769 for (@w) { 2764 for (@w) {
2770 my ($dx, $dy) = splice @s, 0, 2, (); 2765 my ($dx, $dy) = splice @s, 0, 2, ();
2771 2766
2772 $_->{x} = $dx + $para->{indent}; 2767 $_->{x} = $dx + $para->{indent};
2773 $_->{y} = $dy + $y - $y0; 2768 $_->{y} = $dy + $y - $y0;
2774 2769
2775 $_->draw; 2770 $_->draw;
2776 } 2771 }
2777 glEnable GL_BLEND;
2778 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2779 } 2772 }
2780 } 2773 }
2781 2774
2782 $y += $h; 2775 $y += $h;
2783 } 2776 }
2784
2785 glDisable GL_BLEND;
2786 }; 2777 };
2787 }); 2778 });
2788} 2779}
2789 2780
2790sub reconfigure { 2781sub reconfigure {
3086 for my $item (@{ $self->{items} }) { 3077 for my $item (@{ $self->{items} }) {
3087 my ($widget, $cb, $tooltip) = @$item; 3078 my ($widget, $cb, $tooltip) = @$item;
3088 3079
3089 # handle various types of items, only text for now 3080 # handle various types of items, only text for now
3090 if (!ref $widget) { 3081 if (!ref $widget) {
3082 if ($widget =~ /\t/) {
3083 my ($left, $right) = split /\t/, $widget, 2;
3084
3085 $widget = new CFClient::UI::HBox
3086 can_hover => 1,
3087 can_events => 1,
3088 tooltip => $tooltip,
3089 children => [
3090 (new CFClient::UI::Label markup => $left, expand => 1),
3091 (new CFClient::UI::Label markup => $right, align => +1),
3092 ],
3093 ;
3094
3095 } else {
3091 $widget = new CFClient::UI::Label 3096 $widget = new CFClient::UI::Label
3092 can_hover => 1, 3097 can_hover => 1,
3093 can_events => 1, 3098 can_events => 1,
3094 markup => $widget, 3099 markup => $widget,
3095 tooltip => $tooltip 3100 tooltip => $tooltip;
3101 }
3096 } 3102 }
3097 3103
3098 $self->{item}{$widget} = $item; 3104 $self->{item}{$widget} = $item;
3099 3105
3100 $self->{vbox}->add ($widget); 3106 $self->{vbox}->add ($widget);
3822 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 3828 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
3823 3829
3824 $w = 0 if $w < 0; 3830 $w = 0 if $w < 0;
3825 $h = 0 if $h < 0; 3831 $h = 0 if $h < 0;
3826 3832
3833 $w = max $widget->{min_w}, $w;
3834 $h = max $widget->{min_h}, $h;
3835
3836 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3837 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3838
3827 $w = int $w + 0.5; 3839 $w = int $w + 0.5;
3828 $h = int $h + 0.5; 3840 $h = int $h + 0.5;
3829 3841
3830 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 3842 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
3831 $widget->{old_w} = $widget->{w}; 3843 $widget->{old_w} = $widget->{w};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines