<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="Max Interface Tutorial 2: Picture UI Elements">

<setdocpatch name="02uPictureUIElements" patch="02uPictureUIElements.maxpat"/>
  <previous name="interfacechapter01">Bpatchers</previous>
<next name="pattrchapter01">Pattr Basics</next>
<parent name="00_maxindex">Max Tutorials</parent>

<indexinfo category="User Interface" title="Picture UI Elements">Designing user interfaces with custom image elements</indexinfo>

<h1>Interface Tutorial 2: Picture UI Elements</h1>

<h2>Introduction</h2>

<p>This tutorial covers the creation of custom controls using your own pictures.  This function is provided by the <o>pictctrl</o> and <o>pictslider</o> objects, which use specially formatted pictures to give you customizable user interfaces.</p>

<p>Changing the colors and sizes of user interface elements can only get you so far when creating custom interfaces. The <o>pictctrl</o> and <o>pictslider</o> objects take it to the next level: virtually any graphic can be used to create switches, sliders and state indicators. However, in order to get the best possible result, you will have to format the images to make them conform to the objects’ requirements.</p>

<p>To open the tutorial patch, click on the <b>Open Tutorial</b> button in the upper right-hand corner of the documentation window.</p>

<h2>Overview of the tutorial patcher</h2>

<p>If you take a look at the tutorial patcher, you will see four rather silly pictures.  In order to see the patch at work, click on the cellphone – it starts the <o>metro</o>, which animates all of the other graphics.  The cellphone is obviously acting like a momentary <i>switch</i>, the ring is a <i>slider</i> (following the output of a <o>drunk</o> object), the thumb is a yea/nay indicator (another type of <i>switch</i>), and the eyes are a multi-state indicator (jumping to the value of the <o>random</o> object's output). Click on the cellphone again, and the whole operation will cease.  Let’s look at each of these controls to see what is causing it to work.</p>

<p>The cellphone image, our momentary button, is made of two images – the plain cellphone and one with the backlight turned on. If you watch the <o>toggle</o> object connected to its output, you see that the output is <m>1</m> when you click the control, and <m>0</m> when you release the mouse. Using the <o>select</o> object at the output allows us to trigger the <o>toggle</o> controlling the <o>metro</o>.</p>

<p>While the <o>metro</o> is off, let’s look at some of the other controls.  They are all being driven by <o>random</o>-like objects, but they can be manually changed as well.  Click and drag on the ring, and you will see that it acts like a horizontal slider – the output connected to the <o>number</o> box provides a current value output when manually changed.  In this case, there are <m>128</m> steps tracked by the object.</p>

<p>The thumb image can also be controlled manually: When you click on it, it becomes neutral.  When you release the mouse button, it reverses state.  The eyes are similar, but change when you drag and click on the image.  There are only a few frames, so it might be convenient to use the <o>number</o> box above it to change the value in a more controllable way.</p>

<h2>Swapping images and settings</h2>

<p>Let’s play with some of the setting of the cellphone switch. Unlock the patch, select the cellphone and open the object inspector.  You will see a large number of attributes available for this object; let’s start by playing with the object sizing. As provided in the patch, there is no way to change the object size: you can mouse around the bottom-right of the object, but the grow box will never be displayed.</p>

<p>In the inspector, you will see that an attribute named <m>Snap Size to Picture Size</m> is turned on.  This attribute defeats user-based sizing; rather, it forces the object to be the size of the source image.  If you turn off this attribute, the object can be resized, and the image will scale to match the sizing of the image.</p>

<p>Sometimes you will want to try certain images for buttons, but you may have to try several images for it to be right.  You can change the image file by looking in the <i>image</i> section and clicking on the <b>Choose…</b> button for the <m>Image File</m> attribute. As an example, click on <b>Choose</b>, navigate to the Max folder on your disk, then go to the <i>patches/picts</i> folder and select the <m>boring button.pct</m> image.  This is more of a stock button image, and it replaces the cellphone button completely.</p>

<p>Click on the ring finger slider object, and look at the changes in the inspector.  This is a different object (the <o>pictslider</o> object), and it has a different set of attributes; most notably, two different images are used for the display.  The background image (in this case, the finger) can be used to set the size of the object, while the ring image can be scaled or replaced separately.  Click on the <b>Choose</b> button for the <m>Knob Image File</m> of the <o>pictslider</o>, move to the <i>patches/picts</i> folder, and select the "smiley2.pct" file.  It will immediately show both smiley faces; one of these is the <i>clicked</i> image, so you need to click on the <m>Has Clicked Image</m> attribute to make it look right.  Now, instead of moving a ring around the finger, you are sliding a face.  You may want to try changing the <m>Bottom Margin</m> attribute to center the face correctly for this image.</p>

<h2>Resizing and reformatting</h2>

<p>There are a variety of object attributes that require specific image formatting.  For example, attributes such as <m>Has Image Mask</m> and <m>Has Clicked Image</m> require that the source file be specially formatted to support those options.  If you have an image editor available, you might want to open the <i>thumbtoggle.pct</i> and <i>eyedial.pct</i> files to see how the complexity of a file increases when certain options are selected.  The “eyes” <o>pictctrl</o>, which supports <i>dial</i> mode, also provides an example of attributes that are only able in dial mode.</p>

<p>To get more information about the image formats for the <o>pictctrl</o> and <o>pictslider</o> object, open the help file for each and select the <m>picture_format</m> tab to see how an image has to be created for it to be a valid controller.  If most of the special features are not used, the image can often be fairly simple, but more robust controls require more complex images – especially if a mask is used to provide transparency.</p>

<h2>Summary</h2>

<p>Covering all of the custom UI options made available by <o>pictctrl</o> and <o>pictslider</o> is beyond the scope of this tutorial.  However, you should be able to see how the user interface of a patch can be completely altered by using custom image-based elements.  While proper creation of the images can be difficult, the effort allows for complete control of the visual control environment.</p>

<seealsolist>
<seealso name="pictctrl">Picture-based control</seealso>
<seealso name="pictslider">Picture-based slider control</seealso>
<seealso name="decide">Choose randomly between on and off (1 and 0)</seealso>
</seealsolist>

</chapter>
