@@ -45,7 +45,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor)
4545 wi::Resource res = wi::resourcemanager::Load (fileName);
4646 if (!res.IsValid ())
4747 return ;
48- iconResource.SetTexture (editor->CreateThumbnail (res.GetTexture (), 128 , 128 ));
48+ iconResource.SetTexture (editor->CreateThumbnail (res.GetTexture (), 128 , 128 , true ));
4949 iconName = fileName;
5050 iconButton.SetImage (iconResource);
5151 });
162162 if (iconResource.IsValid ())
163163 {
164164 wi::helper::saveTextureToFile (iconResource.GetTexture (), directory + " icon.png" );
165+ wi::helper::saveTextureToFile (iconResource.GetTexture (), directory + " icon.ico" );
165166 }
166167 if (thumbnailResource.IsValid ())
167168 {
@@ -260,41 +261,46 @@ end)
260261 uint32_t biClrImportant; // Important colors
261262 };
262263
263- const uint32_t pixelCount = tex.desc .width * tex.desc .height ;
264- const uint32_t rgbDataSize = pixelCount * 4 ; // 32-bit RGBA
265- const uint32_t maskSize = ((tex.desc .width + 7 ) / 8 ) * tex.desc .height ; // 1-bit mask, padded to byte
266- const uint32_t bmpInfoHeaderSize = sizeof (BITMAPINFOHEADER );
267- const uint32_t iconDirSize = sizeof (ICONDIR );
268- const uint32_t iconDirEntrySize = sizeof (ICONDIRENTRY );
269- const uint32_t imageDataSize = bmpInfoHeaderSize + rgbDataSize + maskSize;
270-
271- BITMAPINFOHEADER bmpHeader = {
272- bmpInfoHeaderSize, // Size of header
273- int32_t (tex.desc .width ), // Width
274- int32_t (tex.desc .height * 2 ), // Height (doubled for XOR + AND mask)
275- 1 , // Planes
276- 32 , // Bits per pixel
277- 0 , // No compression
278- rgbDataSize + maskSize, // Image size
279- 0 , // X pixels per meter
280- 0 , // Y pixels per meter
281- 0 , // Colors used
282- 0 // Important colors
283- };
284-
285- wi::vector<uint8_t > bmpvec (sizeof (bmpHeader));
286- std::memcpy (bmpvec.data (), &bmpHeader, sizeof (bmpHeader));
264+ const int resolutions[] = {128 ,64 ,32 };
287265
288- // searches for exact BMP header match:
289- auto it = std::search (exedata.begin (), exedata.end (), bmpvec.begin (), bmpvec.end ());
290- if (it != exedata.end ())
266+ for (int res : resolutions)
291267 {
292- wi::vector<uint8_t > iconfiledata;
293- if (wi::helper::saveTextureToMemoryFile (tex, " ico" , iconfiledata))
268+ const uint32_t pixelCount = res * res;
269+ const uint32_t rgbDataSize = pixelCount * 4 ; // 32-bit RGBA
270+ const uint32_t maskSize = ((res + 7 ) / 8 ) * res; // 1-bit mask, padded to byte
271+ const uint32_t bmpInfoHeaderSize = sizeof (BITMAPINFOHEADER );
272+ const uint32_t iconDirSize = sizeof (ICONDIR );
273+ const uint32_t iconDirEntrySize = sizeof (ICONDIRENTRY );
274+ const uint32_t imageDataSize = bmpInfoHeaderSize + rgbDataSize + maskSize;
275+
276+ BITMAPINFOHEADER bmpHeader = {
277+ bmpInfoHeaderSize, // Size of header
278+ int32_t (res), // Width
279+ int32_t (res * 2 ), // Height (doubled for XOR + AND mask)
280+ 1 , // Planes
281+ 32 , // Bits per pixel
282+ 0 , // No compression
283+ rgbDataSize + maskSize, // Image size
284+ 0 , // X pixels per meter
285+ 0 , // Y pixels per meter
286+ 0 , // Colors used
287+ 0 // Important colors
288+ };
289+
290+ wi::vector<uint8_t > bmpvec (sizeof (bmpHeader));
291+ std::memcpy (bmpvec.data (), &bmpHeader, sizeof (bmpHeader));
292+
293+ // searches for exact BMP header match:
294+ auto it = std::search (exedata.begin (), exedata.end (), bmpvec.begin (), bmpvec.end ());
295+ if (it != exedata.end ())
294296 {
295- // replace the BMP header and data part:
296- std::copy (iconfiledata.begin () + sizeof (ICONDIR ) + sizeof (ICONDIRENTRY ), iconfiledata.end (), it);
297- wilog (" \t Overwritten Win32 icon" );
297+ wi::vector<uint8_t > iconfiledata;
298+ if (wi::helper::saveTextureToMemoryFile (editor->CreateThumbnail (tex, res, res), " ico" , iconfiledata))
299+ {
300+ // replace the BMP header and data part:
301+ std::copy (iconfiledata.begin () + sizeof (ICONDIR ) + sizeof (ICONDIRENTRY ), iconfiledata.end (), it);
302+ wilog (" \t Overwritten Win32 icon at %d * %d resolution" , res, res);
303+ }
298304 }
299305 }
300306 }
0 commit comments