PaiusCatalin9577

Composite - Laborator 11

May 28th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. #include<windows.h>
  5.  
  6. class UIControl {
  7. protected:
  8.     int X, Y, Width, Height; // coordonatele controlului
  9.     UIControl *Parent; // Parintele controlului (NULL inseamna ca nu are parinte)
  10. public:
  11.     virtual void Paint() = 0; // functie care deseneaza controlul
  12.     virtual void SetParent(UIControl *parent){
  13.         this->Parent = parent;
  14.     }
  15. };
  16.  
  17. class UIButton : public UIControl{
  18. private:
  19.     bool IsPressed;
  20.     std::string Text;
  21. public:
  22.     UIButton(int x, int y, int height, int width, std::string text){
  23.         this->X = x;
  24.         this->Y = y;
  25.         this->Height = height;
  26.         this->Width = width;
  27.         this->Text = text;
  28.         this->IsPressed = true;
  29.     }
  30.     void setPress(bool press){
  31.         this->IsPressed = press;
  32.     }
  33.     void setText(std::string text){
  34.         this->Text = text;
  35.     }
  36.     std::string GetText(){
  37.         return this->Text;
  38.     }
  39.     void Paint(){
  40.         COORD c;
  41.         c.X = this->X;
  42.         c.Y = this->Y;
  43.         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
  44.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (this->Width & 0x0F) + ((this->Height & 0x0F) << 4));
  45.         printf("%s", this->Text.c_str());
  46.     }
  47. };
  48.  
  49. class UILabel : public UIControl{
  50.     std::string Text;
  51. public:
  52.     UILabel(int x, int y, int height, int width, std::string text){
  53.         this->X = x;
  54.         this->Y = y;
  55.         this->Height = height;
  56.         this->Width = width;
  57.         this->Text = text;
  58.     }
  59.     void SetText(std::string text){
  60.         this->Text = text;
  61.     }
  62.     std::string GetText(){
  63.         return this->Text;
  64.     }
  65.     void Paint(){
  66.         COORD c;
  67.         c.X = this->X;
  68.         c.Y = this->Y;
  69.         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
  70.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (this->Width & 0x0F) + ((this->Height & 0x0F) << 4));
  71.         printf("%s", this->Text.c_str());
  72.     }
  73. };
  74.  
  75. class UIPanel : public UIControl{
  76.     std::vector<UIControl *> Children;
  77. public:
  78.     void AddChild(UIControl *child){
  79.         Children.push_back(child);
  80.     }
  81.     void Paint(){
  82.         for (unsigned int i = 0; i < Children.size(); ++i){
  83.             Children[i]->Paint();
  84.         }
  85.     }
  86. };
  87.  
  88. void main(void){
  89.     UIPanel ControlPanel[100];
  90.     ControlPanel[0].AddChild(new UILabel(0, 3, 10, 9, "Text 1\n"));
  91.     ControlPanel[1].AddChild(new UIButton(3, 6, 9, 10, "Text 2\n"));
  92.     ControlPanel[1].AddChild(new UIButton(6, 9, 12, 1, "Text 3\n"));
  93.     ControlPanel[1].AddChild(new UIButton(9, 12, 11, 13, "Text 4\n"));
  94.     ControlPanel[0].Paint();
  95.     ControlPanel[1].Paint();
  96. }
Add Comment
Please, Sign In to add comment