Skip to content

Commit b11d8f5

Browse files
authored
Uploading project 3
1 parent fbfa0ae commit b11d8f5

27 files changed

+3010
-0
lines changed

GUI/Input.cpp

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#include "Input.h"
2+
#include "Output.h"
3+
4+
5+
6+
7+
Input::Input(window* pW)
8+
{
9+
pWind = pW; //point to the passed window
10+
}
11+
12+
void Input::GetPointClicked(Point &P) const
13+
{
14+
pWind->WaitMouseClick(P.x, P.y); //Wait for mouse click
15+
}
16+
17+
18+
string Input::GetString(Output *pO) const
19+
{
20+
string Str;
21+
char Key;
22+
while(1)
23+
{
24+
pWind->WaitKeyPress(Key);
25+
if(Key == 27 ) //ESCAPE key is pressed
26+
return ""; //returns nothing as user has cancelled label
27+
if(Key == 13 ) //ENTER key is pressed
28+
return Str;
29+
if (Key == 8) //BackSpace is pressed
30+
{
31+
if (Str.size() > 0)Str.resize(Str.size() - 1);
32+
}
33+
else
34+
Str += Key;
35+
pO->PrintMessage(Str);
36+
}
37+
38+
}
39+
40+
41+
double Input::GetValue(Output* pO) const // Reads a double value from the user
42+
{
43+
44+
int ctr = 0;
45+
string Str;
46+
char Key;
47+
while (1)
48+
{
49+
pWind->WaitKeyPress(Key);
50+
if (Key == 27) //ESCAPE key is pressed
51+
return 0; //returns nothing as user has cancelled label
52+
if (Key == 13) //ENTER key is pressed
53+
break;
54+
if (Key == 8) //BackSpace is pressed
55+
{
56+
if (Str.size() > 0)Str.resize(Str.size() - 1);
57+
}
58+
else if (Key >= 48 && Key <= 57) //keys nymber
59+
Str += Key;
60+
else if (Key == 46)
61+
{
62+
if (ctr == 0)
63+
{
64+
Str += Key;
65+
ctr++;
66+
}
67+
}
68+
else if (Key == 45)
69+
if (Str.size()==0)
70+
Str += Key;
71+
pO->PrintMessage(Str);
72+
}
73+
74+
stringstream i(Str);
75+
double D=0;
76+
i >> D;
77+
78+
return D;
79+
}
80+
81+
ActionType Input::GetUserAction() const
82+
{
83+
//This function reads the position where the user clicks to determine the desired action
84+
85+
int x, y;
86+
pWind->WaitMouseClick(x, y); //Get the coordinates of the user click
87+
88+
if (UI.AppMode == DESIGN) //application is in design mode
89+
{
90+
//[1] If user clicks on the Toolbar
91+
if (y >= 0 && y <= 57)
92+
{
93+
//Check whick Menu item was clicked
94+
if (x >= 0 && x <= 63)
95+
return SIM_MODE;
96+
if (x > 63 && x <= 139)
97+
return ADD_ellipse_start;
98+
if (x > 139 && x <= 234)
99+
return ADD_Read;
100+
if (x > 234 && x <= 305)
101+
return ADD_One_Variable;
102+
if (x > 305 && x <= 379)
103+
return ADD_SMPL_ASSIGN;
104+
if (x > 379 && x <= 457)
105+
return ADD_Single_OP;
106+
if (x > 457 && x <= 532)
107+
return ADD_ellipse_END;
108+
if (x > 532 && x <= 592)
109+
return ADD_CONDITION;
110+
if (x > 592 && x <= 646)
111+
return ADD_CONNECTOR;
112+
if (x > 646 && x <= 717)
113+
return COPY;
114+
if (x > 717 && x <= 781)
115+
return CUT;
116+
if (x > 781 && x <= 838)
117+
return MOVE;
118+
if (x > 838 && x <= 908)
119+
return COMMENT;
120+
return DSN_TOOL; //a click on empty part of the tool bar
121+
122+
}
123+
else if (y >= 60 && y <= UI.TlBrWdth)
124+
{
125+
if (x >= 0 && x <= 63)
126+
return LOAD;
127+
if (x > 63 && x <= 139)
128+
return SAVE;
129+
if (x > 139 && x <= 234)
130+
return ADD_Write;
131+
if (x > 234 && x <= 305)
132+
return SELECT;
133+
if (x > 305 && x <= 379)
134+
return MULTI_SELECT;
135+
if (x > 379 && x <= 457)
136+
return UNDO;
137+
if (x > 457 && x <= 532)
138+
return REDO;
139+
if (x > 532 && x <= 592)
140+
return ZoomIn;
141+
if (x > 592 && x <= 646)
142+
return ZoomOut;
143+
if (x > 646 && x <= 717)
144+
return EDIT_CONN;
145+
if (x > 717 && x <= 781)
146+
return EDIT_STAT;
147+
if (x > 781 && x <= 838)
148+
return DEL;
149+
if (x > 838 && x <= 908)
150+
return EXIT;
151+
}
152+
153+
//[2] User clicks on the drawing area
154+
if (y >= UI.TlBrWdth && y < UI.height - UI.StBrWdth)
155+
{
156+
return No_Action; //user want to select/unselect a statement in the flowchart
157+
}
158+
159+
//[3] User clicks on the status bar
160+
return STATUS;
161+
}
162+
else //Application is in Simulation mode
163+
{
164+
//return SIM_MODE; //This should be changed after creating the compelete simulation bar
165+
if (y >= 0 && y <= 78)
166+
{
167+
if (x >= 0 && x <= 77)
168+
return DSN_MODE;
169+
else if (x>77 && x <= 157)
170+
return RUN;
171+
else if (x>157 && x <= 234)
172+
return DEBUG;
173+
else if (x>234 && x <= 314)
174+
return VALID;
175+
else if (x>314 && x <= 395)
176+
return Generate;
177+
else return No_Action;
178+
}
179+
else {
180+
return No_Action;
181+
}
182+
}
183+
184+
}
185+
Input::~Input()
186+
{
187+
}

GUI/Input.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef INPUT_H
2+
#define INPUT_H
3+
4+
#include "..\DEFS.h"
5+
#include "UI_Info.h"
6+
#include "..\CMUgraphicsLib\CMUgraphics.h"
7+
#include<sstream>
8+
class Output;
9+
class Input //The application manager should have a pointer to this class
10+
{
11+
private:
12+
window *pWind; //Pointer to the Graphics Window
13+
public:
14+
Input(window *pW); //Consturctor
15+
void GetPointClicked(Point &P) const;//Gets coordinate where user clicks
16+
17+
double GetValue(Output* pO) const; // Reads a double value from the user
18+
19+
string GetString(Output* pO) const ; //Returns a string entered by the user
20+
21+
ActionType GetUserAction() const; //Reads the user click and maps it to an action
22+
23+
~Input();
24+
};
25+
26+
#endif

0 commit comments

Comments
 (0)