2
* Copyright (C) 2002-2004 by The Widelands Development Team
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include "interactive_base.h"
23
#include "rendertarget.h"
33
Map_View::Map_View(UIPanel *parent, int x, int y, uint w, uint h, Interactive_Base *player)
34
: UIPanel(parent, x, y, w, h)
37
m_viewpoint.x = m_viewpoint.y = 0;
49
Map_View::~Map_View(void)
56
Map_View::warp_mouse_to_field
58
Moves the mouse cursor so that it is directly above the given field
61
void Map_View::warp_mouse_to_field(Coords c)
65
m_intbase->get_map()->get_save_pix(c, &x, &y);
69
if(x>=get_w() || y>=get_h()) {
70
// The user has scrolled the field outside
71
// the viewable area, he most surely doesn't
76
if(x<=0) { warp_mouse_to_field(Coords(c.x+m_intbase->get_map()->get_width(),c.y)); return; }
77
if(y<=0) { warp_mouse_to_field(Coords(c.x, c.y+m_intbase->get_map()->get_height())); return; }
87
This is the guts!! this function draws the whole
88
map the user can see. we spend a lot of time
92
void Map_View::draw(RenderTarget* dst)
94
dst->rendermap(m_intbase->get_egbase(), m_intbase->get_visibility(), m_viewpoint);
100
Map_View::set_viewpoint
102
Set the viewpoint to the given pixel coordinates
105
void Map_View::set_viewpoint(Point vp)
107
if (vp == m_viewpoint)
110
m_intbase->get_map()->normalize_pix(&vp);
113
warpview.call(m_viewpoint.x, m_viewpoint.y);
116
/** Map_View::handle_mouseclick(uint btn, bool down, int x, int y)
118
* Mouseclicks on the map:
119
* Right-click: enable/disable dragging
120
* Left-click: field action window
122
bool Map_View::handle_mouseclick(uint btn, bool down, int x, int y)
124
if (btn == MOUSE_LEFT)
132
else if (btn == MOUSE_RIGHT)
138
} else if (m_dragging) {
139
Sys_MouseLock(false);
151
Map_View::handle_mousemove
153
Scroll the view according to mouse movement.
156
void Map_View::handle_mousemove(int x, int y, int xdiff, int ydiff, uint btns)
158
if (!(btns & (1<<MOUSE_RIGHT)))
163
set_rel_viewpoint(Point(xdiff, ydiff));
166
if (!m_intbase->get_fieldsel_freeze())
169
g_gr->update_fullscreen();
175
Map_View::track_fsel(int mx, int my)
177
Move the fsel to the given mouse position.
178
Does not honour fieldsel freeze.
181
void Map_View::track_fsel(int mx, int my)
185
fsel = m_intbase->get_map()->calc_coords(Point(m_viewpoint.x + mx, m_viewpoint.y + my));
187
// Apply the new fieldsel
188
m_intbase->set_fieldsel_pos(fsel);