• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kblackbox

  • sources
  • kde-4.14
  • kdegames
  • kblackbox
kbbgraphicsitemborder.cpp
Go to the documentation of this file.
1 //
2 // KBlackbox
3 //
4 // A simple game inspired by an emacs module
5 //
6 /***************************************************************************
7  * Copyright (c) 1999-2000, Robert Cimrman *
8  * cimrman3@students.zcu.cz *
9  * *
10  * Copyright (c) 2007, Nicolas Roffet *
11  * nicolas-kde@roffet.com *
12  * *
13  * *
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. *
18  * *
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. *
23  * *
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  ***************************************************************************/
29 
30 #include "kbbgraphicsitemborder.h"
31 
32 
33 
34 #include "kbbscalablegraphicwidget.h"
35 
36 
37 
38 //
39 // Constructor / Destructor
40 //
41 
42 KBBGraphicsItemBorder::KBBGraphicsItemBorder(int borderPosition, int columns, int rows, float offset)
43 {
44  m_offset = offset;
45 
46  setSize(borderPosition, columns, rows);
47 }
48 
49 
50 
51 //
52 // Public
53 //
54 
55 void KBBGraphicsItemBorder::setSize(int borderPosition, int columns, int rows)
56 {
57  m_borderPosition = borderPosition;
58  m_columns = columns;
59  m_rows = rows;
60 
61  centerCoordinate(m_borderPosition, m_centerX, m_centerY, m_offset);
62 }
63 
64 
65 
66 //
67 // Protected
68 //
69 
70 void KBBGraphicsItemBorder::setBorderPosition(int borderPosition)
71 {
72  setSize(borderPosition, m_columns, m_rows);
73 }
74 
75 
76 void KBBGraphicsItemBorder::centerCoordinate(int borderPosition, float &centerX, float &centerY, float offset)
77 {
78  const float b = (float) KBBScalableGraphicWidget::BORDER_SIZE;
79  const float r = (float) KBBScalableGraphicWidget::RATIO;
80  float x;
81  float y;
82  if (borderPosition<m_columns) {
83  x = borderPosition*r + b;
84  y = offset;
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;
91  } else {
92  x = offset;
93  y = (2*m_columns + 2*m_rows - borderPosition)*r + b/2;
94  }
95 
96  centerX = x + r/2;
97  centerY = y + r/2;
98 }
99 
100 
101 float KBBGraphicsItemBorder::centerX() const
102 {
103  return m_centerX;
104 }
105 
106 
107 float KBBGraphicsItemBorder::centerY() const
108 {
109  return m_centerY;
110 }
111 
112 
113 int KBBGraphicsItemBorder::rotationAngle()
114 {
115  if (m_borderPosition<m_columns) {
116  return 0;
117  } else if (m_borderPosition<m_columns + m_rows) {
118  return 90;
119  } else if (m_borderPosition<2*m_columns + m_rows) {
120  return 180;
121  } else {
122  return 270;
123  }
124 }
KBBGraphicsItemBorder::m_borderPosition
int m_borderPosition
Definition: kbbgraphicsitemborder.h:59
KBBGraphicsItemBorder::setSize
void setSize(int borderPosition, int columns, int rows)
Definition: kbbgraphicsitemborder.cpp:55
KBBGraphicsItemBorder::centerX
float centerX() const
Definition: kbbgraphicsitemborder.cpp:101
KBBGraphicsItemBorder::m_columns
int m_columns
Definition: kbbgraphicsitemborder.h:62
KBBGraphicsItemBorder::centerCoordinate
void centerCoordinate(int borderPosition, float &centerX, float &centerY, float offset)
Definition: kbbgraphicsitemborder.cpp:76
KBBGraphicsItemBorder::m_centerX
float m_centerX
Definition: kbbgraphicsitemborder.h:60
kbbscalablegraphicwidget.h
KBBScalableGraphicWidget::BORDER_SIZE
static int const BORDER_SIZE
Distance between the black box and the widget border.
Definition: kbbscalablegraphicwidget.h:74
KBBGraphicsItemBorder::rotationAngle
int rotationAngle()
Definition: kbbgraphicsitemborder.cpp:113
KBBGraphicsItemBorder::m_offset
float m_offset
Definition: kbbgraphicsitemborder.h:63
KBBGraphicsItemBorder::centerY
float centerY() const
Definition: kbbgraphicsitemborder.cpp:107
KBBGraphicsItemBorder::KBBGraphicsItemBorder
KBBGraphicsItemBorder(int borderPosition, int columns, int rows, float offset)
Constructor.
Definition: kbbgraphicsitemborder.cpp:42
KBBGraphicsItemBorder::setBorderPosition
void setBorderPosition(int borderPosition)
Definition: kbbgraphicsitemborder.cpp:70
KBBGraphicsItemBorder::m_centerY
float m_centerY
Definition: kbbgraphicsitemborder.h:61
KBBScalableGraphicWidget::RATIO
static int const RATIO
Width and height of a single square on the black box.
Definition: kbbscalablegraphicwidget.h:81
KBBGraphicsItemBorder::m_rows
int m_rows
Definition: kbbgraphicsitemborder.h:64
kbbgraphicsitemborder.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kblackbox

Skip menu "kblackbox"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal