Merge branch 'feature-draw-through' into develop

This commit is contained in:
cnjinhao
2015-02-02 19:17:44 +08:00
10 changed files with 101 additions and 10 deletions

View File

@@ -292,6 +292,13 @@ namespace nana
return false;
}
bool basic_window::is_draw_through() const
{
if (::nana::category::flags::root == this->other.category)
return static_cast<bool>(other.attribute.root->draw_through);
return false;
}
void basic_window::_m_init_pos_and_size(basic_window* parent, const rectangle& r)
{
pos_owner = pos_root = r;

View File

@@ -1286,6 +1286,15 @@ namespace detail
brock.event_move(msgwnd, (int)(short) LOWORD(lParam), (int)(short) HIWORD(lParam));
break;
case WM_PAINT:
if (msgwnd->is_draw_through())
{
msgwnd->other.attribute.root->draw_through();
::PAINTSTRUCT ps;
::BeginPaint(root_window, &ps);
::EndPaint(root_window, &ps);
}
else
{
::PAINTSTRUCT ps;
::HDC dc = ::BeginPaint(root_window, &ps);
@@ -1602,6 +1611,26 @@ namespace detail
return impl_->estore;
}
void bedrock::map_through_widgets(core_window_t* wd, native_drawable_type drawable)
{
#if defined(NANA_WINDOWS)
auto graph_context = reinterpret_cast<HDC>(wd->root_graph->handle()->context);
for (auto child : wd->children)
{
if (!child->visible) continue;
if (::nana::category::flags::widget == child->other.category)
{
::BitBlt(reinterpret_cast<HDC>(drawable), child->pos_root.x, child->pos_root.y, static_cast<int>(child->dimension.width), static_cast<int>(child->dimension.height),
graph_context, child->pos_root.x, child->pos_root.y, SRCCOPY);
}
else if (::nana::category::flags::lite_widget == child->other.category)
map_through_widgets(child, drawable);
}
#endif
}
bool bedrock::emit(event_code evt_code, core_window_t* wd, const arg_mouse& arg, bool ask_update, thread_context* thrd)
{
if (evt_code != arg.evt_code)

View File

@@ -675,7 +675,7 @@ namespace detail
{
//Thread-Safe Required!
std::lock_guard<decltype(mutex_)> lock(mutex_);
if (impl_->wd_register.available(wd))
if (impl_->wd_register.available(wd) && !wd->is_draw_through())
{
//Copy the root buffer that wd specified into DeviceContext
#if defined(NANA_LINUX)
@@ -739,7 +739,7 @@ namespace detail
if (false == impl_->wd_register.available(wd))
return false;
if(wd->visible)
if(wd->visible && (!wd->is_draw_through()))
{
if (wd->visible_parents())
{

View File

@@ -20,19 +20,27 @@ namespace nana
//@brief: This name is only visible for this compiling-unit
namespace restrict
{
typedef detail::bedrock::core_window_t core_window_t;
extern detail::bedrock& bedrock;
inline detail::drawer& get_drawer(window wd)
namespace
{
return reinterpret_cast<core_window_t*>(wd)->drawer;
using core_window_t = detail::bedrock::core_window_t;
inline detail::drawer& get_drawer(window wd)
{
return reinterpret_cast<core_window_t*>(wd)->drawer;
}
}
}
//class drawing
drawing::drawing(window wd)
:handle_(wd)
{}
{
if (!API::is_window(wd))
throw std::invalid_argument("drawing: invalid window parameter");
if (reinterpret_cast<restrict::core_window_t*>(wd)->is_draw_through())
throw std::invalid_argument("drawing: the window is draw_through enabled");
}
drawing::~drawing(){} //Just for polymorphism

View File

@@ -354,6 +354,11 @@ namespace API
return (restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd)) == false);
}
bool is_window(window wd)
{
return restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd));
}
void enable_dropfiles(window wd, bool enb)
{
internal_scope_guard lock;
@@ -569,6 +574,27 @@ namespace API
return false;
}
void draw_through(window wd, std::function<void()> draw_fn)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if (!restrict::bedrock.wd_manager.available(iwd))
throw std::invalid_argument("draw_through: invalid window parameter");
if (::nana::category::flags::root != iwd->other.category)
throw std::invalid_argument("draw_through: the window is not a root widget");
iwd->other.attribute.root->draw_through.swap(draw_fn);
}
void map_through_widgets(window wd, native_drawable_type drawable)
{
auto iwd = reinterpret_cast<::nana::detail::basic_window*>(wd);
internal_scope_guard lock;
if (restrict::bedrock.wd_manager.available(iwd) && iwd->is_draw_through() )
restrict::bedrock.map_through_widgets(iwd, drawable);
}
nana::size window_size(window wd)
{
nana::rectangle r;