Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////
- /// \file graphics_skin_manager.cpp
- /// \author Sergey Zubkov <seZubkov@gmail.com>
- /// \date 04/05/2010
- /// Copyright
- ////////////////////////////////////////////////////////////////////////////////
- #include "graphics_skin_manager.h"
- #include "graphics_interfaces.h"
- #include <windows.h>
- //! Для распаковки скинов.
- #include <zlib/unzip.h>
- #include "graphics_skin_parser.h"
- namespace est_api
- {
- namespace g_interface
- {
- std::vector<std::wstring> skin_manager::get_list_skins()
- {
- std::vector<std::wstring> list_skin;
- //
- WIN32_FIND_DATA find_data;
- HANDLE h_file_find =
- ::FindFirstFile( (this->skin_path_ + _Text("*.*")).c_str(), &find_data );
- if ( h_file_find == INVALID_HANDLE_VALUE )
- {
- return list_skin;
- }
- // Перебираем все файлы.
- do
- {
- if ( wcsstr(find_data.cFileName, skin_file_extention.c_str()) != NULL )
- {
- list_skin.push_back(find_data.cFileName);
- //
- continue;
- }
- }
- while ( ::FindNextFile(h_file_find, &find_data) == TRUE );
- //
- FindClose(h_file_find);
- //
- return list_skin;
- }
- bool skin_manager::set_skin_directory(const std::wstring & skin_path)
- {
- this->skin_path_ = skin_path;
- // Проверка на существование директории.
- return true;
- }
- bool skin_manager::load_skin(const std::wstring & skin_name)
- {
- unsigned long file_size = 0; char * file_buff = NULL;
- this->read_file_from_skin(
- L"\\zip_test.zip", L"black_skin_.json", file_size, (void**)&file_buff);
- //
- return false;
- }
- bool skin_manager::read_file_from_skin(
- const std::wstring & skin_file_name, const std::wstring & file_name,
- unsigned long & file_size, void ** buffer
- )
- {
- // Открываем Zip - архив со скином.
- HZIP zip_h_file = OpenZip(skin_file_name.c_str(), NULL);
- // Не смогли открыть архив, выходим.
- if ( zip_h_file == NULL )
- {
- return false;
- }
- int index_item = 0; ZIPENTRY ze;
- // Ищем нужный файл.
- ZRESULT z_result = FindZipItem(
- zip_h_file, file_name.c_str(), true, &index_item, &ze);
- // Не нашли нужный файл в архиве.
- if ( z_result != ZR_OK )
- {
- return false;
- }
- // Выделяем память под файл.
- try
- {
- *buffer = (unsigned char *)new unsigned char [ze.unc_size];
- }
- catch(std::bad_alloc & e)
- {
- *buffer = NULL;
- //
- return false;
- }
- // Копируем файл в память.
- z_result = UnzipItem(zip_h_file, index_item, *buffer, ze.unc_size);
- // Зкарываем архив.
- CloseZip(zip_h_file);
- return true;
- }
- const std::vector<element_rectangle> & skin_converter::grid_to_rectangle(
- const std::vector<element_grid> &el_grid, const gr_rect & rect
- )
- {
- std::vector<element_rectangle> els_rect;
- skin_converter::type_alignment t_alig = none;
- if (el_grid.begin() != el_grid.end())
- {
- if ( el_grid.front().get_size().h_ != NULL || el_grid.front().get_size().h_p_ != NULL )
- {
- t_alig = skin_converter::horizontal;
- }
- else
- {
- t_alig = skin_converter::vertical;
- }
- }
- gr_rect el_region = rect;
- long residue_x = el_region.right_ - el_region.left_;
- long residue_y = el_region.bottom_ - el_region.top_;
- // Фиксированные значения сетки.
- for ( std::vector<element_grid>::const_iterator i = el_grid.begin();
- i != el_grid.end(); ++i )
- {
- if ( t_alig == skin_converter::horizontal )
- {
- if ( i->get_size().w_ != NULL )
- {
- residue_x = residue_x - *i->get_size().w_;
- }
- //
- continue;
- }
- if ( t_alig == skin_converter::vertical )
- {
- if ( i->get_size().h_ != NULL )
- {
- residue_y = residue_y - *i->get_size().h_;
- }
- //
- continue;
- }
- }
- // Процентное задание областей.
- for ( std::vector<element_grid>::const_iterator i = el_grid.begin();
- i != el_grid.end(); ++i )
- {
- //
- if ( t_alig == skin_converter::horizontal )
- {
- if ( i->get_size().w_ != NULL )
- {
- gr_rect curent_rect;
- //
- curent_rect.left_ = el_region.left_;
- curent_rect.right_ = el_region.left_ + *i->get_size().w_;
- curent_rect.top_ = el_region.top_;
- curent_rect.bottom_ = el_region.bottom_;
- //
- grid_to_rectangle( i->get_elements_child(), curent_rect);
- //
- el_region.left_ += *i->get_size().w_;
- //
- continue;
- }
- if ( i->get_size().w_p_ != NULL )
- {
- //
- continue;
- }
- }
- if ( t_alig == skin_converter::vertical )
- {
- if ( i->get_size().h_ != NULL )
- {
- //
- continue;
- }
- if ( i->get_size().h_p_ != NULL )
- {
- //
- continue;
- }
- //
- continue;
- }
- }
- return el_rect;
- }
- } // namespace graphics
- } // namespace est_api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement