From 95f4e0ee00f7b500bb753d9ec1af65d36213d4f3 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 29 Apr 2023 09:19:03 +0300 Subject: [PATCH 37/37] gtk4: Implement selection rectangle drawing See osdn #47814 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/canvas.c | 10 ++++++++++ client/gui-gtk-4.0/canvas.c | 10 ++++++++++ client/gui-gtk-4.0/mapview.c | 25 ++++++++----------------- client/include/canvas_g.h | 8 ++++---- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/client/gui-gtk-3.22/canvas.c b/client/gui-gtk-3.22/canvas.c index a6aee763f6..e8f01afe4b 100644 --- a/client/gui-gtk-3.22/canvas.c +++ b/client/gui-gtk-3.22/canvas.c @@ -252,6 +252,11 @@ void canvas_put_line(struct canvas *pcanvas, case LINE_GOTO: cairo_set_line_width(cr, 2.); break; + case LINE_SELECT_RECT: + cairo_set_line_width(cr, 2.); + cairo_set_dash(cr, dashes, 2, 0); + cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); + break; } gdk_cairo_set_source_rgba(cr, &pcolor->color); @@ -304,6 +309,11 @@ void canvas_put_curved_line(struct canvas *pcanvas, case LINE_GOTO: cairo_set_line_width(cr, 2.); break; + case LINE_SELECT_RECT: + cairo_set_line_width(cr, 2.); + cairo_set_dash(cr, dashes, 2, 0); + cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); + break; } gdk_cairo_set_source_rgba(cr, &pcolor->color); diff --git a/client/gui-gtk-4.0/canvas.c b/client/gui-gtk-4.0/canvas.c index 55ff70deaf..e6af6d0a81 100644 --- a/client/gui-gtk-4.0/canvas.c +++ b/client/gui-gtk-4.0/canvas.c @@ -252,6 +252,11 @@ void canvas_put_line(struct canvas *pcanvas, case LINE_GOTO: cairo_set_line_width(cr, 2.); break; + case LINE_SELECT_RECT: + cairo_set_line_width(cr, 2.); + cairo_set_dash(cr, dashes, 2, 0); + cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); + break; } gdk_cairo_set_source_rgba(cr, &pcolor->color); @@ -304,6 +309,11 @@ void canvas_put_curved_line(struct canvas *pcanvas, case LINE_GOTO: cairo_set_line_width(cr, 2.); break; + case LINE_SELECT_RECT: + cairo_set_line_width(cr, 2.); + cairo_set_dash(cr, dashes, 2, 0); + cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); + break; } gdk_cairo_set_source_rgba(cr, &pcolor->color); diff --git a/client/gui-gtk-4.0/mapview.c b/client/gui-gtk-4.0/mapview.c index 0cd6d37378..78eb074d6e 100644 --- a/client/gui-gtk-4.0/mapview.c +++ b/client/gui-gtk-4.0/mapview.c @@ -722,12 +722,7 @@ void scrollbar_jump_callback(GtkAdjustment *adj, gpointer hscrollbar) **************************************************************************/ void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h) { -#if 0 - double dashes[2] = {4.0, 4.0}; struct color *pcolor; - cairo_t *cr; - GdkDrawingContext *ctx; - GdkSurface *wndw; if (w == 0 || h == 0) { return; @@ -738,18 +733,14 @@ void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h) return; } - wndw = gtk_native_get_surface(gtk_widget_get_native(map_canvas)); - ctx = gdk_window_begin_draw_frame(wndw, NULL, - gdk_window_get_clip_region(wndw)); - cr = gdk_drawing_context_get_cairo_context(ctx); - gdk_cairo_set_source_rgba(cr, &pcolor->color); - cairo_set_line_width(cr, 2.0); - cairo_set_dash(cr, dashes, 2, 0); - cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); - cairo_rectangle(cr, canvas_x, canvas_y, w, h); - cairo_stroke(cr); - gdk_window_end_draw_frame(wndw, ctx); -#endif + canvas_put_line(mapview.store, pcolor, LINE_SELECT_RECT, + canvas_x, canvas_y, w, 0); + canvas_put_line(mapview.store, pcolor, LINE_SELECT_RECT, + canvas_x, canvas_y, 0, h); + canvas_put_line(mapview.store, pcolor, LINE_SELECT_RECT, + canvas_x, canvas_y + h, w, 0); + canvas_put_line(mapview.store, pcolor, LINE_SELECT_RECT, + canvas_x + w, canvas_y, 0, h); } /**********************************************************************//** diff --git a/client/include/canvas_g.h b/client/include/canvas_g.h index be6bc1152a..0ecf2f68cb 100644 --- a/client/include/canvas_g.h +++ b/client/include/canvas_g.h @@ -20,10 +20,10 @@ struct color; struct sprite; -struct canvas; /* opaque type, real type is gui-dep */ +struct canvas; /* Opaque type, real type is gui-dep */ enum line_type { - LINE_NORMAL, LINE_BORDER, LINE_TILE_FRAME, LINE_GOTO + LINE_NORMAL, LINE_BORDER, LINE_TILE_FRAME, LINE_GOTO, LINE_SELECT_RECT }; /* Creator and destructor */ @@ -42,7 +42,7 @@ GUI_FUNC_PROTO(void, canvas_copy, struct canvas *dest, struct canvas *src, GUI_FUNC_PROTO(void, canvas_put_sprite, struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *sprite, int offset_x, int offset_y, int width, int height); -GUI_FUNC_PROTO(void, canvas_put_sprite_full, struct canvas *pcanvas, +GUI_FUNC_PROTO(void, canvas_put_sprite_full, struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *sprite) GUI_FUNC_PROTO(void, canvas_put_sprite_fogged, struct canvas *pcanvas, @@ -78,4 +78,4 @@ GUI_FUNC_PROTO(void, canvas_put_text, struct canvas *pcanvas, int canvas_x, int canvas_y, enum client_font font, struct color *pcolor, const char *text) -#endif /* FC__CANVAS_G_H */ +#endif /* FC__CANVAS_G_H */ -- 2.39.2