00001 #include "gui_frame.hpp" 00002 #include "gui_backdrop.hpp" 00003 #include "gui_region.hpp" 00004 #include "gui_fontstring.hpp" 00005 #include "gui_texture.hpp" 00006 #include "gui_out.hpp" 00007 00008 #include <luapp_function.hpp> 00009 00010 namespace gui 00011 { 00012 lua_frame::lua_frame(lua_State* pLua) : lua_uiobject(pLua) 00013 { 00014 pFrameParent_ = dynamic_cast<frame*>(pParent_); 00015 if (pParent_ && !pFrameParent_) 00016 throw exception("lua_frame", "Dynamic cast failed !"); 00017 } 00018 00019 int lua_frame::_create_font_string(lua_State* pLua) 00020 { 00021 if (!check_parent_()) 00022 return 0; 00023 00024 lua::function mFunc("Frame:create_font_string", pLua, 1); 00025 mFunc.add(0, "name", lua::TYPE_STRING); 00026 mFunc.add(1, "layer", lua::TYPE_STRING, true); 00027 mFunc.add(2, "inherits", lua::TYPE_STRING, true); 00028 00029 if (mFunc.check()) 00030 { 00031 std::string sName = mFunc.get(0)->get_string(); 00032 00033 layer_type mLayer; 00034 if (mFunc.is_provided(1) && mFunc.get(1)->get_type() == lua::TYPE_STRING) 00035 mLayer = layer::get_layer_type(mFunc.get(1)->get_string()); 00036 else 00037 mLayer = LAYER_ARTWORK; 00038 00039 std::string sInheritance; 00040 if (mFunc.is_provided(2)) 00041 sInheritance = mFunc.get(2)->get_string(); 00042 00043 region* pRegion = pFrameParent_->create_region( 00044 mLayer, "FontString", sName, sInheritance 00045 ); 00046 00047 if (pRegion) 00048 { 00049 pRegion->push_on_lua(mFunc.get_state()); 00050 mFunc.notify_pushed(); 00051 } 00052 else 00053 mFunc.push_nil(); 00054 } 00055 00056 return mFunc.on_return(); 00057 } 00058 00059 int lua_frame::_create_texture(lua_State* pLua) 00060 { 00061 if (!check_parent_()) 00062 return 0; 00063 00064 lua::function mFunc("Frame:create_texture", pLua, 1); 00065 mFunc.add(0, "name", lua::TYPE_STRING); 00066 mFunc.add(1, "layer", lua::TYPE_STRING, true); 00067 mFunc.add(2, "inherits", lua::TYPE_STRING, true); 00068 00069 if (mFunc.check()) 00070 { 00071 std::string sName = mFunc.get(0)->get_string(); 00072 00073 layer_type mLayer; 00074 if (mFunc.is_provided(1) && mFunc.get(1)->get_type() == lua::TYPE_STRING) 00075 mLayer = layer::get_layer_type(mFunc.get(1)->get_string()); 00076 else 00077 mLayer = LAYER_ARTWORK; 00078 00079 std::string sInheritance; 00080 if (mFunc.is_provided(2)) 00081 sInheritance = mFunc.get(2)->get_string(); 00082 00083 region* pRegion = pFrameParent_->create_region( 00084 mLayer, "Texture", sName, sInheritance 00085 ); 00086 00087 if (pRegion) 00088 { 00089 pRegion->push_on_lua(mFunc.get_state()); 00090 mFunc.notify_pushed(); 00091 } 00092 else 00093 mFunc.push_nil(); 00094 } 00095 00096 return mFunc.on_return(); 00097 } 00098 00099 int lua_frame::_create_title_region(lua_State* pLua) 00100 { 00101 if (!check_parent_()) 00102 return 0; 00103 00104 lua::function mFunc("Frame:create_title_region", pLua); 00105 00106 pFrameParent_->create_title_region(); 00107 00108 return mFunc.on_return(); 00109 } 00110 00111 int lua_frame::_disable_draw_layer(lua_State* pLua) 00112 { 00113 if (!check_parent_()) 00114 return 0; 00115 00116 lua::function mFunc("Frame:disable_draw_layer", pLua); 00117 mFunc.add(0, "layer", lua::TYPE_STRING); 00118 if (mFunc.check()) 00119 { 00120 std::string sLayer = mFunc.get(0)->get_string(); 00121 if (sLayer == "BACKGROUND") 00122 pFrameParent_->disable_draw_layer(LAYER_BACKGROUND); 00123 else if (sLayer == "BORDER") 00124 pFrameParent_->disable_draw_layer(LAYER_BORDER); 00125 else if (sLayer == "ARTWORK") 00126 pFrameParent_->disable_draw_layer(LAYER_ARTWORK); 00127 else if (sLayer == "OVERLAY") 00128 pFrameParent_->disable_draw_layer(LAYER_OVERLAY); 00129 else if (sLayer == "HIGHLIGHT") 00130 pFrameParent_->disable_draw_layer(LAYER_HIGHLIGHT); 00131 else 00132 gui::out << gui::warning << mFunc.get_name() << " : Unknown layer : \"" << sLayer << "\"." << std::endl; 00133 } 00134 00135 return mFunc.on_return(); 00136 } 00137 00138 int lua_frame::_enable_draw_layer(lua_State* pLua) 00139 { 00140 if (!check_parent_()) 00141 return 0; 00142 00143 lua::function mFunc("Frame:enable_draw_layer", pLua); 00144 mFunc.add(0, "layer", lua::TYPE_STRING); 00145 if (mFunc.check()) 00146 { 00147 std::string sLayer = mFunc.get(0)->get_string(); 00148 if (sLayer == "BACKGROUND") 00149 pFrameParent_->enable_draw_layer(LAYER_BACKGROUND); 00150 else if (sLayer == "BORDER") 00151 pFrameParent_->enable_draw_layer(LAYER_BORDER); 00152 else if (sLayer == "ARTWORK") 00153 pFrameParent_->enable_draw_layer(LAYER_ARTWORK); 00154 else if (sLayer == "OVERLAY") 00155 pFrameParent_->enable_draw_layer(LAYER_OVERLAY); 00156 else if (sLayer == "HIGHLIGHT") 00157 pFrameParent_->enable_draw_layer(LAYER_HIGHLIGHT); 00158 else 00159 gui::out << gui::warning << mFunc.get_name() << " : Unknown layer : \"" << sLayer << "\"." << std::endl; 00160 } 00161 00162 return mFunc.on_return(); 00163 } 00164 00165 int lua_frame::_enable_keyboard(lua_State* pLua) 00166 { 00167 if (!check_parent_()) 00168 return 0; 00169 00170 lua::function mFunc("Frame:enable_keyboard", pLua); 00171 mFunc.add(0, "is keyboard enable", lua::TYPE_BOOLEAN); 00172 if (mFunc.check()) 00173 pFrameParent_->enable_keyboard(mFunc.get(0)->get_bool()); 00174 00175 return mFunc.on_return(); 00176 } 00177 00178 int lua_frame::_enable_mouse(lua_State* pLua) 00179 { 00180 if (!check_parent_()) 00181 return 0; 00182 00183 lua::function mFunc("Frame:enable_mouse", pLua); 00184 mFunc.add(0, "is mouse enabled", lua::TYPE_BOOLEAN); 00185 mFunc.add(1, "is world input allowed", lua::TYPE_BOOLEAN, true); 00186 if (mFunc.check()) 00187 { 00188 if (mFunc.is_provided(0)) 00189 pFrameParent_->enable_mouse(mFunc.get(0)->get_bool(), mFunc.get(1)->get_bool()); 00190 else 00191 pFrameParent_->enable_mouse(mFunc.get(0)->get_bool()); 00192 } 00193 00194 return mFunc.on_return(); 00195 } 00196 00197 int lua_frame::_enable_mouse_wheel(lua_State* pLua) 00198 { 00199 if (!check_parent_()) 00200 return 0; 00201 00202 lua::function mFunc("Frame:enable_mouse_wheel", pLua); 00203 mFunc.add(0, "is mouse wheel enabled", lua::TYPE_BOOLEAN); 00204 if (mFunc.check()) 00205 pFrameParent_->enable_mouse_wheel(mFunc.get(0)->get_bool()); 00206 00207 return mFunc.on_return(); 00208 } 00209 00210 int lua_frame::_get_backdrop(lua_State* pLua) 00211 { 00212 if (!check_parent_()) 00213 return 0; 00214 00215 lua::function mFunc("Frame:get_backdrop", pLua, 1); 00216 00217 if (utils::refptr<backdrop> pBackdrop = pFrameParent_->get_backdrop().lock()) 00218 { 00219 lua::state* pState = mFunc.get_state(); 00220 00221 pState->new_table(); 00222 pState->set_field_string("bgFile", pBackdrop->get_background_file()); 00223 pState->set_field_string("edgeFile", pBackdrop->get_edge_file()); 00224 pState->set_field_bool("tile", pBackdrop->is_background_tilling()); 00225 00226 pState->set_field_int("tileSize", pBackdrop->get_tile_size()); 00227 pState->set_field_int("edgeSize", pBackdrop->get_edge_size()); 00228 00229 pState->new_table(); 00230 pState->set_field("insets"); 00231 pState->get_field("insets"); 00232 00233 const std::array<int,4>& lInsets = pBackdrop->get_background_insets(); 00234 pState->set_field_int("left", lInsets[BORDER_LEFT]); 00235 pState->set_field_int("right", lInsets[BORDER_RIGHT]); 00236 pState->set_field_int("top", lInsets[BORDER_TOP]); 00237 pState->set_field_int("bottom", lInsets[BORDER_BOTTOM]); 00238 00239 pState->pop(); 00240 00241 mFunc.notify_pushed(); 00242 } 00243 else 00244 mFunc.push_nil(); 00245 00246 return mFunc.on_return(); 00247 } 00248 00249 int lua_frame::_get_backdrop_border_color(lua_State* pLua) 00250 { 00251 if (!check_parent_()) 00252 return 0; 00253 00254 lua::function mFunc("Frame:get_backdrop_border_color", pLua, 4); 00255 00256 if (pFrameParent_->get_backdrop()) 00257 { 00258 const color& mColor = pFrameParent_->get_backdrop()->get_edge_color(); 00259 mFunc.push(mColor.r); 00260 mFunc.push(mColor.g); 00261 mFunc.push(mColor.b); 00262 mFunc.push(mColor.a); 00263 } 00264 else 00265 mFunc.push_nil(4); 00266 00267 return mFunc.on_return(); 00268 } 00269 00270 int lua_frame::_get_backdrop_color(lua_State* pLua) 00271 { 00272 if (!check_parent_()) 00273 return 0; 00274 00275 lua::function mFunc("Frame:get_backdrop_color", pLua, 4); 00276 00277 if (pFrameParent_->get_backdrop()) 00278 { 00279 const color& mColor = pFrameParent_->get_backdrop()->get_background_color(); 00280 mFunc.push(mColor.r); 00281 mFunc.push(mColor.g); 00282 mFunc.push(mColor.b); 00283 mFunc.push(mColor.a); 00284 } 00285 else 00286 mFunc.push_nil(4); 00287 00288 return mFunc.on_return(); 00289 } 00290 00291 int lua_frame::_get_children(lua_State* pLua) 00292 { 00293 const std::map<uint, frame* >& lChildList = pFrameParent_->get_children(); 00294 if (!check_parent_()) 00295 return 0; 00296 00297 lua::function mFunc("Frame:get_children", pLua, lChildList.size()); 00298 00299 std::map<uint, frame*>::const_iterator iterChild; 00300 foreach (iterChild, lChildList) 00301 { 00302 iterChild->second->push_on_lua(mFunc.get_state()); 00303 mFunc.notify_pushed(); 00304 } 00305 00306 return mFunc.on_return(); 00307 } 00308 00309 int lua_frame::_get_effective_alpha(lua_State* pLua) 00310 { 00311 if (!check_parent_()) 00312 return 0; 00313 00314 lua::function mFunc("Frame:get_effective_alpha", pLua, 1); 00315 00316 mFunc.push(pFrameParent_->get_effective_alpha()); 00317 00318 return mFunc.on_return(); 00319 } 00320 00321 int lua_frame::_get_effective_scale(lua_State* pLua) 00322 { 00323 if (!check_parent_()) 00324 return 0; 00325 00326 lua::function mFunc("Frame:get_effective_scale", pLua, 1); 00327 00328 mFunc.push(pFrameParent_->get_effective_scale()); 00329 00330 return mFunc.on_return(); 00331 } 00332 00333 int lua_frame::_get_frame_level(lua_State* pLua) 00334 { 00335 if (!check_parent_()) 00336 return 0; 00337 00338 lua::function mFunc("Frame:get_frame_level", pLua, 1); 00339 00340 mFunc.push(pFrameParent_->get_frame_level()); 00341 00342 return mFunc.on_return(); 00343 } 00344 00345 int lua_frame::_get_frame_strata(lua_State* pLua) 00346 { 00347 if (!check_parent_()) 00348 return 0; 00349 00350 lua::function mFunc("Frame:get_frame_strata", pLua, 1); 00351 00352 frame_strata mStrata = pFrameParent_->get_frame_strata(); 00353 std::string sStrata; 00354 00355 if (mStrata == STRATA_BACKGROUND) 00356 sStrata = "BACKGROUND"; 00357 else if (mStrata == STRATA_LOW) 00358 sStrata = "LOW"; 00359 else if (mStrata == STRATA_MEDIUM) 00360 sStrata = "MEDIUM"; 00361 else if (mStrata == STRATA_HIGH) 00362 sStrata = "HIGH"; 00363 else if (mStrata == STRATA_DIALOG) 00364 sStrata = "DIALOG"; 00365 else if (mStrata == STRATA_FULLSCREEN) 00366 sStrata = "FULLSCREEN"; 00367 else if (mStrata == STRATA_FULLSCREEN_DIALOG) 00368 sStrata = "FULLSCREEN_DIALOG"; 00369 else if (mStrata == STRATA_TOOLTIP) 00370 sStrata = "TOOLTIP"; 00371 00372 mFunc.push(sStrata); 00373 00374 return mFunc.on_return(); 00375 } 00376 00377 int lua_frame::_get_frame_type(lua_State* pLua) 00378 { 00379 if (!check_parent_()) 00380 return 0; 00381 00382 lua::function mFunc("Frame:get_frame_type", pLua, 1); 00383 00384 mFunc.push(pFrameParent_->get_frame_type()); 00385 00386 return mFunc.on_return(); 00387 } 00388 00389 int lua_frame::_get_hit_rect_insets(lua_State* pLua) 00390 { 00391 if (!check_parent_()) 00392 return 0; 00393 00394 lua::function mFunc("Frame:get_hit_rect_inset", pLua, 4); 00395 00396 const std::array<int,4>& lInsets = pFrameParent_->get_abs_hit_rect_insets(); 00397 00398 for (uint i = 0; i < 4; ++i) 00399 mFunc.push(lInsets[i]); 00400 00401 return mFunc.on_return(); 00402 } 00403 00404 int lua_frame::_get_id(lua_State* pLua) 00405 { 00406 if (!check_parent_()) 00407 return 0; 00408 00409 lua::function mFunc("Frame:get_id", pLua, 1); 00410 00411 mFunc.push(pFrameParent_->get_id()); 00412 00413 return mFunc.on_return(); 00414 } 00415 00416 int lua_frame::_get_max_resize(lua_State* pLua) 00417 { 00418 if (!check_parent_()) 00419 return 0; 00420 00421 lua::function mFunc("Frame:get_max_resize", pLua, 2); 00422 00423 std::array<uint,2> lMax = pFrameParent_->get_max_resize(); 00424 00425 mFunc.push(lMax[0]); 00426 mFunc.push(lMax[1]); 00427 00428 return mFunc.on_return(); 00429 } 00430 00431 int lua_frame::_get_min_resize(lua_State* pLua) 00432 { 00433 if (!check_parent_()) 00434 return 0; 00435 00436 lua::function mFunc("Frame:get_min_resize", pLua, 2); 00437 00438 std::array<uint,2> lMin = pFrameParent_->get_min_resize(); 00439 00440 mFunc.push(lMin[0]); 00441 mFunc.push(lMin[1]); 00442 00443 return mFunc.on_return(); 00444 } 00445 00446 int lua_frame::_get_num_children(lua_State* pLua) 00447 { 00448 if (!check_parent_()) 00449 return 0; 00450 00451 lua::function mFunc("Frame:get_num_children", pLua, 1); 00452 00453 mFunc.push(pFrameParent_->get_num_children()); 00454 00455 return mFunc.on_return(); 00456 } 00457 00458 int lua_frame::_get_num_regions(lua_State* pLua) 00459 { 00460 if (!check_parent_()) 00461 return 0; 00462 00463 lua::function mFunc("Frame:get_num_regions", pLua, 1); 00464 00465 mFunc.push(pFrameParent_->get_num_regions()); 00466 00467 return mFunc.on_return(); 00468 } 00469 00470 int lua_frame::_get_scale(lua_State* pLua) 00471 { 00472 if (!check_parent_()) 00473 return 0; 00474 00475 lua::function mFunc("Frame:get_scale", pLua, 1); 00476 00477 mFunc.push(pFrameParent_->get_scale()); 00478 00479 return mFunc.on_return(); 00480 } 00481 00482 int lua_frame::_get_script(lua_State* pLua) 00483 { 00484 if (!check_parent_()) 00485 return 0; 00486 00487 lua::function mFunc("Frame:get_script", pLua, 1); 00488 mFunc.add(0, "script name", lua::TYPE_STRING); 00489 if (mFunc.check()) 00490 { 00491 std::string sScriptName = mFunc.get(0)->get_string(); 00492 if (pFrameParent_->has_script(sScriptName)) 00493 { 00494 lua_getglobal(pLua, (pFrameParent_->get_name() + ":" + sScriptName).c_str()); 00495 mFunc.notify_pushed(); 00496 } 00497 } 00498 00499 return mFunc.on_return(); 00500 } 00501 00502 int lua_frame::_get_title_region(lua_State* pLua) 00503 { 00504 if (!check_parent_()) 00505 return 0; 00506 00507 lua::function mFunc("Frame:get_title_region", pLua, 1); 00508 00509 if (pFrameParent_->get_title_region()) 00510 { 00511 pFrameParent_->get_title_region()->push_on_lua(mFunc.get_state()); 00512 mFunc.notify_pushed(); 00513 } 00514 else 00515 mFunc.push_nil(); 00516 00517 return mFunc.on_return(); 00518 } 00519 00520 int lua_frame::_has_script(lua_State* pLua) 00521 { 00522 if (!check_parent_()) 00523 return 0; 00524 00525 lua::function mFunc("Frame:has_script", pLua, 1); 00526 mFunc.add(0, "script name", lua::TYPE_STRING); 00527 if (mFunc.check()) 00528 mFunc.push(pFrameParent_->can_use_script(mFunc.get(0)->get_string())); 00529 00530 return mFunc.on_return(); 00531 } 00532 00533 int lua_frame::_is_clamped_to_screen(lua_State* pLua) 00534 { 00535 if (!check_parent_()) 00536 return 0; 00537 00538 lua::function mFunc("Frame:is_clamped_to_screen", pLua, 1); 00539 00540 mFunc.push(pFrameParent_->is_clamped_to_screen()); 00541 00542 return mFunc.on_return(); 00543 } 00544 00545 int lua_frame::_is_frame_type(lua_State* pLua) 00546 { 00547 if (!check_parent_()) 00548 return 0; 00549 00550 lua::function mFunc("Frame:is_frame_type", pLua, 1); 00551 mFunc.add(0, "Frame type", lua::TYPE_STRING); 00552 if (mFunc.check()) 00553 { 00554 if (pFrameParent_->get_frame_type() == mFunc.get(0)->get_string()) 00555 mFunc.push(bool(true)); 00556 else 00557 mFunc.push(bool(false)); 00558 } 00559 00560 return mFunc.on_return(); 00561 } 00562 00563 int lua_frame::_is_keyboard_enabled(lua_State* pLua) 00564 { 00565 if (!check_parent_()) 00566 return 0; 00567 00568 lua::function mFunc("Frame:is_keyboard_enabled", pLua, 1); 00569 00570 mFunc.push(pFrameParent_->is_keyboard_enabled()); 00571 00572 return mFunc.on_return(); 00573 } 00574 00575 int lua_frame::_is_mouse_enabled(lua_State* pLua) 00576 { 00577 if (!check_parent_()) 00578 return 0; 00579 00580 lua::function mFunc("Frame:is_mouse_enabled", pLua, 1); 00581 00582 mFunc.push(pFrameParent_->is_mouse_enabled()); 00583 00584 return mFunc.on_return(); 00585 } 00586 00587 int lua_frame::_is_mouse_wheel_enabled(lua_State* pLua) 00588 { 00589 if (!check_parent_()) 00590 return 0; 00591 00592 lua::function mFunc("Frame:is_mouse_wheel_enabled", pLua, 1); 00593 00594 mFunc.push(pFrameParent_->is_mouse_wheel_enabled()); 00595 00596 return mFunc.on_return(); 00597 } 00598 00599 int lua_frame::_is_movable(lua_State* pLua) 00600 { 00601 if (!check_parent_()) 00602 return 0; 00603 00604 lua::function mFunc("Frame:is_movable", pLua, 1); 00605 00606 mFunc.push(pFrameParent_->is_movable()); 00607 00608 return mFunc.on_return(); 00609 } 00610 00611 int lua_frame::_is_resizable(lua_State* pLua) 00612 { 00613 if (!check_parent_()) 00614 return 0; 00615 00616 lua::function mFunc("Frame:is_resizable", pLua, 1); 00617 00618 mFunc.push(pFrameParent_->is_resizable()); 00619 00620 return mFunc.on_return(); 00621 } 00622 00623 int lua_frame::_is_top_level(lua_State* pLua) 00624 { 00625 if (!check_parent_()) 00626 return 0; 00627 00628 lua::function mFunc("Frame:is_top_level", pLua, 1); 00629 00630 mFunc.push(pFrameParent_->is_top_level()); 00631 00632 return mFunc.on_return(); 00633 } 00634 00635 int lua_frame::_is_user_placed(lua_State* pLua) 00636 { 00637 if (!check_parent_()) 00638 return 0; 00639 00640 lua::function mFunc("Frame:is_user_placed", pLua, 1); 00641 00642 mFunc.push(pFrameParent_->is_user_placed()); 00643 00644 return mFunc.on_return(); 00645 } 00646 00647 int lua_frame::_on(lua_State* pLua) 00648 { 00649 if (!check_parent_()) 00650 return 0; 00651 00652 lua::function mFunc("Frame:on", pLua); 00653 mFunc.add(0, "script", lua::TYPE_STRING); 00654 if (mFunc.check()) 00655 { 00656 std::string sScript = mFunc.get(0)->get_string(); 00657 if (!sScript.empty()) 00658 { 00659 if ('a' <= sScript[0] && sScript[0] <= 'z') 00660 { 00661 sScript[0] = toupper(sScript[0]); 00662 std::string::iterator iter; 00663 foreach (iter, sScript) 00664 { 00665 if (*iter == '_') 00666 { 00667 iter = sScript.erase(iter); 00668 if (iter == sScript.end()) 00669 break; 00670 00671 *iter = toupper(*iter); 00672 } 00673 } 00674 } 00675 00676 pFrameParent_->on(sScript); 00677 } 00678 } 00679 00680 return mFunc.on_return(); 00681 } 00682 00683 int lua_frame::_raise(lua_State* pLua) 00684 { 00685 if (!check_parent_()) 00686 return 0; 00687 00688 lua::function mFunc("Frame:raise", pLua); 00689 00690 pFrameParent_->raise(); 00691 00692 return mFunc.on_return(); 00693 } 00694 00695 int lua_frame::_register_all_events(lua_State* pLua) 00696 { 00697 if (!check_parent_()) 00698 return 0; 00699 00700 lua::function mFunc("Frame:register_all_events", pLua); 00701 00702 pFrameParent_->register_all_events(); 00703 00704 return mFunc.on_return(); 00705 } 00706 00707 int lua_frame::_register_event(lua_State* pLua) 00708 { 00709 if (!check_parent_()) 00710 return 0; 00711 00712 lua::function mFunc("Frame:register_event", pLua); 00713 mFunc.add(0, "event name", lua::TYPE_STRING); 00714 if (mFunc.check()) 00715 pFrameParent_->register_event(mFunc.get(0)->get_string()); 00716 00717 return mFunc.on_return(); 00718 } 00719 00720 int lua_frame::_register_for_drag(lua_State* pLua) 00721 { 00722 if (!check_parent_()) 00723 return 0; 00724 00725 lua::function mFunc("Frame:register_for_drag", pLua); 00726 mFunc.add(0, "button 1", lua::TYPE_STRING, true); 00727 mFunc.add(1, "button 2", lua::TYPE_STRING, true); 00728 mFunc.add(2, "button 3", lua::TYPE_STRING, true); 00729 if (mFunc.check()) 00730 { 00731 std::vector<std::string> lButtonList; 00732 for (uint i = 0; i < 3; ++i) 00733 { 00734 if (mFunc.is_provided(i)) 00735 lButtonList.push_back(mFunc.get(i)->get_string()); 00736 else 00737 break; 00738 } 00739 pFrameParent_->register_for_drag(lButtonList); 00740 } 00741 00742 return mFunc.on_return(); 00743 } 00744 00745 int lua_frame::_set_backdrop(lua_State* pLua) 00746 { 00747 if (!check_parent_()) 00748 return 0; 00749 00750 lua::function mFunc("Frame:set_backdrop", pLua); 00751 mFunc.add(0, "backdrop table", lua::TYPE_TABLE); 00752 mFunc.add(0, "nil", lua::TYPE_NIL); 00753 if (mFunc.check()) 00754 { 00755 if (mFunc.get(0)->get_type() == lua::TYPE_NIL) 00756 { 00757 pFrameParent_->set_backdrop(nullptr); 00758 } 00759 else 00760 { 00761 utils::refptr<backdrop> pBackdrop(new backdrop(pFrameParent_)); 00762 00763 lua::state* pState = mFunc.get_state(); 00764 00765 pBackdrop->set_background(pState->get_field_string("bgFile", false, "")); 00766 pBackdrop->set_edge(pState->get_field_string("edgeFile", false, "")); 00767 pBackdrop->set_backgrond_tilling(pState->get_field_bool("tile", false, false)); 00768 00769 uint uiTileSize = uint(pState->get_field_int("tileSize", false, 0)); 00770 if (uiTileSize != 0) 00771 pBackdrop->set_tile_size(uiTileSize); 00772 00773 uint uiEdgeSize = uint(pState->get_field_int("edgeSize", false, 0)); 00774 if (uiEdgeSize != 0) 00775 pBackdrop->set_edge_size(uiEdgeSize); 00776 00777 pState->get_field("insets"); 00778 00779 if (pState->get_type() == lua::TYPE_TABLE) 00780 { 00781 pBackdrop->set_background_insets({{ 00782 pState->get_field_int("left", false, 0), 00783 pState->get_field_int("right", false, 0), 00784 pState->get_field_int("top", false, 0), 00785 pState->get_field_int("bottom", false, 0) 00786 }}); 00787 } 00788 00789 pFrameParent_->set_backdrop(pBackdrop); 00790 } 00791 } 00792 00793 return mFunc.on_return(); 00794 } 00795 00796 int lua_frame::_set_backdrop_border_color(lua_State* pLua) 00797 { 00798 if (!check_parent_()) 00799 return 0; 00800 00801 lua::function mFunc("Frame:set_backdrop_border_color", pLua); 00802 mFunc.add(0, "red", lua::TYPE_NUMBER); 00803 mFunc.add(1, "green", lua::TYPE_NUMBER); 00804 mFunc.add(2, "blue", lua::TYPE_NUMBER); 00805 mFunc.add(3, "alpha", lua::TYPE_NUMBER, true); 00806 if (mFunc.check()) 00807 { 00808 utils::refptr<backdrop> pBackdrop = pFrameParent_->get_backdrop().lock(); 00809 if (!pBackdrop) 00810 { 00811 pBackdrop = utils::refptr<backdrop>(new backdrop(pFrameParent_)); 00812 pFrameParent_->set_backdrop(pBackdrop); 00813 } 00814 00815 color mColor; 00816 if (mFunc.is_provided(3)) 00817 { 00818 mColor = color( 00819 mFunc.get(0)->get_number(), 00820 mFunc.get(1)->get_number(), 00821 mFunc.get(2)->get_number(), 00822 mFunc.get(3)->get_number() 00823 ); 00824 } 00825 else 00826 { 00827 mColor = color( 00828 mFunc.get(0)->get_number(), 00829 mFunc.get(1)->get_number(), 00830 mFunc.get(2)->get_number() 00831 ); 00832 } 00833 00834 pBackdrop->set_edge_color(mColor); 00835 } 00836 00837 return mFunc.on_return(); 00838 } 00839 00840 int lua_frame::_set_backdrop_color(lua_State* pLua) 00841 { 00842 if (!check_parent_()) 00843 return 0; 00844 00845 lua::function mFunc("Frame:set_backdrop_color", pLua); 00846 mFunc.add(0, "red", lua::TYPE_NUMBER); 00847 mFunc.add(1, "green", lua::TYPE_NUMBER); 00848 mFunc.add(2, "blue", lua::TYPE_NUMBER); 00849 mFunc.add(3, "alpha", lua::TYPE_NUMBER, true); 00850 if (mFunc.check()) 00851 { 00852 utils::refptr<backdrop> pBackdrop = pFrameParent_->get_backdrop().lock(); 00853 if (!pBackdrop) 00854 { 00855 pBackdrop = utils::refptr<backdrop>(new backdrop(pFrameParent_)); 00856 pFrameParent_->set_backdrop(pBackdrop); 00857 } 00858 00859 color mColor; 00860 if (mFunc.is_provided(3)) 00861 { 00862 mColor = color( 00863 mFunc.get(0)->get_number(), 00864 mFunc.get(1)->get_number(), 00865 mFunc.get(2)->get_number(), 00866 mFunc.get(3)->get_number() 00867 ); 00868 } 00869 else 00870 { 00871 mColor = color( 00872 mFunc.get(0)->get_number(), 00873 mFunc.get(1)->get_number(), 00874 mFunc.get(2)->get_number() 00875 ); 00876 } 00877 00878 pBackdrop->set_background_color(mColor); 00879 } 00880 00881 return mFunc.on_return(); 00882 } 00883 00884 00885 int lua_frame::_set_clamped_to_screen(lua_State* pLua) 00886 { 00887 if (!check_parent_()) 00888 return 0; 00889 00890 lua::function mFunc("Frame:set_clamped_to_screen", pLua); 00891 mFunc.add(0, "is clamped to screen", lua::TYPE_BOOLEAN); 00892 if (mFunc.check()) 00893 pFrameParent_->set_clamped_to_screen(mFunc.get(0)->get_bool()); 00894 00895 return mFunc.on_return(); 00896 } 00897 00898 int lua_frame::_set_frame_level(lua_State* pLua) 00899 { 00900 if (!check_parent_()) 00901 return 0; 00902 00903 lua::function mFunc("Frame:set_frame_level", pLua); 00904 mFunc.add(0, "level", lua::TYPE_NUMBER); 00905 if (mFunc.check()) 00906 pFrameParent_->set_level(mFunc.get(0)->get_number()); 00907 00908 return mFunc.on_return(); 00909 } 00910 00911 int lua_frame::_set_frame_strata(lua_State* pLua) 00912 { 00913 if (!check_parent_()) 00914 return 0; 00915 00916 lua::function mFunc("Frame:set_frame_strata", pLua); 00917 mFunc.add(0, "strata", lua::TYPE_STRING); 00918 if (mFunc.check()) 00919 pFrameParent_->set_frame_strata(mFunc.get(0)->get_string()); 00920 00921 return mFunc.on_return(); 00922 } 00923 00924 int lua_frame::_set_hit_rect_insets(lua_State* pLua) 00925 { 00926 if (!check_parent_()) 00927 return 0; 00928 00929 lua::function mFunc("Frame:set_hit_rect_insets", pLua); 00930 mFunc.add(0, "left", lua::TYPE_NUMBER); 00931 mFunc.add(1, "right", lua::TYPE_NUMBER); 00932 mFunc.add(2, "top", lua::TYPE_NUMBER); 00933 mFunc.add(3, "bottom", lua::TYPE_NUMBER); 00934 if (mFunc.check()) 00935 { 00936 pFrameParent_->set_abs_hit_rect_insets( 00937 int(mFunc.get(0)->get_number()), 00938 int(mFunc.get(1)->get_number()), 00939 int(mFunc.get(2)->get_number()), 00940 int(mFunc.get(3)->get_number()) 00941 ); 00942 } 00943 00944 return mFunc.on_return(); 00945 } 00946 00947 int lua_frame::_set_max_resize(lua_State* pLua) 00948 { 00949 if (!check_parent_()) 00950 return 0; 00951 00952 lua::function mFunc("Frame:set_max_resize", pLua); 00953 mFunc.add(0, "width", lua::TYPE_NUMBER); 00954 mFunc.add(1, "height", lua::TYPE_NUMBER); 00955 if (mFunc.check()) 00956 { 00957 pFrameParent_->set_max_resize( 00958 uint(mFunc.get(0)->get_number()), 00959 uint(mFunc.get(1)->get_number()) 00960 ); 00961 } 00962 00963 return mFunc.on_return(); 00964 } 00965 00966 int lua_frame::_set_min_resize(lua_State* pLua) 00967 { 00968 if (!check_parent_()) 00969 return 0; 00970 00971 lua::function mFunc("Frame:set_min_resize", pLua); 00972 mFunc.add(0, "width", lua::TYPE_NUMBER); 00973 mFunc.add(1, "height", lua::TYPE_NUMBER); 00974 if (mFunc.check()) 00975 { 00976 pFrameParent_->set_min_resize( 00977 uint(mFunc.get(0)->get_number()), 00978 uint(mFunc.get(1)->get_number()) 00979 ); 00980 } 00981 00982 return mFunc.on_return(); 00983 } 00984 00985 int lua_frame::_set_max_width(lua_State* pLua) 00986 { 00987 if (!check_parent_()) 00988 return 0; 00989 00990 lua::function mFunc("Frame:set_max_width", pLua); 00991 mFunc.add(0, "width", lua::TYPE_NUMBER); 00992 if (mFunc.check()) 00993 { 00994 pFrameParent_->set_max_width( 00995 uint(mFunc.get(0)->get_number()) 00996 ); 00997 } 00998 00999 return mFunc.on_return(); 01000 } 01001 01002 int lua_frame::_set_max_height(lua_State* pLua) 01003 { 01004 if (!check_parent_()) 01005 return 0; 01006 01007 lua::function mFunc("Frame:set_max_height", pLua); 01008 mFunc.add(0, "height", lua::TYPE_NUMBER); 01009 if (mFunc.check()) 01010 { 01011 pFrameParent_->set_max_height( 01012 uint(mFunc.get(0)->get_number()) 01013 ); 01014 } 01015 01016 return mFunc.on_return(); 01017 } 01018 01019 int lua_frame::_set_min_width(lua_State* pLua) 01020 { 01021 if (!check_parent_()) 01022 return 0; 01023 01024 lua::function mFunc("Frame:set_min_width", pLua); 01025 mFunc.add(0, "width", lua::TYPE_NUMBER); 01026 if (mFunc.check()) 01027 { 01028 pFrameParent_->set_min_width( 01029 uint(mFunc.get(0)->get_number()) 01030 ); 01031 } 01032 01033 return mFunc.on_return(); 01034 } 01035 01036 int lua_frame::_set_min_height(lua_State* pLua) 01037 { 01038 if (!check_parent_()) 01039 return 0; 01040 01041 lua::function mFunc("Frame:set_min_height", pLua); 01042 mFunc.add(0, "height", lua::TYPE_NUMBER); 01043 if (mFunc.check()) 01044 { 01045 pFrameParent_->set_min_height( 01046 uint(mFunc.get(0)->get_number()) 01047 ); 01048 } 01049 01050 return mFunc.on_return(); 01051 } 01052 01053 int lua_frame::_set_movable(lua_State* pLua) 01054 { 01055 if (!check_parent_()) 01056 return 0; 01057 01058 lua::function mFunc("Frame:set_movable", pLua); 01059 mFunc.add(0, "is movable", lua::TYPE_BOOLEAN); 01060 if (mFunc.check()) 01061 pFrameParent_->set_movable(mFunc.get(0)->get_bool()); 01062 01063 return mFunc.on_return(); 01064 } 01065 01066 int lua_frame::_set_resizable(lua_State* pLua) 01067 { 01068 if (!check_parent_()) 01069 return 0; 01070 01071 lua::function mFunc("Frame:set_resizable", pLua); 01072 mFunc.add(0, "is resizable", lua::TYPE_BOOLEAN); 01073 if (mFunc.check()) 01074 pFrameParent_->set_resizable(mFunc.get(0)->get_bool()); 01075 01076 return mFunc.on_return(); 01077 } 01078 01079 int lua_frame::_set_scale(lua_State* pLua) 01080 { 01081 if (!check_parent_()) 01082 return 0; 01083 01084 lua::function mFunc("Frame:set_scale", pLua); 01085 mFunc.add(0, "scale", lua::TYPE_NUMBER); 01086 if (mFunc.check()) 01087 pFrameParent_->set_scale(mFunc.get(0)->get_number()); 01088 01089 return mFunc.on_return(); 01090 } 01091 01092 int lua_frame::_set_script(lua_State* pLua) 01093 { 01094 if (!check_parent_()) 01095 return 0; 01096 01097 lua::function mFunc("Frame:set_script", pLua); 01098 mFunc.add(0, "script name", lua::TYPE_STRING); 01099 mFunc.add(1, "function", lua::TYPE_FUNCTION, true); 01100 mFunc.add(1, "nil", lua::TYPE_NIL, true); 01101 if (mFunc.check()) 01102 { 01103 std::string sScriptName = mFunc.get(0)->get_string(); 01104 if (pFrameParent_->can_use_script(sScriptName)) 01105 { 01106 lua::state* pLua = mFunc.get_state(); 01107 utils::wptr<lua::argument> pArg = mFunc.get(1); 01108 if (pArg->is_provided() && pArg->get_type() == lua::TYPE_FUNCTION) 01109 { 01110 pLua->push_value(pArg->get_index()); 01111 pLua->set_global(pFrameParent_->get_name() + ":" + sScriptName); 01112 pFrameParent_->notify_script_defined(sScriptName, true); 01113 } 01114 else 01115 { 01116 pLua->push_nil(); 01117 pLua->set_global(pFrameParent_->get_name() + ":" + sScriptName); 01118 pFrameParent_->notify_script_defined(sScriptName, false); 01119 } 01120 } 01121 else 01122 { 01123 gui::out << gui::error << pFrameParent_->get_frame_type() << " : " 01124 << "\"" << pFrameParent_->get_name() << "\" can't use script \"" << sScriptName << "\"." << std::endl; 01125 } 01126 } 01127 01128 return mFunc.on_return(); 01129 } 01130 01131 int lua_frame::_set_top_level(lua_State* pLua) 01132 { 01133 if (!check_parent_()) 01134 return 0; 01135 01136 lua::function mFunc("Frame:set_top_level", pLua); 01137 mFunc.add(0, "is top level", lua::TYPE_BOOLEAN); 01138 if (mFunc.check()) 01139 pFrameParent_->set_top_level(mFunc.get(0)->get_bool()); 01140 01141 return mFunc.on_return(); 01142 } 01143 01144 int lua_frame::_set_user_placed(lua_State* pLua) 01145 { 01146 if (!check_parent_()) 01147 return 0; 01148 01149 lua::function mFunc("Frame:set_user_placed", pLua); 01150 mFunc.add(0, "is user placed", lua::TYPE_BOOLEAN); 01151 if (mFunc.check()) 01152 pFrameParent_->set_user_placed(mFunc.get(0)->get_bool()); 01153 01154 return mFunc.on_return(); 01155 } 01156 01157 int lua_frame::_start_moving(lua_State* pLua) 01158 { 01159 if (!check_parent_()) 01160 return 0; 01161 01162 lua::function mFunc("Frame:start_moving", pLua); 01163 01164 pFrameParent_->start_moving(); 01165 01166 return mFunc.on_return(); 01167 } 01168 01169 int lua_frame::_start_sizing(lua_State* pLua) 01170 { 01171 if (!check_parent_()) 01172 return 0; 01173 01174 lua::function mFunc("Frame:start_sizing", pLua); 01175 mFunc.add(0, "point", lua::TYPE_STRING); 01176 if (mFunc.check()) 01177 pFrameParent_->start_sizing(anchor::get_anchor_point(mFunc.get(0)->get_string())); 01178 01179 return mFunc.on_return(); 01180 } 01181 01182 int lua_frame::_stop_moving_or_sizing(lua_State* pLua) 01183 { 01184 if (!check_parent_()) 01185 return 0; 01186 01187 lua::function mFunc("Frame:stop_moving_or_sizing", pLua); 01188 01189 pFrameParent_->stop_moving(); 01190 pFrameParent_->stop_sizing(); 01191 01192 return mFunc.on_return(); 01193 } 01194 01195 int lua_frame::_unregister_all_events(lua_State* pLua) 01196 { 01197 if (!check_parent_()) 01198 return 0; 01199 01200 lua::function mFunc("Frame:unregister_all_events", pLua); 01201 01202 pFrameParent_->unregister_all_events(); 01203 01204 return mFunc.on_return(); 01205 } 01206 01207 int lua_frame::_unregister_event(lua_State* pLua) 01208 { 01209 if (!check_parent_()) 01210 return 0; 01211 01212 lua::function mFunc("Frame:unregister_event", pLua); 01213 mFunc.add(0, "event name", lua::TYPE_STRING); 01214 if (mFunc.check()) 01215 pFrameParent_->unregister_event(mFunc.get(0)->get_string()); 01216 01217 return mFunc.on_return(); 01218 } 01219 }