SCI: Add support for enabling/disabling Mac icon bar images
This commit is contained in:
parent
257bae431a
commit
0933325b7c
3 changed files with 75 additions and 10 deletions
|
@ -366,8 +366,6 @@ reg_t kIconBar(EngineState *s, int argc, reg_t *argv) {
|
||||||
for (int i = 0; i < argv[1].toUint16(); i++)
|
for (int i = 0; i < argv[1].toUint16(); i++)
|
||||||
g_sci->_gfxMacIconBar->addIcon(argv[i + 2]);
|
g_sci->_gfxMacIconBar->addIcon(argv[i + 2]);
|
||||||
|
|
||||||
g_sci->_gfxMacIconBar->drawIcons();
|
|
||||||
|
|
||||||
// TODO: Should return icon bar handle
|
// TODO: Should return icon bar handle
|
||||||
// Said handle is then used by DisposeIconBar
|
// Said handle is then used by DisposeIconBar
|
||||||
break;
|
break;
|
||||||
|
@ -375,10 +373,12 @@ reg_t kIconBar(EngineState *s, int argc, reg_t *argv) {
|
||||||
warning("kIconBar(Dispose)");
|
warning("kIconBar(Dispose)");
|
||||||
break;
|
break;
|
||||||
case 2: // EnableIconBar (0xffff = all)
|
case 2: // EnableIconBar (0xffff = all)
|
||||||
warning("kIconBar(Enable, %d)", argv[1].toUint16());
|
debug(0, "kIconBar(Enable, %d)", argv[1].toUint16());
|
||||||
|
g_sci->_gfxMacIconBar->setIconEnabled(argv[1].toUint16(), true);
|
||||||
break;
|
break;
|
||||||
case 3: // DisableIconBar (0xffff = all)
|
case 3: // DisableIconBar (0xffff = all)
|
||||||
warning("kIconBar(Disable, %d)", argv[1].toUint16());
|
debug(0, "kIconBar(Disable, %d)", argv[1].toUint16());
|
||||||
|
g_sci->_gfxMacIconBar->setIconEnabled(argv[1].toUint16(), false);
|
||||||
break;
|
break;
|
||||||
case 4: // SetIconBarIcon
|
case 4: // SetIconBarIcon
|
||||||
warning("kIconBar(SetIcon, %d, %d)", argv[1].toUint16(), argv[2].toUint16());
|
warning("kIconBar(SetIcon, %d, %d)", argv[1].toUint16(), argv[2].toUint16());
|
||||||
|
@ -387,6 +387,8 @@ reg_t kIconBar(EngineState *s, int argc, reg_t *argv) {
|
||||||
error("Unknown kIconBar(%d)", argv[0].toUint16());
|
error("Unknown kIconBar(%d)", argv[0].toUint16());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_sci->_gfxMacIconBar->drawIcons();
|
||||||
|
|
||||||
return NULL_REG;
|
return NULL_REG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ void GfxMacIconBar::addIcon(reg_t obj) {
|
||||||
item.object = obj;
|
item.object = obj;
|
||||||
item.nonSelectedImage = createImage(iconIndex, false);
|
item.nonSelectedImage = createImage(iconIndex, false);
|
||||||
item.selectedImage = createImage(iconIndex, true);
|
item.selectedImage = createImage(iconIndex, true);
|
||||||
|
item.enabled = true;
|
||||||
|
|
||||||
// Start after the main viewing window and add a two pixel buffer
|
// Start after the main viewing window and add a two pixel buffer
|
||||||
uint16 y = g_sci->_gfxScreen->getHeight() + 2;
|
uint16 y = g_sci->_gfxScreen->getHeight() + 2;
|
||||||
|
@ -80,13 +81,67 @@ void GfxMacIconBar::addIcon(reg_t obj) {
|
||||||
void GfxMacIconBar::drawIcons() {
|
void GfxMacIconBar::drawIcons() {
|
||||||
// Draw the icons to the bottom of the screen
|
// Draw the icons to the bottom of the screen
|
||||||
|
|
||||||
for (uint32 i = 0; i < _iconBarItems.size(); i++) {
|
for (uint32 i = 0; i < _iconBarItems.size(); i++)
|
||||||
Graphics::Surface *surface = _iconBarItems[i].nonSelectedImage;
|
redrawIcon(i);
|
||||||
|
}
|
||||||
|
|
||||||
if (surface) {
|
void GfxMacIconBar::redrawIcon(uint16 iconIndex) {
|
||||||
g_system->copyRectToScreen((byte *)surface->pixels, surface->pitch, _iconBarItems[i].rect.left,
|
if (iconIndex >= _iconBarItems.size())
|
||||||
_iconBarItems[i].rect.top, _iconBarItems[i].rect.width(), _iconBarItems[i].rect.height());
|
return;
|
||||||
}
|
|
||||||
|
if (_iconBarItems[iconIndex].enabled)
|
||||||
|
drawEnabledImage(_iconBarItems[iconIndex].nonSelectedImage, _iconBarItems[iconIndex].rect);
|
||||||
|
else
|
||||||
|
drawDisabledImage(_iconBarItems[iconIndex].nonSelectedImage, _iconBarItems[iconIndex].rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxMacIconBar::drawEnabledImage(Graphics::Surface *surface, const Common::Rect &rect) {
|
||||||
|
if (surface)
|
||||||
|
g_system->copyRectToScreen((byte *)surface->pixels, surface->pitch, rect.left, rect.top, rect.width(), rect.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxMacIconBar::drawDisabledImage(Graphics::Surface *surface, const Common::Rect &rect) {
|
||||||
|
if (!surface)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Add a black checkboard pattern to the image before copying it to the screen
|
||||||
|
|
||||||
|
Graphics::Surface newSurf;
|
||||||
|
newSurf.copyFrom(*surface);
|
||||||
|
|
||||||
|
for (int i = 0; i < newSurf.h; i++) {
|
||||||
|
int startX = rect.left & 3;
|
||||||
|
|
||||||
|
if ((i + rect.top) & 1)
|
||||||
|
startX += 2;
|
||||||
|
|
||||||
|
for (int j = startX; j < newSurf.w; j += 4)
|
||||||
|
*((byte *)newSurf.getBasePtr(j, i)) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_system->copyRectToScreen((byte *)newSurf.pixels, newSurf.pitch, rect.left, rect.top, rect.width(), rect.height());
|
||||||
|
newSurf.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxMacIconBar::drawSelectedImage(uint16 iconIndex) {
|
||||||
|
assert(iconIndex <= _iconBarItems.size());
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GfxMacIconBar::isIconEnabled(uint16 iconIndex) const {
|
||||||
|
if (iconIndex >= _iconBarItems.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return _iconBarItems[iconIndex].enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxMacIconBar::setIconEnabled(uint16 iconIndex, bool enabled) {
|
||||||
|
if (iconIndex == 0xffff) {
|
||||||
|
for (uint32 i = 0; i < _iconBarItems.size(); i++)
|
||||||
|
_iconBarItems[i].enabled = enabled;
|
||||||
|
} else if (iconIndex < _iconBarItems.size()) {
|
||||||
|
_iconBarItems[iconIndex].enabled = enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,10 @@ public:
|
||||||
|
|
||||||
void addIcon(reg_t obj);
|
void addIcon(reg_t obj);
|
||||||
void drawIcons();
|
void drawIcons();
|
||||||
|
void redrawIcon(uint16 index);
|
||||||
|
void drawSelectedImage(uint16 index);
|
||||||
|
bool isIconEnabled(uint16 index) const;
|
||||||
|
void setIconEnabled(uint16 index, bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct IconBarItem {
|
struct IconBarItem {
|
||||||
|
@ -50,6 +54,7 @@ private:
|
||||||
Graphics::Surface *nonSelectedImage;
|
Graphics::Surface *nonSelectedImage;
|
||||||
Graphics::Surface *selectedImage;
|
Graphics::Surface *selectedImage;
|
||||||
Common::Rect rect;
|
Common::Rect rect;
|
||||||
|
bool enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
Common::Array<IconBarItem> _iconBarItems;
|
Common::Array<IconBarItem> _iconBarItems;
|
||||||
|
@ -57,6 +62,9 @@ private:
|
||||||
|
|
||||||
Graphics::Surface *createImage(uint32 iconIndex, bool isSelected);
|
Graphics::Surface *createImage(uint32 iconIndex, bool isSelected);
|
||||||
void remapColors(Graphics::Surface *surf, byte *palette);
|
void remapColors(Graphics::Surface *surf, byte *palette);
|
||||||
|
|
||||||
|
void drawEnabledImage(Graphics::Surface *surface, const Common::Rect &rect);
|
||||||
|
void drawDisabledImage(Graphics::Surface *surface, const Common::Rect &rect);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sci
|
} // End of namespace Sci
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue