fork download
  1. #include <includes.h>
  2.  
  3. //AARRGGBB
  4. struct button_color
  5. {
  6. DWORD button;
  7. DWORD border;
  8. DWORD text;
  9. button_color(){}
  10. ~button_color(){}
  11. button_color(DWORD color_button,DWORD color_border,DWORD color_text)
  12. : button(color_button),border(color_border),text(color_text)
  13. {}
  14. };
  15.  
  16. class button
  17. {
  18. public:
  19. std::string text_;
  20. button_color appearance_;
  21. button_color highlighted_;
  22. button_color mousedown_;
  23. bool clickable_;
  24. bool highlight_;
  25. unsigned short vkkey_;
  26. int fontid_;
  27.  
  28. button(){}
  29. ~button(){}
  30. button(std::string button_text,button_color &appearance, button_color &highlighted, button_color &mousedown, bool clickable, bool highlight, int fontid = 1, unsigned short vkkey = VK_LBUTTON)
  31. : text_(button_text), appearance_(appearance), highlighted_(highlighted), clickable_(clickable), highlight_(highlight), mousedown_(mousedown), vkkey_(vkkey), fontid_(fontid)
  32. {}
  33.  
  34. std::function<void(void)> callback;
  35. template<class Functor> button(Functor&& f) : callback(std::forward<Functor>(f))
  36. {
  37.  
  38. }
  39. template<class Functor> void SetFunction(Functor&& f)
  40. {
  41. callback = std::forward<Functor>(f);
  42. }
  43. void SetInfo(std::string button_text,button_color &appearance, button_color &highlighted, button_color &mousedown, bool clickable, bool highlight, int fontid = 1, unsigned short vkkey = VK_LBUTTON)
  44. {
  45. text_.assign(button_text);
  46. appearance_ = appearance;
  47. highlighted_ = highlighted;
  48. clickable_ = clickable;
  49. highlight_ = highlight;
  50. mousedown_ = mousedown;
  51. vkkey_ = vkkey;
  52. fontid_ = fontid;
  53. }
  54. float GetLenght()
  55. {
  56. return DirectXFont::Access(fontid_)->DrawLength(text_.c_str());
  57. }
  58. float GetHeight()
  59. {
  60. return DirectXFont::Access(fontid_)->DrawHeight();
  61. }
  62. bool IsCursorOnThis(float btn_x, float btn_y, float btn_w, float btn_h)
  63. {
  64. return IsPointInArea(cursorPos.x,cursorPos.y,btn_x,btn_y,btn_w,btn_h);
  65. }
  66. void Display(float btn_x, float btn_y, float btn_w, float btn_h)
  67. {
  68. if(!IsPointInArea(cursorPos.x,cursorPos.y,btn_x,btn_y,btn_w,btn_h))
  69. {
  70. render->D3DBoxBorder(btn_x,btn_y,btn_w,btn_h,appearance_.border,appearance_.button);
  71. DirectXFont::Access(fontid_)->Print(btn_x+((btn_w-GetLenght())/2.0f),btn_y+((btn_h-GetHeight())/2.0f),appearance_.text,text_.c_str(),true);
  72. return;
  73. }
  74. if(!clickable_)
  75. {
  76. render->D3DBoxBorder(btn_x,btn_y,btn_w,btn_h,(highlight_)? highlighted_.border : appearance_.border,(highlight_)? highlighted_.button : appearance_.button);
  77. DirectXFont::Access(fontid_)->Print(btn_x+((btn_w-GetLenght())/2.0f),btn_y+((btn_h-GetHeight())/2.0f),(highlight_)? highlighted_.text : appearance_.text,text_.c_str(),true);
  78. return;
  79. }
  80. if(!OldKeys(vkkey_).Down)
  81. {
  82. render->D3DBoxBorder(btn_x,btn_y,btn_w,btn_h,(highlight_)? highlighted_.border : appearance_.border,(highlight_)? highlighted_.button : appearance_.button);
  83. DirectXFont::Access(fontid_)->Print(btn_x+((btn_w-GetLenght())/2.0f),btn_y+((btn_h-GetHeight())/2.0f),(highlight_)? highlighted_.text : appearance_.text,text_.c_str(),true);
  84. return;
  85. }
  86. if(!Keys(vkkey_).Released)
  87. {
  88. render->D3DBoxBorder(btn_x,btn_y,btn_w,btn_h, mousedown_.border,mousedown_.button);
  89. DirectXFont::Access(fontid_)->Print(btn_x+((btn_w-GetLenght())/2.0f),btn_y+((btn_h-GetHeight())/2.0f), mousedown_.text,text_.c_str(),true);
  90. return;
  91. }
  92. callback();
  93. return;
  94. }
  95. void DisplayEx(float btn_x, float btn_y, float btn_w, float btn_h)
  96. {
  97. Display(btn_x, btn_y,GetLenght()+btn_w, GetHeight()+btn_h);
  98. }
  99. };
  100.  
  101. class Menu
  102. {
  103. public:
  104. std::vector<std::shared_ptr<button>> Buttons_;
  105. float pos_top_;
  106. float pos_left_;
  107. float spacing_;
  108. float width_;
  109. float height_;
  110. DWORD BoxColor;
  111. DWORD BorderColor;
  112.  
  113. std::string name_;
  114. Menu()
  115. {
  116. pos_top_ = 0.0f;
  117. pos_left_ = 0.0f;
  118. spacing_ = 5.0f;
  119. width_ = 0.0f;
  120. height_ = 0.0f;
  121. BoxColor = 0xFF330088;
  122. BorderColor = 0xFF338800;
  123. }
  124. ~Menu(){}
  125. void SetupWidth()
  126. {
  127. width_ = 0.0f;
  128. height_ = 0.0f;
  129. for(unsigned int i = 0; i < Buttons_.size(); ++i)
  130. {
  131. if(width_ < Buttons_[i]->GetLenght())
  132. {
  133. width_ = Buttons_[i]->GetLenght();
  134. }
  135. if(height_ < Buttons_[i]->GetHeight())
  136. {
  137. height_ = Buttons_[i]->GetHeight();
  138. }
  139. }
  140. }
  141. void AddButton(std::shared_ptr<button> button)
  142. {
  143. Buttons_.push_back(button);
  144. SetupWidth();
  145. }
  146. void RemoveButton(std::shared_ptr<button> button)
  147. {
  148. for(unsigned int i = 0; i < Buttons_.size(); ++i)
  149. {
  150. if(Buttons_[i] == button)
  151. {
  152. Buttons_.erase(Buttons_.begin()+i);
  153. }
  154. }
  155. SetupWidth();
  156. }
  157. float GetWidth(bool horizontal = false)
  158. {
  159. if(!horizontal)
  160. return (width_ + (spacing_ * 4.0f));
  161. if(Buttons_.empty())
  162. return spacing_;
  163. return spacing_ + ((width_ + (3.0f * spacing_)) * ((float)Buttons_.size()));
  164. }
  165. float GetHeight(bool horizontal = false)
  166. {
  167. if(horizontal)
  168. return (3.0f * spacing_) + height_;
  169. if(Buttons_.empty())
  170. return spacing_;
  171. return spacing_ + (((float)Buttons_.size())*spacing_)+((spacing_ + height_)*((float)Buttons_.size()));
  172. }
  173. void Process(bool horizontal = false, bool central = true)
  174. {
  175. if(Buttons_.empty())
  176. return;
  177. if(central)
  178. {
  179. Pos((((float)ScreenX)/2.0f)-(GetWidth(horizontal)/2.0f),(((float)ScreenY)/2.0f)-(GetHeight(horizontal)/2.0f));
  180. }
  181. if(!horizontal)
  182. {
  183. render->D3DBoxBorder(pos_left_,pos_top_,(width_ + (spacing_ * 4.0f)),spacing_ + (((float)Buttons_.size())*spacing_)+((spacing_ + height_)*((float)Buttons_.size())), BorderColor,BoxColor);
  184. for(unsigned int i = 0; i < Buttons_.size(); ++i)
  185. {
  186. Buttons_[i]->Display(pos_left_ + spacing_,pos_top_ + spacing_ + spacing_*((float)i) + ((spacing_ + height_)*(float)i),(width_ + (2.0f * spacing_)),height_+spacing_);
  187. }
  188. }
  189. else
  190. {
  191. render->D3DBoxBorder(pos_left_,pos_top_,spacing_ + ((width_ + (3.0f * spacing_)) * ((float)Buttons_.size())),(3.0f * spacing_) + height_, BorderColor,BoxColor);
  192. for(unsigned int i = 0; i < Buttons_.size(); ++i)
  193. {
  194. Buttons_[i]->Display(pos_left_ + spacing_ + ((width_ + (3.0f * spacing_)) * ((float)i)),pos_top_ + spacing_ ,(width_ + (2.0f * spacing_)),height_+spacing_);
  195. }
  196. }
  197. }
  198. void Pos(float x, float y)
  199. {
  200. pos_left_ = x;
  201. pos_top_ = y;
  202. }
  203. void Colors(DWORD border,DWORD background)
  204. {
  205. BorderColor = border;
  206. BoxColor = background;
  207. }
  208. };
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty