00001 #include "gui_layeredregion.hpp" 00002 00003 #include "gui_uiobject.hpp" 00004 #include "gui_frame.hpp" 00005 #include "gui_manager.hpp" 00006 #include "gui_out.hpp" 00007 00008 #include <sstream> 00009 00010 namespace gui 00011 { 00012 layered_region::layered_region(manager* pManager) : region(pManager), 00013 mLayer_(LAYER_ARTWORK), pFrameParent_(nullptr) 00014 { 00015 lType_.push_back("LayeredRegion"); 00016 } 00017 00018 layered_region::~layered_region() 00019 { 00020 } 00021 00022 std::string layered_region::serialize(const std::string& sTab) const 00023 { 00024 std::ostringstream sStr; 00025 sStr << region::serialize(sTab); 00026 00027 sStr << sTab << " # Layer : "; 00028 switch (mLayer_) 00029 { 00030 case LAYER_BACKGROUND : sStr << "BACKGROUND\n"; break; 00031 case LAYER_BORDER : sStr << "BORDER\n"; break; 00032 case LAYER_ARTWORK : sStr << "ARTWORK\n"; break; 00033 case LAYER_OVERLAY : sStr << "OVERLAY\n"; break; 00034 case LAYER_HIGHLIGHT : sStr << "HIGHLIGHT\n"; break; 00035 case LAYER_SPECIALHIGH : sStr << "SPECIALHIGH\n"; break; 00036 default : sStr << "<error>\n"; break; 00037 }; 00038 00039 return sStr.str(); 00040 } 00041 00042 void layered_region::create_glue() 00043 { 00044 utils::wptr<lua::state> pLua = pManager_->get_lua(); 00045 pLua->push_string(sName_); 00046 lGlueList_.push_back(pLua->push_new<lua_layered_region>()); 00047 pLua->set_global(sName_); 00048 pLua->pop(); 00049 } 00050 00051 void layered_region::set_parent(uiobject* pParent) 00052 { 00053 pFrameParent_ = dynamic_cast<frame*>(pParent); 00054 uiobject::set_parent(pParent); 00055 } 00056 00057 void layered_region::show() 00058 { 00059 if (!bIsShown_) 00060 { 00061 bIsShown_ = true; 00062 notify_renderer_need_redraw(); 00063 } 00064 } 00065 00066 void layered_region::hide() 00067 { 00068 if (bIsShown_) 00069 { 00070 bIsShown_ = false; 00071 notify_renderer_need_redraw(); 00072 } 00073 } 00074 00075 bool layered_region::is_visible() const 00076 { 00077 return pParent_->is_visible() && bIsShown_; 00078 } 00079 00080 layer_type layered_region::get_draw_layer() 00081 { 00082 return mLayer_; 00083 } 00084 00085 void layered_region::set_draw_layer(layer_type mLayer) 00086 { 00087 if (mLayer_ != mLayer) 00088 { 00089 mLayer_ = mLayer; 00090 notify_renderer_need_redraw(); 00091 pFrameParent_->fire_build_layer_list(); 00092 } 00093 } 00094 00095 void layered_region::set_draw_layer(const std::string& sLayer) 00096 { 00097 layer_type mLayer; 00098 if (sLayer == "ARTWORK") 00099 mLayer = LAYER_ARTWORK; 00100 else if (sLayer == "BACKGROUND") 00101 mLayer = LAYER_BACKGROUND; 00102 else if (sLayer == "BORDER") 00103 mLayer = LAYER_BORDER; 00104 else if (sLayer == "HIGHLIGHT") 00105 mLayer = LAYER_HIGHLIGHT; 00106 else if (sLayer == "OVERLAY") 00107 mLayer = LAYER_OVERLAY; 00108 else 00109 { 00110 gui::out << gui::warning << "gui::" << lType_.back() << " : " 00111 << "Uknown layer type : \"" << sLayer << "\". Using \"ARTWORK\"." << std::endl; 00112 00113 mLayer = LAYER_ARTWORK; 00114 } 00115 00116 if (mLayer_ != mLayer) 00117 { 00118 mLayer_ = mLayer; 00119 notify_renderer_need_redraw(); 00120 pFrameParent_->fire_build_layer_list(); 00121 } 00122 } 00123 00124 void layered_region::notify_renderer_need_redraw() const 00125 { 00126 if (!bVirtual_) 00127 { 00128 if (pRenderer_) 00129 pRenderer_->fire_redraw(); 00130 else if (pFrameParent_) 00131 pFrameParent_->notify_renderer_need_redraw(); 00132 } 00133 } 00134 }