From 8240e5b96d072fda2f84abdf84c27cf90ee891a5 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 3 Jul 2008 19:42:04 +0000 Subject: [PATCH] Rendering pipeline. WIP. (I see working buttons) svn-id: r32898 --- common/xmlparser.h | 9 ++++++- graphics/VectorRenderer.h | 8 +++---- gui/ThemeDefaultXML.cpp | 2 +- gui/ThemeRenderer.cpp | 50 +++++++++++++++++++++++++++++++-------- gui/ThemeRenderer.h | 10 +++++--- gui/newgui.cpp | 2 +- 6 files changed, 61 insertions(+), 20 deletions(-) diff --git a/common/xmlparser.h b/common/xmlparser.h index fa1f10061a0..167d04249cd 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -63,7 +63,7 @@ public: _pos = idx; - return _stream->readSByte(); + return _stream->readByte(); } void loadStream(SeekableReadStream *s) { @@ -331,6 +331,13 @@ protected: return (*key == 0); } + /** + * Overload if your parser needs to support parsing the same file + * several times, so you can clean up the internal state of the + * parser before each parse. + */ + virtual void cleanup() {} + int _pos; /** Current position on the XML buffer. */ XMLStream _text; /** Buffer with the text being parsed */ Common::String _fileName; diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h index 0b9ccc4836b..0e679663d9e 100644 --- a/graphics/VectorRenderer.h +++ b/graphics/VectorRenderer.h @@ -536,11 +536,11 @@ public: */ virtual void copyFrame(OSystem *sys, const Common::Rect &r) { #ifdef OVERLAY_MULTIPLE_DEPTHS // TODO: change OSystem to support templated copyRectToOverlay - sys->copyRectToOverlay((const PixelType*)_activeSurface->pixels, - _activeSurface->pitch, r.top, r.left, r.width(), r.height()); + sys->copyRectToOverlay((const PixelType*)_activeSurface->getBasePtr(r.left, r.top), + _activeSurface->w, r.top, r.left, r.width(), r.height()); #else - sys->copyRectToOverlay((const OverlayColor*)_activeSurface->pixels, - _activeSurface->pitch, r.top, r.left, r.width(), r.height()); + sys->copyRectToOverlay((const OverlayColor*)_activeSurface->getBasePtr(r.left, r.top), + _activeSurface->w, r.top, r.left, r.width(), r.height()); #endif } diff --git a/gui/ThemeDefaultXML.cpp b/gui/ThemeDefaultXML.cpp index 43b3e249a07..11ef1b58b0d 100644 --- a/gui/ThemeDefaultXML.cpp +++ b/gui/ThemeDefaultXML.cpp @@ -58,7 +58,7 @@ bool ThemeRenderer::loadDefaultXML() { "" ""; - if (!parser()->loadBuffer(defaultXML, false)) + if (!parser()->loadBuffer((const byte*)defaultXML, strlen(defaultXML), false)) return false; return parser()->parse(); diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp index 7b14b93b236..a5a1625fb67 100644 --- a/gui/ThemeRenderer.cpp +++ b/gui/ThemeRenderer.cpp @@ -47,6 +47,7 @@ const char *ThemeRenderer::kDrawDataStrings[] = { "button_idle", "button_hover", + "button_disabled", "surface", @@ -70,7 +71,7 @@ const char *ThemeRenderer::kDrawDataStrings[] = { ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) : _vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled), - _screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false) { + _screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false), _enabled(false) { _system = g_system; _parser = new ThemeParser(this); @@ -81,8 +82,7 @@ ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) : _graphicsMode = mode; setGraphicsMode(_graphicsMode); - if (isThemeLoadingRequired()) - loadTheme(themeName); + loadConfigFile("classic"); _initOk = true; _themeName = themeName; @@ -99,9 +99,21 @@ bool ThemeRenderer::init() { resetDrawArea(); } - if (isThemeLoadingRequired()) + if (!_themeOk || isThemeLoadingRequired()) { loadTheme(_themeName); + Theme::loadTheme(_defaultConfig); + Theme::loadTheme(_configFile, false, true); + } + + if (_fontName.empty()) { + if (_screen->w >= 400 && _screen->h >= 300) { + _font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); + } else { + _font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont); + } + } + return true; } @@ -110,7 +122,6 @@ void ThemeRenderer::deinit() { _system->hideOverlay(); freeRenderer(); freeScreen(); - unloadTheme(); _initOk = false; } } @@ -119,9 +130,21 @@ void ThemeRenderer::clearAll() { if (!_initOk) return; - _vectorRenderer->clearSurface(); - _vectorRenderer->copyWholeFrame(_system); - _system->updateScreen(); + _system->clearOverlay(); + _system->grabOverlay((OverlayColor*)_screen->pixels, _screen->w); +} + +void ThemeRenderer::enable() { + init(); + resetDrawArea(); + _system->showOverlay(); + clearAll(); + _enabled = true; +} + +void ThemeRenderer::disable() { + _system->hideOverlay(); + _enabled = false; } template @@ -228,7 +251,7 @@ void ThemeRenderer::drawCached(DrawData type, const Common::Rect &r) { void ThemeRenderer::drawDD(DrawData type, const Common::Rect &r) { if (isWidgetCached(type, r)) { drawCached(type, r); - } else { + } else if (_widgets[type] != 0) { for (uint i = 0; i < _widgets[type]->_steps.size(); ++i) _vectorRenderer->drawStep(r, *_widgets[type]->_steps[i]); } @@ -242,6 +265,8 @@ void ThemeRenderer::drawButton(const Common::Rect &r, const Common::String &str, drawDD(kDDButtonIdle, r); else if (state == kStateHighlight) drawDD(kDDButtonHover, r); + else if (state == kStateDisabled) + drawDD(kDDButtonDisabled, r); // TODO: Add text drawing. @@ -290,6 +315,11 @@ void ThemeRenderer::drawScrollbar(const Common::Rect &r, int sliderY, int slider return; } +void ThemeRenderer::updateScreen() { +// renderDirtyScreen(); + _vectorRenderer->copyWholeFrame(_system); +} + void ThemeRenderer::renderDirtyScreen() { // TODO: This isn't really optimized. Check dirty squares for collisions // and all that. @@ -299,7 +329,7 @@ void ThemeRenderer::renderDirtyScreen() { for (uint i = 0; i < _dirtyScreen.size(); ++i) _vectorRenderer->copyFrame(_system, _dirtyScreen[i]); - _system->updateScreen(); +// _system->updateScreen(); _dirtyScreen.clear(); } diff --git a/gui/ThemeRenderer.h b/gui/ThemeRenderer.h index 8d3f57b5477..3ce17c25b07 100644 --- a/gui/ThemeRenderer.h +++ b/gui/ThemeRenderer.h @@ -87,6 +87,7 @@ public: kDDButtonIdle, kDDButtonHover, + kDDButtonDisabled, kDDSurface, @@ -124,13 +125,13 @@ public: void clearAll(); void refresh() {} - void enable() {} - void disable() {} + void enable(); + void disable(); void openDialog() {} void closeAllDialogs() {} - void updateScreen() {} + void updateScreen(); //{} void resetDrawArea() {} void openDialog(bool top) {} @@ -210,6 +211,8 @@ protected: delete _widgets[i]; _widgets[i] = 0; } + + _themeOk = false; } void screenChange() {} @@ -268,6 +271,7 @@ protected: bool _initOk; bool _themeOk; bool _caching; + bool _enabled; Common::String _themeName; }; diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 4d0b3905b9f..efa7a910e2b 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -242,7 +242,7 @@ void NewGui::runLoop() { while (!_dialogStack.empty() && activeDialog == getTopDialog()) { if (_needRedraw) { redraw(); - _needRedraw = false; +// _needRedraw = false; } // Don't "tickle" the dialog until the theme has had a chance