private IImage GetIcon(bool large, String name, UIEngine engine, Theme theme) { String iconsPath = theme.ThemeFolder + "/icons/fsys/"; if (true == large) { return(engine.CreateImage(iconsPath + name + "_32x32")); } else { return(engine.CreateImage(iconsPath + name + "_16x16")); } }
/// <summary> /// Constructs cached font. /// </summary> /// <param name="engine">ui engine.</param> /// <param name="fontName">font name.</param> /// <param name="size">font size.</param> /// <param name="bold">is font bold.</param> /// <param name="italic">is font italic.</param> public WinFontCached(UIEngine engine, String fontName, int size, bool bold, bool italic) : this(fontName, size, bold, italic) { IXmlReader reader = engine.OpenXmlFile(cacheFolder + ToString() + ".xml"); if ((null != reader) && (null != reader.RootElement)) { this.letters = new WinLetterCached[256 * 256]; foreach (IXmlElement element in reader.RootElement.Elements) { int code = int.Parse(element.GetAttributeValue("code", "0")); int index = int.Parse(element.GetAttributeValue("index", "0")); int us = int.Parse(element.GetAttributeValue("us", "0")); int vs = int.Parse(element.GetAttributeValue("vs", "0")); int ue = int.Parse(element.GetAttributeValue("ue", "0")); int ve = int.Parse(element.GetAttributeValue("ve", "0")); int w = int.Parse(element.GetAttributeValue("width", "0")); int offX = int.Parse(element.GetAttributeValue("x", "0")); int offY = int.Parse(element.GetAttributeValue("y", "0")); if ((this.cachedImages.Count <= index) || (this.cachedImages[index] != null)) { IImage img = engine.CreateImage(cacheFolder + ToString() + "_" + index); if (this.cachedImages.Count == index) { this.cachedImages.Add(img); } else { this.cachedImages[index] = img; } } if (code >= 0 && code < cacheLetters) { this.letters[code] = new WinLetterCached(engine); this.letters[code].SetCachedData(this.cachedImages[index], us, vs, ue, ve, w, offX, offY); } } this.loaded = true; } }
private IImage GetIcon(bool large, String name, UIEngine engine, Theme theme) { String iconsPath = theme.ThemeFolder + "/icons/fsys/"; if (true == large) { return engine.CreateImage(iconsPath + name + "_32x32"); } else { return engine.CreateImage(iconsPath + name + "_16x16"); } }
private IImage GetIconWindows(IntPtr hIcon, UIEngine engine, bool large) { IconInfo iconInfo = new IconInfo(); if (true == GetIconInfo(hIcon, out iconInfo)) { BitmapInfo bitmapInfo = new BitmapInfo(); bitmapInfo.bmiHeader.biSize = Marshal.SizeOf(bitmapInfo); IntPtr dc = CreateCompatibleDC(IntPtr.Zero); int rez = GetDIBits(dc, iconInfo.hbmColor, 0, 0, null, ref bitmapInfo, Win32.DIB_RGB_COLORS); if (rez == 0) { DeleteDC(dc); return null; } byte[] pBuffer = new byte[bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 4]; byte[] buffer = new byte[bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 4]; rez = GetDIBits(dc, iconInfo.hbmColor, 0, (uint)bitmapInfo.bmiHeader.biHeight, buffer, ref bitmapInfo, Win32.DIB_RGB_COLORS); bool bAllAlphaTransparent = true; for (int y = 0; y < bitmapInfo.bmiHeader.biHeight; y++) { for (int x = 0; x < bitmapInfo.bmiHeader.biWidth; x++) { pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3]; if ((false != bAllAlphaTransparent) && (pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3] != 0x0)) { bAllAlphaTransparent = false; } } } rez = GetDIBits(dc, iconInfo.hbmMask, 0, 0, null, ref bitmapInfo, Win32.DIB_RGB_COLORS); if ((rez == 0) || (false == bAllAlphaTransparent)) { } else { byte[] colorBits = new byte[4096 * 4]; byte[] maskBits = new byte[4096 * 4]; BitmapInfo bmi = new BitmapInfo(); bmi.bmiHeader.biSize = Marshal.SizeOf(bmi); bmi.bmiHeader.biWidth = /*32;*/ bitmapInfo.bmiHeader.biWidth; bmi.bmiHeader.biHeight = /*32;*/ bitmapInfo.bmiHeader.biHeight; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = Win32.BI_RGB; // Extract the color bitmap int nBits = bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 32 / 8; GetDIBits(dc, iconInfo.hbmColor, 0, 32, colorBits, ref bmi, Win32.DIB_RGB_COLORS); // Extract the mask bitmap GetDIBits(dc, iconInfo.hbmMask, 0, 32, maskBits, ref bmi, Win32.DIB_RGB_COLORS); // Copy the mask alphas into the color bits for (int i = 0; i < nBits; i++) { colorBits[i + 0] = (byte)(colorBits[i + 0] | ((maskBits[i + 0] != 0) ? 0 : 0xff)); } memcpy(pBuffer, colorBits, bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 4); byte[] buffer1 = colorBits; for (int y = 0; y < bitmapInfo.bmiHeader.biHeight; y++) { for (int x = 0; x < bitmapInfo.bmiHeader.biWidth; x++) { pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3]; } } } DeleteDC(dc); DeleteObject(iconInfo.hbmColor); DeleteObject(iconInfo.hbmMask); IImage resultImage = engine.CreateImage("icon_" + hIcon.ToInt64() + "_" + large, bitmapInfo.bmiHeader.biWidth, bitmapInfo.bmiHeader.biHeight, pBuffer); return resultImage; } return null; }
private IImage GetIconWindows(IntPtr hIcon, UIEngine engine, bool large) { IconInfo iconInfo = new IconInfo(); if (true == GetIconInfo(hIcon, out iconInfo)) { BitmapInfo bitmapInfo = new BitmapInfo(); bitmapInfo.bmiHeader.biSize = Marshal.SizeOf(bitmapInfo); IntPtr dc = CreateCompatibleDC(IntPtr.Zero); int rez = GetDIBits(dc, iconInfo.hbmColor, 0, 0, null, ref bitmapInfo, Win32.DIB_RGB_COLORS); if (rez == 0) { DeleteDC(dc); return(null); } byte[] pBuffer = new byte[bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 4]; byte[] buffer = new byte[bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 4]; rez = GetDIBits(dc, iconInfo.hbmColor, 0, (uint)bitmapInfo.bmiHeader.biHeight, buffer, ref bitmapInfo, Win32.DIB_RGB_COLORS); bool bAllAlphaTransparent = true; for (int y = 0; y < bitmapInfo.bmiHeader.biHeight; y++) { for (int x = 0; x < bitmapInfo.bmiHeader.biWidth; x++) { pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3] = buffer[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3]; if ((false != bAllAlphaTransparent) && (pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3] != 0x0)) { bAllAlphaTransparent = false; } } } rez = GetDIBits(dc, iconInfo.hbmMask, 0, 0, null, ref bitmapInfo, Win32.DIB_RGB_COLORS); if ((rez == 0) || (false == bAllAlphaTransparent)) { } else { byte[] colorBits = new byte[4096 * 4]; byte[] maskBits = new byte[4096 * 4]; BitmapInfo bmi = new BitmapInfo(); bmi.bmiHeader.biSize = Marshal.SizeOf(bmi); bmi.bmiHeader.biWidth = /*32;*/ bitmapInfo.bmiHeader.biWidth; bmi.bmiHeader.biHeight = /*32;*/ bitmapInfo.bmiHeader.biHeight; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = Win32.BI_RGB; // Extract the color bitmap int nBits = bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 32 / 8; GetDIBits(dc, iconInfo.hbmColor, 0, 32, colorBits, ref bmi, Win32.DIB_RGB_COLORS); // Extract the mask bitmap GetDIBits(dc, iconInfo.hbmMask, 0, 32, maskBits, ref bmi, Win32.DIB_RGB_COLORS); // Copy the mask alphas into the color bits for (int i = 0; i < nBits; i++) { colorBits[i + 0] = (byte)(colorBits[i + 0] | ((maskBits[i + 0] != 0) ? 0 : 0xff)); } memcpy(pBuffer, colorBits, bitmapInfo.bmiHeader.biWidth * bitmapInfo.bmiHeader.biHeight * 4); byte[] buffer1 = colorBits; for (int y = 0; y < bitmapInfo.bmiHeader.biHeight; y++) { for (int x = 0; x < bitmapInfo.bmiHeader.biWidth; x++) { pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 1]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 2] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 0]; pBuffer[y * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3] = buffer1[(bitmapInfo.bmiHeader.biHeight - y - 1) * bitmapInfo.bmiHeader.biWidth * 4 + x * 4 + 3]; } } } DeleteDC(dc); DeleteObject(iconInfo.hbmColor); DeleteObject(iconInfo.hbmMask); IImage resultImage = engine.CreateImage("icon_" + hIcon.ToInt64() + "_" + large, bitmapInfo.bmiHeader.biWidth, bitmapInfo.bmiHeader.biHeight, pBuffer); return(resultImage); } return(null); }