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

@@ -18,7 +18,6 @@
//Windows:
#define NANA_WINDOWS 1
#define PLATFORM_SPEC_HPP <nana/detail/win32/platform_spec.hpp>
#define GUI_BEDROCK_HPP <nana/gui/detail/bedrock.hpp>
//Test if it is MINGW
#if defined(__MINGW32__)
@@ -31,8 +30,6 @@
#define NANA_LINUX 1
#define NANA_X11 1
#define PLATFORM_SPEC_HPP <nana/detail/linux_X11/platform_spec.hpp>
#define GUI_BEDROCK_HPP <nana/gui/detail/bedrock.hpp>
#define STD_CODECVT_NOT_SUPPORTED
#endif

View File

@@ -14,7 +14,7 @@
#define NANA_GUI_DETAIL_BASIC_WINDOW_HPP
#include "drawer.hpp"
#include "events_holder.hpp"
#include "../basis.hpp"
#include "widget_colors.hpp"
#include <nana/basic_types.hpp>
#include <nana/system/platform.hpp>
#include <nana/gui/effects.hpp>
@@ -181,6 +181,8 @@ namespace detail
color bgcolor;
color activated;
}colors;
widget_colors* expr_colors{ nullptr };
struct
{

View File

@@ -16,6 +16,7 @@
#include "events_operation.hpp"
#include "runtime_manager.hpp"
#include "general_events.hpp"
#include "color_schemes.hpp"
#include "internal_scope_guard.hpp"
namespace nana
@@ -76,6 +77,9 @@ namespace detail
void set_cursor(core_window_t*, nana::cursor, thread_context*);
void define_state_cursor(core_window_t*, nana::cursor, thread_context*);
void undefine_state_cursor(core_window_t*, thread_context*);
widget_colors& get_scheme_template(scheme_factory_base&&);
std::unique_ptr<widget_colors> make_scheme(scheme_factory_base&&);
public:
window_manager_t wd_manager;
events_operation evt_operation;
@@ -92,6 +96,8 @@ namespace detail
private:
static bedrock bedrock_object;
struct pi_data;
pi_data* pi_data_;
struct private_impl;
private_impl *impl_;
};//end class bedrock

View File

@@ -0,0 +1,18 @@
#ifndef NANA_DETAIL_BEDROCK_PI_DATA_HPP
#define NANA_DETAIL_BEDROCK_PI_DATA_HPP
#include <nana/gui/detail/bedrock.hpp>
#include "color_schemes.hpp"
namespace nana
{
namespace detail
{
struct bedrock::pi_data
{
color_schemes scheme;
};
}
}
#endif

View File

@@ -0,0 +1,80 @@
/*
* Color Schemes
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/gui/color_schemes.hpp
* @description:
*/
#ifndef NANA_DETAIL_COLOR_SCHEMES_HPP
#define NANA_DETAIL_COLOR_SCHEMES_HPP
#include "widget_colors.hpp"
#include <nana/pat/cloneable.hpp>
namespace nana
{
namespace detail
{
class scheme_factory_base
{
public:
struct factory_identifier{};
virtual ~scheme_factory_base() = default;
virtual factory_identifier* get_id() const = 0;
virtual std::unique_ptr<widget_colors> create() = 0;
virtual std::unique_ptr<widget_colors> create(widget_colors&) = 0;
};
template<typename Scheme>
class scheme_factory
: public scheme_factory_base
{
private:
factory_identifier* get_id() const override
{
return &fid_;
}
std::unique_ptr<widget_colors> create() override
{
return std::unique_ptr<widget_colors>(new Scheme);
}
std::unique_ptr<widget_colors> create(widget_colors& other) override
{
return std::unique_ptr<widget_colors>{new Scheme(static_cast<Scheme&>(other))};
}
private:
static factory_identifier fid_;
};
template<typename Scheme>
scheme_factory_base::factory_identifier scheme_factory<Scheme>::fid_;
class color_schemes
{
struct implement;
color_schemes(const color_schemes&) = delete;
color_schemes(color_schemes&&) = delete;
color_schemes& operator=(const color_schemes&) = delete;
color_schemes& operator=(color_schemes&&) = delete;
public:
using scheme = widget_colors;
color_schemes();
~color_schemes();
scheme& scheme_template(scheme_factory_base&&);
std::unique_ptr<scheme> create(scheme_factory_base&&);
private:
implement * impl_;
};
}//end namespace detail;
}//end namespace nana
#endif

View File

@@ -28,21 +28,21 @@ namespace nana
class event_interface
{
public:
virtual ~event_interface(){}
virtual ~event_interface() = default;
virtual void remove(event_handle) = 0;
};
class docker_interface
{
public:
virtual ~docker_interface(){}
virtual ~docker_interface() = default;
virtual event_interface* get_event() const = 0;
};
class event_arg_interface
{
public:
virtual ~event_arg_interface(){}
virtual ~event_arg_interface() = default;
};
void events_operation_register(event_handle);
@@ -471,6 +471,7 @@ namespace nana
basic_event<arg_move> move;
basic_event<arg_resizing> resizing;
basic_event<arg_resized> resized;
basic_event<arg_destroy> destroy;
};

View File

@@ -0,0 +1,44 @@
/*
* Color Schemes
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/gui/color_schemes.hpp
* @description:
*/
#ifndef NANA_DETAIL_WIDGET_COLORS_HPP
#define NANA_DETAIL_WIDGET_COLORS_HPP
#include <nana/gui/basis.hpp>
#include <memory>
namespace nana
{
class color_proxy
{
public:
color_proxy(const color_proxy&);
color_proxy(color_rgb);
color_proxy(colors);
color_proxy& operator=(const color_proxy&);
color_proxy& operator=(const ::nana::color&);
color get_color() const;
operator color() const;
private:
std::shared_ptr<color> color_;
};//end namespace color_proxy
struct widget_colors
{
virtual ~widget_colors() = default;
color_proxy activated{ static_cast<color_rgb>(0x60C8FD) };
color_proxy background{colors::button_face};
color_proxy foreground{colors::black};
};
}
#endif

View File

@@ -13,7 +13,7 @@
#ifndef NANA_GUI_PROGRAMMING_INTERFACE_HPP
#define NANA_GUI_PROGRAMMING_INTERFACE_HPP
#include <nana/config.hpp>
#include GUI_BEDROCK_HPP
#include "detail/bedrock.hpp"
#include "effects.hpp"
#include "detail/general_events.hpp"
#include <nana/paint/image.hpp>
@@ -45,6 +45,16 @@ namespace API
}
bool set_events(window, const std::shared_ptr<general_events>&);
template<typename Scheme>
std::unique_ptr<Scheme> make_scheme()
{
return std::unique_ptr<Scheme>(
static_cast<Scheme*>(::nana::detail::bedrock::instance().make_scheme(::nana::detail::scheme_factory<Scheme>()).release()));
}
void set_scheme(window, widget_colors*);
widget_colors* get_scheme(window);
void attach_drawer(widget&, drawer_trigger&);
nana::string window_caption(window);
@@ -66,6 +76,13 @@ namespace API
void exit();
template<typename Scheme>
Scheme& get_scheme()
{
auto & brock = ::nana::detail::bedrock::instance();
return static_cast<Scheme&>(brock.get_scheme_template(::nana::detail::scheme_factory<Scheme>{}));
}
nana::string transform_shortkey_text(nana::string text, nana::string::value_type &shortkey, nana::string::size_type *skpos);
bool register_shortkey(window, unsigned long);
void unregister_shortkey(window);

View File

@@ -14,6 +14,7 @@
#define NANA_GUI_WIDGETS_COMBOX_HPP
#include "widget.hpp"
#include "float_listbox.hpp"
#include "skeletons/text_editor_scheme.hpp"
#include <nana/key_type.hpp>
#include <nana/concepts.hpp>
#include <functional>
@@ -160,7 +161,7 @@ namespace nana
}//end namespace drawerbase
class combox
: public widget_object<category::widget_tag, drawerbase::combox::trigger, drawerbase::combox::combox_events>,
: public widget_object<category::widget_tag, drawerbase::combox::trigger, drawerbase::combox::combox_events, ::nana::widgets::skeletons::text_editor_scheme>,
public nana::concepts::any_objective<std::size_t, 1>
{
public:

View File

@@ -47,6 +47,7 @@ namespace nana
form(window, const rectangle&, const appearance& = {});
void modality() const;
void wait_for_this();
};
class nested_form : public widget_object<category::root_tag, drawerbase::form::trigger, detail::events_root_extension>

View File

@@ -14,9 +14,9 @@
#ifndef NANA_GUI_SKELETONS_TEXT_EDITOR_HPP
#define NANA_GUI_SKELETONS_TEXT_EDITOR_HPP
#include "textbase.hpp"
#include "text_editor_scheme.hpp"
#include <nana/gui/widgets/scroll.hpp>
#include <nana/unicode_bidi.hpp>
#include <memory>
namespace nana{ namespace widgets
{
@@ -128,18 +128,18 @@ namespace nana{ namespace widgets
class undo_input_text;
class undo_move_text;
public:
typedef nana::char_t char_type;
typedef ::nana::char_t char_type;
typedef textbase<char_type>::size_type size_type;
typedef textbase<char_type>::string_type string_type;
typedef nana::paint::graphics & graph_reference;
typedef ::nana::paint::graphics & graph_reference;
struct ext_renderer_tag
{
std::function<void(graph_reference, const nana::rectangle& text_area, const ::nana::color&)> background;
};
text_editor(window, graph_reference);
text_editor(window, graph_reference, const text_editor_scheme*);
~text_editor();
bool respone_keyboard(nana::char_t, bool enterable);
@@ -263,10 +263,10 @@ namespace nana{ namespace widgets
//_m_draw_string
//@brief: Draw a line of string
void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const nana::string&, bool if_mask) const;
//_m_draw
//@brief: Draw a character at a position specified by caret pos.
//@return: true if beyond the border
bool _m_draw(nana::char_t, std::size_t secondary_before);
//_m_update_caret_line
//@brief: redraw whole line specified by caret pos.
//@return: true if caret overs the border
bool _m_update_caret_line(std::size_t secondary_before);
bool _m_get_sort_select_points(nana::upoint&, nana::upoint&) const;
void _m_offset_y(int y);
@@ -279,6 +279,8 @@ namespace nana{ namespace widgets
undoable<command> undo_;
nana::window window_;
graph_reference graph_;
const text_editor_scheme* scheme_;
skeletons::textbase<nana::char_t> textbase_;
nana::char_t mask_char_{0};

View File

@@ -0,0 +1,22 @@
#ifndef NANA_WIDGETS_SKELETONS_TEXT_EDITOR_SCHEME_HPP
#define NANA_WIDGETS_SKELETONS_TEXT_EDITOR_SCHEME_HPP
#include "../../detail/widget_colors.hpp"
namespace nana
{
namespace widgets
{
namespace skeletons
{
struct text_editor_scheme
: public ::nana::widget_colors
{
color_proxy selection{static_cast<color_rgb>(0x3399FF)};
color_proxy selection_text{colors::white};
};
}
}
}
#endif

View File

@@ -13,6 +13,7 @@
#define NANA_GUI_WIDGET_TEXTBOX_HPP
#include <nana/gui/widgets/widget.hpp>
#include "skeletons/textbase_export_interface.hpp"
#include "skeletons/text_editor_scheme.hpp"
namespace nana
{
@@ -96,7 +97,7 @@ namespace nana
/// Allow users to enter and edit text by typing on the keyboard.
class textbox
:public widget_object<category::widget_tag, drawerbase::textbox::drawer, drawerbase::textbox::textbox_events>
:public widget_object<category::widget_tag, drawerbase::textbox::drawer, drawerbase::textbox::textbox_events, ::nana::widgets::skeletons::text_editor_scheme>
{
public:
/// The default constructor without creating the widget.

View File

@@ -117,14 +117,17 @@ namespace nana
};
/// Base class of all the classes defined as a widget window. Defaultly a widget_tag
template<typename Category, typename DrawerTrigger, typename Events = nana::general_events>
template<typename Category, typename DrawerTrigger, typename Events = ::nana::general_events, typename Scheme = ::nana::widget_colors>
class widget_object: public widget
{
protected:
typedef DrawerTrigger drawer_trigger_t;
public:
using scheme_type = Scheme;
widget_object()
: events_(std::make_shared<Events>())
: events_{ std::make_shared<Events>() },
scheme_{ API::dev::make_scheme<Scheme>() }
{}
~widget_object()
@@ -143,12 +146,13 @@ namespace nana
return create(parent_wd, rectangle(), visible);
}
bool create(window parent_wd, const rectangle & r = rectangle(), bool visible = true) ///< in a widget/root window specified by parent_wd.
bool create(window parent_wd, const rectangle & r = {}, bool visible = true) ///< in a widget/root window specified by parent_wd.
{
if(parent_wd && this->empty())
{
handle_ = API::dev::create_widget(parent_wd, r, this);
API::dev::set_events(handle_, events_);
API::dev::set_scheme(handle_, scheme_.get());
API::dev::attach_signal(handle_, *this, &widget_object::signal);
API::dev::attach_drawer(*this, trigger_);
if(visible)
@@ -174,6 +178,11 @@ namespace nana
{
return API::widget_borderless(handle_);
}
scheme_type& scheme() const
{
return *scheme_;
}
protected:
DrawerTrigger& get_drawer_trigger()
{
@@ -212,18 +221,20 @@ namespace nana
window handle_{nullptr};
DrawerTrigger trigger_;
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
};//end class widget_object
/// Base class of all the classes defined as a non-graphics-buffer widget window. The second template parameter DrawerTrigger is always ignored.\see nana::panel
template<typename DrawerTrigger, typename Events>
class widget_object<category::lite_widget_tag, DrawerTrigger, Events>: public widget
template<typename DrawerTrigger, typename Events, typename Scheme>
class widget_object<category::lite_widget_tag, DrawerTrigger, Events, Scheme>: public widget
{
protected:
typedef DrawerTrigger drawer_trigger_t;
public:
using scheme_type = Scheme;
widget_object()
: events_(std::make_shared<Events>())
: events_{ std::make_shared<Events>() }, scheme_{ API::dev::make_scheme<scheme_type>() }
{}
~widget_object()
@@ -248,6 +259,7 @@ namespace nana
{
handle_ = API::dev::create_lite_widget(parent_wd, r, this);
API::dev::set_events(handle_, events_);
API::dev::set_scheme(handle_, scheme_.get());
if(visible)
API::show_window(handle_, true);
this->_m_complete_creation();
@@ -259,6 +271,11 @@ namespace nana
{
return handle_;
}
scheme_type& scheme() const
{
return *scheme_;
}
private:
void signal(detail::signals::code code, const detail::signals& sig)
{
@@ -286,16 +303,18 @@ namespace nana
private:
window handle_{nullptr};
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
};//end class widget_object
/// Base class of all the classes defined as a root window. \see nana::form
template<typename DrawerTrigger, typename Events>
class widget_object<category::root_tag, DrawerTrigger, Events>: public widget
template<typename DrawerTrigger, typename Events, typename Scheme>
class widget_object<category::root_tag, DrawerTrigger, Events, Scheme>: public widget
{
protected:
typedef DrawerTrigger drawer_trigger_t;
public:
using scheme_type = Scheme;
widget_object()
{
@@ -303,13 +322,13 @@ namespace nana
_m_bind_and_attach();
}
widget_object(const rectangle& r, const appearance& apr = appearance())
widget_object(const rectangle& r, const appearance& apr = {})
{
handle_ = API::dev::create_window(nullptr, false, r, apr, this);
_m_bind_and_attach();
}
widget_object(window owner, bool nested, const rectangle& r = rectangle(), const appearance& apr = appearance())
widget_object(window owner, bool nested, const rectangle& r = {}, const appearance& apr = {})
{
handle_ = API::dev::create_window(owner, nested, r, apr, this);
_m_bind_and_attach();
@@ -376,6 +395,11 @@ namespace nana
API::set_window_z_order(handle_, wd_after, action_if_no_wd_after);
return *this;
}
scheme_type& scheme() const
{
return *scheme_;
}
protected:
DrawerTrigger& get_drawer_trigger()
{
@@ -410,6 +434,9 @@ namespace nana
{
events_ = std::make_shared<Events>();
API::dev::set_events(handle_, events_);
scheme_ = API::dev::make_scheme<scheme_type>();
API::dev::set_scheme(handle_, scheme_.get());
API::dev::attach_signal(handle_, *this, &widget_object::signal);
API::dev::attach_drawer(*this, trigger_);
}
@@ -422,21 +449,24 @@ namespace nana
window handle_;
DrawerTrigger trigger_;
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
};//end class widget_object<root_tag>
/// Base class of all the classes defined as a frame window. \see nana::frame
template<typename Drawer, typename Events>
class widget_object<category::frame_tag, Drawer, Events>: public widget{};
template<typename Drawer, typename Events, typename Scheme>
class widget_object<category::frame_tag, Drawer, Events, Scheme>: public widget{};
/// Especialization. Base class of all the classes defined as a frame window. \see nana::frame
template<typename Events>
class widget_object<category::frame_tag, int, Events>: public widget
template<typename Events, typename Scheme>
class widget_object<category::frame_tag, int, Events, Scheme>: public widget
{
protected:
typedef int drawer_trigger_t;
public:
using scheme_type = Scheme;
widget_object()
: events_(std::make_shared<Events>())
: events_{ std::make_shared<Events>() }, scheme_{ API::dev::make_scheme<scheme_type>() }
{}
~widget_object()
@@ -461,6 +491,7 @@ namespace nana
{
handle_ = API::dev::create_frame(parent_wd, r, this);
API::dev::set_events(handle_, events_);
API::dev::set_scheme(handle_, scheme_.get());
API::dev::attach_signal(handle_, *this, &widget_object::signal);
API::show_window(handle_, visible);
this->_m_complete_creation();
@@ -472,6 +503,11 @@ namespace nana
{
return handle_;
}
scheme_type& scheme() const
{
return *scheme_;
}
private:
virtual drawer_trigger* get_drawer_trigger()
{
@@ -504,6 +540,7 @@ namespace nana
private:
window handle_{nullptr};
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
};//end class widget_object<category::frame_tag>
}//end namespace nana
#endif

View File

@@ -28,7 +28,6 @@ namespace gadget
void arrow_16_pixels(nana::paint::graphics&, int x, int y, const color&, uint32_t style, directions::t direction);
void close_16_pixels(nana::paint::graphics&, int x, int y, uint32_t style, const color&);
//void cross(nana::paint::graphics&, int x, int y, uint32_t size, uint32_t thickness, nana::color_t color); //deprecated
void cross(nana::paint::graphics&, int x, int y, uint32_t size, uint32_t thickness, const nana::color&);
}//end namespace gadget

View File

@@ -13,11 +13,6 @@ namespace nana
text_renderer(graph_reference graph, align = align::left);
//void render(int x, int y, nana::color_t, const nana::char_t*, std::size_t len); //deprecated
//void render(int x, int y, nana::color_t, const nana::char_t*, std::size_t len, unsigned restricted_pixels, bool omitted); //deprecated
//void render(int x, int y, nana::color_t, const nana::char_t*, std::size_t len, unsigned restricted_pixels); //deprecated
nana::size extent_size(int x, int y, const nana::char_t*, std::size_t len, unsigned restricted_pixels) const;
void render(const point&, const char_t*, std::size_t len);