Defined a new color class

The new color class is temporarily named expr_color for experiment.
This commit is contained in:
cnjinhao
2014-12-14 10:15:19 +08:00
parent d0a317bd45
commit 74c09eb9b3
37 changed files with 1495 additions and 674 deletions

View File

@@ -347,9 +347,12 @@ namespace nana
visible = false;
color.foreground = 0x0;
color.background = nana::color::button_face;
color.active = 0x60C8FD;
colors.foreground = 0x0; //deprecated
colors.background = nana::color::button_face;
colors.active = 0x60C8FD;
colors.fgcolor = ::nana::expr_color(::nana::colors::black);
colors.bgcolor = ::nana::expr_color(static_cast<::nana::colors>(nana::color::button_face));
colors.activated = ::nana::expr_color(0x60, 0xc8, 0xfd);
effect.edge_nimbus = effects::edge_nimbus::none;
effect.bground = nullptr;

View File

@@ -19,7 +19,7 @@ namespace nana
class crook
: public crook_interface
{
bool draw(graph_reference graph, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle& r, element_state es, const data& crook_data) override
bool draw(graph_reference graph, const nana::expr_color& bgcolor, const nana::expr_color& fgcolor, const nana::rectangle& r, element_state es, const data& crook_data) override
{
if(crook_data.radio)
{
@@ -129,21 +129,28 @@ namespace nana
}
else
{
const nana::color_t highlighted = 0x5EB6F7;
//const nana::color_t highlighted = 0x5EB6F7; //deprecated
nana::expr_color highlighted(0x5e, 0xb6, 0xf7);
auto bld_bgcolor = bgcolor;
auto bld_fgcolor = fgcolor;
switch(es)
{
case element_state::hovered:
case element_state::focus_hovered:
bgcolor = graph.mix(bgcolor, highlighted, 0.8);
fgcolor = graph.mix(fgcolor, highlighted, 0.8);
bld_bgcolor.blend(highlighted, 0.8);
bld_fgcolor.blend(highlighted, 0.8);
//bgcolor = graph.mix(bgcolor, highlighted, 0.8); //deprecated
//fgcolor = graph.mix(fgcolor, highlighted, 0.8);
break;
case element_state::pressed:
bgcolor = graph.mix(bgcolor, highlighted, 0.4);
fgcolor = graph.mix(fgcolor, highlighted, 0.4);
bld_bgcolor.blend(highlighted, 0.4);
bld_fgcolor.blend(highlighted, 0.4);
//bgcolor = graph.mix(bgcolor, highlighted, 0.4); //deprecated
//fgcolor = graph.mix(fgcolor, highlighted, 0.4);
break;
case element_state::disabled:
bgcolor = fgcolor = 0xB2B7BC;
bld_bgcolor = bld_fgcolor = nana::expr_color(0xb2, 0xb7, 0xbc);
//bgcolor = fgcolor = 0xB2B7BC; //deprecated
break;
default:
//Leave things as they are
@@ -152,8 +159,11 @@ namespace nana
const int x = r.x + 1;
const int y = r.y + 1;
graph.rectangle(x, y, 13, 13, fgcolor, false);
graph.rectangle(x + 1, y + 1, 11, 11, bgcolor, true);
graph.set_color(bld_bgcolor);
graph.rectangle(rectangle{ x + 1, y + 1, 11, 11 }, true);
graph.set_color(bld_fgcolor);
graph.rectangle(rectangle{ x, y, 13, 13 }, false);
switch(crook_data.check_state)
{
@@ -166,19 +176,19 @@ namespace nana
{
sx++;
sy++;
graph.line(sx, sy, sx, sy + 3, fgcolor);
graph.line(point{ sx, sy }, point{ sx, sy + 3 });
}
for(int i = 0; i < 4; i++)
{
sx++;
sy--;
graph.line(sx, sy, sx, sy + 3, fgcolor);
graph.line(point{ sx, sy }, point{ sx, sy + 3 });
}
}
break;
case state::partial:
graph.rectangle(x + 2, y + 2, 9, 9, fgcolor, true);
graph.rectangle(rectangle{ x + 2, y + 2, 9, 9 }, true);
break;
default:
break;
@@ -191,7 +201,7 @@ namespace nana
class menu_crook
: public crook_interface
{
bool draw(graph_reference graph, nana::color_t, nana::color_t fgcolor, const nana::rectangle& r, element_state es, const data& crook_data) override
bool draw(graph_reference graph, const ::nana::expr_color&, const ::nana::expr_color& fgcolor, const nana::rectangle& r, element_state es, const data& crook_data) override
{
if(crook_data.check_state == state::unchecked)
return true;
@@ -228,14 +238,27 @@ 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_t light = graph.mix(fgcolor, 0xFFFFFF, 0.5);
::nana::expr_color light(colors::white);
light.blend(fgcolor, 0.5);
graph.line(x + 3, y + 7, x + 6, y + 10, fgcolor);
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.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 });
graph.line(point{ x + 7, y + 8 }, point{ x + 11, y + 4 });
//nana::color_t light = graph.mix(fgcolor, 0xFFFFFF, 0.5); //deprecated
/*
graph.line(point{ x + 3, y + 7 }, point{ x + 6, y + 10 }, fgcolor); //deprecated
graph.line(x + 7, y + 9, x + 12, y + 4, fgcolor);
graph.line(x + 3, y + 8, x + 6, y + 11, light);
graph.line(x + 7, y + 10, x + 12, y + 5, light);
graph.line(x + 4, y + 7, x + 6, y + 9, light);
graph.line(x + 7, y + 8, x + 11, y + 4, light);
*/
}
return true;
}
@@ -433,7 +456,7 @@ namespace nana
keeper_ = element::provider().keeper_crook(name);
}
bool facade<element::crook>::draw(graph_reference graph, nana::color_t bgcol, nana::color_t fgcol, const nana::rectangle& r, element_state es)
bool facade<element::crook>::draw(graph_reference graph, const ::nana::expr_color& bgcol, const ::nana::expr_color& fgcol, const nana::rectangle& r, element_state es)
{
return (*keeper_)->draw(graph, bgcol, fgcol, r, es, data_);
}
@@ -470,7 +493,7 @@ namespace nana
ref_ptr_ = detail::bedrock::instance().get_element_store().bground(name);
}
bool cite_bground::draw(graph_reference dst, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle& r, element_state state)
bool cite_bground::draw(graph_reference dst, const ::nana::expr_color& bgcolor, const ::nana::expr_color& fgcolor, const nana::rectangle& r, element_state state)
{
if (ref_ptr_ && *ref_ptr_)
return (*ref_ptr_)->draw(dst, bgcolor, fgcolor, r, state);
@@ -656,7 +679,7 @@ namespace nana
}
//Implement the methods of bground_interface.
bool bground::draw(graph_reference dst, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle& to_r, element_state state)
bool bground::draw(graph_reference dst, const ::nana::expr_color&, const ::nana::expr_color&, const nana::rectangle& to_r, element_state state)
{
if (nullptr == method_)
return false;

View File

@@ -157,7 +157,7 @@ namespace API
if(restrict::window_manager.available(iwd))
{
iwd->drawer.graphics.make(iwd->dimension.width, iwd->dimension.height);
iwd->drawer.graphics.rectangle(iwd->color.background, true);
iwd->drawer.graphics.rectangle(iwd->colors.background, true);
iwd->drawer.attached(wd, dr);
iwd->drawer.refresh(); //Always redrawe no matter it is visible or invisible. This can make the graphics data correctly.
}
@@ -790,24 +790,24 @@ namespace API
restrict::bedrock.pump_event(wd, false);
}
nana::color_t foreground(window wd)
nana::color_t foreground(window wd) //deprecated
{
internal_scope_guard lock;
if(restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd)))
return reinterpret_cast<restrict::core_window_t*>(wd)->color.foreground;
return reinterpret_cast<restrict::core_window_t*>(wd)->colors.foreground;
return 0;
}
color_t foreground(window wd, color_t col)
color_t foreground(window wd, color_t col) //deprecated
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if(restrict::window_manager.available(iwd))
{
color_t prev = iwd->color.foreground;
color_t prev = iwd->colors.foreground;
if(prev != col)
{
iwd->color.foreground = col;
iwd->colors.foreground = col;
restrict::window_manager.update(iwd, true, false);
}
return prev;
@@ -815,24 +815,24 @@ namespace API
return 0;
}
color_t background(window wd)
color_t background(window wd) //deprecated
{
internal_scope_guard lock;
if(restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd)))
return reinterpret_cast<restrict::core_window_t*>(wd)->color.background;
return reinterpret_cast<restrict::core_window_t*>(wd)->colors.background;
return 0;
}
color_t background(window wd, color_t col)
color_t background(window wd, color_t col) //deprecated
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if(restrict::window_manager.available(iwd))
{
color_t prev = iwd->color.background;
color_t prev = iwd->colors.background;
if(prev != col)
{
iwd->color.background = col;
iwd->colors.background = col;
restrict::window_manager.update(iwd, true, false);
}
return prev;
@@ -840,24 +840,24 @@ namespace API
return 0;
}
color_t active(window wd)
color_t active(window wd) //deprecated
{
internal_scope_guard lock;
if(restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd)))
return reinterpret_cast<restrict::core_window_t*>(wd)->color.active;
return reinterpret_cast<restrict::core_window_t*>(wd)->colors.active;
return 0;
}
color_t active(window wd, color_t col)
color_t active(window wd, color_t col) //deprecated
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if(restrict::window_manager.available(iwd))
{
color_t prev = iwd->color.active;
color_t prev = iwd->colors.active;
if(prev != col)
{
iwd->color.active = col;
iwd->colors.active = col;
restrict::window_manager.update(iwd, true, false);
}
return prev;
@@ -866,6 +866,83 @@ namespace API
return 0;
}
expr_color fgcolor(window wd)
{
internal_scope_guard lock;
if (restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd)))
return reinterpret_cast<restrict::core_window_t*>(wd)->colors.fgcolor;
return{};
}
expr_color fgcolor(window wd, const expr_color& col)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if (restrict::window_manager.available(iwd))
{
auto prev = iwd->colors.fgcolor;
if (prev != col)
{
iwd->colors.fgcolor = col;
restrict::window_manager.update(iwd, true, false);
}
return prev;
}
return{};
}
expr_color bgcolor(window wd)
{
internal_scope_guard lock;
if (restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd)))
return reinterpret_cast<restrict::core_window_t*>(wd)->colors.bgcolor;
return{};
}
expr_color bgcolor(window wd, const expr_color& col)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if (restrict::window_manager.available(iwd))
{
auto prev = iwd->colors.bgcolor;
if (prev != col)
{
iwd->colors.bgcolor = col;
restrict::window_manager.update(iwd, true, false);
}
return prev;
}
return{};
}
expr_color activated_color(window wd)
{
internal_scope_guard lock;
if (restrict::window_manager.available(reinterpret_cast<restrict::core_window_t*>(wd)))
return reinterpret_cast<restrict::core_window_t*>(wd)->colors.activated;
return{};
}
expr_color activated_color(window wd, const expr_color& col)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if (restrict::window_manager.available(iwd))
{
auto prev = iwd->colors.activated;
if (prev != col)
{
iwd->colors.activated = col;
restrict::window_manager.update(iwd, true, false);
}
return prev;
}
return{};
}
void create_caret(window wd, unsigned width, unsigned height)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);

View File

@@ -20,12 +20,8 @@ namespace nana{ namespace drawerbase
//trigger
//@brief: draw the button
trigger::trigger()
: widget_(nullptr),
graph_(nullptr),
cite_("button")
{
attr_.e_state = element_state::normal;
attr_.omitted = attr_.focused = attr_.pushed = attr_.enable_pushed = attr_.keep_pressed = false;
attr_.focus_color = true;
attr_.icon = nullptr;
@@ -40,7 +36,7 @@ namespace nana{ namespace drawerbase
{
graph_ = &graph;
widget_ = &widget;
wdg_ = &widget;
window wd = widget;
API::tabstop(wd);
@@ -61,7 +57,7 @@ namespace nana{ namespace drawerbase
attr_.pushed = pshd;
if(false == pshd)
{
if (API::find_window(API::cursor_position()) == widget_->handle())
if (API::find_window(API::cursor_position()) == wdg_->handle())
attr_.e_state = element_state::hovered;
else
attr_.e_state = element_state::normal;
@@ -128,13 +124,13 @@ namespace nana{ namespace drawerbase
attr_.keep_pressed = true;
_m_draw(graph);
API::capture_window(*widget_, true);
API::capture_window(*wdg_, true);
API::lazy_refresh();
}
void trigger::mouse_up(graph_reference graph, const arg_mouse&)
{
API::capture_window(*widget_, false);
API::capture_window(*wdg_, false);
attr_.keep_pressed = false;
if(attr_.enable_pushed && (false == attr_.pushed))
{
@@ -173,7 +169,7 @@ namespace nana{ namespace drawerbase
default:
return;
}
API::move_tabstop(widget_->handle(), ch_tabstop_next);
API::move_tabstop(*wdg_, ch_tabstop_next);
}
void trigger::focus(graph_reference graph, const arg_focus& arg)
@@ -185,7 +181,7 @@ namespace nana{ namespace drawerbase
void trigger::_m_draw_title(graph_reference graph, bool enabled)
{
nana::string text = widget_->caption();
nana::string text = wdg_->caption();
nana::string::value_type shortkey;
nana::string::size_type shortkey_pos;
@@ -201,11 +197,14 @@ namespace nana{ namespace drawerbase
icon_sz.width += 5;
}
int x = (static_cast<int>(gsize.width - 1 - ts.width) >> 1);
int y = (static_cast<int>(gsize.height - 1 - ts.height) >> 1);
//int x = (static_cast<int>(gsize.width - 1 - ts.width) >> 1); //deprecated
//int y = (static_cast<int>(gsize.height - 1 - ts.height) >> 1);
nana::point pos{
static_cast<int>(gsize.width - 1 - ts.width) >> 1, static_cast<int>(gsize.height - 1 - ts.height) >> 1
};
if(x < static_cast<int>(icon_sz.width))
x = static_cast<int>(icon_sz.width);
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();
@@ -217,35 +216,53 @@ namespace nana{ namespace drawerbase
{
if (element_state::pressed == attr_.e_state)
{
++x;
++y;
++pos.x;
++pos.y;
}
color_t fgcolor = (attr_.focus_color ? (attr_.focused ? 0xFF : attr_.fgcolor) : attr_.fgcolor);
//color_t fgcolor = (attr_.focus_color ? (attr_.focused ? 0xFF : attr_.fgcolor) : attr_.fgcolor);
auto fgcolor = attr_.fgcolor;
if (attr_.focus_color && attr_.focused)
fgcolor = ::nana::expr_color(colors::blue);
graph.set_text_color(fgcolor);
/*
if(attr_.omitted)
tr.render(x, y, fgcolor, txtptr, txtlen, omitted_pixels, true);
tr.render(x, y, fgcolor.argb().value, txtptr, txtlen, omitted_pixels, true); //deprecated
else
graph.bidi_string(x, y, fgcolor, txtptr, txtlen);
*/
if (attr_.omitted)
tr.render(pos, txtptr, txtlen, omitted_pixels, true); //deprecated
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);
x += off_w;
y += shortkey_size.height;
graph.line(x, y, x + shortkey_size.width - 1, y, 0x0);
pos.x += off_w;
pos.y += static_cast<int>(shortkey_size.height);
//graph.line(x, y, x + shortkey_size.width - 1, y, 0x0); //deprecated
graph.set_color(::nana::expr_color(colors::black));
graph.line(pos, point{ pos.x + static_cast<int>(shortkey_size.width) - 1, pos.y });
}
}
else
{
graph.set_text_color(::nana::expr_color(colors::white));
if(attr_.omitted)
{
tr.render(x + 1, y + 1, 0xFFFFFF, txtptr, txtlen, omitted_pixels, true);
tr.render(x, y, 0x808080, txtptr, txtlen, omitted_pixels, true);
tr.render(point{ pos.x + 1, pos.y + 1 }, txtptr, txtlen, omitted_pixels, true);
graph.set_text_color(::nana::expr_color(colors::gray));
tr.render(pos, txtptr, txtlen, omitted_pixels, true);
}
else
{
graph.bidi_string(x + 1, y + 1, 0xFFFFFF, txtptr, txtlen);
graph.bidi_string(x, y, 0x808080, txtptr, txtlen);
graph.bidi_string(point{ pos.x + 1, pos.y + 1 }, txtptr, txtlen);
graph.set_text_color(::nana::expr_color(colors::gray));
graph.bidi_string(pos, txtptr, txtlen);
}
}
}
@@ -256,11 +273,10 @@ namespace nana{ namespace drawerbase
void trigger::_m_draw(graph_reference graph)
{
window wd = widget_->handle();
bool eb = API::window_enabled(wd);
bool eb = wdg_->enabled();;
attr_.bgcolor = API::background(wd);
attr_.fgcolor = API::foreground(wd);
attr_.bgcolor = wdg_->bgcolor();
attr_.fgcolor = wdg_->fgcolor();
element_state e_state = attr_.e_state;
if (eb)
@@ -278,7 +294,7 @@ namespace nana{ namespace drawerbase
if (false == cite_.draw(graph, attr_.bgcolor, attr_.fgcolor, graph.size(), e_state))
{
if (bground_mode::basic != API::effects_bground_mode(wd))
if (bground_mode::basic != API::effects_bground_mode(wdg_->handle()))
{
_m_draw_background(graph);
_m_draw_border(graph);
@@ -291,15 +307,21 @@ namespace nana{ namespace drawerbase
{
nana::rectangle r(graph.size());
r.pare_off(1);
nana::color_t color_start = nana::paint::graphics::mix(attr_.bgcolor, 0xFFFFFF, 0.2);
nana::color_t color_end = nana::paint::graphics::mix(attr_.bgcolor, 0x0, 0.95);
//nana::color_t color_start = nana::paint::graphics::mix(attr_.bgcolor.argb().value, 0xFFFFFF, 0.2); //deprecated
//nana::color_t color_end = nana::paint::graphics::mix(attr_.bgcolor.argb().value, 0x0, 0.95);
::nana::expr_color from(colors::white);
from.blend(attr_.bgcolor, 0.8);
::nana::expr_color to(colors::black);
to.blend(attr_.bgcolor, 0.05);
if (element_state::pressed == attr_.e_state)
{
r.x = r.y = 2;
std::swap(color_start, color_end);
std::swap(from, to);
}
graph.shadow_rectangle(r, color_start, color_end, true);
//graph.shadow_rectangle(r, color_start, color_end, true); //deprecated
graph.gradual_rectangle(r, from, to, true);
}
void trigger::_m_draw_border(graph_reference graph)
@@ -329,7 +351,7 @@ namespace nana{ namespace drawerbase
{
arg_mouse arg;
arg.evt_code = event_code::click;
arg.window_handle = widget_->handle();
arg.window_handle = wdg_->handle();
arg.ctrl = arg.shift = false;
arg.mid_button = arg.right_button = false;
arg.left_button = true;

View File

@@ -93,7 +93,7 @@ namespace checkbox
void drawer::_m_draw_checkbox(graph_reference graph, unsigned first_line_height)
{
impl_->crook.draw(graph, widget_->background(), widget_->foreground(), rectangle(0, first_line_height > 16 ? (first_line_height - 16) / 2 : 0, 16, 16), API::element_state(*widget_));
impl_->crook.draw(graph, widget_->bgcolor(), widget_->fgcolor(), rectangle(0, first_line_height > 16 ? (first_line_height - 16) / 2 : 0, 16, 16), API::element_state(*widget_));
}
void drawer::_m_draw_title(graph_reference graph)

View File

@@ -28,7 +28,7 @@ namespace nana
namespace listbox
{
//struct cell
cell::format::format(color_t bgcolor, color_t fgcolor)
cell::format::format(const ::nana::expr_color& bgcolor, const ::nana::expr_color& fgcolor)
: bgcolor{ bgcolor }, fgcolor{ fgcolor }
{}
@@ -53,7 +53,7 @@ namespace nana
custom_format(new format{ fmt }) //make_unique
{}
cell::cell(nana::string text, color_t bgcolor, color_t fgcolor)
cell::cell(nana::string text, const ::nana::expr_color& bgcolor, const ::nana::expr_color& fgcolor)
: text(std::move(text)),
custom_format{ new format{ bgcolor, fgcolor } } //make_unique
{}
@@ -577,8 +577,10 @@ namespace nana
typedef std::vector<cell> container;
container cells;
color_t bgcolor{0xFF000000};
color_t fgcolor{0xFF000000};
//color_t bgcolor{0xFF000000}; //deprecated
//color_t fgcolor{0xFF000000};
nana::expr_color bgcolor;
nana::expr_color fgcolor;
paint::image img;
nana::size img_show_size;
@@ -616,7 +618,7 @@ namespace nana
cells.emplace_back(std::move(s));
}
item_t(nana::string&& s, color_t bg, color_t fg)
item_t(nana::string&& s, const nana::expr_color& bg, const nana::expr_color& fg)
: bgcolor(bg),
fgcolor(fg)
{
@@ -2343,12 +2345,15 @@ namespace nana
size_type n = essence_->number_of_lister_items(true);
if(0 == n)return;
widget * wdptr = essence_->lister.wd_ptr();
nana::color_t bgcolor = wdptr->background();
nana::color_t txtcolor = wdptr->foreground();
//nana::color_t bgcolor = wdptr->background();
//nana::color_t txtcolor = wdptr->foreground(); //deprecated
auto bgcolor = wdptr->bgcolor();
auto fgcolor = wdptr->fgcolor();
unsigned header_w = essence_->header.pixels();
essence_->graph->set_color(bgcolor);
if(header_w - essence_->scroll.offset_x < rect.width)
essence_->graph->rectangle(rect.x + header_w - essence_->scroll.offset_x, rect.y, rect.width - (header_w - essence_->scroll.offset_x), rect.height, bgcolor, true);
essence_->graph->rectangle(rectangle{ rect.x + static_cast<int>(header_w)-essence_->scroll.offset_x, rect.y, rect.width - (header_w - essence_->scroll.offset_x), rect.height }, true);
es_lister & lister = essence_->lister;
//The Tracker indicates the item where mouse placed.
@@ -2391,7 +2396,7 @@ namespace nana
if(n-- == 0) break;
state = (tracker == idx ? essence_t::state_t::highlighted : essence_t::state_t::normal);
_m_draw_item(i_categ->items[lister.absolute(index_pair(idx.cat, offs))], x, y, txtoff, header_w, rect, subitems, bgcolor, txtcolor, state);
_m_draw_item(i_categ->items[lister.absolute(index_pair(idx.cat, offs))], x, y, txtoff, header_w, rect, subitems, bgcolor,fgcolor, state);
y += essence_->item_size;
}
}
@@ -2402,7 +2407,7 @@ namespace nana
if(n-- == 0) break;
state = (tracker == idx ? essence_t::state_t::highlighted : essence_t::state_t::normal);
_m_draw_item(*i, x, y, txtoff, header_w, rect, subitems, bgcolor, txtcolor, state);
_m_draw_item(*i, x, y, txtoff, header_w, rect, subitems, bgcolor, fgcolor, state);
y += essence_->item_size;
}
}
@@ -2431,7 +2436,7 @@ namespace nana
if(n-- == 0) break;
state = (idx == tracker ? essence_t::state_t::highlighted : essence_t::state_t::normal);
_m_draw_item(i_categ->items[lister.absolute(index_pair(idx.cat, pos))], x, y, txtoff, header_w, rect, subitems, bgcolor, txtcolor, state);
_m_draw_item(i_categ->items[lister.absolute(index_pair(idx.cat, pos))], x, y, txtoff, header_w, rect, subitems, bgcolor, fgcolor, state);
y += essence_->item_size;
++idx.item;
}
@@ -2444,7 +2449,7 @@ namespace nana
state = (idx == tracker ? essence_t::state_t::highlighted : essence_t::state_t::normal);
_m_draw_item(m, x, y, txtoff, header_w, rect, subitems, bgcolor, txtcolor, state);
_m_draw_item(m, x, y, txtoff, header_w, rect, subitems, bgcolor, fgcolor, state);
y += essence_->item_size;
++idx.item;
@@ -2452,21 +2457,25 @@ namespace nana
}
}
if(y < rect.y + static_cast<int>(rect.height))
essence_->graph->rectangle(rect.x, y, rect.width, rect.y + rect.height - y, bgcolor, true);
if (y < rect.y + static_cast<int>(rect.height))
{
essence_->graph->set_color(bgcolor);
essence_->graph->rectangle(rectangle{ rect.x, y, rect.width, rect.y + rect.height - y }, true);
}
}
private:
void _m_draw_categ(const category_t& categ, int x, int y, int txtoff, unsigned width, const nana::rectangle& r, nana::color_t bgcolor, essence_t::state_t state) const
void _m_draw_categ(const category_t& categ, int x, int y, int txtoff, unsigned width, const nana::rectangle& r, nana::expr_color bgcolor, essence_t::state_t state) const
{
bool sel = categ.selected();
if(sel && (categ.expand == false))
bgcolor = 0xD5EFFC;
bgcolor = nana::expr_color(0xD5, 0xEF, 0xFC);
if(state == essence_t::state_t::highlighted)
bgcolor = essence_->graph->mix(bgcolor, 0x99DEFD, 0.8);
if (state == essence_t::state_t::highlighted)
bgcolor.blend(::nana::expr_color(0x99, 0xde, 0xfd), 0.8);
auto graph = essence_->graph;
graph->rectangle(x, y, width, essence_->item_size, bgcolor, true);
graph->set_color(bgcolor);
graph->rectangle(rectangle{ x, y, width, essence_->item_size }, true);
nana::paint::gadget::arrow_16_pixels(*graph, x + 5, y + (essence_->item_size - 16) /2, 0x3399, 2, (categ.expand ? nana::paint::gadget::directions::to_north : nana::paint::gadget::directions::to_south));
nana::size text_s = graph->text_extent_size(categ.text);
@@ -2491,25 +2500,26 @@ 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_t bgcolor, nana::color_t txtcolor, essence_t::state_t state) const
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::expr_color bgcolor, nana::expr_color fgcolor, essence_t::state_t state) const
{
if(item.flags.selected)
bgcolor = 0xD5EFFC;
else if ((item.bgcolor & 0xFF000000) == 0)
bgcolor = nana::expr_color(0xD5, 0xEF, 0xFC);
else if (!item.bgcolor.invisible())
bgcolor = item.bgcolor;
if((item.fgcolor & 0xFF000000) == 0)
txtcolor = item.fgcolor;
if(!item.fgcolor.invisible())
fgcolor = item.fgcolor;
auto graph = essence_->graph;
if(essence_t::state_t::highlighted == state)
bgcolor = graph->mix(bgcolor, 0x99DEFD, 0.8);
if (essence_t::state_t::highlighted == state)
bgcolor.blend(::nana::expr_color(0x99, 0xde, 0xfd), 0.8);// = graph->mix(bgcolor, 0x99DEFD, 0.8); //deprecated
unsigned show_w = width - essence_->scroll.offset_x;
if(show_w >= r.width) show_w = r.width;
//draw the background
graph->rectangle(r.x, y, show_w, essence_->item_size, bgcolor, true);
graph->set_color(bgcolor);
graph->rectangle(rectangle{ r.x, y, show_w, essence_->item_size }, true);
int item_xpos = x;
bool first = true;
@@ -2541,7 +2551,7 @@ namespace nana
typedef std::remove_reference<decltype(crook_renderer_)>::type::state state;
crook_renderer_.check(item.flags.checked ? state::checked : state::unchecked);
crook_renderer_.draw(*graph, bgcolor, txtcolor, essence_->checkarea(item_xpos, y), estate);
crook_renderer_.draw(*graph, bgcolor, fgcolor, essence_->checkarea(item_xpos, y), estate);
}
auto & m_cell = item.cells[index];
@@ -2559,32 +2569,37 @@ namespace nana
ext_w += 18;
}
auto cell_txtcolor = txtcolor;
if (m_cell.custom_format)
auto cell_txtcolor = fgcolor;
if (m_cell.custom_format && (!m_cell.custom_format->bgcolor.invisible()))
{
if (!item.flags.selected && !(m_cell.custom_format->bgcolor & 0xFF000000))
if (!item.flags.selected)
{
auto cell_bgcolor = m_cell.custom_format->bgcolor;
if (essence_t::state_t::highlighted == state)
cell_bgcolor = graph->mix(cell_bgcolor, 0x99DEFD, 0.8);
graph->rectangle(item_xpos, y, header.pixels, essence_->item_size, cell_bgcolor, true);
cell_bgcolor.blend(::nana::expr_color(0x99, 0xde, 0xfd), 0.8); //= graph->mix(cell_bgcolor, 0x99DEFD, 0.8); //deprecated
graph->set_color(cell_bgcolor);
graph->rectangle(rectangle{ item_xpos, y, header.pixels, essence_->item_size }, true);
}
if (!(m_cell.custom_format->bgcolor & 0xFF000000))
cell_txtcolor = m_cell.custom_format->fgcolor;
cell_txtcolor = m_cell.custom_format->fgcolor;
}
graph->string(item_xpos + ext_w, y + txtoff, cell_txtcolor, m_cell.text);
graph->set_text_color(cell_txtcolor);
graph->string(point{ item_xpos + ext_w, y + txtoff }, m_cell.text);
if(ts.width + ext_w > header.pixels)
if (ts.width + ext_w > header.pixels)
{
//The text is painted over the next subitem
int xpos = item_xpos + header.pixels - essence_->suspension_width;
graph->rectangle(xpos, y + 2, essence_->suspension_width, essence_->item_size - 4, bgcolor, true);
graph->string(xpos, y + 2, txtcolor, STR("..."));
graph->set_color(bgcolor);
graph->rectangle(rectangle{ xpos, y + 2, essence_->suspension_width, essence_->item_size - 4 }, true);
graph->set_text_color(fgcolor);
graph->string(point{ xpos, y + 2 }, STR("..."));
//Erase the part that over the next subitem.
auto erase_bgcolor = index + 1 < seqs.size() ? bgcolor : item.bgcolor;
graph->rectangle(item_xpos + header.pixels, y + 2, ts.width + ext_w - header.pixels, essence_->item_size - 4, erase_bgcolor, true);
if (index + 1 >= seqs.size())
graph->set_color(item.bgcolor);
graph->rectangle(rectangle{item_xpos + static_cast<int>(header.pixels), y + 2, ts.width + ext_w - header.pixels, essence_->item_size - 4}, true);
}
}
@@ -3021,26 +3036,26 @@ namespace nana
return cat_->items.at(pos_.item).flags.selected;
}
item_proxy & item_proxy::bgcolor(nana::color_t col)
item_proxy & item_proxy::bgcolor(const nana::expr_color& col)
{
cat_->items.at(pos_.item).flags.selected;
cat_->items.at(pos_.item).bgcolor = col;
ess_->update();
return *this;
}
nana::color_t item_proxy::bgcolor() const
nana::expr_color item_proxy::bgcolor() const
{
return cat_->items.at(pos_.item).bgcolor;
}
item_proxy& item_proxy::fgcolor(nana::color_t col)
item_proxy& item_proxy::fgcolor(const nana::expr_color& col)
{
cat_->items.at(pos_.item).fgcolor = col;
ess_->update();
return *this;
}
nana::color_t item_proxy::fgcolor() const
nana::expr_color item_proxy::fgcolor() const
{
return cat_->items.at(pos_.item).fgcolor;
}
@@ -3265,8 +3280,8 @@ namespace nana
if(wd && !(API::empty_window(wd->handle())))
{
auto & m = cat_->items.back();
m.bgcolor = wd->background();
m.fgcolor = wd->foreground();
m.bgcolor = wd->bgcolor();
m.fgcolor = wd->fgcolor();
ess_->update();
}
}
@@ -3425,8 +3440,8 @@ namespace nana
if (wd && !(API::empty_window(wd->handle())))
{
auto & m = cat_->items.back();
m.bgcolor = wd->background();
m.fgcolor = wd->foreground();
m.bgcolor = wd->bgcolor();
m.fgcolor = wd->fgcolor();
ess_->update();
}
}
@@ -3534,8 +3549,8 @@ namespace nana
if (false == API::empty_window(wd))
{
auto & item = ess.lister.at(pos);
item.bgcolor = API::background(wd);
item.fgcolor = API::foreground(wd);
item.bgcolor = bgcolor();
item.fgcolor = fgcolor();
ess.update();
}
}

View File

@@ -136,7 +136,7 @@ namespace nana
nana::rectangle crook_r = r;
crook_r.width = 16;
crook_.radio(at.check_style == checks::option);
crook_.draw(graph, 0xE6EFF4, 0x0, crook_r, element_state::normal);
crook_.draw(graph, ::nana::expr_color(0xE6, 0xEF, 0xF4), colors::black, crook_r, element_state::normal);
}
}

View File

@@ -1078,7 +1078,16 @@ namespace nana
class internal_renderer
: public renderer_interface
{
void bground(graph_reference graph, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface * compset) const override
nana::expr_color bgcolor_;
nana::expr_color fgcolor_;
void set_color(const nana::expr_color & bgcolor, const nana::expr_color& fgcolor) override
{
bgcolor_ = bgcolor;
fgcolor_ = fgcolor;
}
void bground(graph_reference graph, const compset_interface * compset) const override
{
comp_attribute_t attr;
@@ -1108,7 +1117,7 @@ namespace nana
}
}
void expander(graph_reference graph, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface * compset) const override
void expander(graph_reference graph, const compset_interface * compset) const override
{
comp_attribute_t attr;
if(compset->comp_attribute(component::expender, attr))
@@ -1126,18 +1135,18 @@ namespace nana
}
}
void crook(graph_reference graph, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface * compset) const override
void crook(graph_reference graph, const compset_interface * compset) const override
{
comp_attribute_t attr;
if(compset->comp_attribute(component::crook, attr))
{
attr.area.y += (attr.area.height - 16) / 2;
crook_.check(compset->item_attribute().checked);
crook_.draw(graph, bgcolor, fgcolor, attr.area, attr.mouse_pointed ? element_state::hovered : element_state::normal);
crook_.draw(graph, bgcolor_, fgcolor_, attr.area, attr.mouse_pointed ? element_state::hovered : element_state::normal);
}
}
virtual void icon(graph_reference graph, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface * compset) const override
virtual void icon(graph_reference graph, const compset_interface * compset) const override
{
comp_attribute_t attr;
if(compset->comp_attribute(component::icon, attr))
@@ -1170,11 +1179,14 @@ namespace nana
}
}
virtual void text(graph_reference graph, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface * compset) const override
virtual void text(graph_reference graph, const compset_interface * compset) const override
{
comp_attribute_t attr;
if(compset->comp_attribute(component::text, attr))
graph.string(attr.area.x, attr.area.y + 3, fgcolor, compset->item_attribute().text);
if (compset->comp_attribute(component::text, attr))
{
graph.set_text_color(fgcolor_);
graph.string(point{ attr.area.x, attr.area.y + 3 }, compset->item_attribute().text);
}
}
private:
@@ -1279,8 +1291,8 @@ namespace nana
item_renderer(implement * impl, const nana::point& pos)
:impl_(impl), pos_(pos)
{
bgcolor_ = impl_->data.widget_ptr->background();
fgcolor_ = impl_->data.widget_ptr->foreground();
bgcolor_ = impl_->data.widget_ptr->bgcolor();
fgcolor_ = impl_->data.widget_ptr->fgcolor();
}
//affect
@@ -1310,11 +1322,12 @@ namespace nana
node_r_.height = comp_placer->item_height(*impl_->data.graph);
auto renderer = draw_impl->data.renderer;
renderer->bground(*draw_impl->data.graph, bgcolor_, fgcolor_, this);
renderer->expander(*draw_impl->data.graph, bgcolor_, fgcolor_, this);
renderer->crook(*draw_impl->data.graph, bgcolor_, fgcolor_, this);
renderer->icon(*draw_impl->data.graph, bgcolor_, fgcolor_, this);
renderer->text(*draw_impl->data.graph, bgcolor_, fgcolor_, this);
renderer->set_color(bgcolor_, fgcolor_);
renderer->bground(*draw_impl->data.graph, this);
renderer->expander(*draw_impl->data.graph, this);
renderer->crook(*draw_impl->data.graph, this);
renderer->icon(*draw_impl->data.graph, this);
renderer->text(*draw_impl->data.graph, this);
pos_.y += node_r_.height;
@@ -1343,8 +1356,10 @@ namespace nana
}
private:
trigger::implement * impl_;
nana::color_t bgcolor_;
nana::color_t fgcolor_;
//nana::color_t bgcolor_; //deprecated
//nana::color_t fgcolor_;
nana::expr_color bgcolor_;
nana::expr_color fgcolor_;
nana::point pos_;
const node_type * iterated_node_;
item_attribute_t node_attr_;
@@ -1386,13 +1401,12 @@ namespace nana
nana::paint::graphics item_graph(item_r_.width, item_r_.height);
item_graph.typeface(graph_->typeface());
auto bgcolor = widget_->background();
auto fgcolor = widget_->foreground();
renderer_->bground(item_graph, bgcolor, fgcolor, this);
renderer_->expander(item_graph, bgcolor, fgcolor, this);
renderer_->crook(item_graph, bgcolor, fgcolor, this);
renderer_->icon(item_graph, bgcolor, fgcolor, this);
renderer_->text(item_graph, bgcolor, fgcolor, this);
renderer_->set_color(widget_->bgcolor(), widget_->fgcolor());
renderer_->bground(item_graph, this);
renderer_->expander(item_graph, this);
renderer_->crook(item_graph, this);
renderer_->icon(item_graph, this);
renderer_->text(item_graph, this);
item_graph.paste(attr.area, *graph_, 1, 1);
graph_->rectangle(0x0, false);

View File

@@ -143,22 +143,42 @@ namespace nana
void widget::foreground(nana::color_t value)
{
_m_foreground(value);
_m_fgcolor(expr_color(static_cast<colors>(value)));
}
nana::color_t widget::foreground() const
{
return _m_foreground();
return _m_fgcolor().argb().value;
}
void widget::background(nana::color_t value)
{
_m_background(value);
_m_bgcolor(expr_color(static_cast<colors>(value)));
}
nana::color_t widget::background() const
{
return _m_background();
return _m_bgcolor().argb().value;
}
void widget::fgcolor(const nana::expr_color& col)
{
_m_fgcolor(col);
}
nana::expr_color widget::fgcolor() const
{
return _m_fgcolor();
}
void widget::bgcolor(const nana::expr_color& col)
{
_m_bgcolor(col);
}
nana::expr_color widget::bgcolor() const
{
return _m_bgcolor();
}
general_events& widget::events() const
@@ -261,24 +281,24 @@ namespace nana
return API::typeface(handle());
}
void widget::_m_foreground(nana::color_t value)
void widget::_m_fgcolor(const nana::expr_color& col)
{
API::foreground(handle(), value);
API::fgcolor(handle(), col);
}
nana::color_t widget::_m_foreground() const
nana::expr_color widget::_m_fgcolor() const
{
return API::foreground(handle());
return API::fgcolor(handle());
}
void widget::_m_background(nana::color_t value)
void widget::_m_bgcolor(const nana::expr_color& col)
{
API::background(handle(), value);
API::bgcolor(handle(), col);
}
nana::color_t widget::_m_background() const
nana::expr_color widget::_m_bgcolor() const
{
return API::background(handle());
return API::bgcolor(handle());
}
//end class widget