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

Comparing deliantra/Deliantra/Deliantra/MapWidget.pm (file contents):
Revision 1.1 by root, Sun Feb 5 21:18:07 2006 UTC vs.
Revision 1.2 by root, Sun Feb 5 22:24:41 2006 UTC

48 $_[1]->height (20 * TILESIZE); 48 $_[1]->height (20 * TILESIZE);
49 49
50 1 50 1
51 }); 51 });
52 52
53 $self->signal_connect (expose_event => sub { $self->expose ($_[1]) }); 53 $self->signal_connect (expose_event => sub { $self->expose ($_[1]); 1 });
54 54
55 $self->signal_connect_after (configure_event => sub { 55 $self->signal_connect_after (configure_event => sub {
56 $self->set_viewport ($self->{x}, $self->{y}); 56 $self->set_viewport ($self->{x}, $self->{y});
57
57 1 58 0
58 }); 59 });
60
61 # reduces unnecessary redraws
62 $self->signal_connect_after (focus_in_event => sub { 1 });
63 $self->signal_connect_after (focus_out_event => sub { 1 });
64
65 $self->{tooltip} = -1; # initially disabled
66
67 $self->signal_connect_after (enter_notify_event => sub { $self->enable_tooltip; 0 });
68 $self->signal_connect_after (leave_notify_event => sub { $self->disable_tooltip; 0 });
59 69
60 $self->signal_connect (button_press_event => sub { 70 $self->signal_connect (button_press_event => sub {
61 my ($self, $event) = @_; 71 my ($self, $event) = @_;
72
73 $self->disable_tooltip;
62 74
63 my ($x, $y) = ($event->x, $event->y); 75 my ($x, $y) = ($event->x, $event->y);
64 76
65 if ($_[1]->button == 2) { 77 if ($_[1]->button == 2) {
66 $_[0]->grab_focus; 78 $_[0]->grab_focus;
67 $self->{in_drag} = [$self->{x}, $self->{y}, $x, $y]; 79 $self->{in_drag} = [$self->{x}, $self->{y}, $x, $y];
68 return 0; 80 return 1;
69 }
70
71 1 81 }
82
83 0
72 }); 84 });
73 85
74 $self->signal_connect (motion_notify_event => sub { 86 $self->signal_connect (motion_notify_event => sub {
75 my ($self) = @_; 87 my ($self) = @_;
76 88
77 my ($x, $y) = $self->get_pointer; 89 $self->update_tooltip;
78 90
79 if (my $di = $self->{in_drag}) { 91 if (my $di = $self->{in_drag}) {
92 my ($x, $y) = $self->get_pointer;
93
80 $self->set_viewport ( 94 $self->set_viewport (
81 $di->[0] + $di->[2] - $x, 95 $di->[0] + $di->[2] - $x,
82 $di->[1] + $di->[3] - $y, 96 $di->[1] + $di->[3] - $y,
83 ); 97 );
84 98
85 return 0; 99 return 1;
100 }
101
86 } 102 0
87
88 1;
89 }); 103 });
90 104
91 $self->signal_connect (button_release_event => sub { 105 $self->signal_connect (button_release_event => sub {
92 my ($self) = @_; 106 my ($self) = @_;
93 107
108 $self->enable_tooltip;
109
94 delete $self->{in_drag}; 110 delete $self->{in_drag};
95 111
96 1 112 1
97 }); 113 });
98
99 # unnecessary redraws...
100 $self->signal_connect (focus_in_event => sub { 1 });
101 $self->signal_connect (focus_out_event => sub { 1 });
102 114
103 # gtk+ supports no motion compression, a major lacking feature. we have to pay for the 115 # gtk+ supports no motion compression, a major lacking feature. we have to pay for the
104 # workaround with incorrect behaviour and extra server-turnarounds. 116 # workaround with incorrect behaviour and extra server-turnarounds.
105 $self->add_events ([qw(key_press_mask key_release_mask button_press_mask button_release_mask button-motion-mask scroll_mask pointer-motion-hint-mask)]); 117 $self->add_events ([qw(key_press_mask key_release_mask
118 button_press_mask button_release_mask button-motion-mask
119 pointer-motion-mask pointer-motion-hint-mask
120 enter-notify-mask leave-notify-mask)]);
106 $self->can_focus (1); 121 $self->can_focus (1);
107 122
108# $self->signal_connect (key_press_event => sub { $self->handle_key ($_[1]->keyval, $_[1]->state) }); 123# $self->signal_connect (key_press_event => sub { $self->handle_key ($_[1]->keyval, $_[1]->state) });
124}
125
126sub enable_tooltip {
127 my ($self) = @_;
128
129 $self->{tooltip}++;
130 $self->update_tooltip;
131}
132
133sub disable_tooltip {
134 my ($self) = @_;
135
136 $self->{tooltip}--;
137 $self->update_tooltip;
138}
139
140sub update_tooltip {
141 my ($self) = @_;
142
143 if ($self->{tooltip} >= 0) {
144 my $screen = $self->{window}->get_screen;
145 my ($pscreen, $x, $y) = $screen->get_display->get_pointer;
146
147 if ($pscreen == $screen) {
148 if (!$self->{tip}) {
149 $self->{tip} = new Gtk2::Window "popup";
150 $self->{tip}->set_name ("gtk-tooltips");
151 $self->{tip}->set_decorated (0);
152 $self->{tip}->set_border_width (4);
153 }
154
155 my ($mx, $my) = $self->coord ($self->get_pointer);
156
157 if ($self->{tipinfo}[0] != $mx || $self->{tipinfo}[1] != $my) {
158 $self->fill_tooltip ($mx, $my);
159
160 $self->{tipinfo} = [$mx, $my];
161 }
162
163 $self->{tip}->move ($x + TILESIZE, $y);
164 $self->{tip}->show_all;
165
166 return;
167 }
168 }
169
170 delete $self->{tipinfo};
171 (delete $self->{tip})->destroy if $self->{tip};
172}
173
174sub fill_tooltip {
175 my ($self, $x, $y) = @_;
176
177 $self->{tip}->remove ($self->{tip}->get_children)
178 if $self->{tip}->get_children;
179
180 $self->{tip}->add (my $frame = new Gtk2::Frame "($x|$y)");
181
182 $frame->set_shadow_type ("none");
183
184 if ($x < 0 || $x >= $self->{map}{width}
185 || $y < 0 || $y >= $self->{map}{height}) {
186 $frame->add (new Gtk2::Label "<off-map>");
187 } else {
188 $frame->add (my $vbox = new Gtk2::VBox);
189
190 #TODO: fill tooltip via signal, defaulting to this:
191
192 # fill tooltip with info about $x, $y
193 my $as = $self->{map}{map}[$x][$y] || [];
194 for my $a (@$as) {
195 $vbox->add (new Gtk2::Label $a->{_name});
196 }
197 }
109} 198}
110 199
111sub set_viewport { 200sub set_viewport {
112 my ($self, $x, $y) = @_; 201 my ($self, $x, $y) = @_;
113 202
382 0, 0, 471 0, 0,
383 $x[0] * TILESIZE - $ox, $y[0] * TILESIZE - $oy, 472 $x[0] * TILESIZE - $ox, $y[0] * TILESIZE - $oy,
384 TILESIZE * @x, TILESIZE * @y, 473 TILESIZE * @x, TILESIZE * @y,
385 'max', 0, 0); 474 'max', 0, 0);
386 } 475 }
387
388 1
389} 476}
390 477
391=back 478=back
392 479
393=head1 AUTHOR 480=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines