Skip to content

Commit

Permalink
directvt#571 WIP: Saturate_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Apr 20, 2024
1 parent 1309904 commit 9ee06d4
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 263 deletions.
3 changes: 2 additions & 1 deletion src/netxs/apps/desk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ namespace netxs::app::desk
{
if (auto taskbar_grips = boss.base::parent())
{
taskbar_grips->base::min_sz.x = std::max(1, taskbar_grips->base::min_sz.x + gear.delta.get().x);
auto delta = twod{ gear.delta.get() };
taskbar_grips->base::min_sz.x = std::max(1, taskbar_grips->base::min_sz.x + delta.x);
taskbar_grips->base::max_sz.x = taskbar_grips->base::min_sz.x;
active ? menu_max_size = taskbar_grips->base::min_sz.x
: menu_min_size = taskbar_grips->base::min_sz.x;
Expand Down
20 changes: 10 additions & 10 deletions src/netxs/desktopio/ansivt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace netxs::ansi
static const auto c0_ack = '\x06'; // Acknowledge - Response to an ENQ, or an indication of successful receipt of a message.
static const auto c0_bel = '\x07'; // Bell, Alert \a - Originally used to sound a bell on the terminal. Later used for a beep on systems that didn't have a physical bell. May also quickly turn on and off inverse video (a visual bell).
static const auto c0_bs = '\x08'; // Backspace \b - Move cursor one position leftwards. On input, this may delete the character to the left of the cursor. On output, where in early computer technology a character once printed could not be erased, the backspace was sometimes used to generate accented characters in ASCII. For example, à could be produced using the three character sequence a BS ` (or, using the characters’ hex values, 0x61 0x08 0x60). This usage is now deprecated and generally not supported. To provide disambiguation between the two potential uses of backspace, the cancel character control code was made part of the standard C1 control set.
static const auto c0_ht = '\x09'; // Character \t - Tabulation, Horizontal Tabulation \t Position to the next character tab stop.
static const auto c0_ht = '\x09'; // Character \t - Tabulation, Horizontal Tabulation \t Position to the next character tab stop.
static const auto c0_lf = '\x0A'; // Line Feed \n - On typewriters, printers, and some terminal emulators, moves cursor down one row without affecting its column position. On Unix, used to mark end-of-line. In DOS, Windows, and various network standards, LF is used following CR as part of the end-of-line mark.
static const auto c0_vt = '\x0B'; // Line Tab,VTab \v - Position the form at the next line tab stop.
static const auto c0_ff = '\x0C'; // Form Feed \f - On printers, load the next page. Treated as whitespace in many programming languages, and may be used to separate logical divisions in code. In some terminal emulators, it clears the screen. It still appears in some common plain text files as a page break character, such as the RFCs published by IETF.
Expand Down Expand Up @@ -917,10 +917,10 @@ namespace netxs::ansi
//hz, // text horizontal alignment.
//rf, // reverse (line) feed.

//wl, // set left horizontal wrapping field.
//wr, // set right horizontal wrapping field.
//wt, // set top vertical wrapping field.
//wb, // set bottom vertical wrapping field.
//wl, // set left horizontal wrapping field.
//wr, // set right horizontal wrapping field.
//wt, // set top vertical wrapping field.
//wb, // set bottom vertical wrapping field.

sc, // Save cursor position.
rc, // Load cursor position.
Expand Down Expand Up @@ -1107,7 +1107,7 @@ namespace netxs::ansi
struct marker
{
using changer = std::array<void (*)(cell&), ctrl::count>;
changer setter = {};
changer setter{};
marker()
{
//setter[ctrl::alm] = [](cell& p){ p.rtl(true); };
Expand Down Expand Up @@ -1614,13 +1614,13 @@ namespace netxs::ansi
// vt_parser: Set keypad mode.
static void keym(qiew& /*ascii*/, T*& /*p*/)
{
// Keypad mode Application ESC =
// Keypad mode Numeric ESC >
// Keypad mode Application ESC =
// Keypad mode Numeric ESC >

//if (ascii)
//{
// ascii.pop_front(); // Take mode specifier =/>
// //todo implement
// ascii.pop_front(); // Take mode specifier =/>
// //todo implement
//}
}

Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/baseui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ namespace netxs::ui
detach();
}
// base: Recursively calculate global coordinate.
void global(twod& coor)
void global(auto& coor)
{
coor -= base::region.coor;
if (auto parent_ptr = parent())
Expand Down
56 changes: 27 additions & 29 deletions src/netxs/desktopio/canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,40 +331,38 @@ namespace netxs
// argb: Rough alpha blending ARGB colors.
//void mix_alpha(argb c)
//{
// auto blend = [](auto const& c1, auto const& c2, auto const& alpha)
// {
// return ((c1 << 8) + (c2 - c1) * alpha) >> 8;
// };
// auto norm = [](auto const& c2, auto const& alpha)
// {
// return (c2 * alpha) >> 8;
// };
// auto blend = [](auto const& c1, auto const& c2, auto const& alpha)
// {
// return ((c1 << 8) + (c2 - c1) * alpha) >> 8;
// };
// auto norm = [](auto const& c2, auto const& alpha)
// {
// return (c2 * alpha) >> 8;
// };
//
// if (chan.a)
// {
// if (c.chan.a)
// {
// auto& a1 = chan.a;
// auto& a2 = c.chan.a;
// chan.r = blend(norm(c.chan.r, a2), chan.r, a1);
// chan.g = blend(norm(c.chan.g, a2), chan.g, a1);
// chan.b = blend(norm(c.chan.b, a2), chan.b, a1);
// chan.a = c.chan.a;
// }
// }
// else
// {
// chan = c.chan;
// }
// if (chan.a)
// {
// if (c.chan.a)
// {
// auto& a1 = chan.a;
// auto& a2 = c.chan.a;
// chan.r = blend(norm(c.chan.r, a2), chan.r, a1);
// chan.g = blend(norm(c.chan.g, a2), chan.g, a1);
// chan.b = blend(norm(c.chan.b, a2), chan.b, a1);
// chan.a = c.chan.a;
// }
// }
// else
// {
// chan = c.chan;
// }
//}

//// argb: Are the colors identical.
//bool like(argb c) const
//{
//
// static constexpr auto k = ui32{ 0b11110000 };
// static constexpr auto threshold = ui32{ 0x00 + k << 16 + k << 8 + k };
// return (token & threshold) == (c.token & threshold);
// static constexpr auto k = ui32{ 0b11110000 };
// static constexpr auto threshold = ui32{ 0x00 + k << 16 + k << 8 + k };
// return (token & threshold) == (c.token & threshold);
//}
// argb: Shift color.
void xlight(si32 factor = 1)
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ namespace netxs::ui
//todo optimize - cache tooltip_page
auto tooltip_page = page{ tooltip_data };
auto full_area = full;
full_area.coor = std::max(dot_00, gear.coord - twod{ 4, tooltip_page.size() + 1 });
full_area.coor = std::max(dot_00, twod{ gear.coord } - twod{ 4, tooltip_page.size() + 1 });
full_area.size.x = dot_mx.x; // Prevent line wrapping.
canvas.full(full_area);
canvas.cup(dot_00);
Expand Down
24 changes: 12 additions & 12 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ namespace netxs::ui
{
if (square.x != new_area.size.x)
{
deform(new_area);
deform(new_area);
}
}

Expand Down Expand Up @@ -3779,18 +3779,18 @@ namespace netxs::ui
};
//LISTEN(tier::release, hids::events::mouse::move, gear)
//{
// auto apply = [&](auto active)
// {
// wide = active;
// if (Axis == axis::Y) config(active ? init * 2 // Make vertical scrollbar
// : init); // wider on hover
// base::reflow();
// return faux; // One shot call
// };
// auto apply = [&](auto active)
// {
// wide = active;
// if (Axis == axis::Y) config(active ? init * 2 // Make vertical scrollbar
// : init); // wider on hover
// base::reflow();
// return faux; // One shot call
// };
//
// timer.pacify(activity::mouse_leave);
// apply(activity::mouse_hover);
// timer.template actify<activity::mouse_leave>(skin::globals().active_timeout, apply);
// timer.pacify(activity::mouse_leave);
// apply(activity::mouse_hover);
// timer.template actify<activity::mouse_leave>(skin::globals().active_timeout, apply);
//};
LISTEN(tier::release, e2::render::any, parent_canvas)
{
Expand Down
24 changes: 12 additions & 12 deletions src/netxs/desktopio/directvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,37 +143,35 @@ namespace netxs::directvt
|| std::is_same_v<D, byte>
|| std::is_same_v<D, type>)
{
block.text::push_back(static_cast<char>(data));
block.text::push_back((char)data);
}
else if constexpr (std::is_integral_v<D>
else if constexpr (std::is_arithmetic_v<D>
|| std::is_same_v<D, twod>
|| std::is_same_v<D, fp2d>
|| std::is_same_v<D, dent>
|| std::is_same_v<D, rect>)
{
auto le_data = netxs::letoh(data);
auto v = view{ reinterpret_cast<char const*>(&le_data), sizeof(le_data) };
block += v;
block += view{ (char*)&le_data, sizeof(le_data) };
}
else if constexpr (std::is_same_v<D, argb>)
{
auto v = view{ reinterpret_cast<char const*>(&data), sizeof(data) };
block += v;
block += view{ (char*)&data, sizeof(data) };
}
else if constexpr (std::is_same_v<D, view>
|| std::is_same_v<D, qiew>
|| std::is_same_v<D, text>)
{
auto length = static_cast<sz_t>(data.length());
auto le_data = netxs::letoh(length);
auto size = view{ reinterpret_cast<char const*>(&le_data), sizeof(le_data) };
block += size;
auto length = (sz_t)data.length();
auto le_len = netxs::letoh(length);
block += view{ (char*)&le_len, sizeof(le_len) };
block += data;
}
else if constexpr (std::is_same_v<D, time>)
{
auto n = data.time_since_epoch().count();
auto v = view{ reinterpret_cast<char const*>(&n), sizeof(n) };
block += v;
auto le_n = netxs::letoh(n);
block += view{ (char*)&le_n, sizeof(le_n) };
}
else if constexpr (std::is_same_v<D, std::unordered_map<text, text>>
|| std::is_same_v<D, std::map<text, text>>
Expand Down Expand Up @@ -836,7 +834,9 @@ namespace netxs::directvt
(bool, wheeled) // sysmouse: Vertical scroll wheel.
(bool, hzwheel) // sysmouse: Horizontal scroll wheel.
(si32, wheeldt) // sysmouse: Scroll delta.
//todo use pixel-wise coords only
(twod, coordxy) // sysmouse: Cursor coordinates.
(fp2d, pixelxy) // sysmouse: Pixel-wise cursor coordinates.
(time, timecod) // sysmouse: Event time code.
(ui32, changed)) // sysmouse: Update stamp.
STRUCT_macro(mousebar, (bool, mode)) // CCC_SMS/* 26:1p */
Expand Down
4 changes: 2 additions & 2 deletions src/netxs/desktopio/gcscale.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ If such a modifier appears the first in the input stream the terminal should be
Assing VT-sequence as a CSI/SGR command, because it define characters rendition state and sets the appearance of the following characters.
```
Human readable format
ESC[ 110; <n1>;<n2>;<n3>;<n4> m
ESC[ 110; <n1>;<n2>;<n3>;<n4> m
Sequence with "cooked" parameter
ESC[ 111; <P> m
ESC[ 111; <P> m
```
- `n1`, `n2`, `n3`, `n4` are from 0 to 4.
- `n1 = Dx`, `n2 = Nx`, `n3 = Dy`, `n4 = Ny`.
Expand Down
6 changes: 3 additions & 3 deletions src/netxs/desktopio/generics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,9 @@ namespace netxs
//template<class M, class K>
//auto on_key_get(M const& map, K const& key)
//{
// const auto it = map.find(key);
// return it == map.end() ? std::nullopt
// : std::optional{ it };
// const auto it = map.find(key);
// return it == map.end() ? std::nullopt
// : std::optional{ it };
//}

template<class M>
Expand Down
12 changes: 8 additions & 4 deletions src/netxs/desktopio/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ namespace netxs
//duplet operator << (T i) const { return { x << i, y << i }; }
//duplet operator >> (T i) const { return { x >> i, y >> i }; }

template<class D, std::enable_if_t<std::is_arithmetic_v<D>>* = nullptr> constexpr auto operator / (D i) const { return duplet<D>{ x / i, y / i }; }
template<class D, std::enable_if_t<std::is_arithmetic_v<D>>* = nullptr> constexpr auto operator + (D i) const { return duplet<D>{ x + i, y + i }; }
template<class D, std::enable_if_t<std::is_arithmetic_v<D>>* = nullptr> constexpr auto operator - (D i) const { return duplet<D>{ x - i, y - i }; }
template<class D, std::enable_if_t<std::is_arithmetic_v<D>>* = nullptr> constexpr auto operator * (D i) const { return duplet<D>{ x * i, y * i }; }
template<class D, class = std::enable_if_t<std::is_arithmetic_v<D>>> constexpr auto operator / (D i) const { return duplet<D>{ x / i, y / i }; }
template<class D, class = std::enable_if_t<std::is_arithmetic_v<D>>> constexpr auto operator + (D i) const { return duplet<D>{ x + i, y + i }; }
template<class D, class = std::enable_if_t<std::is_arithmetic_v<D>>> constexpr auto operator - (D i) const { return duplet<D>{ x - i, y - i }; }
template<class D, class = std::enable_if_t<std::is_arithmetic_v<D>>> constexpr auto operator * (D i) const { return duplet<D>{ x * i, y * i }; }

bool operator () (duplet const& p)
{
Expand Down Expand Up @@ -171,6 +171,7 @@ namespace netxs

// geometry: 2D point.
using twod = duplet<si32>;
using fp2d = duplet<fp32>;

static constexpr auto dot_00 = twod{ 0,0 };
static constexpr auto dot_01 = twod{ 0,1 };
Expand All @@ -185,6 +186,9 @@ namespace netxs
twod divround(si32 n, twod p) { return { divround(n , p.x), divround(n , p.y) }; }
twod divround(twod n, twod p) { return { divround(n.x, p.x), divround(n.y, p.y) }; }
twod divupper(twod n, twod p) { return { divupper(n.x, p.x), divupper(n.y, p.y) }; }

//auto operator == (twod&& p1, fp2d&& p2) { return p1.x == p2.x && p1.y == p2.y; }
//auto operator == (fp2d&& p1, twod&& p2) { return p1.x == p2.x && p1.y == p2.y; }
}

namespace std
Expand Down
3 changes: 3 additions & 0 deletions src/netxs/desktopio/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ namespace netxs::input

using hist = std::array<hist_t, numofbuttons>;
using knob = std::array<knob_t, numofbuttons>;
//using tail = netxs::datetime::tail<fp2d>;
using tail = netxs::datetime::tail<twod>;

static constexpr auto dragstrt = mouse_event::button::drag::start:: any.group<numofbuttons>();
Expand All @@ -611,6 +612,8 @@ namespace netxs::input
static constexpr auto movement = mouse_event::move.id;
static constexpr auto noactive = si32{ -1 };

//fp2d prime = {}; // mouse: System mouse cursor coordinates.
//fp2d coord = {}; // mouse: Relative mouse cursor coordinates.
twod prime = {}; // mouse: System mouse cursor coordinates.
twod coord = {}; // mouse: Relative mouse cursor coordinates.
tail delta = {}; // mouse: History of mouse movements for a specified period of time.
Expand Down
Loading

0 comments on commit 9ee06d4

Please sign in to comment.