GUI.hpp
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* GUI.hpp :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: gychoi <gychoi@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/12/04 19:56:41 by gychoi #+# #+# */ 9 /* Updated: 2023/12/10 21:47:15 by gychoi ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #pragma once 14 #ifndef __GUI_HPP__ 15 #define __GUI_HPP__ 16 17 #include <dirent.h> 18 #include <signal.h> 19 #include <sys/ioctl.h> 20 #include <termios.h> 21 #include <time.h> 22 #include <unistd.h> 23 #include <cstdio> 24 #include <cstdlib> 25 #include <cstring> 26 #include <iostream> 27 #include <string> 28 29 #include "Bureaucrat.hpp" 30 #include "Intern.hpp" 31 32 #define OK (1) 33 #define ERR (0) 34 35 #define MARGIN (10) 36 #define WIDTH (70) 37 #define HEIGHT (12) 38 #define BOX_WIDTH (40) 39 #define BOX_HEIGHT (6) 40 41 #define SELECT "\033[7m" 42 #define RESET "\033[0m" 43 44 enum eKey 45 { 46 NONE, 47 UP, 48 DOWN, 49 RIGHT, 50 LEFT, 51 ENTER, 52 LETTER, 53 BACKSPACE 54 }; 55 56 enum eLogin 57 { 58 ID, 59 GRADE, 60 CHECK_LOGIN 61 }; 62 63 enum eStage 64 { 65 LOGIN, 66 LOBBY, 67 CHECK, 68 IMAGE, 69 FORM, 70 MESSAGE 71 }; 72 73 enum eLobby 74 { 75 MAKE, 76 SHOW, 77 LOGOUT, 78 QUIT 79 }; 80 81 enum eForm 82 { 83 BACK, 84 SHRUBBERY, 85 ROBOTOMY, 86 PRESIDENT 87 }; 88 89 enum ePopUP 90 { 91 DISABLE, 92 NAME, 93 SIGN, 94 EXECUTE, 95 RESULT 96 }; 97 98 struct FormInfo 99 { 100 std::string name; 101 std::string message; 102 AForm* form; 103 }; 104 105 struct BureaucratInfo 106 { 107 std::string name; 108 std::string grade; 109 Bureaucrat* bureaucrat; 110 }; 111 112 struct Status 113 { 114 float renderSpeed; 115 bool renderStop; 116 char letter; 117 unsigned short stage; 118 short select; 119 bool create; 120 short popUp; 121 bool pressEnter; 122 bool yesNo; 123 bool pressLetter; 124 bool pressBackSpace; 125 struct BureaucratInfo bureaucratInfo; 126 struct FormInfo formInfo; 127 std::string shrubberyArray[8]; 128 std::string filename; 129 bool isError; 130 std::string errorMessage; 131 }; 132 133 extern struct Status status; 134 135 void resetTerminal(); 136 bool configureTerminal(); 137 void eraseTerminal(); 138 139 int readInput(); 140 int readKey(char* buf, int k); 141 void controlKey(int key); 142 void makeBuffer(); 143 144 void deleteBureaucrat(); 145 void deleteForm(); 146 147 void initStatus(); 148 void deleteInfo(); 149 void setStage(); 150 void updateStatus(); 151 void updatePopUp(); 152 void setFilename(); 153 154 void drawLobby(); 155 void drawCheck(); 156 void drawForm(); 157 void drawSignPopUp(); 158 void drawNamePopUp(); 159 void drawExecutePopUp(); 160 void drawShrubberyResultPopUp(); 161 void drawRobotomyResultPopUp(); 162 void drawLogin(); 163 void drawImage(); 164 void drawGoodbye(); 165 166 void printIfError(); 167 void changeRenderSpeed(float speed); 168 void setFilename(); 169 void findAllShrubberyFiles(std::string shrubberyArray[]); 170 short getArraySize(std::string const arr[], short size); 171 172 #endif /* __GUI_HPP__ */