public static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot) { //IconInfo tmp = new IconInfo(); //GetIconInfo(bmp.GetHicon(), ref tmp); //tmp.xHotspot = xHotSpot; //tmp.yHotspot = yHotSpot; //tmp.fIcon = false; //IntPtr ptr = CreateIconIndirect(ref tmp); //SafeFileHandle handle = new SafeFileHandle(ptr, true); //return CursorInteropHelper.Create(handle); var iconInfo = new IconInfo(); GetIconInfo(bmp.GetHicon(), ref iconInfo); iconInfo.xHotspot = xHotSpot; iconInfo.yHotspot = yHotSpot; iconInfo.fIcon = false; SafeIconHandle cursorHandle = CreateIconIndirect(ref iconInfo); return CursorInteropHelper.Create(cursorHandle); }
/// <summary> /// カーソルを作成する /// </summary> /// <param name="bitmap">カーソル画像</param> /// <param name="xHotSpot">ホットスポットのX座標</param> /// <param name="yHotSpot">ホットスポットのY座標</param> /// <returns>作成したカーソル</returns> public static Cursor CreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot) { Bitmap andMask = new Bitmap(bitmap.Width, bitmap.Height); Bitmap xorMask = new Bitmap(bitmap.Width, bitmap.Height); Color transparent = bitmap.GetPixel(bitmap.Width - 1, bitmap.Height - 1); for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { Color pixel = bitmap.GetPixel(x, y); if (pixel == transparent) { andMask.SetPixel(x, y, Color.White); xorMask.SetPixel(x, y, Color.Transparent); } else { andMask.SetPixel(x, y, Color.Black); xorMask.SetPixel(x, y, pixel); } } } IntPtr hIcon = bitmap.GetHicon(); IconInfo info = new IconInfo(); NativeMethods.GetIconInfo(hIcon, ref info); info.xHotspot = xHotSpot; info.yHotspot = yHotSpot; info.hbmMask = andMask.GetHbitmap(); info.hbmColor = xorMask.GetHbitmap(); info.fIcon = false; hIcon = NativeMethods.CreateIconIndirect(ref info); return new Cursor(hIcon); }
public static System.Windows.Forms.Cursor CreateCursor( System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot ) { IconInfo tmp = new IconInfo(); GetIconInfo( bmp.GetHicon(), ref tmp ); tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; tmp.fIcon = false; return new System.Windows.Forms.Cursor( CreateIconIndirect( ref tmp ) ); }
public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot) { IconInfo tmp = new IconInfo(); GetIconInfo(bmp.GetHicon(), ref tmp); tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; tmp.fIcon = false; return new Cursor(CreateIconIndirect(ref tmp)); }
public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot) { var ptr = bmp.GetHicon(); var tmp = new IconInfo(); NativeMethods.GetIconInfo(ptr, ref tmp); tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; tmp.fIcon = false; ptr = NativeMethods.CreateIconIndirect(ref tmp); return new Cursor(ptr); }
/// <summary> /// Creates the cursor using P/Invoke /// </summary> /// <param name="bmp">The BMP to display as cursor</param> /// <param name="xHotSpot">The x hot spot.</param> /// <param name="yHotSpot">The y hot spot.</param> /// <returns></returns> private Cursor CreateCursor(Bitmap bmp, Point hotSpot) { IntPtr iconHandle = bmp.GetHicon(); var iconInfo = new IconInfo(); UnManagedMethodWrapper.GetIconInfo(iconHandle, ref iconInfo); iconInfo.xHotspot = hotSpot.X; iconInfo.yHotspot = hotSpot.Y; iconInfo.fIcon = false; iconHandle = UnManagedMethodWrapper.CreateIconIndirect(ref iconInfo); return new Cursor(iconHandle); }
public static System.Windows.Forms.Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot) { IntPtr ptr = bmp.GetHicon(); IconInfo tmp = new IconInfo(); GetIconInfo(ptr, ref tmp); tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; tmp.fIcon = false; ptr = CreateIconIndirect(ref tmp); return new System.Windows.Forms.Cursor(ptr); }
/// <summary> /// Create a cursor from the supplied bitmap & hotspot coordinates /// </summary> /// <param name="bitmap">Bitmap to create an icon from</param> /// <param name="hotspotX">Hotspot X coordinate</param> /// <param name="hotspotY">Hotspot Y coordinate</param> /// <returns>Cursor</returns> private static Cursor CreateCursor(Bitmap bitmap, int hotspotX, int hotspotY) { using (SafeIconHandle iconHandle = new SafeIconHandle( bitmap.GetHicon())) { IntPtr icon; IconInfo iconInfo = new IconInfo(); User32.GetIconInfo(iconHandle, out iconInfo); iconInfo.xHotspot = hotspotX; iconInfo.yHotspot = hotspotY; iconInfo.fIcon = false; icon = User32.CreateIconIndirect(ref iconInfo); return new Cursor(icon); } }
private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot) { IconInfo tmp = new IconInfo(); GetIconInfo(bmp.GetHicon(), ref tmp); tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; tmp.fIcon = false; IntPtr ptr = CreateIconIndirect(ref tmp); SafeFileHandle handle = new SafeFileHandle(ptr, true); return CursorInteropHelper.Create(handle); }
// Based on the article and comments here: // http://www.switchonthecode.com/tutorials/csharp-tutorial-how-to-use-custom-cursors // Note that the returned Cursor must be disposed of after use, or you'll leak memory! public static Cursor CreateCursor(Bitmap bm , int xHotspot , int yHotspot) { IntPtr cursorPtr; IntPtr ptr = bm.GetHicon(); IconInfo tmp = new IconInfo(); GetIconInfo(ptr , ref tmp); tmp.xHotspot = xHotspot; tmp.yHotspot = yHotspot; tmp.fIcon = false; cursorPtr = CreateIconIndirect(ref tmp); if (tmp.hbmColor != IntPtr.Zero) DeleteObject(tmp.hbmColor); if (tmp.hbmMask != IntPtr.Zero) DeleteObject(tmp.hbmMask); if (ptr != IntPtr.Zero) DestroyIcon(ptr); return new Cursor(cursorPtr); }
// GUI protected override void OnContentGUI() { float currentViewWidth = EditorGUIUtility.currentViewWidth; bool canHaveColumns = currentViewWidth > 500f; float horizIconWidth = (currentViewWidth * 0.75f) * 0.45f; EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(showMissingProperty); if (EditorGUI.EndChangeCheck()) { serializedSettings.ApplyModifiedProperties(); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(currentViewWidth)); { EditorGUILayout.BeginVertical(Style.TabBackground, GUILayout.Width(currentViewWidth * 0.075F)); { EditorGUI.BeginChangeCheck(); showAllProperty.boolValue = GUILayout.Toggle(showAllProperty.boolValue, "Show All\nIcons", Style.LargeButtonSmallTextStyle); if (EditorGUI.EndChangeCheck()) { serializedSettings.ApplyModifiedProperties(); } #if UNITY_2019_1_OR_NEWER EditorGUILayout.Space(6f); #else EditorGUILayout.Space(); #endif selection = GUILayout.SelectionGrid(selection, componentCategories.Keys.ToArray(), 1, Style.LargeButtonStyle); } EditorGUILayout.EndVertical(); // Any rare usecases EditorGUILayout.BeginVertical(Style.TabBackground); { if (showAllProperty.boolValue) { EditorGUILayout.LabelField("All Icons are shown as \"Show All Icons\" is enabled", Style.CenteredBoldLabel); } EditorGUI.BeginDisabledGroup(showAllProperty.boolValue); KeyValuePair <String, List <IconInfo> > category = componentCategories.ElementAt(selection); List <IconInfo> icons = category.Value; bool hasColumn = false; if (selection == componentCategories.Keys.Count - 1) { DrawGlobalToggles(serializedCustomComponents); #if UNITY_2019_1_OR_NEWER EditorGUILayout.Space(10f); #else EditorGUILayout.Space(); #endif DrawCustomComponents(); } else { DrawGlobalToggles(icons); #if UNITY_2019_1_OR_NEWER EditorGUILayout.Space(10f); #else EditorGUILayout.Space(); #endif EditorGUIUtility.SetIconSize(Vector2.one * 16f); int validIndex = 0; for (int j = 0; j < icons.Count; j++) { IconInfo icon = icons[j]; Type iconType = icon.type; GUIContent content = EditorGUIUtility.ObjectContent(null, iconType); content.text = iconType.Name; // Setup group to display two column view of icons hasColumn = validIndex % 2 == 0; EditorGUI.BeginChangeCheck(); GUIHelper.BeginConditionalHorizontal(hasColumn && canHaveColumns); icon.property.boolValue = EditorGUILayout.ToggleLeft(content, icon.property.boolValue, GUILayout.Width(horizIconWidth)); GUIHelper.EndConditionHorizontal(!hasColumn && canHaveColumns); if (EditorGUI.EndChangeCheck()) { serializedSettings.ApplyModifiedProperties(); } validIndex++; } } EditorGUIUtility.SetIconSize(Vector2.zero); GUIHelper.EndConditionHorizontal(hasColumn && canHaveColumns); EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); }
/// <summary> /// Gets the System.Drawing.Icon that best fits the current display device. /// </summary> /// <param name="icon">System.Drawing.Icon to be searched.</param> /// <param name="desiredSize">Specifies the desired size of the icon.</param> /// <param name="isMonochrome">Specifies whether to get the monochrome icon or the colored one.</param> /// <returns>System.Drawing.Icon that best fit the current display device.</returns> public static Icon GetBestFitIcon(Icon icon, Size desiredSize, bool isMonochrome) { IconInfo info = new IconInfo(icon); int index = info.GetBestFitIconIndex(desiredSize, isMonochrome); return info.Images[index]; }
/// <summary> /// Splits the group icon into a list of icons (the single icon file can contain a set of icons). /// </summary> /// <param name="icon">The System.Drawing.Icon need to be splitted.</param> /// <returns>List of System.Drawing.Icon.</returns> public static List<Icon> SplitGroupIcon(Icon icon) { IconInfo info = new IconInfo(icon); return info.Images; }
/// <summary> /// Create a cursor from the supplied bitmap & hotspot coordinates /// </summary> /// <param name="bitmap">Bitmap to create an icon from</param> /// <param name="hotspotX">Hotspot X coordinate</param> /// <param name="hotspotY">Hotspot Y coordinate</param> /// <returns>Cursor</returns> private static Cursor CreateCursor(Bitmap bitmap, int hotspotX, int hotspotY) { IntPtr iconHandle = bitmap.GetHicon(); IntPtr icon; IconInfo iconInfo = new IconInfo(); User32.GetIconInfo(iconHandle, out iconInfo); iconInfo.xHotspot = hotspotX; iconInfo.yHotspot = hotspotY; iconInfo.fIcon = false; icon = User32.CreateIconIndirect(ref iconInfo); Cursor returnCursor = new Cursor(icon); //User32.DestroyIcon(icon); User32.DestroyIcon(iconHandle); return returnCursor; }
public void NotifyOccured(NotifyType notifyType, Socket socket, BaseInfo baseInfo) { switch (notifyType) { case NotifyType.Reply_UpdateUser: { UserInfo userName = (UserInfo)baseInfo; Window1.main.nickName.Content = userName.Nickname; ToolTip tt = new ToolTip(); tt.Content = userName.Nickname; Window1.main.nickName.ToolTip = tt; IniFileEdit _IniFileEdit = new IniFileEdit(Window1._UserPath); ImageBrush updateImg = new ImageBrush(); updateImg.Stretch = Stretch.Fill; _IniFileEdit.SetIniValue("UserInfo", "userImage", userName.Icon); updateImg.ImageSource = ImageDownloader.GetInstance().GetImage(userName.Icon); myPicture.Fill = updateImg; Window1.main.memberImg.Fill = updateImg; ToolTip sign = new ToolTip(); sign.Content = Window1._UserInfo.Sign; Window1.main.singBox.ToolTip = sign; Window1.main.singBox.Text = Window1._UserInfo.Sign; if (selectGrid.Children.Count > 0 && selectGrid.Children[0] is MyInfoControl) { MyInfoControl myInfoControl = (MyInfoControl)selectGrid.Children[0]; myInfoControl.buttonSave.IsEnabled = false; } MessageBoxCommon.Show("更新成功", MessageBoxType.Ok); } break; case NotifyType.Reply_VideoUpload: { MessageBoxCommon.Show("更改成功.", MessageBoxType.Ok); } break; case NotifyType.Reply_NewID: { UserInfo newUserInfo = (UserInfo)baseInfo; MessageBoxCommon.Show("帐号申请通过." + newUserInfo.Id, MessageBoxType.Ok); userInfoList.Add(newUserInfo); selectGrid.Children.Clear(); NoticeMemberControl noticeMemberControl = new NoticeMemberControl(); noticeMemberControl.listMember(userInfoList); selectGrid.Children.Add(noticeMemberControl); } break; case NotifyType.Reply_IconUpload: { IconInfo newIcon = (IconInfo)baseInfo; iconInfoList.Add(newIcon); selectGrid.Children.Clear(); AlbermControl albermControl = new AlbermControl(); albermControl.pictureList(iconInfoList); selectGrid.Children.Add(albermControl); } break; case NotifyType.Reply_Give: { PresentHistoryInfo presentHistoryInfo = (PresentHistoryInfo)baseInfo; presentHistoryList.Add(presentHistoryInfo); selectGrid.Children.Clear(); InnerControl innerControl = new InnerControl(); innerControl.InnerChatting(chatHistoryList); selectGrid.Children.Add(innerControl); for (int i = 0; i < userInfoList.Count; i++) { if (userInfoList[i].Id == presentHistoryInfo.ReceiveId) { userInfoList[i].Cash = userInfoList[i].Cash + presentHistoryInfo.Cash; selectGrid.Children.Clear(); NoticeMemberControl noticeMemberControl = new NoticeMemberControl(); noticeMemberControl.listMember(userInfoList); selectGrid.Children.Add(noticeMemberControl); break; } } } break; case NotifyType.Reply_UpdatePercent: { UserInfo userPercent = (UserInfo)baseInfo; if (userPercent.Id == Window1._UserInfo.Id) { selectGrid.Children.Clear(); MyInfoControl myInfoControl = new MyInfoControl(); myInfoControl.InitMyInfo(Window1._UserInfo); selectGrid.Children.Add(myInfoControl); } } break; case NotifyType.Reply_IconRemove: { IconInfo newIcon = (IconInfo)baseInfo; for (int i = 0; i < iconInfoList.Count; i++) { if (iconInfoList[i].Icon == newIcon.Icon) { iconInfoList.Remove(iconInfoList[i]); } } selectGrid.Children.Clear(); AlbermControl albermControl = new AlbermControl(); albermControl.pictureList(iconInfoList); selectGrid.Children.Add(albermControl); } break; case NotifyType.Reply_Error: { ResultInfo errorInfo = (ResultInfo)baseInfo; ErrorType errorType = errorInfo.ErrorType; //Window1.ShowError(errorType); } break; } }
private static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
async Task GenerateIcon(AppInfo appInfo, IconInfo iconInfo, StorageFolder folder) { // Draw the icon image into a command list. var commandList = new CanvasCommandList(device); using (var ds = commandList.CreateDrawingSession()) { appInfo.DrawIconImage(ds, iconInfo); } ICanvasImage iconImage = commandList; // Rasterize into a rendertarget. var renderTarget = new CanvasRenderTarget(device, iconInfo.Width, iconInfo.Height, 96); using (var ds = renderTarget.CreateDrawingSession()) { // Initialize with the appropriate background color. ds.Clear(iconInfo.TransparentBackground ? Colors.Transparent : appInfo.BackgroundColor); // Work out where to position the icon image. var imageBounds = iconImage.GetBounds(ds); imageBounds.Height *= 1 + iconInfo.BottomPadding; float scaleUpTheSmallerIcons = Math.Max(1, 1 + (60f - iconInfo.Width) / 50f); float imageScale = appInfo.ImageScale * scaleUpTheSmallerIcons; var transform = Matrix3x2.CreateTranslation((float)-imageBounds.X, (float)-imageBounds.Y) * Utils.GetDisplayTransform(renderTarget.Size.ToVector2(), new Vector2((float)imageBounds.Width, (float)imageBounds.Height)) * Matrix3x2.CreateScale(imageScale, renderTarget.Size.ToVector2() / 2); if (iconInfo.Monochrome) { // Optionally convert to monochrome. iconImage = new DiscreteTransferEffect { Source = new Transform2DEffect { Source = new LuminanceToAlphaEffect { Source = iconImage }, TransformMatrix = transform }, RedTable = new float[] { 1 }, GreenTable = new float[] { 1 }, BlueTable = new float[] { 1 }, AlphaTable = new float[] { 0, 1 } }; } else { ds.Transform = transform; // Optional shadow effect. if (appInfo.AddShadow) { var shadow = new ShadowEffect { Source = iconImage, BlurAmount = 12, }; ds.DrawImage(shadow); } } // draw the main icon image. ds.DrawImage(iconImage); } // Save to a file. using (var stream = await folder.OpenStreamForWriteAsync(iconInfo.Filename, CreationCollisionOption.ReplaceExisting)) { await renderTarget.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png); } }
private bool ShouldSerializeSaveIcon() { return(IconInfo.ShouldSerialize(_saveIcon)); }
public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
protected string CalculateLayoutWithImage(string richText, out IList <UIVertex> verts) { Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); float unitsPerPixel = 1 / pixelsPerUnit; float spaceWidth = cachedTextGenerator.GetPreferredWidth(ReplaceChar.ToString(), settings) * unitsPerPixel; float fontSize2 = fontSize * 0.5f; // Image replace icons.Clear(); Match match = null; StringBuilder builder = new StringBuilder(); while ((match = IconReg.Match(richText)).Success) { IconInfo iconInfo = new IconInfo(); iconInfo.name = match.Groups[1].Value; iconInfo.size = new Vector2(fontSize2, fontSize2); float w = 1, h = 1; string e = null, args = null; string vars = match.Groups[2].Value; if (!string.IsNullOrEmpty(vars)) { Match itemMatch = ItemReg.Match(vars); while (itemMatch.Success) { string name = itemMatch.Groups[1].Value; string value = itemMatch.Groups[2].Value; switch (name) { case "w": { float.TryParse(value, out w); break; } case "h": { float.TryParse(value, out h); break; } case "event": { e = value; break; } case "args": { args = value; break; } } itemMatch = itemMatch.NextMatch(); } } if (spriteList.ContainsKey(iconInfo.name)) { Sprite sprite = spriteList[iconInfo.name]; if (sprite != null) { iconInfo.size = new Vector2(sprite.rect.width * w, sprite.rect.height * h); } } iconInfo.e = e; iconInfo.args = args; iconInfo.vertice = match.Index * 4; int holderLen = Mathf.CeilToInt(iconInfo.size.x / spaceWidth); iconInfo.vlength = holderLen * 4; icons.Add(iconInfo); builder.Length = 0; builder.Append(richText, 0, match.Index); builder.Append(ReplaceChar, holderLen); builder.Append(richText, match.Index + match.Length, richText.Length - match.Index - match.Length); richText = builder.ToString(); } // Populate charaters cachedTextGenerator.Populate(richText, settings); verts = cachedTextGenerator.verts; // Last 4 verts are always a new line... int vertCount = verts.Count - 4; // Image wrap check for (int i = 0; i < icons.Count; i++) { IconInfo iconInfo = icons[i]; int vertice = iconInfo.vertice; int vlength = iconInfo.vlength; int maxVertice = Mathf.Min(vertice + vlength, vertCount); if (verts[maxVertice - 2].position.x * unitsPerPixel > rectTransform.rect.xMax) { // New line richText = richText.Insert(vertice / 4, "\r\n"); for (int j = i; j < icons.Count; j++) { icons[j].vertice += 8; } cachedTextGenerator.Populate(richText, settings); verts = cachedTextGenerator.verts; vertCount = verts.Count - 4; } } // Image position calculation for (int i = icons.Count - 1; i >= 0; i--) { IconInfo iconInfo = icons[i]; int vertice = iconInfo.vertice; if (vertice < vertCount) { UIVertex vert = verts[vertice]; Vector2 vertex = vert.position; vertex *= unitsPerPixel; vertex += new Vector2(iconInfo.size.x * 0.5f, fontSize2 * 0.5f); vertex += new Vector2(rectTransform.sizeDelta.x * (rectTransform.pivot.x - 0.5f), rectTransform.sizeDelta.y * (rectTransform.pivot.y - 0.5f)); iconInfo.position = vertex; iconInfo.color = Color.white; if (!string.IsNullOrEmpty(iconInfo.e)) { Event e = new Event(); e.name = iconInfo.e; e.args = iconInfo.args; e.rect = new Rect( verts[vertice].position.x * unitsPerPixel, verts[vertice].position.y * unitsPerPixel + (fontSize2 - iconInfo.size.y) * 0.5f, iconInfo.size.x, iconInfo.size.y ); eventList.Add(e); } } else { icons.RemoveAt(i); } } // Need re-layout image SetImageDirty(); return(richText); }
/// <summary> /// 纹理 /// </summary> protected string CalculateLayoutOfImage(string richText, out IList <UIVertex> verts) { float fontSize2 = fontSize * 0.5f; float unitsPerPixel = 1f / pixelsPerUnit; Vector2 extents = rectTransform.rect.size; var settings = GetGenerationSettings(extents); settings.verticalOverflow = VerticalWrapMode.Overflow; // Image replace icons.Clear(); Match match = null; StringBuilder builder = new StringBuilder(); while ((match = IconReg.Match(richText)).Success) { IconInfo iconInfo = new IconInfo(); float w = fontSize2, h = fontSize2, pivot = 0f, frame = -1f; string[] sprites = null; string atlas = null, e = null, args = null; Match itemMatch = ItemReg.Match(match.Value); while (itemMatch.Success) { string name = itemMatch.Groups[1].Value; string value = itemMatch.Groups[2].Value; switch (name) { case "frame": //帧率 float.TryParse(value, out frame); break; case "sprite": //纹理 sprites = value.Split('+'); break; case "atlas": //图集 atlas = value; break; case "pivot": //y方向锚点 float.TryParse(value, out pivot); break; case "w": //宽 float.TryParse(value, out w); break; case "h": //高 float.TryParse(value, out h); break; case "event": //事件 e = value; break; case "args": //事件参数 args = value; break; } itemMatch = itemMatch.NextMatch(); } iconInfo.size = new Vector2(w, h); iconInfo.pivot = pivot; iconInfo.frame = frame; iconInfo.atlas = atlas; iconInfo.sprite = sprites; iconInfo.evt = e; iconInfo.args = args; iconInfo.vertice = match.Index * 4; icons.Add(iconInfo); float size = (1f - pivot) * (iconInfo.size.y - fontSize) + fontSize; string replace = string.Format("<size={0}>{1}</size>", size, replaceChar); float spaceWidth = cachedTextGenerator.GetPreferredWidth(replace, settings) * unitsPerPixel; int holderLen = Mathf.CeilToInt(iconInfo.size.x / spaceWidth); if (holderLen < 0) { holderLen = 0; } //占位符 builder.Length = 0; builder.Append(string.Format("<color=#00000000><size={0}>", size)); builder.Append(replaceChar, holderLen); builder.Append("</size></color>"); string holder = builder.ToString(); iconInfo.vlength = holder.Length * 4; //截取 builder.Length = 0; builder.Append(richText, 0, match.Index); builder.Append(holder); builder.Append(richText, match.Index + match.Length, richText.Length - match.Index - match.Length); richText = builder.ToString(); } // Populate characters cachedTextGenerator.Populate(richText, settings); //这里不是直接给verts赋值,而是返回一个副本,避免操作unity内部verts造成顶点泄漏 UIVertex[] ary = new UIVertex[cachedTextGenerator.verts.Count]; cachedTextGenerator.verts.CopyTo(ary, 0); verts = new List <UIVertex>(ary); // Last 4 verts are always a new line... int vertCount = verts.Count - 4; if (vertCount <= 0) { icons.Clear(); SetImageDirty(); preferTextWid = preferTextHei = richText; return(richText); } preferTextWid = richText; // Image wrap check if (horizontalOverflow == HorizontalWrapMode.Wrap) { //水平自动换行 for (int i = 0; i < icons.Count; i++) { IconInfo iconInfo = icons[i]; int vertice = iconInfo.vertice; int vlength = iconInfo.vlength; if (verts[vertice + vlength - 1].position.x < verts[vertice].position.x) { // New line richText = richText.Insert(vertice / 4, "\r\n"); for (int j = i; j < icons.Count; j++) { icons[j].vertice += 8; } //todo:这里也要小心 cachedTextGenerator.Populate(richText, settings); verts = cachedTextGenerator.verts; vertCount = verts.Count - 4; } } } if (verticalOverflow == VerticalWrapMode.Truncate) { //溢出框外的不要 float minY = rectTransform.rect.yMin; while (vertCount > 0 && verts[vertCount - 2].position.y * unitsPerPixel < minY) { verts.RemoveAt(vertCount - 1); verts.RemoveAt(vertCount - 2); verts.RemoveAt(vertCount - 3); verts.RemoveAt(vertCount - 4); vertCount -= 4; } } preferTextHei = richText; // Image position calculation for (int i = icons.Count - 1; i >= 0; i--) { IconInfo iconInfo = icons[i]; int vertice = iconInfo.vertice; if (vertice < vertCount) { UIVertex vert = verts[vertice]; Vector2 vertex = vert.position; vertex *= unitsPerPixel; vertex += new Vector2(iconInfo.size.x * 0.5f, (fontSize2 + iconInfo.size.y * (0.5f - iconInfo.pivot)) * 0.5f); vertex += new Vector2(rectTransform.sizeDelta.x * (rectTransform.pivot.x - 0.5f), rectTransform.sizeDelta.y * (rectTransform.pivot.y - 0.5f)); iconInfo.position = vertex; iconInfo.color = Color.white; if (!string.IsNullOrEmpty(iconInfo.evt)) { Event e = new Event(); e.name = iconInfo.evt; e.args = iconInfo.args; e.rect = new Rect(verts[vertice].position.x * unitsPerPixel, verts[vertice].position.y * unitsPerPixel + (fontSize2 - iconInfo.size.y) * 0.5f, iconInfo.size.x, iconInfo.size.y); eventList.Add(e); } } else { icons.RemoveAt(i); } } // Need re-layout image SetImageDirty(); return(richText); }
private static Gdk.Pixbuf PlatformGetIcon(string resource) { IconInfo iconInfo = null; Gdk.Pixbuf icon = null; try { switch (resource) { case "Commands.New.png": iconInfo = _theme.LookupIcon("document-new", 16, 0); break; case "Commands.Open.png": iconInfo = _theme.LookupIcon("document-open", 16, 0); break; case "Commands.Close.png": iconInfo = _theme.LookupIcon("window-close", 16, 0); break; case "Commands.Save.png": iconInfo = _theme.LookupIcon("document-save", 16, 0); break; case "Commands.SaveAs.png": iconInfo = _theme.LookupIcon("document-save-as", 16, 0); break; case "Commands.Undo.png": iconInfo = _theme.LookupIcon("edit-undo", 16, 0); break; case "Commands.Redo.png": iconInfo = _theme.LookupIcon("edit-redo", 16, 0); break; case "Commands.Delete.png": iconInfo = _theme.LookupIcon("edit-delete", 16, 0); break; case "Commands.NewItem.png": iconInfo = _theme.LookupIcon("document-new", 16, 0); break; case "Commands.NewFolder.png": iconInfo = _theme.LookupIcon("folder-new", 16, 0); break; case "Commands.ExistingItem.png": iconInfo = _theme.LookupIcon("document", 16, 0); break; case "Commands.ExistingFolder.png": iconInfo = _theme.LookupIcon("folder", 16, 0); break; case "Commands.Build.png": iconInfo = _theme.LookupIcon("applications-system", 16, 0); break; case "Commands.Rebuild.png": iconInfo = _theme.LookupIcon("system-run", 16, 0); break; case "Commands.Clean.png": iconInfo = _theme.LookupIcon("edit-clear-all", 16, 0); if (iconInfo == null) { iconInfo = _theme.LookupIcon("edit-clear", 16, 0); } break; case "Commands.CancelBuild.png": iconInfo = _theme.LookupIcon("process-stop", 16, 0); break; case "Commands.Help.png": iconInfo = _theme.LookupIcon("system-help", 16, 0); break; case "Build.Information.png": iconInfo = _theme.LookupIcon("dialog-information", 16, 0); break; case "Build.Fail.png": iconInfo = _theme.LookupIcon("dialog-error", 16, 0); break; case "Build.Processing.png": iconInfo = _theme.LookupIcon("preferences-system-time", 16, 0); break; case "Build.Skip.png": iconInfo = _theme.LookupIcon("emblem-default", 16, 0); break; case "Build.Start.png": iconInfo = _theme.LookupIcon("system-run", 16, 0); break; case "Build.EndSucceed.png": iconInfo = _theme.LookupIcon("system-run", 16, 0); break; case "Build.EndFailed.png": iconInfo = _theme.LookupIcon("system-run", 16, 0); break; case "Build.Succeed.png": iconInfo = _theme.LookupIcon("emblem-default", 16, 0); break; } if (iconInfo != null) { icon = iconInfo.LoadIcon(); } if (resource == "Commands.Rename.png" || resource == "Commands.OpenItem.png") { icon = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 1, 1, 1); } } catch { } return(icon); }
// Generate an icon for CompositionExample private static void DrawCompositionExampleIcon(CanvasDrawingSession ds, IconInfo iconInfo) { ds.DrawText("C", 0, 0, Colors.White); }
// For SimpleSample, we draw the same simple graphics as the sample itself. static void DrawSimpleSampleIcon(CanvasDrawingSession ds, IconInfo iconInfo) { ds.DrawEllipse(155, 115, 80, 30, Colors.Black, 3); ds.DrawText("Hello, world!", 100, 100, Colors.Yellow); }
public static extern SafeIconHandle CreateIconIndirect(ref IconInfo icon);
private static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
private void OnTileDragEnter(object sender, DragEventArgs dragEventArgs) { dragEventArgs.Effect = DragDropEffects.Copy; m_draggedTileSheet = m_tilePicker.SelectedTileSheet; m_draggedTileIndex = m_tilePicker.SelectedTileIndex; Bitmap tileImage = TileImageCache.Instance.GetTileBitmap( m_draggedTileSheet, m_draggedTileIndex); IconInfo iconInfo = new IconInfo(); GetIconInfo(tileImage.GetHicon(), ref iconInfo); iconInfo.HotSpotX = tileImage.Width / 2; iconInfo.HotSpotY = tileImage.Height / 2; iconInfo.Icon = false; Cursor = new Cursor(CreateIconIndirect(ref iconInfo)); }
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
public HeaderContent(IconInfo iconInfo, string?text = null) : this() { Add(iconInfo.CreateGtkImage()); TryAddLabel(text); }
IEnumerator Coroutine_Load() { if (m_obj == null) { GameResPackage.AsyncLoadObjectData data = new GameResPackage.AsyncLoadObjectData(); IEnumerator e = PoolManager.Singleton.Coroutine_Load(GameData.GetUIPath("DropItem"), data, true); while (true) { e.MoveNext(); if (data.m_isFinish) { break; } yield return(e.Current); } m_obj = data.m_obj as GameObject; } IsEnable = true; m_obj.transform.localScale = new UnityEngine.Vector3(0.2f, 0.2f, 0.2f); m_obj.transform.localPosition = new Vector3(m_posX, 0.0f, m_posZ); GameObject item = m_obj.transform.Find("DropItmSupply").gameObject; GameObject name = m_obj.transform.Find("ItemName").gameObject; int nIcnID = 0; string NAME = ""; int color = 1; if (1 == m_type) // ����: װ��(��) { EquipInfo einf = GameTable.EquipTableAsset.LookUpEquipInfoById(mItemID); if (einf != null) { int nMdlInfID = einf.ModelRes; // ���Ҷ�Ӧ��ʾͼ�� ModelInfo MdlInf = GameTable.ModelInfoTableAsset.Lookup(nMdlInfID); if (MdlInf != null) { nIcnID = MdlInf.DropIcon; } } NAME = einf.EquipName; color = einf.EqRank; } else if (2 == m_type) // ����: Buf(��) { BuffInfo bfInfo = GameTable.BuffTableAsset.Lookup(mItemID); if (null != bfInfo) { nIcnID = bfInfo.BuffIcon; } else { Debug.LogWarning("CreateDropObj: LOST Buf ItemID = " + mItemID.ToString()); } NAME = bfInfo.BuffName; } else if (3 == m_type) // ��Ǯ { WorldParamInfo WorldParamList; WorldParamList = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enMoneyDropIcon); nIcnID = WorldParamList.IntTypeValue; NAME = GameTable.StringTableAsset.GetString(ENStringIndex.UIEquipmentBindMoney); } else if (4 == m_type) // ���� { WorldParamInfo WorldParamList; WorldParamList = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enRMBMoneyDropIcon); nIcnID = WorldParamList.IntTypeValue; NAME = GameTable.StringTableAsset.GetString(ENStringIndex.UIEquipmentRMBMoney); } else if (5 == m_type) //��Ӿ� { WorldParamInfo WorldParamList; WorldParamList = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enTeamVolumeDropIcon); nIcnID = WorldParamList.IntTypeValue; //todo ����ַ����� NAME = GameTable.StringTableAsset.GetString(ENStringIndex.TeamVolume); } else { Debug.LogWarning("CreateDropObj: Unknown Type = " + m_type.ToString()); } IconInfo icInf = GameTable.IconTableAsset.Lookup(nIcnID); if (icInf == null) { Debug.LogWarning("CreateDropObj: LOST = " + nIcnID.ToString()); } else { // �����ɼ����� GameResPackage.AsyncLoadObjectData data = new GameResPackage.AsyncLoadObjectData(); IEnumerator e = PoolManager.Singleton.Coroutine_Load(GameData.GetUIAtlasPath(icInf.AtlasName), data, false, false); while (true) { e.MoveNext(); if (data.m_isFinish) { break; } yield return(e.Current); } if (data.m_obj != null) { UIAtlas ua = data.m_obj as UIAtlas; if (ua != null) { UISprite spt = item.GetComponent <UISprite>(); spt.atlas = ua; spt.name = icInf.AtlasName; spt.spriteName = icInf.SpriteName; } } } if (NAME != "") { UILabel label = name.GetComponent <UILabel>(); label.text = NAME; switch (color) { case 1: label.color = Color.white; break; case 2: label.color = Color.green; break; case 3: label.color = Color.blue; break; case 4: label.color = Color.magenta; break; case 5: label.color = Color.yellow; break; default: break; } } PickupDropCallback pdCall = item.GetComponent <PickupDropCallback>(); if (pdCall != null) { pdCall.AttachDropValue(this, mDropID, mItemID); // ��Щ������Ҫͬ���������� } }
public static extern SafeIconHandle CreateIconIndirect(ref IconInfo icon);
public static extern bool GetIconInfo(SafeIconHandle iconHandle, out IconInfo iconInfo);
private static extern IntPtr CreateIconIndirect(ref IconInfo icon);
public void NotifyOccured(NotifyType notifyType, Socket socket, BaseInfo baseInfo) { switch (notifyType) { case NotifyType.Reply_UpdateUser: { UserInfo userName = (UserInfo)baseInfo; Login.main.nickName.Content = userName.Nickname; ToolTip tt = new ToolTip(); tt.Content = userName.Nickname; Login.main.nickName.ToolTip = tt; IniFileEdit _IniFileEdit = new IniFileEdit(Login._UserPath); ImageBrush updateImg = new ImageBrush(); updateImg.Stretch = Stretch.Fill; _IniFileEdit.SetIniValue("UserInfo", "userImage", userName.Icon); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(userName.Icon, UriKind.RelativeOrAbsolute); bi.EndInit(); //updateImg.ImageSource = bi; updateImg.ImageSource = ImageDownloader.GetInstance().GetImage(userName.Icon); myPicture.Fill = updateImg; Login.main.memberImg.Fill = updateImg; ToolTip sign = new ToolTip(); sign.Content = Login._UserInfo.Sign; Login.main.singBox.ToolTip = sign; //Login.main.singBox.Text = Login._UserInfo.Sign; if (selectGrid.Children.Count > 0 && selectGrid.Children[0] is MyInfoControl) { MyInfoControl myInfoControl = (MyInfoControl)selectGrid.Children[0]; myInfoControl.buttonSave.IsEnabled = false; } //MessageBoxCommon.Show("更新成功", MessageBoxType.Ok); TempWindowForm tempWindowForm = new TempWindowForm(); QQMessageBox.Show(tempWindowForm, "更新成功", "提示", QQMessageBoxIcon.OK, QQMessageBoxButtons.OK); } break; case NotifyType.Request_VideoUpload: { // 2014-02-09: GreenRose if (Main.loadWnd != null) { Main.loadWnd.Close(); Main.loadWnd = null; } //List<IconInfo> listVideoInfo = new List<IconInfo>(); IconInfo newIcon = (IconInfo)baseInfo; //iconInfoList.Add(newIcon); if (iconInfoList != null) { iconInfoList.Add(newIcon); } else { iconInfoList = new List <IconInfo>(); iconInfoList.Add(newIcon); } selectGrid.Children.Clear(); PictureControl pictureControl = new PictureControl(); pictureControl.InitVideoList(iconInfoList); selectGrid.Children.Add(pictureControl); TempWindowForm tempWindowForm = new TempWindowForm(); QQMessageBox.Show(tempWindowForm, "更新成功", "提示", QQMessageBoxIcon.OK, QQMessageBoxButtons.OK); } break; //case NotifyType.Reply_NewID: // { // UserInfo newUserInfo = (UserInfo)baseInfo; // TempWindowForm tempWindowForm = new TempWindowForm(); // QQMessageBox.Show(tempWindowForm, "帐号申请通过." + newUserInfo.Id + "(首次登陆没有密码 登陆后请完善资料)", "提示", QQMessageBoxIcon.OK, QQMessageBoxButtons.OK); // userInfoList.Add(newUserInfo); // selectGrid.Children.Clear(); // NoticeMemberControl noticeMemberControl = new NoticeMemberControl(); // noticeMemberControl.listMember(userInfoList); // selectGrid.Children.Add(noticeMemberControl); // } // break; case NotifyType.Reply_IconUpload: { IconInfo newIcon = (IconInfo)baseInfo; IconInfo iconInfo = iconInfoList.Find(item => item.Id == newIcon.Id); if (iconInfo == null) { iconInfoList.Add(newIcon); selectGrid.Children.Clear(); AlbermControl albermControl = new AlbermControl(); albermControl.pictureList(iconInfoList); selectGrid.Children.Add(albermControl); } } break; case NotifyType.Reply_Give: { PresentHistoryInfo presentHistoryInfo = (PresentHistoryInfo)baseInfo; presentHistoryList.Add(presentHistoryInfo); selectGrid.Children.Clear(); InnerControl innerControl = new InnerControl(); innerControl.InnerChatting(chatHistoryList); selectGrid.Children.Add(innerControl); for (int i = 0; i < userInfoList.Count; i++) { if (userInfoList[i].Id == presentHistoryInfo.ReceiveId) { userInfoList[i].Cash = userInfoList[i].Cash + presentHistoryInfo.Cash; selectGrid.Children.Clear(); NoticeMemberControl noticeMemberControl = new NoticeMemberControl(); noticeMemberControl.listMember(userInfoList); selectGrid.Children.Add(noticeMemberControl); break; } } } break; case NotifyType.Reply_UpdatePercent: { UserInfo userPercent = (UserInfo)baseInfo; if (userPercent.Id == Login._UserInfo.Id) { selectGrid.Children.Clear(); MyInfoControl myInfoControl = new MyInfoControl(); myInfoControl.InitMyInfo(Login._UserInfo); selectGrid.Children.Add(myInfoControl); } } break; case NotifyType.Reply_IconRemove: { IconInfo newIcon = (IconInfo)baseInfo; for (int i = 0; i < iconInfoList.Count; i++) { if (iconInfoList[i].Icon == newIcon.Icon) { iconInfoList.Remove(iconInfoList[i]); } } selectGrid.Children.Clear(); AlbermControl albermControl = new AlbermControl(); albermControl.pictureList(iconInfoList); selectGrid.Children.Add(albermControl); } break; case NotifyType.Reply_Error: { ResultInfo errorInfo = (ResultInfo)baseInfo; ErrorType errorType = errorInfo.ErrorType; //Login.ShowError(errorType); } break; } }
public UiCommand WithIcon(IconInfo icon) { _icon = icon; return(this); }
internal static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
private void ShowIconProperties(Icon icon) { IconInfo info = new IconInfo(icon); string format = "Width: {0}\nHeight: {1}\nBit Count: {2}\nColor Depth: {3}\nColor Count: {4}\n# Of Images: {5}\n"; string message = string.Format(format, info.Width, info.Height, info.BitCount, info.ColorDepth, info.ColorCount, info.Images.Count); MessageBox.Show(this, message, "Icon Properties"); }
internal static extern IntPtr CreateIconIndirect(ref IconInfo icon);
List<IconInfo> CreateIconInfos(WpfHexViewLine line) { var icons = new List<IconInfo>(); foreach (var glyphTag in GetGlyphTags(line)) { Debug.Assert(glyphTag != null); if (glyphTag == null) continue; GlyphFactoryInfo factoryInfo; // Fails if someone forgot to Export(typeof(HexGlyphFactoryProvider)) with the correct tag types bool b = glyphFactories.TryGetValue(glyphTag.GetType(), out factoryInfo); Debug.Assert(b); if (!b) continue; var elem = factoryInfo.Factory.GenerateGlyph(line, glyphTag); if (elem == null) continue; elem.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var iconInfo = new IconInfo(factoryInfo.Order, elem); icons.Add(iconInfo); // ActualWidth isn't always valid when we're here so use the constant Canvas.SetLeft(elem, (MARGIN_WIDTH - elem.DesiredSize.Width) / 2); Canvas.SetTop(elem, iconInfo.BaseTopValue + line.TextTop); } return icons; }
public static extern LPARAM CreateIconIndirect(ref IconInfo icon);
/// <summary> /// Gets the System.Drawing.Icon that best fits the current display device. /// </summary> /// <param name="icon">System.Drawing.Icon to be searched.</param> /// <returns>System.Drawing.Icon that best fit the current display device.</returns> public static Icon GetBestFitIcon(Icon icon) { IconInfo info = new IconInfo(icon); int index = info.GetBestFitIconIndex(); return info.Images[index]; }
public static extern bool GetIconInfo(LPARAM hIcon, ref IconInfo pIconInfo);
/// <summary> /// Merges a list of icons into one single icon. /// </summary> /// <param name="icons">The icons to be merged.</param> /// <returns>System.Drawing.Icon that contains all the images of the givin icons.</returns> public static Icon Merge(params Icon[] icons) { List<IconInfo> list = new List<IconInfo>(icons.Length); int numImages = 0; foreach (Icon icon in icons) { if (icon != null) { IconInfo info = new IconInfo(icon); list.Add(info); numImages += info.Images.Count; } } if (list.Count == 0) { throw new ArgumentNullException("icons", "The icons list should contain at least one icon."); } //Write the icon to a stream. MemoryStream outputStream = new MemoryStream(); int imageIndex = 0; int imageOffset = IconInfo.SizeOfIconDir + numImages * IconInfo.SizeOfIconDirEntry; for (int i = 0; i < list.Count; i++) { IconInfo iconInfo = list[i]; //The firs image, we should write the icon header. if (i == 0) { //Get the IconDir and update image count with the new count. IconDir dir = iconInfo.IconDir; dir.Count = (short)numImages; //Write the IconDir header. outputStream.Seek(0, SeekOrigin.Begin); Utility.WriteStructure<IconDir>(outputStream, dir); } //For each image in the current icon, we should write the IconDirEntry and the image raw data. for (int j = 0; j < iconInfo.Images.Count; j++) { //Get the IconDirEntry and update the ImageOffset to the new offset. IconDirEntry entry = iconInfo.IconDirEntries[j]; entry.ImageOffset = imageOffset; //Write the IconDirEntry to the stream. outputStream.Seek(IconInfo.SizeOfIconDir + imageIndex * IconInfo.SizeOfIconDirEntry, SeekOrigin.Begin); Utility.WriteStructure<IconDirEntry>(outputStream, entry); //Write the image raw data. outputStream.Seek(imageOffset, SeekOrigin.Begin); outputStream.Write(iconInfo.RawData[j], 0, entry.BytesInRes); //Update the imageIndex and the imageOffset imageIndex++; imageOffset += entry.BytesInRes; } } //Create the icon from the stream. outputStream.Seek(0, SeekOrigin.Begin); Icon resultIcon = new Icon(outputStream); outputStream.Close(); return resultIcon; }
private static extern bool GetIconInfo(IntPtr hIcon, out IconInfo piconinfo);
List<IconInfo> CreateIconInfos(IWpfTextViewLine line) { var icons = new List<IconInfo>(); foreach (var mappingSpan in tagAggregator.GetTags(line.ExtentAsMappingSpan)) { var tag = mappingSpan.Tag; Debug.Assert(tag != null); if (tag == null) continue; GlyphFactoryInfo factoryInfo; // Fails if someone forgot to Export(typeof(IGlyphFactoryProvider)) with the correct tag types bool b = glyphFactories.TryGetValue(tag.GetType(), out factoryInfo); Debug.Assert(b); if (!b) continue; foreach (var span in mappingSpan.Span.GetSpans(wpfTextViewHost.TextView.TextSnapshot)) { if (!line.IntersectsBufferSpan(span)) continue; var elem = factoryInfo.Factory.GenerateGlyph(line, tag); if (elem == null) continue; elem.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var iconInfo = new IconInfo(factoryInfo.Order, elem); icons.Add(iconInfo); // ActualWidth isn't always valid when we're here so use the constant SetLeft(elem, (MARGIN_WIDTH - elem.DesiredSize.Width) / 2); SetTop(elem, iconInfo.BaseTopValue + line.TextTop); } } return icons; }
/// <summary> /// 根据Icon的英文名查询 /// </summary> /// <param name="name">查找字体的英文名</param> /// <returns>如果icon.xml 文件不存在,name找不到, 字体未安装等常见返回空</returns> public IconInfo GetIconFromTTF(string name) { Dictionary <String, IconInfo> dicIcon = Cache.Instance["DicIcon"] as Dictionary <String, IconInfo>; if (dicIcon == null) { string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "\\" + @"Data\icon.xml"; // 如果文件不存在,则返回空 if (!FileUtil.FileIsExist(filePath)) { return(null); } // 读取Icon文件 XmlHelper xmlHelper = new XmlHelper(filePath); XmlNodeList nodeLst = xmlHelper.Read("icons"); dicIcon = new Dictionary <String, IconInfo>(); dicIcon.Clear(); for (var i = 0; i < nodeLst.Count; i++) { IconInfo iconInfo = new IconInfo(); var node = nodeLst[i]; if (node.Attributes["id"] != null) { iconInfo.Id = node.Attributes["id"].Value.ToInt32(); } if (node.Attributes["fontfrom"] != null) { iconInfo.IconCls = node.Attributes["fontfrom"].Value; } if (node.Attributes["value"] != null) { iconInfo.IconUrl = node.Attributes["value"].Value; } if (node.Attributes["name"] != null) { iconInfo.Name = node.Attributes["name"].Value; } if (node.Attributes["chinesename"] != null) { iconInfo.ChineseName = node.Attributes["chinesename"].Value; } if (node.Attributes["strValue"] != null) { iconInfo.StrValue = node.Attributes["strValue"].Value; } if (!dicIcon.ContainsKey(iconInfo.Name)) { dicIcon.Add(iconInfo.Name, iconInfo); } } Cache.Instance["DicIcon"] = dicIcon; } // 判断字体是否存在 if (!dicIcon.ContainsKey(name)) { return(null); } // 判断是否安装了字体 InstalledFontCollection fonts = new InstalledFontCollection(); foreach (System.Drawing.FontFamily family in fonts.Families) { if (family.Name.Equals(dicIcon[name].IconCls, StringComparison.CurrentCultureIgnoreCase)) { return(dicIcon[name]); } } // 字体未按照 return(null); }
public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo piconinfo);
private bool ShouldSerializeEditIcon() { return(IconInfo.ShouldSerialize(_editIcon)); }
public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo piconinfo);
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
private static extern IntPtr CreateIconIndirect(ref IconInfo icon);
private bool ShouldSerializeCancelIcon() { return(IconInfo.ShouldSerialize(_cancelIcon)); }
public static extern bool GetIconInfo(SafeIconHandle iconHandle, out IconInfo iconInfo);
internal IconInfoSafe(IconInfo iconInfo) { _iconInfo = iconInfo; }
public static Cursor CreateCursor(Bitmap bmp, Point hotspot) { if (bmp == null) return Cursors.Default; var ptr = bmp.GetHicon(); var tmp = new IconInfo(); WinAPIHelper.GetIconInfo(ptr, ref tmp); tmp.IsIcon = false; tmp.xHotspot = hotspot.X; tmp.yHotspot = hotspot.Y; ptr = WinAPIHelper.CreateIconIndirect(ref tmp); return ptr == IntPtr.Zero ? Cursors.Default : new Cursor(ptr); }
static extern IntPtr CreateIconIndirect([In] ref IconInfo iconInfo);
public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
// For SimpleSample, we draw the same simple graphics as the sample itself. static void DrawSimpleSampleIcon(CanvasDrawingSession ds, IconInfo iconInfo) { ds.DrawEllipse(155, 115, 80, 30, Colors.Black, 3); ds.DrawText("Hello, world!", 100, 100, Colors.Yellow); }
/// <summary> /// カーソルを作成する /// </summary> /// <param name="bitmap">カーソル画像</param> /// <param name="andMask">ANDマスク画像</param> /// <param name="xHotSpot">ホットスポットのX座標</param> /// <param name="yHotSpot">ホットスポットのY座標</param> /// <returns>作成したカーソル</returns> public static Cursor CreateCursor(Bitmap bitmap, Bitmap andMask, int xHotSpot, int yHotSpot) { Bitmap xorMask = new Bitmap(bitmap.Width, bitmap.Height); Color transparent = andMask.GetPixel(0, 0); for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { xorMask.SetPixel(x, y, andMask.GetPixel(x, y) == transparent ? Color.Transparent : bitmap.GetPixel(x, y)); } } IntPtr hIcon = bitmap.GetHicon(); IconInfo info = new IconInfo(); NativeMethods.GetIconInfo(hIcon, ref info); info.xHotspot = xHotSpot; info.yHotspot = yHotSpot; info.hbmMask = andMask.GetHbitmap(); info.hbmColor = xorMask.GetHbitmap(); info.fIcon = false; hIcon = NativeMethods.CreateIconIndirect(ref info); return new Cursor(hIcon); }
// Generate an icon for CompositionExample private static void DrawCompositionExampleIcon(CanvasDrawingSession ds, IconInfo iconInfo) { ds.DrawText("C", 0, 0, Colors.White); }