Skip to content

Commit

Permalink
Merge pull request #579 from o-sdn-o/gui-bridge
Browse files Browse the repository at this point in the history
Make terminal scrollback transparent by default
  • Loading branch information
o-sdn-o authored Mar 28, 2024
2 parents deba08f + 5b9e5d3 commit db9aedb
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 162 deletions.
4 changes: 2 additions & 2 deletions src/netxs/apps/calc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ namespace netxs::ui
auto region = item.region.normalize();
auto pos1 = region.coor / step * step;
auto pos2 = (region.coor + region.size + step) / step * step;
auto pick = rect{ full.coor + pos1, pos2 - pos1 }.clip(area).clip(clip);
auto pick = rect{ full.coor + pos1, pos2 - pos1 }.trimby(area).trimby(clip);
parent_canvas.fill(pick, fill);
}
if (item.inside)
{
auto pos1 = item.curpos / step * step;
auto pick = rect{ full.coor + pos1, step }.clip(clip);
auto pick = rect{ full.coor + pos1, step }.trimby(clip);
parent_canvas.fill(pick, fill);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/apps/term.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ namespace netxs::app::terminal
}
}
auto clip = parent_canvas.clip();
auto dest = clip.clip({ region.coor, { region.size.x, std::min(bground.size().y, *menu_height) }});
auto dest = clip.trim({ region.coor, { region.size.x, std::min(bground.size().y, *menu_height) }});
parent_canvas.clip(dest);
bground.move(region.coor);
parent_canvas.plot(bground, cell::shaders::blend); // Menu background.
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace netxs::app

namespace netxs::app::shared
{
static const auto version = "v0.9.75";
static const auto version = "v0.9.75b";
static const auto repository = "https://github.com/directvt/vtm";
static const auto usr_config = "~/.config/vtm/settings.xml"s;
static const auto sys_config = "/etc/vtm/settings.xml"s;
Expand Down
13 changes: 6 additions & 7 deletions src/netxs/desktopio/canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2333,9 +2333,8 @@ namespace netxs
void plot(core const& block, P fuse) // core: Fill the client area by the specified block with coordinates inside the canvas area.
{
//todo use block.client instead of block.region
auto local = rect{ client.coor - region.coor, client.size };
auto joint = local.clip(block.region);
if (joint)
auto joint = rect{ client.coor - region.coor, client.size };
if (joint.trimby(block.region))
{
auto place = joint.coor - block.region.coor;
netxs::inbody<faux>(*this, block, joint, place, fuse);
Expand Down Expand Up @@ -2532,17 +2531,17 @@ namespace netxs
{
auto temp = area;
temp.size.y = std::max(0, border.t); // Top
fill(temp.clip(area), fuse);
fill(temp.trim(area), fuse);
temp.coor.y += area.size.y - border.b; // Bottom
temp.size.y = std::max(0, border.b);
fill(temp.clip(area), fuse);
fill(temp.trim(area), fuse);
temp.size.x = std::max(0, border.l); // Left
temp.size.y = std::max(0, area.size.y - border.t - border.b);
temp.coor.y = area.coor.y + border.t;
fill(temp.clip(area), fuse);
fill(temp.trim(area), fuse);
temp.coor.x += area.size.x - border.r; // Right
temp.size.x = std::max(0, border.r);
fill(temp.clip(area), fuse);
fill(temp.trim(area), fuse);
}
template<class P>
void cage(rect area, twod border_width, P fuse) // core: Draw the cage around specified area.
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/consrv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,7 @@ struct impl : consrv
auto size = block.size();
auto clip = block.clip();
auto dest = rect{ coor, clip.size };
trim = dest.clip(trim);
trim.trimby(dest);
clip -= dest - trim;
coor = trim.coor;
auto head = block.begin() + clip.coor.y * size.x;
Expand Down
14 changes: 7 additions & 7 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ namespace netxs::ui
if (deed == hids::events::mouse::scroll::down.id) g.zoomdt -= warp;
else g.zoomdt += warp;
gear.owner.SIGNAL(tier::request, e2::form::prop::viewport, viewport, ());
auto r = g.zoomsz + g.zoomdt;
r.size = std::max(dot_00, r.size);
auto next = r.clip(viewport);
auto next = g.zoomsz + g.zoomdt;
next.size = std::max(dot_00, next.size);
next.trimby(viewport);
auto step = boss.base::extend(next);
if (!step.size) // Undo if can't zoom.
{
Expand All @@ -284,9 +284,9 @@ namespace netxs::ui
{
auto corner = item.corner(area.size);
auto side_x = item.hzgrip.shift(corner).normalize_itself()
.shift_itself(area.coor).clip(area);
.shift_itself(area.coor).trim(area);
auto side_y = item.vtgrip.shift(corner).normalize_itself()
.shift_itself(area.coor).clip(area);
.shift_itself(area.coor).trim(area);
canvas.fill(side_x, fuse);
canvas.fill(side_y, fuse);
});
Expand Down Expand Up @@ -879,7 +879,7 @@ namespace netxs::ui
if (state)
{
auto clip = canvas.core::clip();
if (auto area = clip.clip(body))
if (auto area = clip.trim(body))
{
auto& test = canvas.peek(body.coor);
if (test.wdt() == 2) // Extend cursor to adjacent halves.
Expand Down Expand Up @@ -3923,7 +3923,7 @@ namespace netxs::ui
auto& region_len = region.size[Axis];
auto& object_len = object.size[Axis];

handle = region.clip(handle);
handle.trimby(region);
handle_len = std::max(1, handle_len);

drawfx(*this, parent_canvas, handle, object_len, handle_len, region_len, wide);
Expand Down
192 changes: 75 additions & 117 deletions src/netxs/desktopio/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ namespace netxs
friend auto max(duplet const& p1, duplet const& p2) { return duplet{ std::max(p1.x, p2.x), std::max(p1.y, p2.y) }; }
friend auto round(duplet const& p) { return duplet{ std::round(p.x), std::round(p.y) }; }
friend auto abs(duplet const& p) { return duplet{ std::abs(p.x), std::abs(p.y) }; }
friend auto clamp(duplet const& p, duplet const& p1, duplet const& p2) { return duplet{ std::clamp(p.x, p1.x, p2.x), std::clamp(p.y, p1.y, p2.y) }; }
friend auto clamp(duplet const& p, duplet const& p1, duplet const& p2)
{
return duplet{ std::clamp(p.x, p1.x, p2.x),
std::clamp(p.y, p1.y, p2.y) };
}
static constexpr auto sort(duplet p1, duplet p2)
{
if (p1.x > p2.x) std::swap(p1.x, p2.x);
if (p1.y > p2.y) std::swap(p1.y, p2.y);
return std::pair{ p1, p2 };
}
};

// geometry: 2D point.
Expand Down Expand Up @@ -194,167 +204,115 @@ namespace netxs
twod coor;
twod size;

// rect: Intersect two rects.
template<bool Relative = faux>
constexpr rect clip(rect r) const
{
if constexpr (Relative) r.coor += coor;
auto apex = coor + size;
auto r_apex = r.coor + r.size;
r.coor = std::clamp(r.coor, coor, apex);
r.size = std::clamp(r_apex, coor, apex) - r.coor;
return r;
}
twod clip(twod point) const
{
return std::clamp(point, coor, coor + std::max(dot_00, size - dot_11));
}
bool operator == (rect const&) const = default;
explicit operator bool () const { return size.x != 0 && size.y != 0; }
auto center () const { return coor + size / 2; }
auto area () const { return size.x * size.y; }
twod map (twod p) const { return p - coor; }
rect shift (twod p) const { return { coor + p, size }; }
auto& shift_itself (twod p) { coor += p; return *this; }
rect operator & (rect r) const { return clip(r); }
rect operator | (rect r) const { return unite(r); }
rect operator | (rect r) const { return unite(r, *this); }
auto& operator += (rect r) { coor += r.coor; size += r.size; return *this; }
auto& operator -= (rect r) { coor -= r.coor; size -= r.size; return *this; }

// rect: Return rect trimmed by r.
template<bool Relative = faux>
constexpr rect trim(rect r) const
{
if constexpr (Relative) r.coor += coor;
auto r_apex = r.coor + r.size;
auto [min, max] = twod::sort(coor, coor + size);
r.coor = std::clamp(r.coor, min, max);
r.size = std::clamp(r_apex, min, max) - r.coor;
return r;
}
// rect: Trim by the specified rect.
template<bool Relative = faux>
constexpr auto& trimby(rect r)
{
if constexpr (Relative) coor += r.coor;
auto apex = coor + size;
auto [min, max] = twod::sort(r.coor, r.coor + r.size);
coor = std::clamp(coor, min, max);
size = std::clamp(apex, min, max) - coor;
return *this;
}
// rect: Return clamped point.
constexpr twod clamp(twod point) const
{
auto [min, max] = twod::sort(coor, coor + size);
return std::clamp(point, min, max - dot_11);
}
// rect: Is the point inside the rect.
bool hittest(twod p) const
constexpr bool hittest(twod p) const
{
auto test = faux;
if (size.x > 0)
{
auto t = p.x - coor.x;
test = t >= 0 && t < size.x;
}
else
{
auto t = p.x + coor.x;
test = t >= size.x && t < 0;
}
if (size.x > 0) { auto t = p.x - coor.x; test = t >= 0 && t < size.x; }
else { auto t = p.x + coor.x; test = t >= size.x && t < 0; }

if (test)
{
if (size.y > 0)
{
auto t = p.y - coor.y;
test = t >= 0 && t < size.y;
}
else
{
auto t = p.y + coor.y;
test = t >= size.y && t < 0;
}
return test;
if (size.y > 0) { auto t = p.y - coor.y; test = t >= 0 && t < size.y; }
else { auto t = p.y + coor.y; test = t >= size.y && t < 0; }
}
return faux;
return test;
}
rect rotate(twod dir) const
// rect: Return rect with specified orientation.
constexpr rect rotate(twod dir) const
{
auto r = rect{};
if ((dir.x ^ size.x) < 0)
{
r.coor.x = coor.x + size.x;
r.size.x = -size.x;
}
else
{
r.coor.x = coor.x;
r.size.x = size.x;
}

if ((dir.y ^ size.y) < 0)
{
r.coor.y = coor.y + size.y;
r.size.y = -size.y;
}
else
{
r.coor.y = coor.y;
r.size.y = size.y;
}
return r;
auto sx = (dir.x ^ size.x) < 0;
auto sy = (dir.y ^ size.y) < 0;
return {{ sx ? coor.x + size.x : coor.x, sy ? coor.y + size.y : coor.y },
{ sx ? -size.x : size.x, sy ? -size.y : size.y }};
}
rect normalize() const
// rect: Change orientation.
constexpr auto& rotate_itself(twod dir)
{
auto r = rect{};
if (size.x < 0)
{
r.coor.x = coor.x + size.x;
r.size.x = -size.x;
}
else
{
r.coor.x = coor.x;
r.size.x = size.x;
}

if (size.y < 0)
{
r.coor.y = coor.y + size.y;
r.size.y = -size.y;
}
else
{
r.coor.y = coor.y;
r.size.y = size.y;
}

return r;
if ((dir.x ^ size.x) < 0) { coor.x += size.x; size.x = -size.x; }
if ((dir.y ^ size.y) < 0) { coor.y += size.y; size.y = -size.y; }
return *this;
}
auto& normalize_itself()
// rect: Return rect with top-left orientation.
constexpr rect normalize() const
{
if (size.x < 0)
{
coor.x = coor.x + size.x;
size.x = -size.x;
}
else
{
coor.x = coor.x;
size.x = size.x;
}

if (size.y < 0)
{
coor.y = coor.y + size.y;
size.y = -size.y;
}
else
{
coor.y = coor.y;
size.y = size.y;
}
auto sx = size.x < 0;
auto sy = size.y < 0;
return {{ sx ? coor.x + size.x : coor.x, sy ? coor.y + size.y : coor.y },
{ sx ? -size.x : size.x , sy ? -size.y : size.y }};
}
// rect: Set top-left orientation.
constexpr auto& normalize_itself()
{
if (size.x < 0) { coor.x += size.x; size.x = -size.x; }
if (size.y < 0) { coor.y += size.y; size.y = -size.y; }
return *this;
}
// rect: Intersect the rect with rect{ dot_00, edge }.
rect trunc(twod edge) const
constexpr rect trunc(twod edge) const
{
auto r = rect{};
r.coor = std::clamp(coor, dot_00, edge);
r.size = std::clamp(size, -coor, edge - coor) + coor - r.coor;
return r;
}
// rect: Return circumscribed rect.
rect unite(rect annex) const
static constexpr rect unite(rect r1, rect r2)
{
auto r1 = annex.normalize();
auto r2 = normalize();
r1.normalize_itself();
r2.normalize_itself();
auto tl = std::min(r1.coor, r2.coor);
auto br = std::max(r1.coor + r1.size, r2.coor + r2.size );
return { tl, br - tl};
}
// rect: Return true in case of normalized rectangles are overlapped.
bool overlap(rect r) const
constexpr bool overlap(rect r) const
{
return coor.x < r.coor.x + r.size.x
&& coor.y < r.coor.y + r.size.y
&& coor.x + size.x > r.coor.x
&& coor.y + size.y > r.coor.y;
}
// rect: To string.
auto str() const
{
return "{" + coor.str() + ", " + size.str() + "}";
Expand Down
6 changes: 2 additions & 4 deletions src/netxs/desktopio/intmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,10 @@ namespace netxs
{
auto& rect1 = canvas.area();
auto& rect2 = bitmap.area();

if (auto joint = rect1.clip(rect2))
if (auto joint = rect1.trim(rect2))
{
auto basis = joint.coor - rect2.coor;
joint.coor-= rect1.coor;

inbody<faux>(canvas, bitmap, joint, basis, handle, online);
}
}
Expand All @@ -847,7 +845,7 @@ namespace netxs
void onrect(T& canvas, Rect const& region, P handle, NewlineFx online = {})
{
auto& place = canvas.area();
if (auto joint = region.clip(place))
if (auto joint = region.trim(place))
{
auto basis = joint.coor - place.coor;
auto frame = place.size.x * basis.y + basis.x + canvas.begin();
Expand Down
Loading

0 comments on commit db9aedb

Please sign in to comment.