From 66493421e65d8cbda3e17fdbe43824387e3d51a7 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 23 May 2018 13:04:19 +0100 Subject: Plotters: Change stroke width in the plot_style_t to fixed point. --- frontends/amiga/dt_sound.c | 2 +- frontends/amiga/plotters.c | 8 ++++---- frontends/amiga/plugin_hack.c | 2 +- frontends/atari/plot/plot.c | 6 +++--- frontends/beos/plotters.cpp | 4 ++-- frontends/framebuffer/framebuffer.c | 6 ++++-- frontends/gtk/plotters.c | 29 +++++++++++++++++------------ frontends/gtk/print.c | 30 ++++++++++++++---------------- frontends/riscos/plotters.c | 14 +++++++------- frontends/riscos/save_draw.c | 4 ++-- frontends/windows/plot.c | 8 ++++++-- 11 files changed, 61 insertions(+), 52 deletions(-) (limited to 'frontends') diff --git a/frontends/amiga/dt_sound.c b/frontends/amiga/dt_sound.c index ae313bb51..f3b365ddb 100644 --- a/frontends/amiga/dt_sound.c +++ b/frontends/amiga/dt_sound.c @@ -195,7 +195,7 @@ bool amiga_dt_sound_redraw(struct content *c, .fill_type = PLOT_OP_TYPE_SOLID, .fill_colour = 0xffffff, .stroke_colour = 0x000000, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; struct rect rect; diff --git a/frontends/amiga/plotters.c b/frontends/amiga/plotters.c index b8485430f..58dc90503 100644 --- a/frontends/amiga/plotters.c +++ b/frontends/amiga/plotters.c @@ -722,8 +722,8 @@ ami_line(const struct redraw_context *ctx, struct gui_globals *glob = (struct gui_globals *)ctx->priv; - glob->rp->PenWidth = style->stroke_width; - glob->rp->PenHeight = style->stroke_width; + glob->rp->PenWidth = plot_style_fixed_to_int(style->stroke_width); + glob->rp->PenHeight = plot_style_fixed_to_int(style->stroke_width); switch (style->stroke_type) { case PLOT_OP_TYPE_SOLID: /**< Solid colour */ @@ -780,8 +780,8 @@ ami_rectangle(const struct redraw_context *ctx, } if (style->stroke_type != PLOT_OP_TYPE_NONE) { - glob->rp->PenWidth = style->stroke_width; - glob->rp->PenHeight = style->stroke_width; + glob->rp->PenWidth = plot_style_fixed_to_int(style->stroke_width); + glob->rp->PenHeight = plot_style_fixed_to_int(style->stroke_width); switch (style->stroke_type) { case PLOT_OP_TYPE_SOLID: /**< Solid colour */ diff --git a/frontends/amiga/plugin_hack.c b/frontends/amiga/plugin_hack.c index 4fd1f03f7..5d7ec19c1 100644 --- a/frontends/amiga/plugin_hack.c +++ b/frontends/amiga/plugin_hack.c @@ -151,7 +151,7 @@ bool amiga_plugin_hack_redraw(struct content *c, .fill_type = PLOT_OP_TYPE_SOLID, .fill_colour = 0xffffff, .stroke_colour = 0x000000, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; struct rect rect; nserror res; diff --git a/frontends/atari/plot/plot.c b/frontends/atari/plot/plot.c index 14c670352..5f69f2af5 100644 --- a/frontends/atari/plot/plot.c +++ b/frontends/atari/plot/plot.c @@ -2124,7 +2124,7 @@ plot_line(const struct redraw_context *ctx, { short pxy[4]; uint32_t lt; - int sw = pstyle->stroke_width; + int sw = plot_style_fixed_to_int(pstyle->stroke_width); if (((line->x0 < 0) && (line->x1 < 0)) || ((line->y0 < 0) && (line->y1 < 0))) { @@ -2183,7 +2183,7 @@ plot_rectangle(const struct redraw_context *ctx, { short pxy[4]; GRECT r, rclip, sclip; - int sw = pstyle->stroke_width; + int sw = plot_style_fixed_to_int(pstyle->stroke_width); uint32_t lt; /* current canvas clip: */ @@ -2266,7 +2266,7 @@ plot_rectangle(const struct redraw_context *ctx, if (pstyle->fill_type != PLOT_OP_TYPE_NONE ) { short stroke_width = (short)(pstyle->stroke_type != PLOT_OP_TYPE_NONE) ? - pstyle->stroke_width : 0; + plot_style_fixed_to_int(pstyle->stroke_width) : 0; vsf_rgbcolor(atari_plot_vdi_handle, pstyle->fill_colour); vsf_perimeter(atari_plot_vdi_handle, 0); diff --git a/frontends/beos/plotters.cpp b/frontends/beos/plotters.cpp index c4903e045..a0a70f5b7 100644 --- a/frontends/beos/plotters.cpp +++ b/frontends/beos/plotters.cpp @@ -370,7 +370,7 @@ nsbeos_plot_line(const struct redraw_context *ctx, nsbeos_set_colour(style->stroke_colour); float pensize = view->PenSize(); - view->SetPenSize(style->stroke_width); + view->SetPenSize(plot_style_fixed_to_float(style->stroke_width)); BPoint start(line->x0, line->y0); BPoint end(line->x1, line->y1); @@ -447,7 +447,7 @@ nsbeos_plot_rectangle(const struct redraw_context *ctx, nsbeos_set_colour(style->stroke_colour); float pensize = view->PenSize(); - view->SetPenSize(style->stroke_width); + view->SetPenSize(plot_style_fixed_to_float(style->stroke_width)); BRect rect(nsrect->x0, nsrect->y0, nsrect->x1, nsrect->y1); view->StrokeRect(rect, pat); diff --git a/frontends/framebuffer/framebuffer.c b/frontends/framebuffer/framebuffer.c index 2ccc75062..5a2603535 100644 --- a/frontends/framebuffer/framebuffer.c +++ b/frontends/framebuffer/framebuffer.c @@ -168,7 +168,7 @@ framebuffer_plot_line(const struct redraw_context *ctx, } pen.stroke_colour = style->stroke_colour; - pen.stroke_width = style->stroke_width; + pen.stroke_width = plot_style_fixed_to_int(style->stroke_width); nsfb_plot_line(nsfb, &rect, &pen); } @@ -216,7 +216,9 @@ framebuffer_plot_rectangle(const struct redraw_context *ctx, dashed = true; } - nsfb_plot_rectangle(nsfb, &rect, style->stroke_width, style->stroke_colour, dotted, dashed); + nsfb_plot_rectangle(nsfb, &rect, + plot_style_fixed_to_int(style->stroke_width), + style->stroke_colour, dotted, dashed); } return NSERROR_OK; } diff --git a/frontends/gtk/plotters.c b/frontends/gtk/plotters.c index 88e7760c6..6178104d5 100644 --- a/frontends/gtk/plotters.c +++ b/frontends/gtk/plotters.c @@ -88,6 +88,20 @@ static inline void nsgtk_set_dashed(void) } +/** + * Set cairo context line width. + */ +static inline void nsgtk_set_line_width(plot_style_fixed width) +{ + if (width == 0) { + cairo_set_line_width(current_cr, 1); + } else { + cairo_set_line_width(current_cr, + plot_style_fixed_to_double(width)); + } +} + + /** * \brief Sets a clip rectangle for subsequent plot operations. * @@ -191,10 +205,7 @@ nsgtk_plot_disc(const struct redraw_context *ctx, break; } - if (style->stroke_width == 0) - cairo_set_line_width(current_cr, 1); - else - cairo_set_line_width(current_cr, style->stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_arc(current_cr, x, y, radius, 0, M_PI * 2); @@ -242,10 +253,7 @@ nsgtk_plot_line(const struct redraw_context *ctx, nsgtk_set_colour(style->stroke_colour); } - if (style->stroke_width == 0) - cairo_set_line_width(current_cr, 1); - else - cairo_set_line_width(current_cr, style->stroke_width); + nsgtk_set_line_width(style->stroke_width); /* core expects horizontal and vertical lines to be on pixels, not * between pixels @@ -331,10 +339,7 @@ nsgtk_plot_rectangle(const struct redraw_context *ctx, break; } - if (style->stroke_width == 0) - cairo_set_line_width(current_cr, 1); - else - cairo_set_line_width(current_cr, style->stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_rectangle(current_cr, rect->x0 + 0.5, diff --git a/frontends/gtk/print.c b/frontends/gtk/print.c index 8f71230a6..f447a463e 100644 --- a/frontends/gtk/print.c +++ b/frontends/gtk/print.c @@ -133,6 +133,17 @@ static inline void nsgtk_print_set_dashed(void) cairo_set_dash(gtk_print_current_cr, cdashes, 1, 0); } +/** Set cairo context line width. */ +static inline void nsgtk_set_line_width(plot_style_fixed width) +{ + if (width == 0) { + cairo_set_line_width(gtk_print_current_cr, 1); + } else { + cairo_set_line_width(gtk_print_current_cr, + plot_style_fixed_to_double(width)); + } +} + /** * \brief Sets a clip rectangle for subsequent plot operations. @@ -248,10 +259,7 @@ nsgtk_print_plot_disc(const struct redraw_context *ctx, break; } - if (style->stroke_width == 0) - cairo_set_line_width(gtk_print_current_cr, 1); - else - cairo_set_line_width(gtk_print_current_cr, style->stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_arc(gtk_print_current_cr, x, y, radius, 0, M_PI * 2); @@ -294,10 +302,7 @@ nsgtk_print_plot_line(const struct redraw_context *ctx, break; } - if (style->stroke_width == 0) - cairo_set_line_width(gtk_print_current_cr, 1); - else - cairo_set_line_width(gtk_print_current_cr, style->stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_move_to(gtk_print_current_cr, line->x0 + 0.5, line->y0 + 0.5); cairo_line_to(gtk_print_current_cr, line->x1 + 0.5, line->y1 + 0.5); @@ -350,13 +355,6 @@ nsgtk_print_plot_rectangle(const struct redraw_context *ctx, } if (style->stroke_type != PLOT_OP_TYPE_NONE) { - int stroke_width; - - /* ensure minimum stroke width */ - stroke_width = style->stroke_width; - if (stroke_width == 0) { - stroke_width = 1; - } nsgtk_print_set_colour(style->stroke_colour); @@ -375,7 +373,7 @@ nsgtk_print_plot_rectangle(const struct redraw_context *ctx, break; } - cairo_set_line_width(gtk_print_current_cr, stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_rectangle(gtk_print_current_cr, rect->x0, rect->y0, diff --git a/frontends/riscos/plotters.c b/frontends/riscos/plotters.c index 2fbd12aeb..286ddab1b 100644 --- a/frontends/riscos/plotters.c +++ b/frontends/riscos/plotters.c @@ -324,9 +324,9 @@ ro_plot_line(const struct redraw_context *ctx, dashed = true; return ro_plot_draw_path((const draw_path *)path, - style->stroke_width, - style->stroke_colour, - dotted, dashed); + plot_style_fixed_to_int(style->stroke_width), + style->stroke_colour, + dotted, dashed); } return NSERROR_OK; } @@ -412,10 +412,10 @@ ro_plot_rectangle(const struct redraw_context *ctx, dashed = true; ro_plot_draw_path((const draw_path *)path, - style->stroke_width, - style->stroke_colour, - dotted, - dashed); + plot_style_fixed_to_int(style->stroke_width), + style->stroke_colour, + dotted, + dashed); } return NSERROR_OK; diff --git a/frontends/riscos/save_draw.c b/frontends/riscos/save_draw.c index 9ee730434..41764d927 100644 --- a/frontends/riscos/save_draw.c +++ b/frontends/riscos/save_draw.c @@ -168,7 +168,7 @@ ro_save_draw_line(const struct redraw_context *ctx, sizeof path / sizeof path[0], pencil_TRANSPARENT, style->stroke_colour << 8, - style->stroke_width, + plot_style_fixed_to_int(style->stroke_width), pencil_JOIN_MITRED, pencil_CAP_BUTT, pencil_CAP_BUTT, @@ -235,7 +235,7 @@ ro_save_draw_rectangle(const struct redraw_context *ctx, sizeof path / sizeof path[0], pencil_TRANSPARENT, style->stroke_colour << 8, - style->stroke_width, + plot_style_fixed_to_int(style->stroke_width), pencil_JOIN_MITRED, pencil_CAP_BUTT, pencil_CAP_BUTT, diff --git a/frontends/windows/plot.c b/frontends/windows/plot.c index 3668e4bb6..60b175a6b 100644 --- a/frontends/windows/plot.c +++ b/frontends/windows/plot.c @@ -601,7 +601,9 @@ line(const struct redraw_context *ctx, (style->stroke_type == PLOT_OP_TYPE_DASH) ? PS_DASH: 0); LOGBRUSH lb = {BS_SOLID, col, 0}; - HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); + HPEN pen = ExtCreatePen(penstyle, + plot_style_fixed_to_int(style->stroke_width), + &lb, 0, NULL); if (pen == NULL) { DeleteObject(clipregion); return NSERROR_INVALID; @@ -672,7 +674,9 @@ rectangle(const struct redraw_context *ctx, if (style->fill_type == PLOT_OP_TYPE_NONE) lb1.lbStyle = BS_HOLLOW; - HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); + HPEN pen = ExtCreatePen(penstyle, + plot_style_fixed_to_int(style->stroke_width), + &lb, 0, NULL); if (pen == NULL) { return NSERROR_INVALID; } -- cgit v1.2.3