|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object common:Generic common:ColorMerge
class
This is a generic color blending class. It accepts two
colors and produces a merged result.
class ColorMerge(Generic) { ; This is a generic color blending class. It accepts two ; colors and produces a merged result. public: ; Constructor ; ; @param pparent a reference to the object creating the new object; typically, 'this' func ColorMerge(Generic pparent) Generic.Generic(pparent) endfunc ; Color merging function ; ; @param pbottom color on the bottom ; @param ptop color on the top ; @return merged color; alpha value should be from the top color or composing won't work right color func Merge(color pbottom, color ptop) return ptop endfunc ; Opaque test function ; <p> ; In some cases, formulas want to know if, given a particular ; color, merging it onto another color will leave any of the ; other color visible (i.e. does all the color come from the ; top color). This function should return true in that case. ; The default implementation always returns false; if you ; write a merging class which can identify opaque colors, you ; should override this function. (Note this isn't as simple ; as just looking at the top color's opacity; in non-Normal ; merge modes the bottom color still influences the output.) ; ; @param ptop top color to test ; @return true if top color is fully opaque bool func IsOpaque(color ptop) return false endfunc ; Static composing/blending helper function ; <p> ; The explicit formula provided in the UF help for doing a ; color blend is: ; <p> ; compose(b, blend(t, mergeX(b, t), alpha(b)), o) ; <p> ; This at first seems overly complicated, but in fact is ; necessary to account for alpha in both the bottom and ; top colors. This function wraps up the compose and blend ; steps so you don't have to remember the correct formula. ; To use this, you will need to have the top color both ; before and after the merge function has been applied. ; <p> ; This is a static function, so you can call it without ; creating a ColorMerge object. Just call ColorMerge.Stack() ; directly. ; ; @param pbottom color on the bottom ; @param ptop color on the top (pre-merge) ; @param pmerged color on the top (post-merge) ; @param popacity opacity; 0 indicates all bottom, 1 indicates all top static color func Stack(color pbottom, color ptop, color pmerged, float popacity) return compose(pbottom, blend(ptop, pmerged, alpha(pbottom)), popacity) endfunc ; Composing/blending helper function ; <p> ; Like Stack(), this is a helper function to make it easier ; to merge colors layer-style. However, Stack() still requires ; you to produce the merged color. FullMerge() will do the ; merging for you, but you have to use a ColorMerge object ; (not just call a static function). ; ; @param pbottom color on the bottom ; @param ptop color on the top (pre-merge) ; @param popacity opacity; 0 indicates all bottom, 1 indicates all top color func FullMerge(color pbottom, color ptop, float popacity) return Stack(pbottom, ptop, Merge(pbottom, ptop), popacity) endfunc default: int param v_colormerge caption = "Version (ColorMerge)" default = 100 hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used." visible = @v_colormerge < 100 endparam }
Constructor Summary | |
---|---|
ColorMerge()
|
|
ColorMerge(Generic pparent)
Constructor |
Method Summary | |
---|---|
color |
FullMerge(color pbottom,
color ptop,
float popacity)
Composing/blending helper function |
boolean |
IsOpaque(color ptop)
Opaque test function |
color |
Merge(color pbottom,
color ptop)
Color merging function |
static color |
Stack(color pbottom,
color ptop,
color pmerged,
float popacity)
Static composing/blending helper function |
Methods inherited from class common:Generic |
---|
GetParent |
Methods inherited from class Object |
---|
|
Constructor Detail |
---|
public ColorMerge(Generic pparent)
pparent
- a reference to the object creating the new object; typically, 'this'public ColorMerge()
Method Detail |
---|
public color Merge(color pbottom, color ptop)
pbottom
- color on the bottomptop
- color on the top
public boolean IsOpaque(color ptop)
In some cases, formulas want to know if, given a particular color, merging it onto another color will leave any of the other color visible (i.e. does all the color come from the top color). This function should return true in that case. The default implementation always returns false; if you write a merging class which can identify opaque colors, you should override this function. (Note this isn't as simple as just looking at the top color's opacity; in non-Normal merge modes the bottom color still influences the output.)
ptop
- top color to test
public static color Stack(color pbottom, color ptop, color pmerged, float popacity)
The explicit formula provided in the UF help for doing a color blend is:
compose(b, blend(t, mergeX(b, t), alpha(b)), o)
This at first seems overly complicated, but in fact is necessary to account for alpha in both the bottom and top colors. This function wraps up the compose and blend steps so you don't have to remember the correct formula. To use this, you will need to have the top color both before and after the merge function has been applied.
This is a static function, so you can call it without creating a ColorMerge object. Just call ColorMerge.Stack() directly.
pbottom
- color on the bottomptop
- color on the top (pre-merge)pmerged
- color on the top (post-merge)popacity
- opacity; 0 indicates all bottom, 1 indicates all toppublic color FullMerge(color pbottom, color ptop, float popacity)
Like Stack(), this is a helper function to make it easier to merge colors layer-style. However, Stack() still requires you to produce the merged color. FullMerge() will do the merging for you, but you have to use a ColorMerge object (not just call a static function).
pbottom
- color on the bottomptop
- color on the top (pre-merge)popacity
- opacity; 0 indicates all bottom, 1 indicates all top
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |