PageRenderTime 553ms CodeModel.GetById 151ms app.highlight 152ms RepoModel.GetById 139ms app.codeStats 1ms

/src/ftk_canvas.h

http://ftk.googlecode.com/
C++ Header | 240 lines | 159 code | 51 blank | 30 comment | 70 complexity | a4e806fc4e1a3b0f44bdcce29d7c2e62 MD5 | raw file
  1/*
  2 * File: ftk_canvas.h    
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   drawing kit.
  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 * 2011-04-16 Li XianJing <xianjimli@hotmail.com> change to interface.
 30 *
 31 */
 32
 33#ifndef FTK_CANVAS_H
 34#define FTK_CANVAS_H
 35
 36#include "ftk_gc.h"
 37#include "ftk_display.h"
 38
 39FTK_BEGIN_DECLS
 40
 41typedef enum _FtkBgStyle
 42{
 43	FTK_BG_NORMAL = 0,
 44	FTK_BG_TILE,
 45	FTK_BG_CENTER,
 46	FTK_BG_FOUR_CORNER
 47}FtkBgStyle;
 48
 49struct _FtkCanvas;
 50typedef struct _FtkCanvas FtkCanvas;
 51
 52struct _FtkCanvasVTable;
 53typedef struct _FtkCanvasVTable FtkCanvasVTable;
 54
 55typedef Ret (*FtkCanvasSyncGc)(FtkCanvas* thiz);
 56typedef Ret (*FtkCanvasSetClip)(FtkCanvas* thiz, FtkRegion* clip);
 57
 58typedef Ret (*FtkCanvasDrawPixels)(FtkCanvas* thiz, FtkPoint* points, int nr);
 59typedef Ret (*FtkCanvasDrawLine)(FtkCanvas* thiz, int x1, int y1, int x2, int y2);
 60typedef Ret (*FtkCanvasClearRect)(FtkCanvas* thiz, int x, int y, int w, int h);
 61typedef Ret (*FtkCanvasDrawRect)(FtkCanvas* thiz, int x, int y, int w, int h, int round, int fill);
 62typedef Ret (*FtkCanvasDrawBitmap)(FtkCanvas* thiz, FtkBitmap* bitmap, FtkRect* s, FtkRect* d, int alpha);
 63typedef Ret (*FtkCanvasDrawString)(FtkCanvas* thiz, int x, int y, const char* str, int len, int vcenter);
 64
 65typedef int (*FtkCanvasGetCharExtent)(FtkCanvas* thiz, unsigned short code);
 66typedef int (*FtkCanvasGetStrExtent)(FtkCanvas* thiz, const char* str, int len);
 67
 68typedef Ret (*FtkCanvasLockBuffer)(FtkCanvas* thiz, FtkBitmap** bitmap);
 69typedef Ret (*FtkCanvasUnlockBuffer)(FtkCanvas* thiz);
 70typedef void (*FtkCanvasDestroy)(FtkCanvas* thiz);
 71
 72struct _FtkCanvasVTable
 73{
 74	FtkCanvasSyncGc        sync_gc;
 75	FtkCanvasSetClip       set_clip;
 76	FtkCanvasDrawPixels    draw_pixels;
 77	FtkCanvasDrawLine      draw_line;
 78	FtkCanvasClearRect     clear_rect;
 79	FtkCanvasDrawRect      draw_rect;
 80	FtkCanvasDrawBitmap    draw_bitmap;
 81	FtkCanvasDrawString    draw_string;
 82	FtkCanvasGetStrExtent  get_str_extent;
 83	FtkCanvasGetCharExtent get_char_extent;
 84	FtkCanvasLockBuffer    lock_buffer;
 85	FtkCanvasUnlockBuffer  unlock_buffer;
 86	FtkCanvasDestroy       destroy;
 87};
 88
 89struct _FtkCanvas
 90{
 91	FtkGc gc;
 92	int width;
 93	int height;
 94
 95	const FtkCanvasVTable* vtable;	
 96	char priv[1];
 97};
 98
 99static inline Ret ftk_canvas_sync_gc(FtkCanvas* thiz)
100{
101	Ret ret = RET_FAIL;
102
103	if(thiz != NULL && thiz->vtable != NULL && thiz->vtable->sync_gc != NULL)
104	{
105		ret = thiz->vtable->sync_gc(thiz);
106	}
107
108	return ret;
109}
110
111static inline Ret ftk_canvas_set_clip(FtkCanvas* thiz, FtkRegion* clip)
112{
113	Ret ret = RET_FAIL;
114	
115	if(thiz != NULL && thiz->vtable != NULL && thiz->vtable->set_clip != NULL)
116	{
117		ret = thiz->vtable->set_clip(thiz, clip);
118	}
119
120	return ret;
121}
122
123static inline Ret ftk_canvas_draw_pixels(FtkCanvas* thiz, FtkPoint* points, int nr)
124{
125	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
126		&& thiz->vtable->draw_pixels != NULL, RET_FAIL);
127
128	return thiz->vtable->draw_pixels(thiz, points, nr);
129}
130
131static inline Ret ftk_canvas_draw_line(FtkCanvas* thiz, int x1, int y1, int x2, int y2)
132{
133	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
134		&& thiz->vtable->draw_line != NULL, RET_FAIL);
135
136	return thiz->vtable->draw_line(thiz, x1, y1, x2, y2);
137}
138
139static inline Ret ftk_canvas_clear_rect(FtkCanvas* thiz, int x, int y, int w, int h)
140{
141	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
142		&& thiz->vtable->clear_rect != NULL, RET_FAIL);
143
144	return thiz->vtable->clear_rect(thiz, x, y, w, h);
145}
146
147static inline Ret ftk_canvas_draw_rect(FtkCanvas* thiz, int x, int y, int w, int h, int round, int fill)
148{
149	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
150		&& thiz->vtable->draw_rect != NULL, RET_FAIL);
151
152	return thiz->vtable->draw_rect(thiz, x, y, w, h, round, fill);
153}
154
155static inline Ret ftk_canvas_draw_bitmap(FtkCanvas* thiz, FtkBitmap* bmp, FtkRect* s, FtkRect* d, int alpha)
156{
157	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
158		&& thiz->vtable->draw_bitmap != NULL, RET_FAIL);
159
160	return thiz->vtable->draw_bitmap(thiz, bmp, s, d, alpha);
161}
162
163static inline Ret ftk_canvas_draw_string(FtkCanvas* thiz, int x, int y, 
164	const char* str, int len, int vcenter)
165{
166	len = (len < 0 && str != NULL) ? (int)strlen(str) : len;
167
168	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
169		&& thiz->vtable->draw_string != NULL, RET_FAIL);
170
171	return thiz->vtable->draw_string(thiz, x, y, str, len, vcenter);
172}
173
174static inline int ftk_canvas_get_str_extent(FtkCanvas* thiz, const char* str, int len)
175{
176	len = len >= 0 ? len : strlen(str);
177	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
178		&& thiz->vtable->get_str_extent != NULL, 0);
179
180	return thiz->vtable->get_str_extent(thiz, str, len);
181}
182
183static inline int ftk_canvas_get_char_extent(FtkCanvas* thiz, unsigned short code)
184{
185	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
186		&& thiz->vtable->get_char_extent != NULL, 0);
187
188	return thiz->vtable->get_char_extent(thiz, code);
189}
190
191static inline Ret ftk_canvas_lock_buffer(FtkCanvas* thiz, FtkBitmap** bitmap)
192{
193	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
194		&& thiz->vtable->lock_buffer != NULL, RET_FAIL);
195
196	return thiz->vtable->lock_buffer(thiz, bitmap);
197}
198
199static inline Ret ftk_canvas_unlock_buffer(FtkCanvas* thiz)
200{
201	return_val_if_fail(thiz != NULL && thiz->vtable != NULL 
202		&& thiz->vtable->unlock_buffer != NULL, RET_FAIL);
203
204	return thiz->vtable->unlock_buffer(thiz);
205}
206
207static inline void ftk_canvas_destroy(FtkCanvas* thiz)
208{
209	if(thiz != NULL && thiz->vtable != NULL && thiz->vtable->destroy != NULL)
210	{
211		thiz->vtable->destroy(thiz);
212	}
213
214	return;
215}
216
217FtkGc* ftk_canvas_get_gc(FtkCanvas* thiz);
218Ret    ftk_canvas_reset_gc(FtkCanvas* thiz, FtkGc* gc);
219Ret    ftk_canvas_set_gc(FtkCanvas* thiz, FtkGc* gc);
220Ret    ftk_canvas_set_clip_rect(FtkCanvas* thiz, FtkRect* rect);
221Ret    ftk_canvas_set_clip_region(FtkCanvas* thiz, FtkRegion* region);
222Ret    ftk_canvas_draw_vline(FtkCanvas* thiz, int x, int y, int h);
223Ret    ftk_canvas_draw_hline(FtkCanvas* thiz, int x, int y, int w);
224
225Ret ftk_canvas_draw_bitmap_simple(FtkCanvas* thiz, FtkBitmap* b, 
226	int x, int y, int w, int h, int ox, int oy);
227Ret ftk_canvas_draw_bg_image(FtkCanvas* thiz, FtkBitmap* bitmap, 
228	FtkBgStyle style, int x, int y, int w, int h);
229
230const char* ftk_canvas_calc_str_visible_range(FtkCanvas* thiz, 
231	const char* start, int vstart, int vend, int width, int* ret_extent);
232
233Ret ftk_canvas_show(FtkCanvas* thiz, FtkDisplay* display, FtkRect* rect, int ox, int oy);
234
235FtkCanvas* ftk_canvas_create(int w, int h, FtkColor* clear_color);
236
237FTK_END_DECLS
238
239#endif/*FTK_CANVAS_H*/
240