Advertisement
snake5

[sgs-cppbc] UI control binding code

Nov 12th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #ifndef __SGS_UI_CONTROL__
  2. #define __SGS_UI_CONTROL__
  3.  
  4.  
  5. #include <sgs_cppbc.h>
  6.  
  7. #include <vector>
  8.  
  9.  
  10. #define EV_Paint      1
  11. #define EV_Layout     2
  12. #define EV_KeyDown    10
  13. #define EV_KeyUp      11
  14. #define EV_Char       12
  15. #define EV_ButtonDown 20
  16. #define EV_ButtonUp   21
  17. #define EV_MouseMove  22
  18. #define EV_Attach     30
  19. #define EV_Detach     31
  20. #define EV_HitTest    32
  21.  
  22.  
  23. struct UIEvent
  24. {
  25.     SGS_OBJECT;
  26.    
  27.     UIEvent();
  28.    
  29.     SGS_PROPERTY int type;
  30.     SGS_PROPERTY int key;
  31.     SGS_PROPERTY int button;
  32.     SGS_PROPERTY int uchar;
  33.     SGS_PROPERTY int x;
  34.     SGS_PROPERTY int y;
  35.     SGS_PROPERTY int rx;
  36.     SGS_PROPERTY int ry;
  37. };
  38.  
  39.  
  40. struct UIControl;
  41. struct UIFrame
  42. {
  43.     typedef sgsHandle< UIFrame > Handle;
  44.    
  45.     SGS_OBJECT;
  46.    
  47.     UIFrame();
  48.    
  49.     SGS_METHOD void event( UIEvent* e );
  50.     SGS_METHOD void render();
  51.    
  52.     SGS_IFUNC(SGS_OP_GCMARK) int sgs_gcmark( SGS_CTX, sgs_VarObj* obj, int );
  53.    
  54.     SGS_PROPERTY sgsVariable render_image;
  55.     SGS_PROPERTY sgsVariable render_text;
  56.     SGS_PROPERTY sgsVariable ui_event;
  57.     SGS_PROPERTY float x;
  58.     SGS_PROPERTY float y;
  59.     SGS_PROPERTY float width;
  60.     SGS_PROPERTY float height;
  61.     SGS_PROPERTY sgsHandle< UIControl > root;
  62. };
  63.  
  64.  
  65. struct UIControl
  66. {
  67.     typedef sgsHandle< UIControl > Handle;
  68.     typedef std::vector< Handle > HandleArray;
  69.    
  70.     SGS_OBJECT;
  71.    
  72.     UIControl();
  73.    
  74.     int niEvent( UIEvent* event );
  75.     void niRender();
  76.     void updateLayout();
  77.    
  78.     SGS_METHOD bool addChild( UIControl::Handle ch );
  79.     SGS_METHOD bool removeChild( UIControl::Handle ch );
  80.     SGS_METHOD UIControl::Handle findChild( std::string name );
  81.     SGS_METHOD sgsVariable children();
  82.     SGS_METHOD void sortChildren();
  83.    
  84.     SGS_IFUNC(SGS_OP_GCMARK) int sgs_gcmark( SGS_CTX, sgs_VarObj* obj, int );
  85.    
  86.     SGS_PROPERTY std::string name;
  87.     SGS_PROPERTY std::string caption;
  88.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float x;
  89.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float y;
  90.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float width;
  91.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float height;
  92.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float q0x;
  93.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float q0y;
  94.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float q1x;
  95.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK updateLayout ) float q1y;
  96.     SGS_PROPERTY_FUNC( READ WRITE WRITE_CALLBACK sortChildren ) int index;
  97.     SGS_PROPERTY std::string type;
  98.     SGS_PROPERTY READ Handle parent;
  99.     SGS_PROPERTY READ UIFrame::Handle frame;
  100.     SGS_PROPERTY sgsVariable callback;
  101.     SGS_PROPERTY sgsVariable renderfunc;
  102.    
  103.     SGS_PROPERTY READ float rx0;
  104.     SGS_PROPERTY READ float rx1;
  105.     SGS_PROPERTY READ float ry0;
  106.     SGS_PROPERTY READ float ry1;
  107.    
  108.     HandleArray m_children;
  109.     HandleArray m_sorted;
  110. };
  111.  
  112.  
  113.  
  114. inline void UI_PushEvent( SGS_CTX, UIEvent* e ){ sgs_PushClassFrom( C, e ); }
  115.  
  116.  
  117. #endif // __SGS_UI_CONTROL__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement