4 // A simple game inspired by an emacs module
6 /***************************************************************************
7 * Copyright (c) 1999-2000, Robert Cimrman *
8 * cimrman3@students.zcu.cz *
10 * Copyright (c) 2007, Nicolas Roffet *
11 * nicolas-kde@roffet.com *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
28 ***************************************************************************/
30 #include "kbbgraphicsitemborder.h"
34 #include "kbbscalablegraphicwidget.h"
39 // Constructor / Destructor
42 KBBGraphicsItemBorder::KBBGraphicsItemBorder(int borderPosition
, int columns
, int rows
, float offset
)
46 setSize(borderPosition
, columns
, rows
);
55 void KBBGraphicsItemBorder::setSize(int borderPosition
, int columns
, int rows
)
57 m_borderPosition
= borderPosition
;
61 centerCoordinate(m_borderPosition
, m_centerX
, m_centerY
, m_offset
);
70 void KBBGraphicsItemBorder::setBorderPosition(int borderPosition
)
72 setSize(borderPosition
, m_columns
, m_rows
);
76 void KBBGraphicsItemBorder::centerCoordinate(int borderPosition
, float ¢erX
, float ¢erY
, float offset
)
78 const float b
= (float) KBBScalableGraphicWidget::BORDER_SIZE
;
79 const float r
= (float) KBBScalableGraphicWidget::RATIO
;
82 if (borderPosition
<m_columns
) {
83 x
= borderPosition
*r
+ b
;
85 } else if (borderPosition
<m_columns
+ m_rows
) {
86 x
= m_columns
*r
+ b
+ b
/2 - offset
;
87 y
= (borderPosition
- m_columns
)*r
+ b
;
88 } else if (borderPosition
<2*m_columns
+ m_rows
) {
89 x
= (2*m_columns
+ m_rows
- borderPosition
)*r
+ b
/2;
90 y
= m_rows
*r
+ 3*b
/2 - offset
;
93 y
= (2*m_columns
+ 2*m_rows
- borderPosition
)*r
+ b
/2;
101 float KBBGraphicsItemBorder::centerX() const
107 float KBBGraphicsItemBorder::centerY() const
113 int KBBGraphicsItemBorder::rotation()
115 if (m_borderPosition
<m_columns
) {
117 } else if (m_borderPosition
<m_columns
+ m_rows
) {
119 } else if (m_borderPosition
<2*m_columns
+ m_rows
) {