-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
136 lines (123 loc) · 3.32 KB
/
window.cpp
File metadata and controls
136 lines (123 loc) · 3.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
//
// Created by Sg on 29.07.2022.
//
#include "window.h"
#include <limits>
using namespace std;
std::string Window::isWindow(int x, int y) const {
if(x >= xX && x < xX + xL)
if(y >= yY && y < yY + yH)
return "1";
return "0";
}
void Window::setX(int L) {
int x = 0;
cout << "Enter X coordinate:";
do
{
if(!cin || (xX + x > L - xL || xX + x < 0))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout<<"-----------------------------------------\n";
cout<<"Wrong x!";
cout<<"\n-----------------------------------------\n";
cout<<"Repeat enter X coordinate:";
}
cin>>x;
}
while(!cin || (xX + x > L - xL || xX + x < 0));
xX += x;
cout << "-ok" << endl;
}
void Window::setY(int H) {
int y = 0;
cout << "Enter Y coordinate:";
do
{
if(!cin || (yY + y > H - yH || yY + y < 0))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout<<"-----------------------------------------\n";
cout<<"Wrong Y!";
cout<<"\n-----------------------------------------\n";
cout<<"Repeat enter Y coordinate:";
}
cin>>y;
}
while(!cin || (yY + y > H - yH || yY + y < 0));
yY += y;
cout << "-ok" << endl;
}
void Window::setXL(int L) {
int XL = 0;
cout << "Enter XL:";
do
{
if(!cin || (XL + xX > L || XL < 0))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout<<"-----------------------------------------\n";
cout<<"Wrong XL!";
cout<<"\n-----------------------------------------\n";
cout<<"Repeat enter XL:";
}
cin>>XL;
}
while(!cin || (XL + xX > L || XL < 0));
xL = XL;
cout << "-ok" << endl;
}
void Window::setYH(int H) {
int YH = 0;
cout << "Enter YH:";
do
{
if(!cin || (YH + yY > H || YH < 0))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout<<"-----------------------------------------\n";
cout<<"Wrong YH!";
cout<<"\n-----------------------------------------\n";
cout<<"Repeat enter YH:";
}
cin>>YH;
}
while(!cin || (YH + yY > H || YH < 0));
yH = YH;
cout << "-ok" << endl;
}
void Window::move(const Monitor& M) {
cout << "---Enter vector coordinates---" << endl;
setX(M.getLenght());
setY(M.getHight());
}
void Window::resize(const Monitor& M) {
cout << "---Resize window---" << endl;
setXL(M.getLenght());
setYH(M.getHight());
}
void Monitor::showWindow(const Window& W) const {
for (int i = 0; i < H; ++i)
{
for (int j = 0; j < L; ++j)
cout << W.isWindow(j,i);
cout << endl;
}
}
int Monitor::getLenght() const {
return L;
}
int Monitor::getHight() const {
return H;
}
void showMenu()
{
cout<<"Valid command format: 1 'resize' for resize a window;" << endl;
cout<<" 2 'display' for display a window in the monitor;" << endl;
cout<<" 3 'move' for move a window in the monitor;" << endl;
cout<<" 4 'exit' for exit." << endl;
}