Color Schemes

textbox.scheme().selection = color(colors::red);
Set the text selection background color
This commit is contained in:
cnjinhao
2014-12-28 17:16:52 +08:00
parent ad7c36be3f
commit ecbf71b7e2
38 changed files with 506 additions and 166 deletions

View File

@@ -49,9 +49,7 @@ namespace nana
void caret_descriptor::effective_range(nana::rectangle rect)
{
//Chech rect
if( (rect.width && rect.height) &&
(rect.x + rect.width > 0) &&
(rect.y + rect.height > 0))
if (rect.width && rect.height && rect.right() > 0 && rect.bottom() > 0)
{
if(rect.x < 0)
{
@@ -151,9 +149,9 @@ namespace nana
size.width -= (rect.x - pos.x);
pos.x = rect.x;
}
else if(pos.x + size.width > rect.x + rect.width)
else if(pos.x + size.width > rect.right())
{
size.width -= pos.x + size.width - (rect.x + rect.width);
size.width -= pos.x + size.width - rect.right();
}
if(pos.y < rect.y)
@@ -161,8 +159,8 @@ namespace nana
size.width -= (rect.y - pos.y);
pos.y = rect.y;
}
else if(pos.y + size.height > rect.y + rect.height)
size.height -= pos.y + size.height - (rect.y + rect.height);
else if(pos.y + size.height > rect.bottom())
size.height -= pos.y + size.height - rect.bottom();
if(out_of_range_)
{
@@ -228,7 +226,7 @@ namespace nana
: widget_ptr(wdg), other(category::root_tag::value)
{
drawer.bind(this);
_m_init_pos_and_size(0, rectangle());
_m_init_pos_and_size(nullptr, rectangle());
this->_m_initialize(owner);
}

View File

@@ -12,7 +12,7 @@
#include <nana/config.hpp>
#include PLATFORM_SPEC_HPP
#include GUI_BEDROCK_HPP
#include <nana/gui/detail/bedrock_pi_data.hpp>
#include <nana/gui/detail/event_code.hpp>
#include <nana/system/platform.hpp>
#include <sstream>
@@ -120,6 +120,16 @@ namespace nana
}
}
widget_colors& bedrock::get_scheme_template(scheme_factory_base&& factory)
{
return pi_data_->scheme.scheme_template(std::move(factory));
}
std::unique_ptr<widget_colors> bedrock::make_scheme(scheme_factory_base&& factory)
{
return pi_data_->scheme.create(std::move(factory));
}
void bedrock::_m_emit_core(event_code evt_code, core_window_t* wd, bool draw_only, const ::nana::detail::event_arg_interface& event_arg)
{
switch (evt_code)

View File

@@ -0,0 +1,78 @@
#include <nana/gui/detail/color_schemes.hpp>
#include <map>
namespace nana
{
//class color_proxy
color_proxy::color_proxy(const color_proxy& other)
: color_(other.color_)
{}
color_proxy::color_proxy(color_rgb clr)
: color_(std::make_shared<color>(clr))
{}
color_proxy::color_proxy(colors clr)
: color_(std::make_shared<color>(clr))
{}
color_proxy& color_proxy::operator=(const color_proxy& other)
{
if (this != &other)
color_ = other.color_;
return *this;
}
color_proxy& color_proxy::operator=(const ::nana::color& clr)
{
color_ = std::make_shared<::nana::color>(clr);
return *this;
}
color color_proxy::get_color() const
{
return *color_;
}
color_proxy::operator color() const
{
return *color_;
}
//end class color_proxy
namespace detail
{
//class color_schemes
struct color_schemes::implement
{
std::map<scheme_factory_base::factory_identifier*, std::unique_ptr<scheme>> scheme_template;
};
color_schemes::color_schemes()
: impl_(new implement)
{
}
color_schemes::~color_schemes()
{
delete impl_;
}
auto color_schemes::scheme_template(scheme_factory_base&& factory) -> scheme&
{
auto & tmpl_scheme = impl_->scheme_template[factory.get_id()];
//Creates a scheme template if no template
if (!tmpl_scheme)
factory.create().swap(tmpl_scheme);
return *tmpl_scheme.get();
}
std::unique_ptr<widget_colors> color_schemes::create(scheme_factory_base&& factory)
{
return factory.create(scheme_template(std::move(factory)));
}
//end class color_system
}//end namespace detail
}//end namespace nana

View File

@@ -11,7 +11,7 @@
*/
#include <nana/config.hpp>
#include GUI_BEDROCK_HPP
#include <nana/gui/detail/bedrock.hpp>
#include <nana/gui/detail/drawer.hpp>
#include <nana/gui/detail/dynamic_drawing_object.hpp>
#include <nana/gui/detail/effects_renderer.hpp>

View File

@@ -12,7 +12,7 @@
#include <nana/config.hpp>
#include PLATFORM_SPEC_HPP
#include GUI_BEDROCK_HPP
#include <nana/gui/detail/bedrock_pi_data.hpp>
#include <nana/gui/detail/event_code.hpp>
#include <nana/system/platform.hpp>
#include <nana/gui/detail/inner_fwd_implement.hpp>
@@ -165,13 +165,14 @@ namespace detail
}
bedrock::bedrock()
: impl_(new private_impl)
: pi_data_(new pi_data), impl_(new private_impl)
{
nana::detail::platform_spec::instance().msg_set(timer_proc, window_proc_dispatcher);
}
bedrock::~bedrock()
{
delete pi_data_;
delete impl_;
}

View File

@@ -23,7 +23,7 @@
#include <nana/paint/detail/image_ico.hpp>
#elif defined(NANA_X11)
#include <nana/system/platform.hpp>
#include GUI_BEDROCK_HPP
#include <nana/gui/detail/bedrock.hpp>
#endif
namespace nana{

View File

@@ -13,16 +13,18 @@
#include <nana/config.hpp>
#include PLATFORM_SPEC_HPP
#include GUI_BEDROCK_HPP
#include <nana/gui/detail/bedrock.hpp>
#include <nana/gui/detail/bedrock_pi_data.hpp>
#include <nana/gui/detail/event_code.hpp>
#include <nana/system/platform.hpp>
#include <sstream>
#include <nana/system/timepiece.hpp>
#include <nana/gui/wvl.hpp>
#include <nana/gui.hpp>
#include <nana/gui/detail/inner_fwd_implement.hpp>
#include <nana/gui/detail/native_window_interface.hpp>
#include <nana/gui/layout_utility.hpp>
#include <nana/gui/detail/element_store.hpp>
#include <nana/gui/detail/color_schemes.hpp>
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
@@ -175,7 +177,8 @@ namespace detail
std::recursive_mutex mutex;
thr_context_container thr_contexts;
element_store estore;
color_schemes schemes;
element_store estore;
struct cache_type
{
@@ -213,7 +216,8 @@ namespace detail
static LRESULT WINAPI Bedrock_WIN32_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
bedrock::bedrock()
:impl_(new private_impl)
: pi_data_(new pi_data),
impl_(new private_impl)
{
nana::detail::platform_spec::instance(); //to guaranty the platform_spec object is initialized before using.
@@ -269,6 +273,7 @@ namespace detail
::MessageBoxA(0, ss.str().c_str(), ("Nana C++ Library"), MB_OK);
}
delete impl_;
delete pi_data_;
}
//inc_window

View File

@@ -12,7 +12,7 @@
*/
#include <nana/config.hpp>
#include GUI_BEDROCK_HPP
#include <nana/gui/detail/bedrock.hpp>
#include <nana/gui/detail/handle_manager.hpp>
#include <nana/gui/detail/window_manager.hpp>
#include <nana/gui/detail/native_window_interface.hpp>

View File

@@ -150,6 +150,22 @@ namespace API
return false;
}
void set_scheme(window wd, widget_colors* wdg_colors)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
if (restrict::window_manager.available(iwd))
iwd->expr_colors = wdg_colors;
}
widget_colors* get_scheme(window wd)
{
auto iwd = reinterpret_cast<restrict::core_window_t*>(wd);
internal_scope_guard lock;
return (restrict::window_manager.available(iwd) ? iwd->expr_colors : nullptr);
}
void attach_drawer(widget& wd, drawer_trigger& dr)
{
const auto iwd = reinterpret_cast<restrict::core_window_t*>(wd.handle());
@@ -794,20 +810,20 @@ namespace API
{
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 reinterpret_cast<restrict::core_window_t*>(wd)->expr_colors->foreground.get_color();
return{};
}
color fgcolor(window wd, const color& col)
color fgcolor(window wd, const color& clr)
{
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)
auto prev = iwd->expr_colors->foreground.get_color();
if (prev != clr)
{
iwd->colors.fgcolor = col;
iwd->expr_colors->foreground = clr;
restrict::window_manager.update(iwd, true, false);
}
return prev;
@@ -819,20 +835,20 @@ namespace API
{
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 reinterpret_cast<restrict::core_window_t*>(wd)->expr_colors->background.get_color();
return{};
}
color bgcolor(window wd, const color& col)
color bgcolor(window wd, const color& clr)
{
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)
auto prev = iwd->expr_colors->background.get_color();
if (prev != clr)
{
iwd->colors.bgcolor = col;
iwd->expr_colors->background = clr;
restrict::window_manager.update(iwd, true, false);
}
return prev;
@@ -844,20 +860,20 @@ namespace API
{
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 reinterpret_cast<restrict::core_window_t*>(wd)->expr_colors->activated.get_color();
return{};
}
color activated_color(window wd, const color& col)
color activated_color(window wd, const color& clr)
{
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)
auto prev = iwd->expr_colors->activated.get_color();
if (prev != clr)
{
iwd->colors.activated = col;
iwd->expr_colors->activated = clr;
restrict::window_manager.update(iwd, true, false);
}
return prev;

View File

@@ -84,7 +84,9 @@ namespace nana
void attached(widget_reference wd, graph_reference graph)
{
widget_ = static_cast< ::nana::combox*>(&wd);
editor_ = new widgets::skeletons::text_editor(widget_->handle(), graph);
auto scheme = dynamic_cast< ::nana::widgets::skeletons::text_editor_scheme*>(API::dev::get_scheme(wd));
editor_ = new widgets::skeletons::text_editor(widget_->handle(), graph, scheme);
editor_->border_renderer([this](graph_reference graph, const ::nana::color& bgcolor){
draw_border(graph, bgcolor);
});

View File

@@ -54,6 +54,11 @@ namespace nana
{
API::modal_window(handle());
}
void form::wait_for_this()
{
API::wait_for(handle());
}
//end class form
//class nested_form

View File

@@ -1140,9 +1140,9 @@ namespace nana{ namespace widgets
}; //end class behavior_linewrapped
//class text_editor
text_editor::text_editor(window wd, graph_reference graph)
text_editor::text_editor(window wd, graph_reference graph, const text_editor_scheme* schm)
: behavior_(new behavior_normal(*this)),
window_(wd), graph_(graph)
window_(wd), graph_(graph), scheme_(schm)
{
text_area_.area = graph.size();
text_area_.captured = false;
@@ -1661,7 +1661,7 @@ namespace nana{ namespace widgets
{
const auto bgcolor = _m_bgcolor();
auto fgcolor = API::fgcolor(window_);
auto fgcolor = scheme_->foreground.get_color();
if (!API::window_enabled(window_))
fgcolor.blend(bgcolor, 0.5);
@@ -1727,7 +1727,7 @@ namespace nana{ namespace widgets
behavior_->pre_calc_line(points_.caret.y, width_pixels());
points_.caret.x ++;
if(refresh || _m_draw(c, secondary_before))
if (refresh || _m_update_caret_line(secondary_before))
render(true);
else
draw_scroll_rectangle();
@@ -2524,7 +2524,8 @@ namespace nana{ namespace widgets
//The line of text is in the range of selection
nana::upoint a, b;
graph_.set_text_color(clr);
graph_.set_color({ 0x33, 0x99, 0xFF });
graph_.set_color(scheme_->selection.get_color());
//The text is not selected or the whole line text is selected
if ((!_m_get_sort_select_points(a, b)) || (select_.a.y != str_pos.y && select_.b.y != str_pos.y))
@@ -2539,7 +2540,7 @@ namespace nana{ namespace widgets
{
if (selected)
{
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
graph_.rectangle({ text_pos, { str_w, line_h_pixels } }, true);
}
@@ -2556,11 +2557,11 @@ namespace nana{ namespace widgets
graph_.string(strpos, str, len);
paint::graphics graph(glyph_selected, line_h_pixels);
graph.typeface(this->graph_.typeface());
graph.rectangle(true, { 0x33, 0x99, 0xFF });
graph.rectangle(true, scheme_->selection.get_color());
int sel_xpos = static_cast<int>(str_px - (glyph_front + glyph_selected));
graph.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
graph.string({-sel_xpos, 0}, str, len);
graph_.bitblt(nana::rectangle(strpos.x + sel_xpos, strpos.y, glyph_selected, line_h_pixels), graph);
};
@@ -2584,7 +2585,7 @@ namespace nana{ namespace widgets
if (a.x <= pos && str_end <= b.x)
{
graph_.rectangle({ text_pos, { str_w, line_h_pixels } }, true);
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
}
else
graph_.set_text_color(clr);
@@ -2615,7 +2616,7 @@ namespace nana{ namespace widgets
graph_.rectangle({ part_pos, { sel_w, line_h_pixels } }, true);
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
graph_.string(part_pos, ent.begin + (a.x - pos), endpos - a.x);
if (static_cast<size_t>(endpos) < str_end)
@@ -2641,7 +2642,7 @@ namespace nana{ namespace widgets
{ //LTR
graph_.rectangle({ text_pos, { sel_w, line_h_pixels } }, true);
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
graph_.string(text_pos, ent.begin, endpos - pos);
graph_.set_text_color(clr);
graph_.string(text_pos + ::nana::point(static_cast<int>(sel_w), 0), ent.begin + (endpos - pos), str_end - endpos);
@@ -2666,7 +2667,7 @@ namespace nana{ namespace widgets
if (a.x < pos)
{
graph_.rectangle({ text_pos, { str_w, line_h_pixels } }, true, { 0x33, 0x99, 0xFF });
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
}
graph_.string(text_pos, ent.begin, len);
}
@@ -2684,7 +2685,7 @@ namespace nana{ namespace widgets
::nana::point part_pos{ text_pos.x + static_cast<int>(head_w), text_pos.y };
graph_.rectangle({ part_pos, {str_w - head_w, line_h_pixels } }, true);
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
graph_.string(part_pos, ent.begin + a.x - pos, len - (a.x - pos));
}
}
@@ -2708,7 +2709,7 @@ namespace nana{ namespace widgets
if (pos + len <= b.x)
{
graph_.rectangle({ text_pos, { str_w, line_h_pixels } }, true);
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
graph_.string(text_pos, ent.begin, len);
}
else if (pos <= b.x && b.x < pos + len)
@@ -2721,8 +2722,7 @@ namespace nana{ namespace widgets
else
{
graph_.rectangle({ text_pos, { sel_w, line_h_pixels } }, true);
graph_.set_text_color(colors::white);
graph_.set_text_color(scheme_->selection_text.get_color());
graph_.string(text_pos, ent.begin, b.x - pos);
graph_.set_text_color(clr);
graph_.string(text_pos + ::nana::point(static_cast<int>(sel_w), 0), ent.begin + b.x - pos, len - (b.x - pos));
@@ -2737,10 +2737,7 @@ namespace nana{ namespace widgets
}
}
//_m_draw
//@brief: Draw a character at a position specified by caret pos.
//@return: true if beyond the border
bool text_editor::_m_draw(nana::char_t c, std::size_t secondary_before)
bool text_editor::_m_update_caret_line(std::size_t secondary_before)
{
if (false == behavior_->adjust_caret_into_screen())
{

View File

@@ -71,8 +71,6 @@ namespace nana
public:
enum class style{horizontal, vertical};
enum class parts{none, bar, slider};
//enum dir_t{DirHorizontal, DirVertical}; //deprecated
//enum where_t{WhereNone, WhereBar, WhereSlider};
typedef drawer_trigger::graph_reference graph_reference;

View File

@@ -57,7 +57,9 @@ namespace nana{ namespace drawerbase {
widget_ = &wdg;
evt_agent_.reset(new event_agent(static_cast< ::nana::textbox&>(wdg)));
editor_ = new text_editor(wd, graph);
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_->border_renderer([this](graph_reference graph, const ::nana::color& clr){
this->_m_draw_border(graph, clr);