bindings: Base methods support in Instance class
[sdk] / bindings / c / samples / form.c
1 #define MODULE_NAME  "HelloForm"
2 // #define __CONSOLE_APP__
3
4 #include "ecere.h"
5
6 static Class * class_HelloForm2;
7
8 struct HelloForm2 { Button button; };
9
10 typedef Instance HelloForm2;
11
12 static void HelloForm2_onRedraw(HelloForm2 this, Surface surface)
13 {
14    // Surface_writeTextf(surface, 100, 100, I18N("Testing stuff!"));
15    Surface_writeTextf(surface, 100, 100, "%d + %d = %d", 2, 3, 2+3);
16 }
17
18 static bool HelloForm2_button_notifyClicked(HelloForm2 this, Button button, int x, int y, Modifiers mods)
19 {
20    MessageBox msgBox = newi(class_MessageBox);
21    double i = 3.14159265;
22    char tmp[256];
23    constString s = _onGetString(class_double, &i, tmp, null, null);
24
25    PrintLn(class_String, "Hello! -- ", class_String, s, null); // Need to terminate with a null!
26    Window_set_caption(msgBox, $("Hello!"));
27    MessageBox_set_contents(msgBox, $("C Bindings!"));
28    Window_modal(msgBox);
29    return true;
30 }
31
32 static bool HelloForm2_constructor(HelloForm2 this)
33 {
34    struct HelloForm2 * self = IPTR(this, HelloForm2);
35    Window_set_caption(this, $("My Second Ecere/C Bindings App"));
36    Window_set_borderStyle(this, sizable);
37    Window_set_clientSize(this, &(Size){ 640, 480 });
38    Window_set_hasClose(this, true);
39    Window_set_hasMaximize(this, true);
40    Window_set_hasMinimize(this, true);
41    Window_set_background(this, formColor);
42
43    self->button = newi(class_Button);
44    Window_set_parent(self->button, this);
45    Window_set_position(self->button, &(Point){ 200, 200 });
46    Window_set_caption(self->button, $("Yay!!"));
47    Instance_setMethod(self->button, "NotifyClicked", HelloForm2_button_notifyClicked);
48    return true;
49 }
50
51 static void HelloForm2_destructor(HelloForm2 this)
52 {
53    struct HelloForm2 * self = IPTR(this, HelloForm2);
54    deletei(self->button);
55 }
56
57 GUIAPP_INTRO
58 {
59    class_HelloForm2 = registerClass(app, HelloForm2, Window);
60    addMethod(class_HelloForm2, "OnRedraw", HelloForm2_onRedraw);
61
62    HelloForm2 hello = newi(class_HelloForm2);
63
64    Application_main(app);
65
66    deletei(hello);
67 }
68 ECERE_APP_OUTRO