4
1
mirror of https://github.com/QuasarApp/Snake.git synced 2025-04-30 19:54:45 +00:00

ref Added method for update position and draw-circle and square.

This commit is contained in:
IgorekLoschinin 2021-09-08 22:20:52 +03:00
parent ec8d499b9f
commit aa16e2b1bf
2 changed files with 96 additions and 22 deletions

@ -6,6 +6,8 @@
//# //#
#include "controlpos.h" #include "controlpos.h"
#include "clasteritem.h"
#include <QtMath>
namespace CRAWL { namespace CRAWL {
@ -15,28 +17,74 @@ ControlPos::ControlPos() {
void ControlPos::add(ClasterItem *object) { void ControlPos::add(ClasterItem *object) {
GroupObject::updatePosition(); Claster::add(object);
updatePosition();
} }
void ControlPos::remove(ClasterItem *object) { 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) { void ControlPos::setDistance(int dist) {
GroupObject::updatePosition(); _distance = dist;
}
void ControlPos::updatePosition() {
switch (_shape) {
case CIRCLE:
drawCircle();
break;
case SQUARE:
drawSquare();
break;
case LINE:
break;
default:
break;
} }
if (fig == SQUARE) { }
GroupObject::updatePosition();
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 == 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 { 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 { class ControlPos: public GroupObject {
public: public:
@ -25,22 +36,37 @@ public:
void add(ClasterItem *object); void add(ClasterItem *object);
void remove(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: private:
/** int _distance;
* @brief The _Figure enum Refresh _shape;
*/
enum _Figure {
CIRCLE,
SQUARE,
LINE
};
/** /**
* @brief changeLayout * @brief updatePosition This method updates the coordinates of the positions of all objects.
* @param fig
*/ */
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();
}; };