Incremental Engine  1.0.6
A 2D Game Engine to create Idle Games
IncrementalEngine::Panel Class Reference

#include <Panel.h>

Inheritance diagram for IncrementalEngine::Panel:
IncrementalEngine::Sprite IncrementalEngine::Actor IncrementalEngine::Transformable IncrementalEngine::Drawable

Public Member Functions

 Panel ()
 
virtual ~Panel () override
 
virtual void Update (float dt) override
 
void SetValues (int elementsToShow, float distanceBetweenElements)
 
void AddElement (Actor *actor)
 
void MoveUp ()
 
void MoveDown ()
 
- Public Member Functions inherited from IncrementalEngine::Sprite
 Sprite ()
 
virtual ~Sprite () override
 
void SetTexture (Texture *texture)
 
void ClearTexture ()
 
virtual FloatRect GetLocalBounds () override
 
virtual HRESULT Draw (ID3D11DeviceContext *deviceContext) override
 
- Public Member Functions inherited from IncrementalEngine::Actor
virtual ~Actor ()
 
virtual void Init ()
 
void UpdateRecursive (float dt)
 
HRESULT DrawRecursive (ID3D11DeviceContext *deviceContext)
 
FloatRect GetGlobalBounds ()
 
void Center ()
 
const Transform GetWorldTransform ()
 
const D3DXVECTOR2 GetWorldPosition ()
 
const D3DXVECTOR2 GetWorldScale ()
 
const float GetWorldRotation ()
 
void SetWorldPosition (D3DXVECTOR2 value)
 
virtual void SetPosition (float x, float y) override
 
virtual void SetPosition (const D3DXVECTOR2 &position) override
 
virtual const D3DXVECTOR2 & GetPosition () const override
 
ActorGetParent () const
 
virtual void SetParent (Actor *value, const bool fixWorldPosition=true)
 
void SetActive (bool active)
 
bool IsActive ()
 
- Public Member Functions inherited from IncrementalEngine::Transformable
 Transformable ()
 
virtual void SetScale (float factorX, float factorY)
 
virtual void SetScale (const D3DXVECTOR2 &factors)
 
virtual void SetOrigin (float x, float y)
 
virtual void SetOrigin (const D3DXVECTOR2 &origin)
 
virtual void SetRotation (float angle)
 
virtual float GetRotation () const
 
virtual const D3DXVECTOR2 & GetScale () const
 
virtual const D3DXVECTOR2 & GetOrigin () const
 
void Move (float offsetX, float offsetY)
 
void Move (const D3DXVECTOR2 &offset)
 
void Rotate (float angle)
 
void Scale (float factorX, float factorY)
 
void Scale (const D3DXVECTOR2 &factor)
 
const TransformGetTransform () const
 
const TransformGetInverseTransform () const
 

Protected Attributes

Button_upButton
 
Button_downButton
 
- Protected Attributes inherited from IncrementalEngine::Transformable
bool _transformNeedUpdate
 
- Protected Attributes inherited from IncrementalEngine::Drawable
RenderWindow_renderWindow
 
ShaderManager_shaderManager
 
ID3D11Device * _device
 

Private Attributes

vector< Actor * > _elements
 
int _elementsToShow
 
float _distanceBetweenElements
 
int _currentTopElement
 
bool _panelNeedsUpdate
 

Additional Inherited Members

- Protected Member Functions inherited from IncrementalEngine::Drawable
void CopyParameters (Drawable *drawable)
 

Detailed Description

Definition at line 9 of file Panel.h.

Constructor & Destructor Documentation

◆ Panel()

IncrementalEngine::Panel::Panel ( )

Definition at line 5 of file Panel.cpp.

6  {
7  _elements = vector<Actor*>();
8  }

◆ ~Panel()

IncrementalEngine::Panel::~Panel ( )
overridevirtual

Definition at line 10 of file Panel.cpp.

11  {
12  _elements.clear();
13  }

Member Function Documentation

◆ AddElement()

void IncrementalEngine::Panel::AddElement ( Actor actor)

Definition at line 63 of file Panel.cpp.

64  {
65  if (std::find(_elements.begin(), _elements.end(), actor) != _elements.end())
66  {
67  return;
68  }
69 
70  actor->SetParent(this);
71  _elements.push_back(actor);
72 
73  _panelNeedsUpdate = true;
74  }

◆ MoveDown()

void IncrementalEngine::Panel::MoveDown ( )

Definition at line 85 of file Panel.cpp.

86  {
88  {
90  _panelNeedsUpdate = true;
91  }
92  }

◆ MoveUp()

void IncrementalEngine::Panel::MoveUp ( )

Definition at line 76 of file Panel.cpp.

77  {
78  if (_currentTopElement > 0)
79  {
81  _panelNeedsUpdate = true;
82  }
83  }

◆ SetValues()

void IncrementalEngine::Panel::SetValues ( int  elementsToShow,
float  distanceBetweenElements 
)

Definition at line 55 of file Panel.cpp.

56  {
57  _elementsToShow = elementsToShow;
58  _distanceBetweenElements = distanceBetweenElements;
59 
60  _panelNeedsUpdate = true;
61  }

◆ Update()

void IncrementalEngine::Panel::Update ( float  dt)
overridevirtual

Reimplemented from IncrementalEngine::Sprite.

Definition at line 15 of file Panel.cpp.

16  {
17  Sprite::Update(dt);
18 
19  if (_upButton->Pressed())
20  {
21  MoveUp();
22  }
23 
24  if (_downButton->Pressed())
25  {
26  MoveDown();
27  }
28 
29  if (_panelNeedsUpdate)
30  {
31  SetOrigin(GetOrigin().x, 0);
32 
33  D3DXVECTOR2 pos = D3DXVECTOR2(0, -_distanceBetweenElements);
34  for (int i = 0; i < _elements.size(); i++)
35  {
36  if (i < _currentTopElement || i >= _currentTopElement + _elementsToShow)
37  {
38  _elements[i]->SetActive(false);
39  continue;
40  }
41 
42  pos = {
43  pos.x,
44  pos.y + _distanceBetweenElements + _elements[i]->GetLocalBounds().height()
45  };
46 
47  _elements[i]->SetPosition(pos);
48  _elements[i]->SetActive(true);
49  }
50 
51  _panelNeedsUpdate = false;
52  }
53  }

Member Data Documentation

◆ _currentTopElement

int IncrementalEngine::Panel::_currentTopElement
private

Definition at line 32 of file Panel.h.

◆ _distanceBetweenElements

float IncrementalEngine::Panel::_distanceBetweenElements
private

Definition at line 31 of file Panel.h.

◆ _downButton

Button* IncrementalEngine::Panel::_downButton
protected

Definition at line 25 of file Panel.h.

◆ _elements

vector<Actor*> IncrementalEngine::Panel::_elements
private

Definition at line 28 of file Panel.h.

◆ _elementsToShow

int IncrementalEngine::Panel::_elementsToShow
private

Definition at line 30 of file Panel.h.

◆ _panelNeedsUpdate

bool IncrementalEngine::Panel::_panelNeedsUpdate
private

Definition at line 34 of file Panel.h.

◆ _upButton

Button* IncrementalEngine::Panel::_upButton
protected

Definition at line 24 of file Panel.h.

IncrementalEngine::Button::Pressed
bool Pressed()
Definition: Button.cpp:40
IncrementalEngine::Transformable::SetOrigin
virtual void SetOrigin(float x, float y)
Definition: Transformable.cpp:82
IncrementalEngine::Transformable::GetOrigin
virtual const D3DXVECTOR2 & GetOrigin() const
Definition: Transformable.cpp:110
IncrementalEngine::Panel::_elements
vector< Actor * > _elements
Definition: Panel.h:28
IncrementalEngine::Panel::_distanceBetweenElements
float _distanceBetweenElements
Definition: Panel.h:31
IncrementalEngine::Panel::MoveUp
void MoveUp()
Definition: Panel.cpp:76
IncrementalEngine::Panel::MoveDown
void MoveDown()
Definition: Panel.cpp:85
IncrementalEngine::Panel::_elementsToShow
int _elementsToShow
Definition: Panel.h:30
IncrementalEngine::Sprite::Update
virtual void Update(float dt) override
Definition: Sprite.cpp:58
IncrementalEngine::Panel::_panelNeedsUpdate
bool _panelNeedsUpdate
Definition: Panel.h:34
IncrementalEngine::Panel::_upButton
Button * _upButton
Definition: Panel.h:24
IncrementalEngine::Panel::_currentTopElement
int _currentTopElement
Definition: Panel.h:32
IncrementalEngine::Panel::_downButton
Button * _downButton
Definition: Panel.h:25