Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MATTEO_BITMAP
- {
- private:
- static vector<MATTEO_BITMAP*> immagini_da_distruggere;
- public:
- enum TIPO
- {
- CARICA = 1 << 0,
- CREA = 1 << 1,
- VUOTO = 1 << 2,
- };
- static MATTEO_BITMAP* get_target_bitmap(); //restituisce il bitmap impostato su cui si sta disegnando
- MATTEO_BITMAP();
- MATTEO_BITMAP(int width, int height, int carica_crea, string percorso_file);
- ~MATTEO_BITMAP();
- void re_inizializza(int width, int height, int carica_crea, string percorso_file);
- void add_to_immagini_da_distruggere();
- const bool& operator==(MATTEO_BITMAP altro);
- ALLEGRO_BITMAP* immagine;
- int carica_crea;
- string percorso_file;
- int width;
- int height;
- };
- vector<MATTEO_BITMAP*> MATTEO_BITMAP::immagini_da_distruggere;
- const bool& MATTEO_BITMAP::operator==(MATTEO_BITMAP altro)
- {
- if (this->carica_crea == altro.carica_crea && this->height == altro.height && this->width == altro.width &&
- this->percorso_file == altro.percorso_file)
- {
- if (this->immagine == altro.immagine)
- return true;
- }
- return false;
- }
- void MATTEO_BITMAP::add_to_immagini_da_distruggere()
- {
- bool trovato = false;
- for (size_t i = 0; i < immagini_da_distruggere.size(); i++)
- if (this == immagini_da_distruggere[i])
- trovato = true;
- if(trovato==true)
- immagini_da_distruggere.push_back(this);
- }
- MATTEO_BITMAP* MATTEO_BITMAP::get_target_bitmap()
- {
- for (size_t i = 0; i < MATTEO_BITMAP::immagini_da_distruggere.size(); i++)
- if (MATTEO_BITMAP::immagini_da_distruggere[i]->immagine == al_get_target_bitmap())
- return MATTEO_BITMAP::immagini_da_distruggere[i];
- return nullptr;
- }
- MATTEO_BITMAP::MATTEO_BITMAP() {};
- MATTEO_BITMAP::MATTEO_BITMAP(int width, int height, int carica_crea, string percorso_file)
- {
- this->width = width;
- this->height = height;
- this->carica_crea = carica_crea;
- this->percorso_file = percorso_file;
- if (carica_crea == CARICA)
- {
- immagine = al_load_bitmap(percorso_file.c_str());
- this->height = al_get_bitmap_height(immagine);
- this->width = al_get_bitmap_width(immagine);
- }
- else if (carica_crea == MATTEO_BITMAP::CREA && width>0 && height>0)
- immagine = al_create_bitmap(width, height);
- };
- MATTEO_BITMAP::~MATTEO_BITMAP()
- {
- al_destroy_bitmap(immagine);
- immagine = nullptr;
- }
- void MATTEO_BITMAP::re_inizializza(int width, int height, int carica_crea, string percorso_file)
- {
- if (immagine != nullptr)
- {
- al_destroy_bitmap(immagine);
- immagine = nullptr;
- }
- this->carica_crea = carica_crea;
- if (carica_crea == CARICA)
- {
- this->percorso_file = percorso_file;
- immagine = al_load_bitmap(percorso_file.c_str());
- this->height = al_get_bitmap_height(immagine);
- this->width = al_get_bitmap_width(immagine);
- }
- else if (carica_crea == MATTEO_BITMAP::CREA)
- {
- al_create_bitmap(width, height);
- this->width = width;
- this->height = height;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement