-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationManager.cpp
More file actions
143 lines (120 loc) · 4.32 KB
/
Copy pathApplicationManager.cpp
File metadata and controls
143 lines (120 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "ApplicationManager.h"
#include "Actions\AddRectAction.h"
#include "SendBackAction.h"
#include "BringFrontAction.h"
//Constructor
ApplicationManager::ApplicationManager()
{
//Create Input and output
pOut = new Output;
pIn = pOut->CreateInput();
FigCount = 0;
//Create an array of figure pointers and set them to NULL
for(int i=0; i<MaxFigCount; i++)
FigList[i] = NULL;
}
//==================================================================================//
// Actions Related Functions //
//==================================================================================//
ActionType ApplicationManager::GetUserAction() const
{
//Ask the input to get the action from the user.
return pIn->GetUserAction();
}
////////////////////////////////////////////////////////////////////////////////////
//Creates an action and executes it
void ApplicationManager::ExecuteAction(ActionType ActType)
{
Action* pAct = NULL;
//According to Action Type, create the corresponding action object
switch (ActType)
{
case DRAW_RECT:
pAct = new AddRectAction(this);
break;
case SEND_BACK:
pAct = new SendBackAction(this);
break;
case BRING_FRONT:
pAct = new BringFrontAction(this);
break;
case EXIT:
///create ExitAction here
break;
case STATUS: //a click on the status bar ==> no action
return;
}
//Execute the created action
if(pAct != NULL)
{
pAct->Execute();//Execute
delete pAct; //You may need to change this line depending to your implementation
pAct = NULL;
}
}
//==================================================================================//
// Figures Management Functions //
//==================================================================================//
//Add a figure to the list of figures
void ApplicationManager::AddFigure(CFigure* pFig)
{
if(FigCount < MaxFigCount )
FigList[FigCount++] = pFig;
}
void ApplicationManager::SendFigBack(int SelectedIndex)
{
CFigure* SelectedFigure = FigList[SelectedIndex];//saving the selected figure in a separate pointer
for (int i = SelectedIndex; i > 0; i--)//looping on figlist to increase the index of all preceding figures by one
FigList[i] = FigList[i - 1];//this leaves the first place in the array empty for the selected figure
//note that FigCount does not change
FigList[0] = SelectedFigure;
}
void ApplicationManager::BringFigFront(int SelectedIndex)
{
CFigure* SelectedFigure = FigList[SelectedIndex];//saving the selected figure in a separate pointer
for (int i = SelectedIndex; i < FigCount; i++)//looping on figlist to dectrasee the index of all following figures by one
FigList[i] = FigList[i + 1];//this leaves the last place in the array empty for the selected figure
//note that FigCount does not change
FigList[FigCount-1] = SelectedFigure;
}
////////////////////////////////////////////////////////////////////////////////////
CFigure *ApplicationManager::GetFigure(int x, int y) const
{
//If a figure is found return a pointer to it.
//if this point (x,y) does not belong to any figure return NULL
//Add your code here to search for a figure given a point x,y
//Remember that ApplicationManager only calls functions do NOT implement it.
return NULL;
}
int ApplicationManager::GetSelectedFigureIndex() const
{
for (int i = 0; i < FigCount; i++)//searching for a selected figure
if (FigList[i]->IsSelected())
return i;
return -1;//a flag indicating that no figures are selected
}
//==================================================================================//
// Interface Management Functions //
//==================================================================================//
//Draw all figures on the user interface
void ApplicationManager::UpdateInterface() const
{
for(int i=0; i<FigCount; i++)
FigList[i]->Draw(pOut); //Call Draw function (virtual member fn)
}
////////////////////////////////////////////////////////////////////////////////////
//Return a pointer to the input
Input *ApplicationManager::GetInput() const
{ return pIn; }
//Return a pointer to the output
Output *ApplicationManager::GetOutput() const
{ return pOut; }
////////////////////////////////////////////////////////////////////////////////////
//Destructor
ApplicationManager::~ApplicationManager()
{
for(int i=0; i<FigCount; i++)
delete FigList[i];
delete pIn;
delete pOut;
}