Guest User

Untitled

a guest
Feb 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 35.27 KB | None | 0 0
  1. Imports System.ComponentModel
  2. Imports System.Drawing.Drawing2D
  3. Imports System.Runtime.InteropServices
  4.  
  5. #Region "Depends"
  6. #Region "Themebase"
  7. MustInherit Class customControl
  8.     Inherits Control
  9.  
  10. #Region "DECLARE"
  11.     Protected G As Graphics, B As Bitmap
  12.     Private DoneCreation As Boolean
  13.     Private InPosition As Boolean
  14.     Protected State As MouseState
  15.     Protected tp As Pen, tb As Brush
  16.  
  17.  
  18. #End Region
  19.  
  20. #Region " Initialization "
  21.     Sub New()
  22.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.SupportsTransparentBackColor, True)
  23.  
  24.         Font = New Font("Segoe UI", 9S)
  25.  
  26.     End Sub
  27.  
  28.     Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  29.         If Parent IsNot Nothing Then
  30.             OnCreation()
  31.  
  32.             DoneCreation = True
  33.         End If
  34.         MyBase.OnParentChanged(e)
  35.     End Sub
  36. #End Region
  37.  
  38. #Region "Paint"
  39.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  40.         If Width = 0 OrElse Height = 0 Then Return
  41.         tp = New Pen(Color.Transparent, 1)
  42.         tb = New SolidBrush(Color.Transparent)
  43.  
  44.         G = e.Graphics
  45.         PaintHook()
  46.         tp.Dispose() : tb.Dispose()
  47.     End Sub
  48.     Friend Function retbit() As Bitmap
  49.         If Width = 0 OrElse Height = 0 Then Return New Bitmap(0, 0)
  50.         PaintHook()
  51.         Return B
  52.     End Function
  53. #End Region
  54.  
  55. #Region " Size Handling "
  56.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  57.  
  58.  
  59.         Invalidate()
  60.         MyBase.OnSizeChanged(e)
  61.     End Sub
  62.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  63.         MyBase.SetBoundsCore(x, y, width, height, specified)
  64.     End Sub
  65. #End Region
  66.  
  67. #Region " State Handling "
  68.     Dim isdown% = 0
  69.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  70.         InPosition = True
  71.         SetState(MouseState.Over)
  72.         For Each c As Control In Parent.Controls
  73.             If TypeOf c Is customControl Then
  74.                 DirectCast(c, customControl).leavemouse(e)
  75.                 c.Invalidate()
  76.             End If
  77.         Next
  78.         MyBase.OnMouseEnter(e)
  79.     End Sub
  80.     Public Sub leavemouse(e As EventArgs)
  81.         OnMouseLeave(e)
  82.     End Sub
  83.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  84.         MyBase.OnMouseUp(e)
  85.         If InPosition Then SetState(MouseState.Over)
  86.         isdown = 0
  87.     End Sub
  88.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  89.         MyBase.OnMouseDown(e)
  90.         If e.Button = MouseButtons.Left Then SetState(MouseState.Down)
  91.         isdown = 1
  92.     End Sub
  93.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  94.         InPosition = False
  95.         SetState(MouseState.None)
  96.         MyBase.OnMouseLeave(e)
  97.     End Sub
  98.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  99.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  100.         MyBase.OnEnabledChanged(e)
  101.     End Sub
  102.     Private Sub SetState(ByVal current As MouseState)
  103.         State = current
  104.         Invalidate()
  105.     End Sub
  106.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  107.         MyBase.OnMouseMove(e)
  108.         If isdown Then mousedownmove(e)
  109.     End Sub
  110.     Protected Overridable Sub mousedownmove(e As MouseEventArgs)
  111.     End Sub
  112. #End Region
  113.  
  114. #Region " Property Helpers "
  115.     Protected Overridable Sub InvalidateBitmap()
  116.         If Width = 0 OrElse Height = 0 Then Return
  117.         B = New Bitmap(Width, Height, Imaging.PixelFormat.Format32bppPArgb)
  118.         G = Graphics.FromImage(B)
  119.     End Sub
  120.  
  121. #End Region
  122.  
  123. #Region " User Hooks "
  124.  
  125.     Protected MustOverride Sub PaintHook()
  126.  
  127.     Protected Overridable Sub OnCreation()
  128.     End Sub
  129. #End Region
  130.  
  131.  
  132. End Class
  133. #End Region
  134.  
  135. Public Module publicvars
  136.  
  137.     Public Enum MouseState As Byte
  138.         None = 0
  139.         Over = 1
  140.         Down = 2
  141.         Block = 3
  142.     End Enum
  143.     <DllImport("user32.dll", SetLastError:=True)> Public Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger) As Boolean
  144.     End Function
  145.  
  146. #Region "LAYER"
  147.     Public Const AC_SRC_OVER As Byte = 0
  148.     Public Const AC_SRC_ALPHA As Byte = 1
  149.     Public Const ULW_ALPHA As Int32 = 2
  150.  
  151.     Public Declare Auto Function CreateCompatibleDC Lib "gdi32.dll" (hDC As IntPtr) As IntPtr
  152.     Public Declare Auto Function GetDC Lib "user32.dll" (hWnd As IntPtr) As IntPtr
  153.  
  154.     <DllImport("gdi32.dll", ExactSpelling:=True)>
  155.     Public Function SelectObject(hDC As IntPtr, hObj As IntPtr) As IntPtr
  156.     End Function
  157.  
  158.     <DllImport("user32.dll", ExactSpelling:=True)>
  159.     Public Function ReleaseDC(hWnd As IntPtr, hDC As IntPtr) As Integer
  160.     End Function
  161.  
  162.     Public Declare Auto Function DeleteDC Lib "gdi32.dll" (hDC As IntPtr) As Integer
  163.     Public Declare Auto Function DeleteObject Lib "gdi32.dll" (hObj As IntPtr) As Integer
  164.     Public Declare Auto Function UpdateLayeredWindow Lib "user32.dll" (hwnd As IntPtr, hdcDst As IntPtr, ByRef pptDst As Point32, ByRef psize As Size32, hdcSrc As IntPtr, ByRef pptSrc As Point32, crKey As Int32, ByRef pblend As BLENDFUNCTION, dwFlags As Int32) As Integer
  165.     Public Declare Auto Function ExtCreateRegion Lib "gdi32.dll" (lpXform As IntPtr, nCount As UInteger, rgnData As IntPtr) As IntPtr
  166.  
  167.     <StructLayout(LayoutKind.Sequential)>
  168.     Public Structure Size32
  169.         Public cx As Int32
  170.         Public cy As Int32
  171.  
  172.         Public Sub New(x As Int32, y As Int32)
  173.             cx = x
  174.             cy = y
  175.         End Sub
  176.     End Structure
  177.  
  178.     <StructLayout(LayoutKind.Sequential, Pack:=1)>
  179.     Public Structure BLENDFUNCTION
  180.         Public BlendOp As Byte
  181.         Public BlendFlags As Byte
  182.         Public SourceConstantAlpha As Byte
  183.         Public AlphaFormat As Byte
  184.     End Structure
  185.  
  186.     <StructLayout(LayoutKind.Sequential)>
  187.     Public Structure Point32
  188.         Public x As Int32
  189.         Public y As Int32
  190.  
  191.         Public Sub New(x As Int32, y As Int32)
  192.             Me.x = x
  193.             Me.y = y
  194.         End Sub
  195.     End Structure
  196.  
  197.     Public Sub SetBits(B As Drawing.Bitmap, handle As IntPtr, toplocpt As Point32, opacity!)
  198.  
  199.         Dim oldBits As IntPtr = IntPtr.Zero
  200.         Dim screenDC As IntPtr = GetDC(IntPtr.Zero)
  201.         Dim hBitmap As IntPtr = IntPtr.Zero
  202.         Dim memDc As IntPtr = CreateCompatibleDC(screenDC)
  203.  
  204.         Try
  205.             Dim topLoc As Point32 = toplocpt
  206.             Dim bitMapSize As New Size32(B.Width, B.Height)
  207.             Dim blendFunc As New BLENDFUNCTION()
  208.             Dim srcLoc As New Point32(0, 0)
  209.  
  210.             hBitmap = B.GetHbitmap(Drawing.Color.FromArgb(0))
  211.             oldBits = SelectObject(memDc, hBitmap)
  212.  
  213.             blendFunc.BlendOp = AC_SRC_OVER
  214.             blendFunc.SourceConstantAlpha = opacity * 255
  215.             blendFunc.AlphaFormat = AC_SRC_ALPHA
  216.             blendFunc.BlendFlags = 0
  217.  
  218.             UpdateLayeredWindow(handle, screenDC, topLoc, bitMapSize, memDc, srcLoc, 0, blendFunc, ULW_ALPHA)
  219.         Finally
  220.             If hBitmap <> IntPtr.Zero Then
  221.                 SelectObject(memDc, oldBits)
  222.                 DeleteObject(hBitmap)
  223.             End If
  224.             ReleaseDC(IntPtr.Zero, screenDC)
  225.             DeleteDC(memDc)
  226.         End Try
  227.     End Sub
  228.  
  229. #End Region
  230.  
  231.  
  232. End Module
  233.  
  234. Public Class LayeredForm : Inherits Form
  235.     Protected Shadows ParentForm As Form
  236.     Private styles As ControlStyles
  237.     Public Sub New(ByRef Parent As Form)
  238.         SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor Or ControlStyles.ResizeRedraw Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  239.         DoubleBuffered = True
  240.         Me.ParentForm = Parent
  241.         ControlBox = False
  242.         AddOwnedForm(ParentForm)
  243.         AddHandler ParentForm.FormClosing, AddressOf Dispose
  244.     End Sub
  245.  
  246.     Public Sub New(ByRef Parent As Form, Styles As ControlStyles)
  247.         Me.New(Parent)
  248.         Me.styles = Styles
  249.     End Sub
  250.  
  251.     Protected Overrides ReadOnly Property CreateParams() As CreateParams
  252.         Get
  253.             Dim cParms As CreateParams = MyBase.CreateParams
  254.             cParms.ExStyle = cParms.ExStyle Or 524288 Or styles
  255.             Return cParms
  256.         End Get
  257.     End Property
  258.     Public Sub SetBits(B As Bitmap)
  259.         If Not IsHandleCreated Or DesignMode Then Exit Sub
  260.  
  261.         If Not Bitmap.IsCanonicalPixelFormat(B.PixelFormat) OrElse Not Bitmap.IsAlphaPixelFormat(B.PixelFormat) Then
  262.             Throw New ApplicationException("The picture must be 32bit picture with alpha channel.")
  263.         End If
  264.  
  265.         Dim oldBits As IntPtr = IntPtr.Zero
  266.         Dim screenDC As IntPtr = GetDC(IntPtr.Zero)
  267.         Dim hBitmap As IntPtr = IntPtr.Zero
  268.         Dim memDc As IntPtr = CreateCompatibleDC(screenDC)
  269.  
  270.         Try
  271.             Dim topLoc As New Point32(Left, Top)
  272.             Dim bitMapSize As New Size32(B.Width, B.Height)
  273.             Dim blendFunc As New BLENDFUNCTION()
  274.             Dim srcLoc As New Point32(0, 0)
  275.  
  276.             hBitmap = B.GetHbitmap(Color.FromArgb(0))
  277.             oldBits = SelectObject(memDc, hBitmap)
  278.  
  279.             blendFunc.BlendOp = AC_SRC_OVER
  280.             blendFunc.SourceConstantAlpha = 255
  281.             blendFunc.AlphaFormat = AC_SRC_ALPHA
  282.             blendFunc.BlendFlags = 0
  283.  
  284.             UpdateLayeredWindow(Handle, screenDC, topLoc, bitMapSize, memDc, srcLoc,
  285.              0, blendFunc, ULW_ALPHA)
  286.         Finally
  287.             If hBitmap <> IntPtr.Zero Then
  288.                 SelectObject(memDc, oldBits)
  289.                 DeleteObject(hBitmap)
  290.             End If
  291.             ReleaseDC(IntPtr.Zero, screenDC)
  292.             DeleteDC(memDc)
  293.         End Try
  294.     End Sub
  295. End Class
  296.  
  297. Public Class ShadowForm
  298.     Inherits LayeredForm
  299.  
  300.     Public ShadowSize As Integer
  301.  
  302. #Region "Ctor"
  303.     Public Sub New(ByRef Parent As Form, ByVal ShadowSize As Integer)
  304.  
  305.         MyBase.New(Parent, 128 Or 134217728 Or 32)
  306.  
  307.         SetStyle(ControlStyles.Selectable Or ControlStyles.StandardClick Or ControlStyles.StandardDoubleClick Or ControlStyles.Opaque, False)
  308.  
  309.         Me.ShadowSize = ShadowSize
  310.  
  311.         FormBorderStyle = FormBorderStyle.None
  312.         ShowInTaskbar = False
  313.         Text = ""
  314.  
  315.  
  316.         AddHandler Parent.Resize, Sub() UpdateBounds()
  317.         AddHandler Parent.Move, Sub() UpdateBounds()
  318.         AddHandler Parent.Layout, Sub() UpdateBounds()
  319.     End Sub
  320. #End Region
  321.  
  322.  
  323.     Public Shadows Sub UpdateBounds()
  324.         SetWindowPos(Handle, ParentForm.Handle, ParentForm.Left - ShadowSize, ParentForm.Top - ShadowSize + 5, ParentForm.Width + ShadowSize * 2 + 1, ParentForm.Height + ShadowSize * 2, &H20)
  325.     End Sub
  326.  
  327.  
  328. End Class
  329.  
  330. Public Module helpers
  331.     Friend Function col(a!, r!, g!, b!, sat!) As Color
  332.         Return Color.FromArgb(CByte(CInt(a)), CByte(Math.Min(255, Math.Max(0, CInt(r) * sat))), CByte(Math.Min(255, Math.Max(0, CInt(g) * sat))), CByte(Math.Min(255, Math.Max(0, CInt(b) * sat))))
  333.     End Function
  334.     Friend Function col(a!, r!, g!, b!) As Color
  335.         Return col(a, r, g, b, 1)
  336.     End Function
  337.     Friend Function col(r As Byte, g As Byte, b As Byte) As Color
  338.         Return col(255, r, g, b)
  339.     End Function
  340.     Friend Function col(n As Byte) As Color
  341.         Return col(n, n, n)
  342.     End Function
  343.     Friend Function col(a As Byte, n As Byte) As Color
  344.         Return col(a, n, n, n)
  345.     End Function
  346.     Friend Function col(a As Byte, c As Color) As Color
  347.         Return col(a, c.R, c.G, c.B, 1)
  348.     End Function
  349.     Friend Function hsltorgb(h!, s!, l!) As Color
  350.         Dim c!, k!, m!
  351.         c = (1 - Math.Abs(2 * l - 1)) * s
  352.         k = c * (1 - Math.Abs(((h / 60) Mod 2) - 1))
  353.         m = l - c / 2
  354.         Return cyltorgb(c, k, m, h)
  355.     End Function
  356.     Friend Function hsvtorgb(h!, s!, v!) As Color
  357.         Dim c!, k!, m!
  358.         c = v * s
  359.         k = c * (1 - Math.Abs(((h / 60) Mod 2) - 1))
  360.         m = v - c
  361.         Return cyltorgb(c, k, m, h)
  362.     End Function
  363.     Private Function cyltorgb(c!, k!, m!, h!) As Color
  364.         Dim rd() = {c, k, 0, 0, k, c}
  365.         Dim gd() = {k, c, c, k, 0, 0}
  366.         Dim bd() = {0, 0, k, c, c, k}
  367.         Dim t = Math.Ceiling(h / 60)
  368.         If t <= 0 Then t = 0 Else t -= 1
  369.         Return col((rd(t) + m) * 255, (gd(t) + m) * 255, (bd(t) + m) * 255)
  370.     End Function
  371.  
  372.     Friend Function rgbtohsv(r!, g!, b!) As Single()
  373.         Dim cmax!, cmin!, rd!, gd!, bd!, del!
  374.         Dim h!, s!, v!
  375.  
  376.         rd = r / 255 : gd = g / 255 : bd = b / 255
  377.         cmax = Math.Max(Math.Max(rd, gd), bd)
  378.         cmin = Math.Min(Math.Min(rd, gd), bd)
  379.         del = cmax - cmin
  380.  
  381.         If Not del = 0 Then
  382.             If cmax = rd Then h = 60 * (((gd - bd) / del) Mod 6)
  383.             If cmax = gd Then h = 60 * ((bd - rd) / del + 2)
  384.             If cmax = bd Then h = 60 * ((rd - gd) / del + 4)
  385.         Else
  386.             h = 0
  387.         End If
  388.         If cmax = 0 Then s = 0 Else s = del / cmax
  389.  
  390.         v = cmax
  391.  
  392.         If h < 0 Then h = 360 + h   'bug where h becomes -ve
  393.  
  394.         Return {h, s, v}
  395.     End Function
  396.     Friend Function rescol(c As Color) As Color
  397.         'Dim t = (Val(CStr(c.R)) + Val(CStr(c.G)) + Val(CStr(c.B))) / 3 '               stupid bug
  398.         Dim t = (CInt(CByte(c.R)) + CInt(CByte(c.G)) + CInt(CByte(c.B))) / 3
  399.         If t < 128 Then Return Color.White Else Return Color.Black
  400.     End Function
  401.  
  402.     'lum = Y=0.3RED+0.59GREEN+0.11Blue   rgb(y,y,y)
  403.     Friend Function invert(c As Color) As Color
  404.         Return col(CByte(CInt(c.A)), CByte(CInt(255 - c.R)), CByte(CInt(255 - c.G)), CByte(CInt(255 - c.B)))
  405.     End Function
  406.     Friend Sub mp(c As Color, ByRef p As Pen)
  407.         p = New Pen(c)
  408.     End Sub
  409.  
  410.     Friend Sub mb(c As Color, ByRef b As SolidBrush)
  411.         b = New SolidBrush(c)
  412.     End Sub
  413.  
  414.     Function rct(x!, y!, w!, h!) As Rectangle
  415.         Return New Rectangle(x, y, w, h)
  416.     End Function
  417.     Function rct(lgb As LinearGradientBrush, Optional xshift! = 0, Optional yshift! = 0, Optional WidthShift! = 0, Optional HeightShift! = 0) As Rectangle
  418.         Dim r = lgb.Rectangle
  419.         Return rct(r.X + xshift, r.Y + yshift, r.Width + WidthShift, r.Height + HeightShift)
  420.     End Function
  421.     Friend Function pt(x!, y!) As Point
  422.         Return New Point(x, y)
  423.     End Function
  424.     Friend Function rgbtohex(c As Color) As String
  425.         Return ColorTranslator.ToHtml(c)
  426.     End Function
  427.     Friend Function hextorgb(hex As String) As Color
  428.         Return ColorTranslator.FromHtml(hex)
  429.     End Function
  430.  
  431. #Region "Math!"
  432.     Public Function clamp#(v#, l#, h#)
  433.         Return Math.Min(h, Math.Max(l, v))
  434.     End Function
  435. #End Region
  436.  
  437.     <DllImport("gdi32.dll", SetLastError:=True)>
  438.     Public Function GetPixel(hdc As IntPtr,
  439.               nXPos As Integer,
  440.               nYPos As Integer) As UInteger
  441.     End Function
  442.     Public Function GetPixelColor(ByVal x As Integer, ByVal y As Integer) As System.Drawing.Color
  443.         Dim hdc As IntPtr = GetDC(IntPtr.Zero)
  444.         Dim pixel As UInteger = GetPixel(hdc, x, y)
  445.         ReleaseDC(IntPtr.Zero, hdc)
  446.         Dim color As Color = Color.FromArgb(CInt(Fix(pixel And &HFF)), CInt(Fix(pixel And &HFF00)) >> 8, CInt(Fix(pixel And &HFF0000)) >> 16)
  447.         Return color
  448.     End Function
  449.  
  450.     Public Class MouseHook
  451.         Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As MouseProcDelegate, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
  452.         Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As MSLLHOOKSTRUCT) As Integer
  453.         Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
  454.         Private Delegate Function MouseProcDelegate(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As MSLLHOOKSTRUCT) As Integer
  455.  
  456.         Private Structure MSLLHOOKSTRUCT
  457.             Public pt As Point
  458.             Public mouseData As Integer
  459.             Public flags As Integer
  460.             Public time As Integer
  461.             Public dwExtraInfo As Integer
  462.         End Structure
  463.  
  464.         Public Enum Wheel_Direction
  465.             WheelUp
  466.             WheelDown
  467.         End Enum
  468.  
  469.         Private Const HC_ACTION As Integer = 0
  470.         Private Const WH_MOUSE_LL As Integer = 14
  471.         Private Const WM_MOUSEMOVE As Integer = &H200
  472.         Private Const WM_LBUTTONDOWN As Integer = &H201
  473.         Private Const WM_LBUTTONUP As Integer = &H202
  474.         Private Const WM_LBUTTONDBLCLK As Integer = &H203
  475.         Private Const WM_RBUTTONDOWN As Integer = &H204
  476.         Private Const WM_RBUTTONUP As Integer = &H205
  477.         Private Const WM_RBUTTONDBLCLK As Integer = &H206
  478.         Private Const WM_MBUTTONDOWN As Integer = &H207
  479.         Private Const WM_MBUTTONUP As Integer = &H208
  480.         Private Const WM_MBUTTONDBLCLK As Integer = &H209
  481.         Private Const WM_MOUSEWHEEL As Integer = &H20A
  482.  
  483.         Private MouseHook As Integer
  484.         Private MouseHookDelegate As MouseProcDelegate
  485.  
  486.         Public Event Mouse_Move(ByVal ptLocat As Point)
  487.         Public Event Mouse_Left_Down(ByVal ptLocat As Point)
  488.         Public Event Mouse_Left_Up(ByVal ptLocat As Point)
  489.         Public Event Mouse_Left_DoubleClick(ByVal ptLocat As Point)
  490.         Public Event Mouse_Right_Down(ByVal ptLocat As Point)
  491.         Public Event Mouse_Right_Up(ByVal ptLocat As Point)
  492.         Public Event Mouse_Right_DoubleClick(ByVal ptLocat As Point)
  493.         Public Event Mouse_Middle_Down(ByVal ptLocat As Point)
  494.         Public Event Mouse_Middle_Up(ByVal ptLocat As Point)
  495.         Public Event Mouse_Middle_DoubleClick(ByVal ptLocat As Point)
  496.         Public Event Mouse_Wheel(ByVal ptLocat As Point, ByVal Direction As Wheel_Direction)
  497.  
  498.         Public Sub New()
  499.             MouseHookDelegate = New MouseProcDelegate(AddressOf MouseProc)
  500.             MouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookDelegate, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
  501.         End Sub
  502.  
  503.         Private Function MouseProc(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As MSLLHOOKSTRUCT) As Integer
  504.             If (nCode = HC_ACTION) Then
  505.                 Select Case wParam
  506.                     Case WM_MOUSEMOVE
  507.                         RaiseEvent Mouse_Move(lParam.pt)
  508.                     Case WM_LBUTTONDOWN
  509.                         RaiseEvent Mouse_Left_Down(lParam.pt)
  510.                     Case WM_LBUTTONUP
  511.                         RaiseEvent Mouse_Left_Up(lParam.pt)
  512.                     Case WM_LBUTTONDBLCLK
  513.                         RaiseEvent Mouse_Left_DoubleClick(lParam.pt)
  514.                     Case WM_RBUTTONDOWN
  515.                         RaiseEvent Mouse_Right_Down(lParam.pt)
  516.                     Case WM_RBUTTONUP
  517.                         RaiseEvent Mouse_Right_Up(lParam.pt)
  518.                     Case WM_RBUTTONDBLCLK
  519.                         RaiseEvent Mouse_Right_DoubleClick(lParam.pt)
  520.                     Case WM_MBUTTONDOWN
  521.                         RaiseEvent Mouse_Middle_Down(lParam.pt)
  522.                     Case WM_MBUTTONUP
  523.                         RaiseEvent Mouse_Middle_Up(lParam.pt)
  524.                     Case WM_MBUTTONDBLCLK
  525.                         RaiseEvent Mouse_Middle_DoubleClick(lParam.pt)
  526.                     Case WM_MOUSEWHEEL
  527.                         Dim wDirection As Wheel_Direction
  528.                         If lParam.mouseData < 0 Then
  529.                             wDirection = Wheel_Direction.WheelDown
  530.                         Else
  531.                             wDirection = Wheel_Direction.WheelUp
  532.                         End If
  533.                         RaiseEvent Mouse_Wheel(lParam.pt, wDirection)
  534.                 End Select
  535.             End If
  536.             Return CallNextHookEx(MouseHook, nCode, wParam, lParam)
  537.         End Function
  538.  
  539.         Protected Overrides Sub Finalize()
  540.             UnhookWindowsHookEx(MouseHook)
  541.             MyBase.Finalize()
  542.         End Sub
  543.     End Class
  544.  
  545.  
  546. End Module
  547.  
  548. #End Region
  549.  
  550. #Region "Components"
  551.  
  552.  
  553. <ToolboxItem(False)> Class picker : Inherits customControl
  554. #Region "DECLARE"
  555.     Public Property DontChange As Boolean = False
  556.     Private hp() As Byte = {0, 0}
  557.     Private tbt() As Bitmap = {New Bitmap(20, 360), New Bitmap(20, 200)}
  558.     Private ia() As Byte = {1, 1, 1}
  559.     Public Event ColorChanged()
  560.     Private _h! : Public Property h!
  561.         Get
  562.             Return clamp(_y2, 0, 200) * 1.8
  563.         End Get
  564.         Set(value!)
  565.             If DontChange Then Return
  566.             _h = value
  567.             _y2 = clamp(value, 0, 360) / 360 * 200
  568.             ia(0) = 1
  569.             ia(1) = 1
  570.             Invalidate()
  571.             Debug.WriteLine("p" + CStr(_h))
  572.         End Set
  573.     End Property
  574.     Private _s! : Public Property s!
  575.         Get
  576.             Return clamp(_x, 0, 200) / 200
  577.         End Get
  578.         Set(value!)
  579.             If DontChange Then Return
  580.             _s = clamp(value, 0, 1)
  581.             _x = clamp(_s * 200, 0, 200)
  582.             ia(0) = 1
  583.             Invalidate()
  584.         End Set
  585.     End Property
  586.     Private _v! : Public Property v!
  587.         Get
  588.             Return clamp((200 - _y1), 0, 200) / 200
  589.         End Get
  590.         Set(value!)
  591.             If DontChange Then Return
  592.             _v = clamp(value, 0, 1)
  593.             _y1 = clamp(200 - _v * 200, 0, 200)
  594.             ia(0) = 1
  595.             Invalidate()
  596.         End Set
  597.     End Property
  598.     Private _a! : Public Property a!
  599.         Get
  600.             Return clamp(_y3, 0, 200) / 200 * 255
  601.         End Get
  602.         Set(value!)
  603.             If DontChange Then Return
  604.             _a = clamp(value, 0, 255)
  605.             _y3 = clamp(_a / 255 * 200, 0, 200)
  606.             ia(2) = 1
  607.             Invalidate()
  608.         End Set
  609.     End Property
  610.     Private _x!, _y1!, _y2!, _y3!
  611. #End Region
  612. #Region "CTOR"
  613.     Sub New(h!, s!, v!, a!)
  614.         Me.h = h
  615.         Me.s = s
  616.         Me.v = v
  617.         Me.a = a
  618.         Left = 0 : Top = 0
  619.         Width = 250 : Height = 200
  620.     End Sub
  621. #End Region
  622. #Region "PAINT"
  623.     Protected Overrides Sub PaintHook()
  624.  
  625.         G.Clear(col(51))
  626.  
  627.         If ia(0) Then
  628.             G.SetClip(rct(0, 0, 200, 200))
  629.             G.Clear(Color.White)
  630.             'Debug.Write(h)
  631.             Dim l1 As New LinearGradientBrush(rct(0, 0, 200, 200), col(0, 0), hsvtorgb(h, 1, 1), 0)
  632.             Dim l2 As New LinearGradientBrush(rct(l1), col(0, 0), col(0), 90)
  633.             G.FillRectangle(l1, rct(l1))
  634.             G.FillRectangle(l2, rct(l2))
  635.  
  636.             G.SmoothingMode = 2
  637.  
  638.             mp(col(150, invert(rescol(hsvtorgb(360 - h, 0, 1 - v)))), tp)
  639.             G.SetClip(rct(_x - 1, _y1 - 1, 3, 3), CombineMode.Exclude)
  640.             G.DrawLine(tp, 0, _y1, 200, _y1)
  641.             G.DrawLine(tp, _x, 0, _x, 200)
  642.             G.ResetClip()
  643.             G.DrawRectangle(tp, rct(_x - 2, _y1 - 2, 4, 4))
  644.         End If 'map
  645.  
  646.  
  647.         If Not hp(0) Then
  648.             With Graphics.FromImage(tbt(0))
  649.                 .Clear(Color.Transparent)
  650.                 For i = 0 To 359
  651.                     mp(hsvtorgb(i, 1, 1), tp)
  652.                     .DrawLine(tp, 0, i, 20, i)
  653.                 Next
  654.             End With
  655.             hp(0) = 1
  656.         End If
  657.  
  658.         If ia(1) Then
  659.             G.SetClip(rct(211, 0, 20, 200))
  660.             G.Clear(Color.White)
  661.             G.DrawImage(tbt(0), 211, 0, 20, 200)
  662.             mp(Color.Black, tp)
  663.             G.SmoothingMode = 2
  664.             G.DrawLine(tp, 211, _y2, 231, _y2)
  665.             mb(Color.Black, tb)
  666.             G.FillPolygon(tb, {pt(210, _y2 - 5), pt(210 + 5, _y2), pt(210, _y2)})
  667.             G.FillPolygon(tb, {pt(210, _y2 + 5), pt(210 + 5, _y2), pt(210, _y2)})
  668.             G.ResetClip()
  669.         End If 'hue
  670.  
  671.  
  672.         If ia(2) Then
  673.             G.SetClip(rct(231, 0, 20, 200))
  674.             G.Clear(col(51))
  675.             For i = 0 To 9
  676.                 mb(col(50, 255), tb)
  677.                 G.FillRectangle(tb, rct(231, i * 20, 10, 10))
  678.                 G.FillRectangle(tb, rct(241, i * 20 + 10, 10, 10))
  679.             Next
  680.             Dim l As New LinearGradientBrush(rct(231, 0, 20, 200), col(0, 0), hsvtorgb(h, s, v), 90)
  681.             G.SmoothingMode = 2
  682.             G.FillRectangle(l, rct(l))
  683.             mp(invert(hsvtorgb(h, s, v)), tp)
  684.             G.DrawLine(tp, 231, _y3, 251, _y3)
  685.             mb(invert(rescol(hsvtorgb(360 - h, 0, 1 - v))), tb)
  686.             G.FillPolygon(tb, {pt(230, _y3 - 5), pt(230 + 5, _y3), pt(230, _y3)})
  687.             G.FillPolygon(tb, {pt(230, _y3 + 5), pt(230 + 5, _y3), pt(230, _y3)})
  688.             G.ResetClip()
  689.         End If 'alpha
  690.  
  691.  
  692.     End Sub
  693. #End Region
  694. #Region "INPUT"
  695.     Protected Overrides Sub OnClick(e As EventArgs)
  696.         MyBase.OnClick(e)
  697.         mousedownmove(e)
  698.     End Sub
  699.     Protected Overrides Sub mousedownmove(e As MouseEventArgs)
  700.         MyBase.mousedownmove(e)
  701.         If Not (e.Y > -1 Or e.Y < 211) Then Return
  702.         'ia(0) = 0 : ia(1) = 0 : ia(2) = 0
  703.         If e.X > -1 And e.X < 211 Then
  704.             _x = e.X
  705.             _y1 = e.Y
  706.             ia(0) = 1
  707.             Invalidate(rct(-1, -1, 211, 211))
  708.             Invalidate(rct(231, 0, 20, 200))
  709.         ElseIf e.X > 200 And e.X < 231 Then
  710.             _y2 = e.Y
  711.             ia(1) = 1
  712.             Invalidate(rct(-1, 0, 232, 200))
  713.         ElseIf e.X > 230 And e.X < 251 Then
  714.             _y3 = e.Y
  715.             ia(2) = 1
  716.             Invalidate(rct(231, 0, 20, 200))
  717.         End If
  718.         RaiseEvent ColorChanged()
  719.     End Sub
  720. #End Region
  721. End Class
  722. Class preview : Inherits LayeredForm
  723.     Public Sub New(ByRef Parent As Form)
  724.         MyBase.New(Parent, 128)
  725.         ShowInTaskbar = 0
  726.         Text = ""
  727.         Top = 0
  728.         Opacity = 1
  729.         FormBorderStyle = 0
  730.         AddHandler Parent.Move, Sub() updatebounds()
  731.  
  732.     End Sub
  733.     Shadows Sub updatebounds()
  734.         SetWindowPos(Handle, ParentForm.Handle, ParentForm.Left + 15, ParentForm.Top + 200 + 9, 250, 45, &H20)
  735.     End Sub
  736.     Protected Overrides Sub OnClick(e As EventArgs)
  737.         MyBase.OnClick(e)
  738.         ParentForm.Close()
  739.         Me.Close()
  740.     End Sub
  741. End Class
  742.  
  743. #End Region
  744.  
  745.  
  746.  
  747. Class customColorPicker : Inherits Form
  748. #Region "DECLARE"
  749.     Dim dc% = -1
  750.     Dim p As New picker(255, 0, 0, 0)
  751.     Dim t(4) As NumericUpDown
  752.     Dim hext As TextBox = New TextBox() With {.BackColor = col(255), .ForeColor = col(51), .Left = 387, .Width = 100, .BorderStyle = BorderStyle.FixedSingle, .Top = 70}
  753.     Dim l(2) As Label
  754.     Private Shadow As New ShadowForm(Me, 14)
  755.     Dim pr As preview = New preview(Shadow)
  756.     Public Property Color As Color
  757.     Dim eb As New Button With {.Left = 300, .Top = 120}
  758. #End Region
  759.  
  760.     Sub New()
  761.  
  762.         TransparencyKey = Color.Fuchsia
  763.  
  764.         Controls.Add(p)
  765.         AddHandler p.ColorChanged, AddressOf ColorChangedbypicker
  766.  
  767.         Dim s() As Char = {"R", "G", "B", "A"}
  768.  
  769.  
  770.         For i = 1 To 4
  771.             t(i - 1) = New NumericUpDown With {.TabIndex = i - 1, .Left = 14 * i + 45 * (i - 1) + 250, .Top = 30, .BorderStyle = BorderStyle.FixedSingle,
  772.                                         .BackColor = col(255), .ForeColor = col(51), .Width = 45, .Font = New Font("Consolas", 10), .Minimum = 0, .Maximum = 255}
  773.             Controls.Add(t(i - 1))
  774.             AddHandler t(i - 1).ValueChanged, AddressOf ColorChangedbytextrgb
  775.         Next
  776.  
  777.         l(0) = New Label With {.Left = 250 + 14, .Top = 10, .ForeColor = col(51), .Font = New Font("Consolas", 10), .Text = "  R      G       B      A", .Width = 250}
  778.         Controls.Add(l(0))
  779.         l(1) = New Label With {.Left = 250 + 14, .Top = 70, .ForeColor = col(51), .Font = New Font("Consolas", 10), .Text = "HEX :", .Width = 50}
  780.         Controls.Add(l(1))
  781.  
  782.         Controls.Add(hext)
  783.         AddHandler hext.TextChanged, AddressOf colorchangebytexthex
  784.  
  785.         Controls.Add(eb)
  786.         AddHandler eb.Click, AddressOf ed
  787.  
  788.     End Sub
  789.     Dim mh As New MouseHook
  790.     Sub ed()
  791.         AddHandler mh.Mouse_Move, AddressOf mm
  792.     End Sub
  793.     Sub mm()
  794.         Color = GetPixelColor(Cursor.Position.X, Cursor.Position.Y)
  795.         dc = 3
  796.         Dim hsv() As Single = rgbtohsv(Color.R, Color.G, Color.B)
  797.         p.h = hsv(0)
  798.         p.s = hsv(1)
  799.         p.v = hsv(2)
  800.         p.a = Color.A
  801.         dc = -1
  802.     End Sub
  803.     Sub ColorChangedbypicker()
  804.         If dc > -1 Then Return
  805.         dc = 0
  806.         Color = col(p.a, hsvtorgb(p.h, p.s, p.v))
  807.         t(0).Value = Color.R
  808.         t(1).Value = Color.G
  809.         t(2).Value = Color.B
  810.         t(3).Value = Color.A
  811.         Dim hexalpha As String = Hex(Color.A)
  812.         If hexalpha.Length = 1 Then hexalpha = "0" + hexalpha
  813.         hext.Text = "#" + hexalpha + rgbtohex(Color).Remove(0, 1)
  814.         drawpreview()
  815.         dc = -1
  816.     End Sub
  817.     Sub ColorChangedbytextrgb()
  818.         If dc > -1 Then Return
  819.         dc = 1
  820.         p.DontChange = False
  821.         Color = col(t(3).Value, t(0).Value, t(1).Value, t(2).Value)
  822.  
  823.         Dim hexalpha As String = Hex(Color.A)
  824.         If hexalpha.Length = 1 Then hexalpha = "0" + hexalpha
  825.         hext.Text = "#" + hexalpha + rgbtohex(Color).Remove(0, 1)
  826.         drawpreview()
  827.         dc = -1
  828.     End Sub
  829.     Sub colorchangebytexthex()
  830.         If dc > -1 Then Return
  831.         dc = 2
  832.         Dim th$ = hext.Text
  833.         If hext.Text.Length = 1 Then th = hext.Text + "0"
  834.         Color = hextorgb(th)
  835.         Dim hsv() As Single = rgbtohsv(Color.R, Color.G, Color.B)
  836.         p.h = hsv(0)
  837.         p.s = hsv(1)
  838.         p.v = hsv(2)
  839.         p.a = Color.A
  840.         t(0).Value = Color.R
  841.         t(1).Value = Color.G
  842.         t(2).Value = Color.B
  843.         t(3).Value = Color.A
  844.         dc = -1
  845.     End Sub
  846. #Region "Other"
  847.     Sub bye()
  848.         Close()
  849.     End Sub
  850.  
  851. #Region "Move"
  852.     Dim mouseOffset As Point
  853.  
  854.     Private Sub Me_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
  855.         mouseOffset = New Point(-e.X, -e.Y)
  856.     End Sub
  857.  
  858.     Private Sub Me_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
  859.  
  860.         If e.Button = MouseButtons.Left Then
  861.             Dim mousePos = Control.MousePosition
  862.             mousePos.Offset(mouseOffset.X, mouseOffset.Y)
  863.             Location = mousePos
  864.         End If
  865.     End Sub
  866. #End Region
  867. #Region "LOAD/CLOSE"
  868.     Protected Overrides Sub OnCreateControl()
  869.         MyBase.OnCreateControl()
  870.         FormBorderStyle = 0
  871.         BackColor = col(245)
  872.         SetWindowPos(Handle, vbNull, Cursor.Position.X - 120, Cursor.Position.Y - 120, 500, 245, &H20)
  873.         DrawShadow()
  874.     End Sub
  875.     Protected Overrides Sub OnLoad(e As EventArgs)
  876.         MyBase.OnLoad(e)
  877.         drawpreview()
  878.         Shadow.Show()
  879.         pr.Visible = 1
  880.         pr.Show()
  881.     End Sub
  882. #End Region
  883. #Region "SHADOW"
  884. #Region "declare"
  885.     Private Rounding!
  886. #End Region
  887.     Public op# = 1.0#
  888.     Private Sub DrawShadow()
  889.         If DesignMode Or IsHandleCreated = False Then Exit Sub
  890.         Dim B As New Bitmap(CInt(Shadow.Size.Width), CInt(Shadow.Size.Height))
  891.         Dim G As Graphics = Graphics.FromImage(B)
  892.         G.InterpolationMode = 7
  893.         G.SmoothingMode = 2 : G.PixelOffsetMode = 2
  894.         Shadow.BackColor = Color.Black
  895.         Static br As SolidBrush
  896.         With G
  897.             Dim s = Shadow.ShadowSize
  898.             .SetClip(New Rectangle(Shadow.ShadowSize + 2, Shadow.ShadowSize + 2, Width - 4, Height - 5 - 4), CombineMode.Exclude)
  899.             For i = s To 0 Step -1
  900.                 Rounding = 5 + s - i
  901.                 Dim pth As GraphicsPath = DM.CreateRoundRectangle(i, i, Shadow.Width - 1 - (i * 2), Shadow.Height - 1 - (i * 2) - 3, Rounding, , , , )
  902.                 mb(col((i ^ (0.111 * i) * op), Shadow.BackColor), br)
  903.                 .FillPath(br, pth)
  904.                 pth.Dispose()
  905.             Next
  906.  
  907.  
  908.             ''(i ^ (i / 9))          Rounding +  (Shadow.ShadowSize - i)
  909.             'Rounding = 1.5 * (Shadow.ShadowSize)
  910.             ''(Shadow.ShadowSize + i) ^ 1.6
  911.             'mb(col((i ^ (0.117647 * i)), Shadow.BackColor), br)
  912.  
  913.  
  914.  
  915.  
  916.         End With
  917.  
  918.         G.Dispose()
  919.         Shadow.SetBits(B)
  920.         B.Dispose()
  921.  
  922.     End Sub
  923.     'below by blackcap
  924.     Friend Class DM
  925.  
  926.         Public Shared Function CreateRoundRectangle(ByVal rectangle As Rectangle, ByVal radius As Integer, Optional ByVal TopLeft As Boolean = True, Optional ByVal TopRigth As Boolean = True, Optional ByVal BottomRigth As Boolean = True, Optional ByVal BottomLeft As Boolean = True) As GraphicsPath
  927.             Dim path As New GraphicsPath()
  928.             Dim l As Integer = rectangle.Left
  929.             Dim t As Integer = rectangle.Top
  930.             Dim w As Integer = rectangle.Width
  931.             Dim h As Integer = rectangle.Height
  932.             Dim d As Integer = radius << 1
  933.  
  934.             If radius <= 0 Then
  935.                 path.AddRectangle(rectangle)
  936.                 Return path
  937.             End If
  938.  
  939.             If TopLeft Then
  940.                 path.AddArc(l, t, d, d, 180, 90)
  941.                 If TopRigth Then path.AddLine(l + radius, t, l + w - radius, t) Else path.AddLine(l + radius, t, l + w, t)
  942.             Else
  943.                 If TopRigth Then path.AddLine(l, t, l + w - radius, t) Else path.AddLine(l, t, l + w, t)
  944.             End If
  945.  
  946.             If TopRigth Then
  947.                 path.AddArc(l + w - d, t, d, d, 270, 90)
  948.                 If BottomRigth Then path.AddLine(l + w, t + radius, l + w, t + h - radius) Else path.AddLine(l + w, t + radius, l + w, t + h)
  949.             Else
  950.                 If BottomRigth Then path.AddLine(l + w, t, l + w, t + h - radius) Else path.AddLine(l + w, t, l + w, t + h)
  951.             End If
  952.  
  953.             If BottomRigth Then
  954.                 path.AddArc(l + w - d, t + h - d, d, d, 0, 90)
  955.                 If BottomLeft Then path.AddLine(l + w - radius, t + h, l + radius, t + h) Else path.AddLine(l + w - radius, t + h, l, t + h)
  956.             Else
  957.                 If BottomLeft Then path.AddLine(l + w, t + h, l + radius, t + h) Else path.AddLine(l + w, t + h, l, t + h)
  958.             End If
  959.  
  960.             If BottomLeft Then
  961.                 path.AddArc(l, t + h - d, d, d, 90, 90)
  962.                 If TopLeft Then path.AddLine(l, t + h - radius, l, t + radius) Else path.AddLine(l, t + h - radius, l, t)
  963.             Else
  964.                 If TopLeft Then path.AddLine(l, t + h, l, t + radius) Else path.AddLine(l, t + h, l, t)
  965.             End If
  966.  
  967.             path.CloseFigure()
  968.             Return path
  969.         End Function
  970.         Public Shared Function CreateRoundRectangle(x As Integer, y As Integer, w As Integer, h As Integer, radius As Integer, Optional ByVal TopLeft As Boolean = True, Optional ByVal TopRigth As Boolean = True, Optional ByVal BottomRigth As Boolean = True, Optional ByVal BottomLeft As Boolean = True) As GraphicsPath
  971.             Return CreateRoundRectangle(New Rectangle(x, y, w, h), radius, TopLeft, TopRigth, BottomRigth, BottomLeft)
  972.         End Function
  973.  
  974.     End Class
  975.     'above by blackcap
  976. #End Region
  977. #Region "PREVIEW"
  978.     Sub drawpreview()
  979.         Dim pb As New Bitmap(250, 45)
  980.         With Graphics.FromImage(pb)
  981.             .Clear(Color)
  982.         End With
  983.         pr.SetBits(pb)
  984.         pb.Dispose()
  985.     End Sub
  986.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  987.         MyBase.OnPaint(e)
  988.         e.Graphics.FillRectangle(Brushes.Fuchsia, rct(0, 200, 250, 45))
  989.     End Sub
  990. #End Region
  991. #End Region
  992. End Class
Add Comment
Please, Sign In to add comment