From 388ce7b8c46ae20b97f891605f014db7fcb2fc6f Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Tue, 21 Mar 2006 17:22:41 +0000 Subject: [project @ 2006-03-21 17:22:41 by rjek] Radio and checkbox widgets are now 3D, and implemented arc plotting for them svn path=/import/netsurf/; revision=2145 --- desktop/plotters.h | 2 ++ gtk/gtk_plotters.c | 21 ++++++++++++++++++- render/html_redraw.c | 58 +++++++++++++++++++++++++++++++++++++++------------- riscos/plotters.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ riscos/save_draw.c | 8 ++++++++ 5 files changed, 125 insertions(+), 15 deletions(-) diff --git a/desktop/plotters.h b/desktop/plotters.h index f191654e5..65abd1774 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -32,6 +32,8 @@ struct plotter_table { bool (*text)(int x, int y, struct css_style *style, const char *text, size_t length, colour bg, colour c); bool (*disc)(int x, int y, int radius, colour c, bool filled); + bool (*arc)(int x, int y, int radius, int angle1, int angle2, + colour c); bool (*bitmap)(int x, int y, int width, int height, struct bitmap *bitmap, colour bg); bool (*bitmap_tile)(int x, int y, int width, int height, diff --git a/gtk/gtk_plotters.c b/gtk/gtk_plotters.c index 911cd2135..8da2d3c51 100644 --- a/gtk/gtk_plotters.c +++ b/gtk/gtk_plotters.c @@ -31,6 +31,8 @@ static bool nsgtk_plot_clip(int clip_x0, int clip_y0, static bool nsgtk_plot_text(int x, int y, struct css_style *style, const char *text, size_t length, colour bg, colour c); static bool nsgtk_plot_disc(int x, int y, int radius, colour c, bool filled); +static bool nsgtk_plot_arc(int x, int y, int radius, int angle1, int angle2, + colour c); static bool nsgtk_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg); static bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height, @@ -53,6 +55,7 @@ const struct plotter_table nsgtk_plotters = { nsgtk_plot_clip, nsgtk_plot_text, nsgtk_plot_disc, + nsgtk_plot_arc, nsgtk_plot_bitmap, nsgtk_plot_bitmap_tile, nsgtk_plot_group_start, @@ -65,7 +68,6 @@ bool nsgtk_plot_clg(colour c) return true; } - bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, int line_width, colour c, bool dotted, bool dashed) { @@ -197,6 +199,23 @@ bool nsgtk_plot_disc(int x, int y, int radius, colour c, bool filled) return true; } +bool nsgtk_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c) +{ + nsgtk_set_colour(c); +#ifdef CAIRO_VERSION + cairo_set_line_width(current_cr, 1); + cairo_arc(current_cr, x, y, radius, + (angle1 + 90) * (M_PI / 180), + (angle2 + 90) * (M_PI / 180)); + cairo_stroke(current_cr); +#else + gdk_draw_arc(current_drawable, current_gc, + FALSE, x - (radius), y - radius, + radius * 2, radius * 2, + angle1 * 64, angle2 * 64); +#endif + return true; +} bool nsgtk_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg) diff --git a/render/html_redraw.c b/render/html_redraw.c index 19bec517b..acecd2d25 100644 --- a/render/html_redraw.c +++ b/render/html_redraw.c @@ -893,21 +893,38 @@ colour html_redraw_aa(colour c0, colour c1) * \return true if successful, false otherwise */ +#define WIDGET_BASEC 0xd9d9d9 +#define WIDGET_BLOBC 0x0000ff bool html_redraw_checkbox(int x, int y, int width, int height, bool selected) { + int dark = html_redraw_darker(html_redraw_darker(WIDGET_BASEC)); + int lite = html_redraw_lighter(html_redraw_lighter(WIDGET_BASEC)); + int z = width * 0.15; if (z == 0) z = 1; - if (!plot.fill(x, y, x + width, y + height, 0x000000)) - return false; - if (!plot.fill(x + z, y + z, x + width - z, y + height - z, 0xffffff)) + + if !((plot.fill(x, y, x + width, y + height, WIDGET_BASEC) && + plot.line(x, y, x + width, y, 1, dark, false, false) && + plot.line(x, y, x, y + height, 1, dark, false, false) && + plot.line(x + width, y, x + width, y + height, 1, lite, + false, false) && + plot.line(x, y + height, x + width, y + height, 1, lite, + false, false))) return false; - if (selected) - if (!plot.fill(x + z + z, y + z + z, - x + width - z - z, y + height - z - z, - 0x0000ff)) + + if (selected) { + if (!plot.line(x + z + z, y + z + z, + x + width - z - z, y + height - z - z, + 2, WIDGET_BLOBC, false, false)) + return false; + + if (!plot.line(x - z - z + width, y + z + z, + x + z + z, y + height - z - z, + 2, WIDGET_BLOBC, false, false)) return false; + } return true; } @@ -923,20 +940,33 @@ bool html_redraw_checkbox(int x, int y, int width, int height, * \param selected the radio icon is selected * \return true if successful, false otherwise */ - bool html_redraw_radio(int x, int y, int width, int height, bool selected) { - if (!plot.disc(x + width * 0.5, y + height * 0.5, - width * 0.5 - 1, 0xffffff, true)) + int dark = html_redraw_darker(html_redraw_darker(WIDGET_BASEC)); + int lite = html_redraw_lighter(html_redraw_lighter(WIDGET_BASEC)); + + /* plot background of radio button */ + if (!plot.disc(x + width * 0.5, y + height * 0.5, + width * 0.5 - 1, WIDGET_BASEC, true)) + return false; + + /* plot dark arc */ + if (!plot.arc(x + width * 0.5, y + height * 0.5, + width * 0.5 - 1, 45, 225, dark)) return false; - if (!plot.disc(x + width * 0.5, y + height * 0.5, - width * 0.5 - 1, 0x000000, false)) + + /* plot light arc */ + if (!plot.arc(x + width * 0.5, y + height * 0.5, + width * 0.5 - 1, 225, 45, lite)) return false; - if (selected) + + if (selected) { + /* plot selection blob */ if (!plot.disc(x + width * 0.5, y + height * 0.5, - width * 0.3 - 1, 0x0000ff, true)) + width * 0.3 - 1, WIDGET_BLOBC, true)) return false; + } return true; } diff --git a/riscos/plotters.c b/riscos/plotters.c index 4f3decb37..c08f7d646 100644 --- a/riscos/plotters.c +++ b/riscos/plotters.c @@ -9,6 +9,7 @@ * Target independent plotting (RISC OS screen implementation). */ +#include #include "oslib/colourtrans.h" #include "oslib/draw.h" #include "oslib/os.h" @@ -34,6 +35,8 @@ static bool ro_plot_clip(int clip_x0, int clip_y0, static bool ro_plot_text(int x, int y, struct css_style *style, const char *text, size_t length, colour bg, colour c); static bool ro_plot_disc(int x, int y, int radius, colour colour, bool filled); +static bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2, + colour c); static bool ro_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg); static bool ro_plot_bitmap_tile(int x, int y, int width, int height, @@ -54,6 +57,7 @@ const struct plotter_table ro_plotters = { ro_plot_clip, ro_plot_text, ro_plot_disc, + ro_plot_arc, ro_plot_bitmap, ro_plot_bitmap_tile, ro_plot_group_start, @@ -318,6 +322,53 @@ bool ro_plot_disc(int x, int y, int radius, colour colour, bool filled) return true; } +bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c) +{ + os_error *error; + int sx, sy, ex, ey; + double t; + + x = ro_plot_origin_x + x * 2; + y = ro_plot_origin_y - y * 2; + radius <<= 1; + + error = xcolourtrans_set_gcol(c << 8, 0, + os_ACTION_OVERWRITE, 0, 0); + + if (error) { + LOG(("xcolourtrans_set_gcol: 0x%x: %s", + error->errnum, error->errmess)); + return false; + } + + t = ((double)angle1 * M_PI) / 180.0; + sx = (x + (int)(radius * cos(t))); + sy = (y + (int)(radius * sin(t))); + + t = ((double)angle2 * M_PI) / 180.0; + ex = (x + (int)(radius * cos(t))); + ey = (y + (int)(radius * sin(t))); + + error = xos_plot(os_MOVE_TO, x, y); /* move to centre */ + if (error) { + LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess)); + return false; + } + + error = xos_plot(os_MOVE_TO, sx, sy); /* move to start */ + if (error) { + LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess)); + return false; + } + + error = xos_plot(os_PLOT_ARC | os_PLOT_TO, ex, ey); /* arc to end */ + if (error) { + LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess)); + return false; + } + + return true; +} bool ro_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg) diff --git a/riscos/save_draw.c b/riscos/save_draw.c index 03afeca41..3b024d620 100644 --- a/riscos/save_draw.c +++ b/riscos/save_draw.c @@ -38,6 +38,8 @@ static bool ro_save_draw_text(int x, int y, struct css_style *style, const char *text, size_t length, colour bg, colour c); static bool ro_save_draw_disc(int x, int y, int radius, colour colour, bool filled); +static bool ro_save_draw_arc(int x, int y, int radius, int angle1, int angle2, + colour c); static bool ro_save_draw_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg); static bool ro_save_draw_bitmap_tile(int x, int y, int width, int height, @@ -57,6 +59,7 @@ const struct plotter_table ro_save_draw_plotters = { ro_save_draw_clip, ro_save_draw_text, ro_save_draw_disc, + ro_save_draw_arc, ro_save_draw_bitmap, ro_save_draw_bitmap_tile, ro_save_draw_group_start, @@ -258,6 +261,11 @@ bool ro_save_draw_disc(int x, int y, int radius, colour colour, bool filled) return true; } +bool ro_save_draw_arc(int x, int y, int radius, int angle1, int angle2, + colour c); +{ + return true; +} bool ro_save_draw_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg) -- cgit v1.2.3