mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-26 01:34:40 +00:00
ref #97 Added method for update position and draw-circle and square.
This commit is contained in:
parent
ec8d499b9f
commit
aa16e2b1bf
@ -6,6 +6,8 @@
|
||||
//#
|
||||
|
||||
#include "controlpos.h"
|
||||
#include "clasteritem.h"
|
||||
#include <QtMath>
|
||||
|
||||
namespace CRAWL {
|
||||
|
||||
@ -15,28 +17,74 @@ ControlPos::ControlPos() {
|
||||
|
||||
void ControlPos::add(ClasterItem *object) {
|
||||
|
||||
GroupObject::updatePosition();
|
||||
Claster::add(object);
|
||||
updatePosition();
|
||||
|
||||
}
|
||||
|
||||
void ControlPos::remove(ClasterItem *object) {
|
||||
|
||||
GroupObject::updatePosition();
|
||||
Claster::remove(object->guiId());
|
||||
updatePosition();
|
||||
|
||||
}
|
||||
|
||||
void ControlPos::changeLayout(const _Figure &fig) {
|
||||
void ControlPos::changeLayout(const Refresh &fig) {
|
||||
_shape = fig;
|
||||
}
|
||||
|
||||
if (fig == CIRCLE) {
|
||||
GroupObject::updatePosition();
|
||||
void ControlPos::setDistance(int dist) {
|
||||
_distance = dist;
|
||||
}
|
||||
|
||||
void ControlPos::updatePosition() {
|
||||
|
||||
switch (_shape) {
|
||||
case CIRCLE:
|
||||
drawCircle();
|
||||
break;
|
||||
|
||||
case SQUARE:
|
||||
drawSquare();
|
||||
break;
|
||||
|
||||
case LINE:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ControlPos::drawCircle() {
|
||||
|
||||
float step = 360 / objects().size();
|
||||
int temp = 1;
|
||||
|
||||
for (ClasterItem* object: objects()) {
|
||||
|
||||
float x = _distance * qCos(step*temp);
|
||||
float y = _distance * qSin(step*temp);
|
||||
GroupObject::updatePosition(object->guiId(), {x, y, 0});
|
||||
|
||||
temp++;
|
||||
}
|
||||
|
||||
if (fig == SQUARE) {
|
||||
GroupObject::updatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
if (fig == LINE) {
|
||||
GroupObject::updatePosition();
|
||||
void ControlPos::drawSquare() {
|
||||
|
||||
float step = 360 / objects().size();
|
||||
int temp = 1;
|
||||
|
||||
for (ClasterItem* object: objects()) {
|
||||
|
||||
float x = _distance * qCos(step*temp);
|
||||
float y = _distance * qSin(step*temp);
|
||||
GroupObject::updatePosition(object->guiId(), {x, y, 0});
|
||||
|
||||
temp++;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,18 @@
|
||||
namespace CRAWL {
|
||||
|
||||
/**
|
||||
* @brief The ControlPos class
|
||||
* @brief The Refresh enum Lists the shapes to convert the group object to.
|
||||
*/
|
||||
enum Refresh {
|
||||
CIRCLE,
|
||||
SPHERE,
|
||||
SQUARE,
|
||||
CUBE,
|
||||
LINE
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The ControlPos class The class that control position of group objects.
|
||||
*/
|
||||
class ControlPos: public GroupObject {
|
||||
public:
|
||||
@ -25,22 +36,37 @@ public:
|
||||
void add(ClasterItem *object);
|
||||
void remove(ClasterItem *object);
|
||||
|
||||
/**
|
||||
* @brief changeLayout This method defines the shape of the group object.
|
||||
* @param fig This is the name of the figure to change the group object.
|
||||
*/
|
||||
void changeLayout(const Refresh &fig);
|
||||
|
||||
/**
|
||||
* @brief setDistance This method sets, depending on the shape selected, the radius for the circle or the indentation for the square.
|
||||
* @param dist This is the radius or margin.
|
||||
*/
|
||||
void setDistance(int dist);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief The _Figure enum
|
||||
*/
|
||||
enum _Figure {
|
||||
CIRCLE,
|
||||
SQUARE,
|
||||
LINE
|
||||
};
|
||||
int _distance;
|
||||
Refresh _shape;
|
||||
|
||||
/**
|
||||
* @brief changeLayout
|
||||
* @param fig
|
||||
* @brief updatePosition This method updates the coordinates of the positions of all objects.
|
||||
*/
|
||||
void changeLayout(const _Figure &fig);
|
||||
void updatePosition();
|
||||
|
||||
/**
|
||||
* @brief drawCircle This method updates the coordinates to a circle shape.
|
||||
*/
|
||||
void drawCircle();
|
||||
|
||||
/**
|
||||
* @brief drawSquare This method updates the coordinates to a square shape.
|
||||
*/
|
||||
void drawSquare();
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user