add clock, change exceptions, add network exceptions, fix some crashes

This commit is contained in:
Eduardo Bart
2011-12-01 20:25:32 -02:00
parent 4afbe43e6f
commit d5e15d1f06
54 changed files with 442 additions and 274 deletions

View File

@@ -24,7 +24,7 @@
#include "uitranslator.h"
#include <framework/graphics/font.h>
#include <framework/otml/otmlnode.h>
#include <framework/platform/platform.h>
#include <framework/core/clock.h>
#include <framework/graphics/graphics.h>
UIFrameCounter::UIFrameCounter()
@@ -32,7 +32,7 @@ UIFrameCounter::UIFrameCounter()
m_focusable = false;
m_phantom = true;
m_align = Fw::AlignLeft;
m_lastFrameTicks = g_platform.getTicks();
m_lastFrameTicks = g_clock.ticks();
m_frameCount = 0;
}
@@ -40,7 +40,7 @@ void UIFrameCounter::render()
{
UIWidget::render();
int now = g_platform.getTicks();
int now = g_clock.ticks();
if(now - m_lastFrameTicks >= 1000) {
m_fpsText = Fw::mkstr("FPS: ", m_frameCount);
m_lastFrameTicks = now;

View File

@@ -24,6 +24,7 @@
#include <framework/graphics/font.h>
#include <framework/graphics/graphics.h>
#include <framework/platform/platform.h>
#include <framework/core/clock.h>
#include <framework/otml/otmlnode.h>
UILineEdit::UILineEdit()
@@ -55,7 +56,7 @@ void UILineEdit::render()
assert(m_cursorPos <= textLength);
// draw every 333ms
const int delay = 333;
int ticks = g_platform.getTicks();
int ticks = g_clock.ticks();
if(ticks - m_cursorTicks <= delay) {
Rect cursorRect;
// when cursor is at 0 or is the first visible element
@@ -447,5 +448,5 @@ bool UILineEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
void UILineEdit::blinkCursor()
{
m_cursorTicks = g_platform.getTicks();
m_cursorTicks = g_clock.ticks();
}

View File

@@ -110,8 +110,8 @@ bool UIManager::importStyles(const std::string& file)
for(const OTMLNodePtr& styleNode : doc->children())
importStyleFromOTML(styleNode);
return true;
} catch(std::exception& e) {
logError("failed to import ui styles from '", file, "':\n", e.what());
} catch(Exception& e) {
logError("Failed to import UI styles from '", file, "': ", e.what());
return false;
}
}
@@ -153,8 +153,11 @@ OTMLNodePtr UIManager::getStyle(const std::string& styleName)
}
auto it = m_styles.find(styleName);
if(it == m_styles.end())
throw std::runtime_error(Fw::mkstr("style '", styleName, "' is not a defined style"));
if(it == m_styles.end()) {
logError("Unable to retrive style '", styleName, "': not a defined style");
return nullptr;
}
return m_styles[styleName];
}
@@ -171,14 +174,14 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
importStyleFromOTML(node);
else {
if(widget)
throw std::runtime_error("cannot have multiple main widgets in .otui files");
Fw::throwException("cannot have multiple main widgets in otui files");
widget = loadWidgetFromOTML(node, parent);
}
}
return widget;
} catch(std::exception& e) {
logError("failed to load ui from '", file, "':\n", e.what());
} catch(Exception& e) {
logError("Failed to load UI from '", file, "': ", e.what());
return nullptr;
}
}

View File

@@ -142,6 +142,8 @@ void UIWidget::setFocusable(bool focusable)
void UIWidget::setStyle(const std::string& styleName)
{
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
if(!styleNode)
return;
applyStyle(styleNode);
m_style = styleNode;
updateStyle();
@@ -331,7 +333,7 @@ UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id)
void UIWidget::focusChild(const UIWidgetPtr& child, Fw::FocusReason reason)
{
if(child && !hasChild(child)) {
logError("attempt to focus an unknown child in a UIWidget");
logError("Attempt to focus an unknown child in a UIWidget");
return;
}
@@ -440,7 +442,7 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
if(focusAnother && !m_focusedChild)
focusPreviousChild(Fw::ActiveFocusReason);
} else
logError("attempt to remove an unknown child from a UIWidget");
logError("Attempt to remove an unknown child from a UIWidget");
}
void UIWidget::focusNextChild(Fw::FocusReason reason)
@@ -774,8 +776,8 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
try {
onStyleApply(styleNode);
callLuaField("onStyleApply", styleNode);
} catch(std::exception& e) {
logError("failed to apply widget '", m_id, "' style: ", e.what());
} catch(Exception& e) {
logError("Failed to apply style to widget '", m_id, "' style: ", e.what());
}
}