PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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/*
 26 * History:
 27 * ================================================================
 28 * 2009-12-17 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#include "ftk_painter.h"
 33
 34typedef struct _PainterPrivInfo
 35{
 36	FtkListener listener;
 37	void* listener_ctx;
 38}PrivInfo;
 39
 40static Ret ftk_painter_on_event(FtkWidget* thiz, FtkEvent* event)
 41{
 42	return RET_OK;
 43}
 44
 45static Ret ftk_painter_on_paint(FtkWidget* thiz)
 46{
 47	DECL_PRIV0(thiz, priv);
 48	
 49	if(priv->listener != NULL)
 50	{
 51		priv->listener(priv->listener_ctx, thiz);
 52	}
 53
 54	return RET_OK;
 55}
 56
 57static void ftk_painter_destroy(FtkWidget* thiz)
 58{
 59	if(thiz != NULL)
 60	{
 61		DECL_PRIV0(thiz, priv);
 62		FTK_ZFREE(priv, sizeof(PrivInfo));
 63	}
 64
 65	return;
 66}
 67
 68FtkWidget* ftk_painter_create(FtkWidget* parent, int x, int y, int width, int height)
 69{
 70	FtkWidget* thiz = (FtkWidget*)FTK_ZALLOC(sizeof(FtkWidget));
 71	return_val_if_fail(thiz != NULL, NULL);
 72	
 73	thiz->priv_subclass[0] = (PrivInfo*)FTK_ZALLOC(sizeof(PrivInfo));
 74	if(thiz->priv_subclass[0] != NULL)
 75	{
 76		thiz->on_event = ftk_painter_on_event;
 77		thiz->on_paint = ftk_painter_on_paint;
 78		thiz->destroy  = ftk_painter_destroy;
 79
 80		ftk_widget_init(thiz, FTK_PAINTER, 0, x, y, width, height, 0);
 81		ftk_widget_append_child(parent, thiz);
 82	}
 83	else
 84	{
 85		FTK_FREE(thiz);
 86	}
 87
 88	return thiz;
 89}
 90
 91Ret ftk_painter_set_paint_listener(FtkWidget* thiz, FtkListener listener, void* ctx)
 92{
 93	DECL_PRIV0(thiz, priv);
 94	return_val_if_fail(thiz != NULL, RET_FAIL);
 95
 96	priv->listener_ctx = ctx;
 97	priv->listener = listener;
 98
 99	return RET_OK;
100}
101
102