~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/smallmap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2001, 2002, 2003 Michael Bartl
 
2
// Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
 
3
// Copyright (C) 2004, 2005, 2006 Andrea Paternesi
 
4
// Copyright (C) 2004 Thomas Plonka
 
5
// Copyright (C) 2006, 2007, 2008 Ben Asselstine
 
6
// Copyright (C) 2007 Ole Laursen
 
7
//
1
8
//  This program is free software; you can redistribute it and/or modify
2
9
//  it under the terms of the GNU General Public License as published by
3
10
//  the Free Software Foundation; either version 2 of the License, or
10
17
//
11
18
//  You should have received a copy of the GNU General Public License
12
19
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
21
//  02110-1301, USA.
14
22
 
15
23
#include <config.h>
16
24
 
23
31
#include "sdl-draw.h"
24
32
#include "timing.h"
25
33
#include "GameMap.h"
 
34
#include "Configuration.h"
26
35
 
27
36
SmallMap::SmallMap()
28
37
{
61
70
    draw_rect(surface, pos.x+1, pos.y+1, pos.x + w-1, pos.y + h-1, raw);
62
71
}
63
72
 
64
 
void SmallMap::center_view(Vector<int> p, bool slide, bool from_tile)
65
 
{
66
 
  if (from_tile == false)
67
 
    {
68
 
      p.x = int(round(p.x / pixels_per_tile));
69
 
      p.y = int(round(p.y / pixels_per_tile));
70
 
 
71
 
      p -= view.dim / 2;
72
 
 
73
 
      p = clip(Vector<int>(0, 0), p, GameMap::get_dim() - view.dim);
74
 
    }
75
 
  else
76
 
      
77
 
    p = clip(Vector<int>(0,0), p - view.dim / 2, GameMap::get_dim() - view.dim);
78
 
 
79
 
  if (slide)
80
 
    slide_view(Rectangle(p.x, p.y, view.w, view.h));
81
 
  else
82
 
    set_view(Rectangle(p.x, p.y, view.w, view.h));
83
 
          
84
 
  if (Playerlist::isFinished()) //window closed while computer player moves
85
 
      return;
 
73
void SmallMap::center_view_on_tile(Vector<int> pos, bool slide)
 
74
{
 
75
  pos = clip(Vector<int>(0,0), pos - view.dim / calculateResizeFactor(), 
 
76
             GameMap::get_dim() - view.dim);
 
77
 
 
78
  if (slide)
 
79
    slide_view(Rectangle(pos.x, pos.y, view.w, view.h));
 
80
  else
 
81
    set_view(Rectangle(pos.x, pos.y, view.w, view.h));
 
82
          
 
83
  view_changed.emit(view);
 
84
}
 
85
 
 
86
void SmallMap::center_view_on_pixel(Vector<int> pos, bool slide)
 
87
{
 
88
  pos.x = int(round(pos.x / pixels_per_tile));
 
89
  pos.y = int(round(pos.y / pixels_per_tile));
 
90
 
 
91
  pos -= view.dim / calculateResizeFactor();
 
92
 
 
93
  pos = clip(Vector<int>(0, 0), pos, GameMap::get_dim() - view.dim);
 
94
 
 
95
  if (slide)
 
96
    slide_view(Rectangle(pos.x, pos.y, view.w, view.h));
 
97
  else
 
98
    set_view(Rectangle(pos.x, pos.y, view.w, view.h));
 
99
          
86
100
  view_changed.emit(view);
87
101
}
88
102
 
89
103
void SmallMap::after_draw()
90
104
{
91
105
  OverviewMap::after_draw();
92
 
  draw_cities(false);
93
 
  draw_selection();
 
106
  if (Playerlist::getActiveplayer()->getType() == Player::HUMAN ||
 
107
      Configuration::s_hidden_map == false)
 
108
    {
 
109
      draw_cities(false);
 
110
      draw_selection();
 
111
    }
94
112
  map_changed.emit(get_surface());
95
113
}
96
114
 
102
120
  if ((e.button == MouseButtonEvent::LEFT_BUTTON ||
103
121
       e.button == MouseButtonEvent::RIGHT_BUTTON)
104
122
      && e.state == MouseButtonEvent::PRESSED)
105
 
    center_view(e.pos, true, false);
 
123
    center_view_on_pixel(e.pos, true);
106
124
}
107
125
 
108
126
void SmallMap::mouse_motion_event(MouseMotionEvent e)
112
130
 
113
131
  if (e.pressed[MouseMotionEvent::LEFT_BUTTON] ||
114
132
      e.pressed[MouseMotionEvent::RIGHT_BUTTON])
115
 
    center_view(e.pos, false, false);
 
133
    center_view_on_pixel(e.pos, false);
116
134
}
 
135
 
117
136
int slide (int x, int y)
118
137
{
119
138
  int skip = 2;
155
174
        }
156
175
    }
157
176
}
 
177
 
 
178
void SmallMap::blank()
 
179
{
 
180
  Uint32 fog_color = SDL_MapRGB(surface->format, 0, 0, 0);
 
181
  int size = int(pixels_per_tile) > 1 ? int(pixels_per_tile) : 1;
 
182
  //fog it up
 
183
  for (int i = 0; i < GameMap::getWidth(); i++)
 
184
    for (int j = 0; j < GameMap::getHeight(); j++)
 
185
      {
 
186
        Vector <int> pos;
 
187
        pos.x = i;
 
188
        pos.y = j;
 
189
        pos = mapToSurface(pos);
 
190
        draw_filled_rect(surface, pos.x, pos.y,
 
191
                         pos.x + size, pos.y + size, fog_color);
 
192
      }
 
193
  map_changed.emit(get_surface());
 
194
}
 
195