00001 #include "gui_statusbar.hpp"
00002 #include "gui_texture.hpp"
00003 #include "gui_out.hpp"
00004
00005 #include <luapp_function.hpp>
00006
00007 namespace gui
00008 {
00009 void status_bar::register_glue(utils::wptr<lua::state> pLua)
00010 {
00011 pLua->reg<lua_status_bar>();
00012 }
00013
00014 lua_status_bar::lua_status_bar(lua_State* pLua) : lua_frame(pLua)
00015 {
00016 pStatusBarParent_ = dynamic_cast<status_bar*>(pParent_);
00017 if (pParent_ && !pStatusBarParent_)
00018 throw exception("lua_status_bar", "Dynamic cast failed !");
00019 }
00020
00021 int lua_status_bar::_get_min_max_values(lua_State* pLua)
00022 {
00023 if (!check_parent_())
00024 return 0;
00025
00026 lua::function mFunc("StatusBar:get_min_max_values", pLua, 2);
00027
00028 mFunc.push(pStatusBarParent_->get_min_value());
00029 mFunc.push(pStatusBarParent_->get_max_value());
00030
00031 return mFunc.on_return();
00032 }
00033
00034 int lua_status_bar::_get_orientation(lua_State* pLua)
00035 {
00036 if (!check_parent_())
00037 return 0;
00038
00039 lua::function mFunc("StatusBar:get_orientation", pLua, 1);
00040
00041 switch (pStatusBarParent_->get_orientation())
00042 {
00043 case status_bar::ORIENT_HORIZONTAL : mFunc.push(std::string("HORIZONTAL"));
00044 case status_bar::ORIENT_VERTICAL : mFunc.push(std::string("VERTICAL"));
00045 }
00046
00047 return mFunc.on_return();
00048 }
00049
00050 int lua_status_bar::_get_status_bar_color(lua_State* pLua)
00051 {
00052 if (!check_parent_())
00053 return 0;
00054
00055 lua::function mFunc("StatusBar:get_status_bar_color", pLua, 4);
00056
00057 const color& mColor = pStatusBarParent_->get_bar_color();
00058
00059 mFunc.push(mColor.r);
00060 mFunc.push(mColor.g);
00061 mFunc.push(mColor.b);
00062 mFunc.push(mColor.a);
00063
00064 return mFunc.on_return();
00065 }
00066
00067 int lua_status_bar::_get_status_bar_texture(lua_State* pLua)
00068 {
00069 if (!check_parent_())
00070 return 0;
00071
00072 lua::function mFunc("StatusBar:get_status_bar_texture", pLua, 1);
00073
00074 texture* pTexture = pStatusBarParent_->get_bar_texture();
00075 if (pTexture)
00076 {
00077 pTexture->push_on_lua(mFunc.get_state());
00078 mFunc.notify_pushed();
00079 }
00080
00081 return mFunc.on_return();
00082 }
00083
00084 int lua_status_bar::_get_value(lua_State* pLua)
00085 {
00086 if (!check_parent_())
00087 return 0;
00088
00089 lua::function mFunc("StatusBar:get_value", pLua, 1);
00090
00091 mFunc.push(pStatusBarParent_->get_value());
00092
00093 return mFunc.on_return();
00094 }
00095
00096 int lua_status_bar::_is_reversed(lua_State* pLua)
00097 {
00098 if (!check_parent_())
00099 return 0;
00100
00101 lua::function mFunc("StatusBar:is_reversed", pLua, 1);
00102
00103 mFunc.push(pStatusBarParent_->is_reversed());
00104
00105 return mFunc.on_return();
00106 }
00107
00108 int lua_status_bar::_set_min_max_values(lua_State* pLua)
00109 {
00110 if (!check_parent_())
00111 return 0;
00112
00113 lua::function mFunc("StatusBar:set_min_max_values", pLua);
00114 mFunc.add(0, "min", lua::TYPE_NUMBER);
00115 mFunc.add(1, "max", lua::TYPE_NUMBER);
00116 if (mFunc.check())
00117 {
00118 pStatusBarParent_->set_min_max_values(
00119 mFunc.get(0)->get_number(),
00120 mFunc.get(1)->get_number()
00121 );
00122 }
00123
00124 return mFunc.on_return();
00125 }
00126
00127 int lua_status_bar::_set_orientation(lua_State* pLua)
00128 {
00129 if (!check_parent_())
00130 return 0;
00131
00132 lua::function mFunc("StatusBar:set_orientation", pLua);
00133 mFunc.add(0, "orientation", lua::TYPE_STRING);
00134
00135 if (mFunc.check())
00136 {
00137 std::string sOrient = mFunc.get(0)->get_string();
00138 if (sOrient == "HORIZONTAL")
00139 pStatusBarParent_->set_orientation(status_bar::ORIENT_HORIZONTAL);
00140 else if (sOrient == "VERTICAL")
00141 pStatusBarParent_->set_orientation(status_bar::ORIENT_VERTICAL);
00142 else
00143 {
00144 gui::out << gui::warning << mFunc.get_name()
00145 << " : Unkonwn status bar orientation : \""+sOrient+"\"." << std::endl;
00146 }
00147 }
00148
00149 return mFunc.on_return();
00150 }
00151
00152 int lua_status_bar::_set_status_bar_color(lua_State* pLua)
00153 {
00154 if (!check_parent_())
00155 return 0;
00156
00157 lua::function mFunc("StatusBar:set_status_bar_color", pLua);
00158 mFunc.add(0, "red", lua::TYPE_NUMBER);
00159 mFunc.add(1, "green", lua::TYPE_NUMBER);
00160 mFunc.add(2, "blue", lua::TYPE_NUMBER);
00161 mFunc.add(3, "alpha", lua::TYPE_NUMBER, true);
00162
00163 if (mFunc.check())
00164 {
00165 color mColor;
00166 if (mFunc.is_provided(3))
00167 {
00168 mColor = color(
00169 mFunc.get(0)->get_number(),
00170 mFunc.get(1)->get_number(),
00171 mFunc.get(2)->get_number(),
00172 mFunc.get(3)->get_number()
00173 );
00174 }
00175 else
00176 {
00177 mColor = color(
00178 mFunc.get(0)->get_number(),
00179 mFunc.get(1)->get_number(),
00180 mFunc.get(2)->get_number()
00181 );
00182 }
00183
00184 pStatusBarParent_->set_bar_color(mColor);
00185 }
00186
00187 return mFunc.on_return();
00188 }
00189
00190 int lua_status_bar::_set_status_bar_texture(lua_State* pLua)
00191 {
00192 if (!check_parent_())
00193 return 0;
00194
00195 lua::function mFunc("StatusBar:set_status_bar_texture", pLua);
00196 mFunc.add(0, "texture", lua::TYPE_USERDATA);
00197 if (mFunc.check())
00198 {
00199 lua_texture* pLuaTexture = mFunc.get_state()->get<lua_texture>();
00200 if (pLuaTexture)
00201 {
00202 texture* pTexture = dynamic_cast<texture*>(pLuaTexture->get_parent());
00203 pStatusBarParent_->set_bar_texture(pTexture);
00204 }
00205 }
00206
00207 return mFunc.on_return();
00208 }
00209
00210 int lua_status_bar::_set_value(lua_State* pLua)
00211 {
00212 if (!check_parent_())
00213 return 0;
00214
00215 lua::function mFunc("StatusBar:set_value", pLua);
00216 mFunc.add(0, "value", lua::TYPE_NUMBER);
00217 if (mFunc.check())
00218 pStatusBarParent_->set_value(mFunc.get(0)->get_number());
00219
00220 return mFunc.on_return();
00221 }
00222
00223 int lua_status_bar::_set_reversed(lua_State* pLua)
00224 {
00225 if (!check_parent_())
00226 return 0;
00227
00228 lua::function mFunc("StatusBar:set_reversed", pLua);
00229 mFunc.add(0, "reversed", lua::TYPE_BOOLEAN);
00230 if (mFunc.check())
00231 pStatusBarParent_->set_reversed(mFunc.get(0)->get_bool());
00232
00233 return mFunc.on_return();
00234 }
00235 }