/src/ftk_painter.c

http://ftk.googlecode.com/ · C · 102 lines · 55 code · 18 blank · 29 comment · 8 complexity · cdba8c728009363954f4ed68818473c7 MD5 · raw file

  1. /*
  2. * File: ftk_painter.c
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: painter
  5. *
  6. * Copyright (c) 2009 - 2010 Li XianJing <xianjimli@hotmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2009-12-17 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #include "ftk_painter.h"
  31. typedef struct _PainterPrivInfo
  32. {
  33. FtkListener listener;
  34. void* listener_ctx;
  35. }PrivInfo;
  36. static Ret ftk_painter_on_event(FtkWidget* thiz, FtkEvent* event)
  37. {
  38. return RET_OK;
  39. }
  40. static Ret ftk_painter_on_paint(FtkWidget* thiz)
  41. {
  42. DECL_PRIV0(thiz, priv);
  43. if(priv->listener != NULL)
  44. {
  45. priv->listener(priv->listener_ctx, thiz);
  46. }
  47. return RET_OK;
  48. }
  49. static void ftk_painter_destroy(FtkWidget* thiz)
  50. {
  51. if(thiz != NULL)
  52. {
  53. DECL_PRIV0(thiz, priv);
  54. FTK_ZFREE(priv, sizeof(PrivInfo));
  55. }
  56. return;
  57. }
  58. FtkWidget* ftk_painter_create(FtkWidget* parent, int x, int y, int width, int height)
  59. {
  60. FtkWidget* thiz = (FtkWidget*)FTK_ZALLOC(sizeof(FtkWidget));
  61. return_val_if_fail(thiz != NULL, NULL);
  62. thiz->priv_subclass[0] = (PrivInfo*)FTK_ZALLOC(sizeof(PrivInfo));
  63. if(thiz->priv_subclass[0] != NULL)
  64. {
  65. thiz->on_event = ftk_painter_on_event;
  66. thiz->on_paint = ftk_painter_on_paint;
  67. thiz->destroy = ftk_painter_destroy;
  68. ftk_widget_init(thiz, FTK_PAINTER, 0, x, y, width, height, 0);
  69. ftk_widget_append_child(parent, thiz);
  70. }
  71. else
  72. {
  73. FTK_FREE(thiz);
  74. }
  75. return thiz;
  76. }
  77. Ret ftk_painter_set_paint_listener(FtkWidget* thiz, FtkListener listener, void* ctx)
  78. {
  79. DECL_PRIV0(thiz, priv);
  80. return_val_if_fail(thiz != NULL, RET_FAIL);
  81. priv->listener_ctx = ctx;
  82. priv->listener = listener;
  83. return RET_OK;
  84. }