Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global SRF_roll
- global SRF_defs
- global SRF_currentIndex
- global SRF_dnBtnRef
- global SRF_flyForm
- global SRF_flyButtons
- global SRF_hoverIndex
- global SRF_dnBG
- global SRF_dnTXT
- global SRF_dnBorder
- global SRF_dnBlue
- global SRF_dnBlueText
- SRF_defs = #("A","B","C","D","E")
- if SRF_currentIndex == undefined do SRF_currentIndex = 1
- SRF_hoverIndex = 0
- fn SRF_clamp255 v = (amax 0 (amin 255 (v as integer)))
- fn SRF_toDNColorFromMaxColor c =
- (
- (dotNetClass "System.Drawing.Color").FromArgb (SRF_clamp255 c.r) (SRF_clamp255 c.g) (SRF_clamp255 c.b)
- )
- fn SRF_maxColorFromColorMan key fallbackColor =
- (
- local p = undefined
- try (p = colorMan.getColor key) catch()
- if p == undefined then fallbackColor else (color (p.x*255) (p.y*255) (p.z*255))
- )
- fn SRF_maxColorFromAnyColorMan keys fallbackColor =
- (
- for k in keys do
- (
- local p = undefined
- try (p = colorMan.getColor k) catch()
- if p != undefined do return (color (p.x*255) (p.y*255) (p.z*255))
- )
- fallbackColor
- )
- fn SRF_closeFlyForm =
- (
- if SRF_flyForm != undefined do
- (
- try (SRF_flyForm.Capture = false) catch()
- try (SRF_flyForm.Close()) catch()
- try (SRF_flyForm.Dispose()) catch()
- SRF_flyForm = undefined
- )
- SRF_flyButtons = undefined
- SRF_hoverIndex = 0
- )
- fn SRF_applyFlyColors =
- (
- if SRF_flyButtons == undefined then return false
- for i = 1 to SRF_flyButtons.count do
- (
- local b = SRF_flyButtons[i]
- if (i == SRF_hoverIndex) or (i == SRF_currentIndex and SRF_hoverIndex == 0) then
- (
- try (b.BackColor = SRF_dnBlue) catch()
- try (b.ForeColor = SRF_dnBlueText) catch()
- )
- else if i == SRF_currentIndex then
- (
- -- selected stays blue (если нет hover)
- try (b.BackColor = SRF_dnBlue) catch()
- try (b.ForeColor = SRF_dnBlueText) catch()
- )
- else
- (
- try (b.BackColor = SRF_dnBG) catch()
- try (b.ForeColor = SRF_dnTXT) catch()
- )
- )
- true
- )
- fn SRF_updateHoverFromCursor form tileW tileH count =
- (
- local mp = (dotNetClass "System.Windows.Forms.Control").MousePosition
- local p = form.PointToClient mp
- local idx = 0
- if (p.X >= 0 and p.X < tileW and p.Y >= 0 and p.Y < (tileH*count)) do
- (
- idx = (floor ((p.Y as float) / tileH)) + 1
- if idx < 1 or idx > count do idx = 0
- )
- if idx != SRF_hoverIndex do
- (
- SRF_hoverIndex = idx
- SRF_applyFlyColors()
- )
- )
- -- ---- flyout form handlers ----
- fn SRF_onFlyFormDeactivate s e = ( SRF_closeFlyForm() )
- fn SRF_onFlyFormKeyDown s e =
- (
- if e.KeyCode == (dotNetClass "System.Windows.Forms.Keys").Escape do SRF_closeFlyForm()
- )
- fn SRF_onFlyFormPaint s e =
- (
- local pen = dotNetObject "System.Drawing.Pen" SRF_dnBorder
- e.Graphics.DrawRectangle pen 0 0 (s.ClientSize.Width-1) (s.ClientSize.Height-1)
- pen.Dispose()
- )
- fn SRF_onFlyFormMouseMove s e =
- (
- SRF_updateHoverFromCursor s 32 32 SRF_defs.count
- )
- fn SRF_onFlyFormMouseUp s e =
- (
- if e.Button == (dotNetClass "System.Windows.Forms.MouseButtons").Left do
- (
- -- на всякий случай обновим hover в момент отпускания
- SRF_updateHoverFromCursor s 32 32 SRF_defs.count
- if SRF_hoverIndex != 0 then
- (
- SRF_currentIndex = SRF_hoverIndex
- if SRF_dnBtnRef != undefined do (try (SRF_dnBtnRef.text = SRF_defs[SRF_currentIndex]) catch())
- format "Selected: %\n" SRF_defs[SRF_currentIndex]
- )
- SRF_closeFlyForm()
- )
- )
- fn SRF_showFlyoutBelowButton dnBtn =
- (
- SRF_closeFlyForm()
- local cnt = SRF_defs.count
- local tile = 32
- local w = tile
- local h = tile * cnt
- local f = dotNetObject "System.Windows.Forms.Form"
- SRF_flyForm = f
- -- disable autoscale (DPI)
- try (f.AutoScaleMode = (dotNetClass "System.Windows.Forms.AutoScaleMode").None) catch()
- try (f.AutoSize = false) catch()
- try (f.Margin = dotNetObject "System.Windows.Forms.Padding" 0) catch()
- try (f.Padding = dotNetObject "System.Windows.Forms.Padding" 0) catch()
- f.FormBorderStyle = (dotNetClass "System.Windows.Forms.FormBorderStyle").None
- f.StartPosition = (dotNetClass "System.Windows.Forms.FormStartPosition").Manual
- f.ShowInTaskbar = false
- f.TopMost = true
- f.KeyPreview = true
- f.BackColor = SRF_dnBG
- f.ForeColor = SRF_dnTXT
- local sz = dotNetObject "System.Drawing.Size" w h
- f.ClientSize = sz
- try (f.MinimumSize = sz) catch()
- try (f.MaximumSize = sz) catch()
- try (f.Size = sz) catch()
- -- place under main button
- local pt = dnBtn.PointToScreen (dotNetObject "System.Drawing.Point" 0 dnBtn.height)
- f.Location = pt
- -- events
- dotNet.addEventHandler f "Deactivate" SRF_onFlyFormDeactivate
- dotNet.addEventHandler f "KeyDown" SRF_onFlyFormKeyDown
- dotNet.addEventHandler f "Paint" SRF_onFlyFormPaint
- dotNet.addEventHandler f "MouseMove" SRF_onFlyFormMouseMove
- dotNet.addEventHandler f "MouseUp" SRF_onFlyFormMouseUp
- -- build buttons (только для отрисовки текста/фона)
- SRF_flyButtons = #()
- for i = 1 to cnt do
- (
- local b = dotNetObject "System.Windows.Forms.Button"
- b.Text = SRF_defs[i]
- b.Tag = i
- try (b.AutoSize = false) catch()
- b.FlatStyle = (dotNetClass "System.Windows.Forms.FlatStyle").Flat
- b.UseVisualStyleBackColor = false
- b.Size = dotNetObject "System.Drawing.Size" tile tile
- b.Location = dotNetObject "System.Drawing.Point" 0 ((i-1)*tile)
- b.Margin = dotNetObject "System.Windows.Forms.Padding" 0
- b.Padding = dotNetObject "System.Windows.Forms.Padding" 0
- b.TabStop = false
- b.TextAlign = (dotNetClass "System.Drawing.ContentAlignment").MiddleCenter
- try (b.Font = dnBtn.Font) catch()
- try (b.FlatAppearance.BorderSize = 0) catch()
- f.Controls.Add b
- append SRF_flyButtons b
- )
- -- show + IMPORTANT: move mouse capture from main button to flyout form
- try (dnBtn.Capture = false) catch()
- f.Show()
- try (f.Activate()) catch()
- try (f.Capture = true) catch()
- -- force size again (иногда WinForms пересчитывает после Show)
- try (f.ClientSize = sz) catch()
- try (f.MinimumSize = sz) catch()
- try (f.MaximumSize = sz) catch()
- try (f.Size = sz) catch()
- -- initial colors (selected blue)
- SRF_hoverIndex = 0
- SRF_applyFlyColors()
- )
- -- ---------- cleanup previous instance ----------
- try (cui.UnRegisterDialogBar SRF_roll) catch()
- try (destroyDialog SRF_roll) catch()
- SRF_closeFlyForm()
- -- ------------------ UI ------------------------
- rollout SRF_roll "Fly" width:32 height:32
- (
- dotNetControl dnBtn "System.Windows.Forms.Button" pos:[0,0] width:32 height:32
- local holdTimer
- local holdFired = false
- fn updateButton =
- (
- if SRF_currentIndex < 1 or SRF_currentIndex > SRF_defs.count do SRF_currentIndex = 1
- dnBtn.text = SRF_defs[SRF_currentIndex]
- )
- fn runCurrent = ( format "Current: %\n" SRF_defs[SRF_currentIndex] )
- fn onHoldTick s e =
- (
- holdTimer.Stop()
- holdFired = true
- SRF_showFlyoutBelowButton dnBtn
- )
- on dnBtn MouseDown s e do
- (
- if e.Button == (dotNetClass "System.Windows.Forms.MouseButtons").Left do
- (
- holdFired = false
- holdTimer.Start()
- )
- )
- on dnBtn MouseUp s e do
- (
- if e.Button == (dotNetClass "System.Windows.Forms.MouseButtons").Left do
- (
- if holdTimer.Enabled do holdTimer.Stop()
- if not holdFired do runCurrent()
- )
- )
- on SRF_roll open do
- (
- SRF_dnBtnRef = dnBtn
- -- theme-ish colors (dark fallbacks)
- local mxBG = SRF_maxColorFromColorMan #background (color 68 68 68)
- local mxTXT = SRF_maxColorFromColorMan #text (color 220 220 220)
- local mxBorder = SRF_maxColorFromAnyColorMan #(#shadow, #hilight, #hilite) (color 40 40 40)
- local mxBlue = SRF_maxColorFromAnyColorMan #(#itemhighlight, #itemhilight, #highlight, #hilight) (color 0 120 215)
- SRF_dnBG = SRF_toDNColorFromMaxColor mxBG
- SRF_dnTXT = SRF_toDNColorFromMaxColor mxTXT
- SRF_dnBorder = SRF_toDNColorFromMaxColor mxBorder
- SRF_dnBlue = SRF_toDNColorFromMaxColor mxBlue
- SRF_dnBlueText = (dotNetClass "System.Drawing.Color").FromArgb 255 255 255
- dnBtn.FlatStyle = (dotNetClass "System.Windows.Forms.FlatStyle").Flat
- dnBtn.UseVisualStyleBackColor = false
- dnBtn.BackColor = SRF_dnBG
- dnBtn.ForeColor = SRF_dnTXT
- dnBtn.TextAlign = (dotNetClass "System.Drawing.ContentAlignment").MiddleCenter
- try (dnBtn.Font = dotNetObject "System.Drawing.Font" "Segoe UI" 10.0) catch()
- try (dnBtn.FlatAppearance.BorderSize = 1) catch()
- try (dnBtn.FlatAppearance.BorderColor = SRF_dnBorder) catch()
- holdTimer = dotNetObject "System.Windows.Forms.Timer"
- holdTimer.Interval = 350
- dotNet.addEventHandler holdTimer "Tick" onHoldTick
- updateButton()
- )
- on SRF_roll close do
- (
- try (if holdTimer != undefined do holdTimer.Stop()) catch()
- SRF_closeFlyForm()
- )
- )
- createDialog SRF_roll style:#(#style_toolwindow)
- cui.RegisterDialogBar SRF_roll minSize:[32,32] maxSize:[32,32] \
- style:#(#cui_dock_all, #cui_floatable, #cui_handles)
- cui.DockDialogBar SRF_roll #cui_dock_top
Advertisement
Add Comment
Please, Sign In to add comment