ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/Map.pm
(Generate patch)

Comparing deliantra/gde/GCE/Map.pm (file contents):
Revision 1.4 by root, Sun Feb 5 05:32:57 2006 UTC vs.
Revision 1.5 by root, Sun Feb 5 17:43:42 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]) });
54
53 $self->signal_connect (expose_event => sub { 55 $self->signal_connect (configure_event => sub {
54 $self->expose ($_[1]); 56 $self->set_viewport ($self->{x}, $self->{y});
57 1
55 }); 58 });
56 59
57 $self->signal_connect (button_press_event => sub { 60 $self->signal_connect (button_press_event => sub {
58 my ($self, $event) = @_; 61 my ($self, $event) = @_;
59 62
72 my ($self) = @_; 75 my ($self) = @_;
73 76
74 my ($x, $y) = $self->get_pointer; 77 my ($x, $y) = $self->get_pointer;
75 78
76 if (my $di = $self->{in_drag}) { 79 if (my $di = $self->{in_drag}) {
77 my $dx = $x - $di->[2]; 80 $self->set_viewport (
78 my $dy = $y - $di->[3]; 81 $di->[0] + $di->[2] - $x,
82 $di->[1] + $di->[3] - $y,
83 );
79 84
80 my $nx = max 0, $di->[0] - $dx;
81 my $ny = max 0, $di->[1] - $dy;
82
83 $self->window->scroll ($self->{x} - $nx, $self->{y} - $ny);
84
85 ($self->{x}, $self->{y}) = ($nx, $ny);
86 return 0; 85 return 0;
87 } 86 }
88 87
89 1; 88 1;
90 }); 89 });
107 $self->can_focus (1); 106 $self->can_focus (1);
108 107
109# $self->signal_connect (key_press_event => sub { $self->handle_key ($_[1]->keyval, $_[1]->state) }); 108# $self->signal_connect (key_press_event => sub { $self->handle_key ($_[1]->keyval, $_[1]->state) });
110} 109}
111 110
112sub do_size_allocate_rounded { 111sub set_viewport {
113 use integer; 112 my ($self, $x, $y) = @_;
114 113
115 $_[1]->width ($_[1]->width / TILESIZE * TILESIZE); 114 my $area = $self->allocation;
116 $_[1]->height ($_[1]->height / TILESIZE * TILESIZE);
117 115
118 $_[0]->signal_chain_from_overridden ($_[1]); 116 $x = max 0, min $self->{width} - $area->width , $x;
117 $y = max 0, min $self->{height} - $area->height, $y;
118
119 $self->window->scroll ($self->{x} - $x, $self->{y} - $y);
120
121 ($self->{x}, $self->{y}) = ($x, $y);
122}
123
124sub set_map {
125 my ($self, $map) = @_;
126
127 $self->{map} = $map;
128 delete $self->{overlay};
129
130 $self->{width} = $map->{width} * TILESIZE;
131 $self->{height} = $map->{height} * TILESIZE;
132
133 $self->{x} =
134 $self->{y} = 0;
135
136 $self->invalidate_all;
119} 137}
120 138
121sub coord { 139sub coord {
122 my ($self, $x, $y) = @_; 140 my ($self, $x, $y) = @_;
123 141
235# } 253# }
236# 254#
237# 1 255# 1
238#} 256#}
239 257
240#sub invalidate { 258sub invalidate {
241# my ($self, $x1, $y1, $x2, $y2) = @_; 259 my ($self, $x, $y, $w, $h) = @_;
242# 260
243# return unless $self->{window}; 261 return unless $self->{window};
244# 262
245# $self->{draw}->queue_draw_area ( 263 $self->queue_draw_area (
246# $x1 * (IW + IX), $y1 * (IH + IY), 264 map $_ * TILESIZE, $x - 1 , $y - 1, $w + 2, $h + 2
247# ($x2 - $x1 + 1) * (IW + IX), ($y2 - $y1 + 1) * (IH + IY),
248# ); 265 );
249#} 266}
250 267
251sub invalidate_all { 268sub invalidate_all {
252 my ($self) = @_; 269 my ($self) = @_;
253 270
254# $self->invalidate (0, 0, $self->{cols} - 1, $self->{page} - 1); 271 $self->queue_draw;
272}
273
274sub update_map {
275 my ($self, $x1, $y1, $x2, $y2) = @_;
255} 276}
256 277
257sub expose { 278sub expose {
258 my ($self, $event) = @_; 279 my ($self, $event) = @_;
259 280
261 282
262 my $ox = $self->{x}; my $ix = int $ox / TILESIZE; 283 my $ox = $self->{x}; my $ix = int $ox / TILESIZE;
263 my $oy = $self->{y}; my $iy = int $oy / TILESIZE; 284 my $oy = $self->{y}; my $iy = int $oy / TILESIZE;
264 285
265 # get_rectangles is buggy in older versions 286 # get_rectangles is buggy in older versions
266 for my $area ($Gtk2::VERSION >= 1.115 ? $event->region->get_rectangles : $event->area) { 287 for my $area ($Gtk2::VERSION > 1.115 ? $event->region->get_rectangles : $event->area) {
267 my ($x, $y, $w, $h) = $area->values; # x y w h 288 my ($x, $y, $w, $h) = $area->values; # x y w h
268 289
269 my @x = ((int ($ox + $x) / TILESIZE) .. int +($ox + $x + $w + TILESIZE - 1) / TILESIZE); 290 my @x = ((int ($ox + $x) / TILESIZE) .. int +($ox + $x + $w + TILESIZE - 1) / TILESIZE);
270 my @y = ((int ($oy + $y) / TILESIZE) .. int +($oy + $y + $h + TILESIZE - 1) / TILESIZE); 291 my @y = ((int ($oy + $y) / TILESIZE) .. int +($oy + $y + $h + TILESIZE - 1) / TILESIZE);
271 292
311 } 332 }
312 333
313 1 334 1
314} 335}
315 336
316#my $win = new Gtk2::Window 'toplevel';
317#my $map = new GCE::Map;
318#$win->add ($map);
319#$win->show_all;
320#$map->{map} = arch2map read_arch "$Crossfire::LIB/maps/mlab/university1";
321#main Gtk2;
322
323=back 337=back
324 338
325=head1 AUTHOR 339=head1 AUTHOR
326 340
327Marc Lehmann <schmorp@schmorp.de> 341Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines