/* * Copyright (C) 2006 Benjamin Otte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ */ #include "game-private.h" #include "game-plain.h" #include "game-marshal.h" enum { PROP_0, PROP_COLOR, }; static GameGraphicClass *parent_class = NULL; static void game_plain_get_property (GObject *plain_, guint param_id, GValue *value, GParamSpec * pspec) { GamePlain *plain = GAME_PLAIN (plain_); switch (param_id) { case PROP_COLOR: g_value_set_boxed (value, &plain->color); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (plain, param_id, pspec); break; } } static void game_plain_set_property (GObject *obj, guint param_id, const GValue *value, GParamSpec *pspec) { GamePlain *plain = GAME_PLAIN (obj); switch (param_id) { case PROP_COLOR: if (g_value_get_boxed (value)) { plain->color = *((GameColor *) g_value_get_boxed (value)); } else { plain->color.r = plain->color.g = plain->color.b = 0.0; plain->color.a = 1.0; } game_graphic_invalidate (GAME_GRAPHIC (plain)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (plain, param_id, pspec); break; } } static void game_plain_draw (GameGraphic *graphic, cairo_t *cr) { GamePlain *plain = GAME_PLAIN (graphic); game_color_as_cairo_source (cr, &plain->color); cairo_paint (cr); } static void game_plain_class_init (gpointer g_class, gpointer class_data) { GObjectClass *object_class = G_OBJECT_CLASS (g_class); GameGraphicClass *graphic_class = GAME_GRAPHIC_CLASS (g_class); parent_class = g_type_class_peek_parent (g_class); object_class->set_property = game_plain_set_property; object_class->get_property = game_plain_get_property; graphic_class->draw = game_plain_draw; g_object_class_install_property (object_class, PROP_COLOR, g_param_spec_boxed ("color", _("color"), _("color to paint"), GAME_TYPE_COLOR, G_PARAM_READWRITE)); } static void game_plain_init (GTypeInstance *instance, gpointer g_class) { } GType game_plain_get_type () { static GType plain_type = 0; if (!plain_type) { static const GTypeInfo plain_info = { sizeof (GamePlainClass), NULL, NULL, game_plain_class_init, NULL, NULL, sizeof (GamePlain), 0, game_plain_init, }; plain_type = g_type_register_static (GAME_TYPE_GRAPHIC, "GamePlain", &plain_info, 0); } return plain_type; }