Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. class MATTEO_BITMAP
  2. {
  3. private:
  4.     static vector<MATTEO_BITMAP*> immagini_da_distruggere;
  5. public:
  6.     enum TIPO
  7.     {
  8.         CARICA = 1 << 0,
  9.         CREA = 1 << 1,
  10.         VUOTO = 1 << 2,
  11.     };
  12.     static MATTEO_BITMAP* get_target_bitmap(); //restituisce il bitmap impostato su cui si sta disegnando
  13.  
  14.     MATTEO_BITMAP();
  15.     MATTEO_BITMAP(int width, int height, int carica_crea, string percorso_file);
  16.     ~MATTEO_BITMAP();
  17.     void re_inizializza(int width, int height, int carica_crea, string percorso_file);
  18.     void add_to_immagini_da_distruggere();
  19.     const bool& operator==(MATTEO_BITMAP altro);
  20.     ALLEGRO_BITMAP* immagine;
  21.     int carica_crea;
  22.     string percorso_file;
  23.     int width;
  24.     int height;
  25. };
  26.  
  27. vector<MATTEO_BITMAP*> MATTEO_BITMAP::immagini_da_distruggere;
  28. const bool& MATTEO_BITMAP::operator==(MATTEO_BITMAP altro)
  29. {
  30.     if (this->carica_crea == altro.carica_crea && this->height == altro.height && this->width == altro.width &&
  31.         this->percorso_file == altro.percorso_file)
  32.     {
  33.         if (this->immagine == altro.immagine)
  34.             return true;
  35.     }
  36.     return false;
  37. }
  38. void MATTEO_BITMAP::add_to_immagini_da_distruggere()
  39. {
  40.     bool trovato = false;
  41.     for (size_t i = 0; i < immagini_da_distruggere.size(); i++)
  42.         if (this == immagini_da_distruggere[i])
  43.             trovato = true;
  44.     if(trovato==true)
  45.         immagini_da_distruggere.push_back(this);
  46. }
  47. MATTEO_BITMAP* MATTEO_BITMAP::get_target_bitmap()
  48. {
  49.     for (size_t i = 0; i < MATTEO_BITMAP::immagini_da_distruggere.size(); i++)
  50.         if (MATTEO_BITMAP::immagini_da_distruggere[i]->immagine == al_get_target_bitmap())
  51.             return MATTEO_BITMAP::immagini_da_distruggere[i];
  52.     return nullptr;
  53. }
  54. MATTEO_BITMAP::MATTEO_BITMAP() {};
  55. MATTEO_BITMAP::MATTEO_BITMAP(int width, int height, int carica_crea, string percorso_file)
  56. {
  57.     this->width = width;
  58.     this->height = height;
  59.     this->carica_crea = carica_crea;
  60.     this->percorso_file = percorso_file;
  61.     if (carica_crea == CARICA)
  62.     {
  63.         immagine = al_load_bitmap(percorso_file.c_str());
  64.         this->height = al_get_bitmap_height(immagine);
  65.         this->width = al_get_bitmap_width(immagine);
  66.     }
  67.     else if (carica_crea == MATTEO_BITMAP::CREA && width>0 && height>0)
  68.         immagine = al_create_bitmap(width, height);
  69. };
  70. MATTEO_BITMAP::~MATTEO_BITMAP()
  71. {
  72.     al_destroy_bitmap(immagine);
  73.     immagine = nullptr;
  74. }
  75. void MATTEO_BITMAP::re_inizializza(int width, int height, int carica_crea, string percorso_file)
  76. {
  77.     if (immagine != nullptr)
  78.     {
  79.         al_destroy_bitmap(immagine);
  80.         immagine = nullptr;
  81.     }
  82.     this->carica_crea = carica_crea;
  83.     if (carica_crea == CARICA)
  84.     {
  85.         this->percorso_file = percorso_file;
  86.         immagine = al_load_bitmap(percorso_file.c_str());
  87.         this->height = al_get_bitmap_height(immagine);
  88.         this->width = al_get_bitmap_width(immagine);
  89.     }
  90.     else if (carica_crea == MATTEO_BITMAP::CREA)
  91.     {
  92.         al_create_bitmap(width, height);
  93.         this->width = width;
  94.         this->height = height;
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement