button.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * File : button.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #ifndef __RTGUI_BUTTON_H__
  15. #define __RTGUI_BUTTON_H__
  16. #include <rtgui/image.h>
  17. #include <rtgui/widgets/widget.h>
  18. #include <rtgui/widgets/label.h>
  19. #include <rtgui/kbddef.h>
  20. #include <rtgui/color.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /**
  25. * @defgroup rtgui_button_t
  26. * @{
  27. */
  28. /** Gets the type of a button */
  29. #define RTGUI_BUTTON_TYPE (rtgui_button_type_get())
  30. /** Casts the object to an rtgui_button_t */
  31. #define RTGUI_BUTTON(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_BUTTON_TYPE, rtgui_button_t))
  32. /** Checks if the object is an rtgui_button_t */
  33. #define RTGUI_IS_BUTTON(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_BUTTON_TYPE))
  34. #define RTGUI_BUTTON_FLAG_PRESS 0x01
  35. #define RTGUI_BUTTON_FLAG_DEFAULT 0x02
  36. #define RTGUI_BUTTON_TYPE_NORMAL 0x00
  37. #define RTGUI_BUTTON_TYPE_PUSH 0x10
  38. /*
  39. * the button widget
  40. */
  41. struct rtgui_button
  42. {
  43. /* inherit from label */
  44. rtgui_label_t parent;
  45. /* button flag */
  46. rt_uint32_t flag;
  47. /* pressed and unpressed image */
  48. rtgui_image_t *image;
  49. /* click button event handler */
  50. void (*on_button)(PVOID wdt, rtgui_event_t *event);
  51. };
  52. typedef struct rtgui_button rtgui_button_t;
  53. typedef void (*rtgui_onbutton_func_t)(PVOID wdt, rtgui_event_t *event);
  54. rtgui_type_t *rtgui_button_type_get(void);
  55. rtgui_button_t* rtgui_button_create(PVOID parent,char* text,int left,int top,int w,int h);
  56. void rtgui_button_destroy(rtgui_button_t* btn);
  57. void rtgui_button_set_image(rtgui_button_t* btn, rtgui_image_t* image);
  58. void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func);
  59. rt_bool_t rtgui_button_event_handler(PVOID wdt, rtgui_event_t* event);
  60. void rtgui_button_set_text(rtgui_button_t* button, const char* text);
  61. /** @} */
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif