Thread Tools Display Modes
05/10/22, 12:15 PM   #1
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Calling a function when zoom level has changed?

Hi guys,
Is it possible to call a function when the zoom level has changed?
I try to avoid using "OnUpdate" aiming at performance optimization.
  Reply With Quote
05/10/22, 12:23 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
I'd check what keybind is used for the zoom in and zoom out at the controls, chck that at the lua file where the settings menu for those controls are created (keybindings) and check what function is used there.
Maybe you can use ZO_PreHook or SecurePostHook on it to react on the zoom change then.

esoui/ingame/globals/bindings.xml
<Category name="SI_KEYBINDINGS_CATEGORY_CAMERA">
<Action name="CAMERA_ZOOM_OUT">
<Down>CameraZoomOut()</Down>
</Action>

<Action name="CAMERA_ZOOM_IN">
<Down>CameraZoomIn()</Down>
</Action>

Func names are CameraZoomIn and CameraZoomOut

Test if they are protected via IsProtectedFunction("CameraZoomIn") or not.
Looks like it isn't so a SecurePostHook should/could work.

Lua Code:
  1. SecurePostHook("CameraZoomIn", function()
  2.     d("Zooming in")
  3. end)
  4. SecurePostHook("CameraZoomOut", function()
  5.     d("Zooming out")
  6. end)

Yep, tested, works

Last edited by Baertram : 05/10/22 at 12:26 PM.
  Reply With Quote
05/10/22, 02:25 PM   #3
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Thanks Beatram,
I forgot to mention that was for the map zoom, I tried "WorldMapZoom" and many other things without success.

"ZO_WorldMapZoomMinus_OnClicked" and "ZO_WorldMapZoomPlus_OnClicked" work but only when you click the + and - button of the zoom.

"ZO_WorldMapZoom_OnMouseWheel" doesn't work

edit: ah : "ZO_WorldMap_MouseWheel" works!

Last edited by Masteroshi430 : 05/10/22 at 02:32 PM.
  Reply With Quote
05/10/22, 02:36 PM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
Try function ZO_MapPanAndZoom:SetCurrentNormalizedZoomInternal(normalizedZoom)
It seems to be called from internal local functions as you click the zoom slider and maybe also if you use the mousewheel as it is called from different zoom functions there (normalized, curved etc.)

The object is stored in the local g_mapPanAndZoom which is returned by function ZO_WorldMap_GetPanAndZoom()

Lua Code:
  1. local mapPanAndZoom = ZO_WorldMap_GetPanAndZoom()
  2. SecurePostHook(mapPanAndZoom , "SetCurrentNormalizedZoomInternal", function(selfMapPanAndZoom, normalizedZoom)
  3. d("normalizedZoom: " ..tostring(normalizedZoom))
  4. end)

If this is not the correct one that will fire as you use the mouse wheel check any other of the update/set functions there, e.g.
:OnMouseWheel(delta)
which will call AddZoomDelta
which calls SetLockedNormalizedZoom
which calls SetTargetNormalizedZoom

Last edited by Baertram : 05/10/22 at 02:40 PM.
  Reply With Quote
05/10/22, 03:13 PM   #5
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Thanks again, it works wonderfully
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Calling a function when zoom level has changed?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off