summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/GUI/Font.bind.cpp
blob: 73fb7e67232e3aa6212124cfc42e47f1aaf558e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "Runtime/GUI/Font.h"
#include "Runtime/Graphics/Shader.h"
#include "Runtime/Debug/Log.h"
#include "Runtime/Graphics/GfxDevice.h"
#include "Runtime/Common/DataBuffer.h"

LUA_BIND_REGISTRY(Font)
{
    LUA_BIND_REGISTER_METHODS(state,
        { "New", _New },
        { "GetCharacter", _GetCharacter },
        { "GetGlyphAtlas", _GetGlyphAtlas }
    );
}

LUA_BIND_POSTPROCESS(Font)
{
}

// Font.New(ttfPath, atlasSize, margin, padding)
// Font.New(ttfData, atlasSize, margin, padding)
LUA_BIND_IMPL_METHOD(Font, _New)
{
    LUA_BIND_STATE(L);
    LUA_BIND_CHECK(L, "STNN!|UTNN!");

    Font* font = NULL;
    if (state.CheckParams(1, "STNN!")) 
    {
        const char* path = state.GetValue<const char*>(1, "");
        TextGeneratingSettings setting;
        setting.atlasSize = state.GetValue<Internal::Vector2>(2, Internal::Vector2(128, 128));
        setting.margin = state.GetValue<int>(3, 0);
        setting.padding = state.GetValue<int>(4, 0);
        try {
            font = new Font(path, setting);
        }
        catch (FontException& e)
        {
            log_error(e.what());
            state.PushNil();
            return 1;
        }
    }
    else if (state.CheckParams(1, "UTNN!")) 
    {
        DataBuffer* buffer = state.GetUserdata<DataBuffer>(1);
        if (buffer == NULL)
        {
            log_error("Create font failed, DataBuffer is invalid.");
            state.PushNil();
            return 1;
        }
        TextGeneratingSettings setting;
        setting.atlasSize = state.GetValue<Internal::Vector2>(2, Internal::Vector2(128, 128));
        setting.margin = state.GetValue<int>(3, 0);
        setting.padding = state.GetValue<int>(4, 0);
        try {
            font = new Font(buffer, setting);
        }
        catch (FontException& e)
        {
            log_error(e.what());
            state.PushNil();
            return 1;
        }
    }

    font->PushUserdata(state);

    return 1;
}

// font:GetCharacter(char, size, encoding)
LUA_BIND_IMPL_METHOD(Font, _GetCharacter)
{
    LUA_BIND_PREPARE(L, Font);
//    Character character = self->GetCharacter(character);
    return 1;
}

// font:GetCharacter(str, size, encoding)
LUA_BIND_IMPL_METHOD(Font, _GetCharacters)
{
    LUA_BIND_PREPARE(L, Font);
//    Character character = self->GetCharacter(character);
    return 1;
}

// font:GetAtlas(i)
// return lightuserdata
LUA_BIND_IMPL_METHOD(Font, _GetGlyphAtlas)
{
    LUA_BIND_PREPARE(L, Font);
    //LUA_BIND_CHECK(L, "UN");

    //int i = state.GetValue<int>(2, 0);
    //GlyphAtals atlas = self->m_Atlases[i];

    //state.Push((const void*)atlas.altas);

    return 1;
}