[Closed] On ImgTag mouseOver issue
Hi guys,
I’m working on a custom user interface made mostly of popup dialogs. I wish to spice it up a bit being able to expand such dialogs on mouse over certain areas. The popup shows most used commands as is opened, then on mouse over a defined area it expands to show advanced commands. So far so good. I thought of using ImgTag because it has plenty solutions for event detection, but I’m running into an issue.
The macroScript is made to toggle the popup, so if the popup is closed it opens it, otherwise it destroys it. On first creation the “on mouseOver” event handler works perfectly, but if I close the popup by running again the macroScript and then open it again, the event handler doesn’t work anymore. I have to make at least one click on the ImgTag to bring it back to life.
I’d like to know if this is an issue with my 3ds Max or not, and if you know of any workaround. I know I could simply use the “on click” event, but it would be awesome to avoid that.
Here is a sample script. Run it, associate a shortcut, then try to open and close the rollout a couple of time without clicking and the ImgTag on “mouseOver” event should be jammed.
Thank you very much.
macroScript MaxUI_Test
category:"Max UI Test"
buttonText:"Max UI Test"
tooltip:"Max UI Test Toggle"
(
global rol_MaxUI_Test
rollout rol_MaxUI_Test "MaxUI Test"
(
imgTag itExtend width:80 height:20 bitmap:(bitmap 1 1 color:(color 255 0 0)) align:#center offset:[0, 10]
on itExtend mouseOver do
(
rol_MaxUI_Test.height += 50
)
)
local p2DialogSize = [100, 50]
on execute do
(
if (not rol_MaxUI_Test.open) then
(
local p2MousePos = mouse.screenPos
createDialog rol_MaxUI_Test p2DialogSize.x p2DialogSize.y (p2MousePos.x - p2DialogSize.x / 2) (p2MousePos.y - p2DialogSize.y / 2)
)
else
(
try ( destroyDialog rol_MaxUI_Test ) catch ()
)
)
)
- Enrico
works fine for me in max 2010 XP64
if you’re not against using .NET controls, every .NET control has a MouseEnter event handler which is triggered when the mouse enters the control’s rectangle as you may have guessed from the name.
here’s an example based on your code that uses a .NET label control instead of the imgtag:
(
try(destroyDialog rol_MaxUI_Test_2)catch()
global rol_MaxUI_Test_2
rollout rol_MaxUI_Test_2 "MaxUI Test"
(
dotnetcontrol itExtend "System.Windows.Forms.Label" width:80 height:20 align:#center offset:[0, 10]
on itExtend MouseEnter arg do
(
rol_MaxUI_Test_2.height += 50
)
on rol_MaxUI_Test_2 open do
(
itExtend.BackColor = itExtend.BackColor.Red -- set the background colour of the label to red
)
)
local p2MousePos = mouse.screenPos
local p2DialogSize = [100, 50]
createDialog rol_MaxUI_Test_2 p2DialogSize.x p2DialogSize.y (p2MousePos.x - p2DialogSize.x / 2) (p2MousePos.y - p2DialogSize.y / 2)
)
Hi Joel, that worked great. Thank you!
I’m not against using dotNet at all, it’s only I don’t know it yet. I don’t know how to pick it up, because it is so huge and I cannot seem to find a “Start here” entry point.
Now I have to figure out what’s the control to display a bitmap, unless the label can do that too, find the “on mouse out” event handler, and I’m ready to go. Going to dive into MSDN
Thanks
- Enrico
most of the stuff you’ll need for dotnet controls can be found in the following namespaces:
System.Windows.Forms
System.Drawing
System.Drawing.Imaging
Also note that as far as I’m aware, the current version of .NET being used in max is 3.5 so try to browse the 3.5 reference, not the 4.0 reference on MSDN since new classes and/or methods (functions) will not work.
to answer your (sort of) question, the PictureBox control is probably the easiest way to display bitmaps although any control with an .Image property should do the trick. one likely problem that you will run into with dotnet and bitmaps is that only a few image types are supported for loading/saving, which are: jpg, bmp, tif, png and gif. You need to do a bit of extra work to open other formats that you may be used to using which are supported in max. There’s been a few threads about it already but the short version is: open the bitmap in max, copy it to the clipboard, then copy it from the clipboard using dotnet into a dotnet image.
Thanks Joel,
I was figuring that out. As I want to keep things super simple, I used the BackgroundImage property of your Label object to set a .bmp loaded through “System.Drawing.Bitmap”. The “on mouse out” event is “MouseLeave”. Everything works fine. I’m only wondering now if there is a way to work with image “strips” like standard 3ds Max UI does, packing more icons into a single file and indexing them, or if every image must be a single file.
I have a workaround in mind, but it doesn’t seem so efficient:
- Create the icon strip file
- Load the icon strip file in a 3ds Max bitmap
- Read the single icon wanted into another 3ds Max bitmap
- Use the clipboard to pass it to dotNet.
It seems overcomplicated. Is there anything better right in dotNet? Thanks.
EDIT:
I think I found something interesting, but I’m stuck:
I can:
- Load the icon strip from hdd in a dotNet bitmap
- Clone a single icon from strip into another dotNet bitmap
- Display the clone
I load the icon strip with:
local bmpIcons = dotNetObject "System.Drawing.Bitmap" "c:\MyIcons.bmp"
Then I try to make a clone with:
local bmpSingleIcon = bmpIcons.clone (dotNetObject "System.Drawing.Rectangle" 10 10 10 10) <PixelFormat>
I figured out what’s a Rectangle object, but don’t know how to define the PixelFormat enumeration. Any insight? Thanks!
- Enrico
you can reference the PixelFormat enum using:
PixelFormat = dotnetclass "System.Drawing.Imaging.PixelFormat"
and pick the enum value you want using for example:
PixelFormat.Format24bppRgb
the list of all PixelFormat values and their meaning can be found here: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat%28v=VS.90%29.aspx
EDIT: typo in the first [ CODE ] block
Great! Just Great!
Thank you very much for all the help and support, works perfectly! Now that almost all technical issues seem to be solved, I have quite a lot of code to write
And this could be my first step into dotNet too.
- Enrico