|
Mastering
3D Studio MAX R3 |
Bitmaps in
the UI
You can add bitmaps to the UI to enhance the UI and make it easier to
understand. You can use a bitmap in a button, checkbutton, materialbutton,
or mapbutton. This is done using the .images property.
Buttons allow up to four different images: two that will be displayed
when the button is not pressed (enabled or disabled), and two that will
be displayed when the button is pressed (also enabled or disabled). The
images must all be the same size, part of the same bitmap file, and placed
side by side like the schematic in Figure 16.11.
FIGURE
16.11 Schematic of a bitmap file for a button
MAX accesses bitmap files by dividing the overall image into four even
pieces; each button state is represented by one piece of the file. Thus,
when a button is enabled and pressed, MAX displays the second quarter
of its bitmap file. Lets create a small script that illustrates
this. It uses the sample bitmap shown in Figure 16.12 and shows the button
image when its enabled or disabled, and when its pressed or
not. This bitmap file (button_test.jpg) is supplied on
the CD. You may need to copy it to any map path, or to the scripts path,
to allow the script to work.
FIGURE
16.12 The Render Channel floater with bitmappreview
rollout imagebutton_rollout Test
(
button test width:200 height:80 \
images:#(button_test.jpg,undefined,4,1,2,3,4)
checkbox en Enabled checked:true
on en changed state do test.enabled = en.checked
)
try (closerolloutfloater ib_floater) catch()
ib_floater = newrolloutfloater Image Button 240 180
addrollout imagebutton_rollout ib_floater
(Actually, you can never see the Image Button Pressed Disabled with this
example. Its only visible with a checkbutton, or if you disable
and press it through the code. But this demonstration should suffice.)
Bitmaps can also be specified directly in rollouts. Instead of using a
button with images, you can use a bitmap directly. Simply use the BITMAP
command and specify this bitmap the same way as spinners or buttons.
A bitmap has two properties: .filename and .bitmap.
The first allows us to specify a filename directly, and the second allows
us to use a bitmap variable that has been declared.
Bitmaps are useful because they allow us to show things like render previews,
materials, maps, and colors in the UI. Lets edit the Render Channel
script and display a window with a preview of the channel youve
selected, as shown in Figure 16.12.
You can load the script from the CDits named render_channel2.msor
you can follow the instructions below and edit the original one yourself.
Between dropdownlist and button, add:
bitmap preview width:150 height:90
In the enable_list function, after channel.enabled,
add:
bmp_small = bitmap 150 90
copy bmp bmp_small
preview.bitmap = bmp_small
gc()
In on channel i selected, after save_it.enabled
= true, add:
if img2 != undefined then (close img2)
if bmp_channel == #RGBA_Channel then img2 = copy img
else img2 = getchannelasmask img bmp_channel
bmp_small = bitmap 150 90
copy img2 bmp_small
preview.bitmap = bmp_small
gc()
Change on save_it pressed to:
on save_it pressed do
(
img2.filename = selectsavebitmap()
save img2
display img2
gc()
)
Also, lets edit the height of the floater, so the new UI fits within
it:
channel_floater = newrolloutfloater Render Channel 200 292
Youre done now. Evaluate this script and notice the previews showing
in the UI.
Notice youve used the command GC(), mentioned earlier. Its
a command (garbage collection) that frees the memory by cleaning
up unused items.
Summary
You can now write complex and useful scripts, which will help you tremendously
on a daily basis.
In the next chapter, you will learn some more advanced tools that will
make scripting easier and will allow you to manipulate files, Xrefs, viewports,
and much more.
© 2000, Frol (selection,
edition, publication)
|