source: subversion/applications/editors/osm-editor/qt3/Map.h @ 16590

Last change on this file since 16590 was 1158, checked in by nick, 13 years ago

moved current version to qt3 directory in preparation for qt4

File size: 3.5 KB
Line 
1/*
2    Copyright (C) 2005 Nick Whitelegg, Hogweed Software, nick@hogweed.org
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU Lesser General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any yer version.
8
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 Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public License
15    axg with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
17
18 */
19#ifndef MAP_H
20#define MAP_H
21
22#include "EarthPoint.h"
23#include "llgr.h"
24
25struct ScreenPos
26{
27        int x,y;
28
29        ScreenPos() { x=y=0; }
30        ScreenPos(int x1,int y1) { x=x1; y=y1; }
31};
32
33
34class Map
35{
36private:
37        EarthPoint bottomLeft;
38        double scale;
39        int width, height;
40        bool gridref;
41
42public:
43        Map(double x,double y, double s, int w, int h)
44                { bottomLeft=EarthPoint(x,y); scale=s; width=w; height=h;
45                  gridref=false; }
46
47        ScreenPos getScreenPos(const EarthPoint& pos)
48                { return ScreenPos ((pos.x-bottomLeft.x)*scale,
49                                                height-((pos.y-bottomLeft.y)*scale)); }
50
51        ScreenPos getScreenPos(double x,double y)
52                { return getScreenPos(EarthPoint(x,y)); }
53
54        EarthPoint getEarthPoint(const ScreenPos& pos)
55                { return getEarthPoint(pos.x,pos.y); }
56
57        EarthPoint getEarthPoint(int x, int y)
58                { return EarthPoint( bottomLeft.x+(((double)x)/scale),
59                                                bottomLeft.y+(((double)(height-y))/scale)); }
60
61        void move(double edis,double ndis)
62                { bottomLeft.x += edis*1000; bottomLeft.y += ndis*1000; }
63
64        void movePx(double xdis, double ydis)
65                { move(earthDist(xdis/1000), -earthDist(ydis/1000)); }
66
67        EarthPoint getTopLeft() { return getEarthPoint(ScreenPos(0,0)); }
68        EarthPoint getBottomRight() 
69                { return getEarthPoint(ScreenPos(width,height)); }
70        EarthPoint getTopRight() { return getEarthPoint(ScreenPos(width,0)); }
71       
72        void rescale(double factor)
73        {
74                EarthPoint middle = getCentre (  );
75                scale *= factor;
76                bottomLeft.x = middle.x - (width/2)/scale;
77                bottomLeft.y = middle.y - (height/2)/scale;
78        }
79
80        EarthPoint getCentre()
81        {
82                return getEarthPoint(ScreenPos(width/2,height/2));
83        }
84
85        EarthPoint getBottomLeft()
86                { return bottomLeft; }
87
88        double getScale()
89                { return scale; }
90
91        bool pt_within_map(const ScreenPos& pos)
92                { return pos.x>=0 && pos.y>=0 &&
93                        pos.x<width && pos.y<height; }
94       
95        bool pt_within_map(const EarthPoint& ep)
96        {
97                EarthPoint topRight=getTopRight();
98                return ep.x>=bottomLeft.x && ep.y>=bottomLeft.y&&
99                           ep.x<=topRight.x && ep.y<=topRight.y; 
100        }
101
102        int getWidth(){return width;}
103        int getHeight(){return height;}
104
105        double earthDist(double pixelDist)
106                { return pixelDist/scale; }
107
108        void rescale(double factor,int w,int h)
109        {
110                EarthPoint middle = getCentre ( w,h );
111                scale *= factor;
112                centreAt (middle);
113        }
114
115        EarthPoint getCentre(int w,int h)
116        {
117                return getEarthPoint(ScreenPos(w/2,h/2));
118        }
119
120        void resize(int newWidth,int newHeight)
121        {
122                width = newWidth;
123                height = newHeight;
124        }
125
126        void resizeTopLeft(int newWidth,int newHeight)
127        {
128                bottomLeft.y -= earthDist(newHeight-height); 
129                resize(newWidth,newHeight);
130        }
131
132        void centreAt(const EarthPoint& centre)
133        {
134                bottomLeft.x = centre.x - (width/2)/scale;
135                bottomLeft.y = centre.y - (height/2)/scale;
136        }
137
138        bool isGridRef() { return gridref; }
139        void setGridRef(bool g) { gridref=g; }
140};
141
142
143#endif
Note: See TracBrowser for help on using the repository browser.