PageRenderTime 343ms CodeModel.GetById 161ms app.highlight 7ms RepoModel.GetById 174ms app.codeStats 0ms

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