Ticket #2421: colorAdd_TextureMaskMode_v3.patch
File colorAdd_TextureMaskMode_v3.patch, 7.4 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/gui/common/colorFades.js
22 22 * duration: maximal duration of the complete fade (if 0 it runs until it is stopped) 23 23 * fun_colorTransform: function which transform the colors; 24 24 * arguments: [var data] 25 * colorMask[optional]: path to a image which is used as a color mask 25 26 * restartAble [optional: if false, the fade can not be restarted; default: true 26 27 * fun_smoothRestart [optional]: a function, which returns a smooth tick counter, if the fade should be started; 27 28 * arguments: [var data]; must return false, if smooth restart was not possible and true, if it was ok 28 29 */ 29 function startColorFade(name, tickInterval, duration, fun_colorTransform, restartAble, fun_smoothRestart)30 function startColorFade(name, tickInterval, duration, fun_colorTransform, colorMask, restartAble, fun_smoothRestart) 30 31 { 31 32 // get the overlay 32 33 var overlay = Engine.GetGUIObjectByName(name); … … 47 48 "tickCounter": 0, 48 49 "justStopAtExternCall": duration == 0, 49 50 "stopFade": false, 50 "rgb": getInitColorFadeRGB() 51 "rgb": getInitColorFadeRGB(), 52 "colorMask": colorMask 51 53 }; 52 54 // store it! 53 55 g_colorFade[name] = data; … … 57 59 } 58 60 else if (restartAble) 59 61 { 60 restartColorFade(name , tickInterval, duration, fun_colorTransform, restartAble, fun_smoothRestart);62 restartColorFade(name); 61 63 return; 62 64 } 63 65 } … … 84 86 var rgb = data.rgb; 85 87 overlay.sprite="colour: " + rgb.r + " " + rgb.g + " " + rgb.b + " " + rgb.o; 86 88 89 // check, if color mask mode is used and add the filename in this case 90 if (data.colorMask) 91 overlay.sprite += ":" + data.colorMask; 92 87 93 // recusive call, if duration is positive 88 94 if (!data.stopFade && (data.justStopAtExternCall || data.duration - (data.tickInterval * data.tickCounter) > 0)) 89 95 { … … 159 165 else 160 166 { 161 167 stopColorFade(name, false); 162 startColorFade(name, data.changeInterval, data.duration, data.fun_colorTransform, data. restartAble, data.fun_smoothRestart);168 startColorFade(name, data.changeInterval, data.duration, data.fun_colorTransform, data.colorMask, data.restartAble, data.fun_smoothRestart); 163 169 } 164 170 return true; 165 171 } -
binaries/data/mods/public/gui/gui.dtd
201 201 <!ATTLIST effect 202 202 add_color CDATA #IMPLIED 203 203 multiply_color CDATA #IMPLIED 204 textureMaskMode %bool; #IMPLIED 204 205 grayscale CDATA #IMPLIED 205 206 > -
binaries/data/mods/public/shaders/effects/gui_add.xml
2 2 <effect> 3 3 4 4 <technique> 5 <require context="!TEXTURE_MASK_MODE"/> 5 6 <require shaders="fixed"/> 6 7 <pass shader="fixed:gui_add"/> 7 8 </technique> -
binaries/data/mods/public/shaders/glsl/gui_add.fs
7 7 8 8 void main() 9 9 { 10 gl_FragColor = texture2D(tex, v_tex) + color; 10 vec4 t = texture2D(tex, v_tex); 11 12 #if TEXTURE_MASK_MODE 13 gl_FragColor.rgb = color.rgb; 14 gl_FragColor.a = min(t.a, color.a); 15 #else 16 gl_FragColor = t + color; 17 #endif 11 18 } -
source/gui/CGUI.cpp
1617 1617 { 1618 1618 effects.m_Greyscale = true; 1619 1619 } 1620 else if (attr_name == "textureMaskMode") 1621 { 1622 effects.m_TextureMaskMode = true; 1623 } 1620 1624 else 1621 1625 { 1622 1626 debug_warn(L"Invalid data - DTD shouldn't allow this"); -
source/gui/CGUISprite.h
64 64 65 65 struct SGUIImageEffects 66 66 { 67 SGUIImageEffects() : m_Greyscale(false) {}67 SGUIImageEffects() : m_Greyscale(false), m_TextureMaskMode(false) {} 68 68 CColor m_AddColor; 69 69 bool m_Greyscale; 70 bool m_TextureMaskMode; 70 71 }; 71 72 72 73 /** -
source/gui/GUIRenderer.cpp
79 79 // "stretched:grayscale:filename.ext" - stretched grayscale image 80 80 // "cropped:(0.5, 0.25)" - stretch this ratio (x,y) of the top left of the image 81 81 // "colour:r g b a" - solid colour 82 // "colour:r g b a:filenameMask.ext" - solid colour with textureMask 82 83 // 83 84 // and if so, try to create it as a new sprite. 84 85 if (SpriteName.substr(0, 10) == "stretched:") … … 137 138 } 138 139 else if (SpriteName.substr(0, 7) == "colour:") 139 140 { 141 SGUIImage* Image = new SGUIImage; 142 143 // check, if there is a sprite for defining of opacity values 144 size_t splitIndex = SpriteName.substr(7).find_first_of(":"); 140 145 CStrW value = wstring_from_utf8(SpriteName.substr(7)); 146 CStrW textureMask; 141 147 CColor color; 142 148 149 // trim the color value and the name of the textureMask 150 if(splitIndex != std::basic_string<char>::npos) 151 { 152 textureMask = value.substr(splitIndex + 1); 153 value = value.substr(0, splitIndex); 154 } 155 143 156 // Check colour is valid 144 157 if (!GUI<CColor>::ParseString(value, color)) 145 158 { … … 147 160 return; 148 161 } 149 162 150 SGUIImage* Image = new SGUIImage; 163 // set background color or add color effect if textureMask is set 164 if(splitIndex != std::basic_string<char>::npos) 165 { 166 // TODO: Should check (nicely) that this is a valid file? 167 Image->m_TextureName = VfsPath("art/textures/ui") / textureMask; 168 Image->m_Effects = new SGUIImageEffects; 169 Image->m_Effects->m_AddColor = color; 170 Image->m_Effects->m_TextureMaskMode = true; 171 } 172 else 173 Image->m_BackColor = color; 151 174 152 Image->m_BackColor = color;153 154 175 CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); 155 176 Image->m_Size = ca; 156 177 Image->m_TextureSize = ca; … … 231 252 { 232 253 if ((*cit)->m_Effects->m_AddColor != CColor()) 233 254 { 234 Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_add); 255 CShaderDefines defines; 256 // enable texture mask mode 257 if ((*cit)->m_Effects->m_TextureMaskMode) 258 defines.Add(str_TEXTURE_MASK_MODE, str_1); 259 260 Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_add, g_Renderer.GetSystemShaderDefines(), defines); 235 261 Call.m_ShaderColorParameter = (*cit)->m_Effects->m_AddColor; 236 262 // Always enable blending if something's being subtracted from 237 263 // the alpha channel -
source/ps/CStrInternStatic.h
64 64 X(USE_SHADOW_PCF) 65 65 X(USE_SHADOW_SAMPLER) 66 66 X(USE_WAVES) 67 X(TEXTURE_MASK_MODE) 67 68 X2(_emptystring, "") 68 69 X(a_skinJoints) 69 70 X(a_skinWeights)