# HG changeset patch # User Ritor1 # Date 1395056672 -21600 # Node ID 8a62bd4d51e229f3653e47ce0a962b859687d1ff # Parent c099af734c4853b6db9de4d98f27f4ad99d452c4 button for MMT_Menu diff -r c099af734c48 -r 8a62bd4d51e2 MMT.cpp --- a/MMT.cpp Mon Mar 17 09:32:23 2014 +0600 +++ b/MMT.cpp Mon Mar 17 17:44:32 2014 +0600 @@ -72,7 +72,7 @@ abort(); } -Texture *ConvertPNG(const char *name) +Texture *LoadPNG(const char *name) { int x, y; int width, height; @@ -85,71 +85,82 @@ uint i = 0; Texture *tex; - char header[8]; // 8 is the maximum size that can be checked + char header[8]; // 8 is the maximum size that can be checked - /* open file and test for it being a png */ - FILE *fp = fopen(name, "rb"); - if (!fp) - Log::Warning(L"[read_png_file] File %s could not be opened for reading", name); - fread(header, 1, 8, fp); - //if (png_sig_cmp(header, 0, 8)) - //Log::Warning(L"[read_png_file] File %s is not recognized as a PNG file", pContainerName); - /* initialize stuff */ - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - - if (!png_ptr) - abort_("[read_png_file] png_create_read_struct failed"); + /* open file and test for it being a png */ + FILE *fp = fopen(name, "rb"); + if (!fp) + abort_("[read_png_file] File %s could not be opened for reading", name); + fread(header, 1, 8, fp); + if (png_sig_cmp((png_bytep)header, 0, 8)) + abort_("[read_png_file] File %s is not recognized as a PNG file", name); + /* initialize stuff */ + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - abort_("[read_png_file] png_create_info_struct failed"); + if (!png_ptr) + abort_("[read_png_file] png_create_read_struct failed"); + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + abort_("[read_png_file] png_create_info_struct failed"); - if (setjmp(png_jmpbuf(png_ptr))) - abort_("[read_png_file] Error during init_io"); + if (setjmp(png_jmpbuf(png_ptr))) + abort_("[read_png_file] Error during init_io"); - png_init_io(png_ptr, fp); - png_set_sig_bytes(png_ptr, 8); + png_init_io(png_ptr, fp); + png_set_sig_bytes(png_ptr, 8); - png_read_info(png_ptr, info_ptr); + png_read_info(png_ptr, info_ptr); - width = png_get_image_width(png_ptr, info_ptr); - height = png_get_image_height(png_ptr, info_ptr); - color_type = png_get_color_type(png_ptr, info_ptr); - bit_depth = png_get_bit_depth(png_ptr, info_ptr); + width = png_get_image_width(png_ptr, info_ptr); + height = png_get_image_height(png_ptr, info_ptr); + color_type = png_get_color_type(png_ptr, info_ptr); + bit_depth = png_get_bit_depth(png_ptr, info_ptr); + + number_of_passes = png_set_interlace_handling(png_ptr); + png_read_update_info(png_ptr, info_ptr); - number_of_passes = png_set_interlace_handling(png_ptr); - png_read_update_info(png_ptr, info_ptr); + /* read file */ + if (setjmp(png_jmpbuf(png_ptr))) + abort_("[read_png_file] Error during read_image"); + row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height); + for (y=0; yuTextureHeight = height; + tex->uTextureWidth = width; + tex->uSizeOfMaxLevelOfDetail = png_get_rowbytes(png_ptr, info_ptr); + tex->uTextureSize = png_get_rowbytes(png_ptr, info_ptr); + tex->uDecompressedSize = png_get_rowbytes(png_ptr, info_ptr); + tex->pPalette16 = (unsigned __int16 *) malloc(sizeof(unsigned __int16) * width * height); + tex->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *) malloc(sizeof(unsigned __int8) * width * height); - fclose(fp); - tex = pIcons_LOD->GetTexture(pIcons_LOD->FindTextureByName("Pending"));//не знаю как зачистить - tex->uTextureHeight = height; - tex->uTextureWidth = width; - tex->uSizeOfMaxLevelOfDetail = png_get_rowbytes(png_ptr, info_ptr); - tex->uTextureSize = png_get_rowbytes(png_ptr, info_ptr); - tex->uDecompressedSize = png_get_rowbytes(png_ptr, info_ptr); - - for (y=0; ypPalette16[i] = Color16(LOBYTE(pl), BYTE1(pl), BYTE2(pl)); - i++; - pl++; - } - } - return tex; + for (y=0; ypPalette16[i] = Color16(ptr[0], ptr[1], ptr[2]); + tex->pLevelOfDetail0_prolly_alpha_mask[i] = ptr[3]; + i++; + } + } + //Ritor1: temporarily stopped, needed change RGBTexture structure/Пока приостановлено в связи с необходимостью внести изменения в структуру(создать)RGBTexture + /*for (int i = 0; i < width * height; ++i) + tex->pPalette16[i] = 0x7FF; + memset(tex->pLevelOfDetail0_prolly_alpha_mask, 1, sizeof(unsigned __int8) * width * height);*/ + return tex; } void MMT_MainMenu_Loop() @@ -175,10 +186,10 @@ pIcons_LOD->_inlined_sub2(); pWindow_MMT_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0); - Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); + //Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png"); - //Texture* MMT_MM6 = ConvertPNG(pContainerName); + Texture* MMT_MM6 = LoadPNG(pContainerName); Texture* MMT_MM7 = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE); @@ -186,7 +197,7 @@ Texture* MMT_Continue = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE); Texture* MMT_Exit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE); - pMMT_MainMenu_BtnMM6 = pWindow_MMT_MainMenu->CreateButton((window->GetWidth() / 4) - 100, window->GetHeight() / 4, MMT_MM6->uTextureWidth, MMT_MM6->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM6, 0, 0, "", MMT_MM6, 0); + pMMT_MainMenu_BtnMM6 = pWindow_MMT_MainMenu->CreateButton(0, 0, MMT_MM6->uTextureWidth, MMT_MM6->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM6, 0, 0, "", MMT_MM6, 0); pMMT_MainMenu_BtnMM7 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() / 4, MMT_MM7->uTextureWidth, MMT_MM7->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM7, 1, 0, "", MMT_MM7, 0); pMMT_MainMenu_BtnMM8 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_MM8->uTextureWidth, MMT_MM8->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM8, 2, 0, "", MMT_MM8, 0); pMMT_MainMenu_BtnContinue = pWindow_MMT_MainMenu->CreateButton((window->GetWidth() / 4) - 100, window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_Continue->uTextureWidth, MMT_Continue->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_Continue, 3, 0, "", MMT_Continue, 0); @@ -237,8 +248,8 @@ { case 0: pTexture = MMT_MM6; - pX = (window->GetWidth() / 4) - 100; - pY = window->GetHeight() / 4; + pX = 0; + pY = 0; break; case 1: pTexture = MMT_MM7;