Notifications
Clear all

[Closed] Viewport Label

Can I make a viewport gw.text-like thing which is clickable?

11 Replies
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

This fn by Raphael ‘Insanto’ Steves is used for ScriptSpotterscript. Maybe can help you somehow.

fn drawtext text:"mouseOverText" pos:[100,100] mPos:mouse.pos = --function to draw the screenText and check if mouse is hovering, does not update the screen after drawing
(
   local mouseOverText = off
   local te = gw.getTextExtent text
   local b1 = Box2 pos.x pos.y te.x te.y
   local b2 = Box2 pos.x (pos.y-te.y) te.x te.y
   gw.setTransform(Matrix3 1)
   if contains b2 mouse.pos do (mouseOverText = on)
   gw.wText [pos.x, pos.y, 0] text color:(if not mouseOverText then color 150 180 210 else color 177 88 22)
   gw.enlargeUpdateRect b1 --b1 --#whole
   return mouseOverText
)--END drawtext FN
drawtext text:"mouseOverText"
registerRedrawViewsCallback drawtext
--unRegisterRedrawViewsCallback drawtext 

Hmm that gets me a nice label, and if you pan the viewport with your mouse over the label it picks up, but I’m not sure it’ll give me a click event… Needs some kind of hit test but whether that would hamper max overall too much…

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

This can capture mouse click-move

unRegisterRedrawViewsCallback drawtext
 fn drawtext text:"mouseOverText" pos:[100,100] mPos:mouse.pos =
 (
    local mouseOverText = off
    local te = gw.getTextExtent text
    local b1 = Box2 pos.x pos.y te.x te.y
    local b2 = Box2 pos.x (pos.y-te.y) te.x te.y
    gw.setTransform(Matrix3 1)
    if contains b2 mouse.pos do (mouseOverText = on)
    gw.wText [pos.x, pos.y, 0] text color:(if not mouseOverText then color 150 180 210 else color 177 88 22)
    gw.enlargeUpdateRect b1
    return (if mouseOverText and mouse.mode == 2 do (messagebox "Mouse Moved" beep:off ; mouseOverText = off))
 )--END drawtext FN
 drawtext text:"mouseOverText"
 registerRedrawViewsCallback drawtext

I not know why mouse.mode == 1 not work here.

Also you can try when mouse over viewport text to run simple tool (lButton event). Maybe this is not good method

This is what I’ve been doing with this… I’ve made a script which adds a label to the viewport to indicate whether the camera is locked or not, which hopefully will help in that old annoying situation where a camera gets nudged accidentally. I’d like to have it so the label is clickable so that I could have a toggle to lock/unlock, but I guess this will just have to go in a quad menu unless anyone else can think of a good hack?

unregisterRedrawViewsCallback drawtextCamLock
fn drawtextCamLock = 
	(
		if viewport.gettype() == #view_camera do
		(
			--is Camera Locked
			local dtext = "[Camera Unlocked ]"
			local textColour 
			if (for i = 1 to 9 where (getTransformLockFlags (viewport.getcamera()))[i] == true collect i).count == 9 then 
			(
				dtext = "[Camera Locked ]" 
				textColour = (color 196 196 196)
				if (viewport.getcamera()).target != undefined do
				(
					if (for i = 1 to 9 where (getTransformLockFlags (viewport.getcamera()).target)[i] == true collect i).count != 9 do
					(
						dtext = "[Camera Locked, Target Unlocked ]" 
						textColour = (color 255 0 0)
					)	
				)
				
			)	
			else 
			(
				dtext = "[Camera Unlocked ]"
				textColour = (color 255 0 0)
			)
			if checkParent (viewport.getcamera()) == "xref" do
			(
				dtext = "[XRef Scene Camera ]"
				textColour = (color 196 196 196)
			)
			local camtext = ("[" + (viewport.getcamera()).name + "]")
			
			local viewportstyle
			if NitrousGraphicsManager.GetActiveViewportSetting() != undefined then
				viewportstyle = ((NitrousGraphicsManager.GetActiveViewportSetting()).VisualStyleMode)
			else
			(
				viewportstyle = case viewport.GetRenderLevel() of
				(
					#smoothhighlights : "[ Smooth + Highlights"
					#wireFrame : "[ Wireframe"
					#smooth : "[ Smooth"
					#facethighlights : "[ Facets//Hi"
					#facet : "[ Facets"
					#flat : "[ Flat"
					#litwireframe : "[ Lit Wires"
					#Box : "[ Box"
					#hiddenline : "[ Hidden Line"
				)
			)
				
			local edgesOn = if (viewport.GetShowEdgeFaces()) then 75 else 0
			local isDisabled = if viewport.isenabled() then 0 else 80
			local pos = [(gw.getTextExtent camtext)[1] + (gw.getTextExtent viewportstyle)[1] + edgesOn + isDisabled + 50,18]
			gw.setTransform(Matrix3 1)
			gw.wText [pos.x, pos.y, 0] dtext color:textColour
			
		)
	)--END drawtext FN
	drawtextCamLock()
	registerRedrawViewsCallback drawtextCamLock
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

do you want to make it nice or just functional right?
why do you try to put ‘lock’ info into a viewport?
you can do it with macro button placed in any toolbar.

I don’t know if this can help you, but you can try it.

BTW… all getTransformLockFlags set doesn’t mean that the node’s transform locked. you still can change it by script, or moving its parent for example… and if you can’t change a camera scale but can change its focus where is a difference?

hopefully i didn’t forget anything:


macroScript CAM_Locked
	tooltip:"Toggle Active Camera Lock" 
	category:"CAM"
	buttontext:"CAM Locked"
	autoUndoEnabled:off
(
	fn isLocked cam: = 
	(
		if cam == unsupplied do cam = getActiveCamera()
		iskindof cam camera and (LockedTracksMan.GetLocked cam cam 0 off) and
		(
			cam.target == undefined or LockedTracksMan.GetLocked cam.target cam 0 off
		)
	)
	fn toggleLock cam: = 
	(
		if cam == unsupplied do cam = getActiveCamera()
		if iskindof cam camera do
		(
			act = isLocked cam:cam
			LockedTracksMan.SetLocks (not act) cam cam 0 off
			if cam.target != undefined do LockedTracksMan.SetLocks (not act) cam.target cam 0 off
		)
	)
	on isEnabled do (viewport.gettype() == #view_camera)
	on isChecked do isLocked()
	on execute do undo "Toggle Camera Lock" on toggleLock()
)

Denis is right, of course. However setting the TM locks and adding a script controller to the fov was sufficient for my case here. My primitive implementation changed the wirecolor of locked cameras to indicate when it had happened. We have a script to manage cameras here now which does pretty much the same thing, but grabs the hierarchy/rig for the camera and locks this too.

edit: Very nice approach, Denis.

It’s easily possible to nudge a camera if you middle-click in an inactive camera viewport, happens all the time. I’ve tried a few approaches in the past to automatically lock cameras on file open, or give tools to lock cameras but I’ve found the guys tend to get frustrated as they go to move a camera and can’t, or simply can’t be bothered to lock the camera, or don’t think about it.

This approach is about giving the user information, and warning in a non-intrusive way. I don’t want to use complex locks in case someone needs to unlock a camera and doesn’t have access to the script, so just locking the transform flags will be fine for now.

We have a custom toolbar which is on all our machines which has quick links to our tools and scripts, so I have a button for locking/unlocking the camera, but it would be a lot nicer if it was possible to do this in one click in the viewport.