Added listbox color scheme

This commit is contained in:
cnjinhao
2014-12-30 06:28:23 +08:00
parent 052d34a746
commit aa12254844
22 changed files with 142 additions and 107 deletions

View File

@@ -21,7 +21,7 @@ namespace nana
{
if(active)
{
native_interface::caret_create(wd_->root, size_.width, size_.height);
native_interface::caret_create(wd_->root, size_);
real_visible_state_ = false;
visible_ = false;
this->position(point_.x, point_.y);
@@ -173,7 +173,7 @@ namespace nana
if(paint_size_ != size)
{
native_interface::caret_destroy(wd_->root);
native_interface::caret_create(wd_->root, size.width, size.height);
native_interface::caret_create(wd_->root, size);
real_visible_state_ = false;
if(visible_)
_m_visible(true);
@@ -181,7 +181,7 @@ namespace nana
paint_size_ = size;
}
native_interface::caret_pos(wd_->root, wd_->pos_root.x + pos.x, wd_->pos_root.y + pos.y);
native_interface::caret_pos(wd_->root, wd_->pos_root + pos);
}
}
//end class caret_descriptor

View File

@@ -29,6 +29,18 @@ namespace nana
return *this;
}
color_proxy& color_proxy::operator = (color_rgb clr)
{
color_ = std::make_shared<::nana::color>(clr);
return *this;
}
color_proxy& color_proxy::operator = (colors clr)
{
color_ = std::make_shared<::nana::color>(clr);
return *this;
}
color color_proxy::get_color() const
{
return *color_;

View File

@@ -1193,13 +1193,13 @@ namespace nana{
#endif
}
void native_interface::caret_create(native_window_type wd, unsigned width, unsigned height)
void native_interface::caret_create(native_window_type wd, const ::nana::size& caret_sz)
{
#if defined(NANA_WINDOWS)
::CreateCaret(reinterpret_cast<HWND>(wd), 0, int(width), int(height));
::CreateCaret(reinterpret_cast<HWND>(wd), 0, int(caret_sz.width), int(caret_sz.height));
#elif defined(NANA_X11)
nana::detail::platform_scope_guard psg;
restrict::spec.caret_open(wd, width, height);
restrict::spec.caret_open(wd, caret_sz);
#endif
}
@@ -1216,21 +1216,21 @@ namespace nana{
#endif
}
void native_interface::caret_pos(native_window_type wd, int x, int y)
void native_interface::caret_pos(native_window_type wd, const point& pos)
{
#if defined(NANA_WINDOWS)
if(::GetCurrentThreadId() != ::GetWindowThreadProcessId(reinterpret_cast<HWND>(wd), 0))
{
auto cp = new nana::detail::messages::caret;
cp->x = x;
cp->y = y;
cp->x = pos.x;
cp->y = pos.y;
::PostMessage(reinterpret_cast<HWND>(wd), nana::detail::messages::operate_caret, 2, reinterpret_cast<LPARAM>(cp));
}
else
::SetCaretPos(x, y);
::SetCaretPos(pos.x, pos.y);
#elif defined(NANA_X11)
nana::detail::platform_scope_guard psg;
restrict::spec.caret_pos(wd, x, y);
restrict::spec.caret_pos(wd, pos);
#endif
}

View File

@@ -141,19 +141,19 @@ namespace nana
}
else
{
nana::color highlighted(0x5e, 0xb6, 0xf7);
::nana::color highlighted(0x5e, 0xb6, 0xf7);
auto bld_bgcolor = bgcolor;
auto bld_fgcolor = fgcolor;
switch(es)
{
case element_state::hovered:
case element_state::focus_hovered:
bld_bgcolor.blend(highlighted, 0.8);
bld_fgcolor.blend(highlighted, 0.8);
bld_bgcolor = bgcolor.blend(highlighted, 0.8);
bld_fgcolor = fgcolor.blend(highlighted, 0.8);
break;
case element_state::pressed:
bld_bgcolor.blend(highlighted, 0.4);
bld_fgcolor.blend(highlighted, 0.4);
bld_bgcolor = bgcolor.blend(highlighted, 0.4);
bld_fgcolor = fgcolor.blend(highlighted, 0.4);
break;
case element_state::disabled:
bld_bgcolor = bld_fgcolor = nana::color(0xb2, 0xb7, 0xbc);
@@ -244,14 +244,11 @@ namespace nana
int x = r.x + (static_cast<int>(r.width) - 16) / 2;
int y = r.y + (static_cast<int>(r.height) - 16) / 2;
::nana::color light(colors::white);
light.blend(fgcolor, 0.5);
graph.set_color(fgcolor);
graph.line(point{ x + 3, y + 7 }, point{ x + 6, y + 10 });
graph.line(point{ x + 7, y + 9 }, point{ x + 12, y + 4 });
graph.set_color(light);
graph.set_color(fgcolor.blend(colors::white, 0.5));
graph.line(point{ x + 3, y + 8 }, point{ x + 6, y + 11 });
graph.line(point{ x + 7, y + 10 }, point{ x + 12, y + 5 });
graph.line(point{ x + 4, y + 7 }, point{ x + 6, y + 9 });

View File

@@ -908,12 +908,12 @@ namespace API
}
}
void caret_pos(window wd, int x, int y)
void caret_pos(window wd, const point& pos)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if(restrict::window_manager.available(iwd) && iwd->together.caret)
iwd->together.caret->position(x, y);
iwd->together.caret->position(pos.x, pos.y);
}
nana::point caret_pos(window wd)

View File

@@ -298,10 +298,8 @@ namespace nana{ namespace drawerbase
nana::rectangle r(graph.size());
r.pare_off(1);
::nana::color from(colors::white);
from.blend(attr_.bgcolor, 0.8);
::nana::color to(colors::black);
to.blend(attr_.bgcolor, 0.05);
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)
{

View File

@@ -78,7 +78,7 @@ namespace nana
if(ue.what == ue.none || (API::window_enabled(wd) == false))
{ //the mouse is out of the widget.
style_.bgcolor.blend(color{ 0xa0, 0xc9, 0xf5 }, 0.9);
style_.bgcolor = style_.bgcolor.blend(color{ 0xa0, 0xc9, 0xf5 }, 0.9);
}
graph.rectangle(r, true, style_.bgcolor);
}

View File

@@ -1693,10 +1693,11 @@ namespace nana
// the state of the struct does not effect on member funcions, therefore all data members are public.
struct essence_t
{
enum class state_t{normal, highlighted, pressed, grabed, floated};
enum class state_t{normal, highlighted, pressed, grabbed, floated};
enum class where_t{unknown = -1, header, lister, checker};
nana::paint::graphics *graph{nullptr};
::nana::listbox::scheme_type* scheme_ptr{nullptr};
::nana::paint::graphics *graph{nullptr};
bool auto_draw{true};
bool checkable{false};
bool if_image{false};
@@ -2207,9 +2208,14 @@ namespace nana
_m_draw(essence_->header.cont(), r);
const int y = r.y + r.height - 1;
essence_->graph->line({ r.x, y }, { r.x + static_cast<int>(r.width), y }, { 0xDE, 0xDF, 0xE1 });
essence_->graph->line({ r.x, y }, { r.x + static_cast<int>(r.width), y }, _m_border_color());
}
private:
::nana::color _m_border_color() const
{
return essence_->scheme_ptr->header_bgcolor.get_color().blend(colors::black, 0.8);
}
size_type _m_target_strip(int x, const nana::rectangle& rect, size_type grab, bool& place_front)
{
//convert x to header logic coordinate.
@@ -2268,32 +2274,36 @@ namespace nana
if(next_x > rect.x)
{
_m_draw_item(graph, x, rect.y, height, txtop, txtcolor, i, (i.index == essence_->pointer_where.second ? state : essence_t::state_t::normal));
graph.line({ next_x - 1, rect.y }, { next_x - 1, bottom_y }, { 0xDE, 0xDF, 0xE1 });
graph.line({ next_x - 1, rect.y }, { next_x - 1, bottom_y }, _m_border_color());
}
if(next_x > rect.right())
break;
x = next_x;
if(x - rect.x > static_cast<int>(rect.width)) break;
}
}
if(x - rect.x < static_cast<int>(rect.width))
graph.rectangle({ x, rect.y, rect.width - x + rect.x, height }, true, { 0xF1, 0xF2, 0xF4 });
graph.rectangle({ x, rect.y, rect.width - x + rect.x, height }, true, essence_->scheme_ptr->header_bgcolor);
}
template<typename Item>
void _m_draw_item(graph_reference graph, int x, int y, unsigned height, int txtop, const ::nana::color& fgcolor, const Item& item, essence_t::state_t state)
{
essence_->scheme_ptr->header_bgcolor.get_color();
::nana::color bgcolor;
typedef essence_t::state_t state_t;
switch(state)
{
case state_t::normal: bgcolor.from_rgb(0xf1, 0xf2, 0xf4); break;
case state_t::highlighted: bgcolor = colors::white; break;
case state_t::normal: bgcolor = essence_->scheme_ptr->header_bgcolor.get_color(); break;
case state_t::highlighted: bgcolor = essence_->scheme_ptr->header_bgcolor.get_color().blend(colors::white, 0.5); break;
case state_t::pressed:
case state_t::grabed: bgcolor.from_rgb(0x8B, 0xD6, 0xF6); break;
case state_t::floated: bgcolor.from_rgb(0xBA, 0xBB, 0xBC); break;
case state_t::grabbed: bgcolor = essence_->scheme_ptr->header_grabbed.get_color(); break;
case state_t::floated: bgcolor = essence_->scheme_ptr->header_floated.get_color(); break;
}
graph.rectangle({ x, y, item.pixels, height }, true, bgcolor);
graph.gradual_rectangle({ x, y, item.pixels, height }, bgcolor.blend(colors::white, 0.9), bgcolor.blend(colors::black, 0.9), true);
graph.string({ x + 5, txtop }, item.text, fgcolor);
if(item.index == essence_->lister.sort_index())
@@ -2467,7 +2477,7 @@ namespace nana
bgcolor = nana::color(0xD5, 0xEF, 0xFC);
if (state == essence_t::state_t::highlighted)
bgcolor.blend(::nana::color(0x99, 0xde, 0xfd), 0.8);
bgcolor = bgcolor.blend(::nana::color(0x99, 0xde, 0xfd), 0.8);
auto graph = essence_->graph;
graph->set_color(bgcolor);
@@ -2501,8 +2511,8 @@ namespace nana
void _m_draw_item(const item_t& item, int x, int y, int txtoff, unsigned width, const nana::rectangle& r, const std::vector<size_type>& seqs, nana::color bgcolor, nana::color fgcolor, essence_t::state_t state) const
{
if(item.flags.selected)
bgcolor = nana::color(0xD5, 0xEF, 0xFC);
if (item.flags.selected)
bgcolor = essence_->scheme_ptr->item_selected;
else if (!item.bgcolor.invisible())
bgcolor = item.bgcolor;
@@ -2511,7 +2521,12 @@ namespace nana
auto graph = essence_->graph;
if (essence_t::state_t::highlighted == state)
bgcolor.blend(::nana::color(0x99, 0xde, 0xfd), 0.8);
{
if (item.flags.selected)
bgcolor = bgcolor.blend(colors::black, 0.98);
else
bgcolor = bgcolor.blend(essence_->scheme_ptr->item_selected, 0.7);
}
unsigned show_w = width - essence_->scroll.offset_x;
if(show_w >= r.width) show_w = r.width;
@@ -2541,7 +2556,7 @@ namespace nana
{
case essence_t::state_t::highlighted:
estate = element_state::hovered; break;
case essence_t::state_t::grabed:
case essence_t::state_t::grabbed:
estate = element_state::pressed; break;
default: break;
}
@@ -2573,10 +2588,10 @@ namespace nana
{
if (!item.flags.selected)
{
auto cell_bgcolor = m_cell.custom_format->bgcolor;
if (essence_t::state_t::highlighted == state)
cell_bgcolor.blend(::nana::color(0x99, 0xde, 0xfd), 0.8);
graph->set_color(cell_bgcolor);
graph->set_color(m_cell.custom_format->bgcolor.blend(::nana::color(0x99, 0xde, 0xfd), 0.8));
else
graph->set_color(m_cell.custom_format->bgcolor);
graph->rectangle(rectangle{ item_xpos, y, header.pixels, essence_->item_size }, true);
}
@@ -2688,6 +2703,7 @@ namespace nana
void trigger::attached(widget_reference widget, graph_reference graph)
{
essence_->scheme_ptr = static_cast<::nana::listbox::scheme_type*>(API::dev::get_scheme(widget));
essence_->graph = &graph;
typeface_changed(graph);
@@ -2719,7 +2735,7 @@ namespace nana
{
if(essence_->pointer_where.first == essence_t::where_t::header)
{
essence_->ptr_state = essence_t::state_t::grabed;
essence_->ptr_state = essence_t::state_t::grabbed;
nana::point pos = arg.pos;
essence_->widget_to_header(pos);
drawer_header_->grab(pos, true);
@@ -2728,7 +2744,7 @@ namespace nana
}
}
if(essence_->ptr_state == essence_t::state_t::grabed)
if(essence_->ptr_state == essence_t::state_t::grabbed)
{
nana::point pos = arg.pos;
essence_->widget_to_header(pos);
@@ -2756,7 +2772,7 @@ namespace nana
}
}
}
if(set_spliter == false && essence_->ptr_state != essence_t::state_t::grabed)
if(set_spliter == false && essence_->ptr_state != essence_t::state_t::grabbed)
{
if((drawer_header_->item_spliter() != npos) || (essence_->lister.wd_ptr()->cursor() == cursor::size_we))
{
@@ -2783,7 +2799,7 @@ namespace nana
typedef essence_t::state_t state_t;
if((essence_->pointer_where.first != essence_t::where_t::unknown) || (essence_->ptr_state != state_t::normal))
{
if(essence_->ptr_state != state_t::grabed)
if(essence_->ptr_state != state_t::grabbed)
{
essence_->pointer_where.first = essence_t::where_t::unknown;
essence_->ptr_state = state_t::normal;
@@ -2892,7 +2908,7 @@ namespace nana
}
}
}
else if(prev_state == state_t::grabed)
else if(prev_state == state_t::grabbed)
{
nana::point pos = arg.pos;
essence_->widget_to_header(pos);

View File

@@ -108,14 +108,12 @@ namespace nana
case item_renderer::state_highlight:
border = colors::highlight;
body.from_rgb(0xC0, 0xDD, 0xFC);
corner = body;
corner.blend(bground, 0.5);
corner = body.blend(bground, 0.5);
break;
case item_renderer::state_selected:
border = colors::dark_border;
body = colors::white;
corner = body;
corner.blend(bground, 0.5);
corner = body.blend(bground, 0.5);
break;
default: //Don't process other states.
return;
@@ -541,8 +539,8 @@ namespace nana
{
int x = item_pos.x + item_s.width;
int y1 = item_pos.y + 2, y2 = item_pos.y + item_s.height - 1;
graph_->line({ x, y1 }, { x, y2 }, ::nana::color(colors::gray_border).blend(bgcolor, 0.6));
graph_->line({ x + 1, y1 }, { x + 1, y2 }, ::nana::color(colors::button_face_shadow_end).blend(bgcolor, 0.5));
graph_->line({ x, y1 }, { x, y2 }, bgcolor.blend(colors::gray_border, 0.4));
graph_->line({ x + 1, y1 }, { x + 1, y2 }, bgcolor.blend(colors::button_face_shadow_end, 0.5));
}
//Draw text, the text is transformed from orignal for hotkey character

View File

@@ -208,7 +208,8 @@ namespace nana
graph.rectangle(r, false, clr);
graph.set_color(clr.blend(colors::white, 0.5));
clr = clr.blend(colors::white, 0.5);
graph.set_color(clr);
r.pare_off(2);

View File

@@ -1528,7 +1528,7 @@ namespace nana{ namespace widgets
API::caret_visible(window_, visible);
if(visible)
API::caret_pos(window_, pos.x, pos.y);
API::caret_pos(window_, pos);
}
}

View File

@@ -40,9 +40,10 @@ namespace nana
if(bgcolor_ != bgcolor)
{
bgcolor_ = bgcolor;
dark_bgcolor_ = ::nana::color{ colors::black }.blend(bgcolor, 0.1);
blcolor_ = ::nana::color{ colors::black }.blend(bgcolor, 0.5);
ilcolor_ = ::nana::color{ colors::white }.blend(bgcolor, 0.1);
dark_bgcolor_ = bgcolor.blend(colors::black, 0.9);
blcolor_ = bgcolor.blend(colors::black, 0.5);
ilcolor_ = bgcolor.blend(colors::white, 0.9);
}
graph.rectangle(true, bgcolor);
@@ -65,8 +66,8 @@ namespace nana
else
{
bgcolor = m.bgcolor;
blcolor = color{ colors::black }.blend(m.bgcolor, 0.5);
dark_bgcolor = color{ colors::black }.blend(m.bgcolor, 0.1);
blcolor = m.bgcolor.blend(colors::black, 0.5);
dark_bgcolor = m.bgcolor.blend(colors::black, 0.9);
}
auto round_r = r;
@@ -81,12 +82,12 @@ namespace nana
if (m.bgcolor.invisible())
beg = ilcolor_;
else
beg = color{ m.bgcolor }.blend(colors::white, 0.5);
beg = m.bgcolor.blend(colors::white, 0.5);
end = bgcolor;
}
if (sta == item_renderer::highlight)
beg.blend(colors::white, 0.5);
beg = beg.blend(colors::white, 0.5);
graph.gradual_rectangle(round_r.pare_off(2), beg, end, true);
}
@@ -131,9 +132,9 @@ namespace nana
::nana::color rect_clr{0x9d, 0xa3, 0xab};
graph.round_rectangle(r, 1, 1, rect_clr, false, {});
nana::rectangle draw_r(r);
graph.rectangle(draw_r.pare_off(1), false, ::nana::color{ rect_clr }.blend(bgcolor, 0.8));
graph.rectangle(draw_r.pare_off(1), false, ::nana::color{ rect_clr }.blend(bgcolor, 0.4));
graph.rectangle(draw_r.pare_off(1), false, ::nana::color{ rect_clr }.blend(bgcolor, 0.2));
graph.rectangle(draw_r.pare_off(1), false, rect_clr.blend(bgcolor, 0.8));
graph.rectangle(draw_r.pare_off(1), false, rect_clr.blend(bgcolor, 0.4));
graph.rectangle(draw_r.pare_off(1), false, rect_clr.blend(bgcolor, 0.2));
}
else if (!active)
clr = ::nana::color{ 0x92, 0x99, 0xA4 };

View File

@@ -395,7 +395,7 @@ namespace nana
void drawer::_m_draw_background(const ::nana::color& clr)
{
graph_->gradual_rectangle(graph_->size(), ::nana::color(colors::white).blend(clr, 0.1), ::nana::color(colors::black).blend(clr, 0.05), true);
graph_->gradual_rectangle(graph_->size(), clr.blend(colors::white, 0.9), clr.blend(colors::black, 0.95), true);
}
void drawer::_m_draw()