MyGUI_ScrollView.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_ScrollView.h"
#include "MyGUI_SkinManager.h"
#include "MyGUI_ISubWidgetText.h"
#include "MyGUI_ScrollBar.h"
namespace MyGUI
{
const int SCROLL_VIEW_MOUSE_WHEEL = 50; // колличество пикселей для колеса мыши
const int SCROLL_VIEW_SCROLL_PAGE = 16; // колличество пикселей для кнопок скрола
ScrollView::ScrollView() :
mContentAlign(Align::Center)
{
mChangeContentByResize = false;
}
void ScrollView::initialiseOverride()
{
Base::initialiseOverride();
// FIXME нам нужен фокус клавы
setNeedKeyFocus(true);
assignWidget(mScrollViewClient, "Client");
if (getClientWidget() != nullptr)
{
getClientWidget()->eventMouseWheel += newDelegate(this, &ScrollView::notifyMouseWheel);
}
// create widget that will be real parent for child widgets
Widget* realClient = _getClientWidget()->createWidget<Widget>("Default", IntCoord(), Align::Default);
realClient->eventMouseWheel += newDelegate(this, &ScrollView::notifyMouseWheel);
setWidgetClient(realClient);
assignWidget(mVScroll, "VScroll");
if (mVScroll != nullptr)
{
mVScroll->eventScrollChangePosition += newDelegate(this, &ScrollView::notifyScrollChangePosition);
}
assignWidget(mHScroll, "HScroll");
if (mHScroll != nullptr)
{
mHScroll->eventScrollChangePosition += newDelegate(this, &ScrollView::notifyScrollChangePosition);
}
updateView();
}
void ScrollView::shutdownOverride()
{
mVScroll = nullptr;
mHScroll = nullptr;
mScrollViewClient = nullptr;
Base::shutdownOverride();
}
void ScrollView::setPosition(const IntPoint& _point)
{
Base::setPosition(_point);
}
void ScrollView::setSize(const IntSize& _size)
{
Base::setSize(_size);
updateView();
}
void ScrollView::setCoord(const IntCoord& _coord)
{
Base::setCoord(_coord);
updateView();
}
void ScrollView::notifyScrollChangePosition(ScrollBar* _sender, size_t _position)
{
if (_sender == mVScroll)
{
IntPoint point = getClientWidget()->getPosition();
point.top = -(int)_position;
getClientWidget()->setPosition(point);
}
else if (_sender == mHScroll)
{
IntPoint point = getClientWidget()->getPosition();
point.left = -(int)_position;
getClientWidget()->setPosition(point);
}
}
void ScrollView::notifyMouseWheel(Widget* _sender, int _rel)
{
if (mVRange != 0)
{
IntPoint point = getClientWidget()->getPosition();
int offset = -point.top;
if (_rel < 0)
offset += SCROLL_VIEW_MOUSE_WHEEL;
else
offset -= SCROLL_VIEW_MOUSE_WHEEL;
if (offset < 0)
offset = 0;
else if (offset > (int)mVRange)
offset = mVRange;
if (offset != point.top)
{
point.top = -offset;
if (mVScroll != nullptr)
{
mVScroll->setScrollPosition(offset);
}
getClientWidget()->setPosition(point);
}
}
else if (mHRange != 0)
{
IntPoint point = getClientWidget()->getPosition();
int offset = -point.left;
if (_rel < 0)
offset += SCROLL_VIEW_MOUSE_WHEEL;
else
offset -= SCROLL_VIEW_MOUSE_WHEEL;
if (offset < 0)
offset = 0;
else if (offset > (int)mHRange)
offset = mHRange;
if (offset != point.left)
{
point.left = -offset;
if (mHScroll != nullptr)
{
mHScroll->setScrollPosition(offset);
}
getClientWidget()->setPosition(point);
}
}
}
IntSize ScrollView::getContentSize() const
{
return getClientWidget()->getSize();
}
IntPoint ScrollView::getContentPosition() const
{
return IntPoint() - getClientWidget()->getPosition();
}
void ScrollView::setContentPosition(const IntPoint& _point)
{
getClientWidget()->setPosition(IntPoint() - _point);
}
IntSize ScrollView::getViewSize() const
{
return mScrollViewClient == nullptr ? getSize() : mScrollViewClient->getSize();
}
size_t ScrollView::getVScrollPage() const
{
return SCROLL_VIEW_SCROLL_PAGE;
}
size_t ScrollView::getHScrollPage() const
{
return SCROLL_VIEW_SCROLL_PAGE;
}
void ScrollView::updateView()
{
updateScrollSize();
updateScrollPosition();
}
void ScrollView::setVisibleVScroll(bool _value)
{
mVisibleVScroll = _value;
updateView();
}
void ScrollView::setVisibleHScroll(bool _value)
{
mVisibleHScroll = _value;
updateView();
}
void ScrollView::setCanvasAlign(Align _value)
{
mContentAlign = _value;
updateView();
}
void ScrollView::setCanvasSize(const IntSize& _value)
{
getClientWidget()->setSize(_value);
updateView();
}
IntSize ScrollView::getCanvasSize() const
{
return getClientWidget()->getSize();
}
void ScrollView::setPropertyOverride(std::string_view _key, std::string_view _value)
{
if (_key == "VisibleVScroll")
setVisibleVScroll(utility::parseValue<bool>(_value));
else if (_key == "VisibleHScroll")
setVisibleHScroll(utility::parseValue<bool>(_value));
else if (_key == "CanvasAlign")
setCanvasAlign(utility::parseValue<Align>(_value));
else if (_key == "CanvasSize")
setCanvasSize(utility::parseValue<IntSize>(_value));
else
{
Base::setPropertyOverride(_key, _value);
return;
}
eventChangeProperty(this, _key, _value);
}
bool ScrollView::isVisibleVScroll() const
{
return mVisibleVScroll;
}
bool ScrollView::isVisibleHScroll() const
{
return mVisibleHScroll;
}
Align ScrollView::getCanvasAlign() const
{
return mContentAlign;
}
void ScrollView::setCanvasSize(int _width, int _height)
{
setCanvasSize(IntSize(_width, _height));
}
Align ScrollView::getContentAlign() const
{
return mContentAlign;
}
void ScrollView::setViewOffset(const IntPoint& _value)
{
IntPoint value = _value;
IntPoint currentOffset = getClientWidget()->getPosition();
if (mHRange != 0)
{
if (value.left > 0)
value.left = 0;
else if (value.left < -(int)mHRange)
value.left = -(int)mHRange;
}
else
{
value.left = currentOffset.left;
}
if (mVRange != 0)
{
if (value.top > 0)
value.top = 0;
else if (value.top < -(int)mVRange)
value.top = -(int)mVRange;
}
else
{
value.top = currentOffset.top;
}
if (mHScroll != nullptr)
mHScroll->setScrollPosition(-value.left);
if (mVScroll != nullptr)
mVScroll->setScrollPosition(-value.top);
getClientWidget()->setPosition(value);
}
IntPoint ScrollView::getViewOffset() const
{
return getClientWidget()->getPosition();
}
IntCoord ScrollView::getViewCoord() const
{
return mScrollViewClient == nullptr ? getCoord() : mScrollViewClient->getCoord();
}
ScrollBar* ScrollView::getVScroll() const
{
return mVScroll;
}
} // namespace MyGUI
MyGUI_ISubWidgetText.h
MyGUI_Precompiled.h
MyGUI_ScrollBar.h
MyGUI_ScrollView.h
MyGUI_SkinManager.h
MyGUI::ICroppedRectangle::getPosition
IntPoint getPosition() const
Definition MyGUI_ICroppedRectangle.h:46
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition MyGUI_ICroppedRectangle.h:51
MyGUI::ScrollBar
widget description should be here.
Definition MyGUI_ScrollBar.h:24
MyGUI::ScrollViewBase::getViewSize
virtual IntSize getViewSize() const
Definition MyGUI_ScrollViewBase.cpp:329
MyGUI::ScrollViewBase::mHScroll
ScrollBar * mHScroll
Definition MyGUI_ScrollViewBase.h:44
MyGUI::ScrollViewBase::mVRange
size_t mVRange
Definition MyGUI_ScrollViewBase.h:50
MyGUI::ScrollViewBase::getHScrollPage
virtual size_t getHScrollPage() const
Definition MyGUI_ScrollViewBase.cpp:334
MyGUI::ScrollViewBase::updateScrollPosition
void updateScrollPosition()
Definition MyGUI_ScrollViewBase.cpp:234
MyGUI::ScrollViewBase::mHRange
size_t mHRange
Definition MyGUI_ScrollViewBase.h:51
MyGUI::ScrollViewBase::mScrollViewClient
Widget * mScrollViewClient
Definition MyGUI_ScrollViewBase.h:45
MyGUI::ScrollViewBase::mVisibleVScroll
bool mVisibleVScroll
Definition MyGUI_ScrollViewBase.h:48
MyGUI::ScrollViewBase::getContentPosition
virtual IntPoint getContentPosition() const
Definition MyGUI_ScrollViewBase.cpp:320
MyGUI::ScrollViewBase::mChangeContentByResize
bool mChangeContentByResize
Definition MyGUI_ScrollViewBase.h:54
MyGUI::ScrollViewBase::mVisibleHScroll
bool mVisibleHScroll
Definition MyGUI_ScrollViewBase.h:47
MyGUI::ScrollViewBase::getContentAlign
virtual Align getContentAlign() const
Definition MyGUI_ScrollViewBase.cpp:344
MyGUI::ScrollViewBase::getContentSize
virtual IntSize getContentSize() const
Definition MyGUI_ScrollViewBase.cpp:315
MyGUI::ScrollViewBase::updateScrollSize
void updateScrollSize()
Definition MyGUI_ScrollViewBase.cpp:14
MyGUI::ScrollViewBase::mVScroll
ScrollBar * mVScroll
Definition MyGUI_ScrollViewBase.h:43
MyGUI::ScrollViewBase::getVScrollPage
virtual size_t getVScrollPage() const
Definition MyGUI_ScrollViewBase.cpp:339
MyGUI::ScrollView::setVisibleHScroll
void setVisibleHScroll(bool _value)
Definition MyGUI_ScrollView.cpp:198
MyGUI::ScrollView::getViewCoord
IntCoord getViewCoord() const
Definition MyGUI_ScrollView.cpp:316
MyGUI::ScrollView::getCanvasSize
IntSize getCanvasSize() const
Definition MyGUI_ScrollView.cpp:216
MyGUI::ScrollView::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_ScrollView.cpp:69
MyGUI::ScrollView::setVisibleVScroll
void setVisibleVScroll(bool _value)
Definition MyGUI_ScrollView.cpp:192
MyGUI::ScrollView::initialiseOverride
void initialiseOverride() override
Definition MyGUI_ScrollView.cpp:25
MyGUI::ScrollView::setViewOffset
void setViewOffset(const IntPoint &_value)
Definition MyGUI_ScrollView.cpp:273
MyGUI::ScrollView::isVisibleHScroll
bool isVisibleHScroll() const
Definition MyGUI_ScrollView.cpp:253
MyGUI::ScrollView::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_ScrollView.cpp:221
MyGUI::ScrollView::getVScroll
ScrollBar * getVScroll() const
Definition MyGUI_ScrollView.cpp:321
MyGUI::ScrollView::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_ScrollView.cpp:74
MyGUI::ScrollView::isVisibleVScroll
bool isVisibleVScroll() const
Definition MyGUI_ScrollView.cpp:248
MyGUI::ScrollView::shutdownOverride
void shutdownOverride() override
Definition MyGUI_ScrollView.cpp:60
MyGUI::ScrollView::ScrollView
ScrollView()
Definition MyGUI_ScrollView.cpp:19
MyGUI::ScrollView::setCanvasAlign
void setCanvasAlign(Align _value)
Definition MyGUI_ScrollView.cpp:204
MyGUI::ScrollView::getCanvasAlign
Align getCanvasAlign() const
Definition MyGUI_ScrollView.cpp:258
MyGUI::ScrollView::updateView
void updateView()
Definition MyGUI_ScrollView.cpp:186
MyGUI::ScrollView::mContentAlign
Align mContentAlign
Definition MyGUI_ScrollView.h:96
MyGUI::ScrollView::setCanvasSize
void setCanvasSize(const IntSize &_value)
Definition MyGUI_ScrollView.cpp:210
MyGUI::ScrollView::getViewOffset
IntPoint getViewOffset() const
Definition MyGUI_ScrollView.cpp:311
MyGUI::ScrollView::notifyMouseWheel
void notifyMouseWheel(Widget *_sender, int _rel)
Definition MyGUI_ScrollView.cpp:104
MyGUI::ScrollView::notifyScrollChangePosition
void notifyScrollChangePosition(ScrollBar *_sender, size_t _position)
Definition MyGUI_ScrollView.cpp:88
MyGUI::ScrollView::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_ScrollView.cpp:81
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::getClientWidget
Widget * getClientWidget()
Definition MyGUI_Widget.cpp:1367
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, std::string_view _name)
Definition MyGUI_Widget.h:413
MyGUI::Widget::setWidgetClient
void setWidgetClient(Widget *_widget)
Definition MyGUI_Widget.cpp:1190
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:94
MyGUI::Widget::_getClientWidget
Widget * _getClientWidget()
If there is client widget return it, otherwise return this.
Definition MyGUI_Widget.cpp:1196
MyGUI::WidgetInput::setNeedKeyFocus
void setNeedKeyFocus(bool _value)
Definition MyGUI_WidgetInput.cpp:142
MyGUI::WidgetInput::eventMouseWheel
EventHandle_WidgetInt eventMouseWheel
Definition MyGUI_WidgetInput.h:144
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::SCROLL_VIEW_MOUSE_WHEEL
const int SCROLL_VIEW_MOUSE_WHEEL
Definition MyGUI_ScrollView.cpp:16
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::SCROLL_VIEW_SCROLL_PAGE
const int SCROLL_VIEW_SCROLL_PAGE
Definition MyGUI_ScrollView.cpp:17
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::Align::Default
@ Default
Definition MyGUI_Align.h:36
MyGUI::types::TPoint::left
T left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::top
T top
Definition MyGUI_TPoint.h:20