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

@@ -283,7 +283,6 @@ namespace detail
};
drawable_impl_type::drawable_impl_type()
: fgcolor_(0xFFFFFFFF)
{
string.tab_length = 4;
string.tab_pixels = 0;
@@ -302,14 +301,76 @@ namespace detail
#endif
}
void drawable_impl_type::fgcolor(unsigned color)
void drawable_impl_type::set_color(nana::color_t col)
{
if(color != fgcolor_)
color_ = col;
}
void drawable_impl_type::set_text_color(nana::color_t col)
{
text_color_ = col;
update_text_color();
}
void drawable_impl_type::update_color()
{
if (color_ != current_color_)
{
auto & spec = nana::detail::platform_spec::instance();
platform_scope_guard lock;
current_color_ = color_;
auto col = color_;
switch (spec.screen_depth())
{
case 16:
col = ((((col >> 16) & 0xFF) * 31 / 255) << 11) |
((((col >> 8) & 0xFF) * 63 / 255) << 5) |
(col & 0xFF) * 31 / 255;
break;
}
::XSetForeground(spec.open_display(), context, col);
::XSetBackground(spec.open_display(), context, col);
}
}
void drawable_impl_type::update_text_color()
{
if (text_color_ != current_color_)
{
auto & spec = nana::detail::platform_spec::instance();
platform_scope_guard lock;
current_color_ = text_color_;
auto col = text_color_;
switch (spec.screen_depth())
{
case 16:
col = ((((col >> 16) & 0xFF) * 31 / 255) << 11) |
((((col >> 8) & 0xFF) * 63 / 255) << 5) |
(col & 0xFF) * 31 / 255;
break;
}
::XSetForeground(spec.open_display(), context, col);
::XSetBackground(spec.open_display(), context, col);
#if defined(NANA_UNICODE)
xft_fgcolor.color.red = ((0xFF0000 & col) >> 16) * 0x101;
xft_fgcolor.color.green = ((0xFF00 & col) >> 8) * 0x101;
xft_fgcolor.color.blue = (0xFF & col) * 0x101;
xft_fgcolor.color.alpha = 0xFFFF;
#endif
}
}
void drawable_impl_type::fgcolor(nana::color_t color)
{
if (color != current_color_)
{
auto & spec = nana::detail::platform_spec::instance();
platform_scope_guard psg;
fgcolor_ = color;
current_color_ = color;
switch(spec.screen_depth())
{
case 16:

View File

@@ -21,17 +21,15 @@ namespace nana
namespace detail
{
drawable_impl_type::drawable_impl_type()
: pixbuf_ptr(nullptr), bytes_per_line(0),
fgcolor_(0xFFFFFFFF)
{
pen.handle = nullptr;
pen.color = nana::null_color;
pen.color = 0xffffffff;
pen.style = -1;
pen.width = -1;
brush.handle = nullptr;
brush.style = brush_spec::Solid;
brush.color = nana::null_color;
brush.color = 0xffffffff;
round_region.handle = nullptr;
round_region.radius_x = round_region.radius_y = 0;
@@ -52,14 +50,40 @@ namespace detail
void drawable_impl_type::fgcolor(nana::color_t col)
{
if(this->fgcolor_ != col)
set_text_color(col);
}
void drawable_impl_type::set_color(nana::color_t col)
{
color_ = col;
}
void drawable_impl_type::set_text_color(nana::color_t col)
{
if(text_color_ != col)
{
::SetTextColor(context, NANA_RGB(col));
fgcolor_ = col;
text_color_ = col;
}
}
void drawable_impl_type::pen_spec::set(HDC context, int style, int width, nana::color_t color)
void drawable_impl_type::update_pen()
{
if (pen.color != color_)
{
pen.handle = ::CreatePen(PS_SOLID, 1, NANA_RGB(color_));
::DeleteObject(::SelectObject(context, pen.handle));
pen.color = color_;
}
}
void drawable_impl_type::update_brush()
{
if (brush.color != color_)
brush.set(context, brush.style, color_);
}
void drawable_impl_type::pen_spec::set(HDC context, int style, int width, nana::color_t color) //deprecated
{
if(this->color != color || this->width != width || this->style != style)
{