mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
OMG the chat is finally scrolling!
* implement UIScrollArea * rework console to allow scrolling * many core ui changes in the way.. so maybe we will have new bugs * fix in UIScrollBar
This commit is contained in:
@@ -112,6 +112,7 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getClippingRect", &UIWidget::getClippingRect);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getChildrenRect", &UIWidget::getChildrenRect);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getAnchoredLayout", &UIWidget::getAnchoredLayout);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);
|
||||
|
@@ -127,7 +127,7 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
|
||||
// determine hooked widget edge point
|
||||
Rect hookedWidgetRect = hookedWidget->getRect();
|
||||
if(hookedWidget == parentWidget)
|
||||
hookedWidgetRect = parentWidget->getChildrenRect();
|
||||
hookedWidgetRect = parentWidget->getClippingRect();
|
||||
|
||||
int point = 0;
|
||||
switch(anchor.getHookedEdge()) {
|
||||
|
@@ -67,8 +67,8 @@ void UIGridLayout::internalUpdate()
|
||||
UIWidgetPtr parentWidget = getParentWidget();
|
||||
UIWidgetList widgets = parentWidget->getChildren();
|
||||
|
||||
Rect childrenRect = parentWidget->getChildrenRect();
|
||||
Point topLeft = childrenRect.topLeft();
|
||||
Rect clippingRect = parentWidget->getClippingRect();
|
||||
Point topLeft = clippingRect.topLeft();
|
||||
|
||||
int index = 0;
|
||||
for(const UIWidgetPtr& widget : widgets) {
|
||||
|
@@ -45,8 +45,8 @@ void UIHorizontalLayout::internalUpdate()
|
||||
if(m_alignRight)
|
||||
std::reverse(widgets.begin(), widgets.end());
|
||||
|
||||
Rect childrenRect = parentWidget->getChildrenRect();
|
||||
Point pos = (m_alignRight) ? childrenRect.topRight() : childrenRect.topLeft();
|
||||
Rect clippingRect = parentWidget->getClippingRect();
|
||||
Point pos = (m_alignRight) ? clippingRect.topRight() : clippingRect.topLeft();
|
||||
int prefferedWidth = 0;
|
||||
int gap;
|
||||
|
||||
@@ -62,15 +62,15 @@ void UIHorizontalLayout::internalUpdate()
|
||||
|
||||
if(widget->isFixedSize()) {
|
||||
// center it
|
||||
pos.y = childrenRect.top() + (childrenRect.height() - (widget->getMarginTop() + widget->getHeight() + widget->getMarginBottom()))/2;
|
||||
pos.y = clippingRect.top() + (clippingRect.height() - (widget->getMarginTop() + widget->getHeight() + widget->getMarginBottom()))/2;
|
||||
pos.y = std::max(pos.y, parentWidget->getY());
|
||||
} else {
|
||||
// expand height
|
||||
size.setHeight(childrenRect.height() - (widget->getMarginTop() + widget->getMarginBottom()));
|
||||
pos.y = childrenRect.top() + (childrenRect.height() - size.height())/2;
|
||||
size.setHeight(clippingRect.height() - (widget->getMarginTop() + widget->getMarginBottom()));
|
||||
pos.y = clippingRect.top() + (clippingRect.height() - size.height())/2;
|
||||
}
|
||||
|
||||
widget->setRect(Rect(pos, size));
|
||||
widget->setRect(Rect(pos + parentWidget->getVirtualOffset(), size));
|
||||
|
||||
gap = (m_alignRight) ? -widget->getMarginLeft() : (widget->getWidth() + widget->getMarginRight());
|
||||
gap += m_spacing;
|
||||
|
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "uilayout.h"
|
||||
#include "uiwidget.h"
|
||||
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
|
||||
@@ -29,9 +30,15 @@ void UILayout::update()
|
||||
if(m_updateDisabled)
|
||||
return;
|
||||
|
||||
assert(!m_updating);
|
||||
if(m_updating) {
|
||||
updateLater();
|
||||
return;
|
||||
}
|
||||
|
||||
m_updating = true;
|
||||
internalUpdate();
|
||||
if(UIWidgetPtr parentWidget = getParentWidget())
|
||||
parentWidget->onLayoutUpdate();
|
||||
m_updating = false;
|
||||
}
|
||||
|
||||
|
@@ -87,22 +87,16 @@ void UIManager::inputEvent(const InputEvent& event)
|
||||
}
|
||||
break;
|
||||
case Fw::MouseReleaseInputEvent: {
|
||||
bool accepted = false;
|
||||
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
|
||||
if(event.mouseButton == Fw::MouseLeftButton) {
|
||||
// release pressed widget
|
||||
if(m_pressedWidget) {
|
||||
if(updatePressedWidget(nullptr, event.mousePos))
|
||||
accepted = true;
|
||||
}
|
||||
if(m_pressedWidget)
|
||||
updatePressedWidget(nullptr, event.mousePos);
|
||||
|
||||
// release dragging widget
|
||||
if(m_draggingWidget) {
|
||||
if(updateDraggingWidget(nullptr, event.mousePos))
|
||||
accepted = true;
|
||||
}
|
||||
if(m_draggingWidget)
|
||||
updateDraggingWidget(nullptr, event.mousePos);
|
||||
}
|
||||
if(!accepted)
|
||||
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
|
||||
break;
|
||||
}
|
||||
case Fw::MouseMoveInputEvent: {
|
||||
@@ -131,14 +125,7 @@ bool UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const P
|
||||
bool accepted = false;
|
||||
|
||||
UIWidgetPtr oldPressedWidget = m_pressedWidget;
|
||||
m_pressedWidget = newPressedWidget;
|
||||
|
||||
if(newPressedWidget)
|
||||
newPressedWidget->updateState(Fw::PressedState);
|
||||
|
||||
if(oldPressedWidget) {
|
||||
oldPressedWidget->updateState(Fw::PressedState);
|
||||
|
||||
if(oldPressedWidget->isEnabled()) {
|
||||
// when releasing mouse inside pressed widget area send onClick event
|
||||
if(!clickedPos.isNull() && oldPressedWidget->containsPoint(clickedPos)) {
|
||||
@@ -150,6 +137,14 @@ bool UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const P
|
||||
}
|
||||
}
|
||||
|
||||
m_pressedWidget = newPressedWidget;
|
||||
|
||||
if(newPressedWidget)
|
||||
newPressedWidget->updateState(Fw::PressedState);
|
||||
|
||||
if(oldPressedWidget)
|
||||
oldPressedWidget->updateState(Fw::PressedState);
|
||||
|
||||
return accepted;
|
||||
}
|
||||
|
||||
@@ -363,7 +358,12 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
|
||||
UIWidgetPtr UIManager::createWidgetFromStyle(const std::string& styleName, const UIWidgetPtr& parent)
|
||||
{
|
||||
OTMLNodePtr node = OTMLNode::create(styleName);
|
||||
return createWidgetFromOTML(node, parent);
|
||||
try {
|
||||
return createWidgetFromOTML(node, parent);
|
||||
} catch(Exception& e) {
|
||||
logError("failed to create widget from style '", styleName, "': ", e.what());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
UIWidgetPtr UIManager::createWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent)
|
||||
|
@@ -45,8 +45,8 @@ void UIVerticalLayout::internalUpdate()
|
||||
if(m_alignBottom)
|
||||
std::reverse(widgets.begin(), widgets.end());
|
||||
|
||||
Rect childrenRect = parentWidget->getChildrenRect();
|
||||
Point pos = (m_alignBottom) ? childrenRect.bottomLeft() : childrenRect.topLeft();
|
||||
Rect clippingRect = parentWidget->getClippingRect();
|
||||
Point pos = (m_alignBottom) ? clippingRect.bottomLeft() : clippingRect.topLeft();
|
||||
int prefferedHeight = 0;
|
||||
int gap;
|
||||
|
||||
@@ -62,15 +62,15 @@ void UIVerticalLayout::internalUpdate()
|
||||
|
||||
if(widget->isFixedSize()) {
|
||||
// center it
|
||||
pos.x = childrenRect.left() + (childrenRect.width() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
|
||||
pos.x = clippingRect.left() + (clippingRect.width() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
|
||||
pos.x = std::max(pos.x, parentWidget->getX());
|
||||
} else {
|
||||
// expand width
|
||||
size.setWidth(childrenRect.width() - (widget->getMarginLeft() + widget->getMarginRight()));
|
||||
pos.x = childrenRect.left() + (childrenRect.width() - size.width())/2;
|
||||
size.setWidth(clippingRect.width() - (widget->getMarginLeft() + widget->getMarginRight()));
|
||||
pos.x = clippingRect.left() + (clippingRect.width() - size.width())/2;
|
||||
}
|
||||
|
||||
widget->setRect(Rect(pos, size));
|
||||
widget->setRect(Rect(pos + parentWidget->getVirtualOffset(), size));
|
||||
|
||||
gap = (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
|
||||
gap += m_spacing;
|
||||
|
@@ -57,7 +57,13 @@ void UIWidget::draw(const Rect& visibleRect)
|
||||
g_graphics.beginClipping(visibleRect);
|
||||
|
||||
drawSelf();
|
||||
drawChildren(visibleRect);
|
||||
|
||||
if(m_children.size() > 0) {
|
||||
if(m_clipping)
|
||||
g_graphics.beginClipping(visibleRect.intersection(getClippingRect()));
|
||||
|
||||
drawChildren(visibleRect);
|
||||
}
|
||||
|
||||
if(m_clipping)
|
||||
g_graphics.endClipping();
|
||||
@@ -890,13 +896,29 @@ int UIWidget::getChildIndex(const UIWidgetPtr& child)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Rect UIWidget::getChildrenRect()
|
||||
Rect UIWidget::getClippingRect()
|
||||
{
|
||||
Rect rect = m_rect;
|
||||
rect.expand(-m_padding.top, -m_padding.right, -m_padding.bottom, -m_padding.left);
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect UIWidget::getChildrenRect()
|
||||
{
|
||||
Rect childrenRect;
|
||||
for(const UIWidgetPtr& child : m_children) {
|
||||
if(!child->isExplicitlyVisible() || !child->getRect().isValid() || child->getOpacity() == 0.0f)
|
||||
continue;
|
||||
if(!childrenRect.isValid())
|
||||
childrenRect = child->getRect();
|
||||
else
|
||||
childrenRect = childrenRect.united(child->getRect());
|
||||
}
|
||||
if(!childrenRect.isValid())
|
||||
childrenRect = getClippingRect();
|
||||
return childrenRect;
|
||||
}
|
||||
|
||||
UIAnchorLayoutPtr UIWidget::getAnchoredLayout()
|
||||
{
|
||||
UIWidgetPtr parent = getParent();
|
||||
@@ -1231,6 +1253,13 @@ void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
||||
callLuaField("onGeometryChange", oldRect, newRect);
|
||||
}
|
||||
|
||||
void UIWidget::onLayoutUpdate()
|
||||
{
|
||||
callLuaField("onLayoutUpdate");
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->onLayoutUpdate();
|
||||
}
|
||||
|
||||
void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason)
|
||||
{
|
||||
callLuaField("onFocusChange", focused, reason);
|
||||
|
@@ -132,6 +132,7 @@ public:
|
||||
bool isChildLocked(const UIWidgetPtr& child);
|
||||
bool hasChild(const UIWidgetPtr& child);
|
||||
int getChildIndex(const UIWidgetPtr& child);
|
||||
Rect getClippingRect();
|
||||
Rect getChildrenRect();
|
||||
UIAnchorLayoutPtr getAnchoredLayout();
|
||||
UIWidgetPtr getRootParent();
|
||||
@@ -173,6 +174,7 @@ private:
|
||||
protected:
|
||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
||||
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
||||
virtual void onLayoutUpdate();
|
||||
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
|
||||
virtual void onChildFocusChange(const UIWidgetPtr& focusedChild, const UIWidgetPtr& unfocusedChild, Fw::FocusReason reason);
|
||||
virtual void onHoverChange(bool hovered);
|
||||
@@ -191,6 +193,8 @@ protected:
|
||||
virtual bool onClick(const Point& mousePos);
|
||||
virtual bool onDoubleClick(const Point& mousePos);
|
||||
|
||||
friend class UILayout;
|
||||
|
||||
bool propagateOnKeyText(const std::string& keyText);
|
||||
bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers);
|
||||
bool propagateOnKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
|
||||
|
@@ -30,7 +30,7 @@ void UICreature::drawSelf()
|
||||
|
||||
if(m_creature) {
|
||||
g_painter.setColor(Color::white);
|
||||
Rect drawRect = getChildrenRect();
|
||||
Rect drawRect = getClippingRect();
|
||||
m_creature->drawOutfit(drawRect, !m_fixedCreatureSize);
|
||||
}
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ void UIMap::zoomIn()
|
||||
|
||||
m_mapView->setVisibleDimension(Size(dimensionWidth, dimensionHeight));
|
||||
|
||||
Rect mapRect = getChildrenRect().expanded(-1);
|
||||
Rect mapRect = getClippingRect().expanded(-1);
|
||||
Size mapSize = m_mapView->getVisibleSize();
|
||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||
|
||||
@@ -85,7 +85,7 @@ void UIMap::zoomOut()
|
||||
|
||||
m_mapView->setVisibleDimension(Size(dimensionWidth, dimensionHeight));
|
||||
|
||||
Rect mapRect = getChildrenRect().expanded(-1);
|
||||
Rect mapRect = getClippingRect().expanded(-1);
|
||||
Size mapSize = m_mapView->getVisibleSize();
|
||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||
|
||||
@@ -116,7 +116,7 @@ void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
||||
{
|
||||
UIWidget::onGeometryChange(oldRect, newRect);
|
||||
|
||||
Rect mapRect = getChildrenRect().expanded(-1);
|
||||
Rect mapRect = getClippingRect().expanded(-1);
|
||||
Size mapSize = m_mapView->getVisibleSize();
|
||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||
|
||||
|
Reference in New Issue
Block a user