Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.78 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// \file graphics_skin_manager.cpp
  3. /// \author Sergey Zubkov <seZubkov@gmail.com>
  4. /// \date 04/05/2010
  5. /// Copyright
  6. ////////////////////////////////////////////////////////////////////////////////
  7. #include "graphics_skin_manager.h"
  8. #include "graphics_interfaces.h"
  9.  
  10. #include <windows.h>
  11. //! Для распаковки скинов.
  12. #include <zlib/unzip.h>
  13.  
  14. #include "graphics_skin_parser.h"
  15.  
  16. namespace est_api
  17. {
  18. namespace g_interface
  19. {
  20.     std::vector<std::wstring> skin_manager::get_list_skins()
  21.     {
  22.         std::vector<std::wstring> list_skin;
  23.         //
  24.         WIN32_FIND_DATA find_data;
  25.  
  26.         HANDLE h_file_find =
  27.             ::FindFirstFile( (this->skin_path_ + _Text("*.*")).c_str(), &find_data );
  28.        
  29.         if ( h_file_find == INVALID_HANDLE_VALUE )
  30.         {
  31.             return list_skin;
  32.         }
  33.  
  34.         // Перебираем все файлы.
  35.         do
  36.         {
  37.             if ( wcsstr(find_data.cFileName, skin_file_extention.c_str()) != NULL )
  38.             {
  39.                 list_skin.push_back(find_data.cFileName);
  40.                 //
  41.                 continue;
  42.             }
  43.         }
  44.         while ( ::FindNextFile(h_file_find, &find_data) == TRUE );
  45.        
  46.         //
  47.         FindClose(h_file_find);
  48.        
  49.         //
  50.         return list_skin;
  51.     }
  52.  
  53.     bool skin_manager::set_skin_directory(const std::wstring & skin_path)
  54.     {
  55.         this->skin_path_ = skin_path;
  56.  
  57.         // Проверка на существование директории.
  58.         return true;
  59.     }
  60.  
  61.     bool skin_manager::load_skin(const std::wstring & skin_name)
  62.     {
  63.         unsigned long file_size = 0; char * file_buff = NULL;
  64.  
  65.         this->read_file_from_skin(
  66.             L"\\zip_test.zip", L"black_skin_.json", file_size, (void**)&file_buff);
  67.         //
  68.         return false;
  69.     }
  70.  
  71.     bool skin_manager::read_file_from_skin(
  72.         const std::wstring & skin_file_name, const std::wstring & file_name,
  73.         unsigned long & file_size, void ** buffer
  74.         )
  75.     {
  76.         // Открываем Zip - архив со скином.
  77.         HZIP zip_h_file = OpenZip(skin_file_name.c_str(), NULL);
  78.  
  79.         // Не смогли открыть архив, выходим.
  80.         if ( zip_h_file == NULL )
  81.         {
  82.             return false;
  83.         }
  84.                
  85.         int index_item = 0; ZIPENTRY ze;
  86.         // Ищем нужный файл.
  87.         ZRESULT z_result = FindZipItem(
  88.             zip_h_file, file_name.c_str(), true, &index_item, &ze);
  89.  
  90.         // Не нашли нужный файл в архиве.
  91.         if ( z_result != ZR_OK )
  92.         {
  93.             return false;
  94.         }
  95.  
  96.         // Выделяем память под файл.
  97.         try
  98.         {
  99.             *buffer = (unsigned char *)new unsigned char [ze.unc_size];
  100.         }
  101.         catch(std::bad_alloc & e)
  102.         {
  103.             *buffer = NULL;
  104.             //
  105.             return false;
  106.         }
  107.  
  108.         // Копируем файл в память.
  109.         z_result = UnzipItem(zip_h_file, index_item, *buffer, ze.unc_size);
  110.  
  111.         // Зкарываем архив.
  112.         CloseZip(zip_h_file);
  113.  
  114.         return true;
  115.     }
  116.  
  117.     const std::vector<element_rectangle> & skin_converter::grid_to_rectangle(
  118.         const std::vector<element_grid> &el_grid,  const gr_rect & rect
  119.         )
  120.     {
  121.         std::vector<element_rectangle> els_rect;
  122.  
  123.         skin_converter::type_alignment t_alig = none;
  124.  
  125.         if (el_grid.begin() != el_grid.end())
  126.         {
  127.             if ( el_grid.front().get_size().h_ != NULL || el_grid.front().get_size().h_p_ != NULL )
  128.             {
  129.                 t_alig = skin_converter::horizontal;
  130.             }
  131.             else
  132.             {
  133.                 t_alig = skin_converter::vertical;
  134.             }
  135.         }
  136.  
  137.         gr_rect el_region = rect;
  138.  
  139.         long residue_x = el_region.right_ - el_region.left_;
  140.         long residue_y = el_region.bottom_ - el_region.top_;
  141.                
  142.         // Фиксированные значения сетки.
  143.         for ( std::vector<element_grid>::const_iterator i = el_grid.begin();
  144.               i != el_grid.end(); ++i )
  145.         {
  146.             if ( t_alig == skin_converter::horizontal )
  147.             {
  148.                 if ( i->get_size().w_ != NULL )
  149.                 {
  150.                     residue_x = residue_x - *i->get_size().w_;
  151.                 }
  152.                 //
  153.                 continue;
  154.             }
  155.             if ( t_alig == skin_converter::vertical )
  156.             {
  157.                 if ( i->get_size().h_ != NULL )
  158.                 {
  159.                     residue_y = residue_y - *i->get_size().h_;
  160.                 }
  161.                 //
  162.                 continue;
  163.             }
  164.         }
  165.  
  166.         // Процентное задание областей.
  167.         for ( std::vector<element_grid>::const_iterator i = el_grid.begin();
  168.               i != el_grid.end(); ++i )
  169.         {
  170.             //
  171.             if ( t_alig == skin_converter::horizontal )
  172.             {
  173.                 if ( i->get_size().w_ != NULL )
  174.                 {
  175.                     gr_rect curent_rect;
  176.                     //
  177.                     curent_rect.left_   = el_region.left_;
  178.                     curent_rect.right_  = el_region.left_ + *i->get_size().w_;
  179.                     curent_rect.top_    = el_region.top_;
  180.                     curent_rect.bottom_ = el_region.bottom_;
  181.                     //
  182.                     grid_to_rectangle( i->get_elements_child(), curent_rect);
  183.                     //
  184.                     el_region.left_ += *i->get_size().w_;
  185.                     //
  186.                     continue;
  187.                 }
  188.                 if ( i->get_size().w_p_ != NULL )
  189.                 {
  190.                     //
  191.                     continue;
  192.                 }
  193.                
  194.             }
  195.             if ( t_alig == skin_converter::vertical )
  196.             {
  197.                 if ( i->get_size().h_ != NULL )
  198.                 {
  199.                     //
  200.                     continue;
  201.                 }
  202.                 if ( i->get_size().h_p_ != NULL )
  203.                 {
  204.                     //
  205.                     continue;
  206.                 }
  207.                 //
  208.                 continue;
  209.             }
  210.         }
  211.                
  212.  
  213.  
  214.         return el_rect;
  215.     }
  216.  
  217. } // namespace graphics
  218. } // namespace est_api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement