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.322 by root, Wed Jul 5 01:53:24 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,
1536 #font => default_font 1550 #font => default_font
1537 #text => initial text 1551 #text => initial text
1538 #markup => initial narkup 1552 #markup => initial narkup
1539 #max_w => maximum pixel width 1553 #max_w => maximum pixel width
1540 ellipsise => 3, # end 1554 ellipsise => 3, # end
1541 layout => (new CFClient::Layout 2), 1555 layout => (new CFClient::Layout),
1542 fontsize => 1, 1556 fontsize => 1,
1543 align => -1, 1557 align => -1,
1544 valign => -1, 1558 valign => -1,
1545 padding_x => 2, 1559 padding_x => 2,
1546 padding_y => 2, 1560 padding_y => 2,
1547 can_events => 0, 1561 can_events => 0,
1548 %arg 1562 %arg
1549 ); 1563 );
1550 1564
1551 if (exists $self->{template}) { 1565 if (exists $self->{template}) {
1552 my $layout = new CFClient::Layout 2; 1566 my $layout = new CFClient::Layout;
1553 $layout->set_text (delete $self->{template}); 1567 $layout->set_text (delete $self->{template});
1554 $self->{template} = $layout; 1568 $self->{template} = $layout;
1555 } 1569 }
1556 1570
1557 if (exists $self->{markup}) { 1571 if (exists $self->{markup}) {
1627 1641
1628 my ($w, $h) = $self->{layout}->size; 1642 my ($w, $h) = $self->{layout}->size;
1629 1643
1630 if (exists $self->{template}) { 1644 if (exists $self->{template}) {
1631 $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);
1632 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1647 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1633 1648
1634 my ($w2, $h2) = $self->{template}->size; 1649 my ($w2, $h2) = $self->{template}->size;
1635 1650
1636 $w = List::Util::max $w, $w2; 1651 $w = List::Util::max $w, $w2;
1688 $self->{layout}->set_width ($self->{w}); 1703 $self->{layout}->set_width ($self->{w});
1689 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1704 $self->{layout}->set_ellipsise ($self->{ellipsise});
1690 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1705 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1691 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1706 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1692 1707
1693 $self->{size_req} 1708 [$self->{layout}->size]
1694 }; 1709 };
1695 1710
1696 unless (exists $self->{ox}) { 1711 unless (exists $self->{ox}) {
1697 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1712 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1698 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} 1713 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x}
1825 1840
1826 my $idx = $self->{layout}->xy_to_index ($x, $y); 1841 my $idx = $self->{layout}->xy_to_index ($x, $y);
1827 1842
1828 # byte-index to char-index 1843 # byte-index to char-index
1829 my $text = $self->{text}; 1844 my $text = $self->{text};
1830 utf8::encode $text; 1845 utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text;
1831 $self->{cursor} = length substr $text, 0, $idx; 1846 $self->{cursor} = length $text;
1832 1847
1833 $self->_set_text ($self->{text}); 1848 $self->_set_text ($self->{text});
1834 $self->update; 1849 $self->update;
1835 1850
1836 1 1851 1
2115 my $self = $class->SUPER::new ( 2130 my $self = $class->SUPER::new (
2116 can_events => 0, 2131 can_events => 0,
2117 @_, 2132 @_,
2118 ); 2133 );
2119 2134
2120 $self->{path} 2135 $self->{path} || $self->{tex}
2121 or Carp::croak "required attribute 'path' not set"; 2136 or Carp::croak "'path' or 'tex' attributes required";
2122 2137
2123 $self->{tex} = $texture_cache{$self->{path}} ||= 2138 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2124 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;
2125 2140
2126 Scalar::Util::weaken $texture_cache{$self->{path}}; 2141 Scalar::Util::weaken $texture_cache{$self->{path}};
2127 2142
2128 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2143 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2561 can_events => 0, 2576 can_events => 0,
2562 indent => 0, 2577 indent => 0,
2563 #font => default_font 2578 #font => default_font
2564 @_, 2579 @_,
2565 2580
2566 layout => (new CFClient::Layout 2), 2581 layout => (new CFClient::Layout),
2567 par => [], 2582 par => [],
2568 height => 0, 2583 height => 0,
2569 children => [ 2584 children => [
2570 (new CFClient::UI::Empty expand => 1), 2585 (new CFClient::UI::Empty expand => 1),
2571 (new CFClient::UI::Slider vertical => 1), 2586 (new CFClient::UI::Slider vertical => 1),
3813 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 3828 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
3814 3829
3815 $w = 0 if $w < 0; 3830 $w = 0 if $w < 0;
3816 $h = 0 if $h < 0; 3831 $h = 0 if $h < 0;
3817 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
3818 $w = int $w + 0.5; 3839 $w = int $w + 0.5;
3819 $h = int $h + 0.5; 3840 $h = int $h + 0.5;
3820 3841
3821 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}) {
3822 $widget->{old_w} = $widget->{w}; 3843 $widget->{old_w} = $widget->{w};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines