Skip to content

Commit

Permalink
TransitionMod: replace WidgetMultiLines with single line
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen committed Apr 11, 2024
1 parent 8fc804f commit cd46621
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 106 deletions.
28 changes: 28 additions & 0 deletions src/gdi/draw_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
SPDX-FileCopyrightText: 2024 Wallix Proxies Team
SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "gdi/draw_utils.hpp"
#include "utils/sugar/numerics/safe_conversions.hpp"
#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"


void gdi_draw_border(
gdi::GraphicApi& drawable, RDPColor color,
int16_t x, int16_t y, uint16_t cx, uint16_t cy,
uint16_t border_width, Rect clip, gdi::ColorCtx color_ctx)
{
auto draw = [&](Rect rect){
drawable.draw(RDPOpaqueRect(rect, color), clip, color_ctx);
};

// top
draw(Rect(x, y, cx - border_width, border_width));
// left
draw(Rect(x, checked_int(y + border_width), border_width, cy - border_width));
// right
draw(Rect(checked_int(x + cx - border_width), y, border_width, cy));
// bottom
draw(Rect(x, checked_int(y + cy - border_width), cx - border_width, border_width));
}
23 changes: 23 additions & 0 deletions src/gdi/draw_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
SPDX-FileCopyrightText: 2024 Wallix Proxies Team
SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include "gdi/graphic_api.hpp"


void gdi_draw_border(
gdi::GraphicApi& drawable, RDPColor color,
int16_t x, int16_t y, uint16_t cx, uint16_t cy,
uint16_t border_width, Rect clip, gdi::ColorCtx color_ctx
);

inline void gdi_draw_border(
gdi::GraphicApi& drawable, RDPColor color,
Rect rect, uint16_t border_width, Rect clip, gdi::ColorCtx color_ctx
)
{
gdi_draw_border(drawable, color, rect.x, rect.y, rect.cx, rect.cy, border_width, clip, color_ctx);
}
1 change: 0 additions & 1 deletion src/gdi/screen_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "gdi/graphic_api.hpp"
#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"
#include "core/RDP/orders/RDPOrdersPrimaryPatBlt.hpp"
#include "utils/rect.hpp"

void gdi_clear_screen(gdi::GraphicApi& drawable, Dimension dim)
{
Expand Down
3 changes: 2 additions & 1 deletion src/gdi/screen_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

#pragma once

class Dimension;
#include "utils/rect.hpp"

namespace gdi
{
class GraphicApi;
Expand Down
52 changes: 42 additions & 10 deletions src/mod/internal/transition_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,60 @@
*/

#include "mod/internal/transition_mod.hpp"
#include "gdi/text_metrics.hpp"
#include "gdi/draw_utils.hpp"
#include "core/font.hpp"
#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"

TransitionMod::TransitionMod(
char const * message,
chars_view message,
gdi::GraphicApi & drawable,
uint16_t width, uint16_t height,
Rect const widget_rect, ClientExecute & rail_client_execute, Font const& font,
Theme const& theme
)
: RailInternalModBase(drawable, width, height, rail_client_execute, font, theme, nullptr)
, ttmessage(drawable, message, 4048,
theme.tooltip.fgcolor, theme.tooltip.bgcolor,
theme.tooltip.border_color, font)
, ttmessage(truncated_bounded_array_view(message))
, drawable(drawable)
, font(font)
, widget_rect(widget_rect)
, fgcolor(theme.tooltip.fgcolor)
, bgcolor(theme.tooltip.bgcolor)
, border_color(theme.tooltip.border_color)
{
Dimension dim = this->ttmessage.get_optimal_dim();
this->ttmessage.set_wh(dim);
this->ttmessage.set_xy(widget_rect.x + (widget_rect.cx - dim.w) / 2,
widget_rect.y + (widget_rect.cy - dim.h) / 2);
this->ttmessage.rdp_input_invalidate(this->ttmessage.get_rect());
this->set_mod_signal(BACK_EVENT_NONE);
this->rdp_input_invalidate(widget_rect);
}

TransitionMod::~TransitionMod() = default;
void TransitionMod::rdp_input_invalidate(Rect r)
{
Rect const clip = r.intersect(widget_rect);

if (!clip.isempty()) {
int padding = 20;
int width = gdi::TextMetrics(font, ttmessage.c_str()).width + padding * 2;
int height = this->font.max_height() + padding * 2;
int x = widget_rect.x + (widget_rect.cx - width) / 2;
int y = widget_rect.y + (widget_rect.cy - height) / 2;

auto color_ctx = gdi::ColorCtx::depth24();
encode_color24 encode;

Rect area(x, y, width, height);

drawable.draw(
RDPOpaqueRect(area, encode(bgcolor)),
clip, gdi::ColorCtx::depth24()
);
gdi::server_draw_text(
drawable, font,
x + padding, y + padding,
ttmessage.c_str(), encode(fgcolor), encode(bgcolor),
color_ctx, clip
);
gdi_draw_border(drawable, encode(border_color), area, 1, clip, color_ctx);
}
}

void TransitionMod::rdp_input_scancode(
KbdFlags flags, Scancode scancode, uint32_t event_time, Keymap const& keymap)
Expand Down
16 changes: 11 additions & 5 deletions src/mod/internal/transition_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,32 @@

#pragma once

#include "mod/internal/widget/tooltip.hpp"
#include "mod/internal/rail_mod_base.hpp"
#include "utils/static_string.hpp"

class TransitionMod : public RailInternalModBase
{
public:
TransitionMod(
char const * message,
chars_view message,
gdi::GraphicApi & drawable,
uint16_t width, uint16_t height,
Rect const widget_rect, ClientExecute & rail_client_execute, Font const& font,
Theme const& theme
);

~TransitionMod() override;

void rdp_input_scancode(KbdFlags flags, Scancode scancode, uint32_t event_time, Keymap const& keymap) override;

void rdp_input_invalidate(Rect r) override;

void acl_update(AclFieldMask const&/* acl_fields*/) override {}

private:
WidgetTooltip ttmessage;
static_string<127> ttmessage;
gdi::GraphicApi & drawable;
Font const& font;
Rect widget_rect;
BGRColor fgcolor;
BGRColor bgcolor;
BGRColor border_color;
};
19 changes: 2 additions & 17 deletions src/mod/internal/widget/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "mod/internal/widget/button.hpp"
#include "mod/internal/widget/label.hpp"
#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"
#include "gdi/graphic_api.hpp"
#include "gdi/draw_utils.hpp"
#include "utils/sugar/cast.hpp"
#include "utils/utf.hpp"
#include "keyboard/keymap.hpp"
Expand Down Expand Up @@ -139,22 +139,7 @@ void WidgetButton::draw(

// border
if (border_width) {
//top
drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
rect.x, rect.y, rect.cx - border_width, border_width
)), fg_color), rect, color_ctx);
//left
drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
rect.x, rect.y + border_width, border_width, rect.cy - border_width
)), fg_color), rect, color_ctx);
//right
drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
rect.x + rect.cx - border_width, rect.y, border_width, rect.cy
)), fg_color), rect, color_ctx);
//bottom
drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
rect.x, rect.y + rect.cy - border_width, rect.cx, border_width
)), fg_color), rect, color_ctx);
gdi_draw_border(drawable, fg_color, rect, border_width, clip, color_ctx);
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/mod/internal/widget/delegated_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"
#include "core/font.hpp"
#include "mod/internal/widget/delegated_copy.hpp"
#include "gdi/graphic_api.hpp"
#include "gdi/draw_utils.hpp"
#include "gdi/text_metrics.hpp"
#include "utils/sugar/cast.hpp"
#include "utils/utf.hpp"
Expand Down Expand Up @@ -73,14 +73,7 @@ void WidgetDelegatedCopy::draw(
rect.cx -= xicon * 2;
rect.cy -= yicon * 2;

// left
drawRect(rect.x, rect.y + 1, 1, rect.cy - 1);
// right
drawRect(rect.eright() - 1, rect.y + 1, 1, rect.cy - 1);
// top
drawRect(rect.x, rect.y + 1, rect.cx, 1);
// bottom
drawRect(rect.x, rect.ebottom() - 1, rect.cx, 1);
gdi_draw_border(drawable, fg, rect.x, rect.y + 1, rect.cx, rect.cy - 1, 1, clip, color_ctx);

// clip
const int16_t d = ((rect.cx - 2) / 4) + /* border=*/1;
Expand Down
19 changes: 2 additions & 17 deletions src/mod/internal/widget/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"
#include "core/font.hpp"
#include "gdi/graphic_api.hpp"
#include "gdi/draw_utils.hpp"
#include "gdi/text_metrics.hpp"
#include "keyboard/keymap.hpp"
#include "mod/internal/widget/edit.hpp"
Expand Down Expand Up @@ -191,22 +191,7 @@ void WidgetEdit::rdp_input_invalidate(Rect clip)

void WidgetEdit::draw_border(Rect clip, Color color)
{
//top
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y(), this->cx() - 1, 1
)), color), clip, gdi::ColorCtx::depth24());
//left
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y() + 1, 1, this->cy() - 2
)), color), clip, gdi::ColorCtx::depth24());
//right
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x() + this->cx() - 1, this->y(), 1, this->cy()
)), color), clip, gdi::ColorCtx::depth24());
//bottom
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y() + this->cy() - 1, this->cx(), 1
)), color), clip, gdi::ColorCtx::depth24());
gdi_draw_border(drawable, color, get_rect(), 1, clip, gdi::ColorCtx::depth24());
}

Rect WidgetEdit::get_cursor_rect() const
Expand Down
19 changes: 2 additions & 17 deletions src/mod/internal/widget/edit_valid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "mod/internal/widget/edit.hpp"
#include "mod/internal/widget/button.hpp"
#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"
#include "gdi/graphic_api.hpp"
#include "gdi/draw_utils.hpp"

namespace
{
Expand Down Expand Up @@ -189,22 +189,7 @@ void WidgetEditValid::rdp_input_invalidate(Rect clip)

void WidgetEditValid::draw_border(const Rect clip, Color color)
{
//top
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y(), this->cx() - 1, 1
)), color), clip, gdi::ColorCtx::depth24());
//left
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y() + 1, 1, this->cy() - /*2*/1
)), color), clip, gdi::ColorCtx::depth24());
//right
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x() + this->cx() - 1, this->y(), 1, this->cy()
)), color), clip, gdi::ColorCtx::depth24());
//bottom
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y() + this->cy() - 1, this->cx(), 1
)), color), clip, gdi::ColorCtx::depth24());
gdi_draw_border(drawable, color, get_rect(), 1, clip, gdi::ColorCtx::depth24());
}

void WidgetEditValid::focus(int reason)
Expand Down
28 changes: 6 additions & 22 deletions src/mod/internal/widget/tooltip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "mod/internal/widget/tooltip.hpp"
#include "core/RDP/orders/RDPOrdersPrimaryOpaqueRect.hpp"
#include "gdi/graphic_api.hpp"
#include "gdi/draw_utils.hpp"

WidgetTooltip::WidgetTooltip(
gdi::GraphicApi & drawable, const char * text, unsigned max_width,
Expand Down Expand Up @@ -72,7 +72,11 @@ void WidgetTooltip::rdp_input_invalidate(Rect clip)
RDPOpaqueRect(this->get_rect(), this->desc.get_bg_color()),
rect_intersect, gdi::ColorCtx::depth24());
this->desc.rdp_input_invalidate(rect_intersect);
this->draw_border(rect_intersect);

gdi_draw_border(
drawable, this->border_color, this->get_rect(), 1,
rect_intersect, gdi::ColorCtx::depth24()
);
}
}

Expand All @@ -87,23 +91,3 @@ void WidgetTooltip::set_wh(uint16_t w, uint16_t h)
Widget::set_wh(w, h);
this->desc.set_wh(w - 2 * w_border, h - 2 * h_border);
}

void WidgetTooltip::draw_border(const Rect clip)
{
//top
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y(), this->cx() - 1, 1
)), this->border_color), clip, gdi::ColorCtx::depth24());
//left
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y() + 1, 1, this->cy() - 2
)), this->border_color), clip, gdi::ColorCtx::depth24());
//right
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x() + this->cx() - 1, this->y(), 1, this->cy()
)), this->border_color), clip, gdi::ColorCtx::depth24());
//bottom
this->drawable.draw(RDPOpaqueRect(clip.intersect(Rect(
this->x(), this->y() + this->cy() - 1, this->cx() - 1, 1
)), this->border_color), clip, gdi::ColorCtx::depth24());
}
2 changes: 0 additions & 2 deletions src/mod/internal/widget/tooltip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class WidgetTooltip : public Widget

using Widget::set_wh;

void draw_border(const Rect clip);

private:
uint w_border;
uint h_border;
Expand Down
Loading

0 comments on commit cd46621

Please sign in to comment.