Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<string>
- #include<windows.h>
- class UIControl {
- protected:
- int X, Y, Width, Height; // coordonatele controlului
- UIControl *Parent; // Parintele controlului (NULL inseamna ca nu are parinte)
- public:
- virtual void Paint() = 0; // functie care deseneaza controlul
- virtual void SetParent(UIControl *parent){
- this->Parent = parent;
- }
- };
- class UIButton : public UIControl{
- private:
- bool IsPressed;
- std::string Text;
- public:
- UIButton(int x, int y, int height, int width, std::string text){
- this->X = x;
- this->Y = y;
- this->Height = height;
- this->Width = width;
- this->Text = text;
- this->IsPressed = true;
- }
- void setPress(bool press){
- this->IsPressed = press;
- }
- void setText(std::string text){
- this->Text = text;
- }
- std::string GetText(){
- return this->Text;
- }
- void Paint(){
- COORD c;
- c.X = this->X;
- c.Y = this->Y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (this->Width & 0x0F) + ((this->Height & 0x0F) << 4));
- printf("%s", this->Text.c_str());
- }
- };
- class UILabel : public UIControl{
- std::string Text;
- public:
- UILabel(int x, int y, int height, int width, std::string text){
- this->X = x;
- this->Y = y;
- this->Height = height;
- this->Width = width;
- this->Text = text;
- }
- void SetText(std::string text){
- this->Text = text;
- }
- std::string GetText(){
- return this->Text;
- }
- void Paint(){
- COORD c;
- c.X = this->X;
- c.Y = this->Y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (this->Width & 0x0F) + ((this->Height & 0x0F) << 4));
- printf("%s", this->Text.c_str());
- }
- };
- class UIPanel : public UIControl{
- std::vector<UIControl *> Children;
- public:
- void AddChild(UIControl *child){
- Children.push_back(child);
- }
- void Paint(){
- for (unsigned int i = 0; i < Children.size(); ++i){
- Children[i]->Paint();
- }
- }
- };
- void main(void){
- UIPanel ControlPanel[100];
- ControlPanel[0].AddChild(new UILabel(0, 3, 10, 9, "Text 1\n"));
- ControlPanel[1].AddChild(new UIButton(3, 6, 9, 10, "Text 2\n"));
- ControlPanel[1].AddChild(new UIButton(6, 9, 12, 1, "Text 3\n"));
- ControlPanel[1].AddChild(new UIButton(9, 12, 11, 13, "Text 4\n"));
- ControlPanel[0].Paint();
- ControlPanel[1].Paint();
- }
Add Comment
Please, Sign In to add comment