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.2 by root, Sun Feb 5 22:24:41 2006 UTC vs.
Revision 1.3 by root, Sun Feb 5 22:53:46 2006 UTC

135 135
136 $self->{tooltip}--; 136 $self->{tooltip}--;
137 $self->update_tooltip; 137 $self->update_tooltip;
138} 138}
139 139
140sub overlay {
141 my ($self, $name, $x, $y, $w, $h, $cb) = @_;
142
143 if (my $ov = delete $self->{overlay}{$name}) {
144 my ($x, $y, $w, $h) = @$ov;
145
146 $self->queue_draw_area ($x - $self->{x}, $y - $self->{y}, $w, $h);
147 }
148
149 if ($h) {
150 $self->{overlay}{$name} = [$x, $y, $w, $h, $cb];
151
152 $self->queue_draw_area ($x - $self->{x}, $y - $self->{y}, $w, $h);
153 }
154}
155
140sub update_tooltip { 156sub update_tooltip {
141 my ($self) = @_; 157 my ($self) = @_;
142 158
143 if ($self->{tooltip} >= 0) { 159 if ($self->{tooltip} >= 0) {
144 my $screen = $self->{window}->get_screen; 160 my $screen = $self->{window}->get_screen;
145 my ($pscreen, $x, $y) = $screen->get_display->get_pointer; 161 my ($pscreen, $x, $y) = $screen->get_display->get_pointer;
146 162
147 if ($pscreen == $screen) { 163 if ($pscreen == $screen) {
148 if (!$self->{tip}) { 164 if (!$self->{tip}) {
149 $self->{tip} = new Gtk2::Window "popup"; 165 $self->{tip} = new Gtk2::Window "popup";
166 $self->{tip}->can_focus (0);
150 $self->{tip}->set_name ("gtk-tooltips"); 167 $self->{tip}->set_name ("gtk-tooltips");
151 $self->{tip}->set_decorated (0); 168 $self->{tip}->set_decorated (0);
152 $self->{tip}->set_border_width (4); 169 $self->{tip}->set_border_width (4);
170 $self->{tip}->set_has_frame (1);
153 } 171 }
154 172
155 my ($mx, $my) = $self->coord ($self->get_pointer); 173 my ($mx, $my) = $self->coord ($self->get_pointer);
156 174
157 if ($self->{tipinfo}[0] != $mx || $self->{tipinfo}[1] != $my) { 175 if ($self->{tipinfo}[0] != $mx || $self->{tipinfo}[1] != $my) {
158 $self->fill_tooltip ($mx, $my); 176 $self->fill_tooltip ($mx, $my);
159 177
160 $self->{tipinfo} = [$mx, $my]; 178 $self->{tipinfo} = [$mx, $my];
179
180 $self->overlay (_tooltip => $mx * TILESIZE, $my * TILESIZE, TILESIZE, TILESIZE, sub {
181 my ($self, $x, $y) = @_;
182
183 $self->{window}->draw_rectangle ($_ & 1 ? $self->style->black_gc : $self->style->white_gc, 0,
184 $x + $_, $y + $_,
185 TILESIZE - 1 - $_ * 2, TILESIZE - 1 - $_ * 2)
186 for 0..3;
187
188 my $req = $self->{tip}->size_request;
189 $self->{tip}->resize ($req->width, $req->height);
190 });
191
192 $self->{tip}->show_all;
161 } 193 }
162 194
163 $self->{tip}->move ($x + TILESIZE, $y); 195 $self->{tip}->move ($x + TILESIZE, $y);
164 $self->{tip}->show_all;
165 196
166 return; 197 return;
167 } 198 }
168 } 199 }
169 200
201 $self->overlay ("_tooltip");
170 delete $self->{tipinfo}; 202 delete $self->{tipinfo};
171 (delete $self->{tip})->destroy if $self->{tip}; 203 (delete $self->{tip})->destroy if $self->{tip};
172} 204}
173 205
174sub fill_tooltip { 206sub fill_tooltip {
183 215
184 if ($x < 0 || $x >= $self->{map}{width} 216 if ($x < 0 || $x >= $self->{map}{width}
185 || $y < 0 || $y >= $self->{map}{height}) { 217 || $y < 0 || $y >= $self->{map}{height}) {
186 $frame->add (new Gtk2::Label "<off-map>"); 218 $frame->add (new Gtk2::Label "<off-map>");
187 } else { 219 } else {
188 $frame->add (my $vbox = new Gtk2::VBox); 220 $frame->add (my $vbox = new Gtk2::VBox 1, 2);
189 221
190 #TODO: fill tooltip via signal, defaulting to this: 222 #TODO: fill tooltip via signal, defaulting to this:
191 223
192 # fill tooltip with info about $x, $y 224 # fill tooltip with info about $x, $y
193 my $as = $self->{map}{map}[$x][$y] || []; 225 my $as = $self->{map}{map}[$x][$y] || [];
194 for my $a (@$as) { 226 for my $a (@$as) {
195 $vbox->add (new Gtk2::Label $a->{_name}); 227 $vbox->add (my $label = new Gtk2::Label $a->{_name});
196 } 228 }
197 } 229 }
198} 230}
199 231
200sub set_viewport { 232sub set_viewport {
221 $self->{x} = 253 $self->{x} =
222 $self->{y} = 0; 254 $self->{y} = 0;
223 255
224 delete $self->{face}; 256 delete $self->{face};
225 $self->update_map (0, 0, $self->{width}, $self->{height}); 257 $self->update_map (0, 0, $self->{width}, $self->{height});
226 258 delete $self->{tipinfo};
259 $self->update_tooltip;
227 $self->invalidate_all; 260 $self->invalidate_all;
228} 261}
229 262
230sub coord { 263sub coord {
231 my ($self, $x, $y) = @_; 264 my ($self, $x, $y) = @_;
471 0, 0, 504 0, 0,
472 $x[0] * TILESIZE - $ox, $y[0] * TILESIZE - $oy, 505 $x[0] * TILESIZE - $ox, $y[0] * TILESIZE - $oy,
473 TILESIZE * @x, TILESIZE * @y, 506 TILESIZE * @x, TILESIZE * @y,
474 'max', 0, 0); 507 'max', 0, 0);
475 } 508 }
509
510 $_->[4]->($self, $_->[0] - $self->{x}, $_->[1] - $self->{y})
511 for values %{ $self->{overlay} || {} };
476} 512}
477 513
478=back 514=back
479 515
480=head1 AUTHOR 516=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines