From c9f51868e286689890337ec03cc2f657443e0f5e Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Thu, 28 Apr 2016 15:50:04 +0200 Subject: [PATCH] add x_draw_clipped_string and use it in the text_list gui --- common/utils/T/tracer/gui/text_list.c | 6 ++++-- common/utils/T/tracer/gui/x.c | 12 ++++++++++++ common/utils/T/tracer/gui/x.h | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/utils/T/tracer/gui/text_list.c b/common/utils/T/tracer/gui/text_list.c index 59de2809d..bd664bdb6 100644 --- a/common/utils/T/tracer/gui/text_list.c +++ b/common/utils/T/tracer/gui/text_list.c @@ -16,10 +16,12 @@ printf("PAINT text_list %p xywh %d %d %d %d\n", _this, this->common.x, this->com this->common.width, this->common.height); for (i = 0, j = this->starting_line; i < this->allocated_nlines && j < this->text_count; i++, j++) - x_draw_string(g->x, g->xwin, FOREGROUND_COLOR, + x_draw_clipped_string(g->x, g->xwin, FOREGROUND_COLOR, this->common.x, this->common.y + i * this->line_height + this->baseline, - this->text[j]); + this->text[j], + this->common.x, this->common.y, + this->common.width, this->common.height); } static void hints(gui *_gui, widget *_w, int *width, int *height) diff --git a/common/utils/T/tracer/gui/x.c b/common/utils/T/tracer/gui/x.c index e68e3bcb9..d739cc9b4 100644 --- a/common/utils/T/tracer/gui/x.c +++ b/common/utils/T/tracer/gui/x.c @@ -279,6 +279,18 @@ void x_draw_string(x_connection *_c, x_window *_w, int color, XDrawString(c->d, w->p, c->colors[color], x, y, t, tlen); } +void x_draw_clipped_string(x_connection *_c, x_window *_w, int color, + int x, int y, const char *t, + int clipx, int clipy, int clipwidth, int clipheight) +{ + struct x_connection *c = _c; + + XRectangle clip = { clipx, clipy, clipwidth, clipheight }; + XSetClipRectangles(c->d, c->colors[color], 0, 0, &clip, 1, Unsorted); + x_draw_string(_c, _w, color, x, y, t); + XSetClipMask(c->d, c->colors[color], None); +} + void x_draw(x_connection *_c, x_window *_w) { struct x_connection *c = _c; diff --git a/common/utils/T/tracer/gui/x.h b/common/utils/T/tracer/gui/x.h index e8f1d42d1..165785923 100644 --- a/common/utils/T/tracer/gui/x.h +++ b/common/utils/T/tracer/gui/x.h @@ -41,6 +41,10 @@ void x_fill_rectangle(x_connection *c, x_window *w, int color, void x_draw_string(x_connection *_c, x_window *_w, int color, int x, int y, const char *t); +void x_draw_clipped_string(x_connection *_c, x_window *_w, int color, + int x, int y, const char *t, + int clipx, int clipy, int clipwidth, int clipheight); + /* specials functions to plot many points * you call several times x_add_point() then x_plot_points() */ -- GitLab