2016-07-31 08:43:49 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2016-09-03 10:46:38 +00:00
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
2016-07-31 08:43:49 +00:00
|
|
|
|
2016-07-29 08:27:30 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
|
2016-07-31 09:16:09 +00:00
|
|
|
#include "graphics/macgui/macwindowborder.h"
|
2016-07-29 08:27:30 +00:00
|
|
|
#include "graphics/macgui/macwindowmanager.h"
|
|
|
|
|
2016-06-02 17:02:32 +00:00
|
|
|
namespace Graphics {
|
|
|
|
|
2016-07-29 08:27:30 +00:00
|
|
|
using namespace Graphics::MacGUIConstants;
|
|
|
|
|
2016-06-03 18:49:54 +00:00
|
|
|
MacWindowBorder::MacWindowBorder() : _activeInitialized(false), _inactiveInitialized(false) {
|
2016-06-02 17:02:32 +00:00
|
|
|
_activeBorder = nullptr;
|
2016-07-29 10:16:08 +00:00
|
|
|
_inactiveBorder = nullptr;
|
2019-09-29 21:24:37 +00:00
|
|
|
|
|
|
|
_borderOffsets.right = -1; // make invalid rect
|
2016-06-02 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MacWindowBorder::~MacWindowBorder() {
|
|
|
|
if (_activeBorder)
|
|
|
|
delete _activeBorder;
|
|
|
|
if (_inactiveBorder)
|
|
|
|
delete _inactiveBorder;
|
|
|
|
}
|
|
|
|
|
2016-07-29 10:16:08 +00:00
|
|
|
bool MacWindowBorder::hasBorder(bool active) {
|
|
|
|
return active ? _activeInitialized : _inactiveInitialized;
|
2016-06-03 18:49:54 +00:00
|
|
|
}
|
2016-07-29 10:14:19 +00:00
|
|
|
|
2016-08-25 11:03:46 +00:00
|
|
|
void MacWindowBorder::addActiveBorder(TransparentSurface *source) {
|
2016-06-03 18:49:54 +00:00
|
|
|
assert(!_activeBorder);
|
2016-08-25 11:03:46 +00:00
|
|
|
_activeBorder = new NinePatchBitmap(source, true);
|
2016-06-03 18:49:54 +00:00
|
|
|
_activeInitialized = true;
|
2019-09-29 21:24:37 +00:00
|
|
|
|
|
|
|
if (_activeBorder->getPadding().isValidRect())
|
|
|
|
setOffsets(_activeBorder->getPadding());
|
2016-06-02 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 11:03:46 +00:00
|
|
|
void MacWindowBorder::addInactiveBorder(TransparentSurface *source) {
|
2016-06-03 18:49:54 +00:00
|
|
|
assert(!_inactiveBorder);
|
2016-08-25 11:03:46 +00:00
|
|
|
_inactiveBorder = new NinePatchBitmap(source, true);
|
2016-06-03 18:49:54 +00:00
|
|
|
_inactiveInitialized = true;
|
2019-09-29 21:24:37 +00:00
|
|
|
|
|
|
|
if (!_inactiveBorder->getPadding().isValidRect())
|
|
|
|
setOffsets(_inactiveBorder->getPadding());
|
2016-06-02 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 10:16:08 +00:00
|
|
|
bool MacWindowBorder::hasOffsets() {
|
2019-09-29 21:24:37 +00:00
|
|
|
return _borderOffsets.isValidRect();
|
2016-07-29 10:16:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 08:27:30 +00:00
|
|
|
void MacWindowBorder::setOffsets(int left, int right, int top, int bottom) {
|
2019-09-29 21:24:37 +00:00
|
|
|
_borderOffsets.left = left;
|
|
|
|
_borderOffsets.right = right;
|
|
|
|
_borderOffsets.top = top;
|
|
|
|
_borderOffsets.bottom = bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacWindowBorder::setOffsets(Common::Rect &rect) {
|
|
|
|
_borderOffsets = rect;
|
2016-07-29 10:16:08 +00:00
|
|
|
}
|
|
|
|
|
2019-09-29 21:24:37 +00:00
|
|
|
Common::Rect &MacWindowBorder::getOffset() {
|
|
|
|
return _borderOffsets;
|
2016-07-29 10:16:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 17:02:32 +00:00
|
|
|
void MacWindowBorder::blitBorderInto(ManagedSurface &destination, bool active) {
|
|
|
|
|
|
|
|
TransparentSurface srf;
|
|
|
|
NinePatchBitmap *src = active ? _activeBorder : _inactiveBorder;
|
|
|
|
|
2019-09-29 15:28:50 +00:00
|
|
|
if ((active && !_activeInitialized) || (!active && !_inactiveInitialized)) {
|
|
|
|
warning("Attempt to blit unitialised border");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (destination.w == 0 || destination.h == 0) {
|
|
|
|
warning("Attempt to draw %d x %d window", destination.w, destination.h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-29 08:27:30 +00:00
|
|
|
srf.create(destination.w, destination.h, destination.format);
|
2019-09-29 15:28:50 +00:00
|
|
|
srf.fillRect(Common::Rect(srf.w, srf.h), kColorGreen2);
|
2016-07-29 08:27:30 +00:00
|
|
|
|
2019-09-29 15:40:33 +00:00
|
|
|
byte palette[kColorCount * 3];
|
2016-07-29 08:27:30 +00:00
|
|
|
g_system->getPaletteManager()->grabPalette(palette, 0, kColorCount);
|
2016-06-02 17:02:32 +00:00
|
|
|
|
2016-07-29 08:27:30 +00:00
|
|
|
src->blit(srf, 0, 0, srf.w, srf.h, palette, kColorCount);
|
|
|
|
destination.transBlitFrom(srf, kColorGreen2);
|
2016-08-25 11:21:42 +00:00
|
|
|
srf.free();
|
2016-06-02 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Graphics
|