plot_curve.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * File : plot.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012, 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. * 2012-09-03 Grissiom first version
  13. */
  14. #include <rtgui/color.h>
  15. #include <rtgui/rtgui_mv_model.h>
  16. #include <rtgui/widgets/widget.h>
  17. #include <rtgui/widgets/plot_curve.h>
  18. static void _rtgui_plot_curve_constructor(struct rtgui_plot_curve *curve)
  19. {
  20. curve->color = red;
  21. curve->max_x = curve->min_x = curve->max_y = curve->min_y = 0;
  22. /* init widget and set event handler */
  23. rtgui_object_set_event_handler(RTGUI_OBJECT(curve), RT_NULL);
  24. }
  25. static void _rtgui_plot_curve_destructor(struct rtgui_plot_curve *curve)
  26. {
  27. /* nothing to do so far. */
  28. }
  29. DEFINE_CLASS_TYPE(plot_curve, "plot_curve",
  30. RTGUI_MV_MODEL_TYPE,
  31. _rtgui_plot_curve_constructor,
  32. _rtgui_plot_curve_destructor,
  33. sizeof(struct rtgui_plot_curve));
  34. struct rtgui_plot_curve *rtgui_plot_curve_create(void)
  35. {
  36. struct rtgui_plot_curve *curve;
  37. curve = RTGUI_PLOT_CURVE(rtgui_object_create(RTGUI_PLOT_CURVE_TYPE));
  38. if (curve == RT_NULL)
  39. return RT_NULL;
  40. if (rtgui_mv_model_set_dimension(RTGUI_MV_MODEL(curve), 2) != RT_EOK)
  41. {
  42. rtgui_object_destroy(RTGUI_OBJECT(curve));
  43. return RT_NULL;
  44. }
  45. return curve;
  46. }
  47. RTM_EXPORT(rtgui_plot_curve_create);
  48. void rtgui_plot_curve_destroy(struct rtgui_plot_curve *curve)
  49. {
  50. rtgui_mv_model_destroy(RTGUI_MV_MODEL(curve));
  51. }
  52. RTM_EXPORT(rtgui_plot_curve_destroy);
  53. void rtgui_plot_curve_set_x(struct rtgui_plot_curve *curve, void *p)
  54. {
  55. rtgui_mv_model_set_data(RTGUI_MV_MODEL(curve), 0, p);
  56. }
  57. RTM_EXPORT(rtgui_plot_curve_set_x);
  58. void *rtgui_plot_curve_get_x(struct rtgui_plot_curve *curve)
  59. {
  60. return rtgui_mv_model_get_data(RTGUI_MV_MODEL(curve), 0);
  61. }
  62. RTM_EXPORT(rtgui_plot_curve_get_x);
  63. void rtgui_plot_curve_set_y(struct rtgui_plot_curve *curve, void *p)
  64. {
  65. rtgui_mv_model_set_data(RTGUI_MV_MODEL(curve), 1, p);
  66. }
  67. RTM_EXPORT(rtgui_plot_curve_set_y);
  68. void *rtgui_plot_curve_get_y(struct rtgui_plot_curve *curve)
  69. {
  70. return rtgui_mv_model_get_data(RTGUI_MV_MODEL(curve), 1);
  71. }
  72. RTM_EXPORT(rtgui_plot_curve_get_y);