changeset 2308:8a62bd4d51e2

button for MMT_Menu
author Ritor1
date Mon, 17 Mar 2014 17:44:32 +0600
parents c099af734c48
children 9dbfeda280d7 4b052671da98
files MMT.cpp
diffstat 1 files changed, 71 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- 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; y<height; y++)
+    row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
 
+  png_read_image(png_ptr, row_pointers);
 
-        /* read file */
-        if (setjmp(png_jmpbuf(png_ptr)))
-                abort_("[read_png_file] Error during read_image");
+  fclose(fp);
 
-        row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
-        for (y=0; y<height; y++)
-                row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
-        unsigned __int16 * pl = (unsigned __int16 *)row_pointers;
-        png_read_image(png_ptr, row_pointers);
+  tex = new Texture;
+  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);
+  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; y<height; y++)
-	  {
-	    for (x=0; x<width; x++)
-		{
-		  if ( pl )
-		    tex->pPalette16[i] = Color16(LOBYTE(pl), BYTE1(pl), BYTE2(pl));
-		  i++;
-		  pl++;
-		}
-	  }
-	  return tex;
+  for (y=0; y<height; y++)
+  {
+    png_byte* row = row_pointers[y];
+    for (x=0; x<width; x++)
+    {
+      png_byte* ptr = &(row[x*4]);
+      //Log::Warning(L"Pixel at position [ %d - %d ] has RGBA values: %d - %d - %d - %d\n",
+      //                   x, y, ptr[0], ptr[1], ptr[2], ptr[3]);
+      png_byte tmp = ptr[2];
+      ptr[2] = ptr[0];
+      ptr[0] = ptr[3];
+      ptr[3] = 255 - tmp;
+      tex->pPalette16[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;