Refined code
refined code and implemented select all(ctrl+a) for text_editor
This commit is contained in:
parent
e64b6ec2b2
commit
e5aeb8420f
@ -71,30 +71,31 @@ namespace nana
|
|||||||
|
|
||||||
struct keyboard
|
struct keyboard
|
||||||
{
|
{
|
||||||
enum t{
|
enum{
|
||||||
//Control Code for ASCII
|
//Control Code for ASCII
|
||||||
select_all = 0x1,
|
start_of_headline = 0x1, //Ctrl+A
|
||||||
end_of_text = 0x3, //Ctrl+C
|
end_of_text = 0x3, //Ctrl+C
|
||||||
backspace = 0x8, tab = 0x9,
|
backspace = 0x8, tab = 0x9,
|
||||||
enter_n = 0xA, enter = 0xD, enter_r = 0xD,
|
enter_n = 0xA, enter = 0xD, enter_r = 0xD,
|
||||||
alt = 0x12,
|
alt = 0x12,
|
||||||
sync_idel = 0x16, //Ctrl+V
|
sync_idel = 0x16, //Ctrl+V
|
||||||
cancel = 0x18, //Ctrl+X
|
cancel = 0x18, //Ctrl+X
|
||||||
end_of_medium = 0x19, //Ctrl+Y
|
end_of_medium = 0x19, //Ctrl+Y
|
||||||
substitute = 0x1A, //Ctrl+Z
|
substitute = 0x1A, //Ctrl+Z
|
||||||
escape = 0x1B,
|
escape = 0x1B,
|
||||||
|
|
||||||
//The following names are intuitive name of ASCII control codes
|
//The following names are intuitive name of ASCII control codes
|
||||||
copy = 0x3, //end_of_text
|
select_all = start_of_headline,
|
||||||
paste = 0x16, //sync_idel
|
copy = end_of_text,
|
||||||
cut = 0x18, //cancel
|
paste = sync_idel,
|
||||||
redo = 0x19, //end_of_medium
|
cut = cancel,
|
||||||
undo = 0x1A, //substitue
|
redo = end_of_medium,
|
||||||
|
undo = substitute,
|
||||||
|
|
||||||
//System Code for OS
|
//System Code for OS
|
||||||
os_pageup = 0x21, os_pagedown,
|
os_pageup = 0x21, os_pagedown,
|
||||||
os_arrow_left = 0x25, os_arrow_up, os_arrow_right, os_arrow_down,
|
os_arrow_left = 0x25, os_arrow_up, os_arrow_right, os_arrow_down,
|
||||||
os_insert = 0x2D, os_del
|
os_insert = 0x2D, os_del
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Pixel Buffer Implementation
|
* Pixel Buffer 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.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -19,14 +20,14 @@ namespace nana{ namespace paint
|
|||||||
{
|
{
|
||||||
///@brief Seek a pixel address by using offset bytes
|
///@brief Seek a pixel address by using offset bytes
|
||||||
///@return the specified pixel address
|
///@return the specified pixel address
|
||||||
inline pixel_argb_t * pixel_at(pixel_argb_t * p, std::size_t bytes)
|
inline pixel_color_t * pixel_at(pixel_color_t * p, std::size_t bytes)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<pixel_argb_t*>(reinterpret_cast<char*>(p) + bytes);
|
return reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(p)+bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const pixel_argb_t * pixel_at(const pixel_argb_t * p, std::size_t bytes)
|
inline const pixel_color_t * pixel_at(const pixel_color_t * p, std::size_t bytes)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<const pixel_argb_t*>(reinterpret_cast<const char*>(p) + bytes);
|
return reinterpret_cast<const pixel_color_t*>(reinterpret_cast<const char*>(p)+bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
class pixel_buffer
|
class pixel_buffer
|
||||||
@ -34,7 +35,7 @@ namespace nana{ namespace paint
|
|||||||
struct pixel_buffer_storage;
|
struct pixel_buffer_storage;
|
||||||
typedef bool (pixel_buffer:: * unspecified_bool_t)() const;
|
typedef bool (pixel_buffer:: * unspecified_bool_t)() const;
|
||||||
public:
|
public:
|
||||||
pixel_buffer();
|
pixel_buffer() = default;
|
||||||
pixel_buffer(drawable_type, const nana::rectangle& want_rectangle);
|
pixel_buffer(drawable_type, const nana::rectangle& want_rectangle);
|
||||||
pixel_buffer(drawable_type, std::size_t top, std::size_t lines);
|
pixel_buffer(drawable_type, std::size_t top, std::size_t lines);
|
||||||
pixel_buffer(std::size_t width, std::size_t height);
|
pixel_buffer(std::size_t width, std::size_t height);
|
||||||
@ -60,9 +61,9 @@ namespace nana{ namespace paint
|
|||||||
std::size_t bytes_per_line() const;
|
std::size_t bytes_per_line() const;
|
||||||
nana::size size() const;
|
nana::size size() const;
|
||||||
|
|
||||||
pixel_argb_t * at(const point& pos) const;
|
pixel_color_t * at(const point& pos) const;
|
||||||
pixel_argb_t * raw_ptr(std::size_t row) const;
|
pixel_color_t * raw_ptr(std::size_t row) const;
|
||||||
pixel_argb_t * operator[](std::size_t row) const;
|
pixel_color_t * operator[](std::size_t row) const;
|
||||||
|
|
||||||
void put(const unsigned char* rawbits, std::size_t width, std::size_t height, std::size_t bits_per_pixel, std::size_t bytes_per_line, bool is_negative);
|
void put(const unsigned char* rawbits, std::size_t width, std::size_t height, std::size_t bits_per_pixel, std::size_t bytes_per_line, bool is_negative);
|
||||||
|
|
||||||
@ -70,11 +71,10 @@ namespace nana{ namespace paint
|
|||||||
void line(const ::nana::point& pos_beg, const ::nana::point& pos_end, const ::nana::expr_color&, double fade_rate);
|
void line(const ::nana::point& pos_beg, const ::nana::point& pos_end, const ::nana::expr_color&, double fade_rate);
|
||||||
|
|
||||||
void rectangle(const nana::rectangle&, const ::nana::expr_color&, double fade_rate, bool solid);
|
void rectangle(const nana::rectangle&, const ::nana::expr_color&, double fade_rate, bool solid);
|
||||||
//void shadow_rectangle(const nana::rectangle&, nana::color_t beg, nana::color_t end, double fade_rate, bool vertical); //deprecated
|
|
||||||
void gradual_rectangle(const ::nana::rectangle&, const ::nana::expr_color& from, const ::nana::expr_color& to, double fade_rate, bool vertical);
|
void gradual_rectangle(const ::nana::rectangle&, const ::nana::expr_color& from, const ::nana::expr_color& to, double fade_rate, bool vertical);
|
||||||
|
|
||||||
pixel_argb_t pixel(int x, int y) const;
|
pixel_color_t pixel(int x, int y) const;
|
||||||
void pixel(int x, int y, pixel_argb_t);
|
void pixel(int x, int y, pixel_color_t);
|
||||||
|
|
||||||
void paste(drawable_type, int x, int y) const;
|
void paste(drawable_type, int x, int y) const;
|
||||||
void paste(const nana::rectangle& s_r, drawable_type, int x, int y) const;
|
void paste(const nana::rectangle& s_r, drawable_type, int x, int y) const;
|
||||||
|
|||||||
@ -1165,10 +1165,14 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
bool text_editor::respone_keyboard(nana::char_t key, bool enterable) //key is a character of ASCII code
|
bool text_editor::respone_keyboard(nana::char_t key, bool enterable) //key is a character of ASCII code
|
||||||
{
|
{
|
||||||
if (keyboard::end_of_text == key)
|
switch (key)
|
||||||
{
|
{
|
||||||
|
case keyboard::end_of_text:
|
||||||
copy();
|
copy();
|
||||||
return false;
|
return false;
|
||||||
|
case keyboard::select_all:
|
||||||
|
select(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributes_.editable && enterable)
|
if (attributes_.editable && enterable)
|
||||||
@ -1577,6 +1581,7 @@ namespace nana{ namespace widgets
|
|||||||
if(select_.b.y) --select_.b.y;
|
if(select_.b.y) --select_.b.y;
|
||||||
select_.b.x = static_cast<unsigned>(textbase_.getline(select_.b.y).size());
|
select_.b.x = static_cast<unsigned>(textbase_.getline(select_.b.y).size());
|
||||||
select_.mode_selection = selection::mode_method_selected;
|
select_.mode_selection = selection::mode_method_selected;
|
||||||
|
render(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1939,6 +1944,7 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
void text_editor::move_left()
|
void text_editor::move_left()
|
||||||
{
|
{
|
||||||
|
bool do_render = false;
|
||||||
if(_m_cancel_select(1) == false)
|
if(_m_cancel_select(1) == false)
|
||||||
{
|
{
|
||||||
if(points_.caret.x)
|
if(points_.caret.x)
|
||||||
@ -1952,23 +1958,19 @@ namespace nana{ namespace widgets
|
|||||||
if (attributes_.line_wrapped)
|
if (attributes_.line_wrapped)
|
||||||
adjust_y = behavior_->adjust_caret_into_screen();
|
adjust_y = behavior_->adjust_caret_into_screen();
|
||||||
|
|
||||||
bool adjust_x = _m_move_offset_x_while_over_border(-2);
|
do_render = (_m_move_offset_x_while_over_border(-2) || adjust_y);
|
||||||
|
|
||||||
if (adjust_x || adjust_y)
|
|
||||||
render(true);
|
|
||||||
}
|
}
|
||||||
else if(points_.caret.y)
|
else if(points_.caret.y)
|
||||||
{ //Move to previous line
|
{ //Move to previous line
|
||||||
points_.caret.x = static_cast<unsigned>(textbase_.getline(-- points_.caret.y).size());
|
points_.caret.x = static_cast<unsigned>(textbase_.getline(-- points_.caret.y).size());
|
||||||
if (behavior_->adjust_caret_into_screen())
|
do_render = behavior_->adjust_caret_into_screen();
|
||||||
render(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
do_render = behavior_->adjust_caret_into_screen();
|
||||||
behavior_->adjust_caret_into_screen();
|
|
||||||
|
if (do_render)
|
||||||
render(true);
|
render(true);
|
||||||
}
|
|
||||||
|
|
||||||
_m_scrollbar();
|
_m_scrollbar();
|
||||||
points_.xpos = points_.caret.x;
|
points_.xpos = points_.caret.x;
|
||||||
@ -1976,6 +1978,7 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
void text_editor::move_right()
|
void text_editor::move_right()
|
||||||
{
|
{
|
||||||
|
bool do_render = false;
|
||||||
if(_m_cancel_select(2) == false)
|
if(_m_cancel_select(2) == false)
|
||||||
{
|
{
|
||||||
nana::string lnstr = textbase_.getline(points_.caret.y);
|
nana::string lnstr = textbase_.getline(points_.caret.y);
|
||||||
@ -1987,23 +1990,20 @@ namespace nana{ namespace widgets
|
|||||||
++points_.caret.x;
|
++points_.caret.x;
|
||||||
#endif
|
#endif
|
||||||
bool adjust_y = (attributes_.line_wrapped && behavior_->adjust_caret_into_screen());
|
bool adjust_y = (attributes_.line_wrapped && behavior_->adjust_caret_into_screen());
|
||||||
if (_m_move_offset_x_while_over_border(2) || adjust_y)
|
do_render = (_m_move_offset_x_while_over_border(2) || adjust_y);
|
||||||
render(true);
|
|
||||||
}
|
}
|
||||||
else if(textbase_.lines() && (points_.caret.y < textbase_.lines() - 1))
|
else if(textbase_.lines() && (points_.caret.y < textbase_.lines() - 1))
|
||||||
{ //Move to next line
|
{ //Move to next line
|
||||||
points_.caret.x = 0;
|
points_.caret.x = 0;
|
||||||
++ points_.caret.y;
|
++ points_.caret.y;
|
||||||
|
do_render = behavior_->adjust_caret_into_screen();
|
||||||
if (behavior_->adjust_caret_into_screen())
|
|
||||||
render(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
do_render = behavior_->adjust_caret_into_screen();
|
||||||
if (behavior_->adjust_caret_into_screen())
|
|
||||||
render(true);
|
if (do_render)
|
||||||
}
|
render(true);
|
||||||
|
|
||||||
_m_scrollbar();
|
_m_scrollbar();
|
||||||
points_.xpos = points_.caret.x;
|
points_.xpos = points_.caret.x;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace nana
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
graph.gradual_rectangle({ ad.fixedpos, ad.bound.x, upperblock, len }, clr_from, clr_trans, false); //deprecatd
|
graph.gradual_rectangle({ ad.fixedpos, ad.bound.x, upperblock, len }, clr_from, clr_trans, false);
|
||||||
graph.gradual_rectangle({ ad.fixedpos + static_cast<int>(upperblock), ad.bound.x, ad.block - upperblock, len }, clr_trans, clr_to, false);
|
graph.gradual_rectangle({ ad.fixedpos + static_cast<int>(upperblock), ad.bound.x, ad.block - upperblock, len }, clr_trans, clr_to, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,8 +69,10 @@ namespace nana
|
|||||||
class controller
|
class controller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum dir_t{DirHorizontal, DirVertical};
|
enum class style{horizontal, vertical};
|
||||||
enum where_t{WhereNone, WhereBar, WhereSlider};
|
enum class parts{none, bar, slider};
|
||||||
|
//enum dir_t{DirHorizontal, DirVertical}; //deprecated
|
||||||
|
//enum where_t{WhereNone, WhereBar, WhereSlider};
|
||||||
|
|
||||||
typedef drawer_trigger::graph_reference graph_reference;
|
typedef drawer_trigger::graph_reference graph_reference;
|
||||||
|
|
||||||
@ -83,7 +85,7 @@ namespace nana
|
|||||||
proto_.renderer = pat::cloneable<renderer>(interior_renderer());
|
proto_.renderer = pat::cloneable<renderer>(interior_renderer());
|
||||||
|
|
||||||
attr_.skdir = seekdir::bilateral;
|
attr_.skdir = seekdir::bilateral;
|
||||||
attr_.dir = this->DirHorizontal;
|
attr_.dir = style::horizontal;
|
||||||
attr_.vcur = 0;
|
attr_.vcur = 0;
|
||||||
attr_.vmax = 10;
|
attr_.vmax = 10;
|
||||||
attr_.slider_scale = 8;
|
attr_.slider_scale = 8;
|
||||||
@ -142,7 +144,7 @@ namespace nana
|
|||||||
|
|
||||||
void vertical(bool v)
|
void vertical(bool v)
|
||||||
{
|
{
|
||||||
dir_t dir = (v ? this->DirVertical : this->DirHorizontal);
|
auto dir = (v ? style::vertical : style::horizontal);
|
||||||
|
|
||||||
if(dir != attr_.dir)
|
if(dir != attr_.dir)
|
||||||
{
|
{
|
||||||
@ -153,7 +155,7 @@ namespace nana
|
|||||||
|
|
||||||
bool vertical() const
|
bool vertical() const
|
||||||
{
|
{
|
||||||
return (this->DirVertical == attr_.dir);
|
return (style::vertical == attr_.dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vmax(unsigned m)
|
void vmax(unsigned m)
|
||||||
@ -203,56 +205,56 @@ namespace nana
|
|||||||
attr_.adorn_pos = attr_.pos;
|
attr_.adorn_pos = attr_.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
where_t seek_where(int x, int y) const
|
parts seek_where(::nana::point pos) const
|
||||||
{
|
{
|
||||||
nana::rectangle r = _m_bar_area();
|
nana::rectangle r = _m_bar_area();
|
||||||
if(attr_.dir == this->DirVertical)
|
if(style::vertical == attr_.dir)
|
||||||
{
|
{
|
||||||
std::swap(x, y);
|
std::swap(pos.x, pos.y);
|
||||||
std::swap(r.width, r.height);
|
std::swap(r.width, r.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = _m_slider_pos();
|
int sdpos = _m_slider_pos();
|
||||||
if(pos <= x && x < pos + static_cast<int>(attr_.slider_scale))
|
if (sdpos <= pos.x && pos.x < sdpos + static_cast<int>(attr_.slider_scale))
|
||||||
return WhereSlider;
|
return parts::slider;
|
||||||
|
|
||||||
pos = static_cast<int>(attr_.slider_scale) / 2;
|
sdpos = static_cast<int>(attr_.slider_scale) / 2;
|
||||||
|
|
||||||
if(pos <= x && x < pos + static_cast<int>(r.width))
|
if (sdpos <= pos.x && pos.x < sdpos + static_cast<int>(r.width))
|
||||||
{
|
{
|
||||||
if(y < r.y + static_cast<int>(r.height))
|
if(pos.y < r.y + static_cast<int>(r.height))
|
||||||
return WhereBar;
|
return parts::bar;
|
||||||
}
|
}
|
||||||
return WhereNone;
|
return parts::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
//set_slider_pos
|
//set_slider_pos
|
||||||
//move the slider to a position where a mouse click on WhereBar.
|
//move the slider to a position where a mouse click on WhereBar.
|
||||||
bool set_slider_pos(int x, int y)
|
bool set_slider_pos(::nana::point pos)
|
||||||
{
|
{
|
||||||
if(this->DirVertical == attr_.dir)
|
if(style::vertical == attr_.dir)
|
||||||
std::swap(x, y);
|
std::swap(pos.x, pos.y);
|
||||||
|
|
||||||
x -= _m_slider_refpos();
|
pos.x -= _m_slider_refpos();
|
||||||
if(x < 0)
|
if(pos.x < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(x > static_cast<int>(_m_scale()))
|
if(pos.x > static_cast<int>(_m_scale()))
|
||||||
x = static_cast<int>(_m_scale());
|
pos.x = static_cast<int>(_m_scale());
|
||||||
|
|
||||||
double pos = attr_.pos;
|
double attr_pos = attr_.pos;
|
||||||
double dx = _m_evaluate_by_seekdir(x);
|
double dx = _m_evaluate_by_seekdir(pos.x);
|
||||||
|
|
||||||
attr_.pos = dx;
|
attr_.pos = dx;
|
||||||
attr_.adorn_pos = dx;
|
attr_.adorn_pos = dx;
|
||||||
_m_mk_slider_value_by_pos();
|
_m_mk_slider_value_by_pos();
|
||||||
|
|
||||||
return (attr_.pos != pos);
|
return (attr_.pos != attr_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_slider_refpos(::nana::point pos)
|
void set_slider_refpos(::nana::point pos)
|
||||||
{
|
{
|
||||||
if(this->DirVertical == attr_.dir)
|
if(style::vertical == attr_.dir)
|
||||||
std::swap(pos.x, pos.y);
|
std::swap(pos.x, pos.y);
|
||||||
|
|
||||||
slider_state_.trace = slider_state_.TraceCapture;
|
slider_state_.trace = slider_state_.TraceCapture;
|
||||||
@ -286,21 +288,21 @@ namespace nana
|
|||||||
return (slider_state_.trace == slider_state_.TraceCapture);
|
return (slider_state_.trace == slider_state_.TraceCapture);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool move_slider(int x, int y)
|
bool move_slider(const ::nana::point& pos)
|
||||||
{
|
{
|
||||||
int mpos = (this->DirHorizontal == attr_.dir ? x : y);
|
int mpos = (style::horizontal == attr_.dir ? pos.x : pos.y);
|
||||||
int pos = slider_state_.snap_pos + (mpos - slider_state_.refpos.x);
|
int adorn_pos = slider_state_.snap_pos + (mpos - slider_state_.refpos.x);
|
||||||
|
|
||||||
if(pos > 0)
|
if (adorn_pos > 0)
|
||||||
{
|
{
|
||||||
int scale = static_cast<int>(_m_scale());
|
int scale = static_cast<int>(_m_scale());
|
||||||
if(pos > scale)
|
if (adorn_pos > scale)
|
||||||
pos = scale;
|
adorn_pos = scale;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pos = 0;
|
adorn_pos = 0;
|
||||||
|
|
||||||
double dstpos = _m_evaluate_by_seekdir(pos);
|
double dstpos = _m_evaluate_by_seekdir(adorn_pos);
|
||||||
attr_.is_draw_adorn = true;
|
attr_.is_draw_adorn = true;
|
||||||
|
|
||||||
if(dstpos != attr_.pos)
|
if(dstpos != attr_.pos)
|
||||||
@ -312,15 +314,15 @@ namespace nana
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool move_adorn(int x, int y)
|
bool move_adorn(const ::nana::point& pos)
|
||||||
{
|
{
|
||||||
double xpos = (this->DirHorizontal == attr_.dir ? x : y);
|
double xpos = (style::horizontal == attr_.dir ? pos.x : pos.y);
|
||||||
|
|
||||||
xpos -= _m_slider_refpos();
|
xpos -= _m_slider_refpos();
|
||||||
if(xpos > static_cast<int>(_m_scale()))
|
if(xpos > static_cast<int>(_m_scale()))
|
||||||
xpos = static_cast<int>(_m_scale());
|
xpos = static_cast<int>(_m_scale());
|
||||||
|
|
||||||
int pos = static_cast<int>(attr_.adorn_pos);
|
int adorn_pos = static_cast<int>(attr_.adorn_pos);
|
||||||
xpos = _m_evaluate_by_seekdir(xpos);
|
xpos = _m_evaluate_by_seekdir(xpos);
|
||||||
|
|
||||||
attr_.adorn_pos = xpos;
|
attr_.adorn_pos = xpos;
|
||||||
@ -329,7 +331,7 @@ namespace nana
|
|||||||
if(slider_state_.trace == slider_state_.TraceNone)
|
if(slider_state_.trace == slider_state_.TraceNone)
|
||||||
slider_state_.trace = slider_state_.TraceOver;
|
slider_state_.trace = slider_state_.TraceOver;
|
||||||
|
|
||||||
return (pos != static_cast<int>(xpos));
|
return (adorn_pos != static_cast<int>(xpos));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned move_step(bool forward)
|
unsigned move_step(bool forward)
|
||||||
@ -385,7 +387,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
auto sz = other_.graph->size();
|
auto sz = other_.graph->size();
|
||||||
nana::rectangle r = sz;
|
nana::rectangle r = sz;
|
||||||
if(this->DirHorizontal == attr_.dir)
|
if(style::horizontal == attr_.dir)
|
||||||
{
|
{
|
||||||
r.x = attr_.slider_scale / 2 - attr_.border;
|
r.x = attr_.slider_scale / 2 - attr_.border;
|
||||||
r.width = (static_cast<int>(sz.width) > (r.x << 1) ? sz.width - (r.x << 1) : 0);
|
r.width = (static_cast<int>(sz.width) > (r.x << 1) ? sz.width - (r.x << 1) : 0);
|
||||||
@ -401,7 +403,7 @@ namespace nana
|
|||||||
unsigned _m_scale() const
|
unsigned _m_scale() const
|
||||||
{
|
{
|
||||||
nana::rectangle r = _m_bar_area();
|
nana::rectangle r = _m_bar_area();
|
||||||
return ((this->DirHorizontal == attr_.dir ? r.width : r.height) - attr_.border * 2);
|
return ((style::horizontal == attr_.dir ? r.width : r.height) - attr_.border * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
double _m_evaluate_by_seekdir(double pos) const
|
double _m_evaluate_by_seekdir(double pos) const
|
||||||
@ -465,7 +467,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
renderer::bar_t bar;
|
renderer::bar_t bar;
|
||||||
|
|
||||||
bar.horizontal = (this->DirHorizontal == attr_.dir);
|
bar.horizontal = (style::horizontal == attr_.dir);
|
||||||
bar.border_size = attr_.border;
|
bar.border_size = attr_.border;
|
||||||
bar.r = _m_bar_area();
|
bar.r = _m_bar_area();
|
||||||
|
|
||||||
@ -494,35 +496,23 @@ namespace nana
|
|||||||
nana::string str = proto_.provider->adorn_trace(attr_.vmax, vadorn);
|
nana::string str = proto_.provider->adorn_trace(attr_.vmax, vadorn);
|
||||||
if(str.size())
|
if(str.size())
|
||||||
{
|
{
|
||||||
nana::rectangle r;
|
|
||||||
nana::size ts = other_.graph->text_extent_size(str);
|
nana::size ts = other_.graph->text_extent_size(str);
|
||||||
ts.width += 6;
|
ts.width += 6;
|
||||||
ts.height += 2;
|
ts.height += 2;
|
||||||
|
|
||||||
r.width = ts.width;
|
int x, y;
|
||||||
r.height = ts.height;
|
|
||||||
|
|
||||||
const int room = static_cast<int>(attr_.adorn_pos);
|
const int room = static_cast<int>(attr_.adorn_pos);
|
||||||
if(bar.horizontal)
|
if(bar.horizontal)
|
||||||
{
|
{
|
||||||
r.y = adorn.fixedpos + static_cast<int>(adorn.block - ts.height) / 2;
|
y = adorn.fixedpos + static_cast<int>(adorn.block - ts.height) / 2;
|
||||||
if(room > static_cast<int>(ts.width + 2))
|
x = (room > static_cast<int>(ts.width + 2) ? room - static_cast<int>(ts.width + 2) : room + 2) + _m_slider_refpos();
|
||||||
r.x = room - static_cast<int>(ts.width + 2);
|
|
||||||
else
|
|
||||||
r.x = room + 2;
|
|
||||||
|
|
||||||
r.x += this->_m_slider_refpos();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r.x = (other_.graph->width() - ts.width) / 2;
|
x = (other_.graph->width() - ts.width) / 2;
|
||||||
if(room > static_cast<int>(ts.height + 2))
|
y = (room > static_cast<int>(ts.height + 2) ? room - static_cast<int>(ts.height + 2) : room + 2) + _m_slider_refpos();
|
||||||
r.y = room - static_cast<int>(ts.height + 2);
|
|
||||||
else
|
|
||||||
r.y = room + 2;
|
|
||||||
r.y += this->_m_slider_refpos();
|
|
||||||
}
|
}
|
||||||
proto_.renderer->adorn_textbox(other_.wd, *other_.graph, str, r);
|
proto_.renderer->adorn_textbox(other_.wd, *other_.graph, str, {x, y, ts.width, ts.height});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -531,7 +521,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
renderer::slider_t s;
|
renderer::slider_t s;
|
||||||
s.pos = static_cast<int>(attr_.pos);
|
s.pos = static_cast<int>(attr_.pos);
|
||||||
s.horizontal = (this->DirHorizontal == attr_.dir);
|
s.horizontal = (style::horizontal == attr_.dir);
|
||||||
s.scale = attr_.slider_scale;
|
s.scale = attr_.slider_scale;
|
||||||
s.border = attr_.border;
|
s.border = attr_.border;
|
||||||
proto_.renderer->slider(other_.wd, *other_.graph, s);
|
proto_.renderer->slider(other_.wd, *other_.graph, s);
|
||||||
@ -553,7 +543,7 @@ namespace nana
|
|||||||
struct attr_tag
|
struct attr_tag
|
||||||
{
|
{
|
||||||
seekdir skdir;
|
seekdir skdir;
|
||||||
dir_t dir;
|
style dir;
|
||||||
unsigned border;
|
unsigned border;
|
||||||
unsigned vmax;
|
unsigned vmax;
|
||||||
unsigned vcur;
|
unsigned vcur;
|
||||||
@ -607,10 +597,11 @@ namespace nana
|
|||||||
|
|
||||||
void trigger::mouse_down(graph_reference, const arg_mouse& arg)
|
void trigger::mouse_down(graph_reference, const arg_mouse& arg)
|
||||||
{
|
{
|
||||||
controller_t::where_t what = impl_->seek_where(arg.pos.x, arg.pos.y);
|
using parts = controller_t::parts;
|
||||||
if(controller_t::WhereBar == what || controller_t::WhereSlider == what)
|
auto what = impl_->seek_where(arg.pos);
|
||||||
|
if(parts::bar == what || parts::slider == what)
|
||||||
{
|
{
|
||||||
bool mkdir = impl_->set_slider_pos(arg.pos.x, arg.pos.y);
|
bool mkdir = impl_->set_slider_pos(arg.pos);
|
||||||
impl_->set_slider_refpos(arg.pos);
|
impl_->set_slider_refpos(arg.pos);
|
||||||
if(mkdir)
|
if(mkdir)
|
||||||
{
|
{
|
||||||
@ -635,13 +626,13 @@ namespace nana
|
|||||||
bool mkdraw = false;
|
bool mkdraw = false;
|
||||||
if(impl_->if_trace_slider())
|
if(impl_->if_trace_slider())
|
||||||
{
|
{
|
||||||
mkdraw = impl_->move_slider(arg.pos.x, arg.pos.y);
|
mkdraw = impl_->move_slider(arg.pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
controller_t::where_t what = impl_->seek_where(arg.pos.x, arg.pos.y);
|
auto what = impl_->seek_where(arg.pos);
|
||||||
if(controller_t::WhereNone != what)
|
if(controller_t::parts::none != what)
|
||||||
mkdraw = impl_->move_adorn(arg.pos.x, arg.pos.y);
|
mkdraw = impl_->move_adorn(arg.pos);
|
||||||
else
|
else
|
||||||
mkdraw = impl_->reset_adorn();
|
mkdraw = impl_->reset_adorn();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1225,9 +1225,7 @@ namespace nana
|
|||||||
|
|
||||||
if(pos_.y < item_pos_.y + static_cast<int>(node_r.height))
|
if(pos_.y < item_pos_.y + static_cast<int>(node_r.height))
|
||||||
{
|
{
|
||||||
int logic_x = pos_.x - item_pos_.x;
|
auto logic_pos = pos_ - item_pos_;
|
||||||
int logic_y = pos_.y - item_pos_.y;
|
|
||||||
|
|
||||||
node_ = &node;
|
node_ = &node;
|
||||||
|
|
||||||
for(int comp = static_cast<int>(component::begin); comp != static_cast<int>(component::end); ++comp)
|
for(int comp = static_cast<int>(component::begin); comp != static_cast<int>(component::end); ++comp)
|
||||||
@ -1235,7 +1233,7 @@ namespace nana
|
|||||||
nana::rectangle r = node_r;
|
nana::rectangle r = node_r;
|
||||||
if(comp_placer->locate(static_cast<component>(comp), node_attr_, &r))
|
if(comp_placer->locate(static_cast<component>(comp), node_attr_, &r))
|
||||||
{
|
{
|
||||||
if(r.is_hit(logic_x, logic_y))
|
if(r.is_hit(logic_pos))
|
||||||
{
|
{
|
||||||
what_ = static_cast<component>(comp);
|
what_ = static_cast<component>(comp);
|
||||||
if(component::expender == what_ && (false == node_attr_.has_children))
|
if(component::expender == what_ && (false == node_attr_.has_children))
|
||||||
@ -1275,10 +1273,7 @@ namespace nana
|
|||||||
|
|
||||||
nana::rectangle trigger::item_locator::text_pos() const
|
nana::rectangle trigger::item_locator::text_pos() const
|
||||||
{
|
{
|
||||||
auto r = node_text_r_;
|
return{node_text_r_.x + item_pos_.x, node_text_r_.y + item_pos_.y, node_text_r_.width, node_text_r_.height};
|
||||||
r.x += item_pos_.x;
|
|
||||||
r.y += item_pos_.y;
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
//end class item_locator
|
//end class item_locator
|
||||||
|
|
||||||
@ -1289,10 +1284,10 @@ namespace nana
|
|||||||
typedef tree_cont_type::node_type node_type;
|
typedef tree_cont_type::node_type node_type;
|
||||||
|
|
||||||
item_renderer(implement * impl, const nana::point& pos)
|
item_renderer(implement * impl, const nana::point& pos)
|
||||||
:impl_(impl), pos_(pos)
|
: impl_(impl), pos_(pos),
|
||||||
|
bgcolor_(impl->data.widget_ptr->bgcolor()),
|
||||||
|
fgcolor_(impl->data.widget_ptr->fgcolor())
|
||||||
{
|
{
|
||||||
bgcolor_ = impl_->data.widget_ptr->bgcolor();
|
|
||||||
fgcolor_ = impl_->data.widget_ptr->fgcolor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//affect
|
//affect
|
||||||
@ -1762,7 +1757,6 @@ namespace nana
|
|||||||
|
|
||||||
unsigned trigger::node_width(const node_type *node) const
|
unsigned trigger::node_width(const node_type *node) const
|
||||||
{
|
{
|
||||||
//return (static_cast<int>(impl_->data.graph->text_extent_size(node->value.second.text).width) + impl_->shape.text_offset * 2 + static_cast<unsigned>(impl_->shape.crook_pixels + impl_->shape.image_pixels));
|
|
||||||
node_attribute node_attr;
|
node_attribute node_attr;
|
||||||
impl_->assign_node_attr(node_attr, node);
|
impl_->assign_node_attr(node_attr, node);
|
||||||
return impl_->data.comp_placer->item_width(*impl_->data.graph, node_attr);
|
return impl_->data.comp_placer->item_width(*impl_->data.graph, node_attr);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Graphics Gadget Implementation
|
* Graphics Gadget 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.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -260,60 +261,6 @@ namespace gadget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void cross(graphics& graph, int x, int y, uint32_t size, uint32_t thickness, ::nana::color_t color) //deprecated
|
|
||||||
{
|
|
||||||
if (thickness + 2 <= size)
|
|
||||||
{
|
|
||||||
int gap = (size - thickness) / 2;
|
|
||||||
|
|
||||||
nana::point ps[12];
|
|
||||||
ps[0].x = x + gap;
|
|
||||||
ps[1].x = ps[0].x + thickness - 1;
|
|
||||||
ps[1].y = ps[0].y = y;
|
|
||||||
|
|
||||||
ps[2].x = ps[1].x;
|
|
||||||
ps[2].y = y + gap;
|
|
||||||
|
|
||||||
ps[3].x = ps[2].x + gap;
|
|
||||||
ps[3].y = ps[2].y;
|
|
||||||
|
|
||||||
ps[4].x = ps[3].x;
|
|
||||||
ps[4].y = ps[3].y + thickness - 1;
|
|
||||||
|
|
||||||
ps[5].x = ps[1].x;
|
|
||||||
ps[5].y = ps[4].y;
|
|
||||||
|
|
||||||
ps[6].x = ps[5].x;
|
|
||||||
ps[6].y = ps[5].y + gap;
|
|
||||||
|
|
||||||
ps[7].x = x + gap;
|
|
||||||
ps[7].y = ps[6].y;
|
|
||||||
|
|
||||||
ps[8].x = ps[7].x;
|
|
||||||
ps[8].y = ps[4].y;
|
|
||||||
|
|
||||||
ps[9].x = x;
|
|
||||||
ps[9].y = ps[4].y;
|
|
||||||
|
|
||||||
ps[10].x = x;
|
|
||||||
ps[10].y = y + gap;
|
|
||||||
|
|
||||||
ps[11].x = x + gap;
|
|
||||||
ps[11].y = y + gap;
|
|
||||||
|
|
||||||
nana::color_t dkcolor = graph.mix(color, 0x0, 0.5); //deprecated
|
|
||||||
|
|
||||||
for (int i = 0; i < 11; ++i)
|
|
||||||
graph.line(ps[i], ps[i + 1], dkcolor);
|
|
||||||
graph.line(ps[11], ps[0], dkcolor);
|
|
||||||
|
|
||||||
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)
|
void cross(graphics& graph, int x, int y, uint32_t size, uint32_t thickness, const ::nana::expr_color& color)
|
||||||
{
|
{
|
||||||
if (thickness + 2 <= size)
|
if (thickness + 2 <= size)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Pixel Buffer Implementation
|
* Pixel Buffer 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.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -21,7 +22,6 @@
|
|||||||
|
|
||||||
namespace nana{ namespace paint
|
namespace nana{ namespace paint
|
||||||
{
|
{
|
||||||
|
|
||||||
nana::rectangle valid_rectangle(const nana::size& s, const nana::rectangle& r)
|
nana::rectangle valid_rectangle(const nana::size& s, const nana::rectangle& r)
|
||||||
{
|
{
|
||||||
nana::rectangle good_r;
|
nana::rectangle good_r;
|
||||||
@ -29,6 +29,21 @@ namespace nana{ namespace paint
|
|||||||
return good_r;
|
return good_r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(NANA_WINDOWS)
|
||||||
|
void assign_windows_bitmapinfo(const size& sz, BITMAPINFO& bi)
|
||||||
|
{
|
||||||
|
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
|
||||||
|
bi.bmiHeader.biWidth = sz.width;
|
||||||
|
bi.bmiHeader.biHeight = -static_cast<int>(sz.height);
|
||||||
|
bi.bmiHeader.biPlanes = 1;
|
||||||
|
bi.bmiHeader.biBitCount = 32;
|
||||||
|
bi.bmiHeader.biCompression = BI_RGB;
|
||||||
|
bi.bmiHeader.biSizeImage = static_cast<DWORD>(sz.width * sz.height * sizeof(pixel_color_t));
|
||||||
|
bi.bmiHeader.biClrUsed = 0;
|
||||||
|
bi.bmiHeader.biClrImportant = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct pixel_buffer::pixel_buffer_storage
|
struct pixel_buffer::pixel_buffer_storage
|
||||||
: private nana::noncopyable
|
: private nana::noncopyable
|
||||||
{
|
{
|
||||||
@ -36,9 +51,9 @@ namespace nana{ namespace paint
|
|||||||
const drawable_type drawable; //Attached handle
|
const drawable_type drawable; //Attached handle
|
||||||
const nana::rectangle valid_r;
|
const nana::rectangle valid_r;
|
||||||
const nana::size pixel_size;
|
const nana::size pixel_size;
|
||||||
pixel_argb_t * raw_pixel_buffer;
|
pixel_color_t * raw_pixel_buffer;
|
||||||
const std::size_t bytes_per_line;
|
const std::size_t bytes_per_line;
|
||||||
bool alpha_channel;
|
bool alpha_channel{false};
|
||||||
#if defined(NANA_X11)
|
#if defined(NANA_X11)
|
||||||
struct x11_members
|
struct x11_members
|
||||||
{
|
{
|
||||||
@ -49,25 +64,20 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
struct image_processor_tag
|
struct image_processor_tag
|
||||||
{
|
{
|
||||||
paint::image_process::stretch_interface * stretch_receptacle;
|
paint::image_process::stretch_interface * stretch_receptacle{nullptr};
|
||||||
paint::image_process::stretch_interface * const * stretch;
|
paint::image_process::stretch_interface * const * stretch;
|
||||||
paint::image_process::alpha_blend_interface * alpha_blend_receptacle;
|
paint::image_process::alpha_blend_interface * alpha_blend_receptacle{nullptr};
|
||||||
paint::image_process::alpha_blend_interface * const * alpha_blend;
|
paint::image_process::alpha_blend_interface * const * alpha_blend;
|
||||||
paint::image_process::blend_interface * blend_receptacle;
|
paint::image_process::blend_interface * blend_receptacle{nullptr};
|
||||||
paint::image_process::blend_interface * const * blend;
|
paint::image_process::blend_interface * const * blend;
|
||||||
paint::image_process::line_interface * line_receptacle;
|
paint::image_process::line_interface * line_receptacle{nullptr};
|
||||||
paint::image_process::line_interface * const * line;
|
paint::image_process::line_interface * const * line;
|
||||||
paint::image_process::blur_interface * blur_receptacle;
|
paint::image_process::blur_interface * blur_receptacle{nullptr};
|
||||||
paint::image_process::blur_interface * const * blur;
|
paint::image_process::blur_interface * const * blur;
|
||||||
|
|
||||||
image_processor_tag()
|
image_processor_tag()
|
||||||
: stretch_receptacle(nullptr),
|
|
||||||
alpha_blend_receptacle(nullptr),
|
|
||||||
blend_receptacle(nullptr),
|
|
||||||
line_receptacle(nullptr),
|
|
||||||
blur_receptacle(nullptr)
|
|
||||||
{
|
{
|
||||||
detail::image_process_provider & provider = detail::image_process_provider::instance();
|
auto & provider = detail::image_process_provider::instance();
|
||||||
stretch = provider.stretch();
|
stretch = provider.stretch();
|
||||||
alpha_blend = provider.alpha_blend();
|
alpha_blend = provider.alpha_blend();
|
||||||
blend = provider.blend();
|
blend = provider.blend();
|
||||||
@ -80,9 +90,8 @@ namespace nana{ namespace paint
|
|||||||
: drawable(nullptr),
|
: drawable(nullptr),
|
||||||
valid_r(0, 0, static_cast<unsigned>(width), static_cast<unsigned>(height)),
|
valid_r(0, 0, static_cast<unsigned>(width), static_cast<unsigned>(height)),
|
||||||
pixel_size(static_cast<unsigned>(width), static_cast<unsigned>(height)),
|
pixel_size(static_cast<unsigned>(width), static_cast<unsigned>(height)),
|
||||||
raw_pixel_buffer(new pixel_argb_t[width * height]),
|
raw_pixel_buffer(new pixel_color_t[width * height]),
|
||||||
bytes_per_line(width * sizeof(pixel_argb_t)),
|
bytes_per_line(width * sizeof(pixel_color_t))
|
||||||
alpha_channel(false)
|
|
||||||
{
|
{
|
||||||
#if defined(NANA_X11)
|
#if defined(NANA_X11)
|
||||||
nana::detail::platform_spec & spec = nana::detail::platform_spec::instance();
|
nana::detail::platform_spec & spec = nana::detail::platform_spec::instance();
|
||||||
@ -109,13 +118,12 @@ namespace nana{ namespace paint
|
|||||||
valid_r(valid_rectangle(paint::detail::drawable_size(drawable), want_r)),
|
valid_r(valid_rectangle(paint::detail::drawable_size(drawable), want_r)),
|
||||||
pixel_size(valid_r),
|
pixel_size(valid_r),
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
raw_pixel_buffer(reinterpret_cast<pixel_argb_t*>(reinterpret_cast<char*>(drawable->pixbuf_ptr + valid_r.x) + drawable->bytes_per_line * valid_r.y)),
|
raw_pixel_buffer(reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(drawable->pixbuf_ptr + valid_r.x) + drawable->bytes_per_line * valid_r.y)),
|
||||||
bytes_per_line(drawable->bytes_per_line),
|
bytes_per_line(drawable->bytes_per_line)
|
||||||
#else
|
#else
|
||||||
raw_pixel_buffer(nullptr),
|
raw_pixel_buffer(nullptr),
|
||||||
bytes_per_line(sizeof(pixel_argb_t) * valid_r.width),
|
bytes_per_line(sizeof(pixel_color_t) * valid_r.width)
|
||||||
#endif
|
#endif
|
||||||
alpha_channel(false)
|
|
||||||
{
|
{
|
||||||
#if defined(NANA_X11)
|
#if defined(NANA_X11)
|
||||||
nana::detail::platform_spec & spec = nana::detail::platform_spec::instance();
|
nana::detail::platform_spec & spec = nana::detail::platform_spec::instance();
|
||||||
@ -134,12 +142,12 @@ namespace nana{ namespace paint
|
|||||||
XDestroyImage(x11.image);
|
XDestroyImage(x11.image);
|
||||||
throw std::runtime_error("Nana.pixel_buffer: Invalid pixel buffer context.");
|
throw std::runtime_error("Nana.pixel_buffer: Invalid pixel buffer context.");
|
||||||
}
|
}
|
||||||
raw_pixel_buffer = reinterpret_cast<pixel_argb_t*>(x11.image->data);
|
raw_pixel_buffer = reinterpret_cast<pixel_color_t*>(x11.image->data);
|
||||||
}
|
}
|
||||||
else if(16 == x11.image->depth)
|
else if(16 == x11.image->depth)
|
||||||
{
|
{
|
||||||
//565 to 32
|
//565 to 32
|
||||||
raw_pixel_buffer = new pixel_argb_t[valid_r.width * valid_r.height];
|
raw_pixel_buffer = new pixel_color_t[valid_r.width * valid_r.height];
|
||||||
assign(reinterpret_cast<unsigned char*>(x11.image->data), valid_r.width, valid_r.height, 16, x11.image->bytes_per_line, false);
|
assign(reinterpret_cast<unsigned char*>(x11.image->data), valid_r.width, valid_r.height, 16, x11.image->bytes_per_line, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -170,160 +178,126 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
void assign(const unsigned char* rawbits, std::size_t width, std::size_t height, std::size_t bits_per_pixel, std::size_t bytes_per_line, bool is_negative)
|
void assign(const unsigned char* rawbits, std::size_t width, std::size_t height, std::size_t bits_per_pixel, std::size_t bytes_per_line, bool is_negative)
|
||||||
{
|
{
|
||||||
|
if (!raw_pixel_buffer)
|
||||||
|
return;
|
||||||
|
|
||||||
auto rawptr = raw_pixel_buffer;
|
auto rawptr = raw_pixel_buffer;
|
||||||
if(rawptr)
|
if(32 == bits_per_pixel)
|
||||||
{
|
{
|
||||||
if(32 == bits_per_pixel)
|
if((pixel_size.width == width) && (pixel_size.height == height) && is_negative)
|
||||||
{
|
{
|
||||||
if((pixel_size.width == width) && (pixel_size.height == height) && is_negative)
|
memcpy(rawptr, rawbits, (pixel_size.width * pixel_size.height) * 4);
|
||||||
{
|
|
||||||
memcpy(rawptr, rawbits, (pixel_size.width * pixel_size.height) * 4);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::size_t line_bytes = (pixel_size.width < width ? pixel_size.width : width) * sizeof(pixel_argb_t);
|
|
||||||
|
|
||||||
if(pixel_size.height < height)
|
|
||||||
height = pixel_size.height;
|
|
||||||
|
|
||||||
auto d = rawptr;
|
|
||||||
if(is_negative)
|
|
||||||
{
|
|
||||||
const unsigned char* s = rawbits;
|
|
||||||
for(std::size_t i = 0; i < height; ++i)
|
|
||||||
{
|
|
||||||
memcpy(d, s, line_bytes);
|
|
||||||
d += pixel_size.width;
|
|
||||||
s += bytes_per_line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const unsigned char* s = rawbits + bytes_per_line * (height - 1);
|
|
||||||
for(std::size_t i = 0; i < height; ++i)
|
|
||||||
{
|
|
||||||
memcpy(d, s, line_bytes);
|
|
||||||
d += pixel_size.width;
|
|
||||||
s -= bytes_per_line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(24 == bits_per_pixel)
|
else
|
||||||
{
|
{
|
||||||
if(pixel_size.width < width)
|
std::size_t line_bytes = (pixel_size.width < width ? pixel_size.width : width) * sizeof(pixel_color_t);
|
||||||
width = pixel_size.width;
|
|
||||||
|
|
||||||
if(pixel_size.height < height)
|
if(pixel_size.height < height)
|
||||||
height = pixel_size.height;
|
height = pixel_size.height;
|
||||||
|
|
||||||
auto d = rawptr;
|
auto d = rawptr;
|
||||||
if(is_negative)
|
const unsigned char* s;
|
||||||
|
int src_line_bytes;
|
||||||
|
|
||||||
|
if (is_negative)
|
||||||
{
|
{
|
||||||
const unsigned char* s = rawbits;
|
s = rawbits;
|
||||||
for(std::size_t i = 0; i < height; ++i)
|
src_line_bytes = -static_cast<int>(bytes_per_line);
|
||||||
{
|
|
||||||
auto p = d;
|
|
||||||
const auto end = p + width;
|
|
||||||
std::size_t s_index = 0;
|
|
||||||
for(; p < end; ++p)
|
|
||||||
{
|
|
||||||
const unsigned char * s_p = s + s_index;
|
|
||||||
p->element.blue = s_p[0];
|
|
||||||
p->element.green = s_p[1];
|
|
||||||
p->element.red = s_p[2];
|
|
||||||
s_index += 3;
|
|
||||||
}
|
|
||||||
d += pixel_size.width;
|
|
||||||
s += bytes_per_line;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const unsigned char* s = rawbits + bytes_per_line * (height - 1);
|
s = rawbits + bytes_per_line * (height - 1);
|
||||||
for(std::size_t i = 0; i < height; ++i)
|
src_line_bytes = static_cast<int>(bytes_per_line);
|
||||||
{
|
}
|
||||||
auto p = d;
|
|
||||||
const auto end = p + width;
|
for(std::size_t i = 0; i < height; ++i)
|
||||||
const unsigned char* s_p = s;
|
{
|
||||||
for(; p < end; ++p)
|
memcpy(d, s, line_bytes);
|
||||||
{
|
d += pixel_size.width;
|
||||||
p->element.blue = s_p[0];
|
s -= src_line_bytes;
|
||||||
p->element.green = s_p[1];
|
|
||||||
p->element.red = s_p[2];
|
|
||||||
s_p += 3;
|
|
||||||
}
|
|
||||||
d += pixel_size.width;
|
|
||||||
s -= bytes_per_line;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(16 == bits_per_pixel)
|
}
|
||||||
|
else if(24 == bits_per_pixel)
|
||||||
|
{
|
||||||
|
if(pixel_size.width < width)
|
||||||
|
width = pixel_size.width;
|
||||||
|
|
||||||
|
if(pixel_size.height < height)
|
||||||
|
height = pixel_size.height;
|
||||||
|
|
||||||
|
auto d = rawptr;
|
||||||
|
const unsigned char* s;
|
||||||
|
int src_bytes_per_line;
|
||||||
|
|
||||||
|
if (is_negative)
|
||||||
{
|
{
|
||||||
if(pixel_size.width < width)
|
s = rawbits;
|
||||||
width = pixel_size.width;
|
src_bytes_per_line = -static_cast<int>(bytes_per_line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s = rawbits + bytes_per_line * (height - 1);
|
||||||
|
src_bytes_per_line = static_cast<int>(bytes_per_line);
|
||||||
|
}
|
||||||
|
|
||||||
if(pixel_size.height < height)
|
for(std::size_t i = 0; i < height; ++i)
|
||||||
height = pixel_size.height;
|
{
|
||||||
|
auto p = d;
|
||||||
auto d = rawptr;
|
const auto end = p + width;
|
||||||
|
const unsigned char* s_p = s;
|
||||||
auto rgb_table = new unsigned char[32];
|
for(; p < end; ++p)
|
||||||
|
|
||||||
for(std::size_t i =0; i < 32; ++i)
|
|
||||||
rgb_table[i] = static_cast<unsigned char>(i * 255 / 31);
|
|
||||||
|
|
||||||
if(is_negative)
|
|
||||||
{
|
{
|
||||||
//const unsigned short* s = reinterpret_cast<const unsigned short*>(rawbits);
|
p->element.blue = s_p[0];
|
||||||
for(std::size_t i = 0; i < height; ++i)
|
p->element.green = s_p[1];
|
||||||
{
|
p->element.red = s_p[2];
|
||||||
auto p = d;
|
s_p += 3;
|
||||||
const auto end = p + width;
|
|
||||||
auto s_p = reinterpret_cast<const unsigned short*>(rawbits);
|
|
||||||
for(; p < end; ++p)
|
|
||||||
{
|
|
||||||
p->element.red = rgb_table[(*s_p >> 11) & 0x1F];
|
|
||||||
#if defined(NANA_X11)
|
|
||||||
p->element.green = (*s_p >> 5) & 0x3F;
|
|
||||||
p->element.blue = rgb_table[*s_p & 0x1F];
|
|
||||||
#else
|
|
||||||
p->element.green = rgb_table[(*s_p>> 6) & 0x1F];
|
|
||||||
p->element.blue = rgb_table[(*s_p >> 1) & 0x1F];
|
|
||||||
#endif
|
|
||||||
++s_p;
|
|
||||||
}
|
|
||||||
d += pixel_size.width;
|
|
||||||
rawbits += bytes_per_line;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
d += pixel_size.width;
|
||||||
|
s -= bytes_per_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(16 == bits_per_pixel)
|
||||||
|
{
|
||||||
|
if(pixel_size.width < width)
|
||||||
|
width = pixel_size.width;
|
||||||
|
|
||||||
|
if(pixel_size.height < height)
|
||||||
|
height = pixel_size.height;
|
||||||
|
|
||||||
|
unsigned char rgb_table[32];
|
||||||
|
for(std::size_t i =0; i < 32; ++i)
|
||||||
|
rgb_table[i] = static_cast<unsigned char>(i * 255 / 31);
|
||||||
|
|
||||||
|
int src_bytes_per_line;
|
||||||
|
if (!is_negative)
|
||||||
|
{
|
||||||
|
rawbits += bytes_per_line * (height - 1);
|
||||||
|
src_bytes_per_line = static_cast<int>(bytes_per_line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
src_bytes_per_line = -static_cast<int>(bytes_per_line);
|
||||||
|
|
||||||
|
auto d = rawptr;
|
||||||
|
for (std::size_t i = 0; i < height; ++i)
|
||||||
|
{
|
||||||
|
auto p = d;
|
||||||
|
const auto end = p + width;
|
||||||
|
auto s_p = reinterpret_cast<const unsigned short*>(rawbits);
|
||||||
|
for (; p < end; ++p)
|
||||||
{
|
{
|
||||||
// const unsigned short* s = reinterpret_cast<const unsigned short*>(rawbits + bytes_per_line * (height - 1));
|
p->element.red = rgb_table[(*s_p >> 11) & 0x1F];
|
||||||
rawbits += bytes_per_line * (height - 1);
|
|
||||||
for(std::size_t i = 0; i < height; ++i)
|
|
||||||
{
|
|
||||||
auto p = d;
|
|
||||||
const auto end = p + width;
|
|
||||||
auto s_p = reinterpret_cast<const unsigned short*>(rawbits);
|
|
||||||
for(; p < end; ++p)
|
|
||||||
{
|
|
||||||
p->element.red = rgb_table[(*s_p >> 11) & 0x1F];
|
|
||||||
#if defined(NANA_X11)
|
#if defined(NANA_X11)
|
||||||
p->element.green = ((*s_p >> 5) & 0x3F);
|
p->element.green = (*s_p >> 5) & 0x3F;
|
||||||
p->element.blue = rgb_table[*s_p & 0x1F];
|
p->element.blue = rgb_table[*s_p & 0x1F];
|
||||||
#else
|
#else
|
||||||
p->element.green = rgb_table[(*s_p & 0x7C0) >> 6];
|
p->element.green = rgb_table[(*s_p >> 6) & 0x1F];
|
||||||
p->element.blue = rgb_table[(*s_p >> 1) & 0x1F];
|
p->element.blue = rgb_table[(*s_p >> 1) & 0x1F];
|
||||||
#endif
|
#endif
|
||||||
++s_p;
|
++s_p;
|
||||||
}
|
|
||||||
d += pixel_size.width;
|
|
||||||
//s -= bytes_per_line;
|
|
||||||
rawbits -= bytes_per_line;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delete [] rgb_table;
|
d += pixel_size.width;
|
||||||
|
rawbits -= src_bytes_per_line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -343,7 +317,7 @@ namespace nana{ namespace paint
|
|||||||
const int depth = spec.screen_depth();
|
const int depth = spec.screen_depth();
|
||||||
|
|
||||||
XImage* img = ::XCreateImage(disp, spec.screen_visual(), depth, ZPixmap, 0, 0, pixel_size.width, pixel_size.height, (16 == depth ? 16 : 32), 0);
|
XImage* img = ::XCreateImage(disp, spec.screen_visual(), depth, ZPixmap, 0, 0, pixel_size.width, pixel_size.height, (16 == depth ? 16 : 32), 0);
|
||||||
if(sizeof(pixel_argb_t) * 8 == depth || 24 == depth)
|
if(sizeof(pixel_color_t) * 8 == depth || 24 == depth)
|
||||||
{
|
{
|
||||||
img->data = reinterpret_cast<char*>(raw_pixel_buffer);
|
img->data = reinterpret_cast<char*>(raw_pixel_buffer);
|
||||||
::XPutImage(disp, dw, gc,
|
::XPutImage(disp, dw, gc,
|
||||||
@ -397,9 +371,6 @@ namespace nana{ namespace paint
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
pixel_buffer::pixel_buffer()
|
|
||||||
{}
|
|
||||||
|
|
||||||
pixel_buffer::pixel_buffer(drawable_type drawable, const nana::rectangle& want_rectangle)
|
pixel_buffer::pixel_buffer(drawable_type drawable, const nana::rectangle& want_rectangle)
|
||||||
{
|
{
|
||||||
open(drawable, want_rectangle);
|
open(drawable, want_rectangle);
|
||||||
@ -445,15 +416,7 @@ namespace nana{ namespace paint
|
|||||||
}
|
}
|
||||||
|
|
||||||
BITMAPINFO bmpinfo;
|
BITMAPINFO bmpinfo;
|
||||||
bmpinfo.bmiHeader.biSize = sizeof(bmpinfo.bmiHeader);
|
assign_windows_bitmapinfo(sz, bmpinfo);
|
||||||
bmpinfo.bmiHeader.biWidth = sz.width;
|
|
||||||
bmpinfo.bmiHeader.biHeight = -static_cast<int>(sz.height);
|
|
||||||
bmpinfo.bmiHeader.biPlanes = 1;
|
|
||||||
bmpinfo.bmiHeader.biBitCount = 32;
|
|
||||||
bmpinfo.bmiHeader.biCompression = BI_RGB;
|
|
||||||
bmpinfo.bmiHeader.biSizeImage = static_cast<DWORD>(sz.width * sz.height * sizeof(pixel_argb_t));
|
|
||||||
bmpinfo.bmiHeader.biClrUsed = 0;
|
|
||||||
bmpinfo.bmiHeader.biClrImportant = 0;
|
|
||||||
|
|
||||||
std::size_t read_lines = ::GetDIBits(drawable->context, drawable->pixmap, 0, static_cast<UINT>(sz.height), sp->raw_pixel_buffer, &bmpinfo, DIB_RGB_COLORS);
|
std::size_t read_lines = ::GetDIBits(drawable->context, drawable->pixmap, 0, static_cast<UINT>(sz.height), sp->raw_pixel_buffer, &bmpinfo, DIB_RGB_COLORS);
|
||||||
|
|
||||||
@ -486,15 +449,7 @@ namespace nana{ namespace paint
|
|||||||
return false;
|
return false;
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
BITMAPINFO bmpinfo;
|
BITMAPINFO bmpinfo;
|
||||||
bmpinfo.bmiHeader.biSize = sizeof(bmpinfo.bmiHeader);
|
assign_windows_bitmapinfo({want_r.width, want_r.height}, bmpinfo);
|
||||||
bmpinfo.bmiHeader.biWidth = want_r.width;
|
|
||||||
bmpinfo.bmiHeader.biHeight = -static_cast<int>(want_r.height);
|
|
||||||
bmpinfo.bmiHeader.biPlanes = 1;
|
|
||||||
bmpinfo.bmiHeader.biBitCount = 32;
|
|
||||||
bmpinfo.bmiHeader.biCompression = BI_RGB;
|
|
||||||
bmpinfo.bmiHeader.biSizeImage = static_cast<DWORD>(want_r.width * want_r.height * sizeof(pixel_argb_t));
|
|
||||||
bmpinfo.bmiHeader.biClrUsed = 0;
|
|
||||||
bmpinfo.bmiHeader.biClrImportant = 0;
|
|
||||||
|
|
||||||
bool need_dup = (r.width != sz.width || r.height != sz.height);
|
bool need_dup = (r.width != sz.width || r.height != sz.height);
|
||||||
|
|
||||||
@ -627,7 +582,7 @@ namespace nana{ namespace paint
|
|||||||
{
|
{
|
||||||
auto sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(sp)
|
if(sp)
|
||||||
return sizeof(pixel_argb_t) * (static_cast<std::size_t>(sp->pixel_size.width) * static_cast<std::size_t>(sp->pixel_size.height));
|
return sizeof(pixel_color_t) * (static_cast<std::size_t>(sp->pixel_size.width) * static_cast<std::size_t>(sp->pixel_size.height));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,26 +596,26 @@ namespace nana{ namespace paint
|
|||||||
return (storage_ ? storage_->pixel_size : nana::size());
|
return (storage_ ? storage_->pixel_size : nana::size());
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_argb_t * pixel_buffer::at(const point& pos) const
|
pixel_color_t * pixel_buffer::at(const point& pos) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if (sp && (pos.y < static_cast<int>(sp->pixel_size.height) + sp->valid_r.y))
|
if (sp && (pos.y < static_cast<int>(sp->pixel_size.height) + sp->valid_r.y))
|
||||||
return reinterpret_cast<pixel_argb_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer) + sp->bytes_per_line * (pos.y - sp->valid_r.y)) + (pos.x - sp->valid_r.x);
|
return reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer) + sp->bytes_per_line * (pos.y - sp->valid_r.y)) + (pos.x - sp->valid_r.x);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_argb_t * pixel_buffer::raw_ptr(std::size_t row) const
|
pixel_color_t * pixel_buffer::raw_ptr(std::size_t row) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(sp && (row < sp->pixel_size.height))
|
if(sp && (row < sp->pixel_size.height))
|
||||||
return reinterpret_cast<pixel_argb_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer) + sp->bytes_per_line * row);
|
return reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer) + sp->bytes_per_line * row);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_argb_t * pixel_buffer::operator[](std::size_t row) const
|
pixel_color_t * pixel_buffer::operator[](std::size_t row) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
return reinterpret_cast<pixel_argb_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer) + sp->bytes_per_line * row);
|
return reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer) + sp->bytes_per_line * row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixel_buffer::put(const unsigned char* rawbits, std::size_t width, std::size_t height, std::size_t bits_per_pixel, std::size_t bytes_per_line, bool is_negative)
|
void pixel_buffer::put(const unsigned char* rawbits, std::size_t width, std::size_t height, std::size_t bits_per_pixel, std::size_t bytes_per_line, bool is_negative)
|
||||||
@ -669,20 +624,20 @@ namespace nana{ namespace paint
|
|||||||
storage_->assign(rawbits, width, height, bits_per_pixel, bytes_per_line, is_negative);
|
storage_->assign(rawbits, width, height, bits_per_pixel, bytes_per_line, is_negative);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_argb_t pixel_buffer::pixel(int x, int y) const
|
pixel_color_t pixel_buffer::pixel(int x, int y) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(sp && 0 <= x && x < static_cast<int>(sp->pixel_size.width) && 0 <= y && y < static_cast<int>(sp->pixel_size.height))
|
if(sp && 0 <= x && x < static_cast<int>(sp->pixel_size.width) && 0 <= y && y < static_cast<int>(sp->pixel_size.height))
|
||||||
return *reinterpret_cast<const pixel_argb_t*>(reinterpret_cast<const char*>(sp->raw_pixel_buffer + x) + y * sp->bytes_per_line);
|
return *reinterpret_cast<const pixel_color_t*>(reinterpret_cast<const char*>(sp->raw_pixel_buffer + x) + y * sp->bytes_per_line);
|
||||||
|
|
||||||
return pixel_argb_t();
|
return pixel_color_t();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixel_buffer::pixel(int x, int y, pixel_argb_t px)
|
void pixel_buffer::pixel(int x, int y, pixel_color_t px)
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(sp && 0 <= x && x < static_cast<int>(sp->pixel_size.width) && 0 <= y && y < static_cast<int>(sp->pixel_size.height))
|
if(sp && 0 <= x && x < static_cast<int>(sp->pixel_size.width) && 0 <= y && y < static_cast<int>(sp->pixel_size.height))
|
||||||
*reinterpret_cast<pixel_argb_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer + x) + y * sp->bytes_per_line) = px;
|
*reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer + x) + y * sp->bytes_per_line) = px;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixel_buffer::paste(drawable_type drawable, int x, int y) const
|
void pixel_buffer::paste(drawable_type drawable, int x, int y) const
|
||||||
@ -693,7 +648,7 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
void pixel_buffer::paste(const nana::rectangle& src_r, drawable_type drawable, int x, int y) const
|
void pixel_buffer::paste(const nana::rectangle& src_r, drawable_type drawable, int x, int y) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(drawable && sp)
|
if(drawable && sp)
|
||||||
{
|
{
|
||||||
if(sp->alpha_channel)
|
if(sp->alpha_channel)
|
||||||
@ -709,15 +664,7 @@ namespace nana{ namespace paint
|
|||||||
}
|
}
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
BITMAPINFO bi;
|
BITMAPINFO bi;
|
||||||
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
|
assign_windows_bitmapinfo(sp->pixel_size, bi);
|
||||||
bi.bmiHeader.biWidth = sp->pixel_size.width;
|
|
||||||
bi.bmiHeader.biHeight = -static_cast<int>(sp->pixel_size.height);
|
|
||||||
bi.bmiHeader.biPlanes = 1;
|
|
||||||
bi.bmiHeader.biBitCount = sizeof(pixel_argb_t) * 8;
|
|
||||||
bi.bmiHeader.biCompression = BI_RGB;
|
|
||||||
bi.bmiHeader.biSizeImage = static_cast<DWORD>(sizeof(pixel_argb_t) * sp->pixel_size.width * sp->pixel_size.height);
|
|
||||||
bi.bmiHeader.biClrUsed = 0;
|
|
||||||
bi.bmiHeader.biClrImportant = 0;
|
|
||||||
|
|
||||||
::SetDIBitsToDevice(drawable->context,
|
::SetDIBitsToDevice(drawable->context,
|
||||||
x, y, src_r.width, src_r.height,
|
x, y, src_r.width, src_r.height,
|
||||||
@ -731,22 +678,14 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
void pixel_buffer::paste(native_window_type wd, int x, int y) const
|
void pixel_buffer::paste(native_window_type wd, int x, int y) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(nullptr == wd || nullptr == sp) return;
|
if(nullptr == wd || nullptr == sp) return;
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
HDC handle = ::GetDC(reinterpret_cast<HWND>(wd));
|
HDC handle = ::GetDC(reinterpret_cast<HWND>(wd));
|
||||||
if(handle)
|
if(handle)
|
||||||
{
|
{
|
||||||
BITMAPINFO bi;
|
BITMAPINFO bi;
|
||||||
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
|
assign_windows_bitmapinfo(sp->pixel_size, bi);
|
||||||
bi.bmiHeader.biWidth = sp->pixel_size.width;
|
|
||||||
bi.bmiHeader.biHeight = -static_cast<int>(sp->pixel_size.height);
|
|
||||||
bi.bmiHeader.biPlanes = 1;
|
|
||||||
bi.bmiHeader.biBitCount = sizeof(pixel_argb_t) * 8;
|
|
||||||
bi.bmiHeader.biCompression = BI_RGB;
|
|
||||||
bi.bmiHeader.biSizeImage = static_cast<DWORD>(sizeof(pixel_argb_t) * sp->pixel_size.width * sp->pixel_size.height);
|
|
||||||
bi.bmiHeader.biClrUsed = 0;
|
|
||||||
bi.bmiHeader.biClrImportant = 0;
|
|
||||||
|
|
||||||
::SetDIBitsToDevice(handle,
|
::SetDIBitsToDevice(handle,
|
||||||
x, y, sp->pixel_size.width, sp->pixel_size.height,
|
x, y, sp->pixel_size.width, sp->pixel_size.height,
|
||||||
@ -760,25 +699,24 @@ namespace nana{ namespace paint
|
|||||||
Display * disp = spec.open_display();
|
Display * disp = spec.open_display();
|
||||||
sp->put(reinterpret_cast<Window>(wd), XDefaultGC(disp, XDefaultScreen(disp)), 0, 0, x, y, sp->pixel_size.width, sp->pixel_size.height);
|
sp->put(reinterpret_cast<Window>(wd), XDefaultGC(disp, XDefaultScreen(disp)), 0, 0, x, y, sp->pixel_size.width, sp->pixel_size.height);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixel_buffer::line(const std::string& name)
|
void pixel_buffer::line(const std::string& name)
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
if (storage_ && name.size())
|
||||||
if(sp && name.size())
|
|
||||||
{
|
{
|
||||||
sp->img_pro.line_receptacle = detail::image_process_provider::instance().ref_line(name);
|
auto & img_pro = storage_->img_pro;
|
||||||
if(sp->img_pro.line_receptacle == *detail::image_process_provider::instance().line())
|
img_pro.line_receptacle = detail::image_process_provider::instance().ref_line(name);
|
||||||
sp->img_pro.line = detail::image_process_provider::instance().line();
|
if(img_pro.line_receptacle == *detail::image_process_provider::instance().line())
|
||||||
|
img_pro.line = detail::image_process_provider::instance().line();
|
||||||
else
|
else
|
||||||
sp->img_pro.line = & sp->img_pro.line_receptacle;
|
img_pro.line = &img_pro.line_receptacle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixel_buffer::line(const point &pos_beg, const point &pos_end, const ::nana::expr_color& clr, double fade_rate)
|
void pixel_buffer::line(const point &pos_beg, const point &pos_end, const ::nana::expr_color& clr, double fade_rate)
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(nullptr == sp) return;
|
if(nullptr == sp) return;
|
||||||
|
|
||||||
//Test if the line intersects the rectangle, and retrive the two points that
|
//Test if the line intersects the rectangle, and retrive the two points that
|
||||||
@ -790,7 +728,7 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
void pixel_buffer::rectangle(const nana::rectangle &r, const ::nana::expr_color& clr, double fade_rate, bool solid)
|
void pixel_buffer::rectangle(const nana::rectangle &r, const ::nana::expr_color& clr, double fade_rate, bool solid)
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if((nullptr == sp) || (fade_rate == 1.0)) return;
|
if((nullptr == sp) || (fade_rate == 1.0)) return;
|
||||||
|
|
||||||
bool fade = (fade_rate != 0.0);
|
bool fade = (fade_rate != 0.0);
|
||||||
@ -798,7 +736,7 @@ namespace nana{ namespace paint
|
|||||||
std::unique_ptr<unsigned char[]> autoptr;
|
std::unique_ptr<unsigned char[]> autoptr;
|
||||||
|
|
||||||
auto rgb_color = clr.px_color().value;
|
auto rgb_color = clr.px_color().value;
|
||||||
nana::pixel_argb_t rgb_imd;
|
nana::pixel_color_t rgb_imd;
|
||||||
if(fade)
|
if(fade)
|
||||||
{
|
{
|
||||||
autoptr = detail::alloc_fade_table(1 - fade_rate);
|
autoptr = detail::alloc_fade_table(1 - fade_rate);
|
||||||
@ -809,12 +747,12 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
int xbeg = (0 <= r.x ? r.x : 0);
|
int xbeg = (0 <= r.x ? r.x : 0);
|
||||||
int xend = static_cast<int>(r.x + r.width < sp->pixel_size.width ? r.x + r.width : sp->pixel_size.width);
|
int xend = static_cast<int>(r.x + r.width < sp->pixel_size.width ? r.x + r.width : sp->pixel_size.width);
|
||||||
int ybeg = (0 <= r.y ? r.y : 0);
|
const int ybeg = (0 <= r.y ? r.y : 0);
|
||||||
int yend = static_cast<int>(r.y + r.height < sp->pixel_size.height ? r.y + r.height : sp->pixel_size.height);
|
int yend = static_cast<int>(r.y + r.height < sp->pixel_size.height ? r.y + r.height : sp->pixel_size.height);
|
||||||
|
|
||||||
|
const auto p_rgb = sp->raw_pixel_buffer + ybeg * sp->pixel_size.width;
|
||||||
if (solid)
|
if (solid)
|
||||||
{
|
{
|
||||||
auto p_rgb = sp->raw_pixel_buffer + ybeg * sp->pixel_size.width;
|
|
||||||
auto lineptr = p_rgb + xbeg;
|
auto lineptr = p_rgb + xbeg;
|
||||||
auto end = p_rgb + xend;
|
auto end = p_rgb + xend;
|
||||||
if (fade)
|
if (fade)
|
||||||
@ -845,7 +783,6 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
if((ybeg == r.y) && (r.y + static_cast<int>(r.height) == yend))
|
if((ybeg == r.y) && (r.y + static_cast<int>(r.height) == yend))
|
||||||
{
|
{
|
||||||
auto p_rgb = sp->raw_pixel_buffer + ybeg * sp->pixel_size.width;
|
|
||||||
auto i = p_rgb + xbeg;
|
auto i = p_rgb + xbeg;
|
||||||
auto end = p_rgb + xend;
|
auto end = p_rgb + xend;
|
||||||
auto i_other = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + xbeg;
|
auto i_other = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + xbeg;
|
||||||
@ -870,7 +807,6 @@ namespace nana{ namespace paint
|
|||||||
{
|
{
|
||||||
if(ybeg == r.y)
|
if(ybeg == r.y)
|
||||||
{
|
{
|
||||||
auto p_rgb = sp->raw_pixel_buffer + ybeg * sp->pixel_size.width;
|
|
||||||
auto i = p_rgb;
|
auto i = p_rgb;
|
||||||
auto end = p_rgb + xend;
|
auto end = p_rgb + xend;
|
||||||
if(fade)
|
if(fade)
|
||||||
@ -906,7 +842,6 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
if((xbeg == r.x) && (r.x + static_cast<int>(r.width) == xend))
|
if((xbeg == r.x) && (r.x + static_cast<int>(r.width) == xend))
|
||||||
{
|
{
|
||||||
auto p_rgb = sp->raw_pixel_buffer + ybeg * sp->pixel_size.width;
|
|
||||||
auto i = p_rgb + xbeg;
|
auto i = p_rgb + xbeg;
|
||||||
auto end = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + xbeg;
|
auto end = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + xbeg;
|
||||||
auto i_other = p_rgb + (xend - 1);
|
auto i_other = p_rgb + (xend - 1);
|
||||||
@ -942,7 +877,6 @@ namespace nana{ namespace paint
|
|||||||
{
|
{
|
||||||
if(xbeg == r.x)
|
if(xbeg == r.x)
|
||||||
{
|
{
|
||||||
auto p_rgb = sp->raw_pixel_buffer + ybeg * sp->pixel_size.width;
|
|
||||||
auto i = p_rgb + xbeg;
|
auto i = p_rgb + xbeg;
|
||||||
auto end = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + xbeg;
|
auto end = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + xbeg;
|
||||||
if(fade)
|
if(fade)
|
||||||
@ -969,7 +903,6 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
if(r.x + static_cast<int>(r.width) == xend)
|
if(r.x + static_cast<int>(r.width) == xend)
|
||||||
{
|
{
|
||||||
auto p_rgb = sp->raw_pixel_buffer + ybeg * sp->pixel_size.width;
|
|
||||||
auto i = p_rgb + (xend - 1);
|
auto i = p_rgb + (xend - 1);
|
||||||
auto end = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + (xend - 1);
|
auto end = sp->raw_pixel_buffer + (yend - 1) * sp->pixel_size.width + (xend - 1);
|
||||||
if(fade)
|
if(fade)
|
||||||
@ -996,7 +929,7 @@ namespace nana{ namespace paint
|
|||||||
|
|
||||||
void pixel_buffer::gradual_rectangle(const ::nana::rectangle& draw_rct, const ::nana::expr_color& from, const ::nana::expr_color& to, double fade_rate, bool vertical)
|
void pixel_buffer::gradual_rectangle(const ::nana::rectangle& draw_rct, const ::nana::expr_color& from, const ::nana::expr_color& to, double fade_rate, bool vertical)
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if (nullptr == sp) return;
|
if (nullptr == sp) return;
|
||||||
|
|
||||||
nana::rectangle rct;
|
nana::rectangle rct;
|
||||||
@ -1006,8 +939,8 @@ namespace nana{ namespace paint
|
|||||||
int deltapx = int(vertical ? rct.height : rct.width);
|
int deltapx = int(vertical ? rct.height : rct.width);
|
||||||
if (sp && deltapx)
|
if (sp && deltapx)
|
||||||
{
|
{
|
||||||
auto beg = from.argb().value;
|
auto beg = from.px_color().value;
|
||||||
auto end = to.argb().value;
|
auto end = to.px_color().value;
|
||||||
unsigned r, g, b;
|
unsigned r, g, b;
|
||||||
const int delta_r = (int(end & 0xFF0000) - int(r = (beg & 0xFF0000))) / deltapx;
|
const int delta_r = (int(end & 0xFF0000) - int(r = (beg & 0xFF0000))) / deltapx;
|
||||||
const int delta_g = (int((end & 0xFF00) << 8) - int(g = ((beg & 0xFF00) << 8))) / deltapx;
|
const int delta_g = (int((end & 0xFF00) << 8) - int(g = ((beg & 0xFF00) << 8))) / deltapx;
|
||||||
@ -1016,46 +949,40 @@ namespace nana{ namespace paint
|
|||||||
auto pxbuf = sp->raw_pixel_buffer + rct.x + rct.y * sp->pixel_size.width;
|
auto pxbuf = sp->raw_pixel_buffer + rct.x + rct.y * sp->pixel_size.width;
|
||||||
if (vertical)
|
if (vertical)
|
||||||
{
|
{
|
||||||
if (deltapx + rct.y > 0)
|
unsigned align_4 = (rct.width & ~3);
|
||||||
|
unsigned align_reset = rct.width & 3;
|
||||||
|
while (deltapx--)
|
||||||
{
|
{
|
||||||
unsigned align_4 = (rct.width & ~3);
|
nana::pixel_color_t px;
|
||||||
unsigned align_reset = rct.width & 3;
|
px.value = ((r += delta_r) & 0xFF0000) | (((g += delta_g) & 0xFF0000) >> 8) | (((b += delta_b) & 0xFF0000) >> 16);
|
||||||
while (deltapx--)
|
|
||||||
|
auto dpx = pxbuf;
|
||||||
|
for (auto dpx_end = pxbuf + align_4; dpx != dpx_end; dpx += 4)
|
||||||
{
|
{
|
||||||
nana::pixel_argb_t px;
|
*dpx = px;
|
||||||
|
dpx[1] = px;
|
||||||
px.value = ((r += delta_r) & 0xFF0000) | (((g += delta_g) & 0xFF0000) >> 8) | (((b += delta_b) & 0xFF0000) >> 16);
|
dpx[2] = px;
|
||||||
|
dpx[3] = px;
|
||||||
auto dpx = pxbuf;
|
|
||||||
for (auto dpx_end = pxbuf + align_4; dpx != dpx_end; dpx += 4)
|
|
||||||
{
|
|
||||||
*dpx = px;
|
|
||||||
dpx[1] = px;
|
|
||||||
dpx[2] = px;
|
|
||||||
dpx[3] = px;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto dpx_end = dpx + align_reset; dpx != dpx_end; ++dpx)
|
|
||||||
*dpx = px;
|
|
||||||
|
|
||||||
pxbuf += sp->pixel_size.width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto dpx_end = dpx + align_reset; dpx != dpx_end; ++dpx)
|
||||||
|
*dpx = px;
|
||||||
|
|
||||||
|
pxbuf += sp->pixel_size.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (deltapx + rct.x > 0)
|
auto pxbuf_end = pxbuf + rct.width;
|
||||||
{
|
|
||||||
auto pxbuf_end = pxbuf + rct.width;
|
|
||||||
|
|
||||||
for (; pxbuf != pxbuf_end; ++pxbuf)
|
auto dpx_end = pxbuf + rct.height * sp->pixel_size.width;
|
||||||
{
|
for (; pxbuf != pxbuf_end; ++pxbuf)
|
||||||
nana::pixel_argb_t px;
|
{
|
||||||
px.value = ((r += delta_r) & 0xFF0000) | (((g += delta_g) & 0xFF0000) >> 8) | (((b += delta_b) & 0xFF0000) >> 16);
|
nana::pixel_color_t px;
|
||||||
auto dpx_end = pxbuf + rct.height * sp->pixel_size.width;
|
px.value = ((r += delta_r) & 0xFF0000) | (((g += delta_g) & 0xFF0000) >> 8) | (((b += delta_b) & 0xFF0000) >> 16);
|
||||||
for (auto dpx = pxbuf; dpx != dpx_end; dpx += sp->pixel_size.width)
|
for (auto dpx = pxbuf; dpx != dpx_end; dpx += sp->pixel_size.width)
|
||||||
*dpx = px;
|
*dpx = px;
|
||||||
}
|
++dpx_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1064,21 +991,21 @@ namespace nana{ namespace paint
|
|||||||
//stretch
|
//stretch
|
||||||
void pixel_buffer::stretch(const std::string& name)
|
void pixel_buffer::stretch(const std::string& name)
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
if (storage_ && name.size())
|
||||||
if(sp && name.size())
|
|
||||||
{
|
{
|
||||||
|
auto& img_pro = storage_->img_pro;
|
||||||
auto op_default = detail::image_process_provider::instance().stretch();
|
auto op_default = detail::image_process_provider::instance().stretch();
|
||||||
sp->img_pro.stretch_receptacle = detail::image_process_provider::instance().ref_stretch(name);
|
img_pro.stretch_receptacle = detail::image_process_provider::instance().ref_stretch(name);
|
||||||
if(sp->img_pro.stretch_receptacle == *op_default)
|
if(img_pro.stretch_receptacle == *op_default)
|
||||||
sp->img_pro.stretch = op_default;
|
img_pro.stretch = op_default;
|
||||||
else
|
else
|
||||||
sp->img_pro.stretch = & sp->img_pro.stretch_receptacle;
|
img_pro.stretch = &img_pro.stretch_receptacle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixel_buffer::stretch(const nana::rectangle& src_r, drawable_type drawable, const nana::rectangle& r) const
|
void pixel_buffer::stretch(const nana::rectangle& src_r, drawable_type drawable, const nana::rectangle& r) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(nullptr == sp) return;
|
if(nullptr == sp) return;
|
||||||
|
|
||||||
nana::rectangle good_src_r, good_dst_r;
|
nana::rectangle good_src_r, good_dst_r;
|
||||||
@ -1093,21 +1020,21 @@ namespace nana{ namespace paint
|
|||||||
//blend
|
//blend
|
||||||
void pixel_buffer::blend(const std::string& name)
|
void pixel_buffer::blend(const std::string& name)
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
if (storage_ && name.size())
|
||||||
if(sp && name.size())
|
|
||||||
{
|
{
|
||||||
|
auto& img_pro = storage_->img_pro;
|
||||||
auto op_default = detail::image_process_provider::instance().blend();
|
auto op_default = detail::image_process_provider::instance().blend();
|
||||||
sp->img_pro.blend_receptacle = detail::image_process_provider::instance().ref_blend(name);
|
img_pro.blend_receptacle = detail::image_process_provider::instance().ref_blend(name);
|
||||||
if(sp->img_pro.blend_receptacle == *op_default)
|
if(img_pro.blend_receptacle == *op_default)
|
||||||
sp->img_pro.blend = op_default;
|
img_pro.blend = op_default;
|
||||||
else
|
else
|
||||||
sp->img_pro.blend = & sp->img_pro.blend_receptacle;
|
img_pro.blend = &img_pro.blend_receptacle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pixel_buffer::blend(const nana::rectangle& s_r, drawable_type dw_dst, const nana::point& d_pos, double fade_rate) const
|
void pixel_buffer::blend(const nana::rectangle& s_r, drawable_type dw_dst, const nana::point& d_pos, double fade_rate) const
|
||||||
{
|
{
|
||||||
pixel_buffer_storage * sp = storage_.get();
|
auto sp = storage_.get();
|
||||||
if(nullptr == sp) return;
|
if(nullptr == sp) return;
|
||||||
|
|
||||||
nana::rectangle s_good_r, d_good_r;
|
nana::rectangle s_good_r, d_good_r;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user