Merge remote-tracking branch 'cnjinhao/hotfix-1.5.5' into hotfix-1.5.4
This commit is contained in:
commit
e5fe759c7d
@ -14,7 +14,7 @@ NANAINC = $(NANAPATH)/include
|
||||
NANALIB = $(NANAPATH)/build/bin
|
||||
|
||||
INCS = -I$(NANAINC)
|
||||
LIBS = -L$(NANALIB) -lnana -lX11 -lpthread -lrt -lXft -lpng -lasound
|
||||
LIBS = -L$(NANALIB) -lnana -lX11 -lpthread -lrt -lXft -lpng -lasound -lfontconfig
|
||||
|
||||
LINKOBJ = $(SOURCES:.cpp=.o)
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace nana
|
||||
/// Construct that creates a message box with a specified title and default button.
|
||||
msgbox(const ::std::string&);
|
||||
|
||||
/// Construct that creates a message box with an owner windoow, a specified title and buttons.
|
||||
/// Construct that creates a message box with an owner windoow, a specified title and buttons.
|
||||
msgbox(window, const ::std::string&, button_t = ok);
|
||||
|
||||
/// Sets an icon for informing user.
|
||||
@ -108,6 +108,7 @@ namespace nana
|
||||
virtual window create(window, unsigned label_px) = 0;
|
||||
virtual unsigned fixed_pixels() const;
|
||||
};
|
||||
|
||||
public:
|
||||
class boolean
|
||||
: public abstract_content
|
||||
@ -240,7 +241,6 @@ namespace nana
|
||||
{
|
||||
std::vector<abstract_content*> contents;
|
||||
_m_fetch_args(contents, std::forward<Args>(args)...);
|
||||
|
||||
if (contents.empty())
|
||||
return false;
|
||||
|
||||
@ -261,6 +261,14 @@ namespace nana
|
||||
|
||||
/// Sets a verifier to verify the user input.
|
||||
void verify(std::function<bool(window)> verifier);
|
||||
|
||||
/** Sets the minimum width for the entry fields
|
||||
@param[in] pixels new minimum width
|
||||
|
||||
If not called, the default is 100 pixels
|
||||
*/
|
||||
void min_width_entry_field( unsigned pixels );
|
||||
|
||||
private:
|
||||
void _m_fetch_args(std::vector<abstract_content*>&);
|
||||
|
||||
@ -279,6 +287,7 @@ namespace nana
|
||||
std::function<bool(window)> verifier_;
|
||||
::nana::paint::image images_[4];
|
||||
::nana::rectangle valid_areas_[4];
|
||||
unsigned min_width_entry_field_pixels_;
|
||||
};
|
||||
}//end namespace nana
|
||||
#include <nana/pop_ignore_diagnostic>
|
||||
|
@ -57,8 +57,6 @@ namespace nana
|
||||
class trigger
|
||||
: public drawer_trigger
|
||||
{
|
||||
class itembase;
|
||||
|
||||
struct essence;
|
||||
public:
|
||||
trigger();
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* A Progress Indicator Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -20,42 +20,37 @@ namespace nana
|
||||
{
|
||||
namespace progress
|
||||
{
|
||||
class trigger: public drawer_trigger
|
||||
struct scheme
|
||||
: public widget_geometrics
|
||||
{
|
||||
scheme();
|
||||
|
||||
color_proxy gradient_bgcolor{ colors::button_face_shadow_start };
|
||||
color_proxy gradient_fgcolor{ static_cast<color_rgb>(0x6FFFA8) };
|
||||
};
|
||||
|
||||
class substance;
|
||||
|
||||
class trigger
|
||||
: public drawer_trigger
|
||||
{
|
||||
public:
|
||||
unsigned value() const;
|
||||
unsigned value(unsigned);
|
||||
unsigned inc();
|
||||
unsigned Max() const;
|
||||
unsigned Max(unsigned);
|
||||
void unknown(bool);
|
||||
bool unknown() const;
|
||||
bool stop(bool s = true);
|
||||
bool stopped() const;
|
||||
private:
|
||||
void attached(widget_reference, graph_reference) override;
|
||||
void refresh(graph_reference) override;
|
||||
private:
|
||||
void _m_draw_box(graph_reference);
|
||||
void _m_draw_progress(graph_reference);
|
||||
bool _m_check_changing(unsigned) const;
|
||||
private:
|
||||
static const unsigned border = 2;
|
||||
trigger();
|
||||
~trigger();
|
||||
|
||||
widget * widget_{nullptr};
|
||||
nana::paint::graphics* graph_{nullptr};
|
||||
unsigned draw_width_{static_cast<unsigned>(-1)};
|
||||
bool unknown_{false};
|
||||
bool stop_{false};
|
||||
unsigned max_{100};
|
||||
unsigned value_{0};
|
||||
}; //end class drawer
|
||||
substance* progress() const;
|
||||
private:
|
||||
void attached(widget_reference, graph_reference) override;
|
||||
void refresh(graph_reference) override;
|
||||
private:
|
||||
substance* const progress_;
|
||||
};
|
||||
}
|
||||
}//end namespace drawerbase
|
||||
/// \brief A progressbar widget with two styles: know, and unknow amount value (goal).
|
||||
/// In unknow style the amount is ignored and the bar is scrolled when value change.
|
||||
class progress
|
||||
: public widget_object<category::widget_tag, drawerbase::progress::trigger>
|
||||
class progress
|
||||
: public widget_object<category::widget_tag, drawerbase::progress::trigger, ::nana::general_events, drawerbase::progress::scheme>
|
||||
{
|
||||
public:
|
||||
progress();
|
||||
@ -69,8 +64,6 @@ namespace nana
|
||||
unsigned amount(unsigned value);
|
||||
void unknown(bool);
|
||||
bool unknown() const;
|
||||
bool stop(bool s=true); ///< request stop or cancel and return previus stop status
|
||||
bool stopped() const;
|
||||
};
|
||||
}//end namespace nana
|
||||
#endif
|
||||
|
@ -78,7 +78,7 @@ namespace nana{ namespace audio
|
||||
void buffer_preparation::revert(meta * m)
|
||||
{
|
||||
std::lock_guard<decltype(token_prepared_)> lock(token_prepared_);
|
||||
bool if_signal = prepared_.empty();
|
||||
auto const if_signal = prepared_.empty();
|
||||
prepared_.emplace_back(m);
|
||||
if(if_signal)
|
||||
cond_prepared_.notify_one();
|
||||
|
@ -8,6 +8,8 @@
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* @file: nana/gui/msgbox.hpp
|
||||
* @Contributors
|
||||
* James Bremner
|
||||
*/
|
||||
|
||||
#include <nana/gui.hpp>
|
||||
@ -685,7 +687,7 @@ namespace nana
|
||||
{
|
||||
return impl_->empty_label_text;
|
||||
}
|
||||
|
||||
|
||||
window inputbox::boolean::create(window owner, unsigned label_px)
|
||||
{
|
||||
auto impl = impl_.get();
|
||||
@ -1258,7 +1260,8 @@ namespace nana
|
||||
inputbox::inputbox(window owner, ::std::string desc, ::std::string title)
|
||||
: owner_{ owner },
|
||||
description_(std::move(desc)),
|
||||
title_(std::move(title))
|
||||
title_(std::move(title)),
|
||||
min_width_entry_field_pixels_( 100 )
|
||||
{}
|
||||
|
||||
void inputbox::image(::nana::paint::image img, bool is_left, const rectangle& valid_area)
|
||||
@ -1280,6 +1283,17 @@ namespace nana
|
||||
verifier_ = std::move(verifier);
|
||||
}
|
||||
|
||||
//Inputbox set minimum width entry field(https://github.com/cnjinhao/nana/pull/234)
|
||||
//Contributed by James Bremner
|
||||
void inputbox::min_width_entry_field( unsigned pixels )
|
||||
{
|
||||
// don't let the entry fields vanish entirely
|
||||
if( pixels < 10 )
|
||||
pixels = 10;
|
||||
|
||||
min_width_entry_field_pixels_ = pixels;
|
||||
}
|
||||
|
||||
void inputbox::_m_fetch_args(std::vector<abstract_content*>&)
|
||||
{}
|
||||
|
||||
@ -1304,9 +1318,9 @@ namespace nana
|
||||
each_pixels.push_back(px.height);
|
||||
}
|
||||
|
||||
//Adjust the fixed_px for good looking
|
||||
if (has_0_fixed_px && (fixed_px < 100))
|
||||
fixed_px = 100;
|
||||
//Ensure that the entry fields are at least as wide as the minimum
|
||||
if (has_0_fixed_px && (fixed_px < min_width_entry_field_pixels_ ))
|
||||
fixed_px = min_width_entry_field_pixels_;
|
||||
|
||||
inputbox_window input_wd(owner_, images_, valid_areas_, description_, title_, contents.size(), label_px + 10 + fixed_px, each_pixels);
|
||||
|
||||
|
@ -30,71 +30,31 @@ namespace nana
|
||||
{
|
||||
struct item_type
|
||||
{
|
||||
item_type(const native_string_type& text, unsigned long shortkey)
|
||||
: text(text), shortkey(shortkey)
|
||||
item_type(std::string&& text, wchar_t shortkey, std::size_t shortkey_pos):
|
||||
text(std::move(text)),
|
||||
shortkey(shortkey),
|
||||
shortkey_pos(shortkey_pos)
|
||||
{}
|
||||
|
||||
native_string_type text;
|
||||
unsigned long shortkey;
|
||||
std::string text; ///< Transformed text, the shortkey charactor has been proccessed.
|
||||
wchar_t shortkey;
|
||||
std::size_t shortkey_pos;
|
||||
::nana::menu menu_obj;
|
||||
::nana::point pos;
|
||||
::nana::size size;
|
||||
};
|
||||
|
||||
class trigger::itembase
|
||||
{
|
||||
public:
|
||||
using container = std::vector<item_type*>;
|
||||
|
||||
~itembase()
|
||||
{
|
||||
for(auto i : cont_)
|
||||
delete i;
|
||||
}
|
||||
|
||||
void append(const native_string_type& text, unsigned long shortkey)
|
||||
{
|
||||
if(shortkey && shortkey < 0x61) shortkey += (0x61 - 0x41);
|
||||
cont_.emplace_back(new item_type(text, shortkey));
|
||||
}
|
||||
|
||||
std::size_t find(unsigned long shortkey) const
|
||||
{
|
||||
if(shortkey)
|
||||
{
|
||||
if(shortkey < 0x61) shortkey += (0x61 - 0x41);
|
||||
|
||||
std::size_t index = 0;
|
||||
for(auto i : cont_)
|
||||
{
|
||||
if(i->shortkey == shortkey)
|
||||
return index;
|
||||
++index;
|
||||
}
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
const container& cont() const
|
||||
{
|
||||
return cont_;
|
||||
}
|
||||
private:
|
||||
container cont_;
|
||||
};
|
||||
|
||||
struct trigger::essence
|
||||
{
|
||||
widget *widget_ptr{ nullptr };
|
||||
//paint::graphics *graph{ nullptr };
|
||||
|
||||
itembase items;
|
||||
|
||||
enum class behavior
|
||||
{
|
||||
none, focus, menu,
|
||||
};
|
||||
|
||||
|
||||
widget *widget_ptr{ nullptr };
|
||||
std::vector<item_type*> items;
|
||||
|
||||
struct state_type
|
||||
{
|
||||
std::size_t active{ nana::npos };
|
||||
@ -110,18 +70,30 @@ namespace nana
|
||||
}state;
|
||||
|
||||
//functions
|
||||
|
||||
~essence()
|
||||
{
|
||||
for (auto p : items)
|
||||
delete p;
|
||||
}
|
||||
|
||||
nana::menu& push_back(const std::string& text)
|
||||
{
|
||||
wchar_t shortkey;
|
||||
API::transform_shortkey_text(text, shortkey, nullptr);
|
||||
std::size_t shortkey_pos;
|
||||
auto transformed_text = API::transform_shortkey_text(text, shortkey, &shortkey_pos);
|
||||
|
||||
if (shortkey)
|
||||
API::register_shortkey(this->widget_ptr->handle(), shortkey);
|
||||
API::register_shortkey(*widget_ptr, shortkey);
|
||||
|
||||
this->items.append(to_nstring(text), shortkey);
|
||||
API::refresh_window(this->widget_ptr->handle());
|
||||
|
||||
return this->items.cont()[this->items.cont().size() - 1]->menu_obj;
|
||||
if (shortkey && shortkey < 0x61)
|
||||
shortkey += (0x61 - 0x41);
|
||||
items.emplace_back(new item_type{ std::move(transformed_text), shortkey, shortkey_pos });
|
||||
|
||||
API::refresh_window(*widget_ptr);
|
||||
|
||||
return this->items.back()->menu_obj;
|
||||
}
|
||||
|
||||
bool cancel()
|
||||
@ -130,7 +102,6 @@ namespace nana
|
||||
return false;
|
||||
|
||||
this->close_menu();
|
||||
state.menu_active = false;
|
||||
state.behave = behavior::none;
|
||||
|
||||
auto pos = API::cursor_position();
|
||||
@ -141,13 +112,17 @@ namespace nana
|
||||
}
|
||||
|
||||
|
||||
bool open_menu()
|
||||
bool open_menu(bool activate_menu = false)
|
||||
{
|
||||
if (activate_menu)
|
||||
state.menu_active = true;
|
||||
|
||||
auto pos = state.active;
|
||||
if (pos >= items.cont().size())
|
||||
|
||||
if (pos >= items.size())
|
||||
return false;
|
||||
|
||||
auto item_ptr = items.cont()[pos];
|
||||
auto item_ptr = items[pos];
|
||||
|
||||
if (state.menu_active && (state.menu != &(item_ptr->menu_obj)))
|
||||
{
|
||||
@ -156,6 +131,9 @@ namespace nana
|
||||
API::dev::delay_restore(false);
|
||||
state.active = pos;
|
||||
|
||||
//Resets this flag, because close_menu() deactivates the menu
|
||||
state.menu_active = true;
|
||||
|
||||
state.menu = &(item_ptr->menu_obj);
|
||||
state.menu->destroy_answer([this]
|
||||
{
|
||||
@ -177,6 +155,8 @@ namespace nana
|
||||
|
||||
bool close_menu()
|
||||
{
|
||||
state.menu_active = false;
|
||||
|
||||
if (state.menu)
|
||||
{
|
||||
state.passive_close = false;
|
||||
@ -188,18 +168,37 @@ namespace nana
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::size_t find(wchar_t shortkey) const
|
||||
{
|
||||
if (shortkey)
|
||||
{
|
||||
if (shortkey < 0x61) shortkey += (0x61 - 0x41);
|
||||
|
||||
std::size_t index = 0;
|
||||
for (auto item_ptr : items)
|
||||
{
|
||||
if (item_ptr->shortkey == shortkey)
|
||||
return index;
|
||||
++index;
|
||||
}
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
|
||||
std::size_t find(const ::nana::point& pos)
|
||||
{
|
||||
if ((2 <= pos.x) && (2 <= pos.y) && (pos.y < 25))
|
||||
{
|
||||
int item_x = 2;
|
||||
std::size_t index = 0;
|
||||
for (auto i : items.cont())
|
||||
|
||||
for (auto item_ptr : items)
|
||||
{
|
||||
if (item_x <= pos.x && pos.x < item_x + static_cast<int>(i->size.width))
|
||||
if ((item_x <= pos.x) && (pos.x < item_x + static_cast<int>(item_ptr->size.width)))
|
||||
return index;
|
||||
|
||||
item_x += i->size.width;
|
||||
item_x += static_cast<int>(item_ptr->size.width);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
@ -263,7 +262,7 @@ namespace nana
|
||||
return *ess_;
|
||||
}
|
||||
|
||||
void trigger::attached(widget_reference widget, graph_reference graph)
|
||||
void trigger::attached(widget_reference widget, graph_reference)
|
||||
{
|
||||
ess_->widget_ptr = &widget;
|
||||
}
|
||||
@ -280,15 +279,10 @@ namespace nana
|
||||
nana::size item_s(0, 23);
|
||||
|
||||
unsigned long index = 0;
|
||||
for (auto pm : ess_->items.cont())
|
||||
|
||||
for (auto pm : ess_->items)
|
||||
{
|
||||
//Transform the text if it contains the hotkey character
|
||||
wchar_t hotkey;
|
||||
::std::wstring::size_type hotkey_pos;
|
||||
auto text = API::transform_shortkey_text(to_utf8(pm->text), hotkey, &hotkey_pos);
|
||||
|
||||
nana::size text_s = graph.text_extent_size(text);
|
||||
|
||||
auto text_s = graph.text_extent_size(pm->text);
|
||||
item_s.width = text_s.width + 16;
|
||||
|
||||
pm->pos = item_pos;
|
||||
@ -308,9 +302,9 @@ namespace nana
|
||||
|
||||
//Draw text, the text is transformed from orignal for hotkey character
|
||||
int text_top_off = (item_s.height - text_s.height) / 2;
|
||||
ird.caption({ item_pos.x + 8, item_pos.y + text_top_off }, to_nstring(text));
|
||||
ird.caption({ item_pos.x + 8, item_pos.y + text_top_off }, to_nstring(pm->text));
|
||||
|
||||
API::dev::draw_shortkey_underline(graph, text, hotkey, hotkey_pos, { item_pos.x + 8, item_pos.y + text_top_off }, ird.scheme_ptr()->text_fgcolor);
|
||||
API::dev::draw_shortkey_underline(graph, pm->text, pm->shortkey, pm->shortkey_pos, { item_pos.x + 8, item_pos.y + text_top_off }, ird.scheme_ptr()->text_fgcolor);
|
||||
|
||||
item_pos.x += pm->size.width;
|
||||
++index;
|
||||
@ -365,12 +359,7 @@ namespace nana
|
||||
ess_->state.active = ess_->find(arg.pos);
|
||||
|
||||
if (npos != ess_->state.active)
|
||||
{
|
||||
if (!ess_->state.menu_active)
|
||||
ess_->state.menu_active = true;
|
||||
|
||||
ess_->open_menu();
|
||||
}
|
||||
ess_->open_menu(true);
|
||||
else
|
||||
ess_->cancel();
|
||||
|
||||
@ -402,7 +391,6 @@ namespace nana
|
||||
{
|
||||
ess_->state.behave = essence::behavior::none;
|
||||
ess_->state.nullify_mouse = true;
|
||||
ess_->state.menu_active = false;
|
||||
ess_->close_menu();
|
||||
ess_->state.active = npos;
|
||||
refresh(graph);
|
||||
@ -437,7 +425,6 @@ namespace nana
|
||||
{
|
||||
ess_->close_menu();
|
||||
ess_->state.behave = essence::behavior::focus;
|
||||
ess_->state.menu_active = false;
|
||||
}
|
||||
break;
|
||||
case keyboard::enter:
|
||||
@ -479,8 +466,7 @@ namespace nana
|
||||
case keyboard::os_arrow_up:
|
||||
case keyboard::os_arrow_down:
|
||||
case keyboard::enter:
|
||||
ess_->state.menu_active = true;
|
||||
if(ess_->open_menu())
|
||||
if(ess_->open_menu(true))
|
||||
menu_ptr->goto_next(true);
|
||||
break;
|
||||
case keyboard::escape:
|
||||
@ -491,12 +477,11 @@ namespace nana
|
||||
}
|
||||
break;
|
||||
default:
|
||||
auto index = ess_->items.find(arg.key);
|
||||
auto index = ess_->find(arg.key);
|
||||
if(index != npos)
|
||||
{
|
||||
ess_->state.active = index;
|
||||
ess_->state.menu_active = true;
|
||||
if(ess_->open_menu())
|
||||
if(ess_->open_menu(true))
|
||||
menu_ptr->goto_next(true);
|
||||
}
|
||||
break;
|
||||
@ -534,15 +519,14 @@ namespace nana
|
||||
{
|
||||
API::focus_window(ess_->widget_ptr->handle());
|
||||
|
||||
auto index = ess_->items.find(arg.key);
|
||||
auto index = ess_->find(arg.key);
|
||||
if(index != npos && (index != ess_->state.active || nullptr == ess_->state.menu))
|
||||
{
|
||||
ess_->close_menu();
|
||||
ess_->state.menu_active = true;
|
||||
ess_->state.nullify_mouse = true;
|
||||
ess_->state.active = index;
|
||||
|
||||
if(ess_->open_menu())
|
||||
if(ess_->open_menu(true))
|
||||
ess_->state.menu->goto_next(true);
|
||||
|
||||
refresh(graph);
|
||||
@ -553,9 +537,10 @@ namespace nana
|
||||
|
||||
void trigger::_m_move(graph_reference graph, bool to_left)
|
||||
{
|
||||
if(ess_->items.cont().empty()) return;
|
||||
if (ess_->items.empty()) return;
|
||||
|
||||
const std::size_t last_pos = ess_->items.size() - 1;
|
||||
|
||||
const std::size_t last_pos = ess_->items.cont().size() - 1;
|
||||
auto index = ess_->state.active;
|
||||
if(to_left)
|
||||
{
|
||||
@ -617,12 +602,12 @@ namespace nana
|
||||
|
||||
menu& menubar::at(std::size_t pos) const
|
||||
{
|
||||
return get_drawer_trigger().ess().items.cont().at(pos)->menu_obj;
|
||||
return get_drawer_trigger().ess().items.at(pos)->menu_obj;
|
||||
}
|
||||
|
||||
std::size_t menubar::length() const
|
||||
{
|
||||
return get_drawer_trigger().ess().items.cont().size();
|
||||
return get_drawer_trigger().ess().items.size();
|
||||
}
|
||||
|
||||
bool menubar::cancel()
|
||||
@ -639,7 +624,7 @@ namespace nana
|
||||
if (wd == this->handle())
|
||||
return true;
|
||||
|
||||
auto & items = get_drawer_trigger().ess().items.cont();
|
||||
auto & items = get_drawer_trigger().ess().items;
|
||||
while (wd)
|
||||
{
|
||||
auto owner = API::get_owner_window(wd);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* A Progress Indicator Implementation
|
||||
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -17,136 +17,185 @@ namespace nana
|
||||
{
|
||||
namespace progress
|
||||
{
|
||||
//class trigger
|
||||
void trigger::attached(widget_reference wd, graph_reference graph)
|
||||
scheme::scheme()
|
||||
{
|
||||
widget_ = &wd;
|
||||
graph_ = &graph;
|
||||
foreground = static_cast<color_rgb>(0x107515);
|
||||
}
|
||||
|
||||
unsigned trigger::value() const
|
||||
class substance
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
public:
|
||||
static const unsigned border_px = 1;
|
||||
|
||||
unsigned trigger::value(unsigned v)
|
||||
{
|
||||
internal_scope_guard isg;
|
||||
if(false == unknown_)
|
||||
void set_widget(widget& wdg)
|
||||
{
|
||||
if(value_ != v)
|
||||
value_ = v > max_?max_:v;
|
||||
widget_ = static_cast<nana::progress*>(&wdg);
|
||||
}
|
||||
else
|
||||
value_ += (v?10:v);
|
||||
|
||||
if(_m_check_changing(value_))
|
||||
nana::progress* widget_ptr() const
|
||||
{
|
||||
refresh(*graph_);
|
||||
API::update_window(widget_->handle());
|
||||
return widget_;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
unsigned trigger::inc()
|
||||
{
|
||||
internal_scope_guard isg;
|
||||
if(false == unknown_)
|
||||
unsigned inc()
|
||||
{
|
||||
if(value_ < max_)
|
||||
++value_;
|
||||
auto val = value(nullptr) + 1;
|
||||
return value(&val);
|
||||
}
|
||||
else
|
||||
value_ += 5;
|
||||
|
||||
if(_m_check_changing(value_))
|
||||
API::refresh_window(widget_->handle());
|
||||
return value_;
|
||||
unsigned value(const unsigned* value_ptr)
|
||||
{
|
||||
//Sets new value if value_ptr is not a nullptr
|
||||
if (value_ptr)
|
||||
{
|
||||
if (unknown_)
|
||||
value_ += (*value_ptr ? 5 : 0);
|
||||
else
|
||||
value_ = (std::min)(max_, *value_ptr);
|
||||
|
||||
_m_try_refresh();
|
||||
}
|
||||
return value_;
|
||||
}
|
||||
|
||||
void reset_value()
|
||||
{
|
||||
value_ = 0;
|
||||
}
|
||||
|
||||
unsigned maximum(const unsigned * value_ptr)
|
||||
{
|
||||
//Sets new maximum if value_ptr is not a nullptr
|
||||
if (value_ptr)
|
||||
{
|
||||
max_ = (*value_ptr > 0 ? *value_ptr : 1);
|
||||
_m_try_refresh();
|
||||
}
|
||||
return max_;
|
||||
}
|
||||
|
||||
bool unknown(const bool* state_ptr)
|
||||
{
|
||||
if (state_ptr)
|
||||
{
|
||||
unknown_ = *state_ptr;
|
||||
if (unknown_)
|
||||
value_px_ = 0;
|
||||
else
|
||||
value_ = (std::min)(value_, max_);
|
||||
}
|
||||
return unknown_;
|
||||
}
|
||||
|
||||
unsigned value_px() const
|
||||
{
|
||||
return value_px_;
|
||||
}
|
||||
private:
|
||||
void _m_try_refresh()
|
||||
{
|
||||
if (nullptr == widget_)
|
||||
return;
|
||||
|
||||
auto value_px = (widget_->size().width - border_px * 2) * value_ / max_;
|
||||
|
||||
if (value_px != value_px_)
|
||||
{
|
||||
value_px_ = value_px;
|
||||
API::refresh_window(*widget_);
|
||||
}
|
||||
}
|
||||
private:
|
||||
nana::progress * widget_{ nullptr };
|
||||
unsigned max_{ 100 };
|
||||
unsigned value_{ 0 };
|
||||
unsigned value_px_{ 0 };
|
||||
bool unknown_{ false };
|
||||
};
|
||||
|
||||
trigger::trigger()
|
||||
: progress_(new substance)
|
||||
{}
|
||||
|
||||
trigger::~trigger()
|
||||
{
|
||||
delete progress_;
|
||||
}
|
||||
|
||||
unsigned trigger::Max() const
|
||||
substance* trigger::progress() const
|
||||
{
|
||||
return max_;
|
||||
return progress_;
|
||||
}
|
||||
|
||||
unsigned trigger::Max(unsigned value)
|
||||
|
||||
void trigger::attached(widget_reference wdg, graph_reference)
|
||||
{
|
||||
max_ = value;
|
||||
if(max_ == 0) ++max_;
|
||||
|
||||
API::refresh_window(widget_->handle());
|
||||
return max_;
|
||||
}
|
||||
|
||||
void trigger::unknown(bool enb)
|
||||
{
|
||||
unknown_ = enb;
|
||||
if(enb)
|
||||
draw_width_ = static_cast<unsigned>(-1);
|
||||
}
|
||||
|
||||
bool trigger::unknown() const
|
||||
{
|
||||
return unknown_;
|
||||
}
|
||||
bool trigger::stopped() const
|
||||
{
|
||||
return stop_;
|
||||
}
|
||||
bool trigger::stop(bool s)
|
||||
{
|
||||
std::swap(s,stop_);
|
||||
return s;
|
||||
progress_->set_widget(wdg);
|
||||
}
|
||||
|
||||
void trigger::refresh(graph_reference graph)
|
||||
{
|
||||
if (false == unknown_)
|
||||
draw_width_ = static_cast<unsigned>((graph.width() - border * 2) * (double(value_) / max_));
|
||||
{
|
||||
const unsigned border_px = substance::border_px;
|
||||
|
||||
_m_draw_box(graph);
|
||||
_m_draw_progress(graph);
|
||||
}
|
||||
rectangle rt_val{ graph.size() };
|
||||
auto const width = rt_val.width - border_px * 2;
|
||||
|
||||
void trigger::_m_draw_box(graph_reference graph)
|
||||
{
|
||||
rectangle r{ graph.size() };
|
||||
graph.gradual_rectangle(r, colors::button_face_shadow_end, colors::button_face_shadow_start, true);
|
||||
::nana::color lt{ colors::gray }, rb{colors::white};
|
||||
graph.frame_rectangle(r, lt, lt, rb, rb);
|
||||
}
|
||||
rt_val.pare_off(static_cast<int>(border_px));
|
||||
|
||||
void trigger::_m_draw_progress(graph_reference graph)
|
||||
{
|
||||
unsigned width = graph.width() - border * 2;
|
||||
unsigned height = graph.height() - border * 2;
|
||||
|
||||
if(false == unknown_)
|
||||
auto rt_bground = rt_val;
|
||||
if (false == progress_->unknown(nullptr))
|
||||
{
|
||||
if(draw_width_)
|
||||
graph.gradual_rectangle({ static_cast<int>(border), static_cast<int>(border), draw_width_, height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true);
|
||||
rt_bground.x = static_cast<int>(progress_->value_px()) + static_cast<int>(border_px);
|
||||
rt_bground.width -= progress_->value_px();
|
||||
|
||||
rt_val.width = progress_->value_px();
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned block = width / 3;
|
||||
auto const block = width / 3;
|
||||
|
||||
int left = (value_ < block ? 0 : value_ - block) + border;
|
||||
int right = (value_ >= width - 1 + border? width - 1 + border: value_);
|
||||
auto const value = progress_->value(nullptr);
|
||||
|
||||
if(right >= left)
|
||||
graph.gradual_rectangle({ left, static_cast<int>(border), static_cast<unsigned>(right - left + 1), height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true);
|
||||
auto left = (std::max)(0, static_cast<int>(value - block)) + static_cast<int>(border_px);
|
||||
auto right = static_cast<int>((std::min)(value, width + border_px -1));
|
||||
|
||||
if(value_ >= width + block) value_ = 0;
|
||||
if (right > left)
|
||||
{
|
||||
rt_val.x = left;
|
||||
rt_val.width = static_cast<unsigned>(right - left + 1);
|
||||
}
|
||||
else
|
||||
rt_val.width = 0;
|
||||
|
||||
if (value >= width + block)
|
||||
progress_->reset_value();
|
||||
}
|
||||
}
|
||||
|
||||
bool trigger::_m_check_changing(unsigned newvalue) const
|
||||
{
|
||||
if(graph_)
|
||||
return (((graph_->width() - border * 2) * newvalue / max_) != draw_width_);
|
||||
return false;
|
||||
auto & sch = progress_->widget_ptr()->scheme();
|
||||
|
||||
//Draw the gradient background if gradient_bgcolor is available.
|
||||
|
||||
auto bgcolor = sch.background.get_color();
|
||||
if (bgcolor.invisible())
|
||||
bgcolor = colors::button_face;
|
||||
|
||||
if (sch.gradient_bgcolor.get_color().invisible())
|
||||
graph.rectangle(rt_bground, true, bgcolor);
|
||||
else
|
||||
graph.gradual_rectangle(rt_bground, bgcolor, sch.gradient_bgcolor.get_color(), true);
|
||||
|
||||
//Draw the gradient fgcolor if gradient_fgcolor is available.
|
||||
|
||||
auto fgcolor = sch.foreground.get_color();
|
||||
if (fgcolor.invisible())
|
||||
fgcolor = static_cast<color_rgb>(0x107515);
|
||||
|
||||
if (sch.gradient_fgcolor.get_color().invisible())
|
||||
graph.rectangle(rt_val, true, fgcolor);
|
||||
else
|
||||
graph.gradual_rectangle(rt_val, sch.gradient_fgcolor.get_color(), fgcolor, true);
|
||||
|
||||
graph.frame_rectangle(rectangle{ graph.size() }, colors::gray, colors::gray, colors::white, colors::white);
|
||||
}
|
||||
//end class drawer
|
||||
}//end namespace progress
|
||||
}//end namespace drawerbase
|
||||
|
||||
@ -165,49 +214,42 @@ namespace nana
|
||||
|
||||
unsigned progress::value() const
|
||||
{
|
||||
return get_drawer_trigger().value();
|
||||
return get_drawer_trigger().progress()->value(nullptr);
|
||||
}
|
||||
|
||||
unsigned progress::value(unsigned val)
|
||||
{
|
||||
internal_scope_guard isg;
|
||||
internal_scope_guard lock;
|
||||
if(API::empty_window(this->handle()) == false)
|
||||
return get_drawer_trigger().value(val);
|
||||
return get_drawer_trigger().progress()->value(&val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned progress::inc()
|
||||
{
|
||||
internal_scope_guard isg;
|
||||
return get_drawer_trigger().inc();
|
||||
internal_scope_guard lock;
|
||||
return get_drawer_trigger().progress()->inc();
|
||||
}
|
||||
|
||||
unsigned progress::amount() const
|
||||
{
|
||||
return get_drawer_trigger().Max();
|
||||
return get_drawer_trigger().progress()->maximum(nullptr);
|
||||
}
|
||||
|
||||
unsigned progress::amount(unsigned value)
|
||||
{
|
||||
return get_drawer_trigger().Max(value);
|
||||
return get_drawer_trigger().progress()->maximum(&value);
|
||||
}
|
||||
|
||||
void progress::unknown(bool enb)
|
||||
{
|
||||
get_drawer_trigger().unknown(enb);
|
||||
internal_scope_guard lock;
|
||||
get_drawer_trigger().progress()->unknown(&enb);
|
||||
}
|
||||
|
||||
bool progress::unknown() const
|
||||
{
|
||||
return get_drawer_trigger().unknown();
|
||||
}
|
||||
bool progress::stop(bool s)
|
||||
{
|
||||
return get_drawer_trigger().stop(s);
|
||||
}
|
||||
bool progress::stopped() const
|
||||
{
|
||||
return get_drawer_trigger().stopped();
|
||||
return get_drawer_trigger().progress()->unknown(nullptr);
|
||||
}
|
||||
//end class progress
|
||||
}//end namespace nana
|
||||
|
Loading…
x
Reference in New Issue
Block a user