bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/GObject_tutorial
|
1
by Gustav Hartvigsson
First lesson. |
1 |
#include "animal.h" |
2 |
||
3 |
G_DEFINE_TYPE (TestAnimal, test_animal, G_TYPE_OBJECT) |
|
4 |
//G_DEFINE_TYPE_WITH_PRIVATE (TestAnimal, test_animal, G_TYPE_OBJECT)
|
|
5 |
||
6 |
/*
|
|
7 |
struct _TestAnimalPrivate {
|
|
8 |
|
|
9 |
};
|
|
10 |
*/
|
|
11 |
||
12 |
/******************************************************************************/
|
|
13 |
void
|
|
14 |
test_animal_real_make_sound (TestAnimal * self); |
|
15 |
||
16 |
void
|
|
17 |
test_animal_real_move (TestAnimal * self, gint x, gint y); |
|
18 |
/******************************************************************************/
|
|
19 |
||
20 |
TestAnimal * |
|
21 |
test_animal_new () { |
|
22 |
return g_object_new (TEST_TYPE_ANIMAL, NULL); |
|
23 |
}
|
|
24 |
||
25 |
static void |
|
26 |
test_animal_init (TestAnimal * self) { |
|
27 |
|
|
28 |
}
|
|
29 |
||
30 |
static void |
|
31 |
test_animal_class_init (TestAnimalClass * klass) { |
|
32 |
GObjectClass * obj_class = G_OBJECT_CLASS (klass); |
|
33 |
|
|
34 |
klass->make_sound = test_animal_real_make_sound; |
|
35 |
klass->move = test_animal_real_move; |
|
36 |
|
|
37 |
}
|
|
38 |
||
39 |
void
|
|
40 |
test_animal_make_sound (TestAnimal * self) { |
|
41 |
g_return_if_fail (TEST_IS_ANIMAL (self)); |
|
42 |
TestAnimalClass * klass = TEST_ANIMAL_GET_CLASS (self); |
|
43 |
|
|
44 |
klass->make_sound (self); |
|
45 |
}
|
|
46 |
||
47 |
void
|
|
48 |
test_animal_move (TestAnimal * self, gint x, gint y) { |
|
49 |
g_return_if_fail (TEST_IS_ANIMAL (self)); |
|
50 |
|
|
51 |
TestAnimalClass * klass = TEST_ANIMAL_GET_CLASS (self); |
|
52 |
|
|
53 |
klass->move (self, x, y); |
|
54 |
}
|
|
55 |
||
56 |
/******************************************************************************/
|
|
57 |
void
|
|
58 |
test_animal_real_make_sound (TestAnimal * self) { |
|
59 |
|
|
60 |
g_print ("This animal can't make a sound... :-( \n"); |
|
61 |
}
|
|
62 |
||
63 |
void
|
|
64 |
test_animal_real_move (TestAnimal * self, gint x, gint y) { |
|
65 |
|
|
66 |
g_print ("This animal can't move to %i, %i... :-( \n", x, y); |
|
67 |
}
|
|
68 |
||
69 |