fix and changes

* win32 compilation fix
* add buttons to miniwindow
* dispatcher events fixes
* ui fixes
master
Eduardo Bart 12 years ago
parent 060c1cf8e7
commit 8ea154016b

@ -61,7 +61,6 @@ TopPanel
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: prev.right
anchors.right: next.left
visible: false
TopMenuButtonsPanel

@ -9,6 +9,7 @@ end
function UISplitter:onHoverChange(hovered)
if hovered then
if g_ui.getDraggingWidget() then return end
if self:getWidth() > self:getHeight() then
Mouse.setVerticalCursor()
self.vertical = true
@ -16,13 +17,15 @@ function UISplitter:onHoverChange(hovered)
Mouse.setHorizontalCursor()
self.vertical = false
end
self.hovering = true
if not self:isPressed() then
Effects.fadeIn(self)
end
else
if not self:isPressed() then
if not self:isPressed() and self.hovering then
Mouse.restoreCursor()
Effects.fadeOut(self)
self.hovering = false
end
end
end
@ -63,6 +66,7 @@ function UISplitter:onMouseRelease(mousePos, mouseButton)
if not self:isHovered() then
Mouse.restoreCursor()
Effects.fadeOut(self)
self.hovering = false
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

@ -19,14 +19,45 @@ MiniWindow < UIMiniWindow
height: 24
image-border-bottom: 1
UIButton
id: closeButton
anchors.top: parent.top
anchors.right: parent.right
margin-top: 5
margin-right: 5
size: 14 14
image-source: /game/images/miniwindowbuttons.png
image-clip: 14 0 14 14
$hover:
image-clip: 14 14 14 14
$pressed:
image-clip: 14 28 14 14
UIButton
id: minimizeButton
anchors.top: closeButton.top
anchors.right: closeButton.left
margin-right: 3
size: 14 14
image-source: /game/images/miniwindowbuttons.png
image-clip: 0 0 14 14
$hover:
image-clip: 0 14 14 14
$pressed:
image-clip: 0 28 14 14
ResizeBorder
id: bottomResizeBorder
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
height: 2
margin-bottom: 1
height: 1
minimum: 70
background: #ffffff88
VerticalScrollBar
id: miniwindowScrollBar
@ -37,7 +68,6 @@ MiniWindow < UIMiniWindow
margin-top: 22
margin-right: 2
margin-bottom: 2
fade-effect: false
MiniWindowContents < ScrollablePanel
anchors.fill: parent

@ -1,36 +0,0 @@
UIMiniWindow = extends(UIWindow)
function UIMiniWindow.create()
local miniwindow = UIMiniWindow.internalCreate()
return miniwindow
end
function UIMiniWindow:onDragEnter(mousePos)
local parent = self:getParent()
if not parent then return false end
if parent:getClassName() == 'UIMiniWindowContainer' then
local containerParent = parent:getParent()
parent:removeChild(self)
containerParent:addChild(self)
end
local oldPos = self:getPosition()
self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y }
self:setPosition(oldPos)
return true
end
function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
-- TODO: drop on other interfaces
end
function UIMiniWindow:onFocusChange(focused)
-- miniwindows only raises when its outside MiniWindowContainers
if not focused then return end
local parent = self:getParent()
if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
self:raise()
end
end

@ -2,6 +2,7 @@ UIMiniWindow = extends(UIWindow)
function UIMiniWindow.create()
local miniwindow = UIMiniWindow.internalCreate()
miniwindow:setFocusable(false)
return miniwindow
end

@ -171,7 +171,7 @@ void Application::run()
if(!m_initialized)
return;
ticks_t lastPollTicks = g_clock.updateTicks();
//ticks_t lastPollTicks = g_clock.updateTicks();
m_stopping = false;
m_running = true;
@ -185,10 +185,10 @@ void Application::run()
// poll events every POLL_CYCLE_DELAY
// this delay exists to avoid massive polling thus increasing framerate
if(g_clock.ticksElapsed(lastPollTicks) >= m_pollCycleDelay) {
//if(g_clock.ticksElapsed(lastPollTicks) >= m_pollCycleDelay) {
poll();
lastPollTicks = g_clock.ticks();
}
// lastPollTicks = g_clock.ticks();
//}
if(m_appFlags & Fw::AppEnableGraphics && g_window.isVisible()) {
g_graphics.beginRender();
@ -225,6 +225,7 @@ void Application::poll()
}
Connection::poll();
//g_eventDispatcher.poll(true);
g_eventDispatcher.poll();
}

@ -35,7 +35,7 @@ void EventDispatcher::flush()
m_scheduledEventList.pop();
}
void EventDispatcher::poll()
void EventDispatcher::poll(bool allEvents)
{
while(!m_scheduledEventList.empty()) {
ScheduledEventPtr scheduledEvent = m_scheduledEventList.top();
@ -45,12 +45,16 @@ void EventDispatcher::poll()
scheduledEvent->execute();
}
m_pollEventsSize = m_eventList.size();
for(int i=0;i<m_pollEventsSize;++i) {
EventPtr event = m_eventList.front();
m_eventList.pop_front();
event->execute();
}
do {
m_pollEventsSize = m_eventList.size();
if(m_pollEventsSize == 0)
break;
for(int i=0;i<m_pollEventsSize;++i) {
EventPtr event = m_eventList.front();
m_eventList.pop_front();
event->execute();
}
} while(allEvents);
}
ScheduledEventPtr EventDispatcher::scheduleEvent(const SimpleCallback& callback, int delay)

@ -73,7 +73,7 @@ class EventDispatcher
{
public:
void flush();
void poll();
void poll(bool allEvents = false);
EventPtr addEvent(const SimpleCallback& callback, bool pushFront = false);
ScheduledEventPtr scheduleEvent(const SimpleCallback& callback, int delay);

@ -49,7 +49,6 @@ void Graphics::init()
#endif
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
m_emptyTexture = TexturePtr(new Texture);
@ -112,6 +111,16 @@ void Graphics::beginRender()
void Graphics::endRender()
{
/*
// this is a simple blur effect
static Timer timer;
if(timer.ticksElapsed() >= 20) {
glAccum(GL_MULT, 0.8);
glAccum(GL_ACCUM, 0.2);
timer.restart();
}
glAccum(GL_RETURN, 1);
*/
}
void Graphics::beginClipping(const Rect& clipRect)
@ -126,7 +135,7 @@ void Graphics::beginClipping(const Rect& clipRect)
glColorMask(0, 0, 0, 0);
g_painter.drawFilledRect(clipRect);
// set stencil buffer for clippig
// set stencil buffer for clipping
glColorMask(1, 1, 1, 1);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

@ -312,6 +312,7 @@ void WIN32Window::internalChooseGLVisual()
0, // Reserved
0, 0, 0 }; // Layer Masks Ignored
pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd);
if(!pixelFormat)
logFatal("Could not find a suitable pixel format");

@ -81,11 +81,11 @@ void UIAnchorLayout::removeWidget(const UIWidgetPtr& widget)
removeAnchors(widget);
}
void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup)
bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup)
{
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget)
return;
return false;
Rect newRect = widget->getRect();
bool verticalMoved = false;
@ -214,12 +214,17 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
}
}
widget->setRect(newRect);
bool changed = false;
if(widget->setRect(newRect))
changed = true;
anchorGroup.setUpdated(true);
return changed;
}
void UIAnchorLayout::internalUpdate()
bool UIAnchorLayout::internalUpdate()
{
bool changed = false;
// reset all anchors groups update state
for(auto& it : m_anchorsGroups) {
UIAnchorGroup& anchorGroup = it.second;
@ -230,7 +235,11 @@ void UIAnchorLayout::internalUpdate()
for(auto& it : m_anchorsGroups) {
const UIWidgetPtr& widget = it.first;
UIAnchorGroup& anchorGroup = it.second;
if(!anchorGroup.isUpdated())
updateWidget(widget, anchorGroup);
if(!anchorGroup.isUpdated()) {
if(updateWidget(widget, anchorGroup))
changed = true;
}
}
return changed;
}

@ -75,10 +75,10 @@ public:
UIAnchorLayoutPtr asUIAnchorLayout() { return std::static_pointer_cast<UIAnchorLayout>(shared_from_this()); }
protected:
void internalUpdate();
bool internalUpdate();
private:
void updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup);
bool updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup);
std::map<UIWidgetPtr, UIAnchorGroup> m_anchorsGroups;
};

@ -62,8 +62,9 @@ void UIGridLayout::addWidget(const UIWidgetPtr& widget)
update();
}
void UIGridLayout::internalUpdate()
bool UIGridLayout::internalUpdate()
{
bool changed = false;
UIWidgetPtr parentWidget = getParentWidget();
UIWidgetList widgets = parentWidget->getChildren();
@ -80,12 +81,15 @@ void UIGridLayout::internalUpdate()
Point virtualPos = Point(column * (m_cellSize.width() + m_cellSpacing), line * (m_cellSize.height() + m_cellSpacing));
Point pos = topLeft + virtualPos;
widget->setRect(Rect(pos, m_cellSize));
if(widget->setRect(Rect(pos, m_cellSize)))
changed = true;
index++;
if(index >= m_numColumns * m_numLines)
break;
}
return changed;
}

@ -44,7 +44,7 @@ public:
virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; }
protected:
void internalUpdate();
bool internalUpdate();
private:
Size m_cellSize;

@ -35,16 +35,17 @@ void UIHorizontalLayout::applyStyle(const OTMLNodePtr& styleNode)
}
}
void UIHorizontalLayout::internalUpdate()
bool UIHorizontalLayout::internalUpdate()
{
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget)
return;
return false;
UIWidgetList widgets = parentWidget->getChildren();
if(m_alignRight)
std::reverse(widgets.begin(), widgets.end());
bool changed = false;
Rect clippingRect = parentWidget->getClippingRect();
Point pos = (m_alignRight) ? clippingRect.topRight() : clippingRect.topLeft();
int prefferedWidth = 0;
@ -70,7 +71,8 @@ void UIHorizontalLayout::internalUpdate()
pos.y = clippingRect.top() + (clippingRect.height() - size.height())/2;
}
widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size));
if(widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size)))
changed = true;
gap = (m_alignRight) ? -widget->getMarginLeft() : (widget->getWidth() + widget->getMarginRight());
gap += m_spacing;
@ -87,4 +89,6 @@ void UIHorizontalLayout::internalUpdate()
parentWidget->setWidth(prefferedWidth);
});
}
return true;
}

@ -37,7 +37,7 @@ public:
UIHorizontalLayoutPtr asUIHorizontalLayout() { return std::static_pointer_cast<UIHorizontalLayout>(shared_from_this()); }
protected:
void internalUpdate();
bool internalUpdate();
Boolean<false> m_alignRight;
};

@ -38,7 +38,7 @@ void UILayout::update()
m_updating = true;
internalUpdate();
if(UIWidgetPtr parentWidget = getParentWidget())
parentWidget->onLayoutUpdate();
parentWidget->onLayoutUpdate();
m_updating = false;
}

@ -55,7 +55,7 @@ public:
virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; }
protected:
virtual void internalUpdate() = 0;
virtual bool internalUpdate() = 0;
Boolean<false> m_updateDisabled;
Boolean<false> m_updating;

@ -34,11 +34,13 @@ void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
}
}
void UIVerticalLayout::internalUpdate()
bool UIVerticalLayout::internalUpdate()
{
bool changed = false;
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget)
return;
return false;
UIWidgetList widgets = parentWidget->getChildren();
@ -70,7 +72,8 @@ void UIVerticalLayout::internalUpdate()
pos.x = clippingRect.left() + (clippingRect.width() - size.width())/2;
}
widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size));
if(widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size)))
changed = true;
gap = (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
gap += m_spacing;
@ -87,4 +90,6 @@ void UIVerticalLayout::internalUpdate()
parentWidget->setHeight(prefferedHeight);
});
}
return changed;
}

@ -37,7 +37,7 @@ public:
UIVerticalLayoutPtr asUIVerticalLayout() { return std::static_pointer_cast<UIVerticalLayout>(shared_from_this()); }
protected:
void internalUpdate();
bool internalUpdate();
Boolean<false> m_alignBottom;
};

@ -726,16 +726,16 @@ void UIWidget::setLayout(const UILayoutPtr& layout)
m_layout = layout;
}
void UIWidget::setRect(const Rect& rect)
bool UIWidget::setRect(const Rect& rect)
{
if(rect.width() > 8192 || rect.height() > 8192) {
logError("attempt to set huge rect size (", rect,") for ", m_id);
return;
return false;
}
// only update if the rect really changed
Rect oldRect = m_rect;
if(rect == oldRect)
return;
return false;
m_rect = rect;
@ -752,6 +752,8 @@ void UIWidget::setRect(const Rect& rect)
});
m_updateEventScheduled = true;
}
return true;
}
void UIWidget::setStyle(const std::string& styleName)
@ -978,6 +980,9 @@ UIWidgetPtr UIWidget::getChildById(const std::string& childId)
UIWidgetPtr UIWidget::getChildByPos(const Point& childPos)
{
if(!containsChildPoint(childPos))
return nullptr;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsPoint(childPos))
@ -1010,6 +1015,9 @@ UIWidgetPtr UIWidget::recursiveGetChildById(const std::string& id)
UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
{
if(!containsChildPoint(childPos))
return nullptr;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
@ -1026,6 +1034,9 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
{
UIWidgetList children;
if(!containsChildPoint(childPos))
return children;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
@ -1342,8 +1353,9 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
m_lastClickPosition = mousePos;
}
if(hasLuaField("onMousePress"))
if(hasLuaField("onMousePress")) {
return callLuaField<bool>("onMousePress", mousePos, button);
}
return true;
}

@ -113,7 +113,7 @@ public:
void setId(const std::string& id);
void setParent(const UIWidgetPtr& parent);
void setLayout(const UILayoutPtr& layout);
void setRect(const Rect& rect);
bool setRect(const Rect& rect);
void setStyle(const std::string& styleName);
void setStyleFromNode(const OTMLNodePtr& styleNode);
void setEnabled(bool enabled);
@ -240,6 +240,7 @@ public:
bool isDestroyed() { return m_destroyed; }
bool hasChildren() { return m_children.size() > 0; }
bool containsChildPoint(const Point& point) { return getClippingRect().contains(point); }
bool containsPoint(const Point& point) { return m_rect.contains(point); }
std::string getId() { return m_id; }

Loading…
Cancel
Save