OBUTTCUS.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OBUTTCUS.H
  21. //Description : Header file of button object
  22. #ifndef __OBUTTCUS_H
  23. #define __OBUTTCUS_H
  24. //------- Define type ButtonCustomFP -------//
  25. class ButtonCustom;
  26. typedef void (*ButtonCustomFP)(ButtonCustom *, int repaintBody);
  27. //------- Define struct ButtonCustomFPPara -------//
  28. struct ButtonCustomPara
  29. {
  30. void* ptr;
  31. int value;
  32. ButtonCustomPara( void *p, int v) : ptr(p), value(v) {}
  33. };
  34. //------- Define class ButtonCustom -------//
  35. class ButtonCustom
  36. {
  37. public:
  38. char init_flag;
  39. short x1,y1,x2,y2; // some function will need to access the button's coordination for area detection
  40. char pushed_flag;
  41. char enable_flag; // either 1(Yes) or 0(No)
  42. char elastic_flag;
  43. unsigned short button_key; // button is pressed when user press this key
  44. ButtonCustomFP body_fp;
  45. ButtonCustomPara custom_para; // let body_fp to read a parameter
  46. public:
  47. ButtonCustom();
  48. void create(int pX1, int pY1, int pX2, int pY2, ButtonCustomFP funcPtr,
  49. ButtonCustomPara funcPara, char elasticFlag=1, char defIsPushed=0);
  50. void paint(int pX1, int pY1, int pX2, int pY2, ButtonCustomFP funcPtr,
  51. ButtonCustomPara funcPara, char elasticFlag=1, char defIsPushed=0)
  52. { create(pX1, pY1, pX2, pY2, funcPtr, funcPara, elasticFlag, defIsPushed); paint();}
  53. void paint(int defIsPushed= -1, int repaintBody=1);
  54. void reset() { init_flag=0; }
  55. void hide();
  56. int detect(unsigned=0,unsigned=0,int=0,int=0);
  57. void push() { if(!pushed_flag) paint(1); }
  58. void pop() { if(pushed_flag) paint(0); }
  59. void disable() { if(enable_flag) { enable_flag=0; paint(); } }
  60. void enable() { if(!enable_flag) { enable_flag=1; paint(); } }
  61. static void disp_text_button_func(ButtonCustom *, int repaintBody);
  62. };
  63. //------- Define class ButtonCustomGroup ----------------//
  64. class ButtonCustomGroup
  65. {
  66. public:
  67. int button_num;
  68. int button_pressed;
  69. ButtonCustom* button_array;
  70. public:
  71. ButtonCustomGroup(int);
  72. ~ButtonCustomGroup();
  73. void paint(int= -1);
  74. int detect();
  75. void push(int, int paintFlag=1);
  76. ButtonCustom& operator[](int);
  77. int operator()() { return button_pressed; }
  78. };
  79. //-------------------------------------------------//
  80. #endif