Refined code
refined code and implemented select all(ctrl+a) for text_editor
This commit is contained in:
@@ -38,7 +38,7 @@ namespace nana
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -69,8 +69,10 @@ namespace nana
|
||||
class controller
|
||||
{
|
||||
public:
|
||||
enum dir_t{DirHorizontal, DirVertical};
|
||||
enum where_t{WhereNone, WhereBar, WhereSlider};
|
||||
enum class style{horizontal, vertical};
|
||||
enum class parts{none, bar, slider};
|
||||
//enum dir_t{DirHorizontal, DirVertical}; //deprecated
|
||||
//enum where_t{WhereNone, WhereBar, WhereSlider};
|
||||
|
||||
typedef drawer_trigger::graph_reference graph_reference;
|
||||
|
||||
@@ -83,7 +85,7 @@ namespace nana
|
||||
proto_.renderer = pat::cloneable<renderer>(interior_renderer());
|
||||
|
||||
attr_.skdir = seekdir::bilateral;
|
||||
attr_.dir = this->DirHorizontal;
|
||||
attr_.dir = style::horizontal;
|
||||
attr_.vcur = 0;
|
||||
attr_.vmax = 10;
|
||||
attr_.slider_scale = 8;
|
||||
@@ -142,7 +144,7 @@ namespace nana
|
||||
|
||||
void vertical(bool v)
|
||||
{
|
||||
dir_t dir = (v ? this->DirVertical : this->DirHorizontal);
|
||||
auto dir = (v ? style::vertical : style::horizontal);
|
||||
|
||||
if(dir != attr_.dir)
|
||||
{
|
||||
@@ -153,7 +155,7 @@ namespace nana
|
||||
|
||||
bool vertical() const
|
||||
{
|
||||
return (this->DirVertical == attr_.dir);
|
||||
return (style::vertical == attr_.dir);
|
||||
}
|
||||
|
||||
void vmax(unsigned m)
|
||||
@@ -203,56 +205,56 @@ namespace nana
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
int pos = _m_slider_pos();
|
||||
if(pos <= x && x < pos + static_cast<int>(attr_.slider_scale))
|
||||
return WhereSlider;
|
||||
int sdpos = _m_slider_pos();
|
||||
if (sdpos <= pos.x && pos.x < sdpos + static_cast<int>(attr_.slider_scale))
|
||||
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))
|
||||
return WhereBar;
|
||||
if(pos.y < r.y + static_cast<int>(r.height))
|
||||
return parts::bar;
|
||||
}
|
||||
return WhereNone;
|
||||
return parts::none;
|
||||
}
|
||||
|
||||
//set_slider_pos
|
||||
//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)
|
||||
std::swap(x, y);
|
||||
if(style::vertical == attr_.dir)
|
||||
std::swap(pos.x, pos.y);
|
||||
|
||||
x -= _m_slider_refpos();
|
||||
if(x < 0)
|
||||
pos.x -= _m_slider_refpos();
|
||||
if(pos.x < 0)
|
||||
return false;
|
||||
|
||||
if(x > static_cast<int>(_m_scale()))
|
||||
x = static_cast<int>(_m_scale());
|
||||
if(pos.x > static_cast<int>(_m_scale()))
|
||||
pos.x = static_cast<int>(_m_scale());
|
||||
|
||||
double pos = attr_.pos;
|
||||
double dx = _m_evaluate_by_seekdir(x);
|
||||
double attr_pos = attr_.pos;
|
||||
double dx = _m_evaluate_by_seekdir(pos.x);
|
||||
|
||||
attr_.pos = dx;
|
||||
attr_.adorn_pos = dx;
|
||||
_m_mk_slider_value_by_pos();
|
||||
|
||||
return (attr_.pos != pos);
|
||||
return (attr_.pos != attr_pos);
|
||||
}
|
||||
|
||||
void set_slider_refpos(::nana::point pos)
|
||||
{
|
||||
if(this->DirVertical == attr_.dir)
|
||||
if(style::vertical == attr_.dir)
|
||||
std::swap(pos.x, pos.y);
|
||||
|
||||
slider_state_.trace = slider_state_.TraceCapture;
|
||||
@@ -286,21 +288,21 @@ namespace nana
|
||||
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 pos = slider_state_.snap_pos + (mpos - slider_state_.refpos.x);
|
||||
int mpos = (style::horizontal == attr_.dir ? pos.x : pos.y);
|
||||
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());
|
||||
if(pos > scale)
|
||||
pos = scale;
|
||||
if (adorn_pos > scale)
|
||||
adorn_pos = scale;
|
||||
}
|
||||
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;
|
||||
|
||||
if(dstpos != attr_.pos)
|
||||
@@ -312,15 +314,15 @@ namespace nana
|
||||
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();
|
||||
if(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);
|
||||
|
||||
attr_.adorn_pos = xpos;
|
||||
@@ -329,7 +331,7 @@ namespace nana
|
||||
if(slider_state_.trace == slider_state_.TraceNone)
|
||||
slider_state_.trace = slider_state_.TraceOver;
|
||||
|
||||
return (pos != static_cast<int>(xpos));
|
||||
return (adorn_pos != static_cast<int>(xpos));
|
||||
}
|
||||
|
||||
unsigned move_step(bool forward)
|
||||
@@ -385,7 +387,7 @@ namespace nana
|
||||
{
|
||||
auto sz = other_.graph->size();
|
||||
nana::rectangle r = sz;
|
||||
if(this->DirHorizontal == attr_.dir)
|
||||
if(style::horizontal == attr_.dir)
|
||||
{
|
||||
r.x = attr_.slider_scale / 2 - attr_.border;
|
||||
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
|
||||
{
|
||||
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
|
||||
@@ -465,7 +467,7 @@ namespace nana
|
||||
{
|
||||
renderer::bar_t bar;
|
||||
|
||||
bar.horizontal = (this->DirHorizontal == attr_.dir);
|
||||
bar.horizontal = (style::horizontal == attr_.dir);
|
||||
bar.border_size = attr_.border;
|
||||
bar.r = _m_bar_area();
|
||||
|
||||
@@ -494,35 +496,23 @@ namespace nana
|
||||
nana::string str = proto_.provider->adorn_trace(attr_.vmax, vadorn);
|
||||
if(str.size())
|
||||
{
|
||||
nana::rectangle r;
|
||||
nana::size ts = other_.graph->text_extent_size(str);
|
||||
ts.width += 6;
|
||||
ts.height += 2;
|
||||
|
||||
r.width = ts.width;
|
||||
r.height = ts.height;
|
||||
|
||||
int x, y;
|
||||
const int room = static_cast<int>(attr_.adorn_pos);
|
||||
if(bar.horizontal)
|
||||
{
|
||||
r.y = adorn.fixedpos + static_cast<int>(adorn.block - ts.height) / 2;
|
||||
if(room > static_cast<int>(ts.width + 2))
|
||||
r.x = room - static_cast<int>(ts.width + 2);
|
||||
else
|
||||
r.x = room + 2;
|
||||
|
||||
r.x += this->_m_slider_refpos();
|
||||
y = adorn.fixedpos + static_cast<int>(adorn.block - ts.height) / 2;
|
||||
x = (room > static_cast<int>(ts.width + 2) ? room - static_cast<int>(ts.width + 2) : room + 2) + _m_slider_refpos();
|
||||
}
|
||||
else
|
||||
{
|
||||
r.x = (other_.graph->width() - ts.width) / 2;
|
||||
if(room > static_cast<int>(ts.height + 2))
|
||||
r.y = room - static_cast<int>(ts.height + 2);
|
||||
else
|
||||
r.y = room + 2;
|
||||
r.y += this->_m_slider_refpos();
|
||||
x = (other_.graph->width() - ts.width) / 2;
|
||||
y = (room > static_cast<int>(ts.height + 2) ? room - static_cast<int>(ts.height + 2) : room + 2) + _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;
|
||||
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.border = attr_.border;
|
||||
proto_.renderer->slider(other_.wd, *other_.graph, s);
|
||||
@@ -553,7 +543,7 @@ namespace nana
|
||||
struct attr_tag
|
||||
{
|
||||
seekdir skdir;
|
||||
dir_t dir;
|
||||
style dir;
|
||||
unsigned border;
|
||||
unsigned vmax;
|
||||
unsigned vcur;
|
||||
@@ -607,10 +597,11 @@ namespace nana
|
||||
|
||||
void trigger::mouse_down(graph_reference, const arg_mouse& arg)
|
||||
{
|
||||
controller_t::where_t what = impl_->seek_where(arg.pos.x, arg.pos.y);
|
||||
if(controller_t::WhereBar == what || controller_t::WhereSlider == what)
|
||||
using parts = controller_t::parts;
|
||||
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);
|
||||
if(mkdir)
|
||||
{
|
||||
@@ -635,13 +626,13 @@ namespace nana
|
||||
bool mkdraw = false;
|
||||
if(impl_->if_trace_slider())
|
||||
{
|
||||
mkdraw = impl_->move_slider(arg.pos.x, arg.pos.y);
|
||||
mkdraw = impl_->move_slider(arg.pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
controller_t::where_t what = impl_->seek_where(arg.pos.x, arg.pos.y);
|
||||
if(controller_t::WhereNone != what)
|
||||
mkdraw = impl_->move_adorn(arg.pos.x, arg.pos.y);
|
||||
auto what = impl_->seek_where(arg.pos);
|
||||
if(controller_t::parts::none != what)
|
||||
mkdraw = impl_->move_adorn(arg.pos);
|
||||
else
|
||||
mkdraw = impl_->reset_adorn();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user