INFO702 - TPs
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
MasterShape Struct Reference

Polymorphic class that represents the top class of any complex shape. More...

#include <objects.hpp>

Inheritance diagram for MasterShape:
GraphicalShape Asteroid

Public Types

enum  State { Ok , Collision }
 

Public Member Functions

 MasterShape (QColor cok, QColor cko)
 
void setGraphicalShape (GraphicalShape *f)
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 
virtual QPointF randomPoint () const override
 
virtual bool isInside (const QPointF &p) const override
 
virtual QRectF boundingRect () const override
 
virtual void advance (int step) override
 
State currentState () const
 
QColor currentColor () const
 

Protected Attributes

GraphicalShape_f
 
State _state
 
QColor _cok
 
QColor _cko
 

Detailed Description

Polymorphic class that represents the top class of any complex shape.

It takes care of memorizing collisions and storing the current main coordinates of a shape.

Definition at line 37 of file objects.hpp.

Member Enumeration Documentation

◆ State

enum MasterShape::State

Definition at line 39 of file objects.hpp.

39{ Ok, Collision };

Constructor & Destructor Documentation

◆ MasterShape()

MasterShape::MasterShape ( QColor  cok,
QColor  cko 
)

Definition at line 68 of file objects.cpp.

69 : _f( 0 ), _state( Ok ), _cok( cok ), _cko( cko )
70{
71}

Member Function Documentation

◆ advance()

void MasterShape::advance ( int  step)
overridevirtual

Definition at line 100 of file objects.cpp.

101{
102 if ( !step ) return;
103
104 // (I) Garde les objets dans la scene.
105 auto p = scenePos(); // pareil que pos si MasterShape est bien à la racine.
106 // pos() est dans les coordonnées parent et setPos aussi.
107 if ( p.x() < -SZ_BD ) {
108 auto point = parentItem() != 0
109 ? parentItem()->mapFromScene( QPointF( IMAGE_SIZE + SZ_BD - 1, p.y() ) )
110 : QPointF( IMAGE_SIZE + SZ_BD - 1, p.y() );
111 setPos(point);
112 } else if ( p.x() > IMAGE_SIZE + SZ_BD ) {
113 auto point = parentItem() != 0
114 ? parentItem()->mapFromScene( QPointF( -SZ_BD + 1, p.y() ) )
115 : QPointF( -SZ_BD + 1, p.y() );
116 setPos(point);
117 }
118 if ( p.y() < -SZ_BD ) {
119 auto point = parentItem() != 0 ?
120 parentItem()->mapFromScene( QPointF( p.x(), IMAGE_SIZE + SZ_BD - 1 ) )
121 : QPointF( p.x(), IMAGE_SIZE + SZ_BD - 1 );
122 setPos(point);
123 } else if ( p.y() > IMAGE_SIZE + SZ_BD ) {
124 auto point = parentItem() != 0
125 ? parentItem()->mapFromScene( QPointF( p.x(), -SZ_BD + 1 ) )
126 : QPointF( p.x(), -SZ_BD + 1 );
127 setPos(point);
128 }
129
130 // (II) regarde les intersections avec les autres objets.
131 if ( logical_scene->intersect( this ) )
132 _state = Collision;
133 else
134 _state = Ok;
135}
bool intersect(MasterShape *f1, MasterShape *f2)
Definition objects.cpp:190

◆ boundingRect()

QRectF MasterShape::boundingRect ( ) const
overridevirtual

Definition at line 152 of file objects.cpp.

153{
154 assert( _f != 0 );
155 return mapRectToParent( _f->boundingRect() );
156}

◆ currentColor()

QColor MasterShape::currentColor ( ) const

Definition at line 81 of file objects.cpp.

82{
83 if ( _state == Ok ) return _cok;
84 else return _cko;
85}

◆ currentState()

MasterShape::State MasterShape::currentState ( ) const

Definition at line 88 of file objects.cpp.

89{
90 return _state;
91}

◆ isInside()

bool MasterShape::isInside ( const QPointF &  p) const
overridevirtual

Implements GraphicalShape.

Definition at line 145 of file objects.cpp.

146{
147 assert( _f != 0 );
148 return _f->isInside( mapFromParent( p ) );
149}

◆ paint()

void MasterShape::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)
overridevirtual

Definition at line 94 of file objects.cpp.

95{
96 // nothing to do, Qt automatically calls paint of every QGraphicsItem
97}

◆ randomPoint()

QPointF MasterShape::randomPoint ( ) const
overridevirtual

Implements GraphicalShape.

Definition at line 138 of file objects.cpp.

139{
140 assert( _f != 0 );
141 return mapToParent( _f->randomPoint() );
142}

◆ setGraphicalShape()

void MasterShape::setGraphicalShape ( GraphicalShape f)

Definition at line 74 of file objects.cpp.

75{
76 _f = f;
77 if ( _f != 0 ) _f->setParentItem( this );
78}

Member Data Documentation

◆ _cko

QColor MasterShape::_cko
protected

Definition at line 57 of file objects.hpp.

◆ _cok

QColor MasterShape::_cok
protected

Definition at line 57 of file objects.hpp.

◆ _f

GraphicalShape* MasterShape::_f
protected

Definition at line 55 of file objects.hpp.

◆ _state

State MasterShape::_state
protected

Definition at line 56 of file objects.hpp.


The documentation for this struct was generated from the following files: