| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "GUI/BsGUITabButton.h"
- #include "GUI/BsCGUIWidget.h"
- #include "GUI/BsGUISkin.h"
- #include "GUI/BsGUIDimensions.h"
- #include "GUI/BsGUIMouseEvent.h"
- #include "GUI/BsGUITabbedTitleBar.h"
- namespace bs
- {
- const UINT32 GUITabButton::DRAG_MIN_DISTANCE = 3;
- const String& GUITabButton::getGUITypeName()
- {
- static String name = "TabButton";
- return name;
- }
- GUITabButton::GUITabButton(const String& styleName, const SPtr<GUIToggleGroup>& toggleGroup,
- UINT32 index, const GUIContent& content, const GUIDimensions& dimensions)
- :GUIToggle(styleName, content, toggleGroup, dimensions), mIndex(index), mDraggedState(false)
- {
- }
- GUITabButton* GUITabButton::create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index,
- const HString& text, const String& styleName)
- {
- return new (bs_alloc<GUITabButton>()) GUITabButton(
- getStyleName<GUITabButton>(styleName), toggleGroup, index, GUIContent(text), GUIDimensions::create());
- }
- GUITabButton* GUITabButton::create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index,
- const HString& text, const GUIOptions& options, const String& styleName)
- {
- return new (bs_alloc<GUITabButton>()) GUITabButton(
- getStyleName<GUITabButton>(styleName), toggleGroup, index, GUIContent(text), GUIDimensions::create(options));
- }
- GUITabButton* GUITabButton::create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index,
- const GUIContent& content, const String& styleName)
- {
- return new (bs_alloc<GUITabButton>()) GUITabButton(
- getStyleName<GUITabButton>(styleName), toggleGroup, index, content, GUIDimensions::create());
- }
- GUITabButton* GUITabButton::create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index,
- const GUIContent& content, const GUIOptions& options, const String& styleName)
- {
- return new (bs_alloc<GUITabButton>()) GUITabButton(
- getStyleName<GUITabButton>(styleName), toggleGroup, index, content, GUIDimensions::create(options));
- }
- void GUITabButton::_toggleOn(bool triggerEvents)
- {
- _setElementDepth(0);
- GUIToggle::_toggleOn(triggerEvents);
- }
- void GUITabButton::_toggleOff(bool triggerEvents)
- {
- _setElementDepth(2);
- GUIToggle::_toggleOff(triggerEvents);
- }
- void GUITabButton::_setDraggedState(bool active)
- {
- if(mDraggedState == active)
- return;
- mDraggedState = active;
- if(mDraggedState)
- {
- mInactiveState = getState();
- if(mInactiveState != GUIElementState::Normal)
- _setState(GUIElementState::Normal);
- }
- else
- {
- if(getState() != mInactiveState)
- _setState(mInactiveState);
- }
- }
- bool GUITabButton::_mouseEvent(const GUIMouseEvent& ev)
- {
- if(ev.getType() == GUIMouseEventType::MouseOver)
- {
- if (!_isDisabled())
- {
- GUIElementState state = _isOn() ? GUIElementState::HoverOn : GUIElementState::Hover;
- if (!mDraggedState)
- {
- _setState(state);
- if (!onHover.empty())
- onHover();
- }
- else
- mInactiveState = state;
- }
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseOut)
- {
- if (!_isDisabled())
- {
- GUIElementState state = _isOn() ? GUIElementState::NormalOn : GUIElementState::Normal;
- if (!mDraggedState)
- {
- _setState(state);
- if (!onOut.empty())
- onOut();
- }
- else
- mInactiveState = state;
- }
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseDown)
- {
- if (!_isDisabled())
- {
- if (!mDraggedState)
- _setState(_isOn() ? GUIElementState::ActiveOn : GUIElementState::Active);
- _setElementDepth(0);
- }
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseUp)
- {
- if (!_isDisabled())
- {
- if (!mDraggedState)
- {
- _setState(_isOn() ? GUIElementState::HoverOn : GUIElementState::Hover);
- if (!onClick.empty())
- onClick();
- if (!mIsToggled)
- _toggleOn(true);
- }
- }
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseDragStart)
- {
- if (!_isDisabled())
- mDragStartPosition = ev.getPosition();
- return true;
- }
- else if(ev.getType() == GUIMouseEventType::MouseDrag)
- {
- if (!_isDisabled())
- {
- 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)
- {
- if (!_isDisabled())
- {
- UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
- if (dist > DRAG_MIN_DISTANCE)
- {
- if (!onDragEnd.empty())
- onDragEnd(mIndex, ev.getPosition());
- }
- }
- return true;
- }
- return false;
- }
- }
|