Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey >=1.1.36 <1.2
- SetWorkingDir % A_ScriptDir
- #HotkeyInterval 99000000
- #KeyHistory 0
- #MaxHotkeysPerInterval 99000000
- #MaxThreads 255
- #MaxThreadsPerHotkey 1
- #NoEnv
- #Persistent
- #SingleInstance force
- CoordMode, Mouse, Screen
- CoordMode, Pixel, Screen
- CoordMode, Tooltip, Screen
- DetectHiddenWindows, On
- ListLines, Off
- Process, Priority,, A
- SendMode, Input
- SetBatchLines, -1
- SetControlDelay, 0
- SetKeyDelay, -1
- SetMouseDelay, -1
- SetWinDelay, -1
- Thread, Interrupt, 0
- #MenuMaskKey vkE8
- ; ////////////////////////////////////////////////////////////////////////////
- ; ============================================================================
- ; COLOR PICKER
- ; Standalone RGB / HSV / HEX color picker for AutoHotkey v1.1.
- ; ============================================================================
- global cp_hue := 126
- global cp_sat := 100
- global cp_val := 100
- global cp_r := 0
- global cp_g := 255
- global cp_b := 26
- global cp_hex := "00FF1A"
- global cp_updating := false
- global cp_drag_mode := ""
- global cp_drag_hwnd := 0
- global cp_sv_width := 250
- global cp_sv_height := 250
- global cp_hue_width := 20
- global cp_hue_height := 250
- global cp_preview_width := 104
- global cp_preview_height := 76
- global cp_hwnd_main := 0
- global cp_hwnd_sv := 0
- global cp_hwnd_hue := 0
- global cp_hwnd_preview := 0
- global cp_hwnd_edit_r := 0
- global cp_hwnd_edit_g := 0
- global cp_hwnd_edit_b := 0
- global cp_hwnd_edit_h := 0
- global cp_hwnd_edit_s := 0
- global cp_hwnd_edit_v := 0
- global cp_hwnd_edit_hex := 0
- global cp_hwnd_eyedropper_icon := 0
- global cp_bitmap_sv := 0
- global cp_bitmap_sv_base := 0
- global cp_bitmap_hue := 0
- global cp_bitmap_hue_base := 0
- global cp_bitmap_preview := 0
- global cp_bitmap_overlay := 0
- global cp_bitmap_eyedropper := 0
- global cp_bits_sv := 0
- global cp_bits_sv_base := 0
- global cp_bits_hue := 0
- global cp_bits_hue_base := 0
- global cp_bits_preview := 0
- global cp_bits_overlay := 0
- global cp_last_sv_hue := -1
- global cp_hue_base_ready := false
- global cp_drag_timer_pending := false
- global cp_pending_mouse_x := 0
- global cp_pending_mouse_y := 0
- global cp_gdip_token := 0
- global cp_gdip_module := 0
- global cp_gdip_ready := false
- global cp_pen_outer := 0
- global cp_pen_inner := 0
- global cp_pen_preview := 0
- ; --- Screen eyedropper state -------------------------------------------------
- global cp_screen_pick_active := false
- global cp_screen_pick_cursor_saved := false
- ; --- Screen pick overlay (layered per-pixel-alpha swatch panel) --------------
- global cp_pp_w := 308
- global cp_pp_h := 94
- global cp_pp_hwnd := 0
- global cp_pp_dc := 0
- global cp_pp_dib := 0
- global cp_pp_bits := 0
- global cp_pp_obm := 0
- global cp_pp_graphics := 0
- global cp_pp_visible := false
- global cp_pp_font_families := {}
- OnExit("CP_Cleanup")
- ; -------------------------- GUI setup ----------------------------------------
- Gui, Color, 191B20, 292D34
- Gui, Margin, 0, 0
- Gui, -MinimizeBox
- ; Header: title left, primary action right, matching 24 px margins on both sides.
- Gui, Font, s15 Bold cF4F6FA, Segoe UI
- Gui, Add, Text, x24 y14 w420 h31 BackgroundTrans, COLOR PICKER
- Gui, Font, s9 c929BA8, Segoe UI
- Gui, Add, Text, x25 y43 w480 h19 BackgroundTrans, Pick a color visually or enter its exact values
- ; --- Screen eyedropper button (top-right, aligned with the title row) --------
- ; Icon bitmap and label share the same 3A414C face so they read as one button.
- ; Right edge lands at 656, giving a 24 px margin symmetric with the left edge.
- Gui, Add, Picture, x516 y14 w28 h28 hwndcp_hwnd_eyedropper_icon gCP_ScreenPick +0xE
- Gui, Font, s9 cFFFFFF, Segoe UI
- Gui, Add, Text, x544 y14 w112 h28 Background3A414C +0x200 Center gCP_ScreenPick, PICK FROM SCREEN
- Gui, Add, Text, x14 y63 w330 h285 Background22262D
- Gui, Add, Text, x354 y63 w312 h363 Background22262D
- Gui, Font, s9 cAAB2C0, Segoe UI
- Gui, Add, Text, x24 y69 w280 h16 BackgroundTrans, SATURATION → / VALUE ↓
- Gui, Add, Text, x23 y88 w252 h252 Background626B79
- Gui, Add, Picture, x24 y89 w250 h250 hwndcp_hwnd_sv +0xE
- Gui, Add, Text, x283 y88 w22 h252 Background626B79
- Gui, Add, Picture, x284 y89 w20 h250 hwndcp_hwnd_hue +0xE
- Gui, Add, Text, x365 y69 w250 h16 BackgroundTrans, LIVE PREVIEW
- Gui, Add, Picture, x365 y91 w104 h76 hwndcp_hwnd_preview +0xE +0x200
- Gui, Font, s17 cFFFFFF, Consolas
- Gui, Add, Text, x484 y105 w176 h34 vCP_HexReadout BackgroundTrans, #00FF1A
- Gui, Font, s9 c929BA8, Segoe UI
- Gui, Add, Text, x486 y139 w150 h18 BackgroundTrans, HEX COLOR
- Gui, Font, s9 cAAB2C0, Segoe UI
- Gui, Add, Text, x365 y190 w85 h18 BackgroundTrans, RGB · 0–255
- Gui, Add, Text, x465 y190 w190 h18 BackgroundTrans, HSV · H 0–360 / S,V 0–100`%
- Gui, Font, s9 cF0F2F5, Segoe UI
- Gui, Add, Text, x365 y216 w16 h25 +0x200 BackgroundTrans, R
- Gui, Add, Text, x365 y248 w16 h25 +0x200 BackgroundTrans, G
- Gui, Add, Text, x365 y280 w16 h25 +0x200 BackgroundTrans, B
- Gui, Add, Text, x465 y216 w16 h25 +0x200 BackgroundTrans, H
- Gui, Add, Text, x465 y248 w16 h25 +0x200 BackgroundTrans, S
- Gui, Add, Text, x465 y280 w16 h25 +0x200 BackgroundTrans, V
- Gui, Font, s10 cF4F6FA, Consolas
- Gui, Add, Edit, x383 y212 w66 h29 vCP_EditR hwndcp_hwnd_edit_r gCP_RGBChanged Center Limit3
- Gui, Add, Edit, x383 y244 w66 h29 vCP_EditG hwndcp_hwnd_edit_g gCP_RGBChanged Center Limit3
- Gui, Add, Edit, x383 y276 w66 h29 vCP_EditB hwndcp_hwnd_edit_b gCP_RGBChanged Center Limit3
- Gui, Add, Edit, x483 y212 w66 h29 vCP_EditH hwndcp_hwnd_edit_h gCP_HSVChanged Center Limit3
- Gui, Add, Edit, x483 y244 w66 h29 vCP_EditS hwndcp_hwnd_edit_s gCP_HSVChanged Center Limit3
- Gui, Add, Edit, x483 y276 w66 h29 vCP_EditV hwndcp_hwnd_edit_v gCP_HSVChanged Center Limit3
- Gui, Font, s9 cAAB2C0, Segoe UI
- Gui, Add, Text, x553 y216 w16 h25 +0x200 BackgroundTrans, °
- Gui, Add, Text, x553 y248 w16 h25 +0x200 BackgroundTrans, `%
- Gui, Add, Text, x553 y280 w16 h25 +0x200 BackgroundTrans, `%
- Gui, Font, s9 cAAB2C0, Segoe UI
- Gui, Add, Text, x365 y323 w250 h18 BackgroundTrans, HEX · #RRGGBB
- Gui, Font, s10 cF4F6FA, Consolas
- Gui, Add, Edit, x365 y345 w174 h30 vCP_EditHex hwndcp_hwnd_edit_hex gCP_HEXChanged Center Limit8
- Gui, Font, s9 cFFFFFF, Segoe UI
- Gui, Add, Text, x548 y345 w96 h30 Background3A414C +0x200 Center gCP_CopyHex, COPY HEX
- Gui, Add, Text, x365 y390 w86 h27 Background343A43 +0x200 Center gCP_CopyRGB, COPY RGB
- Gui, Add, Text, x458 y390 w86 h27 Background343A43 +0x200 Center gCP_CopyCSS, COPY CSS
- Gui, Add, Text, x555 y390 w89 h27 Background343A43 +0x200 Center gCP_Random, RANDOM
- Gui, Font, s8 c929BA8, Segoe UI
- Gui, Add, Text, x24 y351 w310 h34 BackgroundTrans, Drag the square to adjust saturation and value.`nDrag the hue strip to change the base color.
- Gui, Font, s8 cAAB2C0, Segoe UI
- Gui, Add, Text, x24 y402 w620 h17 vCP_Status BackgroundTrans, Ready · Select a color, edit its values, or pick from screen.
- Gui, +Hwndcp_hwnd_main
- ; -------------------------- Bitmap initialization ----------------------------
- cp_bitmap_sv := CP_CreateDIB(cp_sv_width, cp_sv_height, cp_bits_sv, 32)
- cp_bitmap_sv_base := CP_CreateDIB(cp_sv_width, cp_sv_height, cp_bits_sv_base, 32)
- cp_bitmap_hue := CP_CreateDIB(cp_hue_width, cp_hue_height, cp_bits_hue, 32)
- cp_bitmap_hue_base := CP_CreateDIB(cp_hue_width, cp_hue_height, cp_bits_hue_base, 32)
- cp_bitmap_preview := CP_CreateDIB(cp_preview_width, cp_preview_height, cp_bits_preview, 32)
- cp_bitmap_overlay := CP_CreateDIB(1, cp_sv_height, cp_bits_overlay, 32)
- if (!cp_bitmap_sv || !cp_bitmap_sv_base || !cp_bitmap_hue || !cp_bitmap_hue_base || !cp_bitmap_preview || !cp_bitmap_overlay) {
- MsgBox, 16, Color Picker, Windows could not create the color-picker bitmaps.
- ExitApp
- }
- if (!CP_BuildBlackOverlay()) {
- MsgBox, 16, Color Picker, Windows could not initialize the color-picker overlay.
- ExitApp
- }
- ; GDI+ is used for antialiased selection indicators, the preview border, the
- ; eyedropper icon, and the screen-pick swatch panel.
- if (!CP_GdipInitialize())
- GuiControl,, CP_Status, GDI+ is unavailable; using standard Windows drawing.
- ; Draw the eyedropper icon into its own 28x28 bitmap (background baked in).
- cp_bitmap_eyedropper := CP_CreateEyedropperBitmap(28, 28)
- if (cp_bitmap_eyedropper) {
- DllCall("SendMessage", "Ptr", cp_hwnd_eyedropper_icon, "UInt", 0x172, "Ptr", 0, "Ptr", cp_bitmap_eyedropper, "Ptr")
- }
- Gui, Show, w680 h435, Color Picker
- ; Attach each display bitmap once. Redraws update the DIB memory and invalidate
- ; the existing control instead of repeatedly replacing its image handle.
- DllCall("SendMessage", "Ptr", cp_hwnd_sv, "UInt", 0x172, "Ptr", 0, "Ptr", cp_bitmap_sv, "Ptr")
- DllCall("SendMessage", "Ptr", cp_hwnd_hue, "UInt", 0x172, "Ptr", 0, "Ptr", cp_bitmap_hue, "Ptr")
- DllCall("SendMessage", "Ptr", cp_hwnd_preview, "UInt", 0x172, "Ptr", 0, "Ptr", cp_bitmap_preview, "Ptr")
- OnMessage(0x201, "CP_WM_LBUTTONDOWN")
- OnMessage(0x200, "CP_WM_MOUSEMOVE")
- OnMessage(0x202, "CP_WM_LBUTTONUP")
- OnMessage(0x215, "CP_WM_CAPTURECHANGED")
- CP_RGBToHSV(cp_r, cp_g, cp_b, cp_hue, cp_sat, cp_val)
- CP_UpdateFields()
- CP_RedrawAll()
- return
- ; -------------------------- GUI event handlers -------------------------------
- GuiClose:
- GuiEscape:
- ExitApp
- return
- CP_RGBChanged:
- if (cp_updating)
- return
- GuiControlGet, rText,, CP_EditR
- GuiControlGet, gText,, CP_EditG
- GuiControlGet, bText,, CP_EditB
- if (!CP_IsIntegerInRange(rText, 0, 255) || !CP_IsIntegerInRange(gText, 0, 255) || !CP_IsIntegerInRange(bText, 0, 255))
- return
- ; Ignore programmatic echoes. Without this guard, dragging the square to
- ; V=0 fires a field update that re-runs RGB->HSV and snaps the marker to
- ; the bottom-left corner because hue is undefined for black.
- if (rText + 0 = cp_r && gText + 0 = cp_g && bText + 0 = cp_b)
- return
- cp_r := rText + 0
- cp_g := gText + 0
- cp_b := bText + 0
- CP_RGBToHSV(cp_r, cp_g, cp_b, cp_hue, cp_sat, cp_val)
- CP_UpdateFields(DllCall("GetFocus", "Ptr"))
- CP_RedrawAll()
- return
- CP_HSVChanged:
- if (cp_updating)
- return
- GuiControlGet, hText,, CP_EditH
- GuiControlGet, sText,, CP_EditS
- GuiControlGet, vText,, CP_EditV
- if (!CP_IsIntegerInRange(hText, 0, 360) || !CP_IsIntegerInRange(sText, 0, 100) || !CP_IsIntegerInRange(vText, 0, 100))
- return
- if (hText + 0 = cp_hue && sText + 0 = cp_sat && vText + 0 = cp_val)
- return
- cp_hue := hText + 0
- cp_sat := sText + 0
- cp_val := vText + 0
- CP_HSVToRGB(cp_hue, cp_sat, cp_val, cp_r, cp_g, cp_b)
- CP_UpdateFields(DllCall("GetFocus", "Ptr"))
- CP_RedrawAll()
- return
- CP_HEXChanged:
- if (cp_updating)
- return
- GuiControlGet, hexText,, CP_EditHex
- if (!CP_ParseHex(hexText, newR, newG, newB))
- return
- if (newR = cp_r && newG = cp_g && newB = cp_b)
- return
- cp_r := newR
- cp_g := newG
- cp_b := newB
- CP_RGBToHSV(cp_r, cp_g, cp_b, cp_hue, cp_sat, cp_val)
- CP_UpdateFields(DllCall("GetFocus", "Ptr"))
- CP_RedrawAll()
- return
- ; -------------------------- Clipboard and random-color actions ---------------
- CP_CopyHex:
- Clipboard := "#" . cp_hex
- GuiControl,, CP_Status, % "Copied #" . cp_hex . " to the clipboard."
- return
- CP_CopyRGB:
- Clipboard := cp_r . ", " . cp_g . ", " . cp_b
- GuiControl,, CP_Status, Copied RGB values to the clipboard.
- return
- CP_CopyCSS:
- Clipboard := "rgb(" . cp_r . ", " . cp_g . ", " . cp_b . ")"
- GuiControl,, CP_Status, Copied CSS rgb() to the clipboard.
- return
- CP_Random:
- Random, cp_hue, 0, 359
- Random, cp_sat, 55, 100
- Random, cp_val, 65, 100
- CP_HSVToRGB(cp_hue, cp_sat, cp_val, cp_r, cp_g, cp_b)
- CP_UpdateFields()
- CP_RedrawAll()
- GuiControl,, CP_Status, Random color generated.
- return
- ; -------------------------- Screen eyedropper --------------------------------
- CP_ScreenPick:
- if (cp_screen_pick_active)
- return
- CP_StartScreenPick()
- return
- CP_StartScreenPick() {
- global cp_screen_pick_active, cp_screen_pick_cursor_saved
- cp_screen_pick_active := true
- ; Hide the main window so it never sits between the cursor and the target pixel.
- Gui, Hide
- ; Crosshair cursor via a temporary system-wide override, restored with SPI_SETCURSORS.
- cp_screen_pick_cursor_saved := CP_SetCrosshairCursor()
- ; Consume LButton/RButton/Escape so the picker click does not reach the
- ; window underneath and so cancelling is reliable.
- try {
- Hotkey, *LButton, CP_ScreenPickConfirm, On UseErrorLevel
- Hotkey, *RButton, CP_ScreenPickCancel, On UseErrorLevel
- Hotkey, *Escape, CP_ScreenPickCancel, On UseErrorLevel
- }
- ; Seed the overlay at the current position and start live tracking.
- MouseGetPos, mx, my
- CP_ScreenPickShowOverlay(mx, my)
- SetTimer, CP_ScreenPickTrack, 30
- }
- CP_ScreenPickShowOverlay(mx, my) {
- PixelGetColor, pickColor, mx, my, RGB
- if (ErrorLevel)
- return
- CP_ComputePickPanelPosition(mx, my, px, py)
- CP_PickPanelShow(px, py, pickColor, mx, my)
- }
- CP_ScreenPickTrack:
- if (!cp_screen_pick_active) {
- SetTimer, CP_ScreenPickTrack, Off
- return
- }
- MouseGetPos, mx, my
- CP_ScreenPickShowOverlay(mx, my)
- return
- CP_ScreenPickConfirm:
- if (!cp_screen_pick_active)
- return
- MouseGetPos, mx, my
- PixelGetColor, pickColor, mx, my, RGB
- pickErr := ErrorLevel
- CP_EndScreenPick()
- Gui, Show
- if (!pickErr)
- CP_ApplyPickedColor(pickColor)
- return
- CP_ScreenPickCancel:
- if (!cp_screen_pick_active)
- return
- CP_EndScreenPick()
- Gui, Show
- return
- CP_ApplyPickedColor(pickColor) {
- global cp_r, cp_g, cp_b, cp_hue, cp_sat, cp_val
- cp_r := (pickColor >> 16) & 0xFF
- cp_g := (pickColor >> 8) & 0xFF
- cp_b := pickColor & 0xFF
- CP_RGBToHSV(cp_r, cp_g, cp_b, cp_hue, cp_sat, cp_val)
- CP_UpdateFields()
- CP_RedrawAll()
- GuiControl,, CP_Status, % "Picked #" . Format("{:06X}", pickColor) . " from screen."
- }
- CP_SetCrosshairCursor() {
- ; Cover every standard system cursor ID. Explorer, Word, browsers, and
- ; many other apps call SetCursor(LoadCursor(NULL, IDC_HAND/IBEAM/WAIT/...))
- ; directly in their WM_SETCURSOR handler, which bypasses SetSystemCursor
- ; for that specific ID. Replacing only IDC_ARROW therefore leaves the hand
- ; and I-beam fully functional while the pick is running.
- ;
- ; The ID list mirrors screenshot_manager.ahk's set_system_cursor() so the
- ; two subsystems behave identically. PIN and PERSON are appended because
- ; Explorer uses them on Quick Access and People surfaces on newer Windows.
- static cursorIds := [32512, 32513, 32514, 32515, 32516
- , 32640, 32641, 32642, 32643, 32644
- , 32645, 32646, 32648, 32649, 32650
- , 32651, 32671, 32672]
- hCursor := DllCall("LoadCursor", "Ptr", 0, "Int", 32515, "Ptr")
- if (!hCursor)
- return false
- ; anyApplied, not allApplied: IDC_PIN and IDC_PERSON only exist on
- ; Windows 8+. If at least one cursor was replaced, restore is still
- ; required on exit. A single failure must not prevent the restore.
- anyApplied := false
- for _, id in cursorIds {
- ; CopyImage is required: SetSystemCursor takes ownership of hcur and
- ; destroys it, so each ID needs its own fresh handle.
- hCopy := DllCall("CopyImage", "Ptr", hCursor, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
- if (!hCopy)
- continue
- if (DllCall("SetSystemCursor", "Ptr", hCopy, "Int", id))
- anyApplied := true
- else
- DllCall("DestroyCursor", "Ptr", hCopy)
- }
- return anyApplied
- }
- CP_EndScreenPick() {
- global cp_screen_pick_active, cp_screen_pick_cursor_saved
- cp_screen_pick_active := false
- SetTimer, CP_ScreenPickTrack, Off
- try {
- Hotkey, *LButton, Off
- Hotkey, *RButton, Off
- Hotkey, *Escape, Off
- }
- CP_PickPanelHide()
- CP_RestoreSystemCursors()
- }
- CP_RestoreSystemCursors() {
- global cp_screen_pick_cursor_saved
- if (!cp_screen_pick_cursor_saved)
- return
- ; SPI_SETCURSORS (0x0057) reloads the cursor table from the current user
- ; scheme. SPIF_SENDCHANGE (0x02) broadcasts WM_SETTINGCHANGE so apps that
- ; cached a cursor handle re-query it.
- DllCall("SystemParametersInfo", "UInt", 0x0057, "UInt", 0, "Ptr", 0, "UInt", 0x02)
- ; Force the window under the cursor to re-run WM_SETCURSOR now. Without
- ; this, Explorer and other apps keep the old cursor until the next mouse
- ; move triggers WM_SETCURSOR naturally.
- ;
- ; wParam = HWND under cursor
- ; lParam = MAKELPARAM(HTCLIENT, WM_MOUSEMOVE) = 0x02000001
- ;
- ; SendMessageTimeout with SMTO_ABORTIFHUNG (0x0002) prevents a deadlock
- ; if the target thread is stuck.
- MouseGetPos, , , hwndUnder
- if (hwndUnder) {
- DllCall("SendMessageTimeout"
- , "Ptr", hwndUnder
- , "UInt", 0x0020 ; WM_SETCURSOR
- , "Ptr", hwndUnder
- , "Ptr", 0x02000001
- , "UInt", 0x0002 ; SMTO_ABORTIFHUNG
- , "UInt", 100 ; 100 ms
- , "Ptr*", result
- , "Ptr")
- }
- ; If our own GUI is under the cursor after this call returns, our thread
- ; owns the visible cursor; set it to the restored arrow explicitly.
- hArrow := DllCall("LoadCursor", "Ptr", 0, "Int", 32512, "Ptr")
- if (hArrow)
- DllCall("SetCursor", "Ptr", hArrow)
- cp_screen_pick_cursor_saved := false
- }
- ; -------------------------- Screen pick overlay ------------------------------
- ; Layered per-pixel-alpha panel that follows the cursor during a screen pick.
- ; Shows the sampled swatch, hex, RGB, and cursor position in one card so the
- ; user can see and read the color without looking away from the target.
- CP_PickPanelEnsure() {
- global
- if (cp_pp_hwnd && cp_pp_graphics)
- return true
- cp_pp_dib := CP_CreateDIB(cp_pp_w, cp_pp_h, cp_pp_bits, 32)
- if (!cp_pp_dib)
- return false
- cp_pp_dc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!cp_pp_dc) {
- DllCall("DeleteObject", "Ptr", cp_pp_dib)
- cp_pp_dib := 0
- return false
- }
- cp_pp_obm := DllCall("SelectObject", "Ptr", cp_pp_dc, "Ptr", cp_pp_dib, "Ptr")
- cp_pp_graphics := CP_GdipCreateGraphics(cp_pp_dc)
- if (!cp_pp_graphics) {
- CP_PickPanelReleaseGdi()
- return false
- }
- ; WS_EX_LAYERED | WS_EX_TRANSPARENT. Transparent makes the panel
- ; click-through, so the sampled pixel is never hidden behind the panel.
- Gui, cp_pp:New, -Caption +ToolWindow +AlwaysOnTop +E0x00080020 +Hwndcp_pp_hwnd
- Gui, cp_pp:Color, 000000
- return true
- }
- CP_PickPanelReleaseGdi() {
- global
- if (cp_pp_graphics) {
- DllCall("gdiplus\GdipDeleteGraphics", "Ptr", cp_pp_graphics, "UInt")
- cp_pp_graphics := 0
- }
- if (cp_pp_dc) {
- if (cp_pp_obm) {
- DllCall("SelectObject", "Ptr", cp_pp_dc, "Ptr", cp_pp_obm, "Ptr")
- cp_pp_obm := 0
- }
- DllCall("DeleteDC", "Ptr", cp_pp_dc)
- cp_pp_dc := 0
- }
- if (cp_pp_dib) {
- DllCall("DeleteObject", "Ptr", cp_pp_dib)
- cp_pp_dib := 0
- }
- }
- CP_ComputePickPanelPosition(mx, my, ByRef outX, ByRef outY) {
- global cp_pp_w, cp_pp_h
- ; Virtual desktop bounds cover every monitor, not only the primary one.
- vx := DllCall("GetSystemMetrics", "Int", 76) ; SM_XVIRTUALSCREEN
- vy := DllCall("GetSystemMetrics", "Int", 77) ; SM_YVIRTUALSCREEN
- vw := DllCall("GetSystemMetrics", "Int", 78) ; SM_CXVIRTUALSCREEN
- vh := DllCall("GetSystemMetrics", "Int", 79) ; SM_CYVIRTUALSCREEN
- vRight := vx + vw
- vBottom := vy + vh
- offset := 24
- outX := mx + offset
- outY := my + offset
- ; Flip to the opposite side before clamping so the panel does not sit on
- ; top of the cursor when the screen edge is close.
- if (outX + cp_pp_w > vRight)
- outX := mx - offset - cp_pp_w
- if (outY + cp_pp_h > vBottom)
- outY := my - offset - cp_pp_h
- ; Clamp for the case where the panel is larger than the remaining space.
- if (outX < vx)
- outX := vx
- if (outY < vy)
- outY := vy
- if (outX + cp_pp_w > vRight)
- outX := vRight - cp_pp_w
- if (outY + cp_pp_h > vBottom)
- outY := vBottom - cp_pp_h
- }
- CP_PickPanelShow(x, y, pickColor, mx, my) {
- global
- if (!CP_PickPanelEnsure())
- return false
- if (!CP_PickPanelRender(pickColor, mx, my))
- return false
- if (!CP_PickPanelUpdateLayeredWindow(x, y))
- return false
- if (!cp_pp_visible) {
- DllCall("ShowWindow", "Ptr", cp_pp_hwnd, "Int", 8) ; SW_SHOWNA
- cp_pp_visible := true
- }
- return true
- }
- CP_PickPanelHide() {
- global
- if (cp_pp_visible && cp_pp_hwnd) {
- DllCall("ShowWindow", "Ptr", cp_pp_hwnd, "Int", 0) ; SW_HIDE
- cp_pp_visible := false
- }
- }
- CP_PickPanelUpdateLayeredWindow(x, y) {
- global cp_pp_hwnd, cp_pp_dc, cp_pp_w, cp_pp_h
- VarSetCapacity(ptDst, 8, 0)
- NumPut(x, ptDst, 0, "Int")
- NumPut(y, ptDst, 4, "Int")
- VarSetCapacity(sz, 8, 0)
- NumPut(cp_pp_w, sz, 0, "Int")
- NumPut(cp_pp_h, sz, 4, "Int")
- VarSetCapacity(ptSrc, 8, 0) ; source origin is 0,0
- ; BLENDFUNCTION packed as a DWORD:
- ; BlendOp = AC_SRC_OVER (0), BlendFlags = 0
- ; SourceConstantAlpha = 255, AlphaFormat = AC_SRC_ALPHA (1)
- blend := 0x01FF0000
- return DllCall("UpdateLayeredWindow"
- , "Ptr", cp_pp_hwnd
- , "Ptr", 0
- , "Ptr", &ptDst
- , "Ptr", &sz
- , "Ptr", cp_pp_dc
- , "Ptr", &ptSrc
- , "UInt", 0
- , "UInt*", blend
- , "UInt", 2) ; ULW_ALPHA
- }
- CP_PickPanelRender(pickColor, mx, my) {
- global cp_pp_graphics, cp_pp_w, cp_pp_h
- g := cp_pp_graphics
- if (!g)
- return false
- ; Fully transparent base.
- DllCall("gdiplus\GdipGraphicsClear", "Ptr", g, "UInt", 0x00000000)
- ; Panel background: soft translucent dark card, 94% opaque.
- CP_GdipFillRectArgb(g, 0xF01A1D22, 0, 0, cp_pp_w, cp_pp_h)
- ; 1px border.
- CP_GdipDrawRectArgb(g, 0xFF3E4550, 1.0, 0.5, 0.5, cp_pp_w - 1, cp_pp_h - 1)
- ; Swatch area: 68x68 at (10, 13), with its own 1px border.
- swatchX := 10
- swatchY := 13
- swatchW := 68
- swatchH := 68
- r := (pickColor >> 16) & 0xFF
- gg := (pickColor >> 8) & 0xFF
- b := pickColor & 0xFF
- swatchArgb := 0xFF000000 | (r << 16) | (gg << 8) | b
- CP_GdipFillRectArgb(g, swatchArgb, swatchX, swatchY, swatchW, swatchH)
- CP_GdipDrawRectArgb(g, 0xFF5A6270, 1.0, swatchX - 0.5, swatchY - 0.5, swatchW + 1, swatchH + 1)
- ; Text column starts right of the swatch.
- textX := swatchX + swatchW + 12
- textW := cp_pp_w - textX - 12
- hexStr := Format("#{:06X}", pickColor)
- rgbStr := "rgb(" r ", " gg ", " b ")"
- posStr := "x " mx " y " my
- ; Hex: large, bright, primary readout.
- CP_GdipDrawText(g, hexStr, textX, 12, textW, 22, 0xFFFFFFFF, 15, "Segoe UI", true)
- ; RGB: mid-emphasis.
- CP_GdipDrawText(g, rgbStr, textX, 36, textW, 16, 0xFFD0D6E0, 10, "Segoe UI", false)
- ; Cursor position: minor.
- CP_GdipDrawText(g, posStr, textX, 54, textW, 14, 0xFF9098A8, 9, "Segoe UI", false)
- ; Hint: dimmest.
- CP_GdipDrawText(g, "Click to pick · Right-click or Esc to cancel", textX, 72, textW, 14, 0xFF7A8290, 8, "Segoe UI", false)
- DllCall("gdiplus\GdipFlush", "Ptr", g, "Int", 1)
- DllCall("GdiFlush")
- return true
- }
- CP_PickPanelCleanup() {
- global cp_pp_hwnd, cp_pp_visible, cp_pp_font_families
- CP_PickPanelHide()
- CP_PickPanelReleaseGdi()
- if (cp_pp_hwnd) {
- Gui, cp_pp:Destroy
- cp_pp_hwnd := 0
- }
- ; Free any font families cached for text rendering.
- for _, pFamily in cp_pp_font_families {
- if (pFamily)
- DllCall("gdiplus\GdipDeleteFontFamily", "Ptr", pFamily, "UInt")
- }
- cp_pp_font_families := {}
- }
- ; -------------------------- GDI+ primitives for the pick overlay -------------
- CP_GdipFillRectArgb(g, argb, x, y, w, h) {
- brush := 0
- DllCall("gdiplus\GdipCreateSolidFill", "UInt", argb, "Ptr*", brush, "UInt")
- if (!brush)
- return false
- DllCall("gdiplus\GdipFillRectangle", "Ptr", g, "Ptr", brush, "Float", x, "Float", y, "Float", w, "Float", h, "UInt")
- DllCall("gdiplus\GdipDeleteBrush", "Ptr", brush, "UInt")
- return true
- }
- CP_GdipDrawRectArgb(g, argb, thickness, x, y, w, h) {
- pen := 0
- DllCall("gdiplus\GdipCreatePen1", "UInt", argb, "Float", thickness, "Int", 2, "Ptr*", pen, "UInt")
- if (!pen)
- return false
- DllCall("gdiplus\GdipDrawRectangle", "Ptr", g, "Ptr", pen, "Float", x, "Float", y, "Float", w, "Float", h, "UInt")
- DllCall("gdiplus\GdipDeletePen", "Ptr", pen, "UInt")
- return true
- }
- CP_GdipDrawText(g, text, x, y, w, h, argb, size, fontName, bold := false) {
- global cp_pp_font_families
- if (!cp_pp_font_families.HasKey(fontName)) {
- pFamily := 0
- DllCall("gdiplus\GdipCreateFontFamilyFromName", "WStr", fontName, "UInt", 0, "Ptr*", pFamily, "UInt")
- cp_pp_font_families[fontName] := pFamily
- }
- hFontFamily := cp_pp_font_families[fontName]
- if (!hFontFamily)
- return false
- ; AntiAlias (4) is the safe choice for layered per-pixel-alpha windows;
- ; ClearType subpixel rendering does not composite correctly through ULW.
- DllCall("gdiplus\GdipSetTextRenderingHint", "Ptr", g, "Int", 4, "UInt")
- style := bold ? 1 : 0
- pFont := 0
- DllCall("gdiplus\GdipCreateFont", "Ptr", hFontFamily, "Float", size, "Int", style, "Int", 2, "Ptr*", pFont, "UInt")
- if (!pFont)
- return false
- pStringFormat := 0
- DllCall("gdiplus\GdipCreateStringFormat", "Int", 0, "Int", 0, "Ptr*", pStringFormat, "UInt")
- if (pStringFormat) {
- DllCall("gdiplus\GdipSetStringFormatAlign", "Ptr", pStringFormat, "Int", 0)
- DllCall("gdiplus\GdipSetStringFormatLineAlign", "Ptr", pStringFormat, "Int", 0)
- DllCall("gdiplus\GdipSetStringFormatTrimming", "Ptr", pStringFormat, "Int", 1)
- }
- pBrush := 0
- DllCall("gdiplus\GdipCreateSolidFill", "UInt", argb, "Ptr*", pBrush, "UInt")
- VarSetCapacity(rectF, 16, 0)
- NumPut(x, rectF, 0, "Float")
- NumPut(y, rectF, 4, "Float")
- NumPut(w, rectF, 8, "Float")
- NumPut(h, rectF, 12, "Float")
- DllCall("gdiplus\GdipDrawString", "Ptr", g, "WStr", text, "Int", -1, "Ptr", pFont, "Ptr", &rectF, "Ptr", pStringFormat, "Ptr", pBrush, "UInt")
- if (pBrush) DllCall("gdiplus\GdipDeleteBrush", "Ptr", pBrush, "UInt")
- if (pStringFormat) DllCall("gdiplus\GdipDeleteStringFormat", "Ptr", pStringFormat, "UInt")
- if (pFont) DllCall("gdiplus\GdipDeleteFont", "Ptr", pFont, "UInt")
- return true
- }
- ; -------------------------- Eyedropper button icon ---------------------------
- CP_CreateEyedropperBitmap(width, height) {
- VarSetCapacity(bi, 40, 0)
- NumPut(40, bi, 0, "UInt")
- NumPut(width, bi, 4, "Int")
- NumPut(-height, bi, 8, "Int")
- NumPut(1, bi, 12, "UShort")
- NumPut(32, bi, 14, "UShort")
- NumPut(0, bi, 16, "UInt")
- hdcScreen := DllCall("GetDC", "Ptr", 0, "Ptr")
- hdc := DllCall("CreateCompatibleDC", "Ptr", hdcScreen, "Ptr")
- DllCall("ReleaseDC", "Ptr", 0, "Ptr", hdcScreen)
- if (!hdc)
- return 0
- bits := 0
- hbm := DllCall("CreateDIBSection", "Ptr", hdc, "Ptr", &bi, "UInt", 0, "Ptr*", bits, "Ptr", 0, "UInt", 0, "Ptr")
- if (!hbm) {
- DllCall("DeleteDC", "Ptr", hdc)
- return 0
- }
- oldBitmap := DllCall("SelectObject", "Ptr", hdc, "Ptr", hbm, "Ptr")
- ; The button face color is baked into the icon bitmap so the Picture control
- ; blends seamlessly with the adjacent Text label.
- bgArgb := 0xFF3A414C
- Loop, % width * height {
- NumPut(bgArgb, bits + ((A_Index - 1) * 4), 0, "UInt")
- }
- ; Draw the eyedropper centered inside a 24x24 icon area.
- iconSize := 24
- offsetX := (width - iconSize) // 2
- offsetY := (height - iconSize) // 2
- graphics := CP_GdipCreateGraphics(hdc)
- if (graphics) {
- ; Bulb: filled circle with a light outline at the top-right.
- bulbBrush := 0, bulbPen := 0
- DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0xFFEAF0FA, "Ptr*", bulbBrush, "UInt")
- DllCall("gdiplus\GdipCreatePen1", "UInt", 0xFF8A95A5, "Float", 1.0, "Int", 2, "Ptr*", bulbPen, "UInt")
- bulbCx := offsetX + 16
- bulbCy := offsetY + 6
- bulbR := 4.5
- if (bulbBrush)
- DllCall("gdiplus\GdipFillEllipse", "Ptr", graphics, "Ptr", bulbBrush, "Float", bulbCx - bulbR, "Float", bulbCy - bulbR, "Float", bulbR * 2, "Float", bulbR * 2, "UInt")
- if (bulbPen)
- DllCall("gdiplus\GdipDrawEllipse", "Ptr", graphics, "Ptr", bulbPen, "Float", bulbCx - bulbR, "Float", bulbCy - bulbR, "Float", bulbR * 2, "Float", bulbR * 2, "UInt")
- if (bulbBrush) DllCall("gdiplus\GdipDeleteBrush", "Ptr", bulbBrush, "UInt")
- if (bulbPen) DllCall("gdiplus\GdipDeletePen", "Ptr", bulbPen, "UInt")
- ; Tube: slanted parallelogram from the bulb down to the tip area.
- tubeBrush := 0
- DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0xFFD2DAE6, "Ptr*", tubeBrush, "UInt")
- if (tubeBrush) {
- VarSetCapacity(tubePts, 32, 0)
- NumPut(offsetX + 13.5, tubePts, 0, "Float")
- NumPut(offsetY + 8.0, tubePts, 4, "Float")
- NumPut(offsetX + 15.5, tubePts, 8, "Float")
- NumPut(offsetY + 10.0, tubePts, 12, "Float")
- NumPut(offsetX + 7.0, tubePts, 16, "Float")
- NumPut(offsetY + 18.0, tubePts, 20, "Float")
- NumPut(offsetX + 5.0, tubePts, 24, "Float")
- NumPut(offsetY + 16.0, tubePts, 28, "Float")
- DllCall("gdiplus\GdipFillPolygon", "Ptr", graphics, "Ptr", tubeBrush, "Ptr", &tubePts, "Int", 4, "Int", 0, "UInt")
- DllCall("gdiplus\GdipDeleteBrush", "Ptr", tubeBrush, "UInt")
- }
- ; Tip: triangle at the bottom-left that connects to the tube's endpoint.
- tipBrush := 0
- DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0xFFA0AEC0, "Ptr*", tipBrush, "UInt")
- if (tipBrush) {
- VarSetCapacity(tipPts, 24, 0)
- NumPut(offsetX + 3.0, tipPts, 0, "Float")
- NumPut(offsetY + 21.0, tipPts, 4, "Float")
- NumPut(offsetX + 7.0, tipPts, 8, "Float")
- NumPut(offsetY + 18.0, tipPts, 12, "Float")
- NumPut(offsetX + 5.0, tipPts, 16, "Float")
- NumPut(offsetY + 16.0, tipPts, 20, "Float")
- DllCall("gdiplus\GdipFillPolygon", "Ptr", graphics, "Ptr", tipBrush, "Ptr", &tipPts, "Int", 3, "Int", 0, "UInt")
- DllCall("gdiplus\GdipDeleteBrush", "Ptr", tipBrush, "UInt")
- }
- DllCall("gdiplus\GdipDeleteGraphics", "Ptr", graphics, "UInt")
- }
- ; GDI+ drawing does not touch the alpha byte; force every pixel opaque so
- ; the Picture control renders the button face correctly.
- Loop, % width * height {
- NumPut(0xFF, bits + ((A_Index - 1) * 4) + 3, 0, "UChar")
- }
- DllCall("GdiFlush")
- if (oldBitmap)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBitmap, "Ptr")
- DllCall("DeleteDC", "Ptr", hdc)
- return hbm
- }
- ; -------------------------- Mouse interaction --------------------------------
- CP_WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
- global cp_hwnd_sv, cp_hwnd_hue, cp_drag_mode, cp_drag_hwnd
- if (cp_drag_mode != "")
- CP_EndDrag()
- VarSetCapacity(point, 8, 0)
- if (!DllCall("GetCursorPos", "Ptr", &point))
- return
- mouseX := NumGet(point, 0, "Int")
- mouseY := NumGet(point, 4, "Int")
- if (CP_PointInsideWindow(cp_hwnd_sv, mouseX, mouseY)) {
- cp_drag_mode := "sv"
- cp_drag_hwnd := cp_hwnd_sv
- } else if (CP_PointInsideWindow(cp_hwnd_hue, mouseX, mouseY)) {
- cp_drag_mode := "hue"
- cp_drag_hwnd := cp_hwnd_hue
- } else {
- return
- }
- DllCall("SetCapture", "Ptr", cp_drag_hwnd, "Ptr")
- CP_ApplyScreenPoint(cp_drag_mode, mouseX, mouseY)
- return 0
- }
- CP_WM_MOUSEMOVE(wParam, lParam, msg, hwnd) {
- global cp_drag_mode
- if (cp_drag_mode = "")
- return
- if (!GetKeyState("LButton", "P")) {
- CP_EndDrag()
- return
- }
- VarSetCapacity(point, 8, 0)
- if (DllCall("GetCursorPos", "Ptr", &point)) {
- mouseX := NumGet(point, 0, "Int")
- mouseY := NumGet(point, 4, "Int")
- CP_QueueScreenPoint(cp_drag_mode, mouseX, mouseY)
- }
- }
- CP_WM_LBUTTONUP(wParam, lParam, msg, hwnd) {
- global cp_drag_mode, cp_drag_timer_pending
- global cp_pending_mouse_x, cp_pending_mouse_y
- if (cp_drag_mode = "")
- return
- SetTimer, CP_DragUpdate, Off
- cp_drag_timer_pending := false
- VarSetCapacity(point, 8, 0)
- if (DllCall("GetCursorPos", "Ptr", &point)) {
- cp_pending_mouse_x := NumGet(point, 0, "Int")
- cp_pending_mouse_y := NumGet(point, 4, "Int")
- CP_ApplyScreenPoint(cp_drag_mode, cp_pending_mouse_x, cp_pending_mouse_y)
- }
- CP_EndDrag()
- return 0
- }
- CP_WM_CAPTURECHANGED(wParam, lParam, msg, hwnd) {
- global cp_drag_hwnd, cp_drag_mode, cp_drag_timer_pending
- if (hwnd = cp_drag_hwnd && cp_drag_mode != "") {
- cp_drag_mode := ""
- cp_drag_hwnd := 0
- cp_drag_timer_pending := false
- SetTimer, CP_DragUpdate, Off
- }
- }
- CP_EndDrag() {
- global cp_drag_mode, cp_drag_hwnd, cp_drag_timer_pending
- SetTimer, CP_DragUpdate, Off
- cp_drag_timer_pending := false
- captureHwnd := cp_drag_hwnd
- cp_drag_mode := ""
- cp_drag_hwnd := 0
- if (captureHwnd && DllCall("GetCapture", "Ptr") = captureHwnd)
- DllCall("ReleaseCapture")
- }
- CP_QueueScreenPoint(mode, screenX, screenY) {
- global cp_pending_mouse_x, cp_pending_mouse_y, cp_drag_timer_pending
- cp_pending_mouse_x := screenX
- cp_pending_mouse_y := screenY
- if (!cp_drag_timer_pending) {
- cp_drag_timer_pending := true
- SetTimer, CP_DragUpdate, -16
- }
- }
- CP_DragUpdate:
- cp_drag_timer_pending := false
- if (cp_drag_mode != "")
- CP_ApplyScreenPoint(cp_drag_mode, cp_pending_mouse_x, cp_pending_mouse_y)
- return
- CP_PointInsideWindow(hwnd, screenX, screenY) {
- if (!hwnd || !DllCall("IsWindow", "Ptr", hwnd))
- return false
- VarSetCapacity(rect, 16, 0)
- if (!DllCall("GetWindowRect", "Ptr", hwnd, "Ptr", &rect))
- return false
- left := NumGet(rect, 0, "Int")
- top := NumGet(rect, 4, "Int")
- right := NumGet(rect, 8, "Int")
- bottom := NumGet(rect, 12, "Int")
- return (screenX >= left && screenX < right && screenY >= top && screenY < bottom)
- }
- CP_ApplyScreenPoint(mode, screenX, screenY) {
- global cp_hwnd_sv, cp_hwnd_hue
- global cp_sv_width, cp_sv_height, cp_hue_height
- global cp_hue, cp_sat, cp_val, cp_r, cp_g, cp_b
- controlHwnd := (mode = "sv") ? cp_hwnd_sv : cp_hwnd_hue
- if (!controlHwnd || !DllCall("IsWindow", "Ptr", controlHwnd))
- return
- VarSetCapacity(rect, 16, 0)
- if (!DllCall("GetWindowRect", "Ptr", controlHwnd, "Ptr", &rect))
- return
- left := NumGet(rect, 0, "Int")
- top := NumGet(rect, 4, "Int")
- right := NumGet(rect, 8, "Int")
- bottom := NumGet(rect, 12, "Int")
- controlWidth := right - left
- controlHeight := bottom - top
- if (controlWidth <= 1 || controlHeight <= 1)
- return
- sourceWidth := (mode = "sv") ? cp_sv_width : cp_hue_width
- sourceHeight := (mode = "sv") ? cp_sv_height : cp_hue_height
- screenX := CP_Clamp(screenX, left, right - 1)
- screenY := CP_Clamp(screenY, top, bottom - 1)
- x := Round((screenX - left) * (sourceWidth - 1) / (controlWidth - 1))
- y := Round((screenY - top) * (sourceHeight - 1) / (controlHeight - 1))
- if (mode = "sv") {
- x := CP_Clamp(x, 0, cp_sv_width - 1)
- y := CP_Clamp(y, 0, cp_sv_height - 1)
- newSat := Round((x / (cp_sv_width - 1)) * 100)
- newVal := Round((1 - (y / (cp_sv_height - 1))) * 100)
- if (newSat = cp_sat && newVal = cp_val)
- return
- cp_sat := newSat
- cp_val := newVal
- } else {
- y := CP_Clamp(y, 0, cp_hue_height - 1)
- newHue := Round((y / (cp_hue_height - 1)) * 360)
- if (newHue = cp_hue)
- return
- cp_hue := newHue
- }
- CP_HSVToRGB(cp_hue, cp_sat, cp_val, cp_r, cp_g, cp_b)
- CP_UpdateFields()
- CP_RedrawInteractive(mode)
- }
- CP_Clamp(value, minimum, maximum) {
- if (value < minimum)
- return minimum
- if (value > maximum)
- return maximum
- return value
- }
- ; -------------------------- DIB creation and refresh -------------------------
- CP_CreateDIB(width, height, ByRef bits, bitCount := 32) {
- VarSetCapacity(bi, 40, 0)
- NumPut(40, bi, 0, "UInt")
- NumPut(width, bi, 4, "Int")
- NumPut(-height, bi, 8, "Int")
- NumPut(1, bi, 12, "UShort")
- NumPut(bitCount, bi, 14, "UShort")
- NumPut(0, bi, 16, "UInt")
- hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!hdc)
- return 0
- hbm := DllCall("CreateDIBSection", "Ptr", hdc, "Ptr", &bi, "UInt", 0, "Ptr*", bits, "Ptr", 0, "UInt", 0, "Ptr")
- DllCall("DeleteDC", "Ptr", hdc)
- return hbm
- }
- CP_RefreshPicture(hwnd) {
- if (!hwnd)
- return
- DllCall("InvalidateRect", "Ptr", hwnd, "Ptr", 0, "Int", 0)
- }
- CP_RedrawAll() {
- global cp_r, cp_g, cp_b, cp_hex
- global cp_hwnd_sv, cp_hwnd_hue, cp_hwnd_preview
- Critical, On
- cp_hex := Format("{:02X}{:02X}{:02X}", cp_r, cp_g, cp_b)
- CP_DrawSV()
- CP_DrawHue()
- CP_DrawPreview()
- DllCall("GdiFlush")
- CP_RefreshPicture(cp_hwnd_sv)
- CP_RefreshPicture(cp_hwnd_hue)
- CP_RefreshPicture(cp_hwnd_preview)
- Critical, Off
- GuiControl,, CP_HexReadout, % "#" . cp_hex
- }
- CP_RedrawInteractive(mode) {
- global cp_r, cp_g, cp_b, cp_hex
- global cp_hwnd_sv, cp_hwnd_hue, cp_hwnd_preview
- Critical, On
- cp_hex := Format("{:02X}{:02X}{:02X}", cp_r, cp_g, cp_b)
- CP_DrawSV()
- if (mode = "hue")
- CP_DrawHue()
- CP_DrawPreview()
- DllCall("GdiFlush")
- CP_RefreshPicture(cp_hwnd_sv)
- if (mode = "hue")
- CP_RefreshPicture(cp_hwnd_hue)
- CP_RefreshPicture(cp_hwnd_preview)
- Critical, Off
- GuiControl,, CP_HexReadout, % "#" . cp_hex
- }
- ; -------------------------- Native Win32 color-field rendering ---------------
- CP_BuildBlackOverlay() {
- global cp_bits_overlay, cp_sv_height
- Loop, %cp_sv_height% {
- y := A_Index - 1
- alpha := Round((y / (cp_sv_height - 1)) * 255)
- pixel := alpha << 24
- NumPut(pixel, cp_bits_overlay + (y * 4), 0, "UInt")
- }
- return true
- }
- CP_BuildSVGradient(hue) {
- global cp_bitmap_sv_base, cp_sv_width, cp_sv_height
- global cp_bitmap_overlay, cp_bits_sv_base
- CP_HSVToRGB(hue, 100, 100, hueR, hueG, hueB)
- hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- overlayDC := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!hdc || !overlayDC) {
- if (hdc)
- DllCall("DeleteDC", "Ptr", hdc)
- if (overlayDC)
- DllCall("DeleteDC", "Ptr", overlayDC)
- return false
- }
- oldBitmap := DllCall("SelectObject", "Ptr", hdc, "Ptr", cp_bitmap_sv_base, "Ptr")
- oldOverlay := DllCall("SelectObject", "Ptr", overlayDC, "Ptr", cp_bitmap_overlay, "Ptr")
- VarSetCapacity(vertices, 32, 0)
- NumPut(0, vertices, 0, "Int")
- NumPut(0, vertices, 4, "Int")
- NumPut(65535, vertices, 8, "UShort")
- NumPut(65535, vertices, 10, "UShort")
- NumPut(65535, vertices, 12, "UShort")
- NumPut(0, vertices, 14, "UShort")
- NumPut(cp_sv_width, vertices, 16, "Int")
- NumPut(cp_sv_height, vertices, 20, "Int")
- NumPut(hueR * 257, vertices, 24, "UShort")
- NumPut(hueG * 257, vertices, 26, "UShort")
- NumPut(hueB * 257, vertices, 28, "UShort")
- NumPut(0, vertices, 30, "UShort")
- VarSetCapacity(mesh, 8, 0)
- NumPut(0, mesh, 0, "UInt")
- NumPut(1, mesh, 4, "UInt")
- gradientOK := DllCall("msimg32\GradientFill", "Ptr", hdc, "Ptr", &vertices, "UInt", 2, "Ptr", &mesh, "UInt", 1, "UInt", 0, "Int")
- blendOK := false
- if (gradientOK) {
- blendFunction := 0x01FF0000
- blendOK := DllCall("msimg32\AlphaBlend", "Ptr", hdc, "Int", 0, "Int", 0, "Int", cp_sv_width, "Int", cp_sv_height, "Ptr", overlayDC, "Int", 0, "Int", 0, "Int", 1, "Int", cp_sv_height, "UInt", blendFunction, "Int")
- }
- DllCall("GdiFlush")
- if (oldOverlay)
- DllCall("SelectObject", "Ptr", overlayDC, "Ptr", oldOverlay, "Ptr")
- if (oldBitmap)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBitmap, "Ptr")
- DllCall("DeleteDC", "Ptr", overlayDC)
- DllCall("DeleteDC", "Ptr", hdc)
- return (gradientOK && blendOK)
- }
- CP_BuildSVGradientPixels(hue) {
- global cp_sv_width, cp_sv_height, cp_bits_sv_base
- CP_HSVToRGB(hue, 100, 100, hueR, hueG, hueB)
- Loop, %cp_sv_height% {
- y := A_Index - 1
- value := 1 - (y / (cp_sv_height - 1))
- rowOffset := y * cp_sv_width * 4
- Loop, %cp_sv_width% {
- x := A_Index - 1
- saturation := x / (cp_sv_width - 1)
- red := Round(value * (255 + (hueR - 255) * saturation))
- green := Round(value * (255 + (hueG - 255) * saturation))
- blue := Round(value * (255 + (hueB - 255) * saturation))
- pixelOffset := rowOffset + (x * 4)
- NumPut(blue, cp_bits_sv_base + pixelOffset, 0, "UChar")
- NumPut(green, cp_bits_sv_base + pixelOffset + 1, 0, "UChar")
- NumPut(red, cp_bits_sv_base + pixelOffset + 2, 0, "UChar")
- NumPut(255, cp_bits_sv_base + pixelOffset + 3, 0, "UChar")
- }
- }
- }
- CP_BuildHueGradient() {
- global cp_bitmap_hue_base, cp_hue_width, cp_hue_height, cp_hue_base_ready
- hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!hdc)
- return false
- oldBitmap := DllCall("SelectObject", "Ptr", hdc, "Ptr", cp_bitmap_hue_base, "Ptr")
- success := true
- Loop, 6 {
- segment := A_Index - 1
- hue1 := segment * 60
- hue2 := (segment + 1) * 60
- CP_HSVToRGB(hue1, 100, 100, r1, g1, b1)
- CP_HSVToRGB(hue2, 100, 100, r2, g2, b2)
- y1 := Round(segment * cp_hue_height / 6)
- y2 := Round((segment + 1) * cp_hue_height / 6)
- VarSetCapacity(vertices, 32, 0)
- NumPut(0, vertices, 0, "Int")
- NumPut(y1, vertices, 4, "Int")
- NumPut(r1 * 257, vertices, 8, "UShort")
- NumPut(g1 * 257, vertices, 10, "UShort")
- NumPut(b1 * 257, vertices, 12, "UShort")
- NumPut(0, vertices, 14, "UShort")
- NumPut(cp_hue_width, vertices, 16, "Int")
- NumPut(y2, vertices, 20, "Int")
- NumPut(r2 * 257, vertices, 24, "UShort")
- NumPut(g2 * 257, vertices, 26, "UShort")
- NumPut(b2 * 257, vertices, 28, "UShort")
- NumPut(0, vertices, 30, "UShort")
- VarSetCapacity(mesh, 8, 0)
- NumPut(0, mesh, 0, "UInt")
- NumPut(1, mesh, 4, "UInt")
- result := DllCall("msimg32\GradientFill", "Ptr", hdc, "Ptr", &vertices, "UInt", 2, "Ptr", &mesh, "UInt", 1, "UInt", 1, "Int")
- if (!result)
- success := false
- }
- DllCall("GdiFlush")
- if (oldBitmap)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBitmap, "Ptr")
- DllCall("DeleteDC", "Ptr", hdc)
- if (success)
- cp_hue_base_ready := true
- return success
- }
- CP_DrawSV() {
- global cp_hue, cp_sat, cp_val, cp_sv_width, cp_sv_height
- global cp_bitmap_sv, cp_bitmap_sv_base, cp_bits_sv, cp_bits_sv_base
- global cp_last_sv_hue
- if (cp_last_sv_hue != cp_hue) {
- if (!CP_BuildSVGradient(cp_hue))
- CP_BuildSVGradientPixels(cp_hue)
- cp_last_sv_hue := cp_hue
- }
- DllCall("RtlMoveMemory", "Ptr", cp_bits_sv, "Ptr", cp_bits_sv_base, "UPtr", cp_sv_width * cp_sv_height * 4)
- markX := Round((cp_sat / 100) * (cp_sv_width - 1))
- markY := Round((1 - (cp_val / 100)) * (cp_sv_height - 1))
- CP_DrawCircleMarker(markX, markY)
- }
- CP_DrawHue() {
- global cp_hue, cp_hue_width, cp_hue_height
- global cp_bitmap_hue, cp_bitmap_hue_base
- global cp_bits_hue, cp_bits_hue_base, cp_hue_base_ready
- if (!cp_hue_base_ready) {
- if (!CP_BuildHueGradient()) {
- Loop, %cp_hue_height% {
- y := A_Index - 1
- hueValue := (y / (cp_hue_height - 1)) * 360
- if (hueValue >= 360)
- hueValue := 0
- CP_HSVToRGB(hueValue, 100, 100, red, green, blue)
- rowOffset := y * cp_hue_width * 4
- Loop, %cp_hue_width% {
- x := A_Index - 1
- pixelOffset := rowOffset + (x * 4)
- NumPut(blue, cp_bits_hue_base + pixelOffset, 0, "UChar")
- NumPut(green, cp_bits_hue_base + pixelOffset + 1, 0, "UChar")
- NumPut(red, cp_bits_hue_base + pixelOffset + 2, 0, "UChar")
- NumPut(255, cp_bits_hue_base + pixelOffset + 3, 0, "UChar")
- }
- }
- cp_hue_base_ready := true
- }
- }
- DllCall("RtlMoveMemory", "Ptr", cp_bits_hue, "Ptr", cp_bits_hue_base, "UPtr", cp_hue_width * cp_hue_height * 4)
- markerY := Round((cp_hue / 360) * (cp_hue_height - 1))
- if (cp_hue = 0)
- markerY := 0
- CP_DrawHorizontalMarker(markerY)
- }
- CP_DrawPreview() {
- global cp_r, cp_g, cp_b, cp_preview_width, cp_preview_height
- global cp_bitmap_preview, cp_hwnd_preview
- hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!hdc)
- return
- oldBitmap := DllCall("SelectObject", "Ptr", hdc, "Ptr", cp_bitmap_preview, "Ptr")
- colorRef := cp_r | (cp_g << 8) | (cp_b << 16)
- brush := DllCall("CreateSolidBrush", "UInt", colorRef, "Ptr")
- if (brush) {
- VarSetCapacity(rect, 16, 0)
- NumPut(0, rect, 0, "Int")
- NumPut(0, rect, 4, "Int")
- NumPut(cp_preview_width, rect, 8, "Int")
- NumPut(cp_preview_height, rect, 12, "Int")
- DllCall("FillRect", "Ptr", hdc, "Ptr", &rect, "Ptr", brush)
- DllCall("DeleteObject", "Ptr", brush)
- DllCall("GdiFlush")
- }
- if (oldBitmap)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBitmap, "Ptr")
- DllCall("DeleteDC", "Ptr", hdc)
- if (cp_gdip_ready)
- CP_DrawPreviewBorder()
- }
- CP_DrawPreviewBorder() {
- global cp_bitmap_preview, cp_preview_width, cp_preview_height, cp_pen_preview
- hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!hdc)
- return
- oldBitmap := DllCall("SelectObject", "Ptr", hdc, "Ptr", cp_bitmap_preview, "Ptr")
- graphics := CP_GdipCreateGraphics(hdc)
- if (graphics) {
- DllCall("gdiplus\GdipDrawRectangle", "Ptr", graphics, "Ptr", cp_pen_preview, "Float", 0.5, "Float", 0.5, "Float", cp_preview_width - 1.0, "Float", cp_preview_height - 1.0, "UInt")
- DllCall("gdiplus\GdipDeleteGraphics", "Ptr", graphics, "UInt")
- }
- if (oldBitmap)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBitmap, "Ptr")
- DllCall("DeleteDC", "Ptr", hdc)
- }
- CP_DrawCircleMarker(cx, cy) {
- global cp_bitmap_sv, cp_gdip_ready, cp_pen_outer, cp_pen_inner
- hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!hdc)
- return
- oldBitmap := DllCall("SelectObject", "Ptr", hdc, "Ptr", cp_bitmap_sv, "Ptr")
- if (cp_gdip_ready) {
- graphics := CP_GdipCreateGraphics(hdc)
- if (graphics) {
- DllCall("gdiplus\GdipDrawEllipse", "Ptr", graphics, "Ptr", cp_pen_outer, "Float", cx - 7.5, "Float", cy - 7.5, "Float", 15.0, "Float", 15.0, "UInt")
- DllCall("gdiplus\GdipDrawEllipse", "Ptr", graphics, "Ptr", cp_pen_inner, "Float", cx - 6.5, "Float", cy - 6.5, "Float", 13.0, "Float", 13.0, "UInt")
- DllCall("gdiplus\GdipDeleteGraphics", "Ptr", graphics, "UInt")
- }
- } else {
- nullBrush := DllCall("GetStockObject", "Int", 5, "Ptr")
- oldBrush := DllCall("SelectObject", "Ptr", hdc, "Ptr", nullBrush, "Ptr")
- blackPen := DllCall("CreatePen", "Int", 0, "Int", 3, "UInt", 0x000000, "Ptr")
- whitePen := DllCall("CreatePen", "Int", 0, "Int", 1, "UInt", 0xFFFFFF, "Ptr")
- oldPen := DllCall("SelectObject", "Ptr", hdc, "Ptr", blackPen, "Ptr")
- DllCall("Ellipse", "Ptr", hdc, "Int", cx - 7, "Int", cy - 7, "Int", cx + 8, "Int", cy + 8)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", whitePen)
- DllCall("Ellipse", "Ptr", hdc, "Int", cx - 6, "Int", cy - 6, "Int", cx + 7, "Int", cy + 7)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldPen)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBrush)
- DllCall("DeleteObject", "Ptr", blackPen)
- DllCall("DeleteObject", "Ptr", whitePen)
- }
- if (oldBitmap)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBitmap, "Ptr")
- DllCall("DeleteDC", "Ptr", hdc)
- }
- CP_DrawHorizontalMarker(y) {
- global cp_bitmap_hue, cp_hue_width, cp_gdip_ready
- global cp_pen_outer, cp_pen_inner
- hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
- if (!hdc)
- return
- oldBitmap := DllCall("SelectObject", "Ptr", hdc, "Ptr", cp_bitmap_hue, "Ptr")
- if (cp_gdip_ready) {
- graphics := CP_GdipCreateGraphics(hdc)
- if (graphics) {
- DllCall("gdiplus\GdipDrawLine", "Ptr", graphics, "Ptr", cp_pen_outer, "Float", 0.5, "Float", y, "Float", cp_hue_width - 0.5, "Float", y, "UInt")
- DllCall("gdiplus\GdipDrawLine", "Ptr", graphics, "Ptr", cp_pen_inner, "Float", 0.5, "Float", y, "Float", cp_hue_width - 0.5, "Float", y, "UInt")
- DllCall("gdiplus\GdipDeleteGraphics", "Ptr", graphics, "UInt")
- }
- } else {
- blackPen := DllCall("CreatePen", "Int", 0, "Int", 3, "UInt", 0x000000, "Ptr")
- whitePen := DllCall("CreatePen", "Int", 0, "Int", 1, "UInt", 0xFFFFFF, "Ptr")
- oldPen := DllCall("SelectObject", "Ptr", hdc, "Ptr", blackPen, "Ptr")
- DllCall("MoveToEx", "Ptr", hdc, "Int", 0, "Int", y, "Ptr", 0)
- DllCall("LineTo", "Ptr", hdc, "Int", cp_hue_width, "Int", y)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", whitePen)
- DllCall("MoveToEx", "Ptr", hdc, "Int", 0, "Int", y, "Ptr", 0)
- DllCall("LineTo", "Ptr", hdc, "Int", cp_hue_width, "Int", y)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldPen)
- DllCall("DeleteObject", "Ptr", blackPen)
- DllCall("DeleteObject", "Ptr", whitePen)
- }
- if (oldBitmap)
- DllCall("SelectObject", "Ptr", hdc, "Ptr", oldBitmap, "Ptr")
- DllCall("DeleteDC", "Ptr", hdc)
- }
- ; -------------------------- Embedded GDI+ rendering --------------------------
- CP_GdipInitialize() {
- global cp_gdip_token, cp_gdip_module, cp_gdip_ready
- global cp_pen_outer, cp_pen_inner, cp_pen_preview
- cp_gdip_module := DllCall("LoadLibrary", "Str", "gdiplus", "Ptr")
- if (!cp_gdip_module)
- return false
- VarSetCapacity(startupInput, A_PtrSize = 8 ? 24 : 16, 0)
- NumPut(1, startupInput, 0, "UInt")
- status := DllCall("gdiplus\GdiplusStartup", "UPtr*", cp_gdip_token, "Ptr", &startupInput, "Ptr", 0, "UInt")
- if (status != 0 || !cp_gdip_token) {
- DllCall("FreeLibrary", "Ptr", cp_gdip_module)
- cp_gdip_module := 0
- cp_gdip_token := 0
- return false
- }
- cp_pen_outer := CP_GdipCreatePen(0xFF05070A, 3.0)
- cp_pen_inner := CP_GdipCreatePen(0xFFF5F7FA, 1.25)
- cp_pen_preview := CP_GdipCreatePen(0xFFB7C0CC, 1.0)
- cp_gdip_ready := !!(cp_pen_outer && cp_pen_inner && cp_pen_preview)
- return cp_gdip_ready
- }
- CP_GdipCreateGraphics(hdc) {
- graphics := 0
- status := DllCall("gdiplus\GdipCreateFromHDC", "Ptr", hdc, "Ptr*", graphics, "UInt")
- if (status != 0 || !graphics)
- return 0
- DllCall("gdiplus\GdipSetSmoothingMode", "Ptr", graphics, "Int", 4, "UInt")
- return graphics
- }
- CP_GdipCreatePen(argb, width) {
- pen := 0
- status := DllCall("gdiplus\GdipCreatePen1", "UInt", argb, "Float", width, "Int", 2, "Ptr*", pen, "UInt")
- if (status != 0)
- return 0
- return pen
- }
- CP_GdipCleanup() {
- global cp_gdip_token, cp_gdip_module, cp_gdip_ready
- global cp_pen_outer, cp_pen_inner, cp_pen_preview
- if (cp_pen_outer)
- DllCall("gdiplus\GdipDeletePen", "Ptr", cp_pen_outer, "UInt")
- if (cp_pen_inner)
- DllCall("gdiplus\GdipDeletePen", "Ptr", cp_pen_inner, "UInt")
- if (cp_pen_preview)
- DllCall("gdiplus\GdipDeletePen", "Ptr", cp_pen_preview, "UInt")
- cp_pen_outer := 0
- cp_pen_inner := 0
- cp_pen_preview := 0
- cp_gdip_ready := false
- if (cp_gdip_token)
- DllCall("gdiplus\GdiplusShutdown", "Ptr", cp_gdip_token)
- cp_gdip_token := 0
- if (cp_gdip_module)
- DllCall("FreeLibrary", "Ptr", cp_gdip_module)
- cp_gdip_module := 0
- }
- ; -------------------------- Color conversion and input validation ------------
- CP_HSVToRGB(h, s, v, ByRef red, ByRef green, ByRef blue) {
- h += 0
- s := s / 100
- v := v / 100
- if (h < 0)
- h := 0
- if (h >= 360)
- h := Mod(h, 360)
- chroma := v * s
- sector := h / 60
- x := chroma * (1 - Abs(Mod(sector, 2) - 1))
- match := v - chroma
- if (sector < 1)
- r1 := chroma, g1 := x, b1 := 0
- else if (sector < 2)
- r1 := x, g1 := chroma, b1 := 0
- else if (sector < 3)
- r1 := 0, g1 := chroma, b1 := x
- else if (sector < 4)
- r1 := 0, g1 := x, b1 := chroma
- else if (sector < 5)
- r1 := x, g1 := 0, b1 := chroma
- else
- r1 := chroma, g1 := 0, b1 := x
- red := Round((r1 + match) * 255)
- green := Round((g1 + match) * 255)
- blue := Round((b1 + match) * 255)
- }
- CP_RGBToHSV(red, green, blue, ByRef h, ByRef s, ByRef v) {
- redN := red / 255
- greenN := green / 255
- blueN := blue / 255
- maxValue := redN
- if (greenN > maxValue)
- maxValue := greenN
- if (blueN > maxValue)
- maxValue := blueN
- minValue := redN
- if (greenN < minValue)
- minValue := greenN
- if (blueN < minValue)
- minValue := blueN
- delta := maxValue - minValue
- ; Hue is undefined for gray and black. Preserve the caller's current hue
- ; so dragging the square to V=0 (or S=0) does not snap the hue slider to
- ; red and teleport the SV marker to the bottom-left corner.
- if (delta != 0) {
- if (maxValue = redN) {
- h := 60 * ((greenN - blueN) / delta)
- if (h < 0)
- h += 360
- } else if (maxValue = greenN)
- h := 60 * (((blueN - redN) / delta) + 2)
- else
- h := 60 * (((redN - greenN) / delta) + 4)
- h := Round(h)
- if (h >= 360)
- h := 0
- }
- if (maxValue = 0)
- s := 0
- else
- s := (delta / maxValue) * 100
- v := maxValue * 100
- s := Round(s)
- v := Round(v)
- }
- CP_ParseHex(hexText, ByRef red, ByRef green, ByRef blue) {
- hexText := Trim(hexText)
- StringReplace, hexText, hexText, #,, All
- StringReplace, hexText, hexText, 0x,, All
- if (StrLen(hexText) = 3 && RegExMatch(hexText, "i)^[0-9a-f]{3}$")) {
- red := "0x" . SubStr(hexText, 1, 1) . SubStr(hexText, 1, 1)
- green := "0x" . SubStr(hexText, 2, 1) . SubStr(hexText, 2, 1)
- blue := "0x" . SubStr(hexText, 3, 1) . SubStr(hexText, 3, 1)
- red += 0
- green += 0
- blue += 0
- return true
- }
- if (StrLen(hexText) != 6 || !RegExMatch(hexText, "i)^[0-9a-f]{6}$"))
- return false
- red := "0x" . SubStr(hexText, 1, 2)
- green := "0x" . SubStr(hexText, 3, 2)
- blue := "0x" . SubStr(hexText, 5, 2)
- red += 0
- green += 0
- blue += 0
- return true
- }
- CP_IsIntegerInRange(value, minimum, maximum) {
- value := Trim(value)
- if (value = "" || !RegExMatch(value, "^\d+$"))
- return false
- number := value + 0
- return (number >= minimum && number <= maximum)
- }
- CP_UpdateFields(skipHwnd := 0) {
- global cp_updating, cp_r, cp_g, cp_b, cp_hue, cp_sat, cp_val, cp_hex
- global cp_hwnd_edit_r, cp_hwnd_edit_g, cp_hwnd_edit_b
- global cp_hwnd_edit_h, cp_hwnd_edit_s, cp_hwnd_edit_v, cp_hwnd_edit_hex
- cp_updating := true
- if (skipHwnd != cp_hwnd_edit_r)
- GuiControl,, CP_EditR, %cp_r%
- if (skipHwnd != cp_hwnd_edit_g)
- GuiControl,, CP_EditG, %cp_g%
- if (skipHwnd != cp_hwnd_edit_b)
- GuiControl,, CP_EditB, %cp_b%
- if (skipHwnd != cp_hwnd_edit_h)
- GuiControl,, CP_EditH, %cp_hue%
- if (skipHwnd != cp_hwnd_edit_s)
- GuiControl,, CP_EditS, %cp_sat%
- if (skipHwnd != cp_hwnd_edit_v)
- GuiControl,, CP_EditV, %cp_val%
- cp_hex := Format("{:02X}{:02X}{:02X}", cp_r, cp_g, cp_b)
- if (skipHwnd != cp_hwnd_edit_hex)
- GuiControl,, CP_EditHex, %cp_hex%
- cp_updating := false
- }
- CP_Cleanup(exitReason := "", exitCode := 0) {
- global cp_drag_mode, cp_drag_hwnd, cp_drag_timer_pending
- global cp_bitmap_sv, cp_bitmap_sv_base, cp_bitmap_hue, cp_bitmap_hue_base
- global cp_bitmap_preview, cp_bitmap_overlay, cp_bitmap_eyedropper
- global cp_hwnd_sv, cp_hwnd_hue, cp_hwnd_preview, cp_hwnd_eyedropper_icon
- global cp_screen_pick_active, cp_screen_pick_cursor_saved
- ; Cancel any in-flight screen pick so its hotkeys and cursor are released.
- if (cp_screen_pick_active) {
- cp_screen_pick_active := false
- SetTimer, CP_ScreenPickTrack, Off
- try {
- Hotkey, *LButton, Off
- Hotkey, *RButton, Off
- Hotkey, *Escape, Off
- }
- CP_PickPanelHide()
- }
- CP_RestoreSystemCursors()
- SetTimer, CP_DragUpdate, Off
- cp_drag_mode := ""
- cp_drag_hwnd := 0
- cp_drag_timer_pending := false
- if (cp_hwnd_sv)
- DllCall("SendMessage", "Ptr", cp_hwnd_sv, "UInt", 0x172, "Ptr", 0, "Ptr", 0, "Ptr")
- if (cp_hwnd_hue)
- DllCall("SendMessage", "Ptr", cp_hwnd_hue, "UInt", 0x172, "Ptr", 0, "Ptr", 0, "Ptr")
- if (cp_hwnd_preview)
- DllCall("SendMessage", "Ptr", cp_hwnd_preview, "UInt", 0x172, "Ptr", 0, "Ptr", 0, "Ptr")
- if (cp_hwnd_eyedropper_icon)
- DllCall("SendMessage", "Ptr", cp_hwnd_eyedropper_icon, "UInt", 0x172, "Ptr", 0, "Ptr", 0, "Ptr")
- ; The screen-pick overlay and its Gdip resources must be released before
- ; GdipShutdown runs, since Gdip_DeleteGraphics/Gdip_DeleteBrush/etc still
- ; need a live GDI+ runtime.
- CP_PickPanelCleanup()
- CP_GdipCleanup()
- if (cp_bitmap_sv)
- DllCall("DeleteObject", "Ptr", cp_bitmap_sv)
- if (cp_bitmap_sv_base)
- DllCall("DeleteObject", "Ptr", cp_bitmap_sv_base)
- if (cp_bitmap_hue)
- DllCall("DeleteObject", "Ptr", cp_bitmap_hue)
- if (cp_bitmap_hue_base)
- DllCall("DeleteObject", "Ptr", cp_bitmap_hue_base)
- if (cp_bitmap_preview)
- DllCall("DeleteObject", "Ptr", cp_bitmap_preview)
- if (cp_bitmap_overlay)
- DllCall("DeleteObject", "Ptr", cp_bitmap_overlay)
- if (cp_bitmap_eyedropper)
- DllCall("DeleteObject", "Ptr", cp_bitmap_eyedropper)
- }
Advertisement
Add Comment
Please, Sign In to add comment