2

Can anyone show a way to make dynamic UI elements in maxscript? For example. I can insert a image button in the ui, but i'd like to control the scale of the image based on the value of a slider element.

R.P. da Costa
  • 109
  • 1
  • 15

2 Answers2

1

I did find a way to make a dynamic user interface, that was the first part of the problem.

But i did not get it to make image button sizes dynamic yet.(mainly because if i use group elements in the way i want to, then the position of every element is hard coded.

try(destroydialog dRolH) catch() 
rollout dRolH "Dialog" height:200 width:200 
(
dropdownlist rolList "Rollouts: " items:#("Rollout A", "Rollout B", "Rollout C") width:175 offset:[0,0]
checkbox lbA "A" pos:[14,50] visible:off
checkbox lbB "B" pos:[14,50] visible:off 
checkbox lbC "C" pos:[14,50] visible:off

local rolls = #(#(lbA), #(lbB), #(lbC))
on rolList selected sel do
(
for k=1 to rolls.count do for c in rolls[k] do c.visible = (k == sel) 
)
)
createDialog dRolH pos:[740, 200]
R.P. da Costa
  • 109
  • 1
  • 15
0

See, this is a bit more complicated. Changing the width and height values of the bitmap element is pretty easy:

bitmap bm "Bitmap:" filename:@"some/file/path.jpg" -- create the bitmap UI element
bm.width = 100
bm.height = 100

But this will only change the size of the bitmap framing. You will also need to rerender the bitmap in a new resolution and switch out the old one. I have implemented this in your code here:

try(destroydialog dRolH) catch()
rollout dRolH "Dialog" height:200 width:200 
(
    dropdownlist rolList "Rollouts: " items:#("Rollout A", "Rollout B", "Rollout C") width:175 offset:[0,0]
    checkbox lbA "A" pos:[14,50] visible:off
    checkbox lbB "B" pos:[14,50] visible:off 
    checkbox lbC "C" pos:[14,50] visible:off
    spinner s "Size (%)" range:[0,1000,100]
    local bm_height = 128
    local bm_width = 128 
    bitmap bm "Bitmap" height:bm_height width:bm_width fileName:@"C:\ProgramData\Microsoft\User Account Pictures\Default Pictures\usertile12.bmp"

    fn scaleAndReloadImage factor =
    (
        -- New sizes
        bm.height = bm_height * factor          
        bm.width = bm_width * factor
        -- Loadimage and
        local image = Bitmaptexture filename:@"C:\ProgramData\Microsoft\User Account Pictures\Default Pictures\usertile12.bmp"
        -- Rerender into new bitmap
        local new_bm = bitmap bm.width bm.height
        rendermap image into:new_bm size:([image.bitmap.width,image.bitmap.height]) filter:on display:off gamma:2.2
        -- Assign new bitmap
        bm.bitmap = new_bm
    )

    -- EVENTS
    local rolls = #(#(lbA), #(lbB), #(lbC))
    on rolList selected sel do
    (
        for k=1 to rolls.count do for c in rolls[k] do c.visible = (k == sel) 
    )

    on s changed val do
    (
        if val == 0 then s.value = val = 100    -- Resets to 100 on rightclick
        local factor = val / 100                    -- Scaling factor
        scaleAndReloadImage factor
    )

    on dRolH open do
    (
        scaleAndReloadImage 1           -- Render image from start, to secure uniform gamma
    )
)
createDialog dRolH pos:[740, 200] height:400

I have put in a few comments for you as well.

Happy hacking :D :)

/goehler

NB: The address I use for the bitmap will probably only work in Windows 7 - but I imagine you have the sense to use another address if need be :)

goehler
  • 180
  • 1
  • 11