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.329 by root, Sun Jul 23 02:44:06 2006 UTC vs.
Revision 1.331 by root, Sun Jul 23 04:46:02 2006 UTC

79sub feed_sdl_key_up_event { 79sub feed_sdl_key_up_event {
80 $FOCUS->emit (key_up => $_[0]) 80 $FOCUS->emit (key_up => $_[0])
81 if $FOCUS; 81 if $FOCUS;
82} 82}
83 83
84sub check_hover {
85 my ($widget) = @_;
86
87 if ($widget != $HOVER) {
88 my $hover = $HOVER; $HOVER = $widget;
89
90 $hover->update if $hover && $hover->{can_hover};
91 $HOVER->update if $HOVER && $HOVER->{can_hover};
92
93 $TOOLTIP_WATCHER->start;
94 }
95}
96
84sub feed_sdl_button_down_event { 97sub feed_sdl_button_down_event {
85 my ($ev) = @_; 98 my ($ev) = @_;
86 my ($x, $y) = ($ev->{x}, $ev->{y}); 99 my ($x, $y) = ($ev->{x}, $ev->{y});
87 100
88 if (!$BUTTON_STATE) { 101 unless ($BUTTON_STATE) {
89 my $widget = $ROOT->find_widget ($x, $y); 102 my $widget = $ROOT->find_widget ($x, $y);
90 103
91 $GRAB = $widget; 104 $GRAB = $widget;
92 $GRAB->update if $GRAB; 105 $GRAB->update if $GRAB;
93 106
94 $TOOLTIP_WATCHER->cb->(); 107 $TOOLTIP_WATCHER->cb->();
95 } 108 }
96 109
97 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 110 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
98 111
99 $GRAB->emit (button_down => $ev, $GRAB->coord2local ($x, $y)) 112 if ($GRAB) {
100 if $GRAB; 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
114 # mousewheel
115 $ev->{dx} = 0;
116 $ev->{dy} = $ev->{button} * 2 - 9;
117 $GRAB->emit (mouse_wheel => $ev);
118 } else {
119 $GRAB->emit (button_down => $ev)
120 }
121 }
101} 122}
102 123
103sub feed_sdl_button_up_event { 124sub feed_sdl_button_up_event {
104 my ($ev) = @_; 125 my ($ev) = @_;
105 my ($x, $y) = ($ev->{x}, $ev->{y});
106 126
107 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 127 my $widget = $GRAB || $ROOT->find_widget ($ev->{x}, $ev->{y});
108 128
109 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); 129 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
110 130
111 $GRAB->emit (button_up => $ev, $GRAB->coord2local ($x, $y)) 131 $GRAB->emit (button_up => $ev)
112 if $GRAB; 132 if $GRAB && $ev->{button} != 4 && $ev->{button} != 5;
113 133
114 if (!$BUTTON_STATE) { 134 unless ($BUTTON_STATE) {
115 my $grab = $GRAB; undef $GRAB; 135 my $grab = $GRAB; undef $GRAB;
116 $grab->update if $grab; 136 $grab->update if $grab;
117 $GRAB->update if $GRAB; 137 $GRAB->update if $GRAB;
118 138
139 check_hover $widget;
119 $TOOLTIP_WATCHER->cb->(); 140 $TOOLTIP_WATCHER->cb->();
120 } 141 }
121} 142}
122 143
123sub feed_sdl_motion_event { 144sub feed_sdl_motion_event {
124 my ($ev) = @_; 145 my ($ev) = @_;
125 my ($x, $y) = ($ev->{x}, $ev->{y}); 146 my ($x, $y) = ($ev->{x}, $ev->{y});
126 147
127 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 148 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
128 149
129 if ($widget != $HOVER) { 150 check_hover $widget;
130 my $hover = $HOVER; $HOVER = $widget;
131 151
132 $hover->update if $hover && $hover->{can_hover}; 152 $HOVER->emit (mouse_motion => $ev)
133 $HOVER->update if $HOVER && $HOVER->{can_hover};
134
135 $TOOLTIP_WATCHER->start;
136 }
137
138 $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y))
139 if $HOVER; 153 if $HOVER;
140} 154}
141 155
142# convert position array to integers 156# convert position array to integers
143sub harmonize { 157sub harmonize {
189 203
190 } 204 }
191 } 205 }
192 206
193 reconfigure_widgets; 207 reconfigure_widgets;
208}
209
210#############################################################################
211
212package CFClient::UI::Event;
213
214sub xy {
215 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
194} 216}
195 217
196############################################################################# 218#############################################################################
197 219
198package CFClient::UI::Base; 220package CFClient::UI::Base;
407 429
408# translate global coordinates to local coordinate system 430# translate global coordinates to local coordinate system
409sub coord2local { 431sub coord2local {
410 my ($self, $x, $y) = @_; 432 my ($self, $x, $y) = @_;
411 433
434 Carp::confess unless $self->{parent};#d#
435
412 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 436 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
413} 437}
414 438
415# translate local coordinates to global coordinate system 439# translate local coordinates to global coordinate system
416sub coord2global { 440sub coord2global {
456 480
457sub invoke_mouse_motion { 0 } 481sub invoke_mouse_motion { 0 }
458sub invoke_button_up { 0 } 482sub invoke_button_up { 0 }
459sub invoke_key_down { 0 } 483sub invoke_key_down { 0 }
460sub invoke_key_up { 0 } 484sub invoke_key_up { 0 }
485sub invoke_mouse_wheel { 0 }
461 486
462sub invoke_button_down { 487sub invoke_button_down {
463 my ($self, $ev, $x, $y) = @_; 488 my ($self, $ev, $x, $y) = @_;
464 489
465 $self->grab_focus; 490 $self->grab_focus;
471 my ($self, $signal, $cb) = @_; 496 my ($self, $signal, $cb) = @_;
472 497
473 push @{ $self->{signal_cb}{$signal} }, $cb; 498 push @{ $self->{signal_cb}{$signal} }, $cb;
474} 499}
475 500
501my %has_coords = (
502 button_down => 1,
503 button_up => 1,
504 mouse_motion => 1,
505 mouse_wheel => 1,
506);
507
476sub emit { 508sub emit {
477 my ($self, $signal, @args) = @_; 509 my ($self, $signal, @args) = @_;
478 510
511 my @append
512 = $has_coords{$signal}
513 ? $args[0]->xy ($self)
514 : ();
515
479 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# 516 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
480 517
481 #d##TODO# stop propagating at first true, do not use sum 518 #d##TODO# stop propagating at first true, do not use sum
482 (List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}) # before 519 (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before
483 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args) # closure 520 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure
484 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent 521 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent
485} 522}
486 523
487sub find_widget { 524sub find_widget {
488 my ($self, $x, $y) = @_; 525 my ($self, $x, $y) = @_;
489 526
979 $self->{vp}->set_offset (0, $_[1]); 1016 $self->{vp}->set_offset (0, $_[1]);
980 }, 1017 },
981 ; 1018 ;
982 1019
983 $self = $class->SUPER::new ( 1020 $self = $class->SUPER::new (
984 vp => (new CFClient::UI::ViewPort expand => 1), 1021 vp => (new CFClient::UI::ViewPort expand => 1),
1022 can_events => 1,
985 slider => $slider, 1023 slider => $slider,
986 %arg, 1024 %arg,
987 ); 1025 );
988 1026
989 $self->SUPER::add ($self->{vp}, $self->{slider}); 1027 $self->SUPER::add ($self->{vp}, $self->{slider});
990 $self->add ($child) if $child; 1028 $self->add ($child) if $child;
998 my ($self, $widget) = @_; 1036 my ($self, $widget) = @_;
999 1037
1000 $self->{vp}->add ($self->{child} = $widget); 1038 $self->{vp}->add ($self->{child} = $widget);
1001} 1039}
1002 1040
1003sub invoke_button_up { 1041sub invoke_mouse_wheel {
1004 my ($self, $ev) = @_; 1042 my ($self, $ev) = @_;
1005 1043
1006 warn "button up $ev->{button}\n";#d# 1044 return 0 unless $ev->{dy}; # only vertical movements
1045
1046 $self->{slider}->emit (mouse_wheel => $ev);
1047
1007 1048 1
1008 0
1009} 1049}
1010 1050
1011sub update_slider { 1051sub update_slider {
1012 my ($self) = @_; 1052 my ($self) = @_;
1013 1053
2461 } 2501 }
2462 2502
2463 1 2503 1
2464} 2504}
2465 2505
2506sub invoke_mouse_wheel {
2507 my ($self, $ev) = @_;
2508
2509 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2510
2511 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1);
2512
2513 ! ! $delta
2514}
2515
2466sub update { 2516sub update {
2467 my ($self) = @_; 2517 my ($self) = @_;
2468 2518
2469 delete $self->{knob_w}; 2519 delete $self->{knob_w};
2470 $self->SUPER::update; 2520 $self->SUPER::update;
2569sub new { 2619sub new {
2570 my $class = shift; 2620 my $class = shift;
2571 2621
2572 my $self = $class->SUPER::new ( 2622 my $self = $class->SUPER::new (
2573 fontsize => 1, 2623 fontsize => 1,
2574 can_events => 0, 2624 can_events => 1,
2575 indent => 0, 2625 indent => 0,
2576 #font => default_font 2626 #font => default_font
2577 @_, 2627 @_,
2578 2628
2579 layout => (new CFClient::Layout), 2629 layout => (new CFClient::Layout),
2619 2669
2620 $self->reflow; 2670 $self->reflow;
2621 2671
2622 local $self->{children} = [$empty, $slider]; 2672 local $self->{children} = [$empty, $slider];
2623 $self->SUPER::invoke_size_allocate ($w, $h) 2673 $self->SUPER::invoke_size_allocate ($w, $h)
2674}
2675
2676sub invoke_mouse_wheel {
2677 my ($self, $ev) = @_;
2678
2679 return 0 unless $ev->{dy}; # only vertical movements
2680
2681 $self->{children}[1]->emit (mouse_wheel => $ev);
2682
2683 1
2624} 2684}
2625 2685
2626sub get_layout { 2686sub get_layout {
2627 my ($self, $para) = @_; 2687 my ($self, $para) = @_;
2628 2688

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines