diff options
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/knockout.c | 39 | ||||
-rw-r--r-- | desktop/plotters.h | 23 | ||||
-rw-r--r-- | desktop/save_pdf/pdf_plotters.c | 8 | ||||
-rw-r--r-- | desktop/textarea.c | 16 |
4 files changed, 68 insertions, 18 deletions
diff --git a/desktop/knockout.c b/desktop/knockout.c index 1fbb67968..7b236c6da 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -75,6 +75,25 @@ #define KNOCKOUT_BOXES 768 /* 28 bytes each */ #define KNOCKOUT_POLYGONS 3072 /* 4 bytes each */ +/** Global fill styles - used everywhere, should they be here? */ +static plot_style_t plot_style_fill_white_static = { + .fill_type = PLOT_OP_TYPE_SOLID, + .fill_colour = 0xffffff, +}; + +static plot_style_t plot_style_fill_red_static = { + .fill_type = PLOT_OP_TYPE_SOLID, + .fill_colour = 0x000000ff, +}; + +static plot_style_t plot_style_fill_black_static = { + .fill_type = PLOT_OP_TYPE_SOLID, + .fill_colour = 0x0, +}; + +plot_style_t *plot_style_fill_white = &plot_style_fill_white_static; +plot_style_t *plot_style_fill_red = &plot_style_fill_red_static; +plot_style_t *plot_style_fill_black = &plot_style_fill_black_static; struct knockout_box; struct knockout_entry; @@ -82,7 +101,7 @@ struct knockout_entry; static void knockout_set_plotters(void); static void knockout_calculate(int x0, int y0, int x1, int y1, struct knockout_box *box); -static bool knockout_plot_fill_recursive(struct knockout_box *box, colour c); +static bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_style); static bool knockout_plot_bitmap_recursive(struct knockout_box *box, struct knockout_entry *entry); @@ -91,7 +110,7 @@ static bool knockout_plot_rectangle(int x0, int y0, int width, int height, static bool knockout_plot_line(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed); static bool knockout_plot_polygon(const int *p, unsigned int n, colour fill); -static bool knockout_plot_fill(int x0, int y0, int x1, int y1, colour c); +static bool knockout_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *plot_style); static bool knockout_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); static bool knockout_plot_text(int x, int y, const struct css_style *style, @@ -189,7 +208,7 @@ struct knockout_entry { int y0; int x1; int y1; - colour c; + plot_style_t plot_style; } fill; struct { int x0; @@ -349,14 +368,14 @@ bool knockout_plot_flush(void) box = knockout_entries[i].box->child; if (box) success &= knockout_plot_fill_recursive(box, - knockout_entries[i].data.fill.c); + &knockout_entries[i].data.fill.plot_style); else if (!knockout_entries[i].box->deleted) success &= plot.fill( knockout_entries[i].data.fill.x0, knockout_entries[i].data.fill.y0, knockout_entries[i].data.fill.x1, knockout_entries[i].data.fill.y1, - knockout_entries[i].data.fill.c); + &knockout_entries[i].data.fill.plot_style); break; case KNOCKOUT_PLOT_CLIP: success &= plot.clip( @@ -575,7 +594,7 @@ void knockout_calculate(int x0, int y0, int x1, int y1, struct knockout_box *own } -bool knockout_plot_fill_recursive(struct knockout_box *box, colour c) +bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_style) { bool success = true; struct knockout_box *parent; @@ -584,13 +603,13 @@ bool knockout_plot_fill_recursive(struct knockout_box *box, colour c) if (parent->deleted) continue; if (parent->child) - knockout_plot_fill_recursive(parent->child, c); + knockout_plot_fill_recursive(parent->child, plot_style); else success &= plot.fill(parent->bbox.x0, parent->bbox.y0, parent->bbox.x1, parent->bbox.y1, - c); + plot_style); } return success; } @@ -700,7 +719,7 @@ bool knockout_plot_path(const float *p, unsigned int n, colour fill, } -bool knockout_plot_fill(int x0, int y0, int x1, int y1, colour c) +bool knockout_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *plot_style) { int kx0, ky0, kx1, ky1; @@ -728,7 +747,7 @@ bool knockout_plot_fill(int x0, int y0, int x1, int y1, colour c) knockout_entries[knockout_entry_cur].data.fill.y0 = y0; knockout_entries[knockout_entry_cur].data.fill.x1 = x1; knockout_entries[knockout_entry_cur].data.fill.y1 = y1; - knockout_entries[knockout_entry_cur].data.fill.c = c; + knockout_entries[knockout_entry_cur].data.fill.plot_style = *plot_style; knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_FILL; if ((++knockout_entry_cur >= KNOCKOUT_ENTRIES) || (++knockout_box_cur >= KNOCKOUT_BOXES)) diff --git a/desktop/plotters.h b/desktop/plotters.h index 8a7183f89..d634f2135 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -35,6 +35,27 @@ typedef unsigned long bitmap_flags_t; #define BITMAPF_REPEAT_X 1 #define BITMAPF_REPEAT_Y 2 +typedef enum { + PLOT_OP_TYPE_NONE = 0, /**< No operation */ + PLOT_OP_TYPE_SOLID, /**< Solid colour */ + PLOT_OP_TYPE_DOT, /**< Doted plot */ + PLOT_OP_TYPE_DASH, /**< dashed plot */ +} plot_operation_type_t; + + +typedef struct { + plot_operation_type_t stroke_type; + int stroke_width; + colour stroke_colour; + plot_operation_type_t fill_type; + colour fill_colour; +} plot_style_t; + +/* global styles */ +extern plot_style_t *plot_style_fill_white; +extern plot_style_t *plot_style_fill_red; +extern plot_style_t *plot_style_fill_black; + /** Set of target specific plotting functions. * * The functions are: @@ -99,7 +120,7 @@ struct plotter_table { bool (*line)(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed); bool (*polygon)(const int *p, unsigned int n, colour fill); - bool (*fill)(int x0, int y0, int x1, int y1, colour c); + bool (*fill)(int x0, int y0, int x1, int y1, plot_style_t *style); bool (*clip)(int x0, int y0, int x1, int y1); bool (*text)(int x, int y, const struct css_style *style, const char *text, size_t length, colour bg, colour c); diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf/pdf_plotters.c index 74c36925b..7f573d9aa 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf/pdf_plotters.c @@ -50,7 +50,7 @@ static bool pdf_plot_rectangle(int x0, int y0, int width, int height, static bool pdf_plot_line(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed); static bool pdf_plot_polygon(const int *p, unsigned int n, colour fill); -static bool pdf_plot_fill(int x0, int y0, int x1, int y1, colour c); +static bool pdf_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *style); static bool pdf_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1); static bool pdf_plot_text(int x, int y, const struct css_style *style, @@ -214,13 +214,13 @@ bool pdf_plot_polygon(const int *p, unsigned int n, colour fill) return true; } -bool pdf_plot_fill(int x0, int y0, int x1, int y1, colour c) +bool pdf_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *style) { #ifdef PDF_DEBUG - LOG(("%d %d %d %d %f %X", x0, y0, x1, y1, page_height - y0, c)); + LOG(("%d %d %d %d %f %X", x0, y0, x1, y1, page_height - y0, style->fill_colour)); #endif - apply_clip_and_mode(false, c, TRANSPARENT, 0., DashPattern_eNone); + apply_clip_and_mode(false, style->fill_colour, TRANSPARENT, 0., DashPattern_eNone); /*Normalize boundaries of the area - to prevent overflows. It is needed only in a few functions, where integers are subtracted. diff --git a/desktop/textarea.c b/desktop/textarea.c index 6fbcec0d8..3e0ce466a 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -41,6 +41,10 @@ #define BORDER_COLOR 0x000000 #define SELECTION_COL 0xFFDDDD +static plot_style_t plot_style_fill_selection = { + .fill_type = PLOT_OP_TYPE_SOLID, + .fill_colour = SELECTION_COL, +}; struct line_info { unsigned int b_start; /**< Byte offset of line start */ @@ -713,6 +717,10 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) int chars, offset; unsigned int c_pos, c_len, b_start, b_end, line_len; char *line_text; + plot_style_t plot_style_fill_bg = { + .fill_type = PLOT_OP_TYPE_SOLID, + .fill_colour = BACKGROUND_COL, + }; if (x1 < ta->x || x0 > ta->x + ta->vis_width || y1 < ta->y || @@ -723,6 +731,9 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) if (ta->lines == NULL) /* Nothing to redraw */ return; + + if (ta->flags & TEXTAREA_READONLY) + plot_style_fill_bg.fill_colour = READONLY_BG; line0 = (y0 - ta->y + ta->scroll_y) / ta->line_height - 1; line1 = (y1 - ta->y + ta->scroll_y) / ta->line_height + 1; @@ -748,8 +759,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) y1 = ta->y + ta->vis_height; plot.clip(x0, y0, x1, y1); - plot.fill(x0, y0, x1, y1, (ta->flags & TEXTAREA_READONLY) ? - READONLY_BG : BACKGROUND_COL); + plot.fill(x0, y0, x1, y1, &plot_style_fill_bg); plot.rectangle(ta->x, ta->y, ta->vis_width - 1, ta->vis_height - 1, 1, BORDER_COLOR, false, false); @@ -837,7 +847,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) x1 - ta->scroll_x, ta->y + (line + 1) * ta->line_height - 1 - ta->scroll_y, - SELECTION_COL); + &plot_style_fill_selection); } |