📄 skinengine.cs
字号:
//+--------------------------------------------------------------------------+
//| |
//| SkinEngine class |
//| |
//+--------------------------------------------------------------------------+
//| |
//| Author Patrice TERRIER |
//| copyright (c) 2006 |
//| |
//| pterrier@zapsolution.com |
//| |
//| www.zapsolution.com |
//| |
//+--------------------------------------------------------------------------+
//| Project started on : 10-17-2006 (MM-DD-YYYY) |
//| Last revised : 10-28-2006 (MM-DD-YYYY) |
//+--------------------------------------------------------------------------+
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using Win32;
namespace SkinEngine
{
class SK
{
private static string usenamespace = null;
public static string UseNameSpace
{
get { return usenamespace; }
set { usenamespace = value; }
}
private static bool ismaximized = false;
public static bool IsMaximized
{
get { return ismaximized; }
set { ismaximized = value; }
}
private static bool isresizable = true;
public static bool IsResizable
{
get { return isresizable; }
set { isresizable = value; }
}
private static bool isdocked = false;
public static bool IsDocked
{
get { return isdocked; }
set { isdocked = value; }
}
private static Color tooltipbackcolor = SystemColors.Info;
public static Color TooltipBackColor
{
get { return tooltipbackcolor; }
set { tooltipbackcolor = value; }
}
private static Color tooltipforecolor = SystemColors.InfoText;
public static Color TooltipForeColor
{
get { return tooltipforecolor; }
set { tooltipforecolor = value; }
}
private static Color colorlayerbackground;
public static Color ColorLayerBackground
{
get { return colorlayerbackground; }
set { colorlayerbackground = value; }
}
private static Color colorcaptionenabled;
public static Color ColorCaptionEnabled
{
get { return colorcaptionenabled; }
set { colorcaptionenabled = value; }
}
private static Color colorcaptiondisabled;
public static Color ColorCaptionDisabled
{
get { return colorcaptiondisabled; }
set { colorcaptiondisabled = value; }
}
private static byte opacitylayerbackground = 254;
public static byte OpacityLayerBackground
{
get { return opacitylayerbackground; }
set { opacitylayerbackground = (byte)Math.Min((byte)value, (byte)254); }
}
private static byte alpha;
public static byte Alpha
{
get { return alpha; }
set { alpha = value; }
}
private static int lastrgnwidth;
public static int LastRgnWidth
{
get { return lastrgnwidth; }
set { lastrgnwidth = value; }
}
private static int lastrgnheight;
public static int LastRgnHeight
{
get { return lastrgnheight; }
set { lastrgnheight = value; }
}
private static int fixcaptionleft;
public static int FixCaptionLeft
{
get { return fixcaptionleft; }
set { fixcaptionleft = value; }
}
private static int fixcaptionright;
public static int FixCaptionRight
{
get { return fixcaptionright; }
set { fixcaptionright = value; }
}
private static int fixcaptionheight;
public static int FixCaptionHeight
{
get { return fixcaptionheight; }
set { fixcaptionheight = value; }
}
private static int fixbottomheight;
public static int FixBottomHeight
{
get { return fixbottomheight; }
set { fixbottomheight = value; }
}
private static int dockheight; // Docking
public static int DockHeight // Docking
{
get { return dockheight; }
set { dockheight = value; }
}
private static int dockheightmax; // Docking
public static int DockHeightMax // Docking
{
get { return dockheightmax; }
set { dockheightmax = value; }
}
private static int dockmin; // Docking
public static int DockMin // Docking
{
get { return dockmin; }
set { dockmin = value; }
}
private static bool usetransprencycolortopleft = false;
public static bool UseTransparencyColorTopLeft
{
get { return usetransprencycolortopleft; }
set { usetransprencycolortopleft = value; }
}
public unsafe static GraphicsPath CreateRegion(Bitmap bitmap)
{
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF boundsF = bitmap.GetBounds(ref unit);
Rectangle bounds = new Rectangle((int)boundsF.Left, (int)boundsF.Top,
(int)boundsF.Width, (int)boundsF.Height);
Color transparencyKey;
if (UseTransparencyColorTopLeft)
{ transparencyKey = bitmap.GetPixel(0, 0); }
else
{ transparencyKey = Color.FromArgb(255, 255, 0, 255); }
uint key = (uint)((transparencyKey.A << 24) |
(transparencyKey.R << 16) |
(transparencyKey.G << 8) |
(transparencyKey.B << 0));
// Access raw bits of the image
BitmapData bitmapData = bitmap.LockBits(bounds, ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
uint* pixelPtr = (uint*)bitmapData.Scan0.ToPointer();
// Get it only once
int yMax = (int)boundsF.Height;
int xMax = (int)boundsF.Width;
// To store the rectangles
GraphicsPath path = new GraphicsPath();
for (int y = 0; y < yMax; y++)
{
// Store pointer to get next line from it
byte* basePos = (byte*)pixelPtr;
for (int x = 0; x < xMax; x++, pixelPtr++)
{ // Is it transparent?
if (*pixelPtr == key) continue; // Yes, go on with the loop
// Store where scan starts
int x0 = x;
//not transparent - scan until we find the next transparent byte
while (x < xMax && (*pixelPtr != key))
{
++x; pixelPtr++;
}
//add rectangle found to path
path.AddRectangle(new Rectangle(x0, y, x - x0, 1));
}
// Goto next line
pixelPtr = (uint*)(basePos + bitmapData.Stride);
}
bitmap.UnlockBits(bitmapData);
return path;
}
public static void CreateFormRegion(Control control, Bitmap bitmap)
{ // Bail out if either control or bitmap are null
if (control == null || bitmap == null) return;
// Cast to a Form object
Form form = (Form)control;
// Create the region
GraphicsPath path = CreateRegion(bitmap);
// Apply new region to form
form.Region = new Region(path);
// Clean up
path.Dispose();
}
// Combine child regions altogether.
public static void CombineRegion(ref IntPtr hRgnClip, IntPtr hRgn, int xOffset, int yOffset, int bmW, int bmH, int rgnX, int rgnY)
{
IntPtr hRgnTemp = Api.CreateRectRgn(0, 0, bmW, bmH);
Api.OffsetRgn(hRgnTemp, xOffset, yOffset);
Api.CombineRgn(hRgnClip, hRgnClip, hRgnTemp, Api.RGN_DIFF);
Api.OffsetRgn(hRgnTemp, -xOffset, -yOffset);
hRgnTemp = Api.CreateRectRgn(0, 0, bmW, bmH);
Api.OffsetRgn(hRgn, rgnX, rgnY);
Api.CombineRgn(hRgnTemp, hRgnTemp, hRgn, Api.RGN_AND);
Api.OffsetRgn(hRgn, -rgnX, -rgnY);
Api.OffsetRgn(hRgnTemp, xOffset, yOffset);
Api.CombineRgn(hRgnClip, hRgnClip, hRgnTemp, Api.RGN_OR);
Api.DeleteObject(hRgnTemp);
}
public static Bitmap GetBitmapFromResource(string imgName)
{
string path = string.Format("{0}.Properties.Resources", UseNameSpace);
System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager(path, typeof(SK).Assembly);
object obj = resourceManager.GetObject(imgName);
return ((System.Drawing.Bitmap)(obj));
}
private static bool ispushbutton = false;
private static bool IsPushButon
{
get { return ispushbutton; }
set { ispushbutton = value; }
}
// Public properties
public static Bitmap GetResourceBitmap(string ResourceName)
{
IsPushButon = false;
Bitmap bmp = null;
string sName = ResourceName.ToUpper();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -