GRAPHICS: MACGUI: Made MacDrawPixel bpp-aware

This commit is contained in:
Eugene Sandulenko 2020-08-15 16:08:32 +02:00
parent 43c3407557
commit e604c97607
6 changed files with 52 additions and 38 deletions

View file

@ -847,7 +847,7 @@ void inkDrawPixel(int x, int y, int src, void *data) {
// Get the pixel that macDrawPixel will give us, but store it to apply the // Get the pixel that macDrawPixel will give us, but store it to apply the
// ink later. // ink later.
tmpDst = *dst; tmpDst = *dst;
Graphics::macDrawPixel(x, y, src, p->ms->pd); (p->_wm->getDrawPixel())(x, y, src, p->ms->pd);
src = *dst; src = *dst;
*dst = tmpDst; *dst = tmpDst;

View file

@ -1020,10 +1020,10 @@ void Window::transZoom(TransParams &t, Common::Rect &clipRect, Graphics::Managed
r.moveTo(t.xStepSize * (i - s), t.yStepSize * (i - s)); r.moveTo(t.xStepSize * (i - s), t.yStepSize * (i - s));
} }
Graphics::drawLine(r.left, r.top, r.right, r.top, 0xffff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.left, r.top, r.right, r.top, 0xffff, _wm->getDrawPixel(), &pd);
Graphics::drawLine(r.right, r.top, r.right, r.bottom, 0xffff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.right, r.top, r.right, r.bottom, 0xffff, _wm->getDrawPixel(), &pd);
Graphics::drawLine(r.left, r.bottom, r.right, r.bottom, 0xffff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.left, r.bottom, r.right, r.bottom, 0xffff, _wm->getDrawPixel(), &pd);
Graphics::drawLine(r.left, r.top, r.left, r.bottom, 0xffff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.left, r.top, r.left, r.bottom, 0xffff, _wm->getDrawPixel(), &pd);
} }
r.setHeight(t.yStepSize * i * 2); r.setHeight(t.yStepSize * i * 2);

View file

@ -74,14 +74,14 @@ void MacButton::invertOuter() {
switch (_buttonType) { switch (_buttonType) {
case kCheckBox: { case kCheckBox: {
Common::Rect c = Common::Rect(r.left + 1, r.top + 3, r.left + 9, r.top + 11); Common::Rect c = Common::Rect(r.left + 1, r.top + 3, r.left + 9, r.top + 11);
Graphics::drawRect(c, 0, Graphics::macDrawPixel, &_pd); Graphics::drawRect(c, 0, _wm->getDrawPixel(), &_pd);
} }
break; break;
case kRound: case kRound:
Graphics::drawRoundRect(r, 4, 0, true, Graphics::macDrawPixel, &_pd); Graphics::drawRoundRect(r, 4, 0, true, _wm->getDrawPixel(), &_pd);
break; break;
case kRadio: case kRadio:
Graphics::drawEllipse(r.left + 1, r.top + 3, r.left + 10, r.top + 12, 0, false, Graphics::macDrawPixel, &_pd); Graphics::drawEllipse(r.left + 1, r.top + 3, r.left + 10, r.top + 12, 0, false, _wm->getDrawPixel(), &_pd);
break; break;
} }
@ -93,14 +93,14 @@ void MacButton::invertInner() {
switch (_buttonType) { switch (_buttonType) {
case kCheckBox: case kCheckBox:
Graphics::drawLine(r.left + 1, r.top + 3, r.left + 9, r.top + 11, 0, Graphics::macDrawPixel, &_pd); Graphics::drawLine(r.left + 1, r.top + 3, r.left + 9, r.top + 11, 0, _wm->getDrawPixel(), &_pd);
Graphics::drawLine(r.left + 1, r.top + 11, r.left + 9, r.top + 3, 0, Graphics::macDrawPixel, &_pd); Graphics::drawLine(r.left + 1, r.top + 11, r.left + 9, r.top + 3, 0, _wm->getDrawPixel(), &_pd);
Graphics::macDrawPixel(5, 7, 0, &_pd); (_wm->getDrawPixel())(5, 7, 0, &_pd);
break; break;
case kRound: case kRound:
break; break;
case kRadio: case kRadio:
Graphics::drawEllipse(r.left + 3, r.top + 5, r.left + 8, r.top + 10, 0, true, Graphics::macDrawPixel, &_pd); Graphics::drawEllipse(r.left + 3, r.top + 5, r.left + 8, r.top + 10, 0, true, _wm->getDrawPixel(), &_pd);
break; break;
} }
@ -119,14 +119,14 @@ bool MacButton::draw(bool forceRedraw) {
switch (_buttonType) { switch (_buttonType) {
case kCheckBox: { case kCheckBox: {
Common::Rect c = Common::Rect(r.left, r.top + 2, r.left + 10, r.top + 2 + 10); Common::Rect c = Common::Rect(r.left, r.top + 2, r.left + 10, r.top + 2 + 10);
Graphics::drawRect(c, 0, Graphics::macDrawPixel, &pd); Graphics::drawRect(c, 0, _wm->getDrawPixel(), &pd);
break; break;
} }
case kRound: case kRound:
Graphics::drawRoundRect(r, 4, 0, _active, Graphics::macDrawPixel, &pd); Graphics::drawRoundRect(r, 4, 0, _active, _wm->getDrawPixel(), &pd);
break; break;
case kRadio: case kRadio:
Graphics::drawEllipse(r.left, r.top + 2, r.left + 11, r.top + 13, 0, false, Graphics::macDrawPixel, &pd); Graphics::drawEllipse(r.left, r.top + 2, r.left + 11, r.top + 13, 0, false, _wm->getDrawPixel(), &pd);
break; break;
} }

View file

@ -374,7 +374,7 @@ void MacWindow::drawSimpleBorder(ManagedSurface *g) {
Common::Rect rr(rx1, ry1, rx2, ry2); Common::Rect rr(rx1, ry1, rx2, ry2);
MacPlotData pd(g, nullptr, &_wm->getPatterns(), 1, 0, 0, 1, _wm->_colorBlack, true); MacPlotData pd(g, nullptr, &_wm->getPatterns(), 1, 0, 0, 1, _wm->_colorBlack, true);
Graphics::drawFilledRect(rr, _wm->_colorBlack, Graphics::macDrawPixel, &pd); Graphics::drawFilledRect(rr, _wm->_colorBlack, _wm->getDrawPixel(), &pd);
} }
} }
if (closeable) { if (closeable) {

View file

@ -401,6 +401,7 @@ void MacWindowManager::removeWindow(MacWindow *target) {
_activeWindow = -1; _activeWindow = -1;
} }
template<typename T>
void macDrawPixel(int x, int y, int color, void *data) { void macDrawPixel(int x, int y, int color, void *data) {
MacPlotData *p = (MacPlotData *)data; MacPlotData *p = (MacPlotData *)data;
@ -414,11 +415,11 @@ void macDrawPixel(int x, int y, int color, void *data) {
uint xu = (uint)x; // for letting compiler optimize it uint xu = (uint)x; // for letting compiler optimize it
uint yu = (uint)y; uint yu = (uint)y;
*((byte *)p->surface->getBasePtr(xu, yu)) = p->invert ? ~(*((byte *)p->surface->getBasePtr(xu, yu))) : *((T)p->surface->getBasePtr(xu, yu)) = p->invert ? ~(*((T)p->surface->getBasePtr(xu, yu))) :
(pat[(yu - p->fillOriginY) % 8] & (1 << (7 - (xu - p->fillOriginX) % 8))) ? color : p->bgColor; (pat[(yu - p->fillOriginY) % 8] & (1 << (7 - (xu - p->fillOriginX) % 8))) ? color : p->bgColor;
if (p->mask) if (p->mask)
*((byte *)p->mask->getBasePtr(xu, yu)) = 0xff; *((T)p->mask->getBasePtr(xu, yu)) = 0xff;
} }
} else { } else {
int x1 = x; int x1 = x;
@ -431,15 +432,22 @@ void macDrawPixel(int x, int y, int color, void *data) {
if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h) { if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h) {
uint xu = (uint)x; // for letting compiler optimize it uint xu = (uint)x; // for letting compiler optimize it
uint yu = (uint)y; uint yu = (uint)y;
*((byte *)p->surface->getBasePtr(xu, yu)) = p->invert ? ~(*((byte *)p->surface->getBasePtr(xu, yu))) : *((T)p->surface->getBasePtr(xu, yu)) = p->invert ? ~(*((T)p->surface->getBasePtr(xu, yu))) :
(pat[(yu - p->fillOriginY) % 8] & (1 << (7 - (xu - p->fillOriginX) % 8))) ? color : p->bgColor; (pat[(yu - p->fillOriginY) % 8] & (1 << (7 - (xu - p->fillOriginX) % 8))) ? color : p->bgColor;
if (p->mask) if (p->mask)
*((byte *)p->mask->getBasePtr(xu, yu)) = 0xff; *((T)p->mask->getBasePtr(xu, yu)) = 0xff;
} }
} }
} }
MacWindowManager::DrawPixPtr MacWindowManager::getDrawPixel() {
if (_pixelformat.bytesPerPixel == 1)
return &macDrawPixel<byte *>;
else
return &macDrawPixel<uint32 *>;
}
void MacWindowManager::loadDesktop() { void MacWindowManager::loadDesktop() {
Common::SeekableReadStream *file = getFile("scummvm_background.bmp"); Common::SeekableReadStream *file = getFile("scummvm_background.bmp");
if (!file) if (!file)
@ -481,7 +489,7 @@ void MacWindowManager::drawDesktop() {
MacPlotData pd(_desktop, nullptr, &_patterns, kPatternCheckers, 0, 0, 1, _colorWhite); MacPlotData pd(_desktop, nullptr, &_patterns, kPatternCheckers, 0, 0, 1, _colorWhite);
Graphics::drawRoundRect(r, kDesktopArc, _colorBlack, true, macDrawPixel, &pd); Graphics::drawRoundRect(r, kDesktopArc, _colorBlack, true, getDrawPixel(), &pd);
} }
} }
@ -549,10 +557,12 @@ void MacWindowManager::draw() {
if (w->isDirty() || forceRedraw) { if (w->isDirty() || forceRedraw) {
w->draw(forceRedraw); w->draw(forceRedraw);
adjustDimensions(clip, outerDims, adjWidth, adjHeight);
if (_pixelformat.bytesPerPixel == 1) {
Surface *surface = g_system->lockScreen(); Surface *surface = g_system->lockScreen();
ManagedSurface *border = w->getBorderSurface(); ManagedSurface *border = w->getBorderSurface();
adjustDimensions(clip, outerDims, adjWidth, adjHeight);
for (int y = 0; y < adjHeight; y++) { for (int y = 0; y < adjHeight; y++) {
const byte *src = (const byte *)border->getBasePtr(clip.left - outerDims.left, y); const byte *src = (const byte *)border->getBasePtr(clip.left - outerDims.left, y);
byte *dst = (byte *)surface->getBasePtr(clip.left, y + clip.top); byte *dst = (byte *)surface->getBasePtr(clip.left, y + clip.top);
@ -562,6 +572,9 @@ void MacWindowManager::draw() {
} }
g_system->unlockScreen(); g_system->unlockScreen();
} else {
g_system->copyRectToScreen(w->getBorderSurface()->getBasePtr(MAX(clip.left - outerDims.left, 0), MAX(clip.top - outerDims.top, 0)), w->getBorderSurface()->pitch, clip.left, clip.top, adjWidth, adjHeight);
}
} }
adjustDimensions(clip, innerDims, adjWidth, adjHeight); adjustDimensions(clip, innerDims, adjWidth, adjHeight);
@ -789,10 +802,10 @@ void MacWindowManager::renderZoomBox(bool redraw) {
} }
void MacWindowManager::zoomBoxInner(Common::Rect &r, Graphics::MacPlotData &pd) { void MacWindowManager::zoomBoxInner(Common::Rect &r, Graphics::MacPlotData &pd) {
Graphics::drawLine(r.left, r.top, r.right, r.top, 0xff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.left, r.top, r.right, r.top, 0xff, getDrawPixel(), &pd);
Graphics::drawLine(r.right, r.top, r.right, r.bottom, 0xff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.right, r.top, r.right, r.bottom, 0xff, getDrawPixel(), &pd);
Graphics::drawLine(r.left, r.bottom, r.right, r.bottom, 0xff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.left, r.bottom, r.right, r.bottom, 0xff, getDrawPixel(), &pd);
Graphics::drawLine(r.left, r.top, r.left, r.bottom, 0xff, Graphics::macDrawPixel, &pd); Graphics::drawLine(r.left, r.top, r.left, r.bottom, 0xff, getDrawPixel(), &pd);
} }
///////////////// /////////////////

View file

@ -131,8 +131,6 @@ struct ZoomBox {
uint32 nextTime; uint32 nextTime;
}; };
void macDrawPixel(int x, int y, int color, void *data);
/** /**
* A manager class to handle window creation, destruction, * A manager class to handle window creation, destruction,
* drawing, moving and event handling. * drawing, moving and event handling.
@ -142,6 +140,9 @@ public:
MacWindowManager(uint32 mode = 0, MacPatterns *patterns = nullptr); MacWindowManager(uint32 mode = 0, MacPatterns *patterns = nullptr);
~MacWindowManager(); ~MacWindowManager();
typedef void (* DrawPixPtr)(int, int, int, void *);
DrawPixPtr getDrawPixel();
/** /**
* Mutator to indicate the surface onto which the desktop will be drawn. * Mutator to indicate the surface onto which the desktop will be drawn.
* Note that this method should be called as soon as the WM is created. * Note that this method should be called as soon as the WM is created.