Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
#include "stdafx.h"

#include "Headers/TextLabel.h"

namespace Divide {

TextLabelStyle::TextLabelStyleMap TextLabelStyle::s_textLabelStyleMap;
SharedLock TextLabelStyle::s_textLableStyleMapMutex;
size_t TextLabelStyle::s_defaultCacheValue = 0;

TextLabelStyle::FontNameHashMap TextLabelStyle::s_fontNameMap;

TextLabelStyle::TextLabelStyle(const char* font,
                               const UColour& colour,
                               U8 fontSize)
  : _width(1),
    _font(_ID_RT(font)),
    _fontSize(fontSize),
    _colour(colour),
    _blurAmount(0.0f),
    _spacing(0.0f),
    _alignFlag(0),
    _bold(false),
    _italic(false),
    _dirty(true)
{
    // First one found
    if (s_defaultCacheValue == 0) {
        s_defaultCacheValue = getHash();

        s_fontNameMap[_ID_RT(Font::DIVIDE_DEFAULT)] = Font::DIVIDE_DEFAULT;
        s_fontNameMap[_ID_RT(Font::BATANG)] = Font::BATANG;
        s_fontNameMap[_ID_RT(Font::DEJA_VU)] = Font::DEJA_VU;
        s_fontNameMap[_ID_RT(Font::DROID_SERIF)] = Font::DROID_SERIF;
        s_fontNameMap[_ID_RT(Font::DROID_SERIF_ITALIC)] = Font::DROID_SERIF_ITALIC;
        s_fontNameMap[_ID_RT(Font::DROID_SERIF_BOLD)] = Font::DROID_SERIF_BOLD;
    }
}

size_t TextLabelStyle::getHash() const {
    if (_dirty) {
        size_t previousCache = Hashable::getHash();

        _hash = 0;
        Util::Hash_combine(_hash, _font);
        Util::Hash_combine(_hash, _fontSize);
        Util::Hash_combine(_hash, _width);
        Util::Hash_combine(_hash, _blurAmount);
        Util::Hash_combine(_hash, _spacing);
        Util::Hash_combine(_hash, _alignFlag);
        Util::Hash_combine(_hash, _colour.r);
        Util::Hash_combine(_hash, _colour.g);
        Util::Hash_combine(_hash, _colour.b);
        Util::Hash_combine(_hash, _colour.a);
        Util::Hash_combine(_hash, _bold);
        Util::Hash_combine(_hash, _italic);

        if (previousCache != _hash) {
            WriteLock w_lock(s_textLableStyleMapMutex);
            hashAlg::insert(s_textLabelStyleMap, _hash, *this);
        }
        _dirty = false;
    }

    return Hashable::getHash();
}

const TextLabelStyle& TextLabelStyle::get(size_t textLabelStyleHash) {
    bool styleFound = false;
    const TextLabelStyle& style = get(textLabelStyleHash, styleFound);
    // Return the state block's descriptor
    return style;
}

const TextLabelStyle& TextLabelStyle::get(size_t textLabelStyleHash, bool& styleFound) {
    styleFound = false;

    ReadLock r_lock(s_textLableStyleMapMutex);
    // Find the render state block associated with the received hash value
    TextLabelStyleMap::const_iterator it = s_textLabelStyleMap.find(textLabelStyleHash);
    if (it != std::cend(s_textLabelStyleMap)) {
        styleFound = true;
        return it->second;
    }

    return s_textLabelStyleMap.find(s_defaultCacheValue)->second;
}

const stringImpl& TextLabelStyle::fontName(size_t fontNameHash) {
    return s_fontNameMap[fontNameHash];
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Utility/TextLabel.cpp

Diff revisions: vs.
Revision Author Commited Message
1004 Diff Diff IonutCava picture IonutCava Wed 20 Dec, 2017 17:16:32 +0000

[Ionut]
- More GUI cleanup (added multiple GUIButton events)
- Typedef vec4<U8> and vec4<F32> to UColour and FColour respectively for easier to read code.

963 IonutCava picture IonutCava Sun 05 Nov, 2017 18:31:51 +0000

[Ionut]
- More multi-window fixes
- Profile guided performance improvements