PDA

View Full Version : Add colorSliderGrp to formLayout ?


SUNCHIRP
10-13-2010, 03:13 PM
Hi,

I'm utilising formLayout for a UI I'm developing, can someone give me a pointer on how to integrate the colorSliderGrp into that, my code is currently taking the form

string $vcsForm = `formLayout -numberOfDivisions 100` ;
string $vcsFButton01 = `button -h 22 -w 200 -label "Stuff" -command "Stuff"`;
formLayout -edit
-attachForm $vcsFButton01 "top" 0
-attachForm $vcsFButton01 "left" 0
$vcsForm;

Ideally, I'd like to place it in a similar way I am placing buttons, i.e., top / left coords.

Thanks.

NaughtyNathan
10-13-2010, 04:02 PM
the ___Grp controls are all actually layouts with a conveniently pre-packaged set of child controls. You can form attach it as a single entity in exactly the same way you do a button or any other control, but additionally you need to use the ___Grp's -cw and other -column___ flags to format it's child controls too.

:nathaN

SUNCHIRP
10-13-2010, 10:20 PM
Thanks for that, been messing around with the various parameters of that command, takes some experimentation.. I think I may initially going about what I want the wrong way. I ideally wanted to have a colour chooser, so just the coloured box area of the colorSliderGrp, so I can choose a colour, then I would set up a button next to it, 'Apply', which would then apply the selected colour, either globally to the object selected, or the vertices that are currently selected instead.

SUNCHIRP
10-14-2010, 12:25 AM
Ok, I've been digging around this for quite a while now, and still as confused as ever, I seem to have tried every combo. of column / row alignment I can think of, yet I can still not get the slider group to appear at the bottom of my buttons on the formLayout ( always at the top - and obscured by my 1st button) , can anybody help with 'exactly' what I should be doing to get this to appear after my buttons : -

My basic code template is : -

string $vcsForm = `formLayout -numberOfDivisions 100` ;
string $vcsFButton01 = `button -h 22 -w 200 -label "Stuff" -command "Stuff"`;
formLayout -edit
-attachForm $vcsFButton01 "top" 0
-attachForm $vcsFButton01 "left" 0
$vcsForm;

I want to add this : -

colorSliderGrp -w 250 -h 22 -rgb 0.5 0.5 0.5 -columnAttach2 "left" "left" -columnOffset2 0 0;

and have it appear 'after / directly under' my buttons, so what flags should I be looking at, because atm, I'm stumped, - oh yeah, also, that's a point, how do I change the size of the slider area also, can't see any flags / options for that either ? :cry:

ewerybody
10-14-2010, 10:30 AM
you just need to define the arrangement after the creation of the elements:{
window;
string $vcsForm = `formLayout -numberOfDivisions 100` ;
string $vcsFButton01 = `button -h 22 -w 200 -label "Stuff" -command "Stuff"`;
colorSliderGrp -w 250 -h 22 -rgb 0.5 0.5 0.5 -columnAttach2 "left" "left" -columnOffset2 0 0 SUNCHIRPcolorSlider;

formLayout -edit
-attachForm $vcsFButton01 "top" 0
-attachForm $vcsFButton01 "left" 0
-ac SUNCHIRPcolorSlider "top" 0 $vcsFButton01
$vcsForm;

showWindow;
}However: you "could" create the slider thereafter as well and edit the formLayout again finding the last element in there and -ac-ing the new thing under it.
But actually for collecting elements one under another the columnLayout (http://download.autodesk.com/us/maya/2009help/Commands/columnLayout.html) is just more than enough! It saves you a lot of hassle because it acts dynamically. Put a control into it: it appears just at the end. Delete one from it: all others move up.{
window;
columnLayout -adj 1 columnLayoutTestColumn;
button -l "add button" -c "columnLayoutTestProc";
showWindow;
}

global proc columnLayoutTestProc()
{
string $thisButton = `button -parent columnLayoutTestColumn`;
button -edit -c ("deleteUI " + $thisButton) -label ("remove me ( " + $thisButton + " )") $thisButton;
}But of course I don't know if you only want to do that! If you want stacked controls to mix with whatever else you can just do so by putting the columnLayout into the formLayout with the others.

SUNCHIRP
10-14-2010, 10:37 AM
Man, that's excellent, thanks for the in depth reply.

The first example is more than enough for what I need, I'm going to delve a little deeper and see if I can understand this more thoroughly. If I'm understanding this so far, you defined the colorSliderGrp as a control called SUNCHIRPcolorSlider, then used the formLayout's -ac flag to attach that control in the appropriate area. Going to look at this further during lunch today.

Thanks again.

S

ewerybody
10-14-2010, 10:48 AM
Of course you can also name it anything else ;] or put it in a variable and then using this again in the formLayout -edit ...

But at least I always tend to use definite names for that stuff.
cheers:beer:

SUNCHIRP
10-14-2010, 01:31 PM
Ok, I've understood how this works in the UI context, and I'm able to carry on building my UI elements - however - I have a button next to my colorSliderGrp, which is essentially my 'Apply' button - to colour the verts or objects selected with the chosen colour, how would I go about capturing the colour info from my colorSliderGrp ?

I've tried

global proc vcsApplyColour()
{
float $vcs_EditColors[] = `colorEditor -q -rgb`;
if (`colorEditor -query -result` == 1)
{
polyColorPerVertex -r $vcs_EditColors[0] -g $vcs_EditColors[1] -b $vcs_EditColors[2];
return;
}
confirmDialog -t "Error ! " -m "Please Select A Colour First." -b Continue;
}

but this is based on the colorEditor, which I thought was the same thing in the colorSliderGrp ? But obviously isn't, as I keep getting the error dialog - I assume I need to call out my control and query that ( SUNCHIRPcolorSlider; ) ?

ewerybody
10-14-2010, 03:08 PM
oh no these are completely different things! The one is a tool you can call and query. The other is a UI control. But of course you call the tool from the control if you press the color-field.

see the -rgbValue flag at colorSliderGrp (http://download.autodesk.com/us/maya/2009help/Commands/colorSliderGrp.html#flagrgbValue)!{
window;
string $vcsForm = `formLayout -numberOfDivisions 100` ;
string $vcsFButton01 = `button -h 22 -w 200 -label "Stuff" -command "vcsApplyColour"`;
colorSliderGrp -w 250 -h 22 -rgb 0.5 0.5 0.5 -columnAttach2 "left" "left" -columnOffset2 0 0 SUNCHIRPcolorSlider;

formLayout -edit
-attachForm $vcsFButton01 "top" 0
-attachForm $vcsFButton01 "left" 0
-ac SUNCHIRPcolorSlider "top" 0 $vcsFButton01
$vcsForm;

showWindow;
}

global proc vcsApplyColour()
{
float $vcs_EditColors[] = `colorSliderGrp -q -rgbValue SUNCHIRPcolorSlider`;
polyColorPerVertex -r $vcs_EditColors[0] -g $vcs_EditColors[1] -b $vcs_EditColors[2];
}

SUNCHIRP
10-14-2010, 04:16 PM
ah, of course, that makes things much clearer ! :bounce:

Thanks again for your time.

Regards.

SUNCHIRP
10-14-2010, 11:37 PM
Hi, looks like I'm still struggling with this... :/

The code works as expected - but if I apply any vertex alpha - and then utilsing my control to apply colour - the colour is applied, but the alpha is not overwritten with the colour values, it stays transparent, and anything selected beyond the alpha has the colour applied ?

Any pointers ?

In my UI - I have two Colour Sliders groups, 1 to apply colour and 1 to apply alpha - so far only the colour one is working as expected ( but with the alpha problem )

my code takes the format

global proc vcsApplyColour()
{
float $vcs_EditColors[] = `colorSliderGrp -q -rgbValue vcsColorSlider`;
polyColorPerVertex -r $vcs_EditColors[0] -g $vcs_EditColors[1] -b $vcs_EditColors[2];
}

and for the alpha

global proc vcsApplyAlpha()
{
float $vcs_EditAlpha[] = `colorSliderGrp -q -rgbValue vcsAlphaSlider`;
polyColorPerVertex -r $vcs_EditAlpha[0] -g $vcs_EditAlpha[1] -b $vcs_EditAlpha[2] -a $vcs_EditAlpha[3];
}

How do I work into the first procedure the ability to overwrite any alpha present with rgb colour only ? appending something like -a $vcs_EditColors[3] will not work correctly, and I'm not sure if that would be correct anyway - I only want rgb colours, no alpha, when I utilise the vcsApplyColour procedure.

Thanks.

SUNCHIRP
10-15-2010, 10:31 AM
Never mind, figured it out, slaps head.... :/

-a 1; ! :thumbsup:

global proc vcsApplyColour()
{
float $vcs_EditColors[] = `colorSliderGrp -q -rgbValue vcsColorSlider`;
polyColorPerVertex -r $vcs_EditColors[0] -g $vcs_EditColors[1] -b $vcs_EditColors[2] -a 1;
}

ewerybody
10-15-2010, 10:46 AM
btw.. I have a vertexColorTool (http://goodsoul.de/mel/vertexColorTool.mel) that fits my needs almost perfectly for years ;] I actually have color and alpha separated by design.

SUNCHIRP
10-15-2010, 11:46 AM
Thanks, ewerybody

It'll be good to have a dig around and see what you've done with your tool.

In my tool, I have quite a few more functions planned as yet - currently it's early stages and has display options for vertex colour, vtx col + texture, vtx col + texture + light, vtx col + texture + light + hq ( as in the bonus games tools script ) and a reset - I then have two buttons - 1 to flood fill object / selection with pure white, the other button to 'smooth' the object / selections vertex colours. I then have my colour slider groups for applying colour or alpha - after that I have planned options for brightness, contrast, dodge / burn, R / G / B values per vertex ( i.e. increase or decrease 'redness' in whatever current selection colour is ), and Saturation. I will also include bake buttons, 1 for Ambient Occlusion bake, 1 for Light / Colour / Shadow, and 1 for bake options dialog ( so you can create seperate colour sets ) and lastly a button to bring up the colour set editor for tweaking / flattening colour sets. I may add more stuff, depends on what cool stuff I come across when developing these ! :)

Regards.

ewerybody
10-15-2010, 01:13 PM
Whoar that sounds like a hell of a ride you have ahead ^^
But I'm sure you gonna dig it.

The things I like about my tool:
* always converts to vertexes, so you can apply on the whole object, an edgeloop or some faces. doesn't matter. It just applies the color. (polyListComponentConversion is your friend!)
* I have MarkingMenus on the color and alpha slider: RMB-upstroke: apply white/aplha 1 RMB-downstroke: apply black/alpha 0
* the vColors toggler works dynamically on the selection

what I actually wanted to add: a way to make gradients over a selection of vertices and maybe a way to make it act on slider drag already so you can see changes instantly.

but you seem to need it for lightmapping purposes?
I use mine mostly for fx.

Sorath
10-15-2010, 01:20 PM
awesome script ewerybody.. thanks for sharing!

looking forward to sunchirps results, would be cool if you can share.

ewerybody
10-15-2010, 01:27 PM
naahh Thanks. But its so tiny... I wouldn't call it awesome :D
But it does what its supposed to. Compared to the Maya built-in one ;]

CGTalk Moderation
10-15-2010, 01:27 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.