GRAPHICS: Add setBackgroundPattern() to MacWindow

Set a background pattern for the window surface. For instance, the
exits window in the MacVenture engine should have a light gray
background, rather than a white one, and this will allow it to get
one without having to draw it by itself.
This commit is contained in:
Torbjörn Andersson 2016-09-04 00:33:38 +02:00
parent 29535c0a55
commit 40c65540fa
4 changed files with 43 additions and 2 deletions

View file

@ -44,6 +44,9 @@ MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Mac
_active = false;
_borderIsDirty = true;
_pattern = 0;
_hasPattern = false;
_highlightedPart = kBorderNone;
_scrollPos = _scrollSize = 0.0;
@ -83,6 +86,10 @@ void MacWindow::resize(int w, int h) {
_surface.free();
_surface.create(w, h, PixelFormat::createFormatCLUT8());
if (_hasPattern)
drawPattern();
_borderSurface.free();
_borderSurface.create(w, h, PixelFormat::createFormatCLUT8());
_composeSurface.free();
@ -115,6 +122,13 @@ void MacWindow::setDimensions(const Common::Rect &r) {
_contentIsDirty = true;
}
void MacWindow::setBackgroundPattern(int pattern) {
_pattern = pattern;
_hasPattern = true;
drawPattern();
_contentIsDirty = true;
}
bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
if (!_borderIsDirty && !_contentIsDirty && !forceRedraw)
return false;
@ -273,6 +287,19 @@ void MacWindow::drawSimpleBorder(ManagedSurface *g) {
}
}
void MacWindow::drawPattern() {
byte *pat = _wm->getPatterns()[_pattern - 1];
for (int y = 0; y < _surface.h; y++) {
for (int x = 0; x < _surface.w; x++) {
byte *dst = (byte *)_surface.getBasePtr(x, y);
if (pat[y % 8] & (1 << (7 - (x % 8))))
*dst = kColorBlack;
else
*dst = kColorWhite;
}
}
}
void MacWindow::setHighlight(WindowClick highlightedPart) {
if (_highlightedPart == highlightedPart)
return;