diff --git a/bazaar/Functions4U/Functions4U.h b/bazaar/Functions4U/Functions4U.h index 8fbc0a8d1..1e60612a5 100644 --- a/bazaar/Functions4U/Functions4U.h +++ b/bazaar/Functions4U/Functions4U.h @@ -255,6 +255,11 @@ template inline T pow3(T a) {return a*a*a;} template inline T pow4(T a) {return pow2(pow2(a));} +template +inline T fround(T x, int numdec) { + int64 mult = 10*numdec; + return T(int64(x*mult + .5))/mult; +} template inline bool Between(const T& val, const T& min, const T& max) { return val >= min && val <= max; @@ -667,6 +672,17 @@ void Shuffle(C &data, int randomSeed = Null) { ShuffleDescending(data, generator); } +template +bool Equal(const T& a, const T& b, const T& ratio) { + if (a == 0) + return b <= ratio; + if (b == 0) + return a <= ratio; + if(abs((a - b)/b) <= ratio) + return true; + return false; +} + template void FindAdd(Range& r, const V& value, int from = 0) { for(int i = from; i < r.GetCount(); i++) @@ -675,6 +691,14 @@ void FindAdd(Range& r, const V& value, int from = 0) { r.Add(value); } +template +void FindAddRatio(Range& r, const V& value, const V& ratio, int from = 0) { + for(int i = from; i < r.GetCount(); i++) + if(Equal(r[i], value, ratio)) + return; + r.Add(value); +} + template int FindIndexDelta(const Range& r, const V& value, const V& delta, int from = 0) { @@ -687,22 +711,36 @@ int FindIndexDelta(const Range& r, const V& value, const V& delta, int from = 0) template int FindIndexRatio(const Range& r, const V& value, const V& ratio, int from = 0) { - for(int i = from; i < r.GetCount(); i++) - if(abs((r[i] - value)/value) <= ratio) + for(int i = from; i < r.GetCount(); i++) { + if (Equal(r[i], value, ratio)) return i; + } return -1; } -template -bool Compare(Range& a, Range& b, int from = 0) { +template +bool Compare(const Range& a, const Range& b, const V& ratio = 0) { if (a.GetCount() != b.GetCount()) return false; - for(int i = from; i < a.GetCount(); i++) - if(a[i] != b[i]) + for(int i = 0; i < a.GetCount(); i++) { + V div = (b[i] != 0) ? b[i] : (a[i] != 0 ? a[i] : 1); + if(abs(a[i] - b[i])/div > ratio) return false; + } return true; } +template +String ToString(const Range& a) { + String ret; + for(int i = 0; i < a.GetCount(); i++) { + if (i > 0) + ret << ";"; + ret << a[i]; + } + return ret; +} + class RealTimeStop { typedef RealTimeStop CLASSNAME; public: diff --git a/bazaar/Functions4U/Functions4U.upp b/bazaar/Functions4U/Functions4U.upp index 0520985f1..d04f0709e 100644 --- a/bazaar/Functions4U/Functions4U.upp +++ b/bazaar/Functions4U/Functions4U.upp @@ -46,3 +46,4 @@ file Html/htmld.h, Copying; + spellcheck_comments "EN-GB" \ No newline at end of file diff --git a/bazaar/Functions4U/Functions4U_Gui.cpp b/bazaar/Functions4U/Functions4U_Gui.cpp index 746828786..b1dde9e55 100644 --- a/bazaar/Functions4U/Functions4U_Gui.cpp +++ b/bazaar/Functions4U/Functions4U_Gui.cpp @@ -193,5 +193,26 @@ ConsoleOutput::~ConsoleOutput() { #endif } +void ArrayCtrlWhenBar(Bar &menu, ArrayCtrl &array) { + menu.Add(t_("Select all"), Null, [&] {ArrayCtrlRowSelect(array);}) + .Key(K_CTRL_A).Help(t_("Select all rows")); + + int count = array.GetSelectCount(); + if (count == 0) + menu.Add(t_("No row selected"), Null, Null).Enable(false).Bold(true); + else { + menu.Add(Format(t_("Selected %d rows"), count), Null, Null).Enable(false).Bold(true); + menu.Add(t_("Copy"), Null, [&] {ArrayCtrlRowCopy(array, false);}) + .Key(K_CTRL_C).Help(t_("Copy selected rows to clipboard")); + } +} + +void ArrayCtrlRowCopy(ArrayCtrl &array, bool header) { + array.SetClipboard(true, header); +} + +void ArrayCtrlRowSelect(ArrayCtrl &array) { + array.Select(0, array.GetCount(), true); +} #endif \ No newline at end of file diff --git a/bazaar/Functions4U/Functions4U_Gui.h b/bazaar/Functions4U/Functions4U_Gui.h index 45bdc7d82..2a1c4f698 100644 --- a/bazaar/Functions4U/Functions4U_Gui.h +++ b/bazaar/Functions4U/Functions4U_Gui.h @@ -106,4 +106,8 @@ private: #endif }; +void ArrayCtrlWhenBar(Bar &menu, ArrayCtrl &array); +void ArrayCtrlRowCopy(ArrayCtrl &array, bool header); +void ArrayCtrlRowSelect(ArrayCtrl &array); + #endif