/src/ftk_gc.h

http://ftk.googlecode.com/ · C Header · 141 lines · 91 code · 21 blank · 29 comment · 25 complexity · e8b3e9b0e185618d1d25f36f5f252570 MD5 · raw file

  1. /*
  2. * File: ftk_gc.h
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: graphic context
  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-10-03 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #ifndef FTK_GC_H
  31. #define FTK_GC_H
  32. #include "ftk_log.h"
  33. #include "ftk_bitmap.h"
  34. #include "ftk_font_desc.h"
  35. FTK_BEGIN_DECLS
  36. enum _FtkGcMask
  37. {
  38. FTK_GC_BG = 1,
  39. FTK_GC_FG = 2,
  40. FTK_GC_FONT = 4,
  41. FTK_GC_ALPHA = 8,
  42. FTK_GC_BITMAP = 16,
  43. FTK_GC_LINE_MASK = 32
  44. };
  45. typedef struct _FtkGc
  46. {
  47. int ref;
  48. unsigned int mask;
  49. FtkColor bg;
  50. FtkColor fg;
  51. FtkFontDesc* font;
  52. FtkBitmap* bitmap;
  53. unsigned char alpha;
  54. unsigned char unused[3];
  55. unsigned int line_mask;
  56. }FtkGc;
  57. static inline Ret ftk_gc_copy(FtkGc* dst, FtkGc* src)
  58. {
  59. return_val_if_fail(dst != NULL && src != NULL, RET_FAIL);
  60. dst->mask |= src->mask;
  61. if(src->mask & FTK_GC_BG)
  62. {
  63. dst->bg = src->bg;
  64. }
  65. if(src->mask & FTK_GC_FG)
  66. {
  67. dst->fg = src->fg;
  68. }
  69. if(src->mask & FTK_GC_FONT)
  70. {
  71. if(dst->font != NULL)
  72. {
  73. ftk_font_desc_unref(dst->font);
  74. }
  75. dst->font = src->font;
  76. if(dst->font != NULL)
  77. {
  78. ftk_font_desc_ref(dst->font);
  79. }
  80. }
  81. if(src->mask & FTK_GC_BITMAP)
  82. {
  83. if(dst->bitmap != NULL)
  84. {
  85. ftk_bitmap_unref(dst->bitmap);
  86. }
  87. dst->bitmap = src->bitmap;
  88. if(dst->bitmap != NULL)
  89. {
  90. ftk_bitmap_ref(dst->bitmap);
  91. }
  92. }
  93. if(src->mask & FTK_GC_LINE_MASK)
  94. {
  95. dst->line_mask = src->line_mask;
  96. }
  97. if(src->mask & FTK_GC_ALPHA)
  98. {
  99. dst->alpha = src->alpha;
  100. }
  101. return RET_OK;
  102. }
  103. static inline Ret ftk_gc_reset(FtkGc* gc)
  104. {
  105. if(gc != NULL)
  106. {
  107. if(gc->mask & FTK_GC_BITMAP && gc->bitmap != NULL)
  108. {
  109. ftk_bitmap_unref(gc->bitmap);
  110. }
  111. if(gc->mask & FTK_GC_FONT && gc->font != NULL)
  112. {
  113. ftk_font_desc_unref(gc->font);
  114. }
  115. memset(gc, 0x00, sizeof(*gc));
  116. }
  117. return RET_OK;
  118. }
  119. FTK_END_DECLS
  120. #endif/*FTK_GC_H*/