From 42788db0777ecd472a86cdab02c68c7e71540933 Mon Sep 17 00:00:00 2001 From: cnjinhao Date: Wed, 17 Dec 2014 11:20:47 +0800 Subject: [PATCH] Breaking changes for expr_color expr_color is a temporary class name for new color type experiment. --- include/nana/basic_types.hpp | 14 +- include/nana/detail/win32/platform_spec.hpp | 1 + include/nana/gui/basis.hpp | 3 +- include/nana/gui/detail/basic_window.hpp | 6 +- include/nana/gui/detail/effects_renderer.hpp | 4 +- include/nana/gui/programming_interface.hpp | 2 + include/nana/gui/widgets/categorize.hpp | 2 +- include/nana/gui/widgets/combox.hpp | 6 +- include/nana/gui/widgets/date_chooser.hpp | 10 +- include/nana/gui/widgets/float_listbox.hpp | 8 +- include/nana/gui/widgets/form.hpp | 5 +- include/nana/gui/widgets/menu.hpp | 2 +- include/nana/gui/widgets/panel.hpp | 5 +- include/nana/gui/widgets/picture.hpp | 17 +- include/nana/gui/widgets/progress.hpp | 15 +- include/nana/gui/widgets/scroll.hpp | 4 +- .../gui/widgets/skeletons/text_editor.hpp | 16 +- .../widgets/skeletons/text_token_stream.hpp | 43 ++-- include/nana/gui/widgets/slider.hpp | 4 +- include/nana/gui/widgets/tabbar.hpp | 16 +- include/nana/gui/widgets/textbox.hpp | 2 +- include/nana/gui/widgets/toolbar.hpp | 4 +- include/nana/gui/widgets/widget.hpp | 4 +- include/nana/paint/gadget.hpp | 6 +- include/nana/paint/graphics.hpp | 44 ++-- include/nana/paint/text_renderer.hpp | 11 +- source/basic_types.cpp | 72 +++++- source/detail/win32/platform_spec.cpp | 5 + source/gui/detail/basic_window.cpp | 12 +- source/gui/effects.cpp | 4 +- source/gui/element.cpp | 4 +- source/gui/programming_interface.cpp | 26 ++- source/gui/tooltip.cpp | 4 +- source/gui/widgets/button.cpp | 24 +- source/gui/widgets/categorize.cpp | 104 ++++++--- source/gui/widgets/checkbox.cpp | 16 +- source/gui/widgets/combox.cpp | 113 +++++----- source/gui/widgets/date_chooser.cpp | 50 +++-- source/gui/widgets/float_listbox.cpp | 58 ++--- source/gui/widgets/form.cpp | 9 +- source/gui/widgets/label.cpp | 32 +-- source/gui/widgets/listbox.cpp | 74 ++++--- source/gui/widgets/menu.cpp | 41 ++-- source/gui/widgets/menubar.cpp | 43 ++-- source/gui/widgets/panel.cpp | 6 +- source/gui/widgets/picture.cpp | 25 +-- source/gui/widgets/progress.cpp | 14 +- source/gui/widgets/scroll.cpp | 92 ++++---- source/gui/widgets/skeletons/text_editor.cpp | 138 +++++++----- source/gui/widgets/slider.cpp | 42 ++-- source/gui/widgets/tabbar.cpp | 206 ++++++++---------- source/gui/widgets/textbox.cpp | 10 +- source/gui/widgets/toolbar.cpp | 80 +++---- source/gui/widgets/treebox.cpp | 28 +-- source/gui/widgets/widget.cpp | 4 +- source/paint/gadget.cpp | 176 +++++++-------- source/paint/graphics.cpp | 148 ++++++++++++- source/paint/text_renderer.cpp | 45 +++- 58 files changed, 1135 insertions(+), 824 deletions(-) diff --git a/include/nana/basic_types.hpp b/include/nana/basic_types.hpp index 16dcbbdc..f56acde4 100644 --- a/include/nana/basic_types.hpp +++ b/include/nana/basic_types.hpp @@ -98,10 +98,10 @@ namespace nana typedef unsigned char uint8_t; typedef unsigned long uint32_t; typedef unsigned uint_t; - typedef unsigned color_t; + typedef unsigned color_t; //deprecated typedef long long long_long_t; - const color_t null_color = 0xFFFFFFFF; + //const color_t null_color = 0xFFFFFFFF; //deprecated union pixel_argb_t { @@ -141,6 +141,7 @@ namespace nana red = 0xFF0000, white = 0xFFFFFF, + //temporary defintions, these will be replaced by color schema button_face_shadow_start = 0xF5F4F2, button_face_shadow_end = 0xD5D2CA, button_face = 0xD4D0C8, @@ -158,12 +159,17 @@ namespace nana expr_color(unsigned red, unsigned green, unsigned blue); expr_color(unsigned red, unsigned green, unsigned blue, double alpha); - void blend(const expr_color& bgcolor, bool ignore_bgcolor_alpha); + expr_color& alpha(double); ///< Sets alpha channel + expr_color& from_rgb(unsigned red, unsigned green, unsigned blue); ///< immutable alpha channel + expr_color& from_hsl(double hue, double saturation, double lightness); ///< immutable alpha channel + + expr_color& blend(const expr_color& bgcolor, bool ignore_bgcolor_alpha); ///< Blends two colors with the specified alpha, and the alpha values that come with these two colors are both ignored. - void blend(const expr_color& bgcolor, double alpha); + expr_color& blend(const expr_color& bgcolor, double alpha); bool invisible() const; + pixel_color_t px_color() const; pixel_argb_t argb() const; pixel_rgba_t rgba() const; diff --git a/include/nana/detail/win32/platform_spec.hpp b/include/nana/detail/win32/platform_spec.hpp index e10814b3..353d0136 100644 --- a/include/nana/detail/win32/platform_spec.hpp +++ b/include/nana/detail/win32/platform_spec.hpp @@ -137,6 +137,7 @@ namespace detail ~drawable_impl_type(); void fgcolor(nana::color_t); //deprecated + unsigned get_color() const; void set_color(nana::color_t); void set_text_color(nana::color_t); diff --git a/include/nana/gui/basis.hpp b/include/nana/gui/basis.hpp index bdaa3a91..0937a4cc 100644 --- a/include/nana/gui/basis.hpp +++ b/include/nana/gui/basis.hpp @@ -97,7 +97,7 @@ namespace nana os_insert = 0x2D, os_del }; }; - + /* namespace color //deprecated { enum @@ -115,6 +115,7 @@ namespace nana highlight = 0x1CC4F7 }; }; + */ enum class cursor { diff --git a/include/nana/gui/detail/basic_window.hpp b/include/nana/gui/detail/basic_window.hpp index 418d557a..b4c08aed 100644 --- a/include/nana/gui/detail/basic_window.hpp +++ b/include/nana/gui/detail/basic_window.hpp @@ -177,9 +177,9 @@ namespace detail struct { - color_t foreground; //deprecated - color_t background; //deprecated - color_t active; //deprecated + //color_t foreground; //deprecated + //color_t background; //deprecated + //color_t active; //deprecated expr_color fgcolor; expr_color bgcolor; diff --git a/include/nana/gui/detail/effects_renderer.hpp b/include/nana/gui/detail/effects_renderer.hpp index 29eb43d4..2a3c340a 100644 --- a/include/nana/gui/detail/effects_renderer.hpp +++ b/include/nana/gui/detail/effects_renderer.hpp @@ -120,12 +120,12 @@ namespace nana{ good_r.x = good_r.y = 1; good_r.width = r.width - 2; good_r.height = r.height - 2; - pixbuf.rectangle(good_r, wd->colors.active, 0.95, false); + pixbuf.rectangle(good_r, wd->colors.activated.px_color().value, 0.95, false); good_r.x = good_r.y = 0; good_r.width = r.width; good_r.height = r.height; - pixbuf.rectangle(good_r, wd->colors.active, 0.4, false); + pixbuf.rectangle(good_r, wd->colors.activated.px_color().value, 0.4, false); pixbuf.pixel(0, 0, px0); pixbuf.pixel(r.width - 1, 0, px1); diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index bc45110c..be64cfe4 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -202,12 +202,14 @@ namespace API void modal_window(window); ///< Blocks the routine til the specified window is closed. void wait_for(window); + /* color_t foreground(window); //deprecated color_t foreground(window, color_t); //deprecated color_t background(window); //deprecated color_t background(window, color_t); //deprecated color_t active(window); //deprecated color_t active(window, color_t); //deprecated + */ expr_color fgcolor(window); expr_color fgcolor(window, const expr_color&); diff --git a/include/nana/gui/widgets/categorize.hpp b/include/nana/gui/widgets/categorize.hpp index 204e4fc5..c5b6b705 100644 --- a/include/nana/gui/widgets/categorize.hpp +++ b/include/nana/gui/widgets/categorize.hpp @@ -164,7 +164,7 @@ namespace nana categorize(window wd, const rectangle& r = rectangle(), bool visible = true) { - this->get_drawer_trigger().template create_event_agent(*this); + this->get_drawer_trigger().create_event_agent(*this); this->create(wd, r, visible); } diff --git a/include/nana/gui/widgets/combox.hpp b/include/nana/gui/widgets/combox.hpp index fc00c092..0a46eed1 100644 --- a/include/nana/gui/widgets/combox.hpp +++ b/include/nana/gui/widgets/combox.hpp @@ -169,15 +169,15 @@ namespace nana combox(); combox(window, bool visible); - combox(window, const nana::string& text, bool visible = true); - combox(window, const nana::char_t* text, bool visible = true); + combox(window, nana::string, bool visible = true); + combox(window, const nana::char_t*, bool visible = true); combox(window, const rectangle& r = rectangle(), bool visible = true); void clear(); void editable(bool); bool editable() const; void set_accept(std::function); - combox& push_back(const nana::string&); + combox& push_back(nana::string); std::size_t the_number_of_options() const; std::size_t option() const; ///< Index of the last selected, from drop-down list, item. void option(std::size_t); ///< Select the text specified by index diff --git a/include/nana/gui/widgets/date_chooser.hpp b/include/nana/gui/widgets/date_chooser.hpp index 03b47c5d..f8d720ae 100644 --- a/include/nana/gui/widgets/date_chooser.hpp +++ b/include/nana/gui/widgets/date_chooser.hpp @@ -45,7 +45,7 @@ namespace nana void week_name(unsigned index, const nana::string&); void month_name(unsigned index, const nana::string&); private: - void _m_init_color(); + //void _m_init_color(); //deprecated where _m_pos_where(graph_reference, int x, int y); void _m_draw(graph_reference); void _m_draw_topbar(graph_reference); @@ -91,10 +91,10 @@ namespace nana struct color_tag { - nana::color_t highlight; - nana::color_t selected; - nana::color_t normal; - nana::color_t bkcolor; + ::nana::expr_color highlight; + ::nana::expr_color selected; + ::nana::expr_color normal; + ::nana::expr_color bgcolor; }color_; }; diff --git a/include/nana/gui/widgets/float_listbox.hpp b/include/nana/gui/widgets/float_listbox.hpp index 146a220f..67e48591 100644 --- a/include/nana/gui/widgets/float_listbox.hpp +++ b/include/nana/gui/widgets/float_listbox.hpp @@ -37,11 +37,9 @@ namespace nana { std::vector> items; - std::size_t max_items; // the number of items display. - mutable std::size_t index; // the result of the selection. + std::size_t max_items{10}; // the number of items display. + mutable std::size_t index{::nana::npos}; // the result of the selection. mutable bool have_selected; - - module_def(); }; class item_renderer @@ -51,7 +49,7 @@ namespace nana typedef paint::graphics& graph_reference; enum state_t{StateNone, StateHighlighted}; - virtual ~item_renderer() = 0; + virtual ~item_renderer() = default; virtual void image(bool enabled, unsigned pixels) = 0; virtual void render(widget_reference, graph_reference, const nana::rectangle&, const item_interface*, state_t) = 0; virtual unsigned item_pixels(graph_reference) const = 0; diff --git a/include/nana/gui/widgets/form.hpp b/include/nana/gui/widgets/form.hpp index 4f6c0aaf..7ea58b5f 100644 --- a/include/nana/gui/widgets/form.hpp +++ b/include/nana/gui/widgets/form.hpp @@ -24,12 +24,11 @@ namespace nana class trigger: public drawer_trigger { public: - trigger(); void attached(widget_reference, graph_reference) override; void refresh(graph_reference) override; - void resized(graph_reference, const arg_resized&) override; + //void resized(graph_reference, const arg_resized&) override; //deprecated private: - widget* wd_; + widget* wd_{nullptr}; }; }//end namespace form }//end namespace drawerbase diff --git a/include/nana/gui/widgets/menu.hpp b/include/nana/gui/widgets/menu.hpp index 7e072324..36f99a28 100644 --- a/include/nana/gui/widgets/menu.hpp +++ b/include/nana/gui/widgets/menu.hpp @@ -104,7 +104,7 @@ namespace nana checks check_style; }; - virtual ~renderer_interface() = 0; + virtual ~renderer_interface() = default; virtual void background(graph_reference, window) = 0; virtual void item(graph_reference, const nana::rectangle&, const attr&) = 0; diff --git a/include/nana/gui/widgets/panel.hpp b/include/nana/gui/widgets/panel.hpp index a9dc6a18..6dc1363e 100644 --- a/include/nana/gui/widgets/panel.hpp +++ b/include/nana/gui/widgets/panel.hpp @@ -25,13 +25,10 @@ namespace nana { class drawer: public drawer_trigger { - public: - drawer(); - private: void attached(widget_reference, graph_reference) override; void refresh(graph_reference) override; private: - window window_; + window window_{nullptr}; }; }// end namespace panel }//end namespace drawerbase diff --git a/include/nana/gui/widgets/picture.hpp b/include/nana/gui/widgets/picture.hpp index 7238fe32..f747eb9f 100644 --- a/include/nana/gui/widgets/picture.hpp +++ b/include/nana/gui/widgets/picture.hpp @@ -26,7 +26,7 @@ namespace nana void attached(widget_reference, graph_reference) override; void load(const nana::char_t* file); void load(const nana::paint::image&); - void set_shadow_background(unsigned begin_color, unsigned end_color, bool horizontal); + void set_shadow_background(const ::nana::expr_color& from, const ::nana::expr_color& to, bool horizontal); bool bgstyle(bool is_stretch, nana::arrange, int beg, int end); private: void refresh(graph_reference) override; @@ -35,13 +35,14 @@ namespace nana widget* widget_; nana::paint::graphics* graph_; - struct runtime_type + struct { - runtime_type(); - unsigned background_shadow_start; - unsigned background_shadow_end; + //unsigned background_shadow_start; //deprecated + //unsigned background_shadow_end; + ::nana::expr_color gradual_from; + ::nana::expr_color gradual_to; bool horizontal; - }runtime_; + }bground_; struct back_image_tag { @@ -72,8 +73,8 @@ namespace nana int end ///< specify the stretchy area of image. ); - /// Fills a gradual change color in background. - void set_shadow_background(unsigned begin_color, unsigned end_color, bool horizontal); + /// Fills a gradual-change color in background. If One of colors is invisible or clr_from is equal to clr_to, it draws background in bgcolor. + void set_gradual_background(const ::nana::expr_color& clr_from, const ::nana::expr_color& clr_to, bool horizontal); void transparent(bool); bool transparent() const; }; diff --git a/include/nana/gui/widgets/progress.hpp b/include/nana/gui/widgets/progress.hpp index 6b12fee5..9e849f75 100644 --- a/include/nana/gui/widgets/progress.hpp +++ b/include/nana/gui/widgets/progress.hpp @@ -23,7 +23,6 @@ namespace nana class trigger: public drawer_trigger { public: - trigger(); unsigned value() const; unsigned value(unsigned); unsigned inc(); @@ -41,13 +40,13 @@ namespace nana bool _m_check_changing(unsigned) const; private: static const unsigned border = 2; - widget * widget_; - nana::paint::graphics* graph_; - unsigned draw_width_; - bool has_value_; - bool unknown_; - unsigned max_; - unsigned value_; + widget * widget_{nullptr}; + nana::paint::graphics* graph_{nullptr}; + unsigned draw_width_{static_cast(-1)}; + bool has_value_{true}; + bool unknown_{false}; + unsigned max_{100}; + unsigned value_{0}; }; //end class drawer } }//end namespace drawerbase diff --git a/include/nana/gui/widgets/scroll.hpp b/include/nana/gui/widgets/scroll.hpp index 26421b48..0cd2775f 100644 --- a/include/nana/gui/widgets/scroll.hpp +++ b/include/nana/gui/widgets/scroll.hpp @@ -81,9 +81,9 @@ namespace nana bool _m_check() const; void _m_adjust_scroll(graph_reference); void _m_background(graph_reference); - void _m_button_frame(graph_reference, int x, int y, unsigned width, unsigned height, int state); + void _m_button_frame(graph_reference, ::nana::rectangle, int state); void _m_draw_scroll(graph_reference, int state); - void _m_draw_button(graph_reference, int x, int y, unsigned width, unsigned height, buttons what, int state); + void _m_draw_button(graph_reference, ::nana::rectangle, buttons what, int state); private: metrics_type &metrics_; bool vertical_; diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 0af6b895..a513e29e 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -136,7 +136,7 @@ namespace nana{ namespace widgets struct ext_renderer_tag { - std::function background; + std::function background; }; text_editor(window, graph_reference); @@ -151,7 +151,7 @@ namespace nana{ namespace widgets /// Set the text_editor whether it is line wrapped, it returns false if the state is not changed. bool line_wrapped(bool); - void border_renderer(std::function); + void border_renderer(std::function); bool load(const nana::char_t*); @@ -227,15 +227,15 @@ namespace nana{ namespace widgets skeletons::textbase& textbase(); const skeletons::textbase& textbase() const; private: - nana::color_t _m_bgcolor() const; + ::nana::expr_color _m_bgcolor() const; bool _m_scroll_text(bool vertical); void _m_on_scroll(const arg_mouse&); void _m_scrollbar(); - nana::size _m_text_area() const; + ::nana::size _m_text_area() const; void _m_get_scrollbar_size(); void _m_reset(); - nana::upoint _m_put(nana::string); - nana::upoint _m_erase_select(); + ::nana::upoint _m_put(nana::string); + ::nana::upoint _m_erase_select(); bool _m_make_select_string(nana::string&) const; static bool _m_resolve_text(const nana::string&, std::vector> & lines); @@ -262,7 +262,7 @@ namespace nana{ namespace widgets //_m_draw_string //@brief: Draw a line of string - void _m_draw_string(int top, nana::color_t color, const nana::upoint& str_pos, const nana::string&, bool if_mask) const; + void _m_draw_string(int top, const ::nana::expr_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 @@ -308,7 +308,7 @@ namespace nana{ namespace widgets unsigned scroll_pixels; unsigned vscroll; unsigned hscroll; - std::function border_renderer; + std::function border_renderer; }text_area_; struct selection diff --git a/include/nana/gui/widgets/skeletons/text_token_stream.hpp b/include/nana/gui/widgets/skeletons/text_token_stream.hpp index a753f3f4..cb517685 100644 --- a/include/nana/gui/widgets/skeletons/text_token_stream.hpp +++ b/include/nana/gui/widgets/skeletons/text_token_stream.hpp @@ -439,16 +439,16 @@ namespace nana{ namespace widgets{ namespace skeletons }; }; - nana::string font; + ::nana::string font; std::size_t font_size; bool bold; bool bold_empty; //bold should be ignored if bold_empty is true aligns::t text_align; - nana::color_t bgcolor; //If the color is not specified, it will be ignored, and the system will search for its parent. - nana::color_t fgcolor; //ditto + ::nana::expr_color bgcolor; //If the color is not specified, it will be ignored, and the system will search for its parent. + ::nana::expr_color fgcolor; //ditto - nana::string target; - nana::string url; + ::nana::string target; + ::nana::string url; fblock * parent; }; @@ -741,41 +741,45 @@ namespace nana{ namespace widgets{ namespace skeletons switch(tknizer.read()) { case token::number: - fp->fgcolor = tknizer.number(); + { + pixel_color_t px; + px.value = static_cast(tknizer.number()); + fp->fgcolor = {px.element.red, px.element.green, px.element.blue}; + } break; case token::red: - fp->fgcolor = 0xFF0000; + fp->fgcolor = colors::red; break; case token::green: - fp->fgcolor = 0xFF00; + fp->fgcolor = colors::green; break; case token::blue: - fp->fgcolor = 0xFF; + fp->fgcolor = colors::blue; break; case token::white: - fp->fgcolor = 0xFFFFFF; + fp->fgcolor = colors::white; break; case token::black: - fp->fgcolor = 0x0; + fp->fgcolor = colors::black; break; default: throw std::runtime_error(""); } break; case token::red: //support the omitting of color. - fp->fgcolor = 0xFF0000; + fp->fgcolor = colors::red; break; case token::green: //support the omitting of color. - fp->fgcolor = 0xFF00; + fp->fgcolor = colors::green; break; case token::blue: //support the omitting of color. - fp->fgcolor = 0xFF; + fp->fgcolor = colors::blue; break; case token::white: //support the omitting of color. - fp->fgcolor = 0xFFFFFF; + fp->fgcolor = colors::white; break; case token::black: //support the omitting of color. - fp->fgcolor = 0x0; + fp->fgcolor = colors::black; break; case token::baseline: fp->text_align = fblock::aligns::baseline; @@ -867,10 +871,6 @@ namespace nana{ namespace widgets{ namespace skeletons fbp->bold_empty = true; fbp->text_align = fblock::aligns::baseline; - //Refer to the definition for the color specification. - fbp->bgcolor = 0xFFFFFFFF; - fbp->fgcolor = 0xFFFFFFFF; - fbp->parent = nullptr; fblocks_.push_back(fbp); @@ -910,8 +910,7 @@ namespace nana{ namespace widgets{ namespace skeletons v.data_ptr = new data_text(idstr); break; default: - int * debug = 0; //for debug - *debug = 0; + break; } line.push_back(v); diff --git a/include/nana/gui/widgets/slider.hpp b/include/nana/gui/widgets/slider.hpp index 51ada7e5..01769e02 100644 --- a/include/nana/gui/widgets/slider.hpp +++ b/include/nana/gui/widgets/slider.hpp @@ -41,7 +41,7 @@ namespace nana class provider { public: - virtual ~provider() = 0; + virtual ~provider() = default; virtual nana::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0; }; @@ -74,7 +74,7 @@ namespace nana unsigned vcur_scale; //pixels of vcur scale. }; - virtual ~renderer() = 0; + virtual ~renderer() = default; virtual void background(window, graph_reference, bool isglass) = 0; virtual void adorn(window, graph_reference, const adorn_t&) = 0; diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 3e265a55..63e6e50b 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -57,7 +57,7 @@ namespace nana class event_agent_interface { public: - virtual ~event_agent_interface() = 0; + virtual ~event_agent_interface() = default; virtual void added(std::size_t) = 0; virtual void activated(std::size_t) = 0; virtual bool removed(std::size_t) = 0; @@ -67,18 +67,18 @@ namespace nana { public: typedef item_renderer item_renderer_type; - typedef nana::paint::graphics & graph_reference; + typedef ::nana::paint::graphics & graph_reference; enum state_t{disable, normal, highlight, press}; struct item_t { - nana::rectangle r; - nana::color_t bgcolor; - nana::color_t fgcolor; + ::nana::rectangle r; + ::nana::expr_color bgcolor; + ::nana::expr_color fgcolor; }; - virtual ~item_renderer() = 0; - virtual void background(graph_reference, const nana::rectangle& r, nana::color_t bgcolor) = 0; + virtual ~item_renderer() = default; + virtual void background(graph_reference, const nana::rectangle& r, const ::nana::expr_color& bgcolor) = 0; virtual void item(graph_reference, const item_t&, bool active, state_t) = 0; virtual void close_fly(graph_reference, const nana::rectangle&, bool active, state_t) = 0; @@ -150,7 +150,7 @@ namespace nana std::size_t length() const; bool close_fly(bool); void relate(size_t, window); - void tab_color(std::size_t, bool is_bgcolor, nana::color_t); + void tab_color(std::size_t, bool is_bgcolor, const ::nana::expr_color&); void tab_image(size_t, const nana::paint::image&); void text(std::size_t, const nana::string&); nana::string text(std::size_t) const; diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index 8bebeb76..d4ea9c65 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -79,7 +79,7 @@ namespace nana void typeface_changed(graph_reference) override; private: void _m_text_area(unsigned width, unsigned height); - void _m_draw_border(graph_reference, nana::color_t bgcolor); + void _m_draw_border(graph_reference, const ::nana::expr_color& bgcolor); private: widget* widget_; struct status_type diff --git a/include/nana/gui/widgets/toolbar.hpp b/include/nana/gui/widgets/toolbar.hpp index fd3b43df..1a155484 100644 --- a/include/nana/gui/widgets/toolbar.hpp +++ b/include/nana/gui/widgets/toolbar.hpp @@ -67,7 +67,7 @@ namespace nana void mouse_up(graph_reference, const arg_mouse&) override; private: size_type _m_which(int x, int y, bool want_if_disabled) const; - void _m_draw_background(nana::color_t); + void _m_draw_background(const ::nana::expr_color&); void _m_draw(); void _m_owner_sized(const arg_resized&); private: @@ -87,7 +87,7 @@ namespace nana public: typedef std::size_t size_type; ///< A type to count the number of elements. - toolbar(); + toolbar() = default; toolbar(window, bool visible); toolbar(window, const rectangle& = rectangle(), bool visible = true); diff --git a/include/nana/gui/widgets/widget.hpp b/include/nana/gui/widgets/widget.hpp index 53e10b70..5b57106a 100644 --- a/include/nana/gui/widgets/widget.hpp +++ b/include/nana/gui/widgets/widget.hpp @@ -73,12 +73,14 @@ namespace nana void move(int x, int y); void move(const rectangle&); + /* void foreground(nana::color_t); //deprecated nana::color_t foreground() const; void background(nana::color_t); nana::color_t background() const; + */ - void fgcolor(const nana::expr_color&); //deprecated + void fgcolor(const nana::expr_color&); nana::expr_color fgcolor() const; void bgcolor(const nana::expr_color&); nana::expr_color bgcolor() const; diff --git a/include/nana/paint/gadget.hpp b/include/nana/paint/gadget.hpp index 3aab2e44..f258d50b 100644 --- a/include/nana/paint/gadget.hpp +++ b/include/nana/paint/gadget.hpp @@ -26,9 +26,9 @@ namespace gadget enum t{to_east, to_southeast, to_south, to_southwest, to_west, to_northwest, to_north, to_northeast}; }; - void arrow_16_pixels(nana::paint::graphics&, int x, int y, unsigned color, uint32_t style, directions::t direction); - void close_16_pixels(nana::paint::graphics&, int x, int y, uint32_t style, uint32_t color); - void cross(nana::paint::graphics&, int x, int y, uint32_t size, uint32_t thickness, nana::color_t color); //deprecated + void arrow_16_pixels(nana::paint::graphics&, int x, int y, const expr_color&, uint32_t style, directions::t direction); + void close_16_pixels(nana::paint::graphics&, int x, int y, uint32_t style, const expr_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::expr_color&); }//end namespace gadget diff --git a/include/nana/paint/graphics.hpp b/include/nana/paint/graphics.hpp index e063e335..eeeb2f4b 100644 --- a/include/nana/paint/graphics.hpp +++ b/include/nana/paint/graphics.hpp @@ -99,12 +99,13 @@ namespace nana bool text_metrics(unsigned & ascent, unsigned& descent, unsigned& internal_leading) const; - unsigned bidi_string(int x, int y, color_t, const char_t *, std::size_t len); - void string(int x, int y, color_t, const ::nana::string&, std::size_t len); - void string(int x, int y, color_t, const ::nana::string&); - void string(int x, int y, color_t, const char_t*, std::size_t len); - void string(int x, int y, color_t, const char_t*); + //unsigned bidi_string(int x, int y, color_t, const char_t *, std::size_t len); //deprecated + //void string(int x, int y, color_t, const ::nana::string&, std::size_t len); + //void string(int x, int y, color_t, const ::nana::string&); + //void string(int x, int y, color_t, const char_t*, std::size_t len); + //void string(int x, int y, color_t, const char_t*); + /* void set_pixel(int x, int y, color_t); void rectangle(int x, int y, unsigned width, unsigned height, color_t, bool solid); void rectangle(color_t, bool solid); @@ -119,8 +120,9 @@ namespace nana void line(int x1, int y1, int x2, int y2, color_t); ///< Draws a line from point (x1, y1) to point (x2, y2) in the specified color. void line(const point& beg, const point& end, color_t); void lines(const point* points, std::size_t n_of_points, color_t); - void line_begin(int x, int y); void line_to(int x, int y, color_t); + */ + void line_begin(int x, int y); void bitblt(int x, int y, const graphics& source); ///< Transfers the source to the specified point. void bitblt(const ::nana::rectangle& r_dst, native_window_type src); ///< Transfers the color data corresponding to r_dst from the src window to this graphics. @@ -141,7 +143,7 @@ namespace nana void rgb_to_wb(); ///< Transform a color graphics into black&white. void stretch(const ::nana::rectangle& src_r, graphics& dst, const ::nana::rectangle& r) const; - void stretch(graphics& dst, const ::nana::rectangle& r) const; + void stretch(graphics& dst, const ::nana::rectangle&) const; void flush(); @@ -152,20 +154,36 @@ namespace nana void release(); void save_as_file(const char*); - static color_t mix(color_t colorX, color_t colorY, double persent); //deprecated + //static color_t mix(color_t colorX, color_t colorY, double persent); //deprecated void set_color(const ::nana::expr_color&); void set_text_color(const ::nana::expr_color&); unsigned bidi_string(const nana::point&, const char_t *, std::size_t len); - void string(nana::point, const char_t*, std::size_t len); - void string(const nana::point&, const char_t*); - void string(const nana::point&, const nana::string&); - void line(const nana::point&, const nana::point&); + void blend(const ::nana::rectangle& r, const ::nana::expr_color&, double fade_rate); + + void set_pixel(int x, int y, const ::nana::expr_color&); + void set_pixel(int x, int y); + + void string(point, const char_t*, std::size_t len); + void string(const point&, const char_t*); + void string(const point&, const ::nana::string&); + void string(const point&, const ::nana::string&, const expr_color&); + + void line(const point&, const point&); + void line(const point&, const point&, const expr_color&); + void line_to(const point&, const expr_color&); + void line_to(const point&); + + void rectangle(bool solid); + void rectangle(bool solid, const expr_color&); void rectangle(const ::nana::rectangle&, bool solid); + void rectangle(const ::nana::rectangle&, bool solid, const expr_color&); + void frame_rectangle(const ::nana::rectangle&, const expr_color& left, const expr_color& top, const expr_color& right, const expr_color& bottom); - void gradual_rectangle(const ::nana::rectangle&, const ::nana::expr_color& from, const ::nana::expr_color& to, bool vertical); + void gradual_rectangle(const ::nana::rectangle&, const expr_color& from, const expr_color& to, bool vertical); + void round_rectangle(const ::nana::rectangle&, unsigned radius_x, unsigned radius_y, const expr_color&, bool solid, const expr_color& color_if_solid); private: std::shared_ptr< ::nana::detail::drawable_impl_type> dwptr_; font font_shadow_; diff --git a/include/nana/paint/text_renderer.hpp b/include/nana/paint/text_renderer.hpp index 1b488702..7ee77050 100644 --- a/include/nana/paint/text_renderer.hpp +++ b/include/nana/paint/text_renderer.hpp @@ -13,13 +13,16 @@ 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); - void render(int x, int y, nana::color_t, const nana::char_t*, std::size_t len, unsigned restricted_pixels, bool omitted); + //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 - void render(int x, int y, nana::color_t, const nana::char_t*, std::size_t len, unsigned restricted_pixels); nana::size extent_size(int x, int y, const nana::char_t*, std::size_t len, unsigned restricted_pixels) const; - void render(const nana::point&, const nana::char_t*, std::size_t len, unsigned restricted_pixels, bool omiited); + void render(const point&, const char_t*, std::size_t len); + void render(const point&, const char_t*, std::size_t len, unsigned restricted_pixels, bool omitted); + void render(const point&, const char_t*, std::size_t len, unsigned restricted_pixels); private: graph_reference graph_; align text_align_; diff --git a/source/basic_types.cpp b/source/basic_types.cpp index 357e7fa4..7cea5221 100644 --- a/source/basic_types.cpp +++ b/source/basic_types.cpp @@ -39,7 +39,64 @@ namespace nana a_ = 1.0; } - void expr_color::blend(const expr_color& bgcolor, bool ignore_bgcolor_alpha) + expr_color& expr_color::from_rgb(unsigned red, unsigned green, unsigned blue) + { + r_ = red; + g_ = green; + b_ = blue; + return *this; + } + + double rgb_from_hue(double v1, double v2, double h) + { + if (h < 0.0) + h += 1.0; + else if (h > 1.0) + h -= 1.0; + + if (h < 0.1666666) return v1 + (v2 - v1) * (6.0 * h); + if (h < 0.5) return v2; + if (h < 0.6666666) return v1 + (v2 - v1) * (4.0 - h * 6.0); + return v1; + } + + expr_color& expr_color::from_hsl(double hue, double saturation, double lightness) + { + if (0.0 == saturation) + { + r_ = lightness * 255.0; + g_ = r_; + b_ = r_; + } + else + { + double var2; + if (lightness < 0.5) + var2 = lightness * (1.0 + saturation); + else + var2 = (lightness + saturation) - (saturation * lightness); + + double var1 = 2.0 * lightness - var2; + + r_ = 255.0 * rgb_from_hue(var1, var2, hue + 0.33333); + g_ = 255.0 * rgb_from_hue(var1, var2, hue); + b_ = 255.0 * rgb_from_hue(var1, var2, hue - 0.33333); + } + return *this; + } + + expr_color& expr_color::alpha(double al) + { + if (al < 0.0) + a_ = 0.0; + else if (al > 1.0) + a_ = 1.0; + else + a_ = al; + return *this; + } + + expr_color& expr_color::blend(const expr_color& bgcolor, bool ignore_bgcolor_alpha) { if (a_ < 1.0) { @@ -68,20 +125,27 @@ namespace nana a_ = (ignore_bgcolor_alpha ? 1.0 : bgcolor.a_); } } + return *this; } - void expr_color::blend(const expr_color& bgcolor, double alpha) + expr_color& expr_color::blend(const expr_color& bgcolor, double alpha) { r_ = r_ * alpha + bgcolor.r_ * (1.0 - alpha); g_ = g_ * alpha + bgcolor.g_ * (1.0 - alpha); b_ = b_ * alpha + bgcolor.b_ * (1.0 - alpha); a_ = 1.0; + return *this; } bool expr_color::invisible() const { return (a_ == 0.0); } + + pixel_color_t expr_color::px_color() const + { + return argb(); + } pixel_argb_t expr_color::argb() const { @@ -123,11 +187,11 @@ namespace nana bool expr_color::operator==(const expr_color& other) const { - return (r_ == other.r_ && g_ == other.g_ && b_ == other.b_ && a_ == other.a_); + return (px_color().value == other.px_color().value); } bool expr_color::operator!=(const expr_color& other) const { - return (r_ != other.r_ || g_ == other.g_ || b_ == other.b_ || a_ == other.a_); + return (px_color().value != other.px_color().value); } //end class color diff --git a/source/detail/win32/platform_spec.cpp b/source/detail/win32/platform_spec.cpp index bf4dafd2..e8081e5c 100644 --- a/source/detail/win32/platform_spec.cpp +++ b/source/detail/win32/platform_spec.cpp @@ -53,6 +53,11 @@ namespace detail set_text_color(col); } + unsigned drawable_impl_type::get_color() const + { + return color_; + } + void drawable_impl_type::set_color(nana::color_t col) { color_ = col; diff --git a/source/gui/detail/basic_window.cpp b/source/gui/detail/basic_window.cpp index 22480840..93f65852 100644 --- a/source/gui/detail/basic_window.cpp +++ b/source/gui/detail/basic_window.cpp @@ -347,12 +347,12 @@ namespace nana visible = false; - 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); + //colors.foreground = 0x0; //deprecated + //colors.background = nana::color::button_face; + //colors.active = 0x60C8FD; + colors.fgcolor = ::nana::colors::black; + colors.bgcolor = ::nana::colors::button_face; + colors.activated.from_rgb(0x60, 0xc8, 0xfd); effect.edge_nimbus = effects::edge_nimbus::none; effect.bground = nullptr; diff --git a/source/gui/effects.cpp b/source/gui/effects.cpp index 8ed77777..70ba5559 100644 --- a/source/gui/effects.cpp +++ b/source/gui/effects.cpp @@ -27,8 +27,8 @@ namespace nana if(fade_rate_ < 0.001) return; - nana::color_t color = API::background(wd); - graph.blend(graph.size(), color, fade_rate_); + //nana::color_t color = API::background(wd); //deprecated + graph.blend(graph.size(), API::bgcolor(wd), fade_rate_); } private: const double fade_rate_; diff --git a/source/gui/element.cpp b/source/gui/element.cpp index c4d59616..4cc819b3 100644 --- a/source/gui/element.cpp +++ b/source/gui/element.cpp @@ -123,7 +123,7 @@ namespace nana for(int left = 0; left < 12; ++left) { if((*colormap)[top][left] != 0xFFFFFF) - graph.set_pixel(left + x, top + y, (*colormap)[top][left]); + graph.set_pixel(left + x, top + y, static_cast((*colormap)[top][left])); } } } @@ -228,7 +228,7 @@ namespace nana { if(colormap[u][v] & 0xFF000000) continue; - graph.set_pixel(x + v, y, colormap[u][v]); + graph.set_pixel(x + v, y, static_cast(colormap[u][v])); } ++y; } diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index c36e75ca..54dc3cca 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -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->colors.background, true); + iwd->drawer.graphics.rectangle(true, iwd->colors.bgcolor); 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,11 +790,12 @@ namespace API restrict::bedrock.pump_event(wd, false); } + /* nana::color_t foreground(window wd) //deprecated { internal_scope_guard lock; if(restrict::window_manager.available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->colors.foreground; + return reinterpret_cast(wd)->colors.fgcolor.px_color().value; return 0; } @@ -804,10 +805,10 @@ namespace API internal_scope_guard lock; if(restrict::window_manager.available(iwd)) { - color_t prev = iwd->colors.foreground; + color_t prev = iwd->colors.fgcolor.px_color().value; if(prev != col) { - iwd->colors.foreground = col; + iwd->colors.fgcolor = static_cast(col); restrict::window_manager.update(iwd, true, false); } return prev; @@ -819,7 +820,7 @@ namespace API { internal_scope_guard lock; if(restrict::window_manager.available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->colors.background; + return reinterpret_cast(wd)->colors.bgcolor.px_color().value; return 0; } @@ -829,10 +830,10 @@ namespace API internal_scope_guard lock; if(restrict::window_manager.available(iwd)) { - color_t prev = iwd->colors.background; + color_t prev = iwd->colors.bgcolor.px_color().value; if(prev != col) { - iwd->colors.background = col; + iwd->colors.bgcolor = static_cast(col); restrict::window_manager.update(iwd, true, false); } return prev; @@ -844,20 +845,20 @@ namespace API { internal_scope_guard lock; if(restrict::window_manager.available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->colors.active; + return reinterpret_cast(wd)->colors.activated.px_color().value; return 0; } - color_t active(window wd, color_t col) //deprecated + color_t active(window wd, color_t clr) //deprecated { auto iwd = reinterpret_cast(wd); internal_scope_guard lock; if(restrict::window_manager.available(iwd)) { - color_t prev = iwd->colors.active; - if(prev != col) + color_t prev = iwd->colors.activated.px_color().value; + if (prev != clr) { - iwd->colors.active = col; + iwd->colors.activated = static_cast(clr); restrict::window_manager.update(iwd, true, false); } return prev; @@ -865,6 +866,7 @@ namespace API return 0; } + */ expr_color fgcolor(window wd) diff --git a/source/gui/tooltip.cpp b/source/gui/tooltip.cpp index 1daa20b4..47ff28c3 100644 --- a/source/gui/tooltip.cpp +++ b/source/gui/tooltip.cpp @@ -26,8 +26,8 @@ namespace nana private: void refresh(graph_reference graph) { - graph.rectangle(0x0, false); - graph.rectangle(1, 1, graph.width() - 2, graph.height() - 2, 0xF0F0F0, true); + graph.rectangle(false, colors::black); + graph.rectangle(::nana::rectangle(graph.size()).pare_off(1), true, {0xf0, 0xf0, 0xf0}); } }; diff --git a/source/gui/widgets/button.cpp b/source/gui/widgets/button.cpp index f37dc23e..7003e386 100644 --- a/source/gui/widgets/button.cpp +++ b/source/gui/widgets/button.cpp @@ -330,21 +330,23 @@ namespace nana{ namespace drawerbase int right = r.width - 1; int bottom = r.height - 1; - graph.rectangle_line(r, - 0x7F7F7F, 0x7F7F7F, 0x707070, 0x707070); + ::nana::expr_color lt{0x7f,0x7f,0x7f}, rb{0x70,0x70,0x70}; + graph.frame_rectangle(r, lt, lt, rb, rb); - graph.set_pixel(1, 1, 0x919191); - graph.set_pixel(right - 1, 1, 0x919191); - graph.set_pixel(right - 1, bottom - 1, 0x919191); - graph.set_pixel(1, bottom - 1, 0x919191); + graph.set_color({0x91,0x91,0x91}); + graph.set_pixel(1, 1); + graph.set_pixel(right - 1, 1); + graph.set_pixel(right - 1, bottom - 1); + graph.set_pixel(1, bottom - 1); - graph.set_pixel(0, 0, color::button_face); - graph.set_pixel(right, 0, color::button_face); - graph.set_pixel(0, bottom, color::button_face); - graph.set_pixel(right, bottom, color::button_face); + graph.set_color(colors::button_face); + graph.set_pixel(0, 0); + graph.set_pixel(right, 0); + graph.set_pixel(0, bottom); + graph.set_pixel(right, bottom); if (element_state::pressed == attr_.e_state) - graph.rectangle(r.pare_off(1), 0xC3C3C3, false); + graph.rectangle(r.pare_off(1), false, {0xc3, 0xc3, 0xc3}); } void trigger::emit_click() diff --git a/source/gui/widgets/categorize.cpp b/source/gui/widgets/categorize.cpp index 26eee1b3..57c003ab 100644 --- a/source/gui/widgets/categorize.cpp +++ b/source/gui/widgets/categorize.cpp @@ -73,14 +73,15 @@ namespace nana void background(graph_reference graph, window wd, const nana::rectangle& r, const ui_element& ue) { ui_el_ = ue; - style_.bgcolor = API::background(wd); - style_.fgcolor = API::foreground(wd); + style_.bgcolor = API::bgcolor(wd); + style_.fgcolor = API::fgcolor(wd); if(ue.what == ue.none || (API::window_enabled(wd) == false)) { //the mouse is out of the widget. - style_.bgcolor = nana::paint::graphics::mix(style_.bgcolor, 0xA0C9F5, 0.9); + style_.bgcolor.blend(expr_color{ 0xa0, 0xc9, 0xf5 }, 0.9); + //style_.bgcolor = nana::paint::graphics::mix(style_.bgcolor, 0xA0C9F5, 0.9); //deprecated } - graph.rectangle(r, style_.bgcolor, true); + graph.rectangle(r, true, style_.bgcolor); } virtual void root_arrow(graph_reference graph, const nana::rectangle& r, mouse_action state) @@ -90,7 +91,7 @@ namespace nana if(ui_el_.what == ui_el_.item_root) { _m_item_bground(graph, r.x + 1, r.y, r.width - 2, r.height, (state == mouse_action::pressed ? mouse_action::pressed : mouse_action::over)); - graph.rectangle(r, 0x3C7FB1, false); + graph.rectangle(r, false, expr_color{ 0x3C, 0x7F, 0xB1 }); if(state == mouse_action::pressed) { ++x; @@ -98,7 +99,7 @@ namespace nana } } else - graph.rectangle(r, style_.bgcolor, true); + graph.rectangle(r, true, style_.bgcolor); nana::paint::gadget::arrow_16_pixels(graph, x, y, style_.fgcolor, 3, nana::paint::gadget::directions::to_west); @@ -126,18 +127,26 @@ namespace nana int top = r.y + 1; unsigned width = r.width - 2; unsigned height = r.height - 2; + + ::nana::expr_color clr{ 0x3C, 0x7F, 0xB1 }; if(has_child) { int left = r.x + r.width - 16; _m_item_bground(graph, left, top, 15, height, state_arrow); width -= 16; --left; - graph.line(left, top, left, r.y + height, 0x3C7FB1); + //graph.line(left, top, left, r.y + height, 0x3C7FB1);//deprecated + graph.set_color(clr); + graph.line({ left, top }, { left, r.y + static_cast(height) }); } + _m_item_bground(graph, r.x + 1, top, width, height, state_name); - graph.rectangle(r, 0x3C7FB1, false); + //graph.rectangle(r, 0x3C7FB1, false); //deprecated + graph.set_color(clr); + graph.rectangle(r, false); } - graph.string(strpos.x, strpos.y, style_.fgcolor, name); + //graph.string(strpos.x, strpos.y, style_.fgcolor, name); //deprecated + graph.string(strpos, name, style_.fgcolor); if(has_child) { @@ -148,9 +157,19 @@ namespace nana void border(graph_reference graph) { - graph.rectangle(0xF0F0F0, false); - graph.rectangle_line(nana::rectangle(graph.size()).pare_off(1), - 0x9DABB9, 0x484E55, 0x484E55, 0x9DABB9); + rectangle r{ graph.size() }; + + graph.set_color({ 0xf0, 0xf0, 0xf0 }); + graph.rectangle(r, false); + + expr_color lb(0x9d, 0xab, 0xb9); + expr_color tr(0x48, 0x4e, 0x55); + graph.frame_rectangle(r.pare_off(1), lb, tr, tr, lb); + + //deprecated + //graph.rectangle(0xF0F0F0, false); + //graph.rectangle_line(nana::rectangle(graph.size()).pare_off(1), + // 0x9DABB9, 0x484E55, 0x484E55, 0x9DABB9); } private: void _m_item_bground(graph_reference graph, int x, int y, unsigned width, unsigned height, mouse_action state) @@ -158,38 +177,55 @@ namespace nana const unsigned half = (height - 2) / 2; int left = x + 1; int top = y + 1; - nana::color_t upcol, downcol; + //nana::color_t upcol, downcol; // deprecated + nana::expr_color clr_top(0xea, 0xea, 0xea), clr_bottom(0xdc, 0xdc, 0xdc); switch(state) { case mouse_action::over: - upcol = 0x0DFF2FC; - downcol = 0xA9DAF5; + clr_top = expr_color(0xdf, 0xf2, 0xfc); + clr_bottom = expr_color(0xa9, 0xda, 0xf5); + //upcol = 0x0DFF2FC; //deprecated + //downcol = 0xA9DAF5; break; case mouse_action::pressed: - upcol = 0xA6D7F2; - downcol = 0x92C4F6; + //upcol = 0xA6D7F2; //deprecated + //downcol = 0x92C4F6; + clr_top = expr_color(0xa6, 0xd7, 0xf2); + clr_bottom = expr_color(0x92, 0xc4, 0xf6); ++left; ++top; break; - case mouse_action::normal: + //case mouse_action::normal: //deprecated default: - upcol = 0xEAEAEA; - downcol = 0xDCDCDC; + //upcol = 0xEAEAEA; //deprecated + //downcol = 0xDCDCDC; break; } - graph.rectangle(left, top, width - 2, half, upcol, true); - graph.rectangle(left, top + static_cast(half), width - 2, (height - 2) - half, downcol, true); + graph.rectangle(rectangle{ left, top, width - 2, half }, true, clr_top); + graph.rectangle(rectangle{ left, top + static_cast(half), width - 2, (height - 2) - half }, true, clr_bottom); + //graph.rectangle(left, top, width - 2, half, upcol, true); //deprecated + //graph.rectangle(left, top + static_cast(half), width - 2, (height - 2) - half, downcol, true); if(mouse_action::pressed == state) { int bottom = y + height - 1; int right = x + width - 1; - graph.line(x, y, right, y, 0x6E8D9F); - graph.line(x, y + 1, x, bottom, 0x6E8D9F); + + graph.set_color(expr_color(0x6e, 0x8d, 0x9f)); + graph.line(point{ x, y }, point{right, y}); + graph.line(point{ x, y + 1 }, point{ x, bottom }); ++x; ++y; - graph.line(x, y, right, y, 0xA6C7D9); - graph.line(x, y + 1, x, bottom, 0xA6C7D9); + graph.set_color(expr_color(0xa6, 0xc7, 0xd9)); + graph.line(point{ x, y }, point{ right, y }); + graph.line(point{ x, y + 1 }, point{ x, bottom }); + + //graph.line(x, y, right, y, 0x6E8D9F); //deprecated + //graph.line(x, y + 1, x, bottom, 0x6E8D9F); + //++x; + //++y; + //graph.line(x, y, right, y, 0xA6C7D9); + //graph.line(x, y + 1, x, bottom, 0xA6C7D9); } } @@ -197,8 +233,10 @@ namespace nana ui_element ui_el_; struct style_tag { - nana::color_t bgcolor; - nana::color_t fgcolor; + //nana::color_t bgcolor; + //nana::color_t fgcolor; + expr_color bgcolor; + expr_color fgcolor; }style_; }; @@ -369,7 +407,6 @@ namespace nana }; scheme() - : graph_(nullptr) { proto_.ui_renderer = pat::cloneable(interior_renderer()); style_.mode = mode::normal; @@ -379,7 +416,8 @@ namespace nana void attach(window wd, nana::paint::graphics* graph) { window_ = wd; - API::background(wd, 0xFFFFFF); + //API::background(wd, 0xFFFFFF); //deprecated + API::bgcolor(wd, colors::white); graph_ = graph; } @@ -637,7 +675,7 @@ namespace nana nana::rectangle _m_make_root_rectangle() const { - return nana::rectangle(1, 1, 16, _m_item_fix_scale()); + return{ 1, 1, 16, _m_item_fix_scale() }; } //_m_make_rectangle @@ -765,8 +803,8 @@ namespace nana } } private: - window window_; - nana::paint::graphics * graph_; + window window_{nullptr}; + nana::paint::graphics * graph_{nullptr}; nana::string splitstr_; std::size_t head_; unsigned item_height_; diff --git a/source/gui/widgets/checkbox.cpp b/source/gui/widgets/checkbox.cpp index f2ba9989..0cc84e32 100644 --- a/source/gui/widgets/checkbox.cpp +++ b/source/gui/widgets/checkbox.cpp @@ -88,7 +88,7 @@ namespace checkbox void drawer::_m_draw_background(graph_reference graph) { if(bground_mode::basic != API::effects_bground_mode(*widget_)) - graph.rectangle(API::background(*widget_), true); + graph.rectangle(true, API::bgcolor(*widget_)); } void drawer::_m_draw_checkbox(graph_reference graph, unsigned first_line_height) @@ -98,21 +98,23 @@ namespace checkbox void drawer::_m_draw_title(graph_reference graph) { - if(graph.width() > 16 + interval) + if (graph.width() > 16 + interval) { nana::string title = widget_->caption(); - unsigned fgcolor = widget_->foreground(); unsigned pixels = graph.width() - (16 + interval); nana::paint::text_renderer tr(graph); - if(API::window_enabled(widget_->handle()) == false) + if (API::window_enabled(widget_->handle()) == false) { - tr.render(17 + interval, 2, 0xFFFFFF, title.c_str(), title.length(), pixels); - fgcolor = 0x808080; + graph.set_text_color(colors::white); + tr.render({ 17 + interval, 2 }, title.c_str(), title.length(), pixels); + graph.set_text_color({ 0x80, 0x80, 0x80 }); } + else + graph.set_text_color(widget_->fgcolor()); - tr.render(16 + interval, 1, fgcolor, title.c_str(), title.length(), pixels); + tr.render({ 16 + interval, 1 }, title.c_str(), title.length(), pixels); } } //end class drawer diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index c4ec001c..19362979 100644 --- a/source/gui/widgets/combox.cpp +++ b/source/gui/widgets/combox.cpp @@ -38,8 +38,8 @@ namespace nana { } - item(const nana::string& s) - : item_text(s) + item(nana::string&& s) + : item_text(std::move(s)) {} private: //implement item_interface methods @@ -85,7 +85,7 @@ namespace nana { widget_ = static_cast< ::nana::combox*>(&wd); editor_ = new widgets::skeletons::text_editor(widget_->handle(), graph); - editor_->border_renderer([this](graph_reference graph, nana::color_t bgcolor){ + editor_->border_renderer([this](graph_reference graph, const ::nana::expr_color& bgcolor){ draw_border(graph, bgcolor); }); editor_->multi_lines(false); @@ -100,9 +100,9 @@ namespace nana graph_ = nullptr; } - void insert(const nana::string& text) + void insert(nana::string&& text) { - items_.emplace_back(std::make_shared(text)); + items_.emplace_back(std::make_shared(std::move(text))); API::refresh_window(widget_->handle()); } @@ -284,11 +284,11 @@ namespace nana _m_draw_image(); } - void draw_border(graph_reference graph, nana::color_t bgcolor) + void draw_border(graph_reference graph, const ::nana::expr_color& bgcolor) { - graph.rectangle((state_.focused ? 0x0595E2 : 0x999A9E), false); + graph.rectangle(false, (state_.focused ? ::nana::expr_color(0x05, 0x95, 0xE2) : ::nana::expr_color(0x99, 0x9A, 0x9E))); nana::rectangle r(graph.size()); - graph.rectangle(r.pare_off(1), bgcolor, false); + graph.rectangle(r.pare_off(1), false, bgcolor); } std::size_t the_number_of_options() const @@ -439,20 +439,20 @@ namespace nana } } - void _m_draw_background(graph_reference graph, const nana::rectangle&, nana::color_t) + void _m_draw_background(graph_reference graph, const rectangle&, const ::nana::expr_color&) { - nana::rectangle r(graph.size()); - nana::color_t color_start = color::button_face_shadow_start; - nana::color_t color_end = color::button_face_shadow_end; + ::nana::rectangle r(graph.size()); + auto clr_from = colors::button_face_shadow_start; + auto clr_to = colors::button_face_shadow_end; if(state_.state == state_t::pressed) { r.pare_off(2); - std::swap(color_start, color_end); + std::swap(clr_from, clr_to); } else r.pare_off(1); - graph.shadow_rectangle(r, color_start, color_end, true); + graph.gradual_rectangle(r, clr_from, clr_to, true); } void _m_draw_push_button(bool enabled) @@ -467,39 +467,40 @@ namespace nana int bottom = graph_->height() - 2; int mid = top + (bottom - top) * 5 / 18; - nana::color_t topcol, topcol_ln, botcol, botcol_ln; - nana::color_t arrow_color; + ::nana::expr_color topcol, topcol_ln, botcol, botcol_ln; + ::nana::expr_color arrow_color{ colors::white }; if (enabled && items_.size()) { - arrow_color = 0xFFFFFF; double percent = 1; if (has_lister() || (state_.state == state_t::pressed && state_.pointer_where == where_t::push_button)) percent = 0.8; else if (state_.state == state_t::mouse_over) percent = 0.9; - topcol_ln = graphics::mix(0x3F476C, 0xFFFFFF, percent); - botcol_ln = graphics::mix(0x031141, 0xFFFFFF, percent); - topcol = graphics::mix(0x3F83B4, 0xFFFFFF, percent); - botcol = graphics::mix(0x0C4A95, 0xFFFFFF, percent); + topcol_ln = expr_color{ 0x3F, 0x47, 0x6C }.blend(arrow_color, percent); + botcol_ln = expr_color{ 0x03, 0x31, 0x114 }.blend(arrow_color, percent); + topcol = expr_color{ 0x3F, 83, 84 }.blend(arrow_color, percent); + botcol = expr_color{ 0x0c, 0x4a, 0x9a }.blend(arrow_color, percent); } else { - arrow_color = 0xFFFFFF; - topcol_ln = 0x7F7F7F; - botcol_ln = 0x505050; - topcol = 0xC3C3C3; - botcol = 0xA0A0A0; + topcol_ln = { 0x7F, 0x7F, 0x7F }; + botcol_ln = { 0x50, 0x50, 0x50 }; + topcol = { 0xC3, 0xC3, 0xC3 }; + botcol = { 0xA0, 0xA0, 0xA0 }; } - graph_->line(left, top, left, mid, topcol_ln); - graph_->line(right - 1, top, right - 1, mid, topcol_ln); + graph_->set_color(topcol_ln); + graph_->line({ left, top }, { left, mid }); + graph_->line({ right - 1, top }, { right - 1, mid }); - graph_->line(left, mid + 1, left, bottom, botcol_ln); - graph_->line(right - 1, mid + 1, right - 1, bottom, botcol_ln); + graph_->set_color(botcol_ln); + graph_->line({ left, mid + 1 }, { left, bottom }); + graph_->line({ right - 1, mid + 1 }, { right - 1, bottom }); - graph_->rectangle(left + 1, top, right - left - 2, mid - top + 1, topcol, true); - graph_->rectangle(left + 1, mid + 1, right - left - 2, bottom - mid, botcol, true); + + graph_->rectangle({ left + 1, top, static_cast(right - left - 2), static_cast(mid - top + 1) }, true, topcol); + graph_->rectangle({ left + 1, mid + 1, static_cast(right - left - 2), static_cast(bottom - mid) }, true, botcol); gadget::arrow_16_pixels(*graph_, left, top + ((bottom - top) / 2) - 7, arrow_color, 1, gadget::directions::to_south); } @@ -579,7 +580,6 @@ namespace nana trigger::~trigger() { delete drawer_; - drawer_ = nullptr; } void trigger::set_accept(std::function&& pred) @@ -599,7 +599,8 @@ namespace nana void trigger::attached(widget_reference wdg, graph_reference graph) { - wdg.background(0xFFFFFF); + wdg.bgcolor(colors::white); + //wdg.background(0xFFFFFF); //deprecated drawer_->attached(wdg, graph); API::effects_edge_nimbus(wdg, effects::edge_nimbus::active); @@ -668,15 +669,12 @@ namespace nana void trigger::mouse_up(graph_reference graph, const arg_mouse& arg) { - if(drawer_->widget_ptr()->enabled()) + if (drawer_->widget_ptr()->enabled() && !drawer_->has_lister()) { - if(false == drawer_->has_lister()) - { - drawer_->editor()->mouse_up(arg.left_button, arg.pos); - drawer_->set_mouse_press(false); - drawer_->draw(); - API::lazy_refresh(); - } + drawer_->editor()->mouse_up(arg.left_button, arg.pos); + drawer_->set_mouse_press(false); + drawer_->draw(); + API::lazy_refresh(); } } @@ -709,7 +707,7 @@ namespace nana void trigger::key_press(graph_reference, const arg_keyboard& arg) { - if(false == drawer_->widget_ptr()->enabled()) + if(!drawer_->widget_ptr()->enabled()) return; if(drawer_->editable()) @@ -906,10 +904,10 @@ namespace nana create(wd, rectangle(), visible); } - combox::combox(window wd, const nana::string& text, bool visible) + combox::combox(window wd, nana::string text, bool visible) { create(wd, rectangle(), visible); - caption(text); + caption(std::move(text)); } combox::combox(window wd, const nana::char_t* text, bool visible) @@ -925,18 +923,20 @@ namespace nana void combox::clear() { - internal_scope_guard sg; + internal_scope_guard lock; get_drawer_trigger().get_drawer_impl().clear(); API::refresh_window(handle()); } void combox::editable(bool eb) { + internal_scope_guard lock; get_drawer_trigger().get_drawer_impl().editable(eb); } bool combox::editable() const { + internal_scope_guard lock; return get_drawer_trigger().get_drawer_impl().editable(); } @@ -946,45 +946,53 @@ namespace nana get_drawer_trigger().set_accept(std::move(pred)); } - combox& combox::push_back(const nana::string& text) + combox& combox::push_back(nana::string text) { - get_drawer_trigger().get_drawer_impl().insert(text); + internal_scope_guard lock; + get_drawer_trigger().get_drawer_impl().insert(std::move(text)); return *this; } std::size_t combox::the_number_of_options() const { + internal_scope_guard lock; return get_drawer_trigger().get_drawer_impl().the_number_of_options(); } std::size_t combox::option() const { + internal_scope_guard lock; return get_drawer_trigger().get_drawer_impl().option(); } void combox::option(std::size_t i) { + internal_scope_guard lock; get_drawer_trigger().get_drawer_impl().option(i, false); API::update_window(handle()); } nana::string combox::text(std::size_t i) const { + internal_scope_guard lock; return get_drawer_trigger().get_drawer_impl().at(i).item_text; } void combox::erase(std::size_t pos) { + internal_scope_guard lock; get_drawer_trigger().get_drawer_impl().erase(pos); } void combox::renderer(item_renderer* ir) { + internal_scope_guard lock; get_drawer_trigger().get_drawer_impl().renderer(ir); } void combox::image(std::size_t i, const nana::paint::image& img) { + internal_scope_guard lock; if(empty()) return; auto & impl = get_drawer_trigger().get_drawer_impl(); @@ -995,42 +1003,47 @@ namespace nana nana::paint::image combox::image(std::size_t pos) const { + internal_scope_guard lock; return get_drawer_trigger().get_drawer_impl().at(pos).item_image; } void combox::image_pixels(unsigned px) { + internal_scope_guard lock; if(get_drawer_trigger().get_drawer_impl().image_pixels(px)) API::refresh_window(*this); } nana::string combox::_m_caption() const { - internal_scope_guard isg; + internal_scope_guard lock; auto editor = get_drawer_trigger().get_drawer_impl().editor(); return (editor ? editor->text() : nana::string()); } void combox::_m_caption(nana::string&& str) { - internal_scope_guard isg; + internal_scope_guard lock; get_drawer_trigger().get_drawer_impl().text(std::move(str)); API::refresh_window(*this); } nana::any * combox::_m_anyobj(std::size_t pos, bool alloc_if_empty) const { + internal_scope_guard lock; return get_drawer_trigger().get_drawer_impl().anyobj(pos, alloc_if_empty); } auto combox::_m_at_key(std::shared_ptr&& p) -> item_proxy { + internal_scope_guard lock; auto & impl = get_drawer_trigger().get_drawer_impl(); return item_proxy(&impl, impl.at_key(std::move(p))); } void combox::_m_erase(nana::detail::key_interface* p) { + internal_scope_guard lock; get_drawer_trigger().get_drawer_impl().erase(p); } //end class combox diff --git a/source/gui/widgets/date_chooser.cpp b/source/gui/widgets/date_chooser.cpp index 52ec5708..6f2fd26c 100644 --- a/source/gui/widgets/date_chooser.cpp +++ b/source/gui/widgets/date_chooser.cpp @@ -35,6 +35,11 @@ namespace nana chdate_.year = chmonth_.year = d.read().year; chdate_.month = chmonth_.month = d.read().month; chdate_.day = d.read().day; + + color_.selected = { 0x2F, 0x36, 0x99 }; + color_.highlight = { 0x4D, 0x56, 0xC8 }; + color_.normal = colors::black; + color_.bgcolor = { 0x88, 0xC4, 0xFF }; } bool trigger::chose() const @@ -58,14 +63,15 @@ namespace nana if(0 <= index && index < 12) this->monthstr_[index] = str; } - - void trigger::_m_init_color() + /* + void trigger::_m_init_color() //deprecated { color_.selected = 0x2F3699; color_.highlight = 0x4D56C8; color_.normal = 0x0; color_.bkcolor = 0x88C4FF; } + */ trigger::where trigger::_m_pos_where(graph_reference graph, int x, int y) { @@ -93,12 +99,15 @@ namespace nana void trigger::_m_draw(graph_reference graph) { - _m_init_color(); + //_m_init_color(); //deprecated const unsigned width = graph.width() - 2; - graph.rectangle(0xB0B0B0, false); - graph.rectangle(1, 1, width, topbar_height, 0xFFFFFF, true); + //graph.rectangle(0xB0B0B0, false); //deprecated + //graph.rectangle(1, 1, width, topbar_height, 0xFFFFFF, true); + + graph.rectangle(false, {0xb0, 0xb0, 0xb0}); + graph.rectangle({ 1, 1, width, static_cast(topbar_height) }, true, colors::white); _m_draw_topbar(graph); @@ -107,7 +116,7 @@ namespace nana nana::point refpos(1, static_cast(topbar_height) + 1); nana::paint::graphics gbuf(width, graph.height() - 2 - topbar_height); - gbuf.rectangle(0xF0F0F0, true); + gbuf.rectangle(true, {0xf0, 0xf0, 0xf0}); switch(page_) { @@ -128,7 +137,7 @@ namespace nana { int ypos = (topbar_height - 16) / 2 + 1; - const nana::color_t color = color_.normal; + const auto color = color_.normal; nana::paint::gadget::arrow_16_pixels(graph, border_size, ypos, (pos_ == where::left_button ? color_.highlight : color), 1, nana::paint::gadget::directions::to_west); nana::paint::gadget::arrow_16_pixels(graph, graph.width() - (border_size + 16 + 1), ypos, (pos_ == where::right_button ? color_.highlight : color), 1, nana::paint::gadget::directions::to_east); @@ -147,12 +156,12 @@ namespace nana nana::size txt_s = graph.text_extent_size(str); - ypos = (topbar_height - txt_s.height) / 2 + 1; + ypos = (topbar_height - static_cast(txt_s.height)) / 2 + 1; - int xpos = (graph.width() - txt_s.width) / 2; + int xpos = static_cast(graph.width() - txt_s.width) / 2; if(xpos < border_size + 16) xpos = 16 + border_size + 1; - graph.string(xpos, ypos, (pos_ == where::topbar ? color_.highlight : color), str); + graph.string({ xpos, ypos }, str, (pos_ == where::topbar ? color_.highlight : color)); } } @@ -181,9 +190,8 @@ namespace nana nana::rectangle r(static_cast(x * dbasis.row_s), static_cast(y * dbasis.line_s), static_cast(dbasis.row_s), static_cast(dbasis.line_s)); - nana::color_t color{ color_.normal }; - - nana::point tpos{ trace_pos_ - dbasis.refpos }; + auto color = color_.normal; + auto tpos = trace_pos_ - dbasis.refpos; if((pos_ == where::textarea) && (r.x <= tpos.x) @@ -194,22 +202,22 @@ namespace nana if((page_ != page::date) || y) { color = color_.highlight; - graph.rectangle(r, color_.bkcolor, true); + graph.rectangle(r, true, color_.bgcolor); } } if(sel) { color = color_.highlight; - graph.rectangle(r, color_.bkcolor, true); - graph.rectangle(r, color_.selected, false); + graph.rectangle(r, true, color_.bgcolor); + graph.rectangle(r, false, color_.selected); } - if(primary == false) - color = 0xB0B0B0; + if(false == primary) + color = { 0xB0, 0xB0, 0xB0 }; nana::size txt_s = graph.text_extent_size(str); - graph.string(r.x + static_cast(r.width - txt_s.width) / 2, r.y + static_cast(r.height - txt_s.height) / 2, color, str); + graph.string({ r.x + static_cast(r.width - txt_s.width) / 2, r.y + static_cast(r.height - txt_s.height) / 2 }, str, color); } void trigger::_m_draw_pos(drawing_basis & dbasis, graph_reference graph, int x, int y, int number, bool primary, bool sel) @@ -417,7 +425,7 @@ namespace nana r.x = static_cast(newbuf.width() - r.width) / 2; r.y = static_cast(newbuf.height() - r.height) / 2; - dzbuf.rectangle(0xFFFFFF, true); + dzbuf.rectangle(true, colors::white); dirtybuf.stretch(dzbuf, r); r.width = static_cast(newbuf.width() + delta * (count - i)); @@ -451,7 +459,7 @@ namespace nana r.height = static_cast(newbuf.height() - delta_h * (count - i)); r.x = static_cast(newbuf.width() - r.width) / 2; r.y = static_cast(newbuf.height() - r.height) / 2; - nzbuf.rectangle(0xFFFFFF, true); + nzbuf.rectangle(true, colors::white); newbuf.stretch(nzbuf, r); nzbuf.blend(nzbuf.size(), dzbuf, nana::point(), fade * (count - i)); diff --git a/source/gui/widgets/float_listbox.cpp b/source/gui/widgets/float_listbox.cpp index d1ca8171..7131bc63 100644 --- a/source/gui/widgets/float_listbox.cpp +++ b/source/gui/widgets/float_listbox.cpp @@ -18,10 +18,6 @@ namespace nana namespace drawerbase{ namespace float_listbox { - //class item_renderer - item_renderer::~item_renderer(){} - //end class item_renderer - class def_item_renderer : public item_renderer { @@ -36,26 +32,39 @@ namespace nana void render(widget_reference, graph_reference graph, const nana::rectangle& r, const item_interface* item, state_t state) { - if(state == StateHighlighted) + if (state == StateHighlighted) { - graph.rectangle(r, 0xAFC7E3, false); + ::nana::expr_color clr{ 0xaf, 0xc7, 0xe3 }; + graph.rectangle(r, false, clr); - graph.set_pixel(r.x, r.y, 0xFFFFFF); - graph.set_pixel(r.x + r.width - 1, r.y, 0xFFFFFF); - graph.set_pixel(r.x, r.y + r.height - 1, 0xFFFFFF); - graph.set_pixel(r.x + r.width - 1, r.y + r.height - 1, 0xFFFFFF); + //graph.set_pixel(r.x, r.y, 0xFFFFFF); //deprecated + //graph.set_pixel(r.x + r.width - 1, r.y, 0xFFFFFF); + //graph.set_pixel(r.x, r.y + r.height - 1, 0xFFFFFF); + //graph.set_pixel(r.x + r.width - 1, r.y + r.height - 1, 0xFFFFFF); - graph.set_pixel(r.x + 1, r.y + 1, 0xAFC7E3); - graph.set_pixel(r.x + r.width - 2, r.y + 1, 0xAFC7E3); - graph.set_pixel(r.x + 1, r.y + r.height - 2, 0xAFC7E3); - graph.set_pixel(r.x + r.width - 2, r.y + r.height - 2, 0xAFC7E3); + graph.set_color(colors::white); + graph.set_pixel(r.x, r.y); + graph.set_pixel(r.x + r.width - 1, r.y); + graph.set_pixel(r.x, r.y + r.height - 1); + graph.set_pixel(r.x + r.width - 1, r.y + r.height - 1); + + //graph.set_pixel(r.x + 1, r.y + 1, 0xAFC7E3); //deprecated + //graph.set_pixel(r.x + r.width - 2, r.y + 1, 0xAFC7E3); + //graph.set_pixel(r.x + 1, r.y + r.height - 2, 0xAFC7E3); + //graph.set_pixel(r.x + r.width - 2, r.y + r.height - 2, 0xAFC7E3); + + graph.set_color(clr); + graph.set_pixel(r.x + 1, r.y + 1); + graph.set_pixel(r.x + r.width - 2, r.y + 1); + graph.set_pixel(r.x + 1, r.y + r.height - 2); + graph.set_pixel(r.x + r.width - 2, r.y + r.height - 2); nana::rectangle po_r(r); - graph.rectangle(po_r.pare_off(1), 0xEBF4FB, false); - graph.shadow_rectangle(po_r.pare_off(1), 0xDDECFD, 0xC2DCFD, true); + graph.rectangle(po_r.pare_off(1), false, { 0xEB, 0xF4, 0xFB }); + graph.gradual_rectangle(po_r.pare_off(1), { 0xDD, 0xEC, 0xFD }, { 0xC2, 0xDC, 0xFD }, true); } else - graph.rectangle(r, 0xFFFFFF, true); + graph.rectangle(r, true, colors::white); int x = r.x + 2; if(image_enabled_) @@ -100,7 +109,8 @@ namespace nana } x += (image_pixels_ + 2); } - graph.string(x, r.y + 2, 0x0, item->text()); + graph.set_text_color(colors::black); + graph.string({ x, r.y + 2 }, item->text()); } unsigned item_pixels(graph_reference graph) const @@ -109,12 +119,6 @@ namespace nana } };//end class item_renderer - //struct module_def - module_def::module_def() - :max_items(10), index(npos) - {} - //end struct module_def - //class drawer_impl class drawer_impl { @@ -339,11 +343,11 @@ namespace nana _m_open_scrollbar(*widget_, pages); } else - graph_->string(4, 4, 0x808080, STR("Empty Listbox, No Module!")); + graph_->string({ 4, 4 }, STR("Empty Listbox, No Module!"), {0x80, 0x80, 0x80}); //Draw border - graph_->rectangle(0x0, false); - graph_->rectangle(nana::rectangle(graph_->size()).pare_off(1), 0xFFFFFF, false); + graph_->rectangle(false, colors::black); + graph_->rectangle(nana::rectangle(graph_->size()).pare_off(1), false, colors::white); } private: bool _m_image_enabled() const diff --git a/source/gui/widgets/form.cpp b/source/gui/widgets/form.cpp index 823e47e7..47d85365 100644 --- a/source/gui/widgets/form.cpp +++ b/source/gui/widgets/form.cpp @@ -18,8 +18,6 @@ namespace nana namespace form { //class trigger - trigger::trigger():wd_(nullptr){} - void trigger::attached(widget_reference widget, graph_reference graph) { wd_ = &widget; @@ -27,14 +25,15 @@ namespace nana void trigger::refresh(graph_reference graph) { - graph.rectangle(API::background(*wd_), true); + graph.rectangle(true, API::bgcolor(*wd_)); } - - void trigger::resized(graph_reference graph, const arg_resized&) + /* + void trigger::resized(graph_reference graph, const arg_resized&) //deprecated { graph.rectangle(API::background(*wd_), true); API::lazy_refresh(); } + */ }//end namespace form }//end namespace drawerbase diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index 686596ff..d128f182 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -74,7 +74,7 @@ namespace nana return true; } - void render(graph_reference graph, nana::color_t fgcolor, align th, align_v tv) + void render(graph_reference graph, const ::nana::expr_color& fgcolor, align th, align_v tv) { traceable_.clear(); @@ -161,18 +161,18 @@ namespace nana return false; } - nana::size measure(graph_reference graph, unsigned limited, align th, align_v tv) + ::nana::size measure(graph_reference graph, unsigned limited, align th, align_v tv) { - nana::size retsize; + ::nana::size retsize; - nana::paint::font ft = graph.typeface(); //used for restoring the font + auto ft = graph.typeface(); //used for restoring the font const unsigned def_line_pixels = graph.text_extent_size(STR(" "), 1).height; font_ = ft; fblock_ = nullptr; - _m_set_default(ft, 0); + _m_set_default(ft, colors::black); _m_measure(graph); render_status rs; @@ -216,7 +216,7 @@ namespace nana } } - void _m_set_default(const nana::paint::font& ft, nana::color_t fgcolor) + void _m_set_default(const ::nana::paint::font& ft, const ::nana::expr_color& fgcolor) { def_.font_name = ft.name(); def_.font_size = ft.size(); @@ -224,9 +224,9 @@ namespace nana def_.fgcolor = fgcolor; } - nana::color_t _m_fgcolor(nana::widgets::skeletons::fblock* fp) + const ::nana::expr_color& _m_fgcolor(nana::widgets::skeletons::fblock* fp) { - while(fp->fgcolor == 0xFFFFFFFF) + while(fp->fgcolor.invisible()) { fp = fp->parent; if(nullptr == fp) @@ -562,12 +562,12 @@ namespace nana if (text_range.second == data_ptr->text().length()) { - graph.string(rs.pos.x, y, _m_fgcolor(fblock_ptr), data_ptr->text()); + graph.string({ rs.pos.x, y }, data_ptr->text(), _m_fgcolor(fblock_ptr)); } else { nana::string str = data_ptr->text().substr(text_range.first, text_range.second); - graph.string(rs.pos.x, y, _m_fgcolor(fblock_ptr), str); + graph.string({ rs.pos.x, y }, str, _m_fgcolor(fblock_ptr)); sz = graph.text_extent_size(str); } _m_inser_if_traceable(rs.pos.x, y, sz, fblock_ptr); @@ -600,16 +600,16 @@ namespace nana private: dstream dstream_; bool format_enabled_ = false; - nana::widgets::skeletons::fblock * fblock_ = nullptr; + ::nana::widgets::skeletons::fblock * fblock_ = nullptr; std::deque traceable_; - nana::paint::font font_; + ::nana::paint::font font_; struct def_font_tag { - nana::string font_name; + ::nana::string font_name; std::size_t font_size; bool font_bold; - nana::color_t fgcolor; + ::nana::expr_color fgcolor; }def_; }; @@ -748,9 +748,9 @@ namespace nana window wd = impl_->wd->handle(); if(bground_mode::basic != API::effects_bground_mode(wd)) - graph.rectangle(API::background(wd), true); + graph.rectangle(true, API::bgcolor(wd)); - impl_->renderer.render(graph, impl_->wd->foreground(), impl_->text_align, impl_->text_align_v); + impl_->renderer.render(graph, API::fgcolor(wd), impl_->text_align, impl_->text_align_v); } //end class label_drawer diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 63b006cc..34792d0a 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -2209,7 +2209,7 @@ namespace nana _m_draw(essence_->header.cont(), r); const int y = r.y + r.height - 1; - essence_->graph->line(r.x, y, r.x + r.width, y, 0xDEDFE1); + essence_->graph->line({ r.x, y }, { r.x + static_cast(r.width), y }, { 0xDE, 0xDF, 0xE1 }); } private: size_type _m_target_strip(int x, const nana::rectangle& rect, size_type grab, bool& place_front) @@ -2239,7 +2239,7 @@ namespace nana x = (place_front ? item_xpos : essence_->header.xpos(essence_->header.neighbor(i, false))); if(i != npos) - essence_->graph->rectangle(x - essence_->scroll.offset_x + rect.x, rect.y, 2, rect.height, 0xFF0000, true); + essence_->graph->rectangle({ x - essence_->scroll.offset_x + rect.x, rect.y, 2, rect.height }, true, colors::red); } return i; } @@ -2254,7 +2254,7 @@ namespace nana unsigned height = rect.height - 1; int txtop = (rect.height - essence_->text_height) / 2 + rect.y; - nana::color_t txtcolor = essence_->lister.wd_ptr()->foreground(); + auto txtcolor = essence_->lister.wd_ptr()->fgcolor(); auto state = essence_t::state_t::normal; //check whether grabing an item, if item_spliter_ != npos, that indicates the grab item is a spliter. @@ -2270,7 +2270,7 @@ 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, 0xDEDFE1); + graph.line({ next_x - 1, rect.y }, { next_x - 1, bottom_y }, { 0xDE, 0xDF, 0xE1 }); } x = next_x; if(x - rect.x > static_cast(rect.width)) break; @@ -2278,30 +2278,30 @@ namespace nana } if(x - rect.x < static_cast(rect.width)) - graph.rectangle(x, rect.y, rect.width - x + rect.x, height, 0xF1F2F4, true); + graph.rectangle({ x, rect.y, rect.width - x + rect.x, height }, true, { 0xF1, 0xF2, 0xF4 }); } template - void _m_draw_item(graph_reference graph, int x, int y, unsigned height, int txtop, nana::color_t txtcolor, const Item& item, essence_t::state_t state) + void _m_draw_item(graph_reference graph, int x, int y, unsigned height, int txtop, const ::nana::expr_color& fgcolor, const Item& item, essence_t::state_t state) { - nana::color_t bgcolor; + ::nana::expr_color bgcolor; typedef essence_t::state_t state_t; switch(state) { - case state_t::normal: bgcolor = 0xF1F2F4; break; - case state_t::highlighted: bgcolor = 0xFFFFFF; break; + case state_t::normal: bgcolor.from_rgb(0xf1, 0xf2, 0xf4); break; + case state_t::highlighted: bgcolor = colors::white; break; case state_t::pressed: - case state_t::grabed: bgcolor = 0x8BD6F6; break; - case state_t::floated: bgcolor = 0xBABBBC; break; + case state_t::grabed: bgcolor.from_rgb(0x8B, 0xD6, 0xF6); break; + case state_t::floated: bgcolor.from_rgb(0xBA, 0xBB, 0xBC); break; } - graph.rectangle(x, y, item.pixels, height, bgcolor, true); - graph.string(x + 5, txtop, txtcolor, item.text); + graph.rectangle({ x, y, item.pixels, height }, true, bgcolor); + graph.string({ x + 5, txtop }, item.text, fgcolor); if(item.index == essence_->lister.sort_index()) { nana::paint::gadget::directions::t dir = essence_->lister.sort_reverse() ? nana::paint::gadget::directions::to_south : nana::paint::gadget::directions::to_north; - nana::paint::gadget::arrow_16_pixels(graph, x + (item.pixels - 16) / 2, -4, 0x0, 0, dir); + nana::paint::gadget::arrow_16_pixels(graph, x + (item.pixels - 16) / 2, -4, colors::black, 0, dir); } } @@ -2313,7 +2313,7 @@ namespace nana ext_graph.typeface(essence_->graph->typeface()); int txtop = (essence_->header_size - essence_->text_height) / 2; - _m_draw_item(ext_graph, 0, 0, essence_->header_size, txtop, 0xFFFFFF, item, essence_t::state_t::floated); + _m_draw_item(ext_graph, 0, 0, essence_->header_size, txtop, colors::white, item, essence_t::state_t::floated); int xpos = essence_->header.xpos(item.index) + pos.x - ref_xpos_; ext_graph.blend(ext_graph.size(), *(essence_->graph), nana::point(xpos - essence_->scroll.offset_x + rect.x, rect.y), 0.5); @@ -2477,9 +2477,10 @@ namespace nana 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::paint::gadget::arrow_16_pixels(*graph, x + 5, y + (essence_->item_size - 16) / 2, { 0x0, 0x33, 0x99 }, 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); - graph->string(x + 20, y + txtoff, 0x3399, categ.text); + + graph->string({ x + 20, y + txtoff }, categ.text, {0, 0x33, 0x99}); std::stringstream ss; ss<<'('<(categ.items.size())<<')'; @@ -2487,11 +2488,13 @@ namespace nana unsigned str_w = graph->text_extent_size(str).width; - graph->string(x + 25 + text_s.width, y + txtoff, 0x3399, str); - - if(x + 35 + text_s.width + str_w < x + width) - graph->line(x + 30 + text_s.width + str_w, y + essence_->item_size / 2, x + width - 5, y + essence_->item_size / 2, 0x3399); + graph->string({ x + 25 + static_cast(text_s.width), y + txtoff }, str); + if (x + 35 + text_s.width + str_w < x + width) + { + ::nana::point pos{ x + 30 + static_cast(text_s.width + str_w), y + static_cast(essence_->item_size) / 2 }; + graph->line(pos, { x + static_cast(width)-5, pos.y }, { 0x0, 0x33, 0x99 }); + } //Draw selecting inner rectangle if(sel && categ.expand == false) { @@ -2603,7 +2606,7 @@ namespace nana } } - graph->line(item_xpos - 1, y, item_xpos - 1, y + essence_->item_size - 1, 0xEBF4F9); + graph->line({ item_xpos - 1, y }, { item_xpos - 1, y + static_cast(essence_->item_size) - 1 }, { 0xEB, 0xF4, 0xF9 }); item_xpos += header.pixels; first = false; @@ -2618,13 +2621,14 @@ namespace nana { //Draw selecting inner rectangle auto graph = essence_->graph; - graph->rectangle(x , y , width, essence_->item_size, 0x99DEFD, false); + graph->rectangle({ x, y, width, essence_->item_size }, false, { 0x99, 0xDE, 0xFD }); - graph->rectangle(x + 1, y + 1, width - 2, essence_->item_size - 2, 0xFFFFFF, false); - graph->set_pixel(x, y, 0xFFFFFF); - graph->set_pixel(x, y + essence_->item_size - 1, 0xFFFFFF); - graph->set_pixel(x + width - 1, y, 0xFFFFFF); - graph->set_pixel(x + width - 1, y + essence_->item_size - 1, 0xFFFFFF); + graph->set_color(colors::white); + graph->rectangle({ x + 1, y + 1, width - 2, essence_->item_size - 2 }, false); + graph->set_pixel(x, y); + graph->set_pixel(x, y + essence_->item_size - 1); + graph->set_pixel(x + width - 1, y); + graph->set_pixel(x + width - 1, y + essence_->item_size - 1); } private: essence_t * essence_; @@ -2674,12 +2678,16 @@ namespace nana auto & graph = *essence_->graph; auto size = graph.size(); //Draw Border - graph.rectangle(0x9CB6C5, false); - graph.line(1, 1, 1, size.height - 2, 0xFFFFFF); - graph.line(size.width - 2, 1, size.width - 2, size.height - 2, 0xFFFFFF); + graph.rectangle(false, {0x9c, 0xb6, 0xc5}); + graph.line({ 1, 1 }, {1, static_cast(size.height) - 2}, colors::white); + graph.line({ static_cast(size.width) - 2, 1 }, { static_cast(size.width) - 2, static_cast(size.height) - 2 }); if ((essence_->scroll.h.empty() == false) && (essence_->scroll.v.empty() == false)) - graph.rectangle(size.width - 1 - essence_->scroll.scale, size.height - 1 - essence_->scroll.scale, essence_->scroll.scale, essence_->scroll.scale, nana::color::button_face, true); + graph.rectangle({ static_cast(size.width - 1 - essence_->scroll.scale), + static_cast(size.height - 1 - essence_->scroll.scale), + essence_->scroll.scale, + essence_->scroll.scale }, + true, colors::button_face); } void trigger::attached(widget_reference widget, graph_reference graph) @@ -2688,7 +2696,7 @@ namespace nana typeface_changed(graph); essence_->lister.bind(essence_, widget); - widget.background(0xFFFFFF); + widget.bgcolor(colors::white); } void trigger::detached() diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 2539cd7c..d8cdc4c7 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -105,38 +105,42 @@ namespace nana nana::size sz = graph.size(); sz.width -= 30; sz.height -= 2; - graph.rectangle(color::gray_border, false); - graph.rectangle(1, 1, 28, sz.height, 0xF6F6F6, true); - graph.rectangle(29, 1, sz.width, sz.height, 0xFFFFFF, true); + graph.rectangle(false, colors::gray_border); + graph.rectangle({ 1, 1, 28, sz.height }, true, { 0xf6, 0xf6, 0xf6 }); + graph.rectangle({ 29, 1, sz.width, sz.height }, true, colors::white); } void item(graph_reference graph, const nana::rectangle& r, const attr& at) { if(at.item_state == state::active) { - graph.rectangle(r, 0xA8D8EB, false); + graph.rectangle(r, false, {0xa8, 0xd8, 0xeb}); nana::point points[4] = { nana::point(r.x, r.y), nana::point(r.x + r.width - 1, r.y), nana::point(r.x, r.y + r.height - 1), nana::point(r.x + r.width - 1, r.y + r.height - 1) }; + + graph.set_color({0xc0, 0xdd, 0xfc}); for(int i = 0; i < 4; ++i) - graph.set_pixel(points[i].x, points[i].y, 0xC0DDFC); + graph.set_pixel(points[i].x, points[i].y); if(at.enabled) - graph.shadow_rectangle(nana::rectangle(r).pare_off(1), 0xE8F0F4, 0xDBECF4, true); + graph.gradual_rectangle(nana::rectangle(r).pare_off(1), { 0xE8, 0xF0, 0xF4 }, { 0xDB,0xEC,0xF4 }, true); } if(at.checked && (checks::none != at.check_style)) { - graph.rectangle(r, 0xCDD3E6, false); - graph.rectangle(nana::rectangle(r).pare_off(1), 0xE6EFF4, true); + graph.rectangle(r, false, { 0xCD, 0xD3, 0xE6 }); + + ::nana::expr_color clr(0xE6, 0xEF, 0xF4); + graph.rectangle(nana::rectangle(r).pare_off(1), true, clr); nana::rectangle crook_r = r; crook_r.width = 16; crook_.radio(at.check_style == checks::option); - crook_.draw(graph, ::nana::expr_color(0xE6, 0xEF, 0xF4), colors::black, crook_r, element_state::normal); + crook_.draw(graph, clr, colors::black, crook_r, element_state::normal); } } @@ -147,24 +151,20 @@ namespace nana void item_text(graph_reference graph, const nana::point& pos, const nana::string& text, unsigned text_pixels, const attr& at) { + graph.set_color(at.enabled ? colors::black : colors::gray_border); nana::paint::text_renderer tr(graph); - tr.render(pos.x, pos.y, (at.enabled ? 0x0 : nana::color::gray_border), text.c_str(), text.length(), text_pixels, true); + tr.render(pos, text.c_str(), text.length(), text_pixels, true); } void sub_arrow(graph_reference graph, const nana::point& pos, unsigned pixels, const attr&) { - nana::paint::gadget::arrow_16_pixels(graph, pos.x, pos.y + static_cast(pixels - 16) / 2, 0x0, 0, nana::paint::gadget::directions::to_east); + nana::paint::gadget::arrow_16_pixels(graph, pos.x, pos.y + static_cast(pixels - 16) / 2, colors::black, 0, nana::paint::gadget::directions::to_east); } private: facade crook_; }; - //class renderer_interface - renderer_interface::~renderer_interface() - {} - //end class renderer_interface - class menu_builder : noncopyable { @@ -537,7 +537,7 @@ namespace nana renderer->item(*graph_, item_r, attr); //Draw text, the text is transformed from orignal for hotkey character - nana::string::value_type hotkey; + nana::char_t hotkey; nana::string::size_type hotkey_pos; nana::string text = API::transform_shortkey_text(m.text, hotkey, &hotkey_pos); @@ -555,7 +555,9 @@ namespace nana nana::size hotkey_size = graph_->text_extent_size(text.c_str() + hotkey_pos, 1); int x = item_r.x + 40 + off_w; int y = item_r.y + text_top_off + hotkey_size.height; - graph_->line(x, y, x + hotkey_size.width - 1, y, 0x0); + + graph_->set_color(colors::black); + graph_->line({ x, y }, { x + static_cast(hotkey_size.width) - 1, y }); } } @@ -566,7 +568,8 @@ namespace nana } else { - graph_->line(item_r.x + 40, item_r.y, graph_->width() - 1, item_r.y, nana::color::gray_border); + graph_->set_color(colors::gray_border); + graph_->line({ item_r.x + 40, item_r.y }, { static_cast(graph_->width()) - 1, item_r.y }); item_r.y += 2; } diff --git a/source/gui/widgets/menubar.cpp b/source/gui/widgets/menubar.cpp index aef4ea45..5690ec50 100644 --- a/source/gui/widgets/menubar.cpp +++ b/source/gui/widgets/menubar.cpp @@ -100,38 +100,41 @@ namespace nana void item_renderer::background(const nana::point& pos, const nana::size& size, state_t state) { - nana::color_t bground = API::background(handle_); - nana::color_t border, body, corner; + auto bground = API::fgcolor(handle_); + ::nana::expr_color border, body, corner; switch(state) { case item_renderer::state_highlight: - border = nana::color::highlight; - body = 0xC0DDFC; - corner = paint::graphics::mix(body, bground, 0.5); + border = colors::highlight; + body.from_rgb(0xC0, 0xDD, 0xFC); + corner = body; + corner.blend(bground, 0.5); break; case item_renderer::state_selected: - border = nana::color::dark_border; - body = 0xFFFFFF; - corner = paint::graphics::mix(border, bground, 0.5); + border = colors::dark_border; + body = colors::white; + corner = body; + corner.blend(bground, 0.5); break; default: //Don't process other states. return; } nana::rectangle r(pos, size); - graph_.rectangle(r, border, false); + graph_.rectangle(r, false, border); - graph_.set_pixel(pos.x, pos.y, corner); - graph_.set_pixel(pos.x + size.width - 1, pos.y, corner); - graph_.set_pixel(pos.x, pos.y + size.height - 1, corner); - graph_.set_pixel(pos.x + size.width - 1, pos.y + size.height - 1, corner); - graph_.rectangle(r.pare_off(1), body, true); + graph_.set_color(corner); + graph_.set_pixel(pos.x, pos.y); + graph_.set_pixel(pos.x + size.width - 1, pos.y); + graph_.set_pixel(pos.x, pos.y + size.height - 1); + graph_.set_pixel(pos.x + size.width - 1, pos.y + size.height - 1); + graph_.rectangle(r.pare_off(1), true, body); } void item_renderer::caption(int x, int y, const nana::string& text) { - graph_.string(x, y, 0x0, text); + graph_.string({ x, y }, text, colors::black); } //end class item_renderer @@ -508,8 +511,8 @@ namespace nana void trigger::_m_draw() { - nana::color_t bground_color = API::background(*widget_); - graph_->rectangle(bground_color, true); + auto bgcolor = API::bgcolor(*widget_); + graph_->rectangle(true, bgcolor); item_renderer ird(*widget_, *graph_); @@ -538,8 +541,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, paint::graphics::mix(color::gray_border, bground_color, 0.6)); - graph_->line(x + 1, y1, x + 1, y2, paint::graphics::mix(color::button_face_shadow_end, bground_color, 0.5)); + graph_->line({ x, y1 }, { x, y2 }, ::nana::expr_color(colors::gray_border).blend(bgcolor, 0.6)); + graph_->line({ x + 1, y1 }, { x + 1, y2 }, ::nana::expr_color(colors::button_face_shadow_end).blend(bgcolor, 0.5)); } //Draw text, the text is transformed from orignal for hotkey character @@ -555,7 +558,7 @@ namespace nana graph_->text_metrics(ascent, descent, inleading); int x = item_pos.x + 8 + off_w; int y = item_pos.y + text_top_off + ascent + 1; - graph_->line(x, y, x + hotkey_size.width - 1, y, 0x0); + graph_->line({ x, y }, { x + static_cast(hotkey_size.width) - 1, y }, ::nana::colors::black); } item_pos.x += i->size.width; diff --git a/source/gui/widgets/panel.cpp b/source/gui/widgets/panel.cpp index 1c3f1f5f..d360d916 100644 --- a/source/gui/widgets/panel.cpp +++ b/source/gui/widgets/panel.cpp @@ -20,10 +20,6 @@ namespace nana namespace panel { //class drawer - drawer::drawer() - :window_(nullptr) - {} - void drawer::attached(widget_reference widget, graph_reference) { widget.caption(STR("Nana Panel")); @@ -33,7 +29,7 @@ namespace nana void drawer::refresh(graph_reference graph) { if(bground_mode::basic != API::effects_bground_mode(window_)) - graph.rectangle(API::background(window_), true); + graph.rectangle(true, API::bgcolor(window_)); } //end class drawer }//end namespace panel diff --git a/source/gui/widgets/picture.cpp b/source/gui/widgets/picture.cpp index ecd546ca..8b60f21f 100644 --- a/source/gui/widgets/picture.cpp +++ b/source/gui/widgets/picture.cpp @@ -22,14 +22,11 @@ namespace nana //class picture_drawer picture_drawer::picture_drawer():graph_(nullptr) { + bground_.horizontal = true; backimg_.arg = nana::arrange::unknown; backimg_.beg = backimg_.end = 0; } - picture_drawer::runtime_type::runtime_type() - :background_shadow_start(0), background_shadow_end(0), horizontal(true) - {} - void picture_drawer::attached(widget_reference& widget, graph_reference graph) { widget_ = &widget; @@ -46,11 +43,11 @@ namespace nana backimg_.image = img; } - void picture_drawer::set_shadow_background(unsigned begin_color, unsigned end_color, bool horizontal) + void picture_drawer::set_shadow_background(const ::nana::expr_color& from, const ::nana::expr_color& to, bool horizontal) { - runtime_.background_shadow_end = end_color; - runtime_.background_shadow_start = begin_color; - runtime_.horizontal = horizontal; + bground_.gradual_from = from; + bground_.gradual_to = to; + bground_.horizontal = horizontal; _m_draw_background(); } @@ -244,10 +241,12 @@ namespace nana { if(graph_ && (bground_mode::basic != API::effects_bground_mode(*widget_))) { - if(runtime_.background_shadow_end == runtime_.background_shadow_start) - graph_->rectangle((runtime_.background_shadow_end ? runtime_.background_shadow_end : widget_->background()), true); + if (bground_.gradual_from.invisible() || bground_.gradual_to.invisible()) + graph_->rectangle(true, widget_->bgcolor()); + else if(bground_.gradual_from == bground_.gradual_to) + graph_->rectangle(true, bground_.gradual_from); else - graph_->shadow_rectangle(graph_->size(), runtime_.background_shadow_start, runtime_.background_shadow_end, !runtime_.horizontal); + graph_->gradual_rectangle(graph_->size(), bground_.gradual_from, bground_.gradual_to, !bground_.horizontal); } } //end class picture_drawer @@ -278,9 +277,9 @@ namespace nana API::refresh_window(*this); } - void picture::set_shadow_background(unsigned begin_color, unsigned end_color, bool horizontal) + void picture::set_gradual_background(const ::nana::expr_color& from, const ::nana::expr_color& to, bool horizontal) { - get_drawer_trigger().set_shadow_background(begin_color, end_color, horizontal); + get_drawer_trigger().set_shadow_background(from, to, horizontal); } void picture::transparent(bool enabled) diff --git a/source/gui/widgets/progress.cpp b/source/gui/widgets/progress.cpp index 2c89cbf5..4180a0ea 100644 --- a/source/gui/widgets/progress.cpp +++ b/source/gui/widgets/progress.cpp @@ -18,11 +18,6 @@ namespace nana namespace progress { //class trigger - trigger::trigger() - : graph_(nullptr), draw_width_(static_cast(-1)), has_value_(true), - unknown_(false), max_(100), value_(0) - {} - void trigger::attached(widget_reference wd, graph_reference graph) { widget_ = &wd; @@ -112,8 +107,9 @@ namespace nana void trigger::_m_draw_box(graph_reference graph) { rectangle r = graph.size(); - graph.shadow_rectangle(r, color::button_face_shadow_end, color::button_face_shadow_start, true); - graph.rectangle_line(r, 0x808080, 0x808080, 0xFFFFFF, 0xFFFFFF); + graph.gradual_rectangle(r, colors::button_face_shadow_end, colors::button_face_shadow_start, true); + ::nana::expr_color lt{ 0x80, 0x80, 0x80 }, rb{colors::white}; + graph.frame_rectangle(r, lt, lt, rb, rb); } void trigger::_m_draw_progress(graph_reference graph) @@ -124,7 +120,7 @@ namespace nana if(false == unknown_) { if(draw_width_) - graph.shadow_rectangle(border, border, draw_width_, height, 0x6FFFA8, 0x107515, true); + graph.gradual_rectangle({ static_cast(border), static_cast(border), draw_width_, height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true); } else { @@ -134,7 +130,7 @@ namespace nana int right = (value_ >= width - 1 + border? width - 1 + border: value_); if(right >= left) - graph.shadow_rectangle(left, border, right - left + 1, height, 0x6FFFA8, 0x107515, true); + graph.gradual_rectangle({ left, static_cast(border), static_cast(right - left + 1), height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true); if(value_ >= width + block) value_ = 0; } diff --git a/source/gui/widgets/scroll.cpp b/source/gui/widgets/scroll.cpp index 780fce92..e638b3b1 100644 --- a/source/gui/widgets/scroll.cpp +++ b/source/gui/widgets/scroll.cpp @@ -1,6 +1,7 @@ /* * A Scroll Implementation - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * 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 @@ -139,31 +140,26 @@ namespace nana _m_background(graph); - unsigned width, height; - int x, y; + ::nana::rectangle r(graph.size()); if(vertical_) { - x = 0; - y = graph.height() - fixedsize; - width = graph.width(); - height = fixedsize; + r.y = r.height - fixedsize; + r.height = fixedsize; } else { - x = graph.width() - fixedsize; - y = 0; - width = fixedsize; - height = graph.height(); + r.x = r.width - fixedsize; + r.width = fixedsize; } int state = ((_m_check() == false || what == buttons::none) ? states::none : states::highlight); int moused_state = (_m_check() ? (metrics_.pressed ? states::selected : states::actived) : states::none); //draw first - _m_draw_button(graph, 0, 0, width, height, buttons::first, (buttons::first == what ? moused_state : state)); + _m_draw_button(graph, { 0, 0, r.width, r.height }, buttons::first, (buttons::first == what ? moused_state : state)); //draw second - _m_draw_button(graph, x, y, width, height, buttons::second, (buttons::second == what ? moused_state : state)); + _m_draw_button(graph, r, buttons::second, (buttons::second == what ? moused_state : state)); //draw scroll _m_draw_scroll(graph, (buttons::scroll == what ? moused_state : states::highlight)); @@ -172,7 +168,7 @@ namespace nana //private: void drawer::_m_background(graph_reference graph) { - graph.rectangle(0xF0F0F0, true); + graph.rectangle(true, {0xf0, 0xf0, 0xf0}); if(metrics_.pressed && _m_check()) { @@ -193,45 +189,44 @@ namespace nana return; if(width && height) - graph.rectangle(x, y, width, height, 0xDCDCDC, true); + graph.rectangle({ x, y, width, height }, true, {0xDC, 0xDC, 0xDC}); } } - void drawer::_m_button_frame(graph_reference graph, int x, int y, unsigned width, unsigned height, int state) + void drawer::_m_button_frame(graph_reference graph, rectangle r, int state) { if(state) { - unsigned color = 0x979797; //highlight + ::nana::expr_color clr{0x97, 0x97, 0x97}; //highlight switch(state) { case states::actived: - color = 0x86D5FD; break; + clr.from_rgb(0x86, 0xD5, 0xFD); break; case states::selected: - color = 0x3C7FB1; break; + clr.from_rgb(0x3C, 0x7F, 0xB1); break; } - graph.rectangle(rectangle(x, y, width, height), color, false); + graph.rectangle(r, false, clr); - unsigned color_x = graph.mix(color, 0xFFFFFF, 0.5); + graph.set_color(clr.blend(colors::white, 0.5)); + //unsigned color_x = graph.mix(color, 0xFFFFFF, 0.5); //deprecated - x += 2; - y += 2; - width -= 4; - height -= 4; + r.pare_off(2); if(vertical_) { - unsigned half = width / 2; - graph.rectangle(x + (width - half), y, half, height, color_x, true); - width -= half; + unsigned half = r.width / 2; + graph.rectangle({ r.x + static_cast(r.width - half), r.y, half, r.height }, true); + r.width -= half; } else { - unsigned half = height / 2; - graph.rectangle(x, y + height - half, width, half, color_x, true); - height -= half; + unsigned half = r.height / 2; + graph.rectangle({r.x, r.y + static_cast(r.height - half), r.width, half}, true); + r.height -= half; } - graph.shadow_rectangle(x, y, width, height, 0xFFFFFF, color_x, !vertical_); + //graph.shadow_rectangle(x, y, width, height, 0xFFFFFF, color_x, !vertical_); + graph.gradual_rectangle(r, colors::white, clr, !vertical_); } } @@ -275,34 +270,27 @@ namespace nana { if(_m_check()) { - int x, y; - unsigned width, height; + ::nana::rectangle r(graph.size()); if(vertical_) { - x = 0; - y = fixedsize + metrics_.scroll_pos; - - width = graph.width(); - height = static_cast(metrics_.scroll_length); + r.y = fixedsize + metrics_.scroll_pos; + r.height = static_cast(metrics_.scroll_length); } else { - x = fixedsize + metrics_.scroll_pos; - y = 0; - - width = static_cast(metrics_.scroll_length); - height = graph.height(); + r.x = fixedsize + metrics_.scroll_pos; + r.width = static_cast(metrics_.scroll_length); } - _m_button_frame(graph, x, y, width, height, state); + _m_button_frame(graph, r, state); } } - void drawer::_m_draw_button(graph_reference graph, int x, int y, unsigned width, unsigned height, buttons what, int state) + void drawer::_m_draw_button(graph_reference graph, rectangle r, buttons what, int state) { if(_m_check()) - _m_button_frame(graph, x, y, width, height, state); + _m_button_frame(graph, r, state); using namespace nana::paint::gadget; @@ -314,12 +302,12 @@ namespace nana { if(vertical_) { - y = static_cast(sz.height - fixedsize); + r.y = static_cast(sz.height - fixedsize); dir = directions::to_south; } else { - x = static_cast(sz.width - fixedsize); + r.x = static_cast(sz.width - fixedsize); dir = directions::to_east; } } @@ -327,11 +315,11 @@ namespace nana dir = vertical_ ? directions::to_north : directions::to_west; if(vertical_) - x = (static_cast(sz.width) - 16) / 2; + r.x = (static_cast(sz.width) - 16) / 2; else - y = (static_cast(sz.height) - 16) / 2; + r.y = (static_cast(sz.height) - 16) / 2; - arrow_16_pixels(graph, x, y, _m_check() ? 0x0 : 0x808080, (states::none == state ? 0 : 1), dir); + arrow_16_pixels(graph, r.x, r.y, (_m_check() ? expr_color(colors::black) : expr_color(0x80, 0x80, 0x80)), (states::none == state ? 0 : 1), dir); } } //end class drawer diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index de5c0946..6249d07b 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -248,7 +248,7 @@ namespace nana{ namespace widgets virtual std::size_t take_lines(std::size_t pos) const = 0; virtual void update_line(std::size_t textline, std::size_t secondary_before) = 0; - virtual void render(nana::color_t fgcolor) = 0; + virtual void render(const ::nana::expr_color& fgcolor) = 0; virtual nana::point caret_to_screen(upoint) = 0; virtual nana::upoint screen_to_caret(point scrpos) = 0; virtual bool move_caret_ns(bool to_north) = 0; @@ -282,11 +282,11 @@ namespace nana{ namespace widgets void update_line(std::size_t textline, std::size_t secondary_before) override { int top = editor_._m_text_top_base() + static_cast(editor_.line_height() * (textline - editor_.points_.offset.y)); - editor_.graph_.rectangle(editor_.text_area_.area.x, top, editor_.text_area_.area.width, editor_.line_height(), API::background(editor_.window_), true); - editor_._m_draw_string(top, API::foreground(editor_.window_), nana::upoint(0, editor_.points_.caret.y), editor_.textbase_.getline(textline), true); + editor_.graph_.rectangle({ editor_.text_area_.area.x, top, editor_.text_area_.area.width, editor_.line_height() }, true, API::bgcolor(editor_.window_)); + editor_._m_draw_string(top, API::fgcolor(editor_.window_), nana::upoint(0, editor_.points_.caret.y), editor_.textbase_.getline(textline), true); } - void render(nana::color_t fgcolor) override + void render(const ::nana::expr_color& fgcolor) override { auto & points = editor_.points_; @@ -685,9 +685,9 @@ namespace nana{ namespace widgets int top = caret_to_screen(upoint{ 0, static_cast(textline) }).y; const unsigned pixels = editor_.line_height(); - editor_.graph_.rectangle(editor_.text_area_.area.x, top, editor_.width_pixels(), static_cast(pixels * secondary_before), API::background(editor_.window_), true); + editor_.graph_.rectangle({ editor_.text_area_.area.x, top, editor_.width_pixels(), static_cast(pixels * secondary_before) }, true, API::bgcolor(editor_.window_)); - auto fgcolor = API::foreground(editor_.window_); + auto fgcolor = API::fgcolor(editor_.window_); auto text_ptr = editor_.textbase_.getline(textline).data(); for (std::size_t pos = 0; pos < secondary_before; ++pos, top+=pixels) @@ -700,7 +700,7 @@ namespace nana{ namespace widgets editor_.render(API::is_focus_window(editor_.window_)); } - void render(nana::color_t fgcolor) override + void render(const ::nana::expr_color& fgcolor) override { std::size_t scrlines = editor_.screen_lines(); @@ -1154,8 +1154,8 @@ namespace nana{ namespace widgets select_.dragged = false; API::create_caret(wd, 1, line_height()); - API::background(wd, 0xFFFFFF); - API::foreground(wd, 0x000000); + API::bgcolor(wd, colors::white); + API::fgcolor(wd, colors::black); } text_editor::~text_editor() @@ -1243,7 +1243,7 @@ namespace nana{ namespace widgets return false; } - void text_editor::border_renderer(std::function f) + void text_editor::border_renderer(std::function f) { text_area_.border_renderer = f; } @@ -1650,23 +1650,23 @@ namespace nana{ namespace widgets { if(text_area_.vscroll && text_area_.hscroll) { - graph_.rectangle( text_area_.area.x + static_cast(text_area_.area.width - text_area_.vscroll), - text_area_.area.y + static_cast(text_area_.area.height - text_area_.hscroll), - text_area_.vscroll, text_area_.hscroll, nana::color::button_face, true); + graph_.rectangle({ text_area_.area.right() - static_cast(text_area_.vscroll), text_area_.area.bottom() - static_cast(text_area_.hscroll), text_area_.vscroll, text_area_.hscroll }, + true, colors::button_face); } } void text_editor::render(bool has_focus) { - const nana::color_t bgcolor = _m_bgcolor(); + const auto bgcolor = _m_bgcolor(); - nana::color_t fgcolor = API::foreground(window_); + auto fgcolor = API::fgcolor(window_); if (!API::window_enabled(window_)) - fgcolor = nana::paint::graphics::mix(bgcolor, fgcolor, 0.5); + fgcolor.blend(bgcolor, 0.5); + //fgcolor = nana::paint::graphics::mix(bgcolor, fgcolor, 0.5); //deprecated //Draw background if(attributes_.enable_background) - graph_.rectangle(text_area_.area, bgcolor, true); + graph_.rectangle(text_area_.area, true, bgcolor); if(ext_renderer_.background) ext_renderer_.background(graph_, text_area_.area, bgcolor); @@ -2040,9 +2040,9 @@ namespace nana{ namespace widgets return false; } - nana::color_t text_editor::_m_bgcolor() const + ::nana::expr_color text_editor::_m_bgcolor() const { - return (!API::window_enabled(window_) ? 0xE0E0E0 : API::background(window_)); + return (!API::window_enabled(window_) ? expr_color{ 0xE0, 0xE0, 0xE0 } : API::bgcolor(window_)); } bool text_editor::_m_scroll_text(bool vert) @@ -2502,10 +2502,10 @@ namespace nana{ namespace widgets void text_editor::_m_draw_tip_string() const { - graph_.string(text_area_.area.x - points_.offset.x, text_area_.area.y, 0x787878, attributes_.tip_string); + graph_.string({ text_area_.area.x - points_.offset.x, text_area_.area.y }, attributes_.tip_string, {0x78, 0x78, 0x78}); } - void text_editor::_m_draw_string(int top, nana::color_t color, const nana::upoint& str_pos, const nana::string& linestr, bool if_mask) const + void text_editor::_m_draw_string(int top, const ::nana::expr_color& clr, const nana::upoint& str_pos, const nana::string& linestr, bool if_mask) const { int x = text_area_.area.x - points_.offset.x; int xend = text_area_.area.x + static_cast(text_area_.area.width); @@ -2514,7 +2514,7 @@ namespace nana{ namespace widgets { nana::string maskstr; maskstr.append(linestr.size(), mask_char_); - graph_.string(x, top, color, maskstr); + graph_.string({ x, top }, maskstr, clr); return; } @@ -2528,6 +2528,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 }); //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)) @@ -2542,27 +2544,30 @@ namespace nana{ namespace widgets { if (selected) { - color = 0xFFFFFF; - graph_.rectangle(x, top, str_w, line_h_pixels, 0x3399FF, true); + //color = 0xFFFFFF; //deprecated + graph_.set_text_color(colors::white); + graph_.rectangle({ x, top, str_w, line_h_pixels }, true); } - graph_.string(x, top, color, ent.begin, len); + graph_.string({x, top}, ent.begin, len); } x += static_cast(str_w); } if (selected) - graph_.rectangle(x, top, whitespace_w, line_h_pixels, 0x3399FF, true); + graph_.rectangle({ x, top, whitespace_w, line_h_pixels }, true); } else { - auto rtl_string = [this,line_h_pixels](point strpos, nana::color_t color, const nana::char_t* str, std::size_t len, std::size_t str_px, unsigned glyph_front, unsigned glyph_selected){ - graph_.string(strpos.x, strpos.y, color, str, len); + auto rtl_string = [this, line_h_pixels](point strpos, const nana::char_t* str, std::size_t len, std::size_t str_px, unsigned glyph_front, unsigned glyph_selected){ + graph_.string(strpos, str, len); paint::graphics graph(glyph_selected, line_h_pixels); graph.typeface(this->graph_.typeface()); - graph.rectangle(0x3399FF, true); + graph.rectangle(true, { 0x33, 0x99, 0xFF }); int sel_xpos = static_cast(str_px - (glyph_front + glyph_selected)); - graph.string(-sel_xpos, 0, 0xFFFFFF, str, len); + + graph.set_text_color(colors::white); + graph.string({-sel_xpos, 0}, str, len); graph_.bitblt(nana::rectangle(strpos.x + sel_xpos, strpos.y, glyph_selected, line_h_pixels), graph); }; @@ -2580,13 +2585,15 @@ namespace nana{ namespace widgets if (pos + len <= a.x || pos >= b.x) { //NOT selected - graph_.string(x, top, color, ent.begin, len); + graph_.set_text_color(clr); + graph_.string({ x, top }, ent.begin, len); } else if (a.x <= pos && pos + len <= b.x) { //Whole selected - graph_.rectangle(x, top, str_w, line_h_pixels, 0x3399FF, true); - graph_.string(x, top, 0xFFFFFF, ent.begin, len); + graph_.rectangle({ x, top, str_w, line_h_pixels }, true); + graph_.set_text_color(colors::white); + graph_.string({x, top}, ent.begin, len); } else if (pos <= a.x && a.x < pos + len) { //Partial selected @@ -2598,19 +2605,22 @@ namespace nana{ namespace widgets auto head_w = std::accumulate(pxbuf, pxbuf + (a.x - pos), unsigned()); auto sel_w = std::accumulate(pxbuf + (a.x - pos), pxbuf + (endpos - pos), unsigned()); + graph_.set_text_color(clr); if (_m_is_right_text(ent)) { //RTL - rtl_string(point{x, top}, color, ent.begin, len, str_w, head_w, sel_w); + rtl_string(point{x, top}, ent.begin, len, str_w, head_w, sel_w); } else { //LTR - graph_.string(x, top, color, ent.begin, a.x - pos); + graph_.string({ x, top }, ent.begin, a.x - pos); - graph_.rectangle(x + head_w, top, sel_w, line_h_pixels, 0x3399FF, true); - graph_.string(x + head_w, top, 0xFFFFFF, ent.begin + (a.x - pos), endpos - a.x); + graph_.rectangle({x + static_cast(head_w), top, sel_w, line_h_pixels}, true); + + graph_.set_text_color(colors::white); + graph_.string({ x + static_cast(head_w), top }, ent.begin + (a.x - pos), endpos - a.x); if (static_cast(endpos) < pos + len) - graph_.string(x + static_cast(head_w + sel_w), top, color, ent.begin + (endpos - pos), pos + len - endpos); + graph_.string({x + static_cast(head_w + sel_w), top}, ent.begin + (endpos - pos), pos + len - endpos); } } } @@ -2618,15 +2628,20 @@ namespace nana{ namespace widgets { //Partial selected int endpos = b.x; unsigned sel_w = graph_.glyph_extent_size(ent.begin, len, 0, endpos - pos).width; + if (_m_is_right_text(ent)) { //RTL - rtl_string(point{x, top}, color, ent.begin, len, str_w, 0, sel_w); + graph_.set_text_color(clr); + rtl_string({x, top}, ent.begin, len, str_w, 0, sel_w); } else { //LTR - graph_.rectangle(x, top, sel_w, line_h_pixels, 0x3399FF, true); - graph_.string(x, top, 0xFFFFFF, ent.begin, endpos - pos); - graph_.string(x + sel_w, top, color, ent.begin + (endpos - pos), pos + len - endpos); + graph_.rectangle({ x, top, sel_w, line_h_pixels }, true); + + graph_.set_text_color(colors::white); + graph_.string({ x, top }, ent.begin, endpos - pos); + graph_.set_text_color(clr); + graph_.string({x + static_cast(sel_w), top}, ent.begin + (endpos - pos), pos + len - endpos); } } } @@ -2641,30 +2656,33 @@ namespace nana{ namespace widgets unsigned str_w = graph_.text_extent_size(ent.begin, len).width; if ((x + static_cast(str_w) > text_area_.area.x) && (x < xend)) { + graph_.set_text_color(clr); std::size_t pos = ent.begin - strbeg + str_pos.x; if (pos + len <= a.x) { //Not selected - graph_.string(x, top, color, ent.begin, len); + graph_.string({x, top}, ent.begin, len); } else if (a.x < pos) { //Whole selected - graph_.rectangle(x, top, str_w, line_h_pixels, 0x3399FF, true); - graph_.string(x, top, 0xFFFFFF, ent.begin, len); + graph_.rectangle({ x, top, str_w, line_h_pixels }, true, { 0x33, 0x99, 0xFF }); + graph_.set_text_color(colors::white); + graph_.string({x, top}, ent.begin, len); } else { unsigned head_w = graph_.glyph_extent_size(ent.begin, len, 0, a.x - pos).width; if (_m_is_right_text(ent)) { //RTL - rtl_string(point{x, top}, color, ent.begin, len, str_w, head_w, str_w - head_w); + rtl_string(point{x, top}, ent.begin, len, str_w, head_w, str_w - head_w); } else { //LTR - graph_.string(x, top, color, ent.begin, a.x - pos); - graph_.rectangle(x + head_w, top, str_w - head_w, line_h_pixels, 0x3399FF, true); - graph_.string(x + head_w, top, 0xFFFFFF, ent.begin + a.x - pos, len - (a.x - pos)); + graph_.string({ x, top }, ent.begin, a.x - pos); + graph_.rectangle({ x + static_cast(head_w), top, str_w - head_w, line_h_pixels }, true); + graph_.set_text_color(colors::white); + graph_.string({ x + static_cast(head_w), top }, ent.begin + a.x - pos, len - (a.x - pos)); } } } @@ -2672,7 +2690,7 @@ namespace nana{ namespace widgets x += static_cast(str_w); } if (a.y <= static_cast(str_pos.y) && static_cast(str_pos.y) < b.y) - graph_.rectangle(x, top, whitespace_w, line_h_pixels, 0x3399FF, true); + graph_.rectangle({ x, top, whitespace_w, line_h_pixels }, true); } else if (b.y == str_pos.y) { @@ -2683,28 +2701,32 @@ namespace nana{ namespace widgets if ((x + static_cast(str_w) > text_area_.area.x) && (x < xend)) { std::size_t pos = ent.begin - strbeg + str_pos.x; - + graph_.set_text_color(clr); if (pos + len <= b.x) { - graph_.rectangle(x, top, str_w, line_h_pixels, 0x3399FF, true); - graph_.string(x, top, 0xFFFFFF, ent.begin, len); + graph_.rectangle({ x, top, str_w, line_h_pixels }, true); + graph_.set_text_color(colors::white); + graph_.string({ x, top }, ent.begin, len); } else if (pos <= b.x && b.x < pos + len) { unsigned sel_w = graph_.glyph_extent_size(ent.begin, len, 0, b.x - pos).width; if (_m_is_right_text(ent)) { //RTL - rtl_string(point{x, top}, color, ent.begin, len,str_w, 0, sel_w); + rtl_string(point{ x, top }, ent.begin, len, str_w, 0, sel_w); } else { - graph_.rectangle(x, top, sel_w, line_h_pixels, 0x3399FF, true); - graph_.string(x, top, 0xFFFFFF, ent.begin, b.x - pos); - graph_.string(x + sel_w, top, color, ent.begin + b.x - pos, len - (b.x - pos)); + graph_.rectangle({ x, top, sel_w, line_h_pixels }, true); + + graph_.set_text_color(colors::white); + graph_.string({ x, top }, ent.begin, b.x - pos); + graph_.set_text_color(clr); + graph_.string({ x + static_cast(sel_w), top }, ent.begin + b.x - pos, len - (b.x - pos)); } } else - graph_.string(x, top, color, ent.begin, len); + graph_.string({x, top}, ent.begin, len); } x += static_cast(str_w); } diff --git a/source/gui/widgets/slider.cpp b/source/gui/widgets/slider.cpp index 89a33900..9de1ce18 100644 --- a/source/gui/widgets/slider.cpp +++ b/source/gui/widgets/slider.cpp @@ -8,50 +8,54 @@ namespace nana namespace slider { - provider::~provider(){} - - renderer::~renderer(){} - class interior_renderer : public renderer { private: virtual void background(window wd, graph_reference graph, bool isglass) { - if(isglass == false) - graph.rectangle(API::background(wd), true); + if(!isglass) + graph.rectangle(true, API::bgcolor(wd)); } virtual void bar(window, graph_reference graph, const bar_t& bi) { //draw border - const nana::color_t dark = 0x83909F; - const nana::color_t gray = 0x9DAEC2; + ::nana::expr_color lt(0x83, 0x90, 0x97), rb(0x9d,0xae,0xc2); + graph.frame_rectangle(bi.r, lt, lt, rb, rb); + //const nana::color_t dark = 0x83909F; //deprecated + //const nana::color_t gray = 0x9DAEC2; - graph.rectangle_line(bi.r, - dark, dark, gray, gray); + //graph.rectangle_line(bi.r, + // dark, dark, gray, gray); //deprecated } virtual void adorn(window, graph_reference graph, const adorn_t& ad) { - int len = ad.bound.y - ad.bound.x; - const unsigned upperblock = ad.block - ad.block / 2; + auto len = static_cast(ad.bound.y - ad.bound.x); + const auto upperblock = ad.block - ad.block / 2; + + ::nana::expr_color clr_from(0x84, 0xc5, 0xff), clr_trans(0x0f, 0x41, 0xcd), clr_to(0x6e, 0x96, 0xff); if(ad.horizontal) { - graph.shadow_rectangle(ad.bound.x, ad.fixedpos, len, upperblock, 0x84C5FF, 0x0F41CD, true); - graph.shadow_rectangle(ad.bound.x, ad.fixedpos + upperblock, len, ad.block - upperblock, 0x0F41CD, 0x6E96FF, true); + //graph.shadow_rectangle(ad.bound.x, ad.fixedpos, len, upperblock, 0x84C5FF, 0x0F41CD, true); //deprecated + //graph.shadow_rectangle(ad.bound.x, ad.fixedpos + upperblock, len, ad.block - upperblock, 0x0F41CD, 0x6E96FF, true); + graph.gradual_rectangle({ ad.bound.x, ad.fixedpos, len, upperblock }, clr_from, clr_trans, true); + graph.gradual_rectangle({ ad.bound.x, ad.fixedpos + static_cast(upperblock), len, ad.block - upperblock }, clr_trans, clr_to, true); } else { - graph.shadow_rectangle(ad.fixedpos, ad.bound.x, upperblock, len, 0x84C5FF, 0x0F41CD, false); - graph.shadow_rectangle(ad.fixedpos + upperblock, ad.bound.x, ad.block - upperblock, len, 0x0F41CD, 0x6E96FF, false); + //graph.shadow_rectangle(ad.fixedpos, ad.bound.x, upperblock, len, 0x84C5FF, 0x0F41CD, false); //deprecatd + //graph.shadow_rectangle(ad.fixedpos + upperblock, ad.bound.x, ad.block - upperblock, len, 0x0F41CD, 0x6E96FF, false); + graph.gradual_rectangle({ ad.fixedpos, ad.bound.x, upperblock, len }, clr_from, clr_trans, false); //deprecatd + graph.gradual_rectangle({ ad.fixedpos + static_cast(upperblock), ad.bound.x, ad.block - upperblock, len }, clr_trans, clr_to, false); } } virtual void adorn_textbox(window, graph_reference graph, const nana::string& str, const nana::rectangle & r) { - graph.rectangle(r, 0xFFFFFF, false); - graph.string(r.x + 2, r.y + 1, 0xFFFFFF, str); + graph.rectangle(r, false, colors::white); + graph.string({ r.x + 2, r.y + 1 }, str, colors::white); } virtual void slider(window, graph_reference graph, const slider_t& s) @@ -67,7 +71,7 @@ namespace nana r.y = s.pos; r.height = s.scale; } - graph.round_rectangle(r, 3, 3, 0x0, true, 0xF0F0F0); + graph.round_rectangle(r, 3, 3, colors::black, true, {0xf0,0xf0,0xf0}); } }; diff --git a/source/gui/widgets/tabbar.cpp b/source/gui/widgets/tabbar.cpp index 8f3df11e..f42ee655 100644 --- a/source/gui/widgets/tabbar.cpp +++ b/source/gui/widgets/tabbar.cpp @@ -20,55 +20,43 @@ namespace nana { namespace tabbar { - event_agent_interface::~event_agent_interface() - {} - struct item_t { - window relative; + window relative{nullptr}; paint::image img; nana::string text; any value; - color_t bgcolor; - color_t fgcolor; - - item_t() - :relative(nullptr), bgcolor(nana::null_color), fgcolor(nana::null_color) - {} + ::nana::expr_color bgcolor; + ::nana::expr_color fgcolor; }; class def_renderer : public item_renderer { - public: - def_renderer() - : bgcolor_(0xFF000000) - {} - private: - virtual void background(graph_reference graph, const nana::rectangle& r, nana::color_t bgcolor) + virtual void background(graph_reference graph, const nana::rectangle& r, const ::nana::expr_color& bgcolor) { if(bgcolor_ != bgcolor) { bgcolor_ = bgcolor; - dark_bgcolor_ = nana::paint::graphics::mix(bgcolor, 0, 0.9); - blcolor_ = nana::paint::graphics::mix(bgcolor, 0, 0.5); - ilcolor_ = nana::paint::graphics::mix(bgcolor, 0xFFFFFF, 0.5); + dark_bgcolor_ = ::nana::expr_color{ colors::black }.blend(bgcolor, 0.1); + blcolor_ = ::nana::expr_color{ colors::black }.blend(bgcolor, 0.5); + ilcolor_ = ::nana::expr_color{ colors::white }.blend(bgcolor, 0.1); } - graph.rectangle(bgcolor, true); + graph.rectangle(true, bgcolor); } virtual void item(graph_reference graph, const item_t& m, bool active, state_t sta) { //* const nana::rectangle & r = m.r; - nana::color_t bgcolor; - nana::color_t blcolor; - nana::color_t dark_bgcolor; + expr_color bgcolor; + expr_color blcolor; + expr_color dark_bgcolor; - if(m.bgcolor == nana::null_color) + if(m.bgcolor.invisible()) { bgcolor = bgcolor_; blcolor = blcolor_; @@ -77,80 +65,82 @@ namespace nana else { bgcolor = m.bgcolor; - blcolor = graph.mix(m.bgcolor, 0, 0.5); - dark_bgcolor = nana::paint::graphics::mix(m.bgcolor, 0, 0.9); + blcolor = expr_color{ colors::black }.blend(m.bgcolor, 0.5); + //dark_bgcolor = nana::paint::graphics::mix(m.bgcolor, 0, 0.9); //deprecated + dark_bgcolor = expr_color{ colors::black }.blend(m.bgcolor, 0.1); } - graph.round_rectangle(r.x, r.y, r.width, r.height + 2, 3, 3, blcolor, true, 0xFFFFFF); + auto round_r = r; + round_r.height += 2; + graph.round_rectangle(round_r, 3, 3, blcolor, true, colors::white); - nana::color_t beg = bgcolor; - nana::color_t end = dark_bgcolor; + auto beg = bgcolor; + auto end = dark_bgcolor; if(active) { - if(m.bgcolor == nana::null_color) + if (m.bgcolor.invisible()) beg = ilcolor_; else - beg = nana::paint::graphics::mix(m.bgcolor, 0xFFFFFF, 0.5); + beg = expr_color{ m.bgcolor }.blend(colors::white, 0.5); end = bgcolor; } - if(sta == item_renderer::highlight) - beg = nana::paint::graphics::mix(beg, 0xFFFFFF, 0.5); + if (sta == item_renderer::highlight) + beg.blend(colors::white, 0.5); - graph.shadow_rectangle(r.x + 2, r.y + 2, r.width - 4, r.height - 2, beg, end, true); + //graph.shadow_rectangle(r.x + 2, r.y + 2, r.width - 4, r.height - 2, beg, end, true); //deprecated + graph.gradual_rectangle(round_r.pare_off(2), beg, end, true); } virtual void add(graph_reference graph, const nana::rectangle& r, state_t sta) { int x = r.x + (static_cast(r.width) - 14) / 2; int y = r.y + (static_cast(r.height) - 14) / 2; - nana::color_t color; + + ::nana::expr_color clr; switch(sta) { case item_renderer::highlight: - color = 0xFFFFFF; break; + clr = { colors::white }; break; case item_renderer::press: - color = 0xA0A0A0; break; + clr = { 0xA0, 0xA0, 0xA0 }; break; case item_renderer::disable: - color = 0x808080; break; + clr = { 0x80, 0x80, 0x80 }; break; default: - color = 0xF0F0F0; + clr = { 0xF0, 0xF0, 0xF0 }; } - graph.rectangle(r, bgcolor_, true); - nana::paint::gadget::cross(graph, x, y, 14, 6, color); + graph.rectangle(r, true, bgcolor_); + nana::paint::gadget::cross(graph, x, y, 14, 6, clr); } virtual void close(graph_reference graph, const nana::rectangle& r, state_t sta) { - nana::paint::gadget::close_16_pixels(graph, r.x + (r.width - 16) / 2, r.y + (r.height - 16) / 2, 1, 0x0); - if(sta == item_renderer::highlight) - { - graph.rectangle(r, 0xA0A0A0, false); - } + nana::paint::gadget::close_16_pixels(graph, r.x + (r.width - 16) / 2, r.y + (r.height - 16) / 2, 1, colors::black); + if(item_renderer::highlight == sta) + graph.rectangle(r, false, {0xa0, 0xa0, 0xa0}); } virtual void close_fly(graph_reference graph, const nana::rectangle& r, bool active, state_t sta) { using namespace nana::paint; - nana::color_t color = (active ? 0x0 : 0x9299A4); + ::nana::expr_color clr{ colors::black }; - if(item_renderer::highlight == sta) + if (sta == item_renderer::highlight) { - nana::color_t bgcolor = 0xCCD2DD; - graph.round_rectangle(r.x, r.y, r.width, r.height, 1, 1, 0x9DA3AB, false, 0); + ::nana::expr_color bgcolor{ 0xCC, 0xD2, 0xDD }; + ::nana::expr_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), graph.mix(0x9DA3AB, bgcolor, 0.8), false); - graph.rectangle(draw_r.pare_off(1), graph.mix(0x9DA3AB, bgcolor, 0.4), false); - graph.rectangle(draw_r.pare_off(1), graph.mix(0x9DA3AB, bgcolor, 0.2), false); - color = 0x0; + graph.rectangle(draw_r.pare_off(1), false, ::nana::expr_color{ rect_clr }.blend(bgcolor, 0.8)); + graph.rectangle(draw_r.pare_off(1), false, ::nana::expr_color{ rect_clr }.blend(bgcolor, 0.4)); + graph.rectangle(draw_r.pare_off(1), false, ::nana::expr_color{ rect_clr }.blend(bgcolor, 0.2)); } + else if (!active) + clr = ::nana::expr_color{ 0x92, 0x99, 0xA4 }; - int x = r.x - (16 - r.width) / 2; - int y = r.y - (16 - r.height) / 2; - - gadget::close_16_pixels(graph, x, y, 1, color); + gadget::close_16_pixels(graph, r.x - (16 - r.width) / 2, r.y - (16 - r.height) / 2, 1, clr); } virtual void back(graph_reference graph, const nana::rectangle& r, state_t sta) @@ -175,24 +165,23 @@ namespace nana { using namespace nana::paint::gadget; - nana::color_t fgcolor = 0x0; + ::nana::expr_color fgcolor(colors::black); int style = 1; if(sta == item_renderer::disable) { style = 0; - fgcolor = 0x808080; + fgcolor = { 0x80, 0x80, 0x80 }; } arrow_16_pixels(graph, r.x + (r.width - 16) / 2, r.y + (r.height - 16) / 2, fgcolor, style, dir); - if(sta == item_renderer::highlight) - { - graph.rectangle(r, 0xA0A0A0, false); - } + + if(item_renderer::highlight == sta) + graph.rectangle(r, false, { 0xA0, 0xA0, 0xA0 }); } private: - nana::color_t bgcolor_; - nana::color_t dark_bgcolor_; - nana::color_t blcolor_; - nana::color_t ilcolor_; + ::nana::expr_color bgcolor_; + ::nana::expr_color dark_bgcolor_; + ::nana::expr_color blcolor_; + ::nana::expr_color ilcolor_; }; class toolbox @@ -606,26 +595,16 @@ namespace nana } } - bool tab_color(std::size_t pos, bool is_bgcolor, nana::color_t color) + bool tab_color(std::size_t pos, bool is_bgcolor, const ::nana::expr_color& clr) { if(pos < list_.size()) { auto & m = *iterator_at(pos); - if(is_bgcolor) + auto & m_clr = (is_bgcolor ? m.bgcolor : m.fgcolor); + if (m_clr != clr) { - if(m.bgcolor != color) - { - m.bgcolor = color; - return true; - } - } - else - { - if(m.fgcolor != color) - { - m.fgcolor = color; - return true; - } + m_clr = clr; + return true; } } return false; @@ -959,15 +938,15 @@ namespace nana void _m_render() { - if(basis_.renderer == 0 || basis_.graph == 0) return; - nana::color_t bgcolor = API::background(basis_.wd); + if(!basis_.renderer || (nullptr == basis_.graph)) + return; - item_renderer::item_t m; - m.r.width = basis_.graph->width(); - m.r.height = basis_.graph->height(); + auto bgcolor = API::bgcolor(basis_.wd); + auto fgcolor = API::fgcolor(basis_.wd); + + item_renderer::item_t m = { basis_.graph->size() }; basis_.renderer->background(*basis_.graph, m.r, bgcolor); - nana::color_t fgcolor = API::foreground(basis_.wd); //the max number of pixels of tabs. int pixels = static_cast(m.r.width - _m_toolbox_pixels()); @@ -1008,8 +987,10 @@ namespace nana if(item.text.size()) { nana::size ts = basis_.graph->text_extent_size(item.text); + basis_.graph->set_text_color(m.fgcolor.invisible() ? fgcolor : m.fgcolor); nana::paint::text_renderer tr(*basis_.graph); - tr.render(m.r.x + 24, m.r.y + (m.r.height - ts.height) / 2, (m.fgcolor == nana::null_color ? fgcolor : m.fgcolor), item.text.c_str(), item.text.length(), basis_.item_pixels - 24 - 18, true); + tr.render({ m.r.x + 24, m.r.y + static_cast(m.r.height - ts.height) / 2 }, + item.text.c_str(), item.text.length(), basis_.item_pixels - 24 - 18, true); } } @@ -1023,26 +1004,28 @@ namespace nana if(_m_nextable()) { int x = _m_itembar_right(); - if(x > 0) + if (x > 0) { - basis_.graph->line(x - 2, 0, x - 2, bottom, 0x808080); - basis_.graph->line(x - 1, 0, x - 1, bottom, 0xF0F0F0); + basis_.graph->line({ x - 2, 0 }, { x - 2, bottom }, { 0x80, 0x80, 0x80 }); + basis_.graph->line({ x - 1, 0 }, { x - 1, bottom }, {0xf0, 0xf0, 0xf0}); } } + basis_.graph->set_color({ 0x80, 0x80, 0x80 }); + int right = static_cast(basis_.graph->width()); int end = active_m.r.x + static_cast(active_m.r.width); if(0 < active_m.r.x && active_m.r.x < right) - basis_.graph->line(0, bottom, active_m.r.x, bottom, 0x808080); + basis_.graph->line({ 0, bottom }, { active_m.r.x, bottom }); if(0 <= end && end < right) - basis_.graph->line(end, bottom, right, bottom, 0x808080); + basis_.graph->line({ end, bottom }, { right, bottom }); } - void _m_render_toolbox(nana::color_t bgcolor) + void _m_render_toolbox(const ::nana::expr_color& bgcolor) { bool backable = (basis_.scroll_pixels != 0); int xbase = _m_toolbox_pos(); - basis_.graph->rectangle(xbase, 0, _m_toolbox_pixels(), basis_.graph->height(), bgcolor, true); + basis_.graph->rectangle({ xbase, 0, _m_toolbox_pixels(), basis_.graph->height() }, true, bgcolor); for(int i = toolbox::ButtonAdd; i < toolbox::ButtonSize; ++i) { toolbox::button_t btn = static_cast(i); @@ -1104,27 +1087,20 @@ namespace nana struct basis_tag { - window wd; - nana::paint::graphics * graph; + window wd{nullptr}; + nana::paint::graphics * graph{nullptr}; pat::cloneable renderer; - unsigned max_pixels; - unsigned min_pixels; - unsigned item_pixels; - unsigned scroll_pixels; - std::size_t active; + unsigned max_pixels{250}; + unsigned min_pixels{100}; + unsigned item_pixels{max_pixels}; + unsigned scroll_pixels{0}; + std::size_t active{npos}; - basis_tag() - : wd(nullptr), graph(nullptr), - renderer(def_renderer()), - max_pixels(250), min_pixels(100), item_pixels(max_pixels), scroll_pixels(0), - active(npos) - { - } + basis_tag():renderer{ def_renderer() } + {} }basis_; }; - item_renderer::~item_renderer(){} - //class trigger trigger::trigger() : layouter_(new layouter) @@ -1191,9 +1167,9 @@ namespace nana layouter_->relate(i, wd); } - void trigger::tab_color(std::size_t i, bool is_bgcolor, nana::color_t color) + void trigger::tab_color(std::size_t i, bool is_bgcolor, const ::nana::expr_color& clr) { - if(layouter_->tab_color(i, is_bgcolor, color)) + if(layouter_->tab_color(i, is_bgcolor, clr)) API::refresh_window(layouter_->widget_handle()); } diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index bea084eb..b352c8e0 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -59,8 +59,8 @@ namespace nana{ namespace drawerbase { editor_ = new text_editor(wd, graph); editor_->textbase().set_event_agent(evt_agent_.get()); - editor_->border_renderer([this](graph_reference graph, nana::color_t color){ - this->_m_draw_border(graph, color); + editor_->border_renderer([this](graph_reference graph, const ::nana::expr_color& clr){ + this->_m_draw_border(graph, clr); }); _m_text_area(graph.width(), graph.height()); @@ -177,13 +177,13 @@ namespace nana{ namespace drawerbase { } } - void drawer::_m_draw_border(graph_reference graph, nana::color_t bgcolor) + void drawer::_m_draw_border(graph_reference graph, const ::nana::expr_color& bgcolor) { if (!API::widget_borderless(widget_->handle())) { nana::rectangle r(graph.size()); - graph.rectangle(r, (status_.has_focus ? 0x0595E2 : 0x999A9E), false); - graph.rectangle(r.pare_off(1), bgcolor, false); + graph.rectangle(r, false, (status_.has_focus ? ::nana::expr_color(0x05, 0x95, 0xE2) : ::nana::expr_color(0x99, 0x9A, 0x9E))); + graph.rectangle(r.pare_off(1), false, bgcolor); } } //end class drawer diff --git a/source/gui/widgets/toolbar.cpp b/source/gui/widgets/toolbar.cpp index 2ba3d9bf..e5d7e01d 100644 --- a/source/gui/widgets/toolbar.cpp +++ b/source/gui/widgets/toolbar.cpp @@ -29,45 +29,43 @@ namespace nana struct item_type { - enum{TypeButton, TypeContainer}; + enum kind{ button, container}; typedef std::size_t size_type; nana::string text; nana::paint::image image; - unsigned pixels; + unsigned pixels{0}; nana::size textsize; - bool enable; - window other; + bool enable{true}; + window other{nullptr}; - int type; + kind type; std::function answer; std::vector children; - item_type(const nana::string& text, const nana::paint::image& img, int type) - :text(text), image(img), pixels(0), enable(true), other(nullptr), type(type) + item_type(const nana::string& text, const nana::paint::image& img, kind type) + :text(text), image(img), type(type) {} }; class container { - container(const container&); - container& operator=(const container&); + container(const container&) = delete; + container& operator=(const container&) = delete; public: typedef std::vector::size_type size_type; typedef std::vector::iterator iterator; typedef std::vector::const_iterator const_iterator; - container() - {} - + container() = default; ~container() { for(auto ptr : cont_) delete ptr; } - void insert(size_type pos, const nana::string& text, const nana::paint::image& img, int type) + void insert(size_type pos, const nana::string& text, const nana::paint::image& img, item_type::kind type) { item_type* m = new item_type(text, img, type); @@ -79,12 +77,12 @@ namespace nana void push_back(const nana::string& text, const nana::paint::image& img) { - insert(cont_.size(), text, img, item_type::TypeButton); + insert(cont_.size(), text, img, item_type::kind::button); } void push_back(const nana::string& text) { - insert(cont_.size(), text, nana::paint::image(), item_type::TypeButton); + insert(cont_.size(), text, nana::paint::image(), item_type::kind::button); } void insert(size_type pos) @@ -142,22 +140,22 @@ namespace nana enum class state_t{normal, highlighted, selected}; const static unsigned extra_size = 6; - item_renderer(nana::paint::graphics& graph, bool textout, unsigned scale, nana::color_t color) - :graph(graph), textout(textout), scale(scale), color(color) + item_renderer(nana::paint::graphics& graph, bool textout, unsigned scale, const ::nana::expr_color& bgcolor) + :graph(graph), textout(textout), scale(scale), bgcolor(bgcolor) {} void operator()(int x, int y, unsigned width, unsigned height, item_type& item, state_t state) { //draw background if(state != state_t::normal) - graph.rectangle(x, y, width, height, 0x3399FF, false); + graph.rectangle({ x, y, width, height }, false, { 0x33, 0x99, 0xFF }); switch(state) { case state_t::highlighted: - graph.shadow_rectangle(x + 1, y + 1, width - 2, height - 2, color, /*graph.mix(color, 0xC0DDFC, 0.5)*/ 0xC0DDFC, true); + graph.gradual_rectangle({ x + 1, y + 1, width - 2, height - 2 }, bgcolor, { 0xC0, 0xDD, 0xFC }, true); break; case state_t::selected: - graph.shadow_rectangle(x + 1, y + 1, width - 2, height - 2, color, /*graph.mix(color, 0x99CCFF, 0.5)*/0x99CCFF, true); + graph.gradual_rectangle({ x + 1, y + 1, width - 2, height - 2 }, bgcolor, { 0x99, 0xCC, 0xFF }, true); default: break; } @@ -180,7 +178,7 @@ namespace nana gh.paste(graph, pos.x, pos.y); } else if(state == state_t::normal) - graph.blend(nana::rectangle(pos, size), graph.mix(color, 0xC0DDFC, 0.5), 0.25); + graph.blend(nana::rectangle(pos, size), ::nana::expr_color(0xc0, 0xdd, 0xfc).blend(bgcolor, 0.5), 0.25); x += scale; width -= scale; @@ -188,7 +186,7 @@ namespace nana if(textout) { - graph.string(x + (width - item.textsize.width) / 2, y + (height - item.textsize.height) / 2, 0x0, item.text); + graph.string({ x + static_cast(width - item.textsize.width) / 2, y + static_cast(height - item.textsize.height) / 2 }, item.text); } } @@ -196,27 +194,19 @@ namespace nana nana::paint::graphics& graph; bool textout; unsigned scale; - nana::color_t color; + ::nana::expr_color bgcolor; }; struct drawer::drawer_impl_type { - event_handle event_size; - unsigned scale; - bool textout; - size_type which; - item_renderer::state_t state; + event_handle event_size{nullptr}; + unsigned scale{16}; + bool textout{false}; + size_type which{npos}; + item_renderer::state_t state{item_renderer::state_t::normal}; container cont; - nana::tooltip tooltip; - - drawer_impl_type() - : event_size(nullptr), - scale(16), - textout(false), - which(npos), - state(item_renderer::state_t::normal) - {} + ::nana::tooltip tooltip; }; //class drawer @@ -403,19 +393,20 @@ namespace nana return npos; } - void drawer::_m_draw_background(nana::color_t color) + void drawer::_m_draw_background(const ::nana::expr_color& clr) { - graph_->shadow_rectangle(graph_->size(), graph_->mix(color, 0xFFFFFF, 0.9), graph_->mix(color, 0x0, 0.95), true); + graph_->gradual_rectangle(graph_->size(), ::nana::expr_color(colors::white).blend(clr, 0.1), ::nana::expr_color(colors::black).blend(clr, 0.05), true); } void drawer::_m_draw() { int x = 2, y = 2; - unsigned color = API::background(widget_->handle()); - _m_draw_background(color); + auto bgcolor = API::bgcolor(widget_->handle()); + graph_->set_text_color(bgcolor); + _m_draw_background(bgcolor); - item_renderer ir(*graph_, impl_->textout, impl_->scale, color); + item_renderer ir(*graph_, impl_->textout, impl_->scale, bgcolor); size_type index = 0; for(auto item : impl_->cont) @@ -428,7 +419,7 @@ namespace nana } else { - graph_->line(x + 2, y + 2, x + 2, y + impl_->scale + ir.extra_size - 4, 0x808080); + graph_->line({ x + 2, y + 2 }, { x + 2, y + static_cast(impl_->scale + ir.extra_size) - 4 }, { 0x80, 0x80, 0x80 }); x += 6; } ++index; @@ -463,9 +454,6 @@ namespace nana }//end namespace drawerbase //class toolbar - toolbar::toolbar() - {} - toolbar::toolbar(window wd, bool visible) { create(wd, rectangle(), visible); diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index eaefa1bb..d81b0ef1 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -223,7 +223,7 @@ namespace nana show_scroll(); //Draw background - data.graph->rectangle(data.widget_ptr->background(), true); + data.graph->rectangle(true, data.widget_ptr->bgcolor()); //Draw tree attr.tree_cont.for_each(shape.first, Renderer(this, nana::point(static_cast(attr.tree_cont.indent_size(shape.first) * shape.indent_pixels) - shape.offset_x, 1))); @@ -1093,26 +1093,26 @@ namespace nana if(compset->comp_attribute(component::bground, attr)) { - const nana::color_t color_table[][2] = { {0xE8F5FD, 0xD8F0FA}, //highlighted - {0xC4E8FA, 0xB6E6FB}, //Selected and highlighted - {0xD5EFFC, 0x99DEFD} //Selected but not highlighted + const ::nana::expr_color color_table[][2] = { { { 0xE8, 0xF5, 0xFD }, { 0xD8, 0xF0, 0xFA } }, //highlighted + { { 0xC4, 0xE8, 0xFA }, { 0xB6, 0xE6, 0xFB } }, //Selected and highlighted + { { 0xD5, 0xEF, 0xFC }, {0x99, 0xDE, 0xFD } } //Selected but not highlighted }; - const nana::color_t *colptr = nullptr; + const ::nana::expr_color *clrptr = nullptr; if(compset->item_attribute().mouse_pointed) { if(compset->item_attribute().selected) - colptr = color_table[1]; + clrptr = color_table[1]; else - colptr = color_table[0]; + clrptr = color_table[0]; } else if(compset->item_attribute().selected) - colptr = color_table[2]; + clrptr = color_table[2]; - if(colptr) + if (clrptr) { - graph.rectangle(attr.area, colptr[1], false); - graph.rectangle(attr.area.pare_off(1), *colptr, true); + graph.rectangle(attr.area, false, clrptr[1]); + graph.rectangle(attr.area.pare_off(1), true, *clrptr); } } } @@ -1131,7 +1131,7 @@ namespace nana style = 0; dir = gadget::directions::to_east; } - gadget::arrow_16_pixels(graph, attr.area.x, attr.area.y + (attr.area.height - 16) / 2, (attr.mouse_pointed ? 0x1CC4F7 : 0x0), style, dir); + gadget::arrow_16_pixels(graph, attr.area.x, attr.area.y + (attr.area.height - 16) / 2, (attr.mouse_pointed ? expr_color(0x1C, 0xC4, 0xF7) : expr_color(colors::black)), style, dir); } } @@ -1409,7 +1409,7 @@ namespace nana renderer_->text(item_graph, this); item_graph.paste(attr.area, *graph_, 1, 1); - graph_->rectangle(0x0, false); + graph_->rectangle(false, colors::black); } } private: @@ -1798,7 +1798,7 @@ namespace nana { impl_->data.graph = &graph; - widget.background(0xFFFFFF); + widget.bgcolor(colors::white); impl_->data.widget_ptr = static_cast< ::nana::treebox*>(&widget); widget.caption(STR("Nana Treebox")); } diff --git a/source/gui/widgets/widget.cpp b/source/gui/widgets/widget.cpp index 8efa77f9..7e49af99 100644 --- a/source/gui/widgets/widget.cpp +++ b/source/gui/widgets/widget.cpp @@ -141,7 +141,8 @@ namespace nana _m_move(r); } - void widget::foreground(nana::color_t value) + /* + void widget::foreground(nana::color_t value) //deprecated { _m_fgcolor(expr_color(static_cast(value))); } @@ -160,6 +161,7 @@ namespace nana { return _m_bgcolor().argb().value; } + */ void widget::fgcolor(const nana::expr_color& col) { diff --git a/source/paint/gadget.cpp b/source/paint/gadget.cpp index ca5031ee..620bcec4 100644 --- a/source/paint/gadget.cpp +++ b/source/paint/gadget.cpp @@ -22,45 +22,45 @@ namespace gadget { typedef nana::paint::graphics& graph_reference; - void hollow_triangle(graph_reference graph, int x, int y, nana::color_t color, uint32_t direction) + void hollow_triangle(graph_reference graph, int x, int y, uint32_t direction) { x += 3; y += 3; - switch(direction) + switch (direction) { case directions::to_east: - graph.line(x + 3, y + 1, x + 3, y + 9, color); - graph.line(x + 4, y + 2 , x + 7, y + 5, color); - graph.line(x + 6, y + 6, x + 4, y + 8, color); + graph.line(point{ x + 3, y + 1 }, point{ x + 3, y + 9 }); + graph.line(point{ x + 4, y + 2 }, point{ x + 7, y + 5 }); + graph.line(point{ x + 6, y + 6 }, point{ x + 4, y + 8 }); break; case directions::to_southeast: - graph.line(x + 2, y + 7, x + 7, y + 7, color); - graph.line(x + 7, y + 2, x + 7, y + 6, color); - graph.line(x + 3, y + 6, x + 6, y + 3, color); + graph.line(point{ x + 2, y + 7 }, point{ x + 7, y + 7 }); + graph.line(point{ x + 7, y + 2 }, point{ x + 7, y + 6 }); + graph.line(point{ x + 3, y + 6 }, point{ x + 6, y + 3 }); break; case directions::to_south: y += 3; - graph.line(x, y, x + 8, y, color); - graph.line(x + 1, y + 1, x + 4, y + 4, color); - graph.line(x + 7, y + 1, x + 5, y + 3, color); + graph.line(point{ x, y }, point{ x + 8, y }); + graph.line(point{ x + 1, y + 1 }, point{ x + 4, y + 4 }); + graph.line(point{ x + 7, y + 1 }, point{ x + 5, y + 3 }); break; case directions::to_west: x += 5; y += 1; - graph.line(x, y, x, y + 8, color); - graph.line(x - 4, y + 4, x - 1, y + 1, color); - graph.line(x - 3, y + 5, x - 1, y + 7, color); + graph.line(point{ x, y }, point{ x, y + 8 }); + graph.line(point{ x - 4, y + 4 }, point{ x - 1, y + 1 }); + graph.line(point{ x - 3, y + 5 }, point{ x - 1, y + 7 }); break; case directions::to_north: y += 7; - graph.line(x, y, x + 8, y, color); - graph.line(x + 1, y - 1, x + 4, y - 4, color); - graph.line(x + 5, y - 3, x + 7, y - 1, color); + graph.line(point{ x, y }, point{x + 8, y}); + graph.line(point{x + 1, y - 1}, point{x + 4, y - 4}); + graph.line(point{x + 5, y - 3}, point{x + 7, y - 1}); break; } } - void solid_triangle(graph_reference graph, int x, int y, nana::color_t color, uint32_t dir) + void solid_triangle(graph_reference graph, int x, int y, uint32_t dir) { x += 3; y += 3; @@ -68,40 +68,40 @@ namespace gadget { case directions::to_east: for(int i = 0; i < 5; ++i) - graph.line(x + 3 + i, y + 1 + i, x + 3 + i, y + 9 - i, color); + graph.line(point{ x + 3 + i, y + 1 + i }, point{ x + 3 + i, y + 9 - i }); break; case directions::to_southeast: for(int i = 0; i < 6; ++i) - graph.line(x + 2 + i, y + 7 - i, x + 7, y + 7 - i, color); + graph.line(point{ x + 2 + i, y + 7 - i }, point{ x + 7, y + 7 - i }); break; case directions::to_south: y += 3; for(int i = 0; i < 5; ++i) - graph.line(x + i, y + i, x + 8 - i, y + i, color); + graph.line(point{ x + i, y + i }, point{ x + 8 - i, y + i }); break; case directions::to_west: x += 5; y += 1; for(int i = 0; i < 5; ++i) - graph.line(x - i, y + i, x - i, y + 8 - i, color); + graph.line(point{ x - i, y + i }, point{ x - i, y + 8 - i }); break; case directions::to_north: y += 7; for(int i = 0; i < 5; ++i) - graph.line(x + i, y - i, x + 8 - i, y - i, color); + graph.line(point{ x + i, y - i }, point{ x + 8 - i, y - i }); break; } } - void direction_arrow(graph_reference graph, int x, int y, nana::color_t color, uint32_t dir) + void direction_arrow(graph_reference graph, int x, int y, uint32_t dir) { + graph.set_color({ 0x0, 0x2, 0x62 }); y += 5; switch(dir) { case directions::to_north: { x += 3; - int pixels = 1; for(int l = 0; l < 4; ++l) { @@ -110,7 +110,7 @@ namespace gadget if(l ==3 && i == 3) {} else - graph.set_pixel(x + i, y, 0x262); + graph.set_pixel(x + i, y); } x--; @@ -118,29 +118,28 @@ namespace gadget pixels += 2; } - graph.set_pixel(x + 1, y, 0x262); - graph.set_pixel(x + 2, y, 0x262); - graph.set_pixel(x + 6, y, 0x262); - graph.set_pixel(x + 7, y, 0x262); + graph.set_pixel(x + 1, y); + graph.set_pixel(x + 2, y); + graph.set_pixel(x + 6, y); + graph.set_pixel(x + 7, y); } break; case directions::to_south: { - graph.set_pixel(x, y, 0x262); - graph.set_pixel(x + 1, y, 0x262); - graph.set_pixel(x + 5, y, 0x262); - graph.set_pixel(x + 6, y, 0x262); + graph.set_pixel(x, y); + graph.set_pixel(x + 1, y); + graph.set_pixel(x + 5, y); + graph.set_pixel(x + 6, y); ++y; int pixels = 7; - for(int l = 0; l < 4; ++l) + for (int l = 0; l < 4; ++l) { - for(int i = 0; i < pixels; ++i) + for (int i = 0; i < pixels; ++i) { - if(l == 0 && i == 3){} - else - graph.set_pixel(x + i, y, 0x262); + if (l != 0 || i != 3) + graph.set_pixel(x + i, y); } x++; @@ -152,54 +151,54 @@ namespace gadget } } - void double_arrow_line(nana::paint::graphics & graph, int x, int y, color_t color, bool horizontal) + void double_arrow_line(nana::paint::graphics & graph, int x, int y, bool horizontal) { - graph.set_pixel(x, y, color); + graph.set_pixel(x, y); if(horizontal) { - graph.set_pixel(x + 1, y, color); - graph.set_pixel(x + 4, y, color); - graph.set_pixel(x + 5, y, color); + graph.set_pixel(x + 1, y); + graph.set_pixel(x + 4, y); + graph.set_pixel(x + 5, y); } else { - graph.set_pixel(x, y + 1, color); - graph.set_pixel(x, y + 4, color); - graph.set_pixel(x, y + 5, color); + graph.set_pixel(x, y + 1); + graph.set_pixel(x, y + 4); + graph.set_pixel(x, y + 5); } } - void double_arrow(nana::paint::graphics& graph, int x, int y, color_t color, directions::t dir) + void double_arrow(nana::paint::graphics& graph, int x, int y, directions::t dir) { switch(dir) { case directions::to_east: - double_arrow_line(graph, x + 4, y + 6, color, true); - double_arrow_line(graph, x + 5, y + 7, color, true); - double_arrow_line(graph, x + 6, y + 8, color, true); - double_arrow_line(graph, x + 5, y + 9, color, true); - double_arrow_line(graph, x + 4, y + 10, color, true); + double_arrow_line(graph, x + 4, y + 6, true); + double_arrow_line(graph, x + 5, y + 7, true); + double_arrow_line(graph, x + 6, y + 8, true); + double_arrow_line(graph, x + 5, y + 9, true); + double_arrow_line(graph, x + 4, y + 10, true); break; case directions::to_west: - double_arrow_line(graph, x + 5, y + 6, color, true); - double_arrow_line(graph, x + 4, y + 7, color, true); - double_arrow_line(graph, x + 3, y + 8, color, true); - double_arrow_line(graph, x + 4, y + 9, color, true); - double_arrow_line(graph, x + 5, y + 10, color, true); + double_arrow_line(graph, x + 5, y + 6, true); + double_arrow_line(graph, x + 4, y + 7, true); + double_arrow_line(graph, x + 3, y + 8, true); + double_arrow_line(graph, x + 4, y + 9, true); + double_arrow_line(graph, x + 5, y + 10, true); break; case directions::to_south: - double_arrow_line(graph, x + 5, y + 4, color, false); - double_arrow_line(graph, x + 6, y + 5, color, false); - double_arrow_line(graph, x + 7, y + 6, color, false); - double_arrow_line(graph, x + 8, y + 5, color, false); - double_arrow_line(graph, x + 9, y + 4, color, false); + double_arrow_line(graph, x + 5, y + 4, false); + double_arrow_line(graph, x + 6, y + 5, false); + double_arrow_line(graph, x + 7, y + 6, false); + double_arrow_line(graph, x + 8, y + 5, false); + double_arrow_line(graph, x + 9, y + 4, false); break; case directions::to_north: - double_arrow_line(graph, x + 5, y + 6, color, false); - double_arrow_line(graph, x + 6, y + 5, color, false); - double_arrow_line(graph, x + 7, y + 4, color, false); - double_arrow_line(graph, x + 8, y + 5, color, false); - double_arrow_line(graph, x + 9, y + 6, color, false); + double_arrow_line(graph, x + 5, y + 6, false); + double_arrow_line(graph, x + 6, y + 5, false); + double_arrow_line(graph, x + 7, y + 4, false); + double_arrow_line(graph, x + 8, y + 5, false); + double_arrow_line(graph, x + 9, y + 6, false); break; default: break; @@ -209,56 +208,59 @@ namespace gadget //arrow_16_pixels //param@style: 0 = hollow, 1 = solid - void arrow_16_pixels(nana::paint::graphics& graph, int x, int y, unsigned color, uint32_t style, directions::t dir) + void arrow_16_pixels(nana::paint::graphics& graph, int x, int y, const nana::expr_color& clr, uint32_t style, directions::t dir) { + graph.set_color(clr); switch(style) { case 1: - detail::solid_triangle(graph, x, y, color, dir); + detail::solid_triangle(graph, x, y, dir); break; case 2: - detail::direction_arrow(graph, x, y, color, dir); + detail::direction_arrow(graph, x, y, dir); break; case 3: - detail::double_arrow(graph, x, y, color, dir); + detail::double_arrow(graph, x, y, dir); break; case 0: default: - detail::hollow_triangle(graph, x, y, color, dir); + detail::hollow_triangle(graph, x, y, dir); break; } } - void close_16_pixels(nana::paint::graphics& graph, int x, int y, uint32_t style, uint32_t color) + void close_16_pixels(::nana::paint::graphics& graph, int x, int y, uint32_t style, const ::nana::expr_color& clr) { + graph.set_color(clr); if(0 == style) { x += 3; y += 3; - graph.line(x, y, x + 9, y + 9, color); - graph.line(x + 1, y, x + 9, y + 8, color); - graph.line(x, y + 1, x + 8, y + 9, color); + graph.line({ x, y }, { x + 9, y + 9 }); + graph.line({ x + 1, y }, { x + 9, y + 8 }); + graph.line({ x, y + 1 }, { x + 8, y + 9 }); - graph.line(x + 9, y, x , y + 9, color); - graph.line(x + 8, y, x, y + 8, color); - graph.line(x + 9, y + 1, x + 1, y + 9, color); + graph.line({ x + 9, y }, { x, y + 9 }); + graph.line({ x + 8, y }, { x, y + 8 }); + graph.line({ x + 9, y + 1 }, { x + 1, y + 9 }); } else { x += 4; y += 4; - graph.line(x, y, x + 7, y + 7, color); - graph.line(x + 1, y, x + 7, y + 6, color); - graph.line(x, y + 1, x + 6, y + 7, color); + graph.line({ x, y }, { x + 7, y + 7 }); + graph.line({ x + 1, y }, { x + 7, y + 6 }); + graph.line({ x, y + 1 }, { x + 6, y + 7 }); - graph.line(x + 7, y, x , y + 7, color); - graph.line(x + 6, y, x, y + 6, color); - graph.line(x + 7, y + 1, x + 1, y + 7, color); + graph.line({ x + 7, y }, { x, y + 7 }); + graph.line({ x + 6, y }, { x, y + 6 }); + graph.line({ x + 7, y + 1 }, { x + 1, y + 7 }); } } + /* void cross(graphics& graph, int x, int y, uint32_t size, uint32_t thickness, ::nana::color_t color) //deprecated { if (thickness + 2 <= size) @@ -309,8 +311,8 @@ namespace gadget graph.rectangle(ps[10].x + 1, ps[10].y + 1, (gap << 1) + thickness - 2, thickness - 2, color, true); graph.rectangle(ps[0].x + 1, ps[0].y + 1, thickness - 2, (gap << 1) + thickness - 2, color, true); } - } + */ void cross(graphics& graph, int x, int y, uint32_t size, uint32_t thickness, const ::nana::expr_color& color) { diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 586a5e72..41bbd2cc 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -522,8 +522,8 @@ namespace paint } return false; } - - unsigned graphics::bidi_string(int x, int y, color_t col, const nana::char_t* str, std::size_t len) + /* + unsigned graphics::bidi_string(int x, int y, color_t col, const nana::char_t* str, std::size_t len) //deprecated { int origin_x = x; unicode_bidi bidi; @@ -536,7 +536,9 @@ namespace paint } return static_cast(x - origin_x); } + */ + /* void graphics::string(int x, int y, color_t color, const nana::string& str, std::size_t len) { string(x, y, color, str.c_str(), len); @@ -592,7 +594,9 @@ namespace paint { string(x, y, c, str, nana::strlen(str)); } + */ + /* void graphics::set_pixel(int x, int y, color_t color) { if(handle_) @@ -816,7 +820,7 @@ namespace paint #endif if(changed_ == false) changed_ = true; } - + */ void graphics::line_begin(int x, int y) { if(!handle_) return; @@ -828,7 +832,7 @@ namespace paint handle_->line_begin_pos.y = y; #endif } - + /* void graphics::line_to(int x, int y, color_t color) { if(!handle_) return; @@ -846,6 +850,7 @@ namespace paint #endif if(changed_ == false) changed_ = true; } + */ void graphics::bitblt(int x, int y, const graphics& src) { @@ -1177,7 +1182,7 @@ namespace paint #endif } } - + /* color_t graphics::mix(color_t a, color_t b, double fade_rate) //deprecated { pixel_argb_t pa, pb, ret; @@ -1191,6 +1196,7 @@ namespace paint return ret.value; } + */ void graphics::set_color(const ::nana::expr_color& col) { @@ -1218,6 +1224,39 @@ namespace paint return static_cast(moved_pos.x - pos.x); } + void graphics::blend(const nana::rectangle& r, const ::nana::expr_color& clr, double fade_rate) + { + if (handle_) + { + nana::paint::detail::blend(handle_, r, clr.px_color().value, fade_rate); + if (changed_ == false) changed_ = true; + } + } + + void graphics::set_pixel(int x, int y, const ::nana::expr_color& clr) + { + if (handle_) + { + handle_->set_color(clr.px_color().value); + set_pixel(x, y); + } + } + + void graphics::set_pixel(int x, int y) + { + if (handle_) + { +#if defined(NANA_WINDOWS) + ::SetPixel(handle_->context, x, y, NANA_RGB(handle_->get_color())); +#elif defined(NANA_X11) + Display* disp = nana::detail::platform_spec::instance().open_display(); + handle_->update_color(); + ::XDrawPoint(disp, handle_->pixmap, handle_->context, x, y); +#endif + if (changed_ == false) changed_ = true; + } + } + void graphics::string(nana::point pos, const char_t* str, std::size_t len) { if (handle_ && str && len) @@ -1270,6 +1309,12 @@ namespace paint string(pos, str.data(), str.size()); } + void graphics::string(const point& pos, const ::nana::string& text, const expr_color& clr) + { + set_text_color(clr); + string(pos, text.data(), text.size()); + } + void graphics::line(const nana::point& pos1, const nana::point& pos2) { if ((!handle_) || (pos1 == pos2)) return; @@ -1288,6 +1333,48 @@ namespace paint if (changed_ == false) changed_ = true; } + void graphics::line(const point& pos_a, const point& pos_b, const expr_color& clr) + { + set_color(clr); + line(pos_a, pos_b); + } + + void graphics::line_to(const point& pos, const expr_color& clr) + { + if (!handle_) return; + handle_->set_color(clr.px_color().value); + line_to(pos); + } + + void graphics::line_to(const point& pos) + { + if (!handle_) return; +#if defined(NANA_WINDOWS) + handle_->update_pen(); + ::LineTo(handle_->context, pos.x, pos.y); +#elif defined(NANA_X11) + Display* disp = nana::detail::platform_spec::instance().open_display(); + handle_->update_color(); + ::XDrawLine(disp, handle_->pixmap, handle_->context, + handle_->line_begin_pos.x, handle_->line_begin_pos.y, + x, y); + handle_->line_begin_pos.x = x; + handle_->line_begin_pos.y = y; +#endif + if (changed_ == false) changed_ = true; + } + + void graphics::rectangle(bool solid) + { + rectangle(size(), solid); + } + + void graphics::rectangle(bool solid, const ::nana::expr_color& clr) + { + set_color(clr); + rectangle(size(), solid); + } + void graphics::rectangle(const ::nana::rectangle& r, bool solid) { if (r.width && r.height && handle_ && r.right() > 0 && r.bottom() > 0) @@ -1308,6 +1395,23 @@ namespace paint } } + void graphics::rectangle(const ::nana::rectangle& r, bool solid, const expr_color& clr) + { + set_color(clr); + rectangle(r, solid); + } + + void graphics::frame_rectangle(const ::nana::rectangle& r, const ::nana::expr_color& left_clr, const ::nana::expr_color& top_clr, const ::nana::expr_color& right_clr, const ::nana::expr_color& bottom_clr) + { + int right = r.right() - 1; + int bottom = r.bottom() - 1; + line_begin(r.x, r.y); + line_to({ right, r.y }, top_clr); + line_to({ right, bottom }, right_clr); + line_to({ r.x, bottom }, bottom_clr); + line_to({ r.x, r.y }, left_clr); + } + void graphics::gradual_rectangle(const ::nana::rectangle& r, const ::nana::expr_color& from, const ::nana::expr_color& to, bool vertical) { #if defined(NANA_WINDOWS) @@ -1364,6 +1468,40 @@ namespace paint #endif if (changed_ == false) changed_ = true; } + + void graphics::round_rectangle(const ::nana::rectangle& r, unsigned radius_x, unsigned radius_y, const expr_color& clr, bool solid, const expr_color& solid_clr) + { + if (handle_) + { +#if defined(NANA_WINDOWS) + handle_->set_color(clr.px_color().value); + if (solid) + { + handle_->update_pen(); + handle_->brush.set(handle_->context, handle_->brush.Solid, solid_clr.px_color().value); + ::RoundRect(handle_->context, r.x, r.y, r.right(), r.bottom(), static_cast(radius_x * 2), static_cast(radius_y * 2)); + } + else + { + handle_->update_brush(); + handle_->round_region.set(r, radius_x, radius_y); + ::FrameRgn(handle_->context, handle_->round_region.handle, handle_->brush.handle, 1, 1); + } + if(changed_ == false) changed_ = true; +#elif defined(NANA_X11) + if(solid && (color == solid_clr)) + { + rectangle(r, true, color); + } + else + { + rectangle(r, false, color); + if(solid) + rectangle(rectangle(r).pare_off(1), true, solid_clr); + } +#endif + } + } //end class graphics }//end namespace paint diff --git a/source/paint/text_renderer.cpp b/source/paint/text_renderer.cpp index 0831c58f..a88bb1cc 100644 --- a/source/paint/text_renderer.cpp +++ b/source/paint/text_renderer.cpp @@ -118,13 +118,14 @@ namespace nana { graphics & graph; int x, endpos; - nana::color_t color; //deprecated + //nana::color_t color; //deprecated + ::nana::expr_color fgcolor; unsigned omitted_pixels; nana::unicode_bidi bidi; std::vector reordered; - draw_string_omitted(graphics& graph, int x, int endpos, nana::color_t color, bool omitted) - : graph(graph), x(x), endpos(endpos), color(color) + draw_string_omitted(graphics& graph, int x, int endpos, const ::nana::expr_color& fgcolor, bool omitted) + : graph(graph), x(x), endpos(endpos), fgcolor(fgcolor) { omitted_pixels = (omitted ? graph.text_extent_size(STR("..."), 3).width : 0); if(endpos - x > static_cast(omitted_pixels)) @@ -169,7 +170,8 @@ namespace nana nana::paint::graphics dum_graph(r.width, r.height); dum_graph.bitblt(r, graph, pos); - dum_graph.string(0, 0, color, i.begin, len); + dum_graph.set_text_color(fgcolor); + dum_graph.string({}, i.begin, len); r.x = pos.x; r.y = top; @@ -553,7 +555,8 @@ namespace nana : graph_(graph), text_align_(ta) {} - void text_renderer::render(int x, int y, nana::color_t col, const nana::char_t * str, std::size_t len) + /* + void text_renderer::render(int x, int y, color_t col, const char_t * str, std::size_t len) { if(graph_) { @@ -562,8 +565,8 @@ namespace nana helper::for_each_line(str, len, y, ds); } } - - void text_renderer::render(int x, int y, nana::color_t col, const nana::char_t * str, std::size_t len, unsigned restricted_pixels, bool omitted) + + void text_renderer::render(int x, int y, color_t col, const char_t * str, std::size_t len, unsigned restricted_pixels, bool omitted) //deprecated { if(graph_) { @@ -572,8 +575,9 @@ namespace nana helper::for_each_line(str, len, y, dso); } } - - void text_renderer::render(int x, int y, nana::color_t col, const nana::char_t * str, std::size_t len, unsigned restricted_pixels) + */ + /* + void text_renderer::render(int x, int y, color_t col, const nana::char_t * str, std::size_t len, unsigned restricted_pixels) { if(graph_) { @@ -582,8 +586,9 @@ namespace nana helper::for_each_line(str, len, y, dsacl); } } + */ - nana::size text_renderer::extent_size(int x, int y, const nana::char_t* str, std::size_t len, unsigned restricted_pixels) const + nana::size text_renderer::extent_size(int x, int y, const char_t* str, std::size_t len, unsigned restricted_pixels) const { nana::size extents; if(graph_) @@ -596,7 +601,16 @@ namespace nana return extents; } - void text_renderer::render(const nana::point& pos, const nana::char_t* str, std::size_t len, unsigned restricted_pixels, bool omitted) + void text_renderer::render(const point& pos, const char_t * str, std::size_t len) + { + if (graph_) + { + helper::draw_string ds(graph_.handle(), pos.x, static_cast(graph_.width()), text_align_); + helper::for_each_line(str, len, pos.y, ds); + } + } + + void text_renderer::render(const point& pos, const char_t* str, std::size_t len, unsigned restricted_pixels, bool omitted) { if (graph_) { @@ -604,6 +618,15 @@ namespace nana helper::for_each_line(str, len, pos.y, dso); } } + + void text_renderer::render(const point& pos, const char_t * str, std::size_t len, unsigned restricted_pixels) + { + if (graph_) + { + helper::draw_string_auto_changing_lines dsacl(graph_, pos.x, pos.x + static_cast(restricted_pixels), text_align_); + helper::for_each_line(str, len, pos.y, dsacl); + } + } //end class text_renderer