Public paste
lalala
By: cMouseMenu.cpp | Date: Oct 25 2009 12:45 | Format: None | Expires: never | Size: 5.32 KB | Hits: 1218

  1. #include "main.h"
  2. #include "cMouseMenu.h"
  3.  
  4. //----------------------------------------------------
  5. //class cButton---------------------------------------
  6. //----------------------------------------------------
  7. cButton::cButton()
  8. {
  9.         int x = 0;
  10.         int y = 0;
  11.         int w = 0;
  12.         int h = 0;
  13.         char *caption = "";
  14.         int red = 0;
  15.         int green = 0;
  16.         int blue = 0;
  17.         int alpha = 255;
  18.         vgui::HFont hFont = g_pMatSystemSurface->CreateFont();
  19.         g_pMatSystemSurface->SetFontGlyphSet(hFont, "Arial", 15, 400, 0, 0, 0);
  20. };
  21.  
  22. bool cButton::bClicked()
  23. {
  24.         if(GetAsyncKeyState(0x01))
  25.         {
  26.                 LPPOINT lpPos;
  27.                 GetCursorPos(lpPos);
  28.                 if((lpPos->x > this->x) && (lpPos->x < this->x+w)
  29.                         &&(lpPos->y > this->y) && (lpPos->y < this->y+h))
  30.                         return true;
  31.         }
  32.         return false;
  33. }
  34.  
  35. void cButton::Draw(bool clicked)
  36. {
  37.         if(!clicked)
  38.         {
  39.                 g_pMatSystemSurface->DrawSetColor(this->red, this->green, this->blue, this->alpha);
  40.                 g_pMatSystemSurface->DrawFilledRect(x, y, x+w, y+h);
  41.                 g_pMatSystemSurface->DrawColoredText(this->hFont, x+2, y+2, 0, 0, 0, 255, (char *)&this->caption);
  42.                 return;
  43.         }
  44.         if(clicked)
  45.         {
  46.                 g_pMatSystemSurface->DrawSetColor(this->red-10, this->green-10, this->blue-10, this->alpha-10);
  47.                 g_pMatSystemSurface->DrawFilledRect(x, y, x+w, y+h);
  48.                 g_pMatSystemSurface->DrawColoredText(this->hFont, x+2, y+2, 0, 0, 0, 255, (char *)&this->caption);
  49.                 return;
  50.         }
  51.         return;
  52. }
  53.  
  54. void cButton::Init(int x, int y, int w, int h, char *caption, int r, int g, int b, int alpha)
  55. {
  56.         this->x = x;
  57.         this->y = y;
  58.         this->w = w;
  59.         this->h = h;
  60.         this->caption = (char *)&caption;
  61.         this->red = r;
  62.         this->green = g;
  63.         this->blue = b;
  64.         this->alpha = alpha;
  65.         return;
  66. }
  67.  
  68. //----------------------------------------------------
  69. //class cCheckobx-------------------------------------
  70. //----------------------------------------------------
  71. cCheckbox::cCheckbox()
  72. {
  73.         this->x = 0;
  74.         this->y = 0;
  75.         this->caption = "";
  76.         this->checked = false;
  77.         vgui::HFont hFont = g_pMatSystemSurface->CreateFont();
  78.         g_pMatSystemSurface->SetFontGlyphSet(hFont, "Arial", 15, 400, 0, 0, 0);
  79. }
  80.  
  81. void cCheckbox::Init(int x, int y, char *caption, bool checked)
  82. {
  83.         this->x = x;
  84.         this->y = y;
  85.         this->caption = (char *)&caption;
  86.         this->checked = checked;
  87.         return;
  88. }
  89.  
  90. void cCheckbox::Draw()
  91. {
  92.         g_pMatSystemSurface->DrawSetColor(0, 0, 0, 255);
  93.         g_pMatSystemSurface->DrawOutlinedRect(x-1, y-1, x+11, y+11);
  94.         g_pMatSystemSurface->DrawSetColor(30, 30, 30, 255);
  95.         g_pMatSystemSurface->DrawFilledRect(x, y, x+10, x+10);
  96.  
  97.         g_pMatSystemSurface->DrawColoredText(this->hFont, x+2, y+2, 0, 0, 0, 255, "%s", this->caption);
  98.        
  99.         if(this->checked)
  100.         {
  101.                 g_pMatSystemSurface->DrawSetColor(0, 0, 0, 255);
  102.                 g_pMatSystemSurface->DrawFilledRect(x+2, y+2, x+8, y+8);
  103.         }
  104.         return;
  105. }
  106.  
  107. bool cCheckbox::bClicked()
  108. {
  109.         if(GetAsyncKeyState(0x01))
  110.         {
  111.                 LPPOINT lpPos;
  112.                 GetCursorPos(lpPos);
  113.  
  114.                 if((lpPos->x >= this->x) && (lpPos->x <= this->x+10)
  115.                         &&(lpPos->y >= this->y) && (lpPos->y <= this->y+10))
  116.                 {
  117.                         if(this->checked)
  118.                         {       this->checked = false; return false;}
  119.                         else if(!this->checked)
  120.                         {       this->checked = true; return true;}
  121.                 }
  122.         }
  123.         return false;
  124. }
  125. //----------------------------------------------------
  126. //class cLabel----------------------------------------
  127. //----------------------------------------------------
  128. cLabel::cLabel()
  129. {
  130.         this->x = 0;
  131.         this->y = 0;
  132.         this->caption = "";
  133.         vgui::HFont hFont = g_pMatSystemSurface->CreateFont();
  134.         g_pMatSystemSurface->SetFontGlyphSet(hFont, "Arial", 15, 400, 0, 0, 0);
  135. }
  136.  
  137. void cLabel::Init(int x, int y, char *caption)
  138. {
  139.         this->x = x;
  140.         this->x = y;
  141.         this->caption = (char *)&caption;
  142. }
  143.  
  144. void cLabel::Draw()
  145. {
  146.         g_pMatSystemSurface->DrawColoredText(this->hFont, x, y, 0, 0, 0, 255, "%s", this->caption);
  147. }
  148. //----------------------------------------------------
  149. //class cMenu-----------------------------------------
  150. //----------------------------------------------------
  151. cMenu::cMenu()
  152. {
  153.         this->x = 0;
  154.         this->y = 0;
  155.         this->w = 0;
  156.         this->h = 0;
  157.  
  158.         this->a = 0;
  159.         this->r = 0;
  160.         this->g = 0;
  161.         this->b = 0;
  162.  
  163.         this->hFont = g_pMatSystemSurface->CreateFont();
  164. }
  165.  
  166. void cMenu::Init(int x, int y, int w, int h, int r, int g, int b, int a, char *caption, char *fontname)
  167. {
  168.         this->x = x;
  169.         this->y = y;
  170.         this->w = w;
  171.         this->h = h;
  172.  
  173.         this->r = r;
  174.         this->g = g;
  175.         this->b = b;
  176.         this->a = a;
  177.  
  178.         this->caption = (char *)&caption;
  179.         g_pMatSystemSurface->SetFontGlyphSet(this->hFont, (char *) &fontname, 20, 400, 0, 0, 0);
  180. }
  181.  
  182. void cMenu::Draw()
  183. {
  184.         g_pMatSystemSurface->DrawSetColor(0, 0, 0, 255);
  185.         g_pMatSystemSurface->DrawOutlinedRect(this->x-1, this->y-1, this->x+this->w+1, this->y+this->h+1);              //Draw black Border of the Main Menu
  186.         g_pMatSystemSurface->DrawOutlinedRect(this->x-1, this->y-31, this->x+this->w+1, this->y-6);                             //Draw black Border of the Captionline
  187.  
  188.         g_pMatSystemSurface->DrawSetColor(this->r, this->g, this->b, this->a);
  189.         g_pMatSystemSurface->DrawFilledRect(this->x, this->y, this->x+this->w, this->y+this->h);                                //Draw Main Menu Window
  190.  
  191.         g_pMatSystemSurface->DrawFilledRect(this->x, this->y-30, this->x+this->w, this->y-5);                                   //Draw Captionline
  192.         g_pMatSystemSurface->DrawColoredText(this->hFont, this->x+3, this->y-27, 0, 0, 0, 255, "%s", this->caption);
  193. };
  194.  
  195. void cMenu::SetAlpha(int a)
  196. {
  197.         this->a = a;
  198. }
  199.  
  200. void cMenu::SetColor(int r, int g, int b, int a)
  201. {
  202.         this->r = r;
  203.         this->g = g;
  204.         this->b = b;
  205.         this->a = a;
  206. }