GRAPHICS: MACGUI: Load border padding directly from the 9-patch

This commit is contained in:
Eugene Sandulenko 2019-09-29 23:24:37 +02:00
parent 45ef1eb166
commit 3fbcc67766
4 changed files with 40 additions and 34 deletions

View file

@ -177,10 +177,10 @@ void MacWindow::updateInnerDims() {
if (_macBorder.hasBorder(_active) && _macBorder.hasOffsets()) { if (_macBorder.hasBorder(_active) && _macBorder.hasOffsets()) {
_innerDims = Common::Rect( _innerDims = Common::Rect(
_dims.left + _macBorder.getOffset(kBorderOffsetLeft), _dims.left + _macBorder.getOffset().left,
_dims.top + _macBorder.getOffset(kBorderOffsetTop), _dims.top + _macBorder.getOffset().top,
_dims.right - _macBorder.getOffset(kBorderOffsetRight), _dims.right - _macBorder.getOffset().right,
_dims.bottom - _macBorder.getOffset(kBorderOffsetBottom)); _dims.bottom - _macBorder.getOffset().bottom);
} else { } else {
_innerDims = _dims; _innerDims = _dims;
_innerDims.grow(-kBorderWidth); _innerDims.grow(-kBorderWidth);
@ -212,7 +212,7 @@ void MacWindow::prepareBorderSurface(ManagedSurface *g) {
void MacWindow::drawBorderFromSurface(ManagedSurface *g) { void MacWindow::drawBorderFromSurface(ManagedSurface *g) {
g->clear(kColorGreen2); g->clear(kColorGreen2);
Common::Rect inside = _innerDims; Common::Rect inside = _innerDims;
inside.moveTo(_macBorder.getOffset(kBorderOffsetLeft), _macBorder.getOffset(kBorderOffsetTop)); inside.moveTo(_macBorder.getOffset().left, _macBorder.getOffset().top);
g->fillRect(inside, kColorGreen); g->fillRect(inside, kColorGreen);
_macBorder.blitBorderInto(_borderSurface, _active); _macBorder.blitBorderInto(_borderSurface, _active);
@ -343,8 +343,11 @@ void MacWindow::loadBorder(Common::SeekableReadStream &file, bool active, int lo
else else
_macBorder.addInactiveBorder(surface); _macBorder.addInactiveBorder(surface);
if (!_macBorder.hasOffsets()) if (!_macBorder.hasOffsets()) {
if (lo + ro + to + bo > -4) { // Checking against default -1
_macBorder.setOffsets(lo, ro, to, bo); _macBorder.setOffsets(lo, ro, to, bo);
}
}
updateInnerDims(); updateInnerDims();
source->free(); source->free();
@ -389,8 +392,8 @@ bool MacWindow::isInCloseButton(int x, int y) {
int bLeft = kBorderWidth; int bLeft = kBorderWidth;
int bTop = kBorderWidth; int bTop = kBorderWidth;
if (_macBorder.hasOffsets()) { if (_macBorder.hasOffsets()) {
bLeft = _macBorder.getOffset(kBorderOffsetLeft); bLeft = _macBorder.getOffset().left;
bTop = _macBorder.getOffset(kBorderOffsetTop); bTop = _macBorder.getOffset().top;
} }
return (x >= _innerDims.left - bLeft && x < _innerDims.left && y >= _innerDims.top - bTop && y < _innerDims.top); return (x >= _innerDims.left - bLeft && x < _innerDims.left && y >= _innerDims.top - bTop && y < _innerDims.top);
} }
@ -399,8 +402,8 @@ bool MacWindow::isInResizeButton(int x, int y) {
int bRight = kBorderWidth; int bRight = kBorderWidth;
int bBottom = kBorderWidth; int bBottom = kBorderWidth;
if (_macBorder.hasOffsets()) { if (_macBorder.hasOffsets()) {
bRight = _macBorder.getOffset(kBorderOffsetRight); bRight = _macBorder.getOffset().right;
bBottom = _macBorder.getOffset(kBorderOffsetBottom); bBottom = _macBorder.getOffset().bottom;
} }
return (x >= _innerDims.right && x < _innerDims.right + bRight && y >= _innerDims.bottom && y < _innerDims.bottom + bBottom); return (x >= _innerDims.right && x < _innerDims.right + bRight && y >= _innerDims.bottom && y < _innerDims.bottom + bBottom);
} }
@ -410,9 +413,9 @@ WindowClick MacWindow::isInScroll(int x, int y) {
int bRight = kBorderWidth; int bRight = kBorderWidth;
int bBottom = kBorderWidth; int bBottom = kBorderWidth;
if (_macBorder.hasOffsets()) { if (_macBorder.hasOffsets()) {
bTop = _macBorder.getOffset(kBorderOffsetTop); bTop = _macBorder.getOffset().top;
bRight = _macBorder.getOffset(kBorderOffsetRight); bRight = _macBorder.getOffset().right;
bBottom = _macBorder.getOffset(kBorderOffsetBottom); bBottom = _macBorder.getOffset().bottom;
} }
if (x >= _innerDims.right && x < _innerDims.right + bRight) { if (x >= _innerDims.right && x < _innerDims.right + bRight) {

View file

@ -276,7 +276,7 @@ public:
* @param to Width of the top side of the border, in pixels. * @param to Width of the top side of the border, in pixels.
* @param bo Width of the bottom side of the border, in pixels. * @param bo Width of the bottom side of the border, in pixels.
*/ */
void loadBorder(Common::SeekableReadStream &file, bool active, int lo, int ro, int to, int bo); void loadBorder(Common::SeekableReadStream &file, bool active, int lo = -1, int ro = -1, int to = -1, int bo = -1);
//void setBorder(TransparentSurface &border, bool active); //void setBorder(TransparentSurface &border, bool active);
/** /**

View file

@ -32,7 +32,8 @@ using namespace Graphics::MacGUIConstants;
MacWindowBorder::MacWindowBorder() : _activeInitialized(false), _inactiveInitialized(false) { MacWindowBorder::MacWindowBorder() : _activeInitialized(false), _inactiveInitialized(false) {
_activeBorder = nullptr; _activeBorder = nullptr;
_inactiveBorder = nullptr; _inactiveBorder = nullptr;
_hasOffsets = false;
_borderOffsets.right = -1; // make invalid rect
} }
MacWindowBorder::~MacWindowBorder() { MacWindowBorder::~MacWindowBorder() {
@ -50,28 +51,37 @@ void MacWindowBorder::addActiveBorder(TransparentSurface *source) {
assert(!_activeBorder); assert(!_activeBorder);
_activeBorder = new NinePatchBitmap(source, true); _activeBorder = new NinePatchBitmap(source, true);
_activeInitialized = true; _activeInitialized = true;
if (_activeBorder->getPadding().isValidRect())
setOffsets(_activeBorder->getPadding());
} }
void MacWindowBorder::addInactiveBorder(TransparentSurface *source) { void MacWindowBorder::addInactiveBorder(TransparentSurface *source) {
assert(!_inactiveBorder); assert(!_inactiveBorder);
_inactiveBorder = new NinePatchBitmap(source, true); _inactiveBorder = new NinePatchBitmap(source, true);
_inactiveInitialized = true; _inactiveInitialized = true;
if (!_inactiveBorder->getPadding().isValidRect())
setOffsets(_inactiveBorder->getPadding());
} }
bool MacWindowBorder::hasOffsets() { bool MacWindowBorder::hasOffsets() {
return _hasOffsets; return _borderOffsets.isValidRect();
} }
void MacWindowBorder::setOffsets(int left, int right, int top, int bottom) { void MacWindowBorder::setOffsets(int left, int right, int top, int bottom) {
_borderOffsets[0] = left; _borderOffsets.left = left;
_borderOffsets[1] = right; _borderOffsets.right = right;
_borderOffsets[2] = top; _borderOffsets.top = top;
_borderOffsets[3] = bottom; _borderOffsets.bottom = bottom;
_hasOffsets = true;
} }
int MacWindowBorder::getOffset(MacBorderOffset offset) { void MacWindowBorder::setOffsets(Common::Rect &rect) {
return _borderOffsets[offset]; _borderOffsets = rect;
}
Common::Rect &MacWindowBorder::getOffset() {
return _borderOffsets;
} }
void MacWindowBorder::blitBorderInto(ManagedSurface &destination, bool active) { void MacWindowBorder::blitBorderInto(ManagedSurface &destination, bool active) {

View file

@ -32,13 +32,6 @@
namespace Graphics { namespace Graphics {
enum MacBorderOffset {
kBorderOffsetLeft = 0,
kBorderOffsetRight = 1,
kBorderOffsetTop = 2,
kBorderOffsetBottom = 3
};
/** /**
* A representation of a custom border, which allows for arbitrary border offsets * A representation of a custom border, which allows for arbitrary border offsets
* and nine-patch resizable displays for both active and inactive states. * and nine-patch resizable displays for both active and inactive states.
@ -89,6 +82,7 @@ public:
* @param bottom Thickness (in pixels) of the bottom side of the border. * @param bottom Thickness (in pixels) of the bottom side of the border.
*/ */
void setOffsets(int left, int right, int top, int bottom); void setOffsets(int left, int right, int top, int bottom);
void setOffsets(Common::Rect &rect);
/** /**
* Accessor method to retrieve a given border. * Accessor method to retrieve a given border.
@ -97,7 +91,7 @@ public:
* @param offset The identifier of the offset wanted. * @param offset The identifier of the offset wanted.
* @return The desired offset in pixels. * @return The desired offset in pixels.
*/ */
int getOffset(MacBorderOffset offset); Common::Rect &getOffset();
/** /**
* Blit the desired border (active or inactive) into a destination surface. * Blit the desired border (active or inactive) into a destination surface.
@ -115,8 +109,7 @@ private:
bool _activeInitialized; bool _activeInitialized;
bool _inactiveInitialized; bool _inactiveInitialized;
bool _hasOffsets; Common::Rect _borderOffsets;
int _borderOffsets[4];
}; };