【 WindowAddHotspot 】
格式:
WindowAddHotspot(BSTR Name,
BSTR HotspotId,
long Left, long Top, long Right, long Bottom,
BSTR MouseOver,
BSTR CancelMouseOver,
BSTR MouseDown,
BSTR CancelMouseDown,
BSTR MouseUp,
BSTR TooltipText,
long Cursor,
long Flags
)
中文:
WindowAddHotspot(所在小視窗名,
Hotspot ID,
左端, 上端, 右端, 下端,
"滑鼠懸停",
"滑鼠離開按鈕",
"滑鼠按下去",
"離開按鈕後鬆開鼠鍵",
"在按鈕內鬆開鼠鍵",
"氣泡提示",
按鈕上鼠標圖示,
行為
)
說明:
建立按鈕的必要函數之一,當使用者點擊區域內,即回應所設定好的動作。
因此這時函數才是按鈕的核心。
這個函數無法在角色檔內調用,必須以Plugin的方式使用(miniwindow系列
皆是如此)。
參數的用途說明如下:
1.所在小視窗名:必須要有,也就是MiniWindow的名稱。
2.Hotspot ID:這個熱點的名字,必要。
3.左端,上端,右端,下端:這個熱點的範圍及位置,有點像用滑鼠從左上往右下
圈選出一個區域,必要。
4.滑鼠懸停:當滑鼠移動到熱點的範圍內,要做什麼,必須建立一個函數,將函
數名填入這裡,如果不使用這個動作,用""留白後繼續下去。在習慣上,這個
動作會讓按鍵變色。函數格式如下:
function function-name (flags, hotspot_id)
指令內容
end -- function
flags 不是指long Flags,而是組合鍵和滑鼠鍵的參數,見6.。
holspot_id 就是熱點的ID名。
5.滑鼠離開按鈕:對應於前項,當滑鼠離開熱點的範圍,要做什麼,設定方式同
上。在認知上,已變色的按鍵會回復原色。
6.滑鼠按下去:無視左右鍵分別,不過有設定的方式,設定方式同4。在認知上,
按下去按鈕會有被推進去的動畫。
值 │說明 │Lua標記
│0x01 (1) │按著Shift鍵 │miniwin.hotspot_got_shift │
│0x02 (2) │按著Ctrl鍵 │miniwin.hotspot_got_control │
│0x04 (4) │按著Alt鍵 │miniwin.hotspot_got_alt │
│0x10 (16) │滑鼠左鍵 │miniwin.hotspot_got_lh_mouse │
│0x20 (32) │滑鼠右鍵 │miniwin.hotspot_got_rh_mouse │
│0x40 (64) │雙擊 │miniwin.hotspot_got_dbl_click │
│0x80 (128) │非首次在熱點懸停鼠標 │miniwin.hotspot_got_not_first │
│0x100 (256) │向下滑動滾輪 (朝向你) │miniwin.wheel_scroll_back │
└──────┴───────────┴───────────────┘
利用上表,可以針對不同組合的點擊,分派不同的工作。組合鍵的做法是將 x
後方的值加總,如Shift+Ctrl+Alt+滑鼠左鍵,就是:
0x(1+2+4+16) = 0x23
接著使用bit.band函數來做判斷,區分左右鍵的內容,如:
if bit.band (flags, 0x10) ~= 0 then
ActWorld:Activate()
elseif bit.band (flags, 0x20) ~= 0 then
ActWorld:Execute('setwins')
end --if bit
7.離開按鈕後鬆開鼠鍵:當你誤按的時候,可能會壓著不放,讓游標離開熱點再
放手,已取消誤按。設定方式同4。
8.在按鈕內鬆開鼠鍵:據作者說明這個動作最適合執行你設定的功能,同時你會
看到按鈕自行復位的動畫,設定方式同4。
4. 5. 6. 7. 8. 代表使用按鈕的一連串動作,如下圖
┌─────┐ ┌─────┐ ┌─────┐
│4.滑鼠移到│→│6.滑鼠按下│→│8.鬆開鼠鍵│
│ 按鈕上方│ │ 按鈕 │ │ │
└─────┘ └─────┘ └─────┘
↓ ↓
┌─────┐ ┌─────┐
│5.離開按鈕│ │7.誤按取消│
│ │ │ │
└─────┘ └─────┘
因此當一個按鈕設定很完整的時候,8.最適合執行功能;但是,這些作者並沒
有提供相關函數或完整範例,在不完整設定的情況下,只要功能執行的內容,
設在6.即可,如此一來,最基本的按鈕就能用了。
9.氣泡提示內容:當滑鼠停留在熱點上方,會顯示提示框,最多可輸入999字元
長度,可省略。
10.按鈕上鼠標圖示:當滑鼠停留在熱點上方,鼠標圖示會改變成設定的圖示。
值│圖示 │Lua 標記
│-1│No cursor │miniwin.cursor_none │
│0 │Arrow(指標) │miniwin.cursor_arrow │
│1 │Hand(小手) │miniwin.cursor_hand │
│2 │I-beam(輸入文字游標) │miniwin.cursor_ibeam │
│3 │+ symbol(十字準星) │miniwin.cursor_plus │
│4 │Wait(沙漏) │miniwin.cursor_wait │
│5 │Up arrow(↑) │miniwin.cursor_up │
│6 │Arrow nw-se(雙箭號"\") │miniwin.cursor_nw_se_arrow│
│7 │Arrow ne-sw(雙箭號"╱") │miniwin.cursor_ne_sw_arrow│
│8 │Arrow e-w(雙箭號"—") │miniwin.cursor_ew_arrow │
│9 │Arrow n-s(雙箭號"|") │miniwin.cursor_ns_arrow │
│10│Arrow - all ways(十字四向箭號) │miniwin.cursor_both_arrow │
│11│(X) cannot do action(禁用"圓內斜線")│miniwin.cursor_x │
│12│Help (指標加問號) │miniwin.cursor_help │
└─┴───────────────────┴─────────────┘
11.行為:用途不明。
值│說明 │Lua標記
│1 │如果有設定,所有的滑鼠│miniwin.hotspot_report_all_mouseovers │
│ │懸停行為都會送到滑鼠懸│ │
│ │停函數處理 │ │
└─┴───────────┴─────────────────────┘
範例:以下為程式作者提供的範例,似乎與畫地圖有關。個人看不懂...別問我!
--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--
function hyperlink_configure_background ()
local new_colour = PickColour (background_colour) -- colour picker
if new_colour ~= -1 then -- if dialog not dismissed
background_colour = new_colour
Display_Map ()
end -- new colour
end -- hyperlink_configure_background
function hyperlink_configure_title ()
local new_colour = PickColour (title_colour) -- colour picker
if new_colour ~= -1 then -- if dialog not dismissed
title_colour = new_colour
Display_Map ()
end -- new colour
end -- hyperlink_configure_title
-- here if they click on the hyperlink
function mousedown (flags, hotspotid)
local f = hyperlink_functions [hotspotid]
if f then
f ()
end -- function found
end -- mousedown
hyperlink_functions = {}
function make_hyperlink (text, id, left, top, action, hint)
-- work out text rectangle size
local height = WindowFontInfo (win, font_id, 1)
local right = left + WindowTextWidth (win, font_id, text)
local bottom = top + height
-- add the hotspot
WindowAddHotspot(win, id,
left, top, right, bottom,
"", -- mouseover (do nothing)
"", -- cancelmouseover (do nothing)
"mousedown",
"", -- cancelmousedown (do nothing)
"", -- mouseup (do nothing)
hint, -- hint text if they hover over it
miniwin.cursor_hand, 0)
-- draw the hyperlink text in the rectangle
WindowText (win, font_id, text, left, top, right, bottom, hyperlink_colour)
-- remember action function
hyperlink_functions [id] = action
end -- make_hyperlink
-- further down, where we draw the map ....
-- hyperlink for title colour
make_hyperlink ("?", "back_colour", width - 15, height - 5 - font_height,
hyperlink_configure_background, "Choose background colour")
-- hyperlink for map body colour
make_hyperlink ("?", "title_colour", width - 15, font_height + 5,
hyperlink_configure_title, "Choose title colour")
--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--==-==--
來源:http://www.gammon.com.au/mushclient/mw_hotspots.htm