Prepare 1.0 alpha3 release.
[tagua/yd.git] / src / pointconverter.h
blob24f731175c427ab002ed434676416630a596a3d4
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef POINTCONVERTER_H
12 #define POINTCONVERTER_H
14 #include <iostream>
16 #if 0
17 class PointConverter {
18 int m_size;
19 bool m_flipped;
21 inline Point flipPoint(const Point& p) const {
22 if (m_flipped)
23 return Point(7-p.x, 7-p.y);
24 else
25 return p;
28 public:
29 PointConverter(int size, bool flipped)
30 : m_size(size)
31 , m_flipped(flipped) { }
33 inline Point toLogical(const QPoint& real) const { return flipPoint(Point(real).div(m_size)); }
34 inline QPoint toReal(const Point& logical) const { return flipPoint(logical) * m_size; }
36 inline void flip(bool flipped) { m_flipped = flipped; }
37 inline void resize(int size) { m_size = size; }
39 #endif
41 class PointConverter {
42 protected:
43 virtual ~PointConverter(){};
45 public:
46 virtual bool flipped() const = 0;
47 virtual int squareSize() const = 0;
48 virtual Point gridSize() const = 0;
50 virtual Point flipPoint(const Point& p) const {
51 if (flipped())
52 return gridSize()-Point(1,1)-p;
53 else
54 return p;
56 virtual Point toLogical(const QPoint& real) const {
57 return flipPoint(Point(real).div( squareSize() ));
59 virtual QPoint toReal(const Point& logical) const {
60 return flipPoint(logical) * squareSize();
65 #endif // POINTCONVERTER_H