2016-07-31 10:43:49 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2016-09-03 12:46:38 +02: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 10:43:49 +02:00
|
|
|
|
2016-07-29 10:27:30 +02:00
|
|
|
#include "common/system.h"
|
|
|
|
|
2016-07-31 11:16:09 +02:00
|
|
|
#include "graphics/macgui/macwindowborder.h"
|
2016-07-29 10:27:30 +02:00
|
|
|
#include "graphics/macgui/macwindowmanager.h"
|
|
|
|
|
2016-06-02 19:02:32 +02:00
|
|
|
namespace Graphics {
|
|
|
|
|
2016-07-29 10:27:30 +02:00
|
|
|
using namespace Graphics::MacGUIConstants;
|
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
MacWindowBorder::MacWindowBorder() {
|
|
|
|
|
|
|
|
_borderInitialized = Common::Array<bool>(_borderTypeNum);
|
|
|
|
_border = Common::Array<NinePatchBitmap *>(_borderTypeNum);
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < _borderTypeNum; i++) {
|
|
|
|
_border[i] = nullptr;
|
|
|
|
_borderInitialized[i] = false;
|
|
|
|
}
|
2019-09-29 23:24:37 +02:00
|
|
|
|
2020-08-05 19:17:08 -04:00
|
|
|
_borderOffsets.left = -1;
|
|
|
|
_borderOffsets.right = -1;
|
|
|
|
_borderOffsets.top = -1;
|
|
|
|
_borderOffsets.bottom = -1;
|
|
|
|
_borderOffsets.titleTop = -1;
|
|
|
|
_borderOffsets.titleBottom = -1;
|
|
|
|
_borderOffsets.dark = false;
|
2016-06-02 19:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MacWindowBorder::~MacWindowBorder() {
|
2021-04-06 16:12:51 +08:00
|
|
|
for (uint32 i = 0; i < _borderTypeNum; i++) {
|
|
|
|
if (_border[i])
|
|
|
|
delete _border[i];
|
|
|
|
}
|
2016-06-03 20:49:54 +02:00
|
|
|
}
|
2016-07-29 12:14:19 +02:00
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
bool MacWindowBorder::hasBorder(uint32 flags) {
|
|
|
|
if (flags >= _borderTypeNum) {
|
|
|
|
warning("Accessing non-existed border type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return _borderInitialized[flags];
|
2016-06-02 19:02:32 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
void MacWindowBorder::addBorder(TransparentSurface *source, uint32 flags, int titlePos, int titleWidth) {
|
|
|
|
if (flags >= _borderTypeNum) {
|
|
|
|
warning("Accessing non-existed border type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_border[flags])
|
|
|
|
delete _border[flags];
|
2020-08-06 14:29:24 -04:00
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
_border[flags] = new NinePatchBitmap(source, true, titlePos, titleWidth);
|
|
|
|
_borderInitialized[flags] = true;
|
2019-09-29 23:24:37 +02:00
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
if (_border[flags]->getPadding().isValidRect())
|
|
|
|
setOffsets(_border[flags]->getPadding());
|
2016-06-02 19:02:32 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
void MacWindowBorder::modifyTitleWidth(uint32 flags, int titleWidth) {
|
|
|
|
if (flags >= _borderTypeNum) {
|
|
|
|
warning("Accessing non-existed border type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_borderInitialized[flags]) {
|
|
|
|
warning("Trying to modify title width of an uninitialized border");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_border[flags]->modifyTitleWidth(titleWidth);
|
2021-04-05 20:35:43 +08:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:16:08 +02:00
|
|
|
bool MacWindowBorder::hasOffsets() {
|
2020-07-31 16:05:10 -04:00
|
|
|
return _borderOffsets.left > -1 && _borderOffsets.right > -1
|
|
|
|
&& _borderOffsets.top > -1 && _borderOffsets.bottom > -1;
|
2016-07-29 12:16:08 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 10:27:30 +02:00
|
|
|
void MacWindowBorder::setOffsets(int left, int right, int top, int bottom) {
|
2019-09-29 23:24:37 +02:00
|
|
|
_borderOffsets.left = left;
|
|
|
|
_borderOffsets.right = right;
|
|
|
|
_borderOffsets.top = top;
|
|
|
|
_borderOffsets.bottom = bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacWindowBorder::setOffsets(Common::Rect &rect) {
|
2020-08-05 19:17:08 -04:00
|
|
|
_borderOffsets.left = rect.left;
|
|
|
|
_borderOffsets.right = rect.right;
|
|
|
|
_borderOffsets.top = rect.top;
|
|
|
|
_borderOffsets.bottom = rect.bottom;
|
2016-07-29 12:16:08 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 19:17:08 -04:00
|
|
|
void MacWindowBorder::setOffsets(const BorderOffsets &offsets) {
|
|
|
|
_borderOffsets = offsets;
|
|
|
|
}
|
|
|
|
|
|
|
|
BorderOffsets &MacWindowBorder::getOffset() {
|
2019-09-29 23:24:37 +02:00
|
|
|
return _borderOffsets;
|
2016-07-29 12:16:08 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
void MacWindowBorder::setTitle(const Common::String& title, int width, MacWindowManager *wm) {
|
|
|
|
_title = title;
|
|
|
|
const Graphics::Font *font = wm->_fontMan->getFont(Graphics::MacFont(kMacFontChicago, 12));
|
|
|
|
int sidesWidth = getOffset().left + getOffset().right;
|
|
|
|
int titleWidth = font->getStringWidth(_title) + 10;
|
|
|
|
int maxWidth = width - sidesWidth - 7;
|
|
|
|
if (titleWidth > maxWidth)
|
|
|
|
titleWidth = maxWidth;
|
|
|
|
|
|
|
|
// if titleWidth is changed, then we modify it
|
|
|
|
// here, we change all the border that has title
|
|
|
|
for (uint32 i = 0; i < _borderTypeNum; i++) {
|
|
|
|
if (_borderInitialized[i] && (i & kWindowBorderTitle))
|
|
|
|
_border[i]->modifyTitleWidth(titleWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacWindowBorder::drawScrollBar(ManagedSurface *g, MacWindowManager *wm) {
|
|
|
|
// here, we first check the _scrollSize, and if it is negative, then we don't draw the scrollBar
|
|
|
|
if (_scrollSize < 0)
|
|
|
|
return;
|
|
|
|
int size = kBorderWidth;
|
|
|
|
int rx1 = 0 + g->w - size + 2;
|
|
|
|
int ry1 = 0 + size + _scrollPos + 1;
|
|
|
|
int rx2 = rx1 + size - 6;
|
|
|
|
int ry2 = ry1 + _scrollSize ;
|
|
|
|
Common::Rect rr(rx1, ry1, rx2, ry2);
|
|
|
|
|
|
|
|
MacPlotData pd(g, nullptr, &wm->getPatterns(), 1, 0, 0, 1, wm->_colorWhite, true);
|
|
|
|
Graphics::drawFilledRect(rr, wm->_colorWhite, wm->getDrawInvertPixel(), &pd);
|
|
|
|
|
|
|
|
// after drawing, we set the _scrollSize negative, to indicate no more drawing is needed
|
|
|
|
_scrollSize = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacWindowBorder::drawTitle(ManagedSurface *g, MacWindowManager *wm) {
|
|
|
|
const Graphics::Font *font = wm->_fontMan->getFont(Graphics::MacFont(kMacFontChicago, 12));
|
|
|
|
int width = g->w;
|
|
|
|
int titleColor = wm->_colorBlack;
|
|
|
|
int titleY = getOffset().titleTop;
|
|
|
|
int sidesWidth = getOffset().left + getOffset().right;
|
|
|
|
int titleWidth = font->getStringWidth(_title) + 10;
|
|
|
|
int yOff = wm->_fontMan->hasBuiltInFonts() ? 3 : 1;
|
|
|
|
int maxWidth = width - sidesWidth - 7;
|
|
|
|
if (titleWidth > maxWidth)
|
|
|
|
titleWidth = maxWidth;
|
|
|
|
|
|
|
|
font->drawString(g, _title, (width - titleWidth) / 2 + 5, titleY + yOff, titleWidth, titleColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacWindowBorder::blitBorderInto(ManagedSurface &destination, uint32 flags, MacWindowManager *wm) {
|
|
|
|
if (flags >= _borderTypeNum) {
|
|
|
|
warning("Accessing non-existed border type");
|
|
|
|
return;
|
|
|
|
}
|
2016-06-02 19:02:32 +02:00
|
|
|
|
|
|
|
TransparentSurface srf;
|
2021-04-06 16:12:51 +08:00
|
|
|
NinePatchBitmap *src = _border[flags];
|
2016-06-02 19:02:32 +02:00
|
|
|
|
2021-04-06 16:12:51 +08:00
|
|
|
if (!_borderInitialized[flags]) {
|
|
|
|
warning("Attempt to blit uninitialized border");
|
2019-09-29 17:28:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (destination.w == 0 || destination.h == 0) {
|
|
|
|
warning("Attempt to draw %d x %d window", destination.w, destination.h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-29 10:27:30 +02:00
|
|
|
srf.create(destination.w, destination.h, destination.format);
|
2020-08-07 16:33:41 -04:00
|
|
|
srf.fillRect(Common::Rect(srf.w, srf.h), wm->_colorGreen2);
|
2016-06-02 19:02:32 +02:00
|
|
|
|
2020-07-31 15:54:06 -04:00
|
|
|
src->blit(srf, 0, 0, srf.w, srf.h, NULL, 0, wm);
|
2020-08-07 16:33:41 -04:00
|
|
|
destination.transBlitFrom(srf, wm->_colorGreen2);
|
2016-08-25 13:21:42 +02:00
|
|
|
srf.free();
|
2021-04-06 16:12:51 +08:00
|
|
|
|
|
|
|
if (flags & kWindowBorderTitle)
|
|
|
|
drawTitle(&destination, wm);
|
|
|
|
|
|
|
|
if (flags & kWindowBorderScrollbar)
|
|
|
|
drawScrollBar(&destination, wm);
|
2016-06-02 19:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Graphics
|