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.8 by root, Sun Feb 5 23:39:36 2006 UTC vs.
Revision 1.9 by root, Tue Feb 7 04:02:56 2006 UTC

49 }); 49 });
50 50
51 $self->set_redraw_on_allocate (0); 51 $self->set_redraw_on_allocate (0);
52 $self->double_buffered (0); 52 $self->double_buffered (0);
53 53
54 $self->{tooltip} = -1; # need focus in first
55
54 # reduces unnecessary redraws 56 # reduces unnecessary redraws
55 $self->signal_connect_after (focus_in_event => sub { 1 }); 57 $self->signal_connect (focus_in_event => sub { $self->enable_tooltip; 1 });
56 $self->signal_connect_after (focus_out_event => sub { 1 }); 58 $self->signal_connect (focus_out_event => sub { $self->disable_tooltip; 1 });
59
60 $self->signal_connect_after (enter_notify_event => sub { $self->update_tooltip; 0 });
61 $self->signal_connect_after (leave_notify_event => sub { $self->update_tooltip; 0 });
57 62
58 $self->signal_connect (size_request => sub { 63 $self->signal_connect (size_request => sub {
59 $_[1]->width (20 * TILESIZE); 64 $_[1]->width (20 * TILESIZE);
60 $_[1]->height (20 * TILESIZE); 65 $_[1]->height (20 * TILESIZE);
61 66
67 $self->signal_connect_after (configure_event => sub { 72 $self->signal_connect_after (configure_event => sub {
68 $self->set_viewport ($self->{x}, $self->{y}); 73 $self->set_viewport ($self->{x}, $self->{y});
69 74
70 0 75 0
71 }); 76 });
72
73 $self->{tooltip} = -2; # need to be mapped _and_ inside
74
75 $self->signal_connect_after (map_event => sub { $self->enable_tooltip; 0 });
76 $self->signal_connect_after (unmap_event => sub { $self->disable_tooltip; 0 });
77
78 $self->signal_connect_after (enter_notify_event => sub { $self->enable_tooltip; 0 });
79 $self->signal_connect_after (leave_notify_event => sub { $self->disable_tooltip; 0 });
80 77
81 $self->signal_connect (button_press_event => sub { 78 $self->signal_connect (button_press_event => sub {
82 my ($self, $event) = @_; 79 my ($self, $event) = @_;
83 80
84 my ($x, $y) = ($event->x, $event->y); 81 my ($x, $y) = ($event->x, $event->y);
163} 160}
164 161
165sub update_tooltip { 162sub update_tooltip {
166 my ($self) = @_; 163 my ($self) = @_;
167 164
168 if ($self->{tooltip} >= 0) { 165 if ($self->{tooltip} >= 0
166 && $self->mapped
167 && $self->get_toplevel->has_toplevel_focus) {
169 my $screen = $self->{window}->get_screen; 168 my $screen = $self->{window}->get_screen;
169
170 if ($self->{window} == ($screen->get_display->get_window_at_pointer)[0]) {
170 my ($pscreen, $x, $y) = $screen->get_display->get_pointer; 171 my ($pscreen, $x, $y) = $screen->get_display->get_pointer;
171 172
172 if ($pscreen == $screen) { 173 if ($pscreen == $screen) {
173 if (!$self->{tip}) { 174 if (!$self->{tip}) {
174 $self->{tip} = new Gtk2::Window "popup"; 175 $self->{tip} = new Gtk2::Window "popup";
175 $self->{tip}->can_focus (0); 176 $self->{tip}->can_focus (0);
176 $self->{tip}->set_name ("gtk-tooltips"); 177 $self->{tip}->set_name ("gtk-tooltips");
177 $self->{tip}->set_decorated (0); 178 $self->{tip}->set_decorated (0);
178 $self->{tip}->set_border_width (4); 179 $self->{tip}->set_border_width (4);
179 $self->{tip}->set_has_frame (0); 180 $self->{tip}->set_has_frame (0);
180 $self->{tip}->set_resizable (0); 181 $self->{tip}->set_resizable (0);
181 $self->{tip}->set_transient_for ($self->get_toplevel); 182 $self->{tip}->set_transient_for ($self->get_toplevel);
183 }
184
185 my ($mx, $my) = $self->coord ($self->get_pointer);
186
187 if ($self->{tipinfo}[0] != $mx || $self->{tipinfo}[1] != $my) {
188 $self->fill_tooltip ($mx, $my);
189
190 $self->{tipinfo} = [$mx, $my];
191
192 $self->overlay (_tooltip => $mx * TILESIZE, $my * TILESIZE, TILESIZE, TILESIZE, sub {
193 my ($self, $x, $y) = @_;
194
195 $self->{window}->draw_rectangle ($_ & 1 ? $self->style->black_gc : $self->style->white_gc, 0,
196 $x + $_, $y + $_,
197 TILESIZE - 1 - $_ * 2, TILESIZE - 1 - $_ * 2)
198 for 0..3;
199
200 my $req = $self->{tip}->size_request;
201 $self->{tip}->resize ($req->width, $req->height);
202 });
203 }
204
205 $self->{tip}->move ($x + TILESIZE, $y);
206 $self->{tip}->show_all;
207
208 return;
182 } 209 }
183
184 my ($mx, $my) = $self->coord ($self->get_pointer);
185
186 if ($self->{tipinfo}[0] != $mx || $self->{tipinfo}[1] != $my) {
187 $self->fill_tooltip ($mx, $my);
188
189 $self->{tipinfo} = [$mx, $my];
190
191 $self->overlay (_tooltip => $mx * TILESIZE, $my * TILESIZE, TILESIZE, TILESIZE, sub {
192 my ($self, $x, $y) = @_;
193
194 $self->{window}->draw_rectangle ($_ & 1 ? $self->style->black_gc : $self->style->white_gc, 0,
195 $x + $_, $y + $_,
196 TILESIZE - 1 - $_ * 2, TILESIZE - 1 - $_ * 2)
197 for 0..3;
198
199 my $req = $self->{tip}->size_request;
200 $self->{tip}->resize ($req->width, $req->height);
201 });
202
203 $self->{tip}->show_all;
204 }
205
206 $self->{tip}->move ($x + TILESIZE, $y);
207
208 return;
209 } 210 }
210 } 211 }
211 212
212 $self->overlay ("_tooltip"); 213 $self->overlay ("_tooltip");
213 delete $self->{tipinfo}; 214 delete $self->{tipinfo};
219 220
220 $self->{tip}->remove ($self->{tip}->get_children) 221 $self->{tip}->remove ($self->{tip}->get_children)
221 if $self->{tip}->get_children; 222 if $self->{tip}->get_children;
222 223
223 $self->{tip}->add (my $frame = new Gtk2::Frame "($x|$y)"); 224 $self->{tip}->add (my $frame = new Gtk2::Frame "($x|$y)");
224
225# $frame->set_shadow_type ("none");
226 225
227 if ($x < 0 || $x >= $self->{map}{width} 226 if ($x < 0 || $x >= $self->{map}{width}
228 || $y < 0 || $y >= $self->{map}{height}) { 227 || $y < 0 || $y >= $self->{map}{height}) {
229 $frame->add (new Gtk2::Label "<off-map>"); 228 $frame->add (new Gtk2::Label "<off-map>");
230 } else { 229 } else {
232 231
233 #TODO: fill tooltip via signal, defaulting to this: 232 #TODO: fill tooltip via signal, defaulting to this:
234 233
235 # fill tooltip with info about $x, $y 234 # fill tooltip with info about $x, $y
236 my $as = $self->{map}{map}[$x][$y] || []; 235 my $as = $self->{map}{map}[$x][$y] || [];
237 for my $a (@$as) { 236 for my $a (reverse @$as) {
238 $vbox->add (my $hbox = new Gtk2::HBox 0, 2); 237 $vbox->add (my $hbox = new Gtk2::HBox 0, 2);
239 238
240 my $tile = $Crossfire::Tilecache::TILECACHE{ $a->{face} || $ARCH->{$a->{_name}}{face} }; 239 my $tile = $Crossfire::Tilecache::TILECACHE{ $a->{face} || $ARCH->{$a->{_name}}{face} };
241 240
242 # this is awful, is this really the best way? 241 # this is awful, is this really the best way?
331 330
332sub update_map { 331sub update_map {
333 my ($self, $x, $y, $w, $h) = @_; 332 my ($self, $x, $y, $w, $h) = @_;
334 333
335 delete $self->{overlay}; 334 delete $self->{overlay};
336 335
337 my $map = $self->{map}{map}; 336 my $map = $self->{map}{map};
338 my $ov = $self->{face} ||= []; 337 my $ov = $self->{face} ||= [];
339 338
340 $x = 0; $w = $self->{map}{width}; 339 $x = 0; $w = $self->{map}{width};
341 $y = 0; $h = $self->{map}{height}; 340 $y = 0; $h = $self->{map}{height};
346 my $TC = \%Crossfire::Tilecache::TILECACHE; 345 my $TC = \%Crossfire::Tilecache::TILECACHE;
347 346
348 my @ov; 347 my @ov;
349 348
350 # update overlay map with bigfaces and chained faces 349 # update overlay map with bigfaces and chained faces
350 my $a;
351 for my $x (@x) { 351 for my $x (@x) {
352 my $ass = $self->{map}{map}[$x]; 352 my $ass = $self->{map}{map}[$x];
353 my $oss = $ov->[$x] ||= []; 353 my $oss = $ov->[$x] ||= [];
354 for my $y (@y) { 354 for my $y (@y) {
355 my $os = $oss->[$y] = []; 355 my $os = $oss->[$y] = [];
390 for (@ov) { 390 for (@ov) {
391 my ($x, $y, $idx) = @$_; 391 my ($x, $y, $idx) = @$_;
392 392
393 push @{ $ov->[$x][$y] }, $idx; 393 push @{ $ov->[$x][$y] }, $idx;
394 } 394 }
395
396 $self->queue_draw_area ($x * TILESIZE - $self->{x},
397 $y * TILESIZE - $self->{y},
398 $w * TILESIZE, $h * TILESIZE);
395} 399}
396 400
397sub expose { 401sub expose {
398 my ($self, $event) = @_; 402 my ($self, $event) = @_;
399 403

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines