1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/* ScummVM - Graphic Adventure Engine
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/system.h"
#include "graphics/macgui/macwindowmanager.h"
#include "graphics/macgui/macwidget.h"
namespace Graphics {
MacWidget::MacWidget(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, bool focusable, uint16 border, uint16 gutter, uint16 shadow, uint32 fgcolor, uint32 bgcolor) :
_focusable(focusable), _parent(parent), _border(border), _gutter(gutter), _shadow(shadow), _wm(wm) {
_contentIsDirty = true;
_priority = 0;
_dims.left = x;
_dims.right = x + w + (2 * border) + (2 * gutter) + shadow;
_dims.top = y;
_dims.bottom = y + h + (2 * border) + gutter + shadow;
_fgcolor = fgcolor;
_bgcolor = bgcolor;
if (parent)
parent->_children.push_back(this);
_composeSurface = new ManagedSurface(_dims.width(), _dims.height(), _wm->_pixelformat);
_composeSurface->clear(_bgcolor);
_active = false;
_editable = false;
}
MacWidget::~MacWidget() {
if (_parent)
_parent->removeWidget(this, false);
if (_wm)
_wm->clearWidgetRefs(this);
if (_composeSurface) {
_composeSurface->free();
delete _composeSurface;
}
}
void MacWidget::setActive(bool active) {
if (!_focusable)
return;
if (active == _active)
return;
_active = active;
}
bool MacWidget::draw(bool forceRedraw) {
_contentIsDirty = false;
return false;
}
bool MacWidget::draw(ManagedSurface *g, bool forceRedraw) {
_contentIsDirty = false;
return false;
}
void MacWidget::blit(ManagedSurface *g, Common::Rect &dest) {
g->transBlitFrom(*_composeSurface, _composeSurface->getBounds(), dest, _wm->_colorGreen2);
}
void MacWidget::setColors(uint32 fg, uint32 bg) {
_fgcolor = fg;
_bgcolor = bg;
_contentIsDirty = true;
}
bool MacWidget::processEvent(Common::Event &event) {
return false;
}
void MacWidget::removeWidget(MacWidget *child, bool del) {
if (_children.size() == 0)
return;
for (uint i = 0; i < _children.size(); i++) {
if (_children[i] == child) {
if (del)
delete _children[i];
_children.remove_at(i);
}
}
}
MacWidget *MacWidget::findEventHandler(Common::Event &event, int dx, int dy) {
switch (event.type) {
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
case Common::EVENT_MOUSEMOVE:
{
Common::Point pos;
pos = g_system->getEventManager()->getMousePos();
if (_dims.contains(pos.x - dx, pos.y - dy)) {
uint priority = 0;
MacWidget *widget = nullptr;
for (uint i = 0; i < _children.size(); i++) {
MacWidget *res = _children[i]->findEventHandler(event, dx + _dims.left, dy + _dims.top);
if (res && res->_priority > priority) {
priority = res->_priority;
widget = res;
}
}
return widget ? widget : this;
}
break;
}
case Common::EVENT_KEYDOWN:
break;
default:
return nullptr;
}
return nullptr;
}
Common::Point MacWidget::getAbsolutePos() {
if (!_parent)
return Common::Point(0, 0);
return Common::Point(_parent->_dims.left, _parent->_dims.top) + _parent->getAbsolutePos();
}
} // End of namespace Graphics
|