Merge branch 'hotfix-1.6.2' into develop-1.7

This commit is contained in:
Jinhao
2018-12-07 06:54:42 +08:00
12 changed files with 253 additions and 166 deletions

View File

@@ -379,7 +379,12 @@ namespace nana{ namespace drawerbase
void trigger::icon(const nana::paint::image& img)
{
if(img.empty()) return;
if(img.empty())
{
delete attr_.icon;
attr_.icon = nullptr;
return;
}
if(nullptr == attr_.icon)
attr_.icon = new paint::image;

View File

@@ -24,6 +24,7 @@ namespace nana{ namespace drawerbase
struct drawer::implement
{
widget * widget_ptr;
scheme * scheme_ptr;
bool react;
bool radio;
facade<element::crook> crook;
@@ -47,6 +48,7 @@ namespace nana{ namespace drawerbase
void drawer::attached(widget_reference widget, graph_reference)
{
impl_->widget_ptr = &widget;
impl_->scheme_ptr =static_cast<scheme*>(API::dev::get_scheme(widget));
API::dev::enable_space_click(widget, true);
}
@@ -78,12 +80,14 @@ namespace nana{ namespace drawerbase
}
//draw crook
#ifdef _nana_std_has_string_view
auto txt_px = graph.text_extent_size(std::wstring_view( L"jN", 2 )).height + 2;
#else
auto txt_px = graph.text_extent_size(L"jN", 2).height + 2;
#endif
impl_->crook.draw(graph, wdg->bgcolor(), wdg->fgcolor(), rectangle(0, txt_px > 16 ? (txt_px - 16) / 2 : 0, 16, 16), API::element_state(*wdg));
unsigned txt_px = 0, descent = 0, ileading = 0;
graph.text_metrics(txt_px, descent, ileading);
txt_px += (descent + 2);
impl_->crook.draw(graph,
impl_->scheme_ptr->square_bgcolor.get(wdg->bgcolor()), impl_->scheme_ptr->square_border_color.get(wdg->fgcolor()),
rectangle(0, txt_px > 16 ? (txt_px - 16) / 2 : 0, 16, 16), API::element_state(*wdg));
}
void drawer::mouse_down(graph_reference graph, const arg_mouse&)

View File

@@ -33,21 +33,16 @@ namespace nana
//end struct metrics_type
//class drawer
drawer::drawer(metrics_type& m)
:metrics_(m)
drawer::drawer(bool vert) :
vert(vert)
{}
void drawer::set_vertical(bool v)
{
vertical_ = v;
}
buttons drawer::what(graph_reference graph, const point& screen_pos)
{
unsigned scale;
int pos;
if(vertical_)
if(vert)
{
scale = graph.height();
pos = screen_pos.y;
@@ -64,15 +59,15 @@ namespace nana
if (pos > static_cast<int>(scale) - bound_pos)
return buttons::second;
if(metrics_.scroll_length)
if(metrics.scroll_length)
{
if(metrics_.scroll_pos + static_cast<int>(fixedsize) <= pos && pos < metrics_.scroll_pos + static_cast<int>(fixedsize + metrics_.scroll_length))
if(metrics.scroll_pos + static_cast<int>(fixedsize) <= pos && pos < metrics.scroll_pos + static_cast<int>(fixedsize + metrics.scroll_length))
return buttons::scroll;
}
if(static_cast<int>(fixedsize) <= pos && pos < metrics_.scroll_pos)
if(static_cast<int>(fixedsize) <= pos && pos < metrics.scroll_pos)
return buttons::forward;
else if(metrics_.scroll_pos + static_cast<int>(metrics_.scroll_length) <= pos && pos < static_cast<int>(scale - fixedsize))
else if(metrics.scroll_pos + static_cast<int>(metrics.scroll_length) <= pos && pos < static_cast<int>(scale - fixedsize))
return buttons::backward;
return buttons::none;
@@ -80,39 +75,39 @@ namespace nana
void drawer::scroll_delta_pos(graph_reference graph, int mouse_pos)
{
if(mouse_pos + metrics_.scroll_mouse_offset == metrics_.scroll_pos) return;
if(mouse_pos + metrics.scroll_mouse_offset == metrics.scroll_pos) return;
unsigned scale = vertical_ ? graph.height() : graph.width();
unsigned scale = vert ? graph.height() : graph.width();
if(scale > fixedsize * 2)
{
int pos = mouse_pos - metrics_.scroll_mouse_offset;
const unsigned scroll_area = static_cast<unsigned>(scale - fixedsize * 2 - metrics_.scroll_length);
int pos = mouse_pos - metrics.scroll_mouse_offset;
const unsigned scroll_area = static_cast<unsigned>(scale - fixedsize * 2 - metrics.scroll_length);
if(pos < 0)
pos = 0;
else if(pos > static_cast<int>(scroll_area))
pos = static_cast<int>(scroll_area);
metrics_.scroll_pos = pos;
auto value_max = metrics_.peak - metrics_.range;
metrics.scroll_pos = pos;
auto value_max = metrics.peak - metrics.range;
//Check scroll_area to avoiding division by zero.
if (scroll_area)
metrics_.value = static_cast<std::size_t>(pos * (static_cast<double>(value_max) / scroll_area)); //converting to double to avoid overflow.
metrics.value = static_cast<std::size_t>(pos * (static_cast<double>(value_max) / scroll_area)); //converting to double to avoid overflow.
if (metrics_.value < value_max)
if (metrics.value < value_max)
{
//converting to double to avoid overflow.
auto const px_per_value = static_cast<double>(scroll_area) / value_max;
int selfpos = static_cast<int>(metrics_.value * px_per_value);
int nextpos = static_cast<int>((metrics_.value + 1) * px_per_value);
int selfpos = static_cast<int>(metrics.value * px_per_value);
int nextpos = static_cast<int>((metrics.value + 1) * px_per_value);
if(selfpos != nextpos && (pos - selfpos > nextpos - pos))
++metrics_.value;
++metrics.value;
}
else
metrics_.value = value_max;
metrics.value = value_max;
}
}
@@ -121,46 +116,46 @@ namespace nana
if (!_m_check())
return;
if(buttons::forward == metrics_.what)
if(buttons::forward == metrics.what)
{ //backward
if(metrics_.value <= metrics_.range)
metrics_.value = 0;
if(metrics.value <= metrics.range)
metrics.value = 0;
else
metrics_.value -= (metrics_.range-1);
metrics.value -= (metrics.range-1);
}
else if(buttons::backward == metrics_.what)
else if(buttons::backward == metrics.what)
{
if(metrics_.peak - metrics_.range - metrics_.value <= metrics_.range)
metrics_.value = metrics_.peak - metrics_.range;
if(metrics.peak - metrics.range - metrics.value <= metrics.range)
metrics.value = metrics.peak - metrics.range;
else
metrics_.value += (metrics_.range-1);
metrics.value += (metrics.range-1);
}
}
void drawer::draw(graph_reference graph, buttons what)
void drawer::draw(graph_reference graph)
{
if(false == metrics_.pressed || metrics_.what != buttons::scroll)
if(false == metrics.pressed || metrics.what != buttons::scroll)
_m_adjust_scroll(graph);
_m_background(graph);
rectangle_rotator r(vertical_, ::nana::rectangle{ graph.size() });
rectangle_rotator r(vert, ::nana::rectangle{ graph.size() });
r.x_ref() = static_cast<int>(r.w() - fixedsize);
r.w_ref() = fixedsize;
int state = ((_m_check() == false || what == buttons::none) ? states::none : states::highlight);
int moused_state = (_m_check() ? (metrics_.pressed ? states::selected : states::actived) : states::none);
auto state = ((_m_check() == false || metrics.what == buttons::none) ? states::none : states::highlight);
auto moused_state = (_m_check() ? (metrics.pressed ? states::selected : states::actived) : states::none);
auto result = r.result();
//draw first
_m_draw_button(graph, { 0, 0, result.width, result.height }, buttons::first, (buttons::first == what ? moused_state : state));
_m_draw_button(graph, { 0, 0, result.width, result.height }, buttons::first, (buttons::first == metrics.what ? moused_state : state));
//draw second
_m_draw_button(graph, result, buttons::second, (buttons::second == what ? moused_state : state));
_m_draw_button(graph, result, buttons::second, (buttons::second == metrics.what ? moused_state : state));
//draw scroll
_m_draw_scroll(graph, (buttons::scroll == what ? moused_state : states::highlight));
_m_draw_scroll(graph, (buttons::scroll == metrics.what ? moused_state : states::highlight));
}
//private:
@@ -168,19 +163,19 @@ namespace nana
{
graph.rectangle(true, {0xf0, 0xf0, 0xf0});
if (!metrics_.pressed || !_m_check())
if (!metrics.pressed || !_m_check())
return;
nana::rectangle_rotator r(vertical_, ::nana::rectangle{ graph.size() });
if(metrics_.what == buttons::forward)
nana::rectangle_rotator r(vert, ::nana::rectangle{ graph.size() });
if(metrics.what == buttons::forward)
{
r.x_ref() = static_cast<int>(fixedsize);
r.w_ref() = metrics_.scroll_pos;
r.w_ref() = metrics.scroll_pos;
}
else if(buttons::backward == metrics_.what)
else if(buttons::backward == metrics.what)
{
r.x_ref() = static_cast<int>(fixedsize + metrics_.scroll_pos + metrics_.scroll_length);
r.w_ref() = static_cast<unsigned>((vertical_ ? graph.height() : graph.width()) - (fixedsize * 2 + metrics_.scroll_pos + metrics_.scroll_length));
r.x_ref() = static_cast<int>(fixedsize + metrics.scroll_pos + metrics.scroll_length);
r.w_ref() = static_cast<unsigned>((vert ? graph.height() : graph.width()) - (fixedsize * 2 + metrics.scroll_pos + metrics.scroll_length));
}
else
return;
@@ -190,9 +185,9 @@ namespace nana
graph.rectangle(result, true, static_cast<color_rgb>(0xDCDCDC));
}
void drawer::_m_button_frame(graph_reference graph, rectangle r, int state)
void drawer::_m_button_frame(graph_reference graph, rectangle r, states state)
{
if (!state)
if (states::none == state)
return;
::nana::color clr{0x97, 0x97, 0x97}; //highlight
@@ -210,7 +205,7 @@ namespace nana
graph.palette(false, clr);
r.pare_off(2);
if(vertical_)
if(vert)
{
unsigned half = r.width / 2;
graph.rectangle({ r.x + static_cast<int>(r.width - half), r.y, half, r.height }, true);
@@ -222,19 +217,19 @@ namespace nana
graph.rectangle({r.x, r.y + static_cast<int>(r.height - half), r.width, half}, true);
r.height -= half;
}
graph.gradual_rectangle(r, colors::white, clr, !vertical_);
graph.gradual_rectangle(r, colors::white, clr, !vert);
}
bool drawer::_m_check() const
{
return (metrics_.scroll_length && metrics_.range && (metrics_.peak > metrics_.range));
return (metrics.scroll_length && metrics.range && (metrics.peak > metrics.range));
}
void drawer::_m_adjust_scroll(graph_reference graph)
{
if(metrics_.range == 0 || metrics_.peak <= metrics_.range) return;
if(metrics.range == 0 || metrics.peak <= metrics.range) return;
unsigned pixels = vertical_ ? graph.height() : graph.width();
unsigned pixels = vert ? graph.height() : graph.width();
int pos = 0;
unsigned len = 0;
@@ -242,38 +237,38 @@ namespace nana
if(pixels > fixedsize * 2)
{
pixels -= (fixedsize * 2);
len = static_cast<unsigned>(pixels * metrics_.range / metrics_.peak);
len = static_cast<unsigned>(pixels * metrics.range / metrics.peak);
if(len < fixedsize)
len = fixedsize;
if(metrics_.value)
if(metrics.value)
{
pos = static_cast<int>(pixels - len);
if(metrics_.value + metrics_.range >= metrics_.peak)
metrics_.value = metrics_.peak - metrics_.range;
if(metrics.value + metrics.range >= metrics.peak)
metrics.value = metrics.peak - metrics.range;
else
pos = static_cast<int>((metrics_.value * pos) /(metrics_.peak - metrics_.range));
pos = static_cast<int>((metrics.value * pos) /(metrics.peak - metrics.range));
}
}
metrics_.scroll_pos = pos;
metrics_.scroll_length = len;
metrics.scroll_pos = pos;
metrics.scroll_length = len;
}
void drawer::_m_draw_scroll(graph_reference graph, int state)
void drawer::_m_draw_scroll(graph_reference graph, states state)
{
if(_m_check())
{
rectangle_rotator r(vertical_, rectangle{ graph.size() });
r.x_ref() = static_cast<int>(fixedsize + metrics_.scroll_pos);
r.w_ref() = static_cast<unsigned>(metrics_.scroll_length);
rectangle_rotator r(vert, rectangle{ graph.size() });
r.x_ref() = static_cast<int>(fixedsize + metrics.scroll_pos);
r.w_ref() = static_cast<unsigned>(metrics.scroll_length);
_m_button_frame(graph, r.result(), state);
}
}
void drawer::_m_draw_button(graph_reference graph, rectangle r, buttons what, int state)
void drawer::_m_draw_button(graph_reference graph, rectangle r, buttons what, states state)
{
if(_m_check())
_m_button_frame(graph, r, state);
@@ -287,7 +282,7 @@ namespace nana
direction dir;
if (buttons::second == what)
{
if (vertical_)
if (vert)
{
r.y = top;
dir = direction::south;
@@ -299,9 +294,9 @@ namespace nana
}
}
else
dir = vertical_ ? direction::north : direction::west;
dir = vert ? direction::north : direction::west;
if (vertical_)
if (vert)
r.x = left / 2;
else
r.y = top / 2;

View File

@@ -230,7 +230,6 @@ namespace nana {
{
cv_scroll->vert.create(window_handle);
cv_scroll->vert.events().value_changed.connect_unignorable(event_fn);
API::take_active(cv_scroll->vert, false, window_handle);
this->passive = false;
}
@@ -261,7 +260,6 @@ namespace nana {
{
cv_scroll->horz.create(window_handle);
cv_scroll->horz.events().value_changed.connect_unignorable(event_fn);
API::take_active(cv_scroll->horz, false, window_handle);
this->passive = false;
}

View File

@@ -492,9 +492,17 @@ namespace nana
return (trace_.what != trace_.null);
}
bool active_by_trace()
bool active_by_trace(const arg_mouse& arg)
{
return ((trace_.what == trace_.item) && (trace_.item_part != trace_.close)? activate(trace_.u.index) : false);
if((trace_.what == trace_.item) && (trace_.item_part != trace_.close))
{
if(false == evt_agent_->click(arg, trace_.u.index))
return activate(trace_.u.index);
return true;
}
return false;
}
bool release()
@@ -1285,7 +1293,7 @@ namespace nana
{
if(layouter_->press())
{
if(false == layouter_->active_by_trace())
if(false == layouter_->active_by_trace(arg))
layouter_->toolbox_answer(arg);
layouter_->render();
API::dev::lazy_refresh();