1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
---|---|
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #include "GUI/BsGUISkin.h" |
4 | #include "GUI/BsGUIElementStyle.h" |
5 | #include "Debug/BsDebug.h" |
6 | #include "Resources/BsResources.h" |
7 | #include "Private/RTTI/BsGUISkinRTTI.h" |
8 | |
9 | namespace bs |
10 | { |
11 | GUIElementStyle GUISkin::DefaultStyle; |
12 | |
13 | GUISkin::GUISkin() |
14 | :Resource(false) |
15 | { } |
16 | |
17 | GUISkin::GUISkin(const GUISkin& skin) |
18 | :Resource(false) |
19 | { } |
20 | |
21 | bool GUISkin::hasStyle(const String& name) const |
22 | { |
23 | auto iterFind = mStyles.find(name); |
24 | |
25 | if (iterFind != mStyles.end()) |
26 | return true; |
27 | |
28 | return false; |
29 | } |
30 | |
31 | const GUIElementStyle* GUISkin::getStyle(const String& guiElemType) const |
32 | { |
33 | auto iterFind = mStyles.find(guiElemType); |
34 | |
35 | if(iterFind != mStyles.end()) |
36 | return &iterFind->second; |
37 | |
38 | LOGWRN("Cannot find GUI style with name: "+ guiElemType + ". Returning default style."); |
39 | |
40 | return &DefaultStyle; |
41 | } |
42 | |
43 | void GUISkin::setStyle(const String& guiElemType, const GUIElementStyle& style) |
44 | { |
45 | mStyles[guiElemType] = style; |
46 | } |
47 | |
48 | void GUISkin::removeStyle(const String& guiElemType) |
49 | { |
50 | mStyles.erase(guiElemType); |
51 | } |
52 | |
53 | Vector<String> GUISkin::getStyleNames() const |
54 | { |
55 | Vector<String> output; |
56 | for (auto& pair : mStyles) |
57 | output.push_back(pair.first); |
58 | |
59 | return output; |
60 | } |
61 | |
62 | HGUISkin GUISkin::create() |
63 | { |
64 | SPtr<GUISkin> newSkin = _createPtr(); |
65 | |
66 | return static_resource_cast<GUISkin>(gResources()._createResourceHandle(newSkin)); |
67 | } |
68 | |
69 | SPtr<GUISkin> GUISkin::_createPtr() |
70 | { |
71 | SPtr<GUISkin> newSkin = bs_core_ptr<GUISkin>(new (bs_alloc<GUISkin>()) GUISkin()); |
72 | newSkin->_setThisPtr(newSkin); |
73 | newSkin->initialize(); |
74 | |
75 | return newSkin; |
76 | } |
77 | |
78 | RTTITypeBase* GUISkin::getRTTIStatic() |
79 | { |
80 | return GUISkinRTTI::instance(); |
81 | } |
82 | |
83 | RTTITypeBase* GUISkin::getRTTI() const |
84 | { |
85 | return GUISkin::getRTTIStatic(); |
86 | } |
87 | } |