Ticket #4811: labels.patch

File labels.patch, 11.0 KB (added by peres, 14 years ago)

A rough solution to the problem

  • graphics.h

     
    444444        void unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor);
    445445
    446446        // labels
    447         void showFloatingLabel(uint label);
     447        void showFloatingLabel(GfxObj *label);
    448448        void hideFloatingLabel();
    449449
    450         uint renderFloatingLabel(Font *font, char *text);
    451         uint createLabel(Font *font, const char *text, byte color);
    452         void showLabel(uint id, int16 x, int16 y);
    453         void hideLabel(uint id);
     450        GfxObj *renderFloatingLabel(Font *font, char *text);
     451        GfxObj *createLabel(Font *font, const char *text, byte color);
     452        void showLabel(GfxObj *label, int16 x, int16 y);
     453        void hideLabel(GfxObj *label);
    454454        void freeLabels();
     455        void unregisterLabel(GfxObj *label);
    455456
    456457        // dialogue handling
    457458        GfxObj* registerBalloon(Frames *frames, const char *text);
     
    528529        void                            scroll();
    529530        #define NO_FLOATING_LABEL       1000
    530531
     532        struct Label {
     533                Common::String _text;
     534                int  _x, _y;
     535                int color;
     536                bool _floating;
     537        };
     538
    531539        GfxObjArray     _labels;
    532540        GfxObjArray _balloons;
    533541        GfxObjArray     _items;
    534542
    535         uint _floatingLabel;
     543        GfxObj *_floatingLabel;
    536544
    537545        // overlay mode enables drawing of graphics with automatic screen-to-game coordinate translation
    538546        bool                            _overlayMode;
  • parallaction.h

     
    547547        uint            _subtitleLipSync;
    548548#endif
    549549        int                     _subtitleY;
    550         int                     _subtitle[2];
     550        GfxObj          *_subtitle[2];
    551551        ZonePtr         _activeZone2;
    552552        uint32          _zoneFlags[NUM_LOCATIONS][NUM_ZONES];
    553553
  • parallaction_br.cpp

     
    8787
    8888        _part = -1;
    8989
    90         _subtitle[0] = -1;
    91         _subtitle[1] = -1;
     90        _subtitle[0] = 0;
     91        _subtitle[1] = 0;
    9292
    9393        memset(_zoneFlags, 0, sizeof(_zoneFlags));
    9494
     
    226226void Parallaction_br::freeLocation(bool removeAll) {
    227227        // free open location stuff
    228228        clearSubtitles();
    229         _subtitle[0] = _subtitle[1] = -1;
     229        _subtitle[0] = _subtitle[1] = 0;
    230230
    231231        _localFlagNames->clear();
    232232
  • objects.h

     
    272272
    273273        uint32                  _type;
    274274        uint32                  _flags;
    275         uint                    _label;
     275        GfxObj                  *_label;
    276276
    277277        TypeData                u;
    278278        CommandList             _commands;
  • graphics.cpp

     
    524524        surf.fillRect(Common::Rect(w,h), LABEL_TRANSPARENT_COLOR);
    525525}
    526526
    527 uint Gfx::renderFloatingLabel(Font *font, char *text) {
     527GfxObj *Gfx::renderFloatingLabel(Font *font, char *text) {
    528528
    529529        Graphics::Surface *cnv = new Graphics::Surface;
    530530
     
    555555        obj->transparentKey = LABEL_TRANSPARENT_COLOR;
    556556        obj->layer = LAYER_FOREGROUND;
    557557
    558         uint id = _labels.size();
    559         _labels.insert_at(id, obj);
    560 
    561         return id;
     558        return obj;
    562559}
    563560
    564 void Gfx::showFloatingLabel(uint label) {
    565         assert(label < _labels.size());
    566 
     561void Gfx::showFloatingLabel(GfxObj *label) {
    567562        hideFloatingLabel();
    568563
    569         _labels[label]->x = -1000;
    570         _labels[label]->y = -1000;
    571         _labels[label]->setFlags(kGfxObjVisible);
    572 
    573         _floatingLabel = label;
     564        if (label) {
     565                label->x = -1000;
     566                label->y = -1000;
     567                label->setFlags(kGfxObjVisible);
     568       
     569                _floatingLabel = label;
     570                _labels.push_back(label);
     571        }
    574572}
    575573
    576574void Gfx::hideFloatingLabel() {
    577         if (_floatingLabel != NO_FLOATING_LABEL) {
    578                 _labels[_floatingLabel]->clearFlags(kGfxObjVisible);
     575        if (_floatingLabel != 0) {
     576                _floatingLabel->clearFlags(kGfxObjVisible);
    579577        }
    580         _floatingLabel = NO_FLOATING_LABEL;
     578        _floatingLabel = 0;
    581579}
    582580
    583581
    584582void Gfx::updateFloatingLabel() {
    585         if (_floatingLabel == NO_FLOATING_LABEL) {
     583        if (_floatingLabel == 0) {
    586584                return;
    587585        }
    588586
     
    596594        } *traits;
    597595
    598596        Common::Rect r;
    599         _labels[_floatingLabel]->getRect(0, r);
     597        _floatingLabel->getRect(0, r);
    600598
    601599        if (_gameType == GType_Nippon) {
    602600                FloatingLabelTraits traits_NS = {
     
    619617        _vm->_input->getCursorPos(cursor);
    620618        Common::Point offset = (_vm->_input->_activeItem._id) ? traits->_offsetWithItem : traits->_offsetWithoutItem;
    621619
    622         _labels[_floatingLabel]->x = CLIP(cursor.x + offset.x, traits->_minX, traits->_maxX);
    623         _labels[_floatingLabel]->y = CLIP(cursor.y + offset.y, traits->_minY, traits->_maxY);
     620        _floatingLabel->x = CLIP(cursor.x + offset.x, traits->_minX, traits->_maxX);
     621        _floatingLabel->y = CLIP(cursor.y + offset.y, traits->_minY, traits->_maxY);
    624622}
    625623
    626624
    627625
    628626
    629 uint Gfx::createLabel(Font *font, const char *text, byte color) {
     627GfxObj *Gfx::createLabel(Font *font, const char *text, byte color) {
    630628        Graphics::Surface *cnv = new Graphics::Surface;
    631629
    632630        uint w, h;
     
    652650        obj->transparentKey = LABEL_TRANSPARENT_COLOR;
    653651        obj->layer = LAYER_FOREGROUND;
    654652
    655         int id = _labels.size();
     653        return obj;
     654}
    656655
    657         _labels.insert_at(id, obj);
     656void Gfx::showLabel(GfxObj *label, int16 x, int16 y) {
     657        if (!label) {
     658                return;
     659        }
    658660
    659         return id;
    660 }
     661        label->setFlags(kGfxObjVisible);
    661662
    662 void Gfx::showLabel(uint id, int16 x, int16 y) {
    663         assert(id < _labels.size());
    664         _labels[id]->setFlags(kGfxObjVisible);
    665 
    666663        Common::Rect r;
    667         _labels[id]->getRect(0, r);
     664        label->getRect(0, r);
    668665
    669666        if (x == CENTER_LABEL_HORIZONTAL) {
    670667                x = CLIP<int16>((_backgroundInfo->width - r.width()) / 2, 0, _backgroundInfo->width/2);
     
    674671                y = CLIP<int16>((_vm->_screenHeight - r.height()) / 2, 0, _vm->_screenHeight/2);
    675672        }
    676673
    677         _labels[id]->x = x;
    678         _labels[id]->y = y;
     674        label->x = x;
     675        label->y = y;
     676       
     677        _labels.push_back(label);
    679678}
    680679
    681 void Gfx::hideLabel(uint id) {
    682         assert(id < _labels.size());
    683         _labels[id]->clearFlags(kGfxObjVisible);
     680void Gfx::hideLabel(GfxObj *label) {
     681        label->clearFlags(kGfxObjVisible);
    684682}
    685683
    686684void Gfx::freeLabels() {
     685//      for (uint i = 0; i < _labels.size(); i++) {
     686//              delete _labels[i];
     687//      }
     688        _labels.clear();
     689        _floatingLabel = 0;
     690}
     691
     692void Gfx::unregisterLabel(GfxObj *label) {
     693        int toBeRemoved = -1;
    687694        for (uint i = 0; i < _labels.size(); i++) {
    688                 delete _labels[i];
     695                if (_labels[i] == label) {
     696                        toBeRemoved = i;
     697                }
    689698        }
    690         _labels.clear();
    691         _floatingLabel = NO_FLOATING_LABEL;
     699       
     700        if (toBeRemoved != -1) {
     701                _labels.remove_at(toBeRemoved);
     702        }
    692703}
    693704
    694705
     
    724735
    725736        setPalette(_palette);
    726737
    727         _floatingLabel = NO_FLOATING_LABEL;
     738        _floatingLabel = 0;
    728739
    729740        _backgroundInfo = 0;
    730741
  • exec_br.cpp

     
    9696                _subtitle[1] = _gfx->createLabel(_labelFont, s2, color);
    9797                _gfx->showLabel(_subtitle[1], CENTER_LABEL_HORIZONTAL, _subtitleY + 5 + _labelFont->height());
    9898        } else {
    99                 _subtitle[1] = -1;
     99                _subtitle[1] = 0;
    100100        }
    101101#if 0   // disabled because no references to lip sync has been found in the scripts
    102102        _subtitleLipSync = 0;
     
    104104}
    105105
    106106void Parallaction_br::clearSubtitles() {
    107         if (_subtitle[0] != -1) {
     107        if (_subtitle[0]) {
    108108                _gfx->hideLabel(_subtitle[0]);
    109109        }
    110110
    111         if (_subtitle[1] != -1) {
     111        if (_subtitle[1]) {
    112112                _gfx->hideLabel(_subtitle[1]);
    113113        }
    114114}
  • parallaction_ns.cpp

     
    355355
    356356        if (locname.hasSlide()) {
    357357                showSlide(locname.slide());
    358                 uint id = _gfx->createLabel(_menuFont, _location._slideText[0].c_str(), 1);
    359                 _gfx->showLabel(id, CENTER_LABEL_HORIZONTAL, 14);
     358                _gfx->showLabel(_gfx->createLabel(_menuFont, _location._slideText[0].c_str(), 1), CENTER_LABEL_HORIZONTAL, 14);
    360359                _gfx->updateScreen();
    361360
    362361                _input->waitForButtonEvent(kMouseLeftUp);
  • callables_ns.cpp

     
    409409
    410410        parseLocation("common");
    411411
    412         uint id[2];
    413         id[0] = _gfx->createLabel(_menuFont, _location._slideText[0].c_str(), 1);
    414         id[1] = _gfx->createLabel(_menuFont, _location._slideText[1].c_str(), 1);
     412        GfxObj *labels[2];
     413        labels[0] = _gfx->createLabel(_menuFont, _location._slideText[0].c_str(), 1);
     414        labels[1] = _gfx->createLabel(_menuFont, _location._slideText[1].c_str(), 1);
    415415
    416         _gfx->showLabel(id[0], CENTER_LABEL_HORIZONTAL, 38);
    417         _gfx->showLabel(id[1], CENTER_LABEL_HORIZONTAL, 58);
     416        _gfx->showLabel(labels[0], CENTER_LABEL_HORIZONTAL, 38);
     417        _gfx->showLabel(labels[1], CENTER_LABEL_HORIZONTAL, 58);
    418418
    419419        return;
    420420}
  • gui_ns.cpp

     
    175175                // user can choose language in this version
    176176                _vm->showSlide("lingua");
    177177
    178                 uint id = _vm->_gfx->createLabel(_vm->_introFont, "SELECT LANGUAGE", 1);
    179                 _vm->_gfx->showLabel(id, 60, 30);
     178                _vm->_gfx->showLabel(_vm->_gfx->createLabel(_vm->_introFont, "SELECT LANGUAGE", 1), 60, 30);
    180179
    181180                _vm->_input->setArrowCursor();
    182181        }
     
    201200        int _choice, _oldChoice;
    202201        Common::String _nextState[2];
    203202
    204         uint    _labels[2];
     203        GfxObj  *_labels[2];
    205204
    206205        Parallaction *_vm;
    207206
     
    321320                _vm->changeBackground("test");
    322321                _vm->_input->setMouseState(MOUSE_ENABLED_HIDE);
    323322
    324                 uint id[4];
     323                GfxObj *id[4];
    325324                id[0] = _vm->_gfx->createLabel(_vm->_menuFont, introMsg3[0], 1);
    326325                id[1] = _vm->_gfx->createLabel(_vm->_menuFont, introMsg3[1], 1);
    327326                id[2] = _vm->_gfx->createLabel(_vm->_menuFont, introMsg3[2], 1);
     
    402401        Graphics::Surface _block;
    403402        Graphics::Surface _emptySlots;
    404403
    405         uint    _labels[2];
     404        GfxObj  *_labels[2];
    406405        uint    _len;
    407406        uint32  _startTime;
    408407
     
    634633        }
    635634
    636635        void drawCurrentLabel() {
    637                 uint id[2];
     636                GfxObj *id[2];
    638637                id[0] = _vm->_gfx->createLabel(_vm->_menuFont, _credits[_current]._role, 1);
    639638                id[1] = _vm->_gfx->createLabel(_vm->_menuFont, _credits[_current]._name, 1);
    640639                _vm->_gfx->showLabel(id[0], CENTER_LABEL_HORIZONTAL, 80);
     
    713712
    714713                if (!_isDemo) {
    715714                        _vm->_soundManI->stopMusic();
    716                         int label = _vm->_gfx->createLabel(_vm->_menuFont, "CLICK MOUSE BUTTON TO START", 1);
    717                         _vm->_gfx->showLabel(label, CENTER_LABEL_HORIZONTAL, 80);
     715                        _vm->_gfx->showLabel(_vm->_gfx->createLabel(_vm->_menuFont, "CLICK MOUSE BUTTON TO START", 1), CENTER_LABEL_HORIZONTAL, 80);
    718716                }
    719717        }
    720718};
     
    763761                _vm->_input->setMouseState(MOUSE_DISABLED);
    764762
    765763                uint16 language = _vm->getInternLanguage();
    766                 uint id[4];
     764                GfxObj *id[4];
    767765                if (_allPartsComplete) {
    768766                        id[0] = _vm->_gfx->createLabel(_vm->_menuFont, endMsg4[language], 1);
    769767                        id[1] = _vm->_gfx->createLabel(_vm->_menuFont, endMsg5[language], 1);
  • objects.cpp

     
    204204}
    205205
    206206Zone::~Zone() {
     207        _vm->_gfx->unregisterLabel(_label);
     208        delete _label;
    207209}
    208210
    209211void Zone::translate(int16 x, int16 y) {