From 263dae410a0236a34e98870f78c320222ca27d63 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 30 Dec 1997 16:08:02 +0000 Subject: [PATCH] Corretta gestione voci di menu lasciate vuote intenzionalmente Migliorato cacheing delle immagini usate come sfondo dei menu git-svn-id: svn://10.65.10.50/trunk@5834 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ba/ba0.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/ba/ba0.cpp b/ba/ba0.cpp index 3f3855278..e1af94b27 100755 --- a/ba/ba0.cpp +++ b/ba/ba0.cpp @@ -23,6 +23,22 @@ #include "ba0.h" #include "ba0100a.h" +/////////////////////////////////////////////////////////// +// TPriority_image +/////////////////////////////////////////////////////////// + +class TTimed_image : public TImage +{ + clock_t _last_time; + +public: + clock_t touch() { return _last_time = clock(); } + clock_t last_time() const { return _last_time; } + + TTimed_image(const char* name) : TImage(name) { touch(); } + virtual ~TTimed_image() { } +}; + /////////////////////////////////////////////////////////// // Picture Mask /////////////////////////////////////////////////////////// @@ -438,8 +454,9 @@ class TMenu : public TAssoc_array int _item; TStack _stack; - TAssoc_array _images; + TFilename _default_bmp; + TAssoc_array _images; TAssoc_array _modules; public: // TObject @@ -507,9 +524,10 @@ void TMenuitem::create(const char* t) _action << ".men"; menu().read(_action, _action); _type = '['; - if (_action.empty()) - _enabled = FALSE; } + + if (_action.empty()) + _enabled = FALSE; if (_enabled && is_program()) _enabled = menu().has_module(_action); @@ -675,7 +693,6 @@ void TSubmenu::read(TScanner& scanner) { bool disable = TRUE; TToken_string mod(line.mid(equal+1, -1), ','); -// for (const char* cod = mod.get(0); cod; cod = mod.get()) FOR_EACH_TOKEN(mod, cod) { const int code = atoi(cod); @@ -864,20 +881,46 @@ bool TMenu::perform() TImage& TMenu::image(const char* name) { - TImage* image = (TImage*)_images.objptr(name); + TTimed_image* image = (TTimed_image*)_images.objptr(name); if (image == NULL) { if (fexist(name)) { - image = new TImage(name); + if (_images.items() == 0) + _default_bmp = name; // Store default bitmap name + + image = new TTimed_image(name); image->convert_transparent_color(MASK_BACK_COLOR); _images.add(name, image); } else - image = (TImage*)_images.objptr("ba00.bmp"); + { + image = (TTimed_image*)_images.objptr(_default_bmp); + if (image == NULL) + fatal_box("Impossibile trovare l'immagine %s", (const char*)_default_bmp); + } + + if (_images.items() > 3) + { + TString worst_bmp; + clock_t worst_time = image->touch(); // Impedisco di cancellare la prossima + _images.restart(); + for (THash_object* o = _images.get_hashobj(); o; o = _images.get_hashobj()) + { + if (o->key() != _default_bmp) + { + TTimed_image& i = (TTimed_image&)o->obj(); + if (i.last_time() < worst_time) + { + worst_time = i.last_time(); + worst_bmp = o->key(); + } + } + } + _images.remove(worst_bmp); + } } - if (image == NULL) - fatal_box("Impossibile trovare l'immagine ba00.bmp"); + image->touch(); return *image; } @@ -886,10 +929,15 @@ void TMenu::reload_images() _images.restart(); for (THash_object* h = _images.get_hashobj(); h; h = _images.get_hashobj()) { - const char* name = h->key(); - TImage& i = (TImage&)h->obj(); - i.load(name); - i.convert_transparent_color(MASK_BACK_COLOR); + const TString& name = h->key(); + if (name == _default_bmp) + { + TImage& i = (TImage&)h->obj(); + i.load(name); + i.convert_transparent_color(MASK_BACK_COLOR); + } + else + _images.remove(name); } } @@ -1139,7 +1187,7 @@ int TMenu_application::do_level() { const TMenuitem& item = curr[i]; caption = item.caption(); - if (item.is_submenu() && caption.find("...") < 0) + if (item.is_submenu() && caption.right(3) != "...") caption << "..."; mask.add_static(-1, 0, caption, x+4, y);