Finished chess animator.
[tagua/yd.git] / src / pointconverter.h
blobc0c71a8b942bbe7da5c493f76c7daa11be07c0be
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
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 private:
46 virtual bool flipped() const = 0;
47 virtual int squareSize() const = 0;
48 virtual Point gridSize() const = 0;
50 public:
51 virtual Point flipPoint(const Point& p) const {
52 if (flipped())
53 return gridSize()-Point(1,1)-p;
54 else
55 return p;
57 virtual Point toLogical(const QPoint& real) const {
58 return flipPoint(Point(real).div( squareSize() ));
60 virtual QPoint toReal(const Point& logical) const {
61 return flipPoint(logical) * squareSize();
66 #endif // POINTCONVERTER_H