Guest User

Untitled

a guest
Mar 2nd, 2026
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. global SRF_roll
  2. global SRF_defs
  3. global SRF_currentIndex
  4. global SRF_dnBtnRef
  5. global SRF_flyForm
  6. global SRF_flyButtons
  7. global SRF_hoverIndex
  8.  
  9. global SRF_dnBG
  10. global SRF_dnTXT
  11. global SRF_dnBorder
  12. global SRF_dnBlue
  13. global SRF_dnBlueText
  14.  
  15. SRF_defs = #("A","B","C","D","E")
  16. if SRF_currentIndex == undefined do SRF_currentIndex = 1
  17. SRF_hoverIndex = 0
  18.  
  19. fn SRF_clamp255 v = (amax 0 (amin 255 (v as integer)))
  20.  
  21. fn SRF_toDNColorFromMaxColor c =
  22. (
  23. (dotNetClass "System.Drawing.Color").FromArgb (SRF_clamp255 c.r) (SRF_clamp255 c.g) (SRF_clamp255 c.b)
  24. )
  25.  
  26. fn SRF_maxColorFromColorMan key fallbackColor =
  27. (
  28. local p = undefined
  29. try (p = colorMan.getColor key) catch()
  30. if p == undefined then fallbackColor else (color (p.x*255) (p.y*255) (p.z*255))
  31. )
  32.  
  33. fn SRF_maxColorFromAnyColorMan keys fallbackColor =
  34. (
  35. for k in keys do
  36. (
  37. local p = undefined
  38. try (p = colorMan.getColor k) catch()
  39. if p != undefined do return (color (p.x*255) (p.y*255) (p.z*255))
  40. )
  41. fallbackColor
  42. )
  43.  
  44. fn SRF_closeFlyForm =
  45. (
  46. if SRF_flyForm != undefined do
  47. (
  48. try (SRF_flyForm.Capture = false) catch()
  49. try (SRF_flyForm.Close()) catch()
  50. try (SRF_flyForm.Dispose()) catch()
  51. SRF_flyForm = undefined
  52. )
  53. SRF_flyButtons = undefined
  54. SRF_hoverIndex = 0
  55. )
  56.  
  57. fn SRF_applyFlyColors =
  58. (
  59. if SRF_flyButtons == undefined then return false
  60. for i = 1 to SRF_flyButtons.count do
  61. (
  62. local b = SRF_flyButtons[i]
  63. if (i == SRF_hoverIndex) or (i == SRF_currentIndex and SRF_hoverIndex == 0) then
  64. (
  65. try (b.BackColor = SRF_dnBlue) catch()
  66. try (b.ForeColor = SRF_dnBlueText) catch()
  67. )
  68. else if i == SRF_currentIndex then
  69. (
  70. -- selected stays blue (если нет hover)
  71. try (b.BackColor = SRF_dnBlue) catch()
  72. try (b.ForeColor = SRF_dnBlueText) catch()
  73. )
  74. else
  75. (
  76. try (b.BackColor = SRF_dnBG) catch()
  77. try (b.ForeColor = SRF_dnTXT) catch()
  78. )
  79. )
  80. true
  81. )
  82.  
  83. fn SRF_updateHoverFromCursor form tileW tileH count =
  84. (
  85. local mp = (dotNetClass "System.Windows.Forms.Control").MousePosition
  86. local p = form.PointToClient mp
  87.  
  88. local idx = 0
  89. if (p.X >= 0 and p.X < tileW and p.Y >= 0 and p.Y < (tileH*count)) do
  90. (
  91. idx = (floor ((p.Y as float) / tileH)) + 1
  92. if idx < 1 or idx > count do idx = 0
  93. )
  94.  
  95. if idx != SRF_hoverIndex do
  96. (
  97. SRF_hoverIndex = idx
  98. SRF_applyFlyColors()
  99. )
  100. )
  101.  
  102. -- ---- flyout form handlers ----
  103. fn SRF_onFlyFormDeactivate s e = ( SRF_closeFlyForm() )
  104.  
  105. fn SRF_onFlyFormKeyDown s e =
  106. (
  107. if e.KeyCode == (dotNetClass "System.Windows.Forms.Keys").Escape do SRF_closeFlyForm()
  108. )
  109.  
  110. fn SRF_onFlyFormPaint s e =
  111. (
  112. local pen = dotNetObject "System.Drawing.Pen" SRF_dnBorder
  113. e.Graphics.DrawRectangle pen 0 0 (s.ClientSize.Width-1) (s.ClientSize.Height-1)
  114. pen.Dispose()
  115. )
  116.  
  117. fn SRF_onFlyFormMouseMove s e =
  118. (
  119. SRF_updateHoverFromCursor s 32 32 SRF_defs.count
  120. )
  121.  
  122. fn SRF_onFlyFormMouseUp s e =
  123. (
  124. if e.Button == (dotNetClass "System.Windows.Forms.MouseButtons").Left do
  125. (
  126. -- на всякий случай обновим hover в момент отпускания
  127. SRF_updateHoverFromCursor s 32 32 SRF_defs.count
  128.  
  129. if SRF_hoverIndex != 0 then
  130. (
  131. SRF_currentIndex = SRF_hoverIndex
  132. if SRF_dnBtnRef != undefined do (try (SRF_dnBtnRef.text = SRF_defs[SRF_currentIndex]) catch())
  133. format "Selected: %\n" SRF_defs[SRF_currentIndex]
  134. )
  135. SRF_closeFlyForm()
  136. )
  137. )
  138.  
  139. fn SRF_showFlyoutBelowButton dnBtn =
  140. (
  141. SRF_closeFlyForm()
  142.  
  143. local cnt = SRF_defs.count
  144. local tile = 32
  145. local w = tile
  146. local h = tile * cnt
  147.  
  148. local f = dotNetObject "System.Windows.Forms.Form"
  149. SRF_flyForm = f
  150.  
  151. -- disable autoscale (DPI)
  152. try (f.AutoScaleMode = (dotNetClass "System.Windows.Forms.AutoScaleMode").None) catch()
  153. try (f.AutoSize = false) catch()
  154. try (f.Margin = dotNetObject "System.Windows.Forms.Padding" 0) catch()
  155. try (f.Padding = dotNetObject "System.Windows.Forms.Padding" 0) catch()
  156.  
  157. f.FormBorderStyle = (dotNetClass "System.Windows.Forms.FormBorderStyle").None
  158. f.StartPosition = (dotNetClass "System.Windows.Forms.FormStartPosition").Manual
  159. f.ShowInTaskbar = false
  160. f.TopMost = true
  161. f.KeyPreview = true
  162.  
  163. f.BackColor = SRF_dnBG
  164. f.ForeColor = SRF_dnTXT
  165.  
  166. local sz = dotNetObject "System.Drawing.Size" w h
  167. f.ClientSize = sz
  168. try (f.MinimumSize = sz) catch()
  169. try (f.MaximumSize = sz) catch()
  170. try (f.Size = sz) catch()
  171.  
  172. -- place under main button
  173. local pt = dnBtn.PointToScreen (dotNetObject "System.Drawing.Point" 0 dnBtn.height)
  174. f.Location = pt
  175.  
  176. -- events
  177. dotNet.addEventHandler f "Deactivate" SRF_onFlyFormDeactivate
  178. dotNet.addEventHandler f "KeyDown" SRF_onFlyFormKeyDown
  179. dotNet.addEventHandler f "Paint" SRF_onFlyFormPaint
  180. dotNet.addEventHandler f "MouseMove" SRF_onFlyFormMouseMove
  181. dotNet.addEventHandler f "MouseUp" SRF_onFlyFormMouseUp
  182.  
  183. -- build buttons (только для отрисовки текста/фона)
  184. SRF_flyButtons = #()
  185. for i = 1 to cnt do
  186. (
  187. local b = dotNetObject "System.Windows.Forms.Button"
  188. b.Text = SRF_defs[i]
  189. b.Tag = i
  190.  
  191. try (b.AutoSize = false) catch()
  192. b.FlatStyle = (dotNetClass "System.Windows.Forms.FlatStyle").Flat
  193. b.UseVisualStyleBackColor = false
  194.  
  195. b.Size = dotNetObject "System.Drawing.Size" tile tile
  196. b.Location = dotNetObject "System.Drawing.Point" 0 ((i-1)*tile)
  197. b.Margin = dotNetObject "System.Windows.Forms.Padding" 0
  198. b.Padding = dotNetObject "System.Windows.Forms.Padding" 0
  199. b.TabStop = false
  200. b.TextAlign = (dotNetClass "System.Drawing.ContentAlignment").MiddleCenter
  201.  
  202. try (b.Font = dnBtn.Font) catch()
  203. try (b.FlatAppearance.BorderSize = 0) catch()
  204.  
  205. f.Controls.Add b
  206. append SRF_flyButtons b
  207. )
  208.  
  209. -- show + IMPORTANT: move mouse capture from main button to flyout form
  210. try (dnBtn.Capture = false) catch()
  211. f.Show()
  212. try (f.Activate()) catch()
  213. try (f.Capture = true) catch()
  214.  
  215. -- force size again (иногда WinForms пересчитывает после Show)
  216. try (f.ClientSize = sz) catch()
  217. try (f.MinimumSize = sz) catch()
  218. try (f.MaximumSize = sz) catch()
  219. try (f.Size = sz) catch()
  220.  
  221. -- initial colors (selected blue)
  222. SRF_hoverIndex = 0
  223. SRF_applyFlyColors()
  224. )
  225.  
  226. -- ---------- cleanup previous instance ----------
  227. try (cui.UnRegisterDialogBar SRF_roll) catch()
  228. try (destroyDialog SRF_roll) catch()
  229. SRF_closeFlyForm()
  230.  
  231. -- ------------------ UI ------------------------
  232. rollout SRF_roll "Fly" width:32 height:32
  233. (
  234. dotNetControl dnBtn "System.Windows.Forms.Button" pos:[0,0] width:32 height:32
  235.  
  236. local holdTimer
  237. local holdFired = false
  238.  
  239. fn updateButton =
  240. (
  241. if SRF_currentIndex < 1 or SRF_currentIndex > SRF_defs.count do SRF_currentIndex = 1
  242. dnBtn.text = SRF_defs[SRF_currentIndex]
  243. )
  244.  
  245. fn runCurrent = ( format "Current: %\n" SRF_defs[SRF_currentIndex] )
  246.  
  247. fn onHoldTick s e =
  248. (
  249. holdTimer.Stop()
  250. holdFired = true
  251. SRF_showFlyoutBelowButton dnBtn
  252. )
  253.  
  254. on dnBtn MouseDown s e do
  255. (
  256. if e.Button == (dotNetClass "System.Windows.Forms.MouseButtons").Left do
  257. (
  258. holdFired = false
  259. holdTimer.Start()
  260. )
  261. )
  262.  
  263. on dnBtn MouseUp s e do
  264. (
  265. if e.Button == (dotNetClass "System.Windows.Forms.MouseButtons").Left do
  266. (
  267. if holdTimer.Enabled do holdTimer.Stop()
  268. if not holdFired do runCurrent()
  269. )
  270. )
  271.  
  272. on SRF_roll open do
  273. (
  274. SRF_dnBtnRef = dnBtn
  275.  
  276. -- theme-ish colors (dark fallbacks)
  277. local mxBG = SRF_maxColorFromColorMan #background (color 68 68 68)
  278. local mxTXT = SRF_maxColorFromColorMan #text (color 220 220 220)
  279. local mxBorder = SRF_maxColorFromAnyColorMan #(#shadow, #hilight, #hilite) (color 40 40 40)
  280. local mxBlue = SRF_maxColorFromAnyColorMan #(#itemhighlight, #itemhilight, #highlight, #hilight) (color 0 120 215)
  281.  
  282. SRF_dnBG = SRF_toDNColorFromMaxColor mxBG
  283. SRF_dnTXT = SRF_toDNColorFromMaxColor mxTXT
  284. SRF_dnBorder = SRF_toDNColorFromMaxColor mxBorder
  285. SRF_dnBlue = SRF_toDNColorFromMaxColor mxBlue
  286. SRF_dnBlueText = (dotNetClass "System.Drawing.Color").FromArgb 255 255 255
  287.  
  288. dnBtn.FlatStyle = (dotNetClass "System.Windows.Forms.FlatStyle").Flat
  289. dnBtn.UseVisualStyleBackColor = false
  290. dnBtn.BackColor = SRF_dnBG
  291. dnBtn.ForeColor = SRF_dnTXT
  292. dnBtn.TextAlign = (dotNetClass "System.Drawing.ContentAlignment").MiddleCenter
  293. try (dnBtn.Font = dotNetObject "System.Drawing.Font" "Segoe UI" 10.0) catch()
  294. try (dnBtn.FlatAppearance.BorderSize = 1) catch()
  295. try (dnBtn.FlatAppearance.BorderColor = SRF_dnBorder) catch()
  296.  
  297. holdTimer = dotNetObject "System.Windows.Forms.Timer"
  298. holdTimer.Interval = 350
  299. dotNet.addEventHandler holdTimer "Tick" onHoldTick
  300.  
  301. updateButton()
  302. )
  303.  
  304. on SRF_roll close do
  305. (
  306. try (if holdTimer != undefined do holdTimer.Stop()) catch()
  307. SRF_closeFlyForm()
  308. )
  309. )
  310.  
  311. createDialog SRF_roll style:#(#style_toolwindow)
  312. cui.RegisterDialogBar SRF_roll minSize:[32,32] maxSize:[32,32] \
  313. style:#(#cui_dock_all, #cui_floatable, #cui_handles)
  314. cui.DockDialogBar SRF_roll #cui_dock_top
Advertisement
Add Comment
Please, Sign In to add comment