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/BsGUIButton.h"
4#include "GUI/BsGUIDimensions.h"
5#include "GUI/BsGUICommandEvent.h"
6
7namespace bs
8{
9 const String& GUIButton::getGUITypeName()
10 {
11 static String name = "Button";
12 return name;
13 }
14
15 GUIButton::GUIButton(const String& styleName, const GUIContent& content, const GUIDimensions& dimensions)
16 :GUIButtonBase(styleName, content, dimensions)
17 { }
18
19 GUIButton* GUIButton::create(const HString& text, const String& styleName)
20 {
21 return create(GUIContent(text), styleName);
22 }
23
24 GUIButton* GUIButton::create(const HString& text, const GUIOptions& options, const String& styleName)
25 {
26 return create(GUIContent(text), options, styleName);
27 }
28
29 GUIButton* GUIButton::create(const GUIContent& content, const String& styleName)
30 {
31 return new (bs_alloc<GUIButton>()) GUIButton(getStyleName<GUIButton>(styleName), content, GUIDimensions::create());
32 }
33
34 GUIButton* GUIButton::create(const GUIContent& content, const GUIOptions& options, const String& styleName)
35 {
36 return new (bs_alloc<GUIButton>()) GUIButton(getStyleName<GUIButton>(styleName), content, GUIDimensions::create(options));
37 }
38
39 bool GUIButton::_commandEvent(const GUICommandEvent& ev)
40 {
41 const bool processed = GUIButtonBase::_commandEvent(ev);
42
43 if(ev.getType() == GUICommandEventType::Confirm)
44 {
45 if(!_isDisabled())
46 {
47 onClick();
48 return true;
49 }
50 }
51
52 return processed;
53 }
54}