| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include "BsGUITabButton.h"
- #include "BsGUIWidget.h"
- #include "BsGUISkin.h"
- #include "BsGUILayoutOptions.h"
- #include "BsGUIMouseEvent.h"
- #include "BsGUITabbedTitleBar.h"
- using namespace CamelotFramework;
- using namespace BansheeEngine;
- namespace BansheeEditor
- {
- const CM::UINT32 GUITabButton::DRAG_MIN_DISTANCE = 3;
- const String& GUITabButton::getGUITypeName()
- {
- static String name = "TabButton";
- return name;
- }
- GUITabButton::GUITabButton(GUIWidget& parent, const GUIElementStyle* style, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUILayoutOptions& layoutOptions)
- :GUIToggle(parent, style, content, toggleGroup, layoutOptions), mIndex(index)
- {
- }
- GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const HString& text, const GUIElementStyle* style)
- {
- if(style == nullptr)
- {
- const GUISkin& skin = parent.getSkin();
- style = skin.getStyle(getGUITypeName());
- }
- return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, GUIContent(text), GUILayoutOptions::create(style));
- }
- GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const HString& text, const GUIOptions& layoutOptions, const GUIElementStyle* style)
- {
- if(style == nullptr)
- {
- const GUISkin& skin = parent.getSkin();
- style = skin.getStyle(getGUITypeName());
- }
- return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, GUIContent(text), GUILayoutOptions::create(layoutOptions, style));
- }
- GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUIElementStyle* style)
- {
- if(style == nullptr)
- {
- const GUISkin& skin = parent.getSkin();
- style = skin.getStyle(getGUITypeName());
- }
- return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, content, GUILayoutOptions::create(style));
- }
- GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUIOptions& layoutOptions, const GUIElementStyle* style)
- {
- if(style == nullptr)
- {
- const GUISkin& skin = parent.getSkin();
- style = skin.getStyle(getGUITypeName());
- }
- return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, content, GUILayoutOptions::create(layoutOptions, style));
- }
- bool GUITabButton::mouseEvent(const GUIMouseEvent& ev)
- {
- bool eventProcessed = GUIButtonBase::mouseEvent(ev);
- if(ev.getType() == GUIMouseEventType::MouseUp)
- {
- if(!mIsToggled)
- toggleOn();
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseDragStart)
- {
- mDragStartPosition = ev.getPosition();
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseDrag)
- {
- UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
- if(dist > DRAG_MIN_DISTANCE)
- {
- if(!onDragged.empty())
- onDragged(mIndex, ev.getPosition());
- }
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseDragEnd)
- {
- UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
- if(dist > DRAG_MIN_DISTANCE)
- {
- if(!onDragEnd.empty())
- onDragEnd(mIndex, ev.getPosition());
- }
- return true;
- }
- return eventProcessed;
- }
- }
|