;- TOP
; AZJIO 13.11.2024
EnableExplicit
;- # Constants
#Window = 0
Enumeration Gadget
#btn
#chTrans
#lg
#lvg
#Coor
#btnSave
EndEnumeration
Enumeration Menu
#mL
#mR
#mV
#mN
#mL1
#mR1
#mV1
#mN1
#mPos
EndEnumeration
#BackColor = $231504
#BackColor2 = $d6d5d4
;- ● Global
Global hGUI
Global slider03
Global id_Gadget = 20
Define trn = 2
; Define cx, cy
Define hWnd, gx, gy, id_gadget2
Define co.POINT
Define indent.POINT
Define tmp.POINT
Structure GdtID
id.i
hdl.i
EndStructure
Global NewList GdtID.GdtID()
;- ● En
#CountStrLang = 9
Global Dim Lng.s(#CountStrLang)
Lng(0) = "Button"
Lng(1) = "CheckBox"
Lng(2) = "Editor"
Lng(3) = "Frame"
Lng(4) = "Text"
Lng(5) = "String"
Lng(6) = "ListView"
Lng(7) = "ListIcon"
Lng(8) = "ComboBox"
Lng(9) = "Option"
Structure Gadgets
List gdt.i()
EndStructure
Global Dim Gadgets.Gadgets(9)
;- ● Declare
Declare SizeWindowHandler()
Declare AddGadget(item)
Declare GadgetPB(Handle)
Declare moveLR(shift)
Declare moveVN(shift)
Declare moveLR1(shift)
Declare moveVN1(shift)
Declare Save()
; Declare GetGadget(hwnd)
slider03 = 55
;-┌──GUI──┐
hGUI = OpenWindow(#Window, 0, 0, 440, 370,
"CreationGuiPB",
#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
; #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | centered)
If hGUI
WindowBounds(#Window, 400, 370, #PB_Ignore, #PB_Ignore)
SetWindowLongPtr_(hGUI, #GWL_EXSTYLE, GetWindowLongPtr_(hGUI, #GWL_EXSTYLE) | #WS_EX_TOPMOST | #WS_EX_LAYERED)
; SetLayeredWindowAttributes_(hGUI, 0, 255, 2)
; SetLayeredWindowAttributes_(hGUI, 0, 255, trn)
SetLayeredWindowAttributes_(hGUI, #BackColor, 255, trn)
; SetWindowColor(#Window, #BackColor)
; StickyWindow(#Window, #True)
; SetWindowCallback(@Callback_Win())
; SetWindowColor(#Window, $e5e5e5)
TextGadget(#Coor, 270, 5, 140, 19, "00, 00, 00, 00", #SS_NOTIFY | #SS_LEFTNOWORDWRAP)
ButtonGadget(#btnSave, 395, 255, 45, 23, "Save")
ListViewGadget(#lvg, 340, 27, 85, 190)
AddGadgetItem(#lvg, - 1, "Button")
AddGadgetItem(#lvg, - 1, "CheckBox")
AddGadgetItem(#lvg, - 1, "Editor")
AddGadgetItem(#lvg, - 1, "Frame")
AddGadgetItem(#lvg, - 1, "Text")
AddGadgetItem(#lvg, - 1, "String")
AddGadgetItem(#lvg, - 1, "ListView")
AddGadgetItem(#lvg, - 1, "ListIcon")
AddGadgetItem(#lvg, - 1, "ComboBox")
AddGadgetItem(#lvg, - 1, "Option")
CheckBoxGadget(#chTrans, 395, 280, 37, 23, "Trns")
TextGadget(#lg, 0, 0, 250, 260, "")
SetGadgetColor(#lg, #PB_Gadget_BackColor, #BackColor2)
BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler())
AddKeyboardShortcut(#Window, #PB_Shortcut_Left, #mL) ; влево
AddKeyboardShortcut(#Window, #PB_Shortcut_Right, #mR); вправо
AddKeyboardShortcut(#Window, #PB_Shortcut_Up, #mV) ; вверх
AddKeyboardShortcut(#Window, #PB_Shortcut_Down, #mN) ; вниз
AddKeyboardShortcut(#Window, #PB_Shortcut_Control | #PB_Shortcut_Left, #mL1) ; влево
AddKeyboardShortcut(#Window, #PB_Shortcut_Control | #PB_Shortcut_Right, #mR1); вправо
AddKeyboardShortcut(#Window, #PB_Shortcut_Control | #PB_Shortcut_Up, #mV1) ; вверх
AddKeyboardShortcut(#Window, #PB_Shortcut_Control | #PB_Shortcut_Down, #mN1) ; вниз
AddKeyboardShortcut(#Window, #PB_Shortcut_Space, #mPos) ; вставить в позицию
; AddKeyboardShortcut(#Window, #PB_Shortcut_Control | #PB_Shortcut_Shift | #PB_Shortcut_C, ) ; Ctrl+Shift+C
; AddKeyboardShortcut(#Window, #PB_Shortcut_Control | #PB_Shortcut_E, ) ; Ctrl+E
; AddKeyboardShortcut(#Window, #PB_Shortcut_Return, ) ; Enter
;-┌──Loop──┐
Repeat
If GetAsyncKeyState_(#VK_LBUTTON)
; co\x = DesktopMouseX()
; co\y = DesktopMouseY()
; Debug GetGadget(#Window)
; Debug ChildWindowFromPoint_(WindowID(#Window), co)
GetCursorPos_(@co.POINT)
hWnd = WindowFromPoint_(co\x | co\y << 32)
id_gadget2 = GadgetPB(hWnd)
If id_gadget2 > 20 And IsGadget(id_gadget2)
co\x = WindowMouseX(#Window)
co\y = WindowMouseY(#Window)
indent\x = co\x - GadgetX(id_gadget2)
indent\y = co\y - GadgetY(id_gadget2)
EndIf
; Debug "Find ID = " + Str(id_gadget2)
; Debug "WFP = " + Str(hWnd)
If id_gadget2 > 20 And IsGadget(id_gadget2)
While GetAsyncKeyState_(#VK_LBUTTON)
co\x = WindowMouseX(#Window)
co\y = WindowMouseY(#Window)
If tmp\x <> co\x Or tmp\y <> co\y
ResizeGadget(id_gadget2, co\x - indent\x, co\y - indent\y, #PB_Ignore , #PB_Ignore)
UpdateWindow_(hGUI)
tmp\x = co\x
tmp\y = co\y
EndIf
Wend
EndIf
EndIf
Select WaitWindowEvent()
Case #PB_Event_Timer
If EventTimer() = 0
SetGadgetColor(#Coor, #PB_Gadget_BackColor, #PB_Default)
RemoveWindowTimer(#Window, 0)
EndIf
;- ├ Menu
Case #PB_Event_Menu
Select EventMenu()
Case #mL
moveLR( - 1)
Case #mR
moveLR(1)
Case #mV
moveVN( - 1)
Case #mN
moveVN(1)
Case #mL1
moveLR1( - 1)
Case #mR1
moveLR1(1)
Case #mV1
moveVN1( - 1)
Case #mN1
moveVN1(1)
EndSelect
Case #PB_Event_Gadget
;- ├ Gadget
Select EventGadget()
Case #btnSave
Save()
Case #Coor
SetClipboardText(GetGadgetText(#Coor))
SetGadgetColor(#Coor, #PB_Gadget_BackColor, $8080FF)
AddWindowTimer(#Window, 0, 55)
Case #chTrans
If GetGadgetState(#chTrans) & #PB_Checkbox_Checked
SetLayeredWindowAttributes_(hGUI, #BackColor, 255 - slider03, trn)
Else
SetLayeredWindowAttributes_(hGUI, #BackColor2, 0, 1)
EndIf
Case #lvg
AddGadget(GetGadgetState(#lvg))
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
;-└──Loop──┘
EndIf
Procedure Save()
Protected tmp$, n, i
For i = 0 To 9
ForEach Gadgets(i)\gdt()
n+1
tmp$ + Lng(i) + "Gadget(" + n + ", " + Str(GadgetX(Gadgets(i)\gdt())) + ", " + Str(GadgetY(Gadgets(i)\gdt())) + ", " + Str(GadgetWidth(Gadgets(i)\gdt())) + ", " + Str(GadgetHeight(Gadgets(i)\gdt())) + ", " + #DQUOTE$ + GetGadgetText(Gadgets(i)\gdt()) + #DQUOTE$ + ")" + #CRLF$
Next
Next
SetClipboardText(tmp$)
MessageRequester("Code on clipboard", tmp$)
EndProcedure
Procedure AddGadget(item)
Protected w, h, y
Static n
y = WindowHeight(#Window) - 50
w = 120
h = 30
n + 1
id_Gadget + 1
Select item
Case - 1
ProcedureReturn
Case 0
ButtonGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(0))
Case 1
CheckBoxGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(1))
Case 2
EditorGadget(id_Gadget, 10, y, w, h)
Case 3
; FrameGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(3))
TextGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(3), #SS_NOTIFY | #WS_BORDER)
Case 4
TextGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(4), #SS_NOTIFY) ; #SS_NOTIFY позволяет перетаскивать
Case 5
StringGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(5))
Case 6
ListViewGadget(id_Gadget, 10, y, w, h)
Case 7
ListIconGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(7), w)
Case 8
ComboBoxGadget(id_Gadget, 10, y, w, h)
Case 9
OptionGadget(id_Gadget, 10, y, w, h, Str(n) + " " + Lng(9))
EndSelect
AddElement(GdtID())
GdtID()\id = id_Gadget
GdtID()\hdl = GadgetID(id_Gadget)
; Debug "Add ID = " + Str(GdtID()\id)
; Debug "Add hwnd = " + Str(GdtID()\hdl)
AddElement(Gadgets(item)\gdt())
Gadgets(item)\gdt() = id_Gadget
EndProcedure
Procedure SizeWindowHandler()
Protected w, h
w = WindowWidth(#Window)
h = WindowHeight(#Window)
ResizeGadget(#lg, #PB_Ignore, #PB_Ignore, w - 190, h - 110)
ResizeGadget(#lvg, w - 100, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#chTrans, w - 45, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Coor, w - 170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#btnSave, w - 45, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ForEach GdtID()
ResizeGadget(GdtID()\id, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore)
Next
EndProcedure
Procedure GadgetPB(Handle)
ForEach GdtID()
If GdtID()\hdl = Handle
ProcedureReturn GdtID()\id
EndIf
Next
ProcedureReturn 0 ; минимальный ID=20, поэтому используем 0
EndProcedure
Procedure moveLR(shift)
Protected x
x = GadgetX(id_Gadget) + shift
ResizeGadget(id_Gadget, x, #PB_Ignore, #PB_Ignore , #PB_Ignore)
SetGadgetText(#Coor, Str(x) + ", " + Str(GadgetY(id_Gadget)) + ", " + Str(GadgetWidth(id_Gadget)) + ", " + Str(GadgetHeight(id_Gadget)))
; нарисовать кайму активного
EndProcedure
Procedure moveVN(shift)
Protected y
y = GadgetY(id_Gadget) + shift
ResizeGadget(id_Gadget, #PB_Ignore, y, #PB_Ignore , #PB_Ignore)
SetGadgetText(#Coor, Str(GadgetX(id_Gadget)) + ", " + Str(y) + ", " + Str(GadgetWidth(id_Gadget)) + ", " + Str(GadgetHeight(id_Gadget)))
EndProcedure
Procedure moveLR1(shift)
Protected w
w = GadgetWidth(id_Gadget) + shift
ResizeGadget(id_Gadget, #PB_Ignore, #PB_Ignore, w , #PB_Ignore)
SetGadgetText(#Coor, Str(GadgetX(id_Gadget)) + ", " + Str(GadgetY(id_Gadget)) + ", " + Str(w) + ", " + Str(GadgetHeight(id_Gadget)))
EndProcedure
Procedure moveVN1(shift)
Protected h
h = GadgetHeight(id_Gadget) + shift
ResizeGadget(id_Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, h)
SetGadgetText(#Coor, Str(GadgetX(id_Gadget)) + ", " + Str(GadgetY(id_Gadget)) + ", " + Str(GadgetWidth(id_Gadget)) + ", " + Str(h))
EndProcedure