Common.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Common.h
  3. *
  4. * Created on: Jun 7, 2017
  5. * Author: guoxs
  6. */
  7. #ifndef _CONTROL_COMMON_H_
  8. #define _CONTROL_COMMON_H_
  9. #include <stdio.h>
  10. #include <stdint.h>
  11. #include <unistd.h>
  12. typedef long ret_t;
  13. struct _bitmap_t;
  14. struct _message_t;
  15. #define ZK_DECLARE_PRIVATE(Class) \
  16. inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(d_ptr); } \
  17. inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(d_ptr); } \
  18. friend class Class##Private;
  19. #define ZK_DECLARE_PUBLIC(Class) \
  20. inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
  21. inline const Class* q_func() const { return static_cast<const Class *>(q_ptr); } \
  22. friend class Class;
  23. #define ZK_D(Class) Class##Private * const _d = d_func()
  24. #define ZK_Q(Class) Class * const _q = q_func()
  25. /********************自定义控件名********************/
  26. #define ZK_WINDOW "zk_window"
  27. #define ZK_SLIDEWINDOW "zk_slidewindow"
  28. #define ZK_SCROLLWINDOW "zk_scrollwindow"
  29. #define ZK_TEXTVIEW "zk_textview"
  30. #define ZK_BUTTON "zk_button"
  31. #define ZK_CHECKBOX "zk_checkbox"
  32. #define ZK_RADIOGROUP "zk_radiogroup"
  33. #define ZK_SEEKBAR "zk_seekbar"
  34. #define ZK_CIRCLEBAR "zk_circlebar"
  35. #define ZK_LISTVIEW "zk_listview"
  36. #define ZK_POINTER "zk_pointer"
  37. #define ZK_DIAGRAM "zk_diagram"
  38. #define ZK_DIGITALCLOCK "zk_digitalclock"
  39. #define ZK_QRCODE "zk_qrcode"
  40. #define ZK_EDITTEXT "zk_edittext"
  41. #define ZK_VIDEOVIEW "zk_videoview"
  42. #define ZK_CAMERAVIEW "zk_cameraview"
  43. #define ZK_SLIDETEXT "zk_slidetext"
  44. #define ZK_ANIMVIEW "zk_animview"
  45. #define ZK_TIMER "zk_timer"
  46. #define ZK_PAINTER "zk_painter"
  47. /**************************************************/
  48. /**********************控件状态*********************/
  49. #define ZK_CONTROL_STATUS_NORMAL 0x00000000
  50. #define ZK_CONTROL_STATUS_PRESSED 0x00000001
  51. #define ZK_CONTROL_STATUS_SELECTED 0x00000002
  52. #define ZK_CONTROL_STATUS_INVALID 0x00000004
  53. #define ZK_CONTROL_STATUS_VISIBLE 0x00000008
  54. #define ZK_CONTROL_STATUS_TOUCHABLE 0x00000010
  55. #define ZK_CONTROL_STATUS_TOUCH_PASS 0x00000020
  56. /**************************************************/
  57. class MotionEvent {
  58. public:
  59. typedef enum {
  60. E_ACTION_NONE,
  61. E_ACTION_DOWN,
  62. E_ACTION_UP,
  63. E_ACTION_MOVE,
  64. E_ACTION_CANCEL
  65. } EActionStatus;
  66. MotionEvent() {
  67. reset();
  68. }
  69. MotionEvent(EActionStatus actionStatus, int x, int y, long eventTime) :
  70. mActionStatus(actionStatus), mX(x), mY(y), mEventTime(eventTime) {
  71. }
  72. MotionEvent(const MotionEvent &ev) :
  73. mActionStatus(ev.mActionStatus), mX(ev.mX), mY(ev.mY), mEventTime(ev.mEventTime) {
  74. }
  75. void reset() {
  76. mActionStatus = E_ACTION_NONE;
  77. mX = 0;
  78. mY = 0;
  79. mEventTime = 0;
  80. }
  81. EActionStatus mActionStatus;
  82. int mX;
  83. int mY;
  84. long mEventTime;
  85. };
  86. class KeyEvent {
  87. public:
  88. typedef enum {
  89. E_KEY_NONE,
  90. E_KEY_DOWN,
  91. E_KEY_LONG_PRESS,
  92. E_KEY_UP
  93. } EKeyStatus;
  94. KeyEvent() {
  95. reset();
  96. }
  97. KeyEvent(int keyCode, EKeyStatus keyStatus, long eventTime) :
  98. mKeyCode(keyCode), mKeyStatus(keyStatus), mEventTime(eventTime) {
  99. }
  100. KeyEvent(const KeyEvent &ke) :
  101. mKeyCode(ke.mKeyCode), mKeyStatus(ke.mKeyStatus), mEventTime(ke.mEventTime) {
  102. }
  103. void reset() {
  104. mKeyCode = 0;
  105. mKeyStatus = E_KEY_NONE;
  106. mEventTime = 0;
  107. }
  108. int mKeyCode;
  109. EKeyStatus mKeyStatus;
  110. long mEventTime;
  111. };
  112. class LayoutPosition {
  113. public:
  114. LayoutPosition(int l = 0, int t = 0, int w = 0, int h = 0) :
  115. mLeft(l), mTop(t), mWidth(w), mHeight(h) {
  116. }
  117. LayoutPosition(const LayoutPosition& lp) :
  118. mLeft(lp.mLeft), mTop(lp.mTop), mWidth(lp.mWidth), mHeight(lp.mHeight) {
  119. }
  120. void offsetPosition(int xOffset, int yOffset) {
  121. mLeft += xOffset;
  122. mTop += yOffset;
  123. }
  124. bool operator==(const LayoutPosition &lp) const {
  125. return (mLeft == lp.mLeft) && (mTop == lp.mTop) &&
  126. (mWidth == lp.mWidth) && (mHeight == lp.mHeight);
  127. }
  128. bool operator!=(const LayoutPosition &lp) const {
  129. return !(*this == lp);
  130. }
  131. bool isHit(int x, int y) const {
  132. return (x >= mLeft) && (x < mLeft + mWidth) &&
  133. (y >= mTop) && (y < mTop + mHeight);
  134. }
  135. int mLeft;
  136. int mTop;
  137. int mWidth;
  138. int mHeight;
  139. };
  140. class LayoutPadding {
  141. public:
  142. LayoutPadding(int pl = 0, int pt = 0, int pr = 0, int pb = 0) :
  143. mPaddingLeft(pl), mPaddingTop(pt),
  144. mPaddingRight(pr), mPaddingBottom(pb) {
  145. }
  146. LayoutPadding(const LayoutPadding& lp) :
  147. mPaddingLeft(lp.mPaddingLeft), mPaddingTop(lp.mPaddingTop),
  148. mPaddingRight(lp.mPaddingRight), mPaddingBottom(lp.mPaddingBottom) {
  149. }
  150. int mPaddingLeft;
  151. int mPaddingTop;
  152. int mPaddingRight;
  153. int mPaddingBottom;
  154. };
  155. typedef struct {
  156. float x;
  157. float y;
  158. } SZKPoint;
  159. #endif /* _CONTROL_COMMON_H_ */