00001 #include "gui_texture.hpp"
00002 #include "gui_layeredregion.hpp"
00003 #include "gui_out.hpp"
00004
00005 #include <luapp_function.hpp>
00006
00007 namespace gui
00008 {
00009 void texture::register_glue(utils::wptr<lua::state> pLua)
00010 {
00011 pLua->reg<lua_texture>();
00012 }
00013
00014 lua_texture::lua_texture(lua_State* pLua) : lua_layered_region(pLua)
00015 {
00016 pTextureParent_ = dynamic_cast<texture*>(pParent_);
00017 if (pParent_ && !pTextureParent_)
00018 throw exception("lua_texture", "Dynamic cast failed !");
00019 }
00020
00021 int lua_texture::_get_blend_mode(lua_State* pLua)
00022 {
00023 if (!check_parent_())
00024 return 0;
00025
00026 lua::function mFunc("Texture:get_blend_mode", pLua, 1);
00027
00028 texture::blend_mode mBlend = pTextureParent_->get_blend_mode();
00029
00030 std::string sBlend;
00031 switch (mBlend)
00032 {
00033 case texture::BLEND_NONE : sBlend = "NONE"; break;
00034 case texture::BLEND_BLEND : sBlend = "BLEND"; break;
00035 case texture::BLEND_KEY : sBlend = "KEY"; break;
00036 case texture::BLEND_ADD : sBlend = "ADD"; break;
00037 case texture::BLEND_MOD : sBlend = "MOD"; break;
00038 }
00039
00040 mFunc.push(sBlend);
00041
00042 return mFunc.on_return();
00043 }
00044
00045 int lua_texture::_get_tex_coord(lua_State* pLua)
00046 {
00047 if (!check_parent_())
00048 return 0;
00049
00050 lua::function mFunc("Texture:get_tex_coord", pLua, 8);
00051
00052 const std::array<float,8>& lCoords = pTextureParent_->get_tex_coord();
00053
00054 for (uint i = 0; i < 8; ++i)
00055 mFunc.push(lCoords[i]);
00056
00057 return mFunc.on_return();
00058 }
00059
00060 int lua_texture::_get_tex_coord_modifies_rect(lua_State* pLua)
00061 {
00062 if (!check_parent_())
00063 return 0;
00064
00065 lua::function mFunc("Texture:get_tex_coord_modifies_rect", pLua, 1);
00066
00067 mFunc.push(pTextureParent_->get_tex_coord_modifies_rect());
00068
00069 return mFunc.on_return();
00070 }
00071
00072 int lua_texture::_get_texture(lua_State* pLua)
00073 {
00074 if (!check_parent_())
00075 return 0;
00076
00077 lua::function mFunc("Texture:get_texture", pLua, 1);
00078
00079 mFunc.push(pTextureParent_->get_texture());
00080
00081 return mFunc.on_return();
00082 }
00083
00084 int lua_texture::_get_vertex_color(lua_State* pLua)
00085 {
00086 if (!check_parent_())
00087 return 0;
00088
00089 lua::function mFunc("Texture:get_vertex_color", pLua, 4);
00090
00091 color mColor = pTextureParent_->get_vertex_color();
00092
00093 mFunc.push(mColor.r);
00094 mFunc.push(mColor.g);
00095 mFunc.push(mColor.b);
00096 mFunc.push(mColor.a);
00097
00098 return mFunc.on_return();
00099 }
00100
00101 int lua_texture::_is_desaturated(lua_State* pLua)
00102 {
00103 if (!check_parent_())
00104 return 0;
00105
00106 lua::function mFunc("Texture:is_desaturated", pLua, 1);
00107
00108 mFunc.push(pTextureParent_->is_desaturated());
00109
00110 return mFunc.on_return();
00111 }
00112
00113 int lua_texture::_set_blend_mode(lua_State* pLua)
00114 {
00115 if (!check_parent_())
00116 return 0;
00117
00118 lua::function mFunc("Texture:set_blend_mode", pLua);
00119 mFunc.add(0, "blend mode", lua::TYPE_STRING);
00120 if (mFunc.check())
00121 {
00122 std::string sBlend = mFunc.get(0)->get_string();
00123 texture::blend_mode mBlend;
00124 if (sBlend == "NONE")
00125 mBlend = texture::BLEND_NONE;
00126 else if (sBlend == "BLEND")
00127 mBlend = texture::BLEND_BLEND;
00128 else if (sBlend == "KEY")
00129 mBlend = texture::BLEND_KEY;
00130 else if (sBlend == "ADD")
00131 mBlend = texture::BLEND_ADD;
00132 else if (sBlend == "MOD")
00133 mBlend = texture::BLEND_MOD;
00134 else
00135 {
00136 gui::out << gui::warning << mFunc.get_name() << " : "
00137 << "Unknown blending mode : \""+sBlend+"\"." << std::endl;
00138 return mFunc.on_return();
00139 }
00140
00141 pTextureParent_->set_blend_mode(mBlend);
00142 }
00143
00144 return mFunc.on_return();
00145 }
00146
00147 int lua_texture::_set_desaturated(lua_State* pLua)
00148 {
00149 if (!check_parent_())
00150 return 0;
00151
00152 lua::function mFunc("Texture:set_desaturated", pLua, 1);
00153 mFunc.add(0, "is desaturated", lua::TYPE_BOOLEAN);
00154 if (mFunc.check())
00155 pTextureParent_->set_desaturated(mFunc.get(0)->get_bool());
00156
00157 mFunc.push(true);
00158
00159 return mFunc.on_return();
00160 }
00161
00162 int lua_texture::_set_gradient(lua_State* pLua)
00163 {
00164 if (!check_parent_())
00165 return 0;
00166
00167 lua::function mFunc("Texture:set_gradient", pLua);
00168 mFunc.add(0, "orientation", lua::TYPE_STRING);
00169 mFunc.add(1, "min red", lua::TYPE_NUMBER);
00170 mFunc.add(2, "min green", lua::TYPE_NUMBER);
00171 mFunc.add(3, "min blue", lua::TYPE_NUMBER);
00172 mFunc.add(4, "max red", lua::TYPE_NUMBER);
00173 mFunc.add(5, "max green", lua::TYPE_NUMBER);
00174 mFunc.add(6, "max blue", lua::TYPE_NUMBER);
00175 if (mFunc.check())
00176 {
00177 std::string sOrientation = mFunc.get(0)->get_string();
00178 gradient::orientation mOrientation;
00179 if (sOrientation == "HORIZONTAL")
00180 mOrientation = gradient::HORIZONTAL;
00181 else if (sOrientation == "VERTICAL")
00182 mOrientation = gradient::VERTICAL;
00183 else
00184 {
00185 gui::out << gui::warning << mFunc.get_name() << " : "
00186 "Unknown gradient orientation : \""+sOrientation+"\"." << std::endl;
00187 return mFunc.on_return();
00188 }
00189
00190 pTextureParent_->set_gradient(gradient(
00191 mOrientation,
00192 color(
00193 mFunc.get(1)->get_number(),
00194 mFunc.get(2)->get_number(),
00195 mFunc.get(3)->get_number()
00196 ),
00197 color(
00198 mFunc.get(4)->get_number(),
00199 mFunc.get(5)->get_number(),
00200 mFunc.get(6)->get_number()
00201 )
00202 ));
00203 }
00204
00205 return mFunc.on_return();
00206 }
00207
00208 int lua_texture::_set_gradientAlpha(lua_State* pLua)
00209 {
00210 if (!check_parent_())
00211 return 0;
00212
00213 lua::function mFunc("Texture:set_gradientAlpha", pLua);
00214 mFunc.add(0, "orientation", lua::TYPE_STRING);
00215 mFunc.add(1, "min red", lua::TYPE_NUMBER);
00216 mFunc.add(2, "min green", lua::TYPE_NUMBER);
00217 mFunc.add(3, "min blue", lua::TYPE_NUMBER);
00218 mFunc.add(4, "min alpha", lua::TYPE_NUMBER);
00219 mFunc.add(5, "max red", lua::TYPE_NUMBER);
00220 mFunc.add(6, "max green", lua::TYPE_NUMBER);
00221 mFunc.add(7, "max blue", lua::TYPE_NUMBER);
00222 mFunc.add(8, "max alpha", lua::TYPE_NUMBER);
00223 if (mFunc.check())
00224 {
00225 std::string sOrientation = mFunc.get(0)->get_string();
00226 gradient::orientation mOrientation;
00227 if (sOrientation == "HORIZONTAL")
00228 mOrientation = gradient::HORIZONTAL;
00229 else if (sOrientation == "VERTICAL")
00230 mOrientation = gradient::VERTICAL;
00231 else
00232 {
00233 gui::out << gui::warning << mFunc.get_name() << " : "
00234 "Unknown gradient orientation : \""+sOrientation+"\"." << std::endl;
00235 return mFunc.on_return();
00236 }
00237
00238 pTextureParent_->set_gradient(gradient(
00239 mOrientation,
00240 color(
00241 mFunc.get(1)->get_number(),
00242 mFunc.get(2)->get_number(),
00243 mFunc.get(3)->get_number(),
00244 mFunc.get(4)->get_number()
00245 ),
00246 color(
00247 mFunc.get(5)->get_number(),
00248 mFunc.get(6)->get_number(),
00249 mFunc.get(7)->get_number(),
00250 mFunc.get(8)->get_number()
00251 )
00252 ));
00253 }
00254
00255 return mFunc.on_return();
00256 }
00257
00258 int lua_texture::_set_tex_coord(lua_State* pLua)
00259 {
00260 if (!check_parent_())
00261 return 0;
00262
00263 lua::function mFunc("Texture:set_tex_coord", pLua);
00264 mFunc.add(0, "left", lua::TYPE_NUMBER);
00265 mFunc.add(1, "top", lua::TYPE_NUMBER);
00266 mFunc.add(2, "right", lua::TYPE_NUMBER);
00267 mFunc.add(3, "bottom", lua::TYPE_NUMBER);
00268 mFunc.new_param_set();
00269 mFunc.add(0, "top-left X", lua::TYPE_NUMBER);
00270 mFunc.add(1, "top-left Y", lua::TYPE_NUMBER);
00271 mFunc.add(2, "top-right X", lua::TYPE_NUMBER);
00272 mFunc.add(3, "top-right Y", lua::TYPE_NUMBER);
00273 mFunc.add(4, "bottom-right X", lua::TYPE_NUMBER);
00274 mFunc.add(5, "bottom-right Y", lua::TYPE_NUMBER);
00275 mFunc.add(6, "bottom-left X", lua::TYPE_NUMBER);
00276 mFunc.add(7, "bottom-left Y", lua::TYPE_NUMBER);
00277
00278 if (mFunc.check())
00279 {
00280 if (mFunc.get_param_set_rank() == 0)
00281 {
00282
00283 pTextureParent_->set_tex_coord(std::array<float,4>({{
00284 mFunc.get(0)->get_number(), mFunc.get(1)->get_number(),
00285 mFunc.get(2)->get_number(), mFunc.get(3)->get_number()
00286 }}));
00287 }
00288 else
00289 {
00290
00291 pTextureParent_->set_tex_coord(std::array<float,8>({{
00292 mFunc.get(0)->get_number(), mFunc.get(1)->get_number(),
00293 mFunc.get(2)->get_number(), mFunc.get(3)->get_number(),
00294 mFunc.get(4)->get_number(), mFunc.get(5)->get_number(),
00295 mFunc.get(6)->get_number(), mFunc.get(7)->get_number()
00296 }}));
00297 }
00298 }
00299
00300 return mFunc.on_return();
00301 }
00302
00303 int lua_texture::_set_tex_coord_modifies_rect(lua_State* pLua)
00304 {
00305 if (!check_parent_())
00306 return 0;
00307
00308 lua::function mFunc("Texture:set_tex_coord_modifies_rect", pLua);
00309 mFunc.add(0, "does set_tex_coord modifies size", lua::TYPE_BOOLEAN);
00310 if (mFunc.check())
00311 pTextureParent_->set_tex_coord_modifies_rect(mFunc.get(0)->get_bool());
00312
00313 return mFunc.on_return();
00314 }
00315
00316 int lua_texture::_set_texture(lua_State* pLua)
00317 {
00318 if (!check_parent_())
00319 return 0;
00320
00321 lua::function mFunc("Texture:set_texture", pLua);
00322 mFunc.add(0, "texture", lua::TYPE_STRING);
00323 mFunc.new_param_set();
00324 mFunc.add(0, "red", lua::TYPE_NUMBER);
00325 mFunc.add(1, "green", lua::TYPE_NUMBER);
00326 mFunc.add(2, "blue", lua::TYPE_NUMBER);
00327 mFunc.add(3, "alpha", lua::TYPE_NUMBER, true);
00328
00329 if (mFunc.check())
00330 {
00331 if (mFunc.get_param_set_rank() == 0)
00332 {
00333
00334 pTextureParent_->set_texture(
00335 pTextureParent_->get_manager()->parse_file_name(mFunc.get(0)->get_string())
00336 );
00337 }
00338 else
00339 {
00340
00341 color mColor;
00342 if (mFunc.is_provided(3))
00343 {
00344 mColor = color(
00345 mFunc.get(0)->get_number(),
00346 mFunc.get(1)->get_number(),
00347 mFunc.get(2)->get_number(),
00348 mFunc.get(3)->get_number()
00349 );
00350 }
00351 else
00352 {
00353 mColor = color(
00354 mFunc.get(0)->get_number(),
00355 mFunc.get(1)->get_number(),
00356 mFunc.get(2)->get_number()
00357 );
00358 }
00359 pTextureParent_->set_color(mColor);
00360 }
00361 }
00362
00363 return mFunc.on_return();
00364 }
00365
00366 int lua_texture::_set_vertex_color(lua_State* pLua)
00367 {
00368 if (!check_parent_())
00369 return 0;
00370
00371 lua::function mFunc("Texture:set_vertex_color", pLua);
00372 mFunc.add(0, "red", lua::TYPE_NUMBER);
00373 mFunc.add(1, "green", lua::TYPE_NUMBER);
00374 mFunc.add(2, "blue", lua::TYPE_NUMBER);
00375 mFunc.add(3, "alpha", lua::TYPE_NUMBER, true);
00376
00377 if (mFunc.check())
00378 {
00379 color mColor;
00380 if (mFunc.is_provided(3))
00381 {
00382 mColor = color(
00383 mFunc.get(0)->get_number(),
00384 mFunc.get(1)->get_number(),
00385 mFunc.get(2)->get_number(),
00386 mFunc.get(3)->get_number()
00387 );
00388 }
00389 else
00390 {
00391 mColor = color(
00392 mFunc.get(0)->get_number(),
00393 mFunc.get(1)->get_number(),
00394 mFunc.get(2)->get_number()
00395 );
00396 }
00397
00398 pTextureParent_->set_vertex_color(mColor);
00399 }
00400
00401 return mFunc.on_return();
00402 }
00403 }