Advertisement
Guest User

GUI_Element

a guest
Sep 17th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. /*
  2. Class: GUI_Element
  3. Purpose: -To provide an ABSTRACT base class for all the GUI elements within the framework.
  4.  
  5. Notes: >The class already holds basic functions for hot, cold, select, and deslect.
  6. Function pointers are going to use to provide callback/like functionality.
  7.  
  8. */
  9.  
  10. #ifndef GUI_ELEMENT_H
  11. #define GUI_ELEMENT_H
  12.  
  13. #include "globalvar.h"
  14. #include "Input.h"
  15. #include "SpritePool.h"
  16.  
  17. class GUI_Element
  18. {
  19. public:
  20. GUI_Element() {}
  21. GUI_Element(SpritePool gui_skin, int x, int y, int w, int h, bool visible, GUI_Element* parent);
  22. virtual ~GUI_Element();
  23.  
  24. //set functions
  25. void set_texture_ptr(SDL_Texture* texture) {texture_ptr = texture;}
  26. void set_parent_element(GUI_Element* parent);
  27. void set_frame(int x, int y, int w, int h);
  28. void set_offset_x(int i) {offset_x = i;}
  29. void set_offset_y(int i) {offset_y = i;}
  30. void set_x(int i) {frame.x = i;}
  31. void set_y(int i) {frame.y = i;}
  32. void set_w(int i) {frame.w = i;}
  33. void set_h(int i) {frame.h = i;}
  34. void set_visible(bool b);
  35. void set_hot(bool b);
  36. void set_selected(bool b);
  37. void set_name(std::string name) {this->name = name;}
  38.  
  39. //get functions
  40. SDL_Texture* get_texture_ptr() {return texture_ptr;}
  41. GUI_Element* get_parent_element() {return parent_element;}
  42. SDL_Rect* get_frame() {return &frame;}
  43. int get_offset_x() {return offset_x;}
  44. int get_offset_y() {return offset_y;}
  45. int get_x() {return frame.x;}
  46. int get_y() {return frame.y;}
  47. int get_w() {return frame.w;}
  48. int get_h() {return frame.h;}
  49. std::string get_name() {return name;}
  50.  
  51. //is_property functions
  52. bool is_visible() {return visible;}
  53. bool is_hot() {return hot;}
  54. bool is_selected() {return selected;}
  55.  
  56. //on_action functions
  57. virtual void on_hot() = 0;
  58. virtual void on_cold() = 0;
  59. virtual void on_select() = 0;
  60. virtual void on_deselect() = 0;
  61.  
  62. //render/update/check input functions
  63. virtual void render() = 0;
  64. virtual void update() = 0;
  65. virtual void check(Input &input) = 0;
  66.  
  67. //function pointers to be called when needed
  68. void (*func_hot) ();
  69. void (*func_select) ();
  70. void (*func_cold) ();
  71. void (*func_deselect) ();
  72.  
  73.  
  74. protected:
  75. int offset_x, offset_y;
  76.  
  77. SDL_Texture* texture_ptr;
  78.  
  79. GUI_Element* parent_element;
  80. std::string name;
  81.  
  82. SDL_Rect frame;
  83.  
  84. bool visible;
  85. bool hot;
  86. bool selected;
  87.  
  88.  
  89.  
  90.  
  91. private:
  92. };
  93.  
  94. #endif // GUI_ELEMENT_H
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. #include "GUI_Element.h"
  111.  
  112. GUI_Element::GUI_Element(SpritePool gui_skin, int x, int y, int w, int h, bool visible, GUI_Element* parent)
  113. {
  114. parent_element = parent;
  115. texture_ptr = gui_skin.get_texture("gui_bg");
  116.  
  117. this->visible = visible;
  118.  
  119. frame.x = x;
  120. frame.y = y;
  121. frame.w = w;
  122. frame.h = h;
  123. }
  124.  
  125. GUI_Element::~GUI_Element()
  126. {
  127. //dtor
  128. }
  129.  
  130. void GUI_Element::set_parent_element(GUI_Element* parent)
  131. {
  132. parent_element = parent;
  133. }
  134.  
  135. void GUI_Element::set_frame(int x, int y, int w, int h)
  136. {
  137. frame.x = x;
  138. frame.y = y;
  139. frame.w = w;
  140. frame.h = h;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement