void trigger::_m_draw_box(graph_reference graph) { rectangle r{ graph.size() }; graph.gradual_rectangle(r, colors::button_face_shadow_end, colors::button_face_shadow_start, true); ::nana::color lt{ colors::gray }, rb{colors::white}; graph.frame_rectangle(r, lt, lt, rb, rb); }
void drawer::attached(graph_reference graph) { window wd = widget_->handle(); editor_ = new text_editor(wd, graph); editor_->textbase().bind_ext_evtbase(extra_evtbase); editor_->border_renderer(nana::make_fun(*this, &drawer::_m_draw_border)); _m_text_area(graph.width(), graph.height()); using namespace API::dev; make_drawer_event<events::focus>(wd); make_drawer_event<events::key_char>(wd); make_drawer_event<events::key_down>(wd); make_drawer_event<events::mouse_down>(wd); make_drawer_event<events::mouse_up>(wd); make_drawer_event<events::mouse_move>(wd); make_drawer_event<events::mouse_wheel>(wd); make_drawer_event<events::mouse_enter>(wd); make_drawer_event<events::mouse_leave>(wd); API::tabstop(wd); API::eat_tabstop(wd, true); API::effects_edge_nimbus(wd, effects::edge_nimbus::active); API::effects_edge_nimbus(wd, effects::edge_nimbus::over); }
void solid_triangle(graph_reference graph, int x, int y, nana::color_t color, uint32_t dir) { x += 3; y += 3; switch(dir) { case directions::to_east: for(int i = 0; i < 5; ++i) graph.line(x + 3 + i, y + 1 + i, x + 3 + i, y + 9 - i, color); break; case directions::to_southeast: for(int i = 0; i < 6; ++i) graph.line(x + 2 + i, y + 7 - i, x + 7, y + 7 - i, color); break; case directions::to_south: y += 3; for(int i = 0; i < 5; ++i) graph.line(x + i, y + i, x + 8 - i, y + i, color); break; case directions::to_west: x += 5; y += 1; for(int i = 0; i < 5; ++i) graph.line(x - i, y + i, x - i, y + 8 - i, color); break; case directions::to_north: y += 7; for(int i = 0; i < 5; ++i) graph.line(x + i, y - i, x + 8 - i, y - i, color); break; } }
void drawer::scroll_delta_pos(graph_reference graph, int mouse_pos) { if(mouse_pos + metrics_.scroll_mouse_offset == metrics_.scroll_pos) return; unsigned scale = vertical_ ? 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); 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; //Check scroll_area to avoiding division by zero. if (scroll_area) metrics_.value = pos * value_max / scroll_area; if(metrics_.value < value_max) { int selfpos = static_cast<int>(metrics_.value * scroll_area / value_max); int nextpos = static_cast<int>((metrics_.value + 1) * scroll_area / value_max); if(selfpos != nextpos && (pos - selfpos > nextpos - pos)) ++metrics_.value; } else metrics_.value = value_max; } }
void drawer::_m_adjust_scroll(graph_reference graph) { if(metrics_.range == 0 || metrics_.peak <= metrics_.range) return; unsigned pixels = vertical_ ? graph.height() : graph.width(); int pos = 0; unsigned len = 0; if(pixels > fixedsize * 2) { pixels -= (fixedsize * 2); len = static_cast<unsigned>(pixels * metrics_.range / metrics_.peak); if(len < fixedsize) len = fixedsize; if(metrics_.value) { pos = static_cast<int>(pixels - len); 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)); } } metrics_.scroll_pos = pos; metrics_.scroll_length = len; }
buttons drawer::what(graph_reference graph, const point& screen_pos) { unsigned scale; int pos; if(vertical_) { scale = graph.height(); pos = screen_pos.y; } else { scale = graph.width(); pos = screen_pos.x; } const auto bound_pos = static_cast<int>(scale >= fixedsize * 2 ? fixedsize : scale / 2); if (pos < bound_pos) return buttons::first; if (pos > static_cast<int>(scale) - bound_pos) return buttons::second; if(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) return buttons::forward; else if(metrics_.scroll_pos + static_cast<int>(metrics_.scroll_length) <= pos && pos < static_cast<int>(scale - fixedsize)) return buttons::backward; return buttons::none; }
void drawer::_m_button_frame(graph_reference graph, rectangle r, int state) { if (!state) return; ::nana::color clr{0x97, 0x97, 0x97}; //highlight switch(state) { case states::actived: clr.from_rgb(0x86, 0xD5, 0xFD); break; case states::selected: clr.from_rgb(0x3C, 0x7F, 0xB1); break; } graph.rectangle(r, false, clr); clr = clr.blend(colors::white, 0.5); graph.palette(false, clr); r.pare_off(2); if(vertical_) { unsigned half = r.width / 2; graph.rectangle({ r.x + static_cast<int>(r.width - half), r.y, half, r.height }, true); r.width -= half; } else { unsigned half = r.height / 2; 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_); }
//private: void drawer::_m_background(graph_reference graph) { graph.rectangle(true, {0xf0, 0xf0, 0xf0}); if (!metrics_.pressed || !_m_check()) return; nana::rectangle_rotator r(vertical_, ::nana::rectangle{ graph.size() }); if(metrics_.what == buttons::forward) { r.x_ref() = static_cast<int>(fixedsize); r.w_ref() = metrics_.scroll_pos; } 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)); } else return; auto result = r.result(); if (!result.empty()) graph.rectangle(result, true, static_cast<color_rgb>(0xDCDCDC)); }
void image_ico::paste(const nana::rectangle& src_r, graph_reference graph, int x, int y) const { if(ptr_ && (graph.empty() == false)) { #if defined(NANA_WINDOWS) ::DrawIconEx(graph.handle()->context, x, y, *ptr_, src_r.width, src_r.height, 0, 0, DI_NORMAL); #endif } }
void image_ico::stretch(const nana::rectangle&, graph_reference graph, const nana::rectangle& r) const { if(ptr_ && (graph.empty() == false)) { #if defined(NANA_WINDOWS) ::DrawIconEx(graph.handle()->context, r.x, r.y, *ptr_, r.width, r.height, 0, 0, DI_NORMAL); #endif } }
void drawer::_m_draw_border(graph_reference graph, nana::color_t bgcolor) { if (!API::widget_borderless(widget_->handle())) { nana::rectangle r(graph.size()); graph.rectangle(r, (status_.has_focus ? 0x0595E2 : 0x999A9E), false); graph.rectangle(r.pare_off(1), bgcolor, false); } }
void drawer::_m_draw_border(graph_reference graph) { if(status_.border) { nana::rectangle r(graph.size()); graph.rectangle(r, (status_.has_focus ? 0x0595E2 : 0x999A9E), false); r.pare_off(1); graph.rectangle(r, 0xFFFFFF, false); } }
void drawer::draw(graph_reference graph, buttons what) { if(false == metrics_.pressed || metrics_.what != buttons::scroll) _m_adjust_scroll(graph); _m_background(graph); rectangle_rotator r(vertical_, ::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 result = r.result(); //draw first _m_draw_button(graph, { 0, 0, result.width, result.height }, buttons::first, (buttons::first == what ? moused_state : state)); //draw second _m_draw_button(graph, result, buttons::second, (buttons::second == what ? moused_state : state)); //draw scroll _m_draw_scroll(graph, (buttons::scroll == what ? moused_state : states::highlight)); }
void trigger::_m_draw_border(graph_reference graph) { nana::rectangle r(graph.size()); ::nana::color lt(static_cast<color_rgb>(0x7f7f7f)), rb(static_cast<color_rgb>(0x707070)); graph.frame_rectangle(r, lt, lt, rb, rb); graph.set_color(colors::button_face); draw_corner_point(graph, r); graph.set_color(static_cast<color_rgb>(0x919191)); draw_corner_point(graph, r.pare_off(1)); if (element_state::pressed == attr_.e_state) graph.rectangle(r, false, static_cast<color_rgb>(0xc3c3c3)); }
void trigger::refresh(graph_reference graph) { if (false == unknown_) draw_width_ = static_cast<unsigned>((graph.width() - border * 2) * (double(value_) / max_)); _m_draw_box(graph); _m_draw_progress(graph); }
void drawer::attached(widget_reference wdg, graph_reference graph) { auto wd = wdg.handle(); widget_ = &wdg; evt_agent_.reset(new event_agent(static_cast<::nana::textbox&>(wdg), editor_->text_position())); auto scheme = API::dev::get_scheme(wdg); editor_ = new text_editor(wd, graph, dynamic_cast<::nana::widgets::skeletons::text_editor_scheme*>(scheme)); editor_->textbase().set_event_agent(evt_agent_.get()); editor_->set_event(evt_agent_.get()); _m_text_area(graph.width(), graph.height()); API::tabstop(wd); API::eat_tabstop(wd, true); API::effects_edge_nimbus(wd, effects::edge_nimbus::active); API::effects_edge_nimbus(wd, effects::edge_nimbus::over); }
void drawer::_m_draw_title(graph_reference graph) { if(graph.width() > 16 + interval) { nana::string title = widget_->caption(); unsigned fgcolor = widget_->foreground(); unsigned pixels = graph.width() - (16 + interval); nana::paint::text_renderer tr(graph); if(API::window_enabled(widget_->handle()) == false) { tr.render(17 + interval, 2, 0xFFFFFF, title.c_str(), title.length(), pixels); fgcolor = 0x808080; } tr.render(16 + interval, 1, fgcolor, title.c_str(), title.length(), pixels); } }
void direction_arrow(graph_reference graph, int x, int y, nana::color_t color, uint32_t dir) { y += 5; switch(dir) { case directions::to_north: { x += 3; int pixels = 1; for(int l = 0; l < 4; ++l) { for(int i = 0; i < pixels; ++i) { if(l ==3 && i == 3) {} else graph.set_pixel(x + i, y, 0x262); } x--; y++; pixels += 2; } graph.set_pixel(x + 1, y, 0x262); graph.set_pixel(x + 2, y, 0x262); graph.set_pixel(x + 6, y, 0x262); graph.set_pixel(x + 7, y, 0x262); } break; case directions::to_south: { graph.set_pixel(x, y, 0x262); graph.set_pixel(x + 1, y, 0x262); graph.set_pixel(x + 5, y, 0x262); graph.set_pixel(x + 6, y, 0x262); ++y; int pixels = 7; for(int l = 0; l < 4; ++l) { for(int i = 0; i < pixels; ++i) { if(l == 0 && i == 3){} else graph.set_pixel(x + i, y, 0x262); } x++; y++; pixels -= 2; } } break; } }
void drawer::_m_draw_scroll(graph_reference graph, int 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); _m_button_frame(graph, r.result(), state); } }
void drawer::_m_draw_title(graph_reference graph) { if (graph.width() > 16 + interval) { nana::string title = widget_->caption(); unsigned pixels = graph.width() - (16 + interval); nana::paint::text_renderer tr(graph); if (API::window_enabled(widget_->handle()) == false) { graph.set_text_color(colors::white); tr.render({ 17 + interval, 2 }, title.c_str(), title.length(), pixels); graph.set_text_color({ 0x80, 0x80, 0x80 }); } else graph.set_text_color(widget_->fgcolor()); tr.render({ 16 + interval, 1 }, title.c_str(), title.length(), pixels); } }
void trigger::_m_draw_progress(graph_reference graph) { unsigned width = graph.width() - border * 2; unsigned height = graph.height() - border * 2; if(false == unknown_) { if(draw_width_) graph.gradual_rectangle({ static_cast<int>(border), static_cast<int>(border), draw_width_, height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true); } else { unsigned block = width / 3; int left = (value_ < block ? 0 : value_ - block) + border; int right = (value_ >= width - 1 + border? width - 1 + border: value_); if(right >= left) graph.gradual_rectangle({ left, static_cast<int>(border), static_cast<unsigned>(right - left + 1), height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true); if(value_ >= width + block) value_ = 0; } }
void drawer::_m_draw_button(graph_reference graph, rectangle r, buttons what, int state) { if(_m_check()) _m_button_frame(graph, r, state); if(buttons::first == what || buttons::second == what) { auto sz = graph.size(); int top = static_cast<int>(sz.height - fixedsize); int left = static_cast<int>(sz.width - fixedsize); direction dir; if (buttons::second == what) { if (vertical_) { r.y = top; dir = direction::south; } else { r.x = left; dir = direction::east; } } else dir = vertical_ ? direction::north : direction::west; if (vertical_) r.x = left / 2; else r.y = top / 2; r.width = r.height = 16; facade<element::arrow> arrow(states::none == state ? "hollow_triangle" : "solid_triangle"); arrow.direction(dir); arrow.draw(graph, {}, (_m_check() ? colors::black : colors::gray), r, element_state::normal); } }
void refresh(graph_reference graph) { graph.rectangle(false, colors::black); graph.rectangle(::nana::rectangle(graph.size()).pare_off(1), true, {0xf0, 0xf0, 0xf0}); }
void drawer::_m_draw_background(graph_reference graph) { if(bground_mode::basic != API::effects_bground_mode(*widget_)) graph.rectangle(true, API::bgcolor(*widget_)); }
void drawer::refresh(graph_reference graph) { _m_draw_background(graph); _m_draw_title(graph); _m_draw_checkbox(graph, graph.text_extent_size(STR("jN"), 2).height + 2); }
void drawer::refresh(graph_reference graph) { if (!API::dev::copy_transparent_background(window_, graph)) graph.rectangle(true, API::bgcolor(window_)); }
void trigger::_m_draw_title(graph_reference graph, bool enabled) { nana::string text = wdg_->caption(); nana::string::value_type shortkey; nana::string::size_type shortkey_pos; nana::string str = API::transform_shortkey_text(text, shortkey, &shortkey_pos); nana::size ts = graph.text_extent_size(str); nana::size gsize = graph.size(); nana::size icon_sz; if(attr_.icon) { icon_sz = attr_.icon->size(); icon_sz.width += 5; } nana::point pos{ static_cast<int>(gsize.width - 1 - ts.width) >> 1, static_cast<int>(gsize.height - 1 - ts.height) >> 1 }; if(pos.x < static_cast<int>(icon_sz.width)) pos.x = static_cast<int>(icon_sz.width); unsigned omitted_pixels = gsize.width - icon_sz.width; std::size_t txtlen = str.size(); const nana::char_t* txtptr = str.c_str(); if(ts.width) { nana::paint::text_renderer tr(graph); if(enabled) { if (element_state::pressed == attr_.e_state) { ++pos.x; ++pos.y; } graph.set_text_color(attr_.focus_color && attr_.focused ? ::nana::color(colors::blue) : attr_.fgcolor); if (attr_.omitted) tr.render(pos, txtptr, txtlen, omitted_pixels, true); else graph.bidi_string(pos, txtptr, txtlen); if(shortkey) { unsigned off_w = (shortkey_pos ? graph.text_extent_size(str, static_cast<unsigned>(shortkey_pos)).width : 0); nana::size shortkey_size = graph.text_extent_size(txtptr + shortkey_pos, 1); pos.x += off_w; pos.y += static_cast<int>(shortkey_size.height); graph.set_color(colors::black); graph.line(pos, point{ pos.x + static_cast<int>(shortkey_size.width) - 1, pos.y }); } } else { graph.set_text_color(::nana::color(colors::white)); if(attr_.omitted) { tr.render(point{ pos.x + 1, pos.y + 1 }, txtptr, txtlen, omitted_pixels, true); graph.set_text_color(::nana::color(colors::gray)); tr.render(pos, txtptr, txtlen, omitted_pixels, true); } else { graph.bidi_string(point{ pos.x + 1, pos.y + 1 }, txtptr, txtlen); graph.set_text_color(::nana::color(colors::gray)); graph.bidi_string(pos, txtptr, txtlen); } } } if(attr_.icon) attr_.icon->paste(graph, point{ 3, static_cast<int>(gsize.height - icon_sz.height) / 2 }); } void trigger::_m_draw_background(graph_reference graph) { nana::rectangle r(graph.size()); r.pare_off(1); auto from = attr_.bgcolor.blend(colors::white, 0.2); auto to = attr_.bgcolor.blend(colors::black, 0.95); if (element_state::pressed == attr_.e_state) { r.x = r.y = 2; std::swap(from, to); } graph.gradual_rectangle(r, from, to, true); }
void take_effect(window, graph_reference graph) const { graph.blur(::nana::rectangle{ graph.size() }, radius_); }
void take_effect(window wd, graph_reference graph) const { if(fade_rate_ < 0.001) return; graph.blend(::nana::rectangle{ graph.size() }, API::bgcolor(wd), fade_rate_); }
void take_effect(window, graph_reference graph) const { graph.blur(graph.size(), radius_); }