5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "guiScrollContainer.h"
22 GUIScrollContainer::GUIScrollContainer(gui::IGUIEnvironment *env,
23 gui::IGUIElement *parent, s32 id, const core::rect<s32> &rectangle,
24 const std::string &orientation, f32 scrollfactor) :
25 gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
26 m_scrollbar(nullptr), m_scrollfactor(scrollfactor)
28 if (orientation == "vertical")
29 m_orientation = VERTICAL;
30 else if (orientation == "horizontal")
31 m_orientation = HORIZONTAL;
33 m_orientation = UNDEFINED;
36 bool GUIScrollContainer::OnEvent(const SEvent &event)
38 if (event.EventType == EET_MOUSE_INPUT_EVENT &&
39 event.MouseInput.Event == EMIE_MOUSE_WHEEL &&
40 !event.MouseInput.isLeftPressed() && m_scrollbar) {
41 Environment->setFocus(m_scrollbar);
42 bool retval = m_scrollbar->OnEvent(event);
44 // a hacky fix for updating the hovering and co.
45 IGUIElement *hovered_elem = getElementFromPoint(core::position2d<s32>(
46 event.MouseInput.X, event.MouseInput.Y));
47 SEvent mov_event = event;
48 mov_event.MouseInput.Event = EMIE_MOUSE_MOVED;
49 Environment->postEventFromUser(mov_event);
51 hovered_elem->OnEvent(mov_event);
56 return IGUIElement::OnEvent(event);
59 void GUIScrollContainer::draw()
62 for (auto child : Children)
63 if (child->isNotClipped() ||
64 AbsoluteClippingRect.isRectCollided(
65 child->getAbsolutePosition()))
70 void GUIScrollContainer::updateScrolling()
72 s32 pos = m_scrollbar->getPos();
73 core::rect<s32> rect = getRelativePosition();
75 if (m_orientation == VERTICAL)
76 rect.UpperLeftCorner.Y = pos * m_scrollfactor;
77 else if (m_orientation == HORIZONTAL)
78 rect.UpperLeftCorner.X = pos * m_scrollfactor;
80 setRelativePosition(rect);