bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/GObject_tutorial
1
by Gustav Hartvigsson
First lesson. |
1 |
#include "cat.h" |
2 |
||
3 |
||
4 |
struct _TestCat { |
|
5 |
TestAnimal parent; |
|
6 |
};
|
|
7 |
||
8 |
G_DEFINE_TYPE (TestCat, test_cat, TEST_TYPE_ANIMAL) |
|
9 |
||
10 |
/******************************************************************************/
|
|
11 |
void
|
|
12 |
test_cat_real_make_sound (TestCat * self); |
|
13 |
||
14 |
void
|
|
15 |
test_cat_real_move (TestCat * self, gint x, gint y); |
|
16 |
||
17 |
/******************************************************************************/
|
|
18 |
TestCat * |
|
19 |
test_cat_new () { |
|
20 |
return g_object_new (TEST_TYPE_CAT, NULL); |
|
21 |
}
|
|
22 |
||
23 |
static void |
|
24 |
test_cat_init (TestCat * self) { |
|
25 |
|
|
26 |
}
|
|
27 |
||
28 |
static void |
|
29 |
test_cat_class_init (TestCatClass * klass) { |
|
30 |
TestAnimalClass * animal_class = TEST_ANIMAL_CLASS (klass); |
|
31 |
animal_class->make_sound = test_cat_real_make_sound; |
|
32 |
animal_class->move = test_cat_real_move; |
|
33 |
}
|
|
34 |
||
35 |
/******************************************************************************/
|
|
36 |
void
|
|
37 |
test_cat_real_make_sound (TestCat * self) { |
|
38 |
g_print ("The cat says \"meew\" and \"rurururu\"\n"); |
|
39 |
}
|
|
40 |
||
41 |
void
|
|
42 |
test_cat_real_move (TestCat * self, gint x, gint y) { |
|
43 |
g_print ("The cat silently moves to (%i, %i).\n", x, y); |
|
44 |
}
|
|
45 |
||
46 |