WAGE: Manage window redraws in the WM

This commit is contained in:
Eugene Sandulenko 2016-04-18 10:36:09 +02:00
parent 56a20ef926
commit 024d1305a2
5 changed files with 34 additions and 6 deletions

View File

@ -154,6 +154,8 @@ Gui::Gui(WageEngine *engine) {
_consoleFullRedraw = true;
_screen.create(g_system->getWidth(), g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8());
_wm.setScreen(&_screen);
_scrollPos = 0;
_consoleLineHeight = 8; // Dummy value which makes sense
_consoleNumLines = 24; // Dummy value
@ -287,6 +289,7 @@ void Gui::drawScene() {
w->setTitle(_scene->_name);
_scene->paint(w->getSurface(), 0, 0);
w->draw(&_screen);
w->setDirty(true);
g_system->copyRectToScreen(_screen.getBasePtr(_scene->_designBounds->left - 2, _scene->_designBounds->top - 2),
_screen.pitch, _scene->_designBounds->left - 2, _scene->_designBounds->top - 2,
_scene->_designBounds->width(), _scene->_designBounds->height());
@ -317,6 +320,7 @@ void Gui::drawConsole() {
renderConsole(w->getSurface(), Common::Rect(kBorderWidth - 2, kBorderWidth - 2,
_scene->_textBounds->width() - kBorderWidth, _scene->_textBounds->height() - kBorderWidth));
w->draw(&_screen);
w->setDirty(true);
g_system->copyRectToScreen(_screen.getBasePtr(_scene->_textBounds->left - 2, _scene->_textBounds->top - 2),
_screen.pitch, _scene->_textBounds->left - 2, _scene->_textBounds->top - 2,
_scene->_textBounds->width(), _scene->_textBounds->height());

View File

@ -97,7 +97,10 @@ void MacWindow::setDimensions(const Common::Rect &r) {
_dims.moveTo(r.left, r.top);
}
void MacWindow::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
bool MacWindow::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
if (!_borderIsDirty && !_contentIsDirty && !forceRedraw)
return false;
if (_borderIsDirty || forceRedraw)
drawBorder();
@ -106,6 +109,8 @@ void MacWindow::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
return true;
}
const Graphics::Font *MacWindow::getTitleFont() {

View File

@ -75,12 +75,14 @@ public:
void move(int x, int y);
void resize(int w, int h);
void setDimensions(const Common::Rect &r);
void draw(Graphics::ManagedSurface *g, bool forceRedraw = false);
const Common::Rect &getDimensions() { return _dims; }
bool draw(Graphics::ManagedSurface *g, bool forceRedraw = false);
void setActive(bool active);
Graphics::ManagedSurface *getSurface() { return &_surface; }
void setTitle(Common::String &title) { _title = title; }
void setHighlight(BorderHighlight highlightedPart) { _highlightedPart = highlightedPart; }
void setScroll(float scrollPos, float scrollSize) { _scrollPos = scrollPos; _scrollSize = scrollSize; }
void setDirty(bool dirty) { _contentIsDirty = dirty; }
private:
void drawBorder();
@ -96,6 +98,7 @@ private:
bool _scrollable;
bool _active;
bool _borderIsDirty;
bool _contentIsDirty;
BorderHighlight _highlightedPart;
float _scrollPos, _scrollSize;

View File

@ -47,6 +47,7 @@
#include "common/list.h"
#include "common/array.h"
#include "common/system.h"
#include "graphics/managed_surface.h"
@ -57,6 +58,7 @@
namespace Wage {
MacWindowManager::MacWindowManager() {
_screen = 0;
_lastId = 0;
_activeWindow = -1;
}
@ -94,9 +96,19 @@ void MacWindowManager::setActive(int id) {
_fullRefresh = true;
}
void MacWindowManager::draw(Graphics::ManagedSurface *g) {
for (Common::List<MacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++)
(*it)->draw(g, _fullRefresh);
void MacWindowManager::draw() {
assert(_screen);
for (Common::List<MacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++) {
MacWindow *w = *it;
if (w->draw(_screen, _fullRefresh)) {
w->setDirty(false);
g_system->copyRectToScreen(_screen->getBasePtr(w->getDimensions().left - 2, w->getDimensions().top - 2),
_screen->pitch, w->getDimensions().left - 2, w->getDimensions().top - 2,
w->getDimensions().width(), w->getDimensions().height());
}
}
_fullRefresh = false;
}

View File

@ -57,14 +57,18 @@ public:
MacWindowManager();
~MacWindowManager();
void setScreen(Graphics::ManagedSurface *screen) { _screen = screen; }
int add(bool scrollable);
void setActive(int id);
void draw(Graphics::ManagedSurface *g);
void draw();
MacWindow *getWindow(int id) { return _windows[id]; }
private:
Graphics::ManagedSurface *_screen;
Common::List<MacWindow *> _windowStack;
Common::Array<MacWindow *> _windows;