LAB: Simplify the gadget enabling/disabling code

This commit is contained in:
Filippos Karapetis 2015-12-08 16:50:44 +02:00 committed by Willem Jan Palenstijn
parent 2d0fab7f4c
commit 0b2bf45a09
3 changed files with 7 additions and 10 deletions

View File

@ -63,9 +63,8 @@ Gadget *EventManager::checkGadgetHit(GadgetList *gadgetList, Common::Point pos)
for (GadgetList::iterator gadgetItr = gadgetList->begin(); gadgetItr != gadgetList->end(); ++gadgetItr) {
Gadget *gadget = *gadgetItr;
Common::Rect gadgetRect(gadget->x, gadget->y, gadget->x + gadget->_image->_width - 1, gadget->y + gadget->_image->_height - 1);
bool gadgetIsEnabled = !(gadget->_flags & GADGETOFF);
if (gadgetRect.contains(pos) && gadgetIsEnabled) {
if (gadgetRect.contains(pos) && gadget->isEnabled) {
if (_vm->_isHiRes) {
_hitGadget = gadget;
} else {

View File

@ -48,6 +48,7 @@ Gadget *createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *im, Image
gptr->_keyEquiv = key;
gptr->_image = im;
gptr->_altImage = imalt;
gptr->isEnabled = true;
return gptr;
} else
@ -69,7 +70,7 @@ void drawGadgetList(GadgetList *gadgetList) {
for (GadgetList::iterator gadget = gadgetList->begin(); gadget != gadgetList->end(); ++gadget) {
(*gadget)->_image->drawImage((*gadget)->x, (*gadget)->y);
if (GADGETOFF & (*gadget)->_flags)
if (!(*gadget)->isEnabled)
disableGadget((*gadget), 1);
}
}
@ -79,7 +80,7 @@ void drawGadgetList(GadgetList *gadgetList) {
*/
void disableGadget(Gadget *curgad, uint16 pencolor) {
g_lab->_graphics->overlayRect(pencolor, curgad->x, curgad->y, curgad->x + curgad->_image->_width - 1, curgad->y + curgad->_image->_height - 1);
curgad->_flags |= GADGETOFF;
curgad->isEnabled = false;
}
/**
@ -87,7 +88,7 @@ void disableGadget(Gadget *curgad, uint16 pencolor) {
*/
void enableGadget(Gadget *curgad) {
curgad->_image->drawImage(curgad->x, curgad->y);
curgad->_flags &= !(GADGETOFF);
curgad->isEnabled = true;
}
/**
@ -114,7 +115,7 @@ Gadget *LabEngine::checkNumGadgetHit(GadgetList *gadgetList, uint16 key) {
Gadget *gadget = *gadgetItr;
if ((gkey - 1 == gadget->_gadgetID || (gkey == 0 && gadget->_gadgetID == 9) ||
(gadget->_keyEquiv != 0 && makeGadgetKeyEquiv(key) == gadget->_keyEquiv))
&& !(GADGETOFF & gadget->_flags)) {
&& gadget->isEnabled) {
_event->mouseHide();
gadget->_altImage->drawImage(gadget->x, gadget->y);
_event->mouseShow();

View File

@ -46,13 +46,10 @@ struct IntuiMessage {
struct Gadget {
uint16 x, y, _gadgetID;
uint16 _keyEquiv; // if not zero, a key that activates gadget
uint32 _flags;
bool isEnabled;
Image *_image, *_altImage;
};
// Defines for the GadgetFlags portion
#define GADGETOFF 0x01
typedef Common::List<Gadget *> GadgetList;
// Defines for the Class variable in IntuiMessage