BUTTON.CPP
上传用户:wtrl82617
上传日期:2007-01-07
资源大小:187k
文件大小:3k
源码类别:

界面编程

开发平台:

DOS

  1. // 1993 (c) ALL RIGHTS RESERVED
  2. // AUTHOR  BY XuYongYong
  3. /*  button.cpp
  4. */
  5. #include "button.h"
  6. #include "yyxsys1.h"
  7. /**************************************************************************/
  8. button_class::button_class (int ID,char *title_hotkey,
  9. int left,int top,int width,int height )
  10. : control_class(ID,title_hotkey,NORMAL ,BUTTON,
  11. left,top,width,height,UNPUSHED,PUSHED,UNPUSHED )
  12. {
  13. setup_control();
  14. }
  15. void button_class::setup_control()
  16. {
  17.   int text_width =textwidth (title);
  18.   int text_height=textheight(title);
  19. title_pos_x =bounds.left + (bounds.right-bounds.left-text_width )/2;
  20. title_pos_y =bounds.top  + (bounds.bottom-bounds.top-text_height)/2-2;
  21. }
  22. void button_class::draw ()
  23. {   if ( status & INVISIBLE) return;    // INVISIBLE
  24. draw_out_button (bounds);
  25. control_class::draw ();
  26. }
  27. /**************************************************************************/
  28. void button_class::select ( )
  29. {   control_class::select ();
  30.   Trect Arect =bounds;
  31. setcolor (BLACK);
  32. FrameRoundRect (Arect,2,2);
  33. InsetRect (&Arect,1,1);
  34. FrameRoundRect (Arect,2,2);
  35. }
  36. /**************************************************************************/
  37. void button_class::unselect ( )
  38. {   control_class::unselect ( );
  39.   Trect Arect =bounds;
  40. setcolor (WHITE);
  41. InsetRect (&Arect,1,1);
  42. FrameRoundRect (Arect,2,2);
  43. }
  44. /**************************************************************************/
  45. int button_class::control_change_value
  46. (int new_value )
  47. {   if (control_class::control_change_value(new_value)==TRUE)
  48. return TRUE;
  49. switch (new_value) {
  50. case UNPUSHED:
  51. draw ();
  52. break;
  53. case PUSHED:
  54. FillRoundRect (bounds,2,2,LIGHTGRAY);
  55. setcolor (BLACK);
  56. outtextxy (title_pos_x,title_pos_y,title);
  57. break;
  58. }
  59. current_value =new_value;
  60. return TRUE;
  61. }
  62. /**************************************************************************/
  63. int button_class::key_pressed_handler (int key_scan_num)
  64. {   switch (key_scan_num ) {
  65. case ENTERKEY:
  66. case SPACEKEY:
  67. control_change_value
  68. (PUSHED);
  69. delay(200);
  70. control_change_value
  71. (UNPUSHED);
  72. thequeue.SendMessage(ID,
  73. ButtonPushedMSG,this);
  74. return TRUE;
  75. default:return control_class::key_pressed_handler (key_scan_num);
  76. }
  77. }
  78. int button_class::msg_handler(MSG& message)
  79. {
  80. switch (message.Action){
  81. case MouseLButtonDownMSG:
  82. control_change_value
  83. (PUSHED);
  84. delay(200);
  85. control_change_value
  86. (UNPUSHED);
  87. thequeue.SendMessage(ID,
  88. ButtonPushedMSG,this);
  89. return TRUE;
  90. default:return control_class::msg_handler (message);
  91. }
  92. }