2006-07-01 22:16:05 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-07-01 22:16:05 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Knockout rendering (implementation).
|
2008-09-15 22:47:37 +04:00
|
|
|
*
|
|
|
|
* Knockout rendering is an optimisation which is particularly for
|
|
|
|
* unaccelerated screen redraw. It tries to avoid plotting the same area more
|
|
|
|
* than once.
|
|
|
|
*
|
|
|
|
* If the object is to plot two overlapping rectangles (one large, one small),
|
|
|
|
* such as:
|
|
|
|
*
|
|
|
|
* +-----------------+
|
|
|
|
* |#################|
|
|
|
|
* |####+-------+####|
|
|
|
|
* |####|:::::::|####|
|
|
|
|
* |####|:::::::|####|
|
|
|
|
* |####|:::::::|####|
|
|
|
|
* |####+-------+####|
|
|
|
|
* |#################|
|
|
|
|
* +-----------------+
|
|
|
|
*
|
|
|
|
* Without knockout rendering we plot the bottom rectangle and then the top one:
|
|
|
|
*
|
|
|
|
* +-----------------+ +-----------------+
|
|
|
|
* |#################| |#################|
|
|
|
|
* |#################| |####+-------+####|
|
|
|
|
* |#################| |####|:::::::|####|
|
|
|
|
* |#################| and then, |####|:::::::|####|
|
|
|
|
* |#################| |####|:::::::|####|
|
|
|
|
* |#################| |####+-------+####|
|
|
|
|
* |#################| |#################|
|
|
|
|
* +-----------------+ +-----------------+
|
|
|
|
*
|
2009-05-28 14:39:53 +04:00
|
|
|
* With knockout rendering, the bottom rectangle is split up into smaller
|
2008-09-15 22:47:37 +04:00
|
|
|
* ones and each pixel is just plotted once:
|
|
|
|
*
|
|
|
|
* +-----------------+
|
|
|
|
* |#################|
|
|
|
|
* +----+-------+----+
|
|
|
|
* |####|:::::::|####|
|
|
|
|
* |####|:::::::|####|
|
|
|
|
* |####|:::::::|####|
|
|
|
|
* +----+-------+----+
|
|
|
|
* |#################|
|
|
|
|
* +-----------------+
|
2006-07-01 22:16:05 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/knockout.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "utils/log.h"
|
2011-04-04 02:23:14 +04:00
|
|
|
|
|
|
|
/* Define to enable knockout debug */
|
|
|
|
#undef KNOCKOUT_DEBUG
|
2006-07-01 22:16:05 +04:00
|
|
|
|
2006-07-02 05:36:02 +04:00
|
|
|
#define KNOCKOUT_ENTRIES 3072 /* 40 bytes each */
|
2006-07-02 17:18:29 +04:00
|
|
|
#define KNOCKOUT_BOXES 768 /* 28 bytes each */
|
2006-07-02 05:36:02 +04:00
|
|
|
#define KNOCKOUT_POLYGONS 3072 /* 4 bytes each */
|
2006-07-01 22:16:05 +04:00
|
|
|
|
|
|
|
struct knockout_box;
|
|
|
|
struct knockout_entry;
|
|
|
|
|
2006-07-02 20:17:51 +04:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
static void knockout_calculate(int x0, int y0, int x1, int y1, struct knockout_box *box);
|
2009-07-06 00:10:17 +04:00
|
|
|
static bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_style);
|
2009-06-30 17:02:23 +04:00
|
|
|
static bool knockout_plot_bitmap_recursive(struct knockout_box *box,
|
2006-07-01 22:16:05 +04:00
|
|
|
struct knockout_entry *entry);
|
|
|
|
|
2009-07-10 22:36:49 +04:00
|
|
|
static bool knockout_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
|
2009-07-14 14:03:58 +04:00
|
|
|
static bool knockout_plot_polygon(const int *p, unsigned int n, const plot_style_t *pstyle);
|
2009-07-09 02:04:40 +04:00
|
|
|
static bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *plot_style);
|
2011-02-15 01:05:39 +03:00
|
|
|
static bool knockout_plot_clip(const struct rect *clip);
|
2009-07-21 14:59:53 +04:00
|
|
|
static bool knockout_plot_text(int x, int y, const char *text, size_t length,
|
|
|
|
const plot_font_style_t *fstyle);
|
2009-07-14 14:03:58 +04:00
|
|
|
static bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle);
|
|
|
|
static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle);
|
2006-07-01 22:16:05 +04:00
|
|
|
static bool knockout_plot_bitmap(int x, int y, int width, int height,
|
|
|
|
struct bitmap *bitmap, colour bg,
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap_flags_t flags);
|
2008-07-30 23:17:27 +04:00
|
|
|
static bool knockout_plot_flush(void);
|
2006-07-01 22:16:05 +04:00
|
|
|
static bool knockout_plot_group_start(const char *name);
|
|
|
|
static bool knockout_plot_group_end(void);
|
2009-02-03 04:27:54 +03:00
|
|
|
static bool knockout_plot_path(const float *p, unsigned int n, colour fill,
|
|
|
|
float width, colour c, const float transform[6]);
|
2006-07-01 22:16:05 +04:00
|
|
|
|
|
|
|
|
|
|
|
const struct plotter_table knockout_plotters = {
|
2009-06-30 17:02:23 +04:00
|
|
|
.rectangle = knockout_plot_rectangle,
|
|
|
|
.line = knockout_plot_line,
|
|
|
|
.polygon = knockout_plot_polygon,
|
|
|
|
.clip = knockout_plot_clip,
|
|
|
|
.text = knockout_plot_text,
|
|
|
|
.disc = knockout_plot_disc,
|
|
|
|
.arc = knockout_plot_arc,
|
|
|
|
.bitmap = knockout_plot_bitmap,
|
|
|
|
.group_start = knockout_plot_group_start,
|
|
|
|
.group_end = knockout_plot_group_end,
|
|
|
|
.flush = knockout_plot_flush,
|
|
|
|
.path = knockout_plot_path,
|
|
|
|
.option_knockout = true,
|
2006-07-01 22:16:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
KNOCKOUT_PLOT_RECTANGLE,
|
|
|
|
KNOCKOUT_PLOT_LINE,
|
|
|
|
KNOCKOUT_PLOT_POLYGON,
|
|
|
|
KNOCKOUT_PLOT_FILL, /* knockout, knocked out */
|
|
|
|
KNOCKOUT_PLOT_CLIP,
|
|
|
|
KNOCKOUT_PLOT_TEXT,
|
|
|
|
KNOCKOUT_PLOT_DISC,
|
|
|
|
KNOCKOUT_PLOT_ARC,
|
2009-06-30 17:02:23 +04:00
|
|
|
KNOCKOUT_PLOT_BITMAP, /* knockout, knocked out */
|
2006-07-01 22:16:05 +04:00
|
|
|
KNOCKOUT_PLOT_GROUP_START,
|
|
|
|
KNOCKOUT_PLOT_GROUP_END,
|
|
|
|
} knockout_type;
|
|
|
|
|
|
|
|
|
|
|
|
struct knockout_box {
|
2011-02-15 01:05:39 +03:00
|
|
|
struct rect bbox;
|
2006-07-02 17:18:29 +04:00
|
|
|
bool deleted; /* box has been deleted, ignore */
|
2006-07-01 22:16:05 +04:00
|
|
|
struct knockout_box *child;
|
|
|
|
struct knockout_box *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct knockout_entry {
|
|
|
|
knockout_type type;
|
|
|
|
struct knockout_box *box; /* relating series of knockout clips */
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int x0;
|
|
|
|
int y0;
|
2009-07-09 02:04:40 +04:00
|
|
|
int x1;
|
|
|
|
int y1;
|
|
|
|
plot_style_t plot_style;
|
2006-07-01 22:16:05 +04:00
|
|
|
} rectangle;
|
|
|
|
struct {
|
|
|
|
int x0;
|
|
|
|
int y0;
|
|
|
|
int x1;
|
|
|
|
int y1;
|
2009-07-10 22:36:49 +04:00
|
|
|
plot_style_t plot_style;
|
2006-07-01 22:16:05 +04:00
|
|
|
} line;
|
|
|
|
struct {
|
|
|
|
int *p;
|
|
|
|
unsigned int n;
|
2009-07-14 14:03:58 +04:00
|
|
|
plot_style_t plot_style;
|
2006-07-01 22:16:05 +04:00
|
|
|
} polygon;
|
|
|
|
struct {
|
|
|
|
int x0;
|
|
|
|
int y0;
|
|
|
|
int x1;
|
|
|
|
int y1;
|
2009-07-06 00:10:17 +04:00
|
|
|
plot_style_t plot_style;
|
2006-07-01 22:16:05 +04:00
|
|
|
} fill;
|
2011-02-15 01:05:39 +03:00
|
|
|
struct rect clip;
|
2006-07-01 22:16:05 +04:00
|
|
|
struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
const char *text;
|
|
|
|
size_t length;
|
2009-07-21 14:59:53 +04:00
|
|
|
plot_font_style_t font_style;
|
2006-07-01 22:16:05 +04:00
|
|
|
} text;
|
|
|
|
struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int radius;
|
2009-07-14 14:03:58 +04:00
|
|
|
plot_style_t plot_style;
|
2006-07-01 22:16:05 +04:00
|
|
|
} disc;
|
|
|
|
struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int radius;
|
|
|
|
int angle1;
|
|
|
|
int angle2;
|
2009-07-14 14:03:58 +04:00
|
|
|
plot_style_t plot_style;
|
2006-07-01 22:16:05 +04:00
|
|
|
} arc;
|
|
|
|
struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
struct bitmap *bitmap;
|
|
|
|
colour bg;
|
2009-07-06 14:46:15 +04:00
|
|
|
bitmap_flags_t flags;
|
2006-07-01 22:16:05 +04:00
|
|
|
} bitmap;
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
} group_start;
|
|
|
|
} data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-30 03:19:24 +04:00
|
|
|
static struct knockout_entry knockout_entries[KNOCKOUT_ENTRIES];
|
|
|
|
static struct knockout_box knockout_boxes[KNOCKOUT_BOXES];
|
|
|
|
static int knockout_polygons[KNOCKOUT_POLYGONS];
|
|
|
|
static int knockout_entry_cur = 0;
|
|
|
|
static int knockout_box_cur = 0;
|
|
|
|
static int knockout_polygon_cur = 0;
|
|
|
|
static struct knockout_box *knockout_list = NULL;
|
|
|
|
|
|
|
|
static struct plotter_table real_plot;
|
|
|
|
|
2011-02-15 01:05:39 +03:00
|
|
|
static struct rect clip_cur;
|
2008-07-30 03:19:24 +04:00
|
|
|
static int nested_depth = 0;
|
2006-07-02 04:08:54 +04:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/**
|
|
|
|
* Start a knockout plotting session
|
|
|
|
*
|
2011-06-30 19:48:07 +04:00
|
|
|
* \param ctx the redraw context with real plotter table
|
|
|
|
* \param knk_ctx updated to copy of ctx, with plotter table replaced
|
2006-07-01 22:16:05 +04:00
|
|
|
* \return true on success, false otherwise
|
|
|
|
*/
|
2011-06-30 19:48:07 +04:00
|
|
|
bool knockout_plot_start(const struct redraw_context *ctx,
|
|
|
|
struct redraw_context *knk_ctx)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
2009-07-06 14:46:15 +04:00
|
|
|
/* check if we're recursing */
|
|
|
|
if (nested_depth++ > 0) {
|
|
|
|
/* we should already have the knockout renderer as default */
|
2011-06-30 19:48:07 +04:00
|
|
|
assert(ctx->plot->rectangle == knockout_plotters.rectangle);
|
|
|
|
*knk_ctx = *ctx;
|
2009-07-06 14:46:15 +04:00
|
|
|
return true;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/* end any previous sessions */
|
|
|
|
if (knockout_entry_cur > 0)
|
|
|
|
knockout_plot_end();
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
/* get copy of real plotter table */
|
|
|
|
real_plot = *(ctx->plot);
|
|
|
|
|
|
|
|
/* set up knockout rendering context */
|
|
|
|
*knk_ctx = *ctx;
|
|
|
|
knk_ctx->plot = &knockout_plotters;
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* End a knockout plotting session
|
|
|
|
*
|
|
|
|
* \return true on success, false otherwise
|
|
|
|
*/
|
|
|
|
bool knockout_plot_end(void)
|
2006-07-02 20:17:51 +04:00
|
|
|
{
|
|
|
|
/* only output when we've finished any nesting */
|
|
|
|
if (--nested_depth == 0)
|
|
|
|
return knockout_plot_flush();
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-02 20:17:51 +04:00
|
|
|
assert(nested_depth > 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush the current knockout session to empty the buffers
|
|
|
|
*
|
|
|
|
* \return true on success, false otherwise
|
|
|
|
*/
|
|
|
|
bool knockout_plot_flush(void)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
bool success = true;
|
|
|
|
struct knockout_box *box;
|
|
|
|
|
2006-07-02 05:36:02 +04:00
|
|
|
/* debugging information */
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef KNOCKOUT_DEBUG
|
2006-07-02 05:36:02 +04:00
|
|
|
LOG(("Entries are %i/%i, %i/%i, %i/%i",
|
|
|
|
knockout_entry_cur, KNOCKOUT_ENTRIES,
|
|
|
|
knockout_box_cur, KNOCKOUT_BOXES,
|
|
|
|
knockout_polygon_cur, KNOCKOUT_POLYGONS));
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2006-07-02 05:36:02 +04:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
for (i = 0; i < knockout_entry_cur; i++) {
|
|
|
|
switch (knockout_entries[i].type) {
|
2009-05-28 19:59:02 +04:00
|
|
|
case KNOCKOUT_PLOT_RECTANGLE:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.rectangle(
|
2009-07-09 02:04:40 +04:00
|
|
|
knockout_entries[i].data.rectangle.x0,
|
|
|
|
knockout_entries[i].data.rectangle.y0,
|
|
|
|
knockout_entries[i].data.rectangle.x1,
|
|
|
|
knockout_entries[i].data.rectangle.y1,
|
|
|
|
&knockout_entries[i].data.rectangle.plot_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_LINE:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.line(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.line.x0,
|
|
|
|
knockout_entries[i].data.line.y0,
|
|
|
|
knockout_entries[i].data.line.x1,
|
|
|
|
knockout_entries[i].data.line.y1,
|
2009-07-10 22:36:49 +04:00
|
|
|
&knockout_entries[i].data.line.plot_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_POLYGON:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.polygon(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.polygon.p,
|
|
|
|
knockout_entries[i].data.polygon.n,
|
2009-07-14 14:03:58 +04:00
|
|
|
&knockout_entries[i].data.polygon.plot_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_FILL:
|
|
|
|
box = knockout_entries[i].box->child;
|
|
|
|
if (box)
|
|
|
|
success &= knockout_plot_fill_recursive(box,
|
2009-07-06 00:10:17 +04:00
|
|
|
&knockout_entries[i].data.fill.plot_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
else if (!knockout_entries[i].box->deleted)
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.rectangle(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.fill.x0,
|
|
|
|
knockout_entries[i].data.fill.y0,
|
|
|
|
knockout_entries[i].data.fill.x1,
|
|
|
|
knockout_entries[i].data.fill.y1,
|
2009-07-06 00:10:17 +04:00
|
|
|
&knockout_entries[i].data.fill.plot_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_CLIP:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.clip(
|
2011-02-15 01:05:39 +03:00
|
|
|
&knockout_entries[i].data.clip);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_TEXT:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.text(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.text.x,
|
|
|
|
knockout_entries[i].data.text.y,
|
|
|
|
knockout_entries[i].data.text.text,
|
|
|
|
knockout_entries[i].data.text.length,
|
2009-07-21 14:59:53 +04:00
|
|
|
&knockout_entries[i].data.text.font_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_DISC:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.disc(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.disc.x,
|
|
|
|
knockout_entries[i].data.disc.y,
|
|
|
|
knockout_entries[i].data.disc.radius,
|
2009-07-14 14:03:58 +04:00
|
|
|
&knockout_entries[i].data.disc.plot_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_ARC:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.arc(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.arc.x,
|
|
|
|
knockout_entries[i].data.arc.y,
|
|
|
|
knockout_entries[i].data.arc.radius,
|
|
|
|
knockout_entries[i].data.arc.angle1,
|
|
|
|
knockout_entries[i].data.arc.angle2,
|
2009-07-14 14:03:58 +04:00
|
|
|
&knockout_entries[i].data.arc.plot_style);
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_BITMAP:
|
|
|
|
box = knockout_entries[i].box->child;
|
|
|
|
if (box) {
|
2009-06-30 17:02:23 +04:00
|
|
|
success &= knockout_plot_bitmap_recursive(box,
|
2009-05-28 19:59:02 +04:00
|
|
|
&knockout_entries[i]);
|
|
|
|
} else if (!knockout_entries[i].box->deleted) {
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.bitmap(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap.x,
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap.y,
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap.width,
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap.height,
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap.bitmap,
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap.bg,
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap.flags);
|
2009-05-28 19:59:02 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_GROUP_START:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.group_start(
|
2009-05-28 19:59:02 +04:00
|
|
|
knockout_entries[i].data.group_start.name);
|
|
|
|
break;
|
|
|
|
case KNOCKOUT_PLOT_GROUP_END:
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.group_end();
|
2009-05-28 19:59:02 +04:00
|
|
|
break;
|
2006-07-01 22:16:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
knockout_entry_cur = 0;
|
|
|
|
knockout_box_cur = 0;
|
|
|
|
knockout_polygon_cur = 0;
|
|
|
|
knockout_list = NULL;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Knockout a section of previous rendering
|
|
|
|
*
|
|
|
|
* \param x0 the left edge of the removal box
|
|
|
|
* \param y0 the bottom edge of the removal box
|
|
|
|
* \param x1 the right edge of the removal box
|
|
|
|
* \param y1 the top edge of the removal box
|
2006-07-02 17:18:29 +04:00
|
|
|
* \param box the parent box set to consider, or NULL for top level
|
2006-07-01 22:16:05 +04:00
|
|
|
*/
|
2006-07-02 17:18:29 +04:00
|
|
|
void knockout_calculate(int x0, int y0, int x1, int y1, struct knockout_box *owner)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
2006-07-02 17:18:29 +04:00
|
|
|
struct knockout_box *box;
|
2006-07-01 22:16:05 +04:00
|
|
|
struct knockout_box *parent;
|
2006-07-02 17:18:29 +04:00
|
|
|
struct knockout_box *prev = NULL;
|
2006-07-01 22:16:05 +04:00
|
|
|
int nx0, ny0, nx1, ny1;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-02 17:18:29 +04:00
|
|
|
if (owner == NULL)
|
|
|
|
box = knockout_list;
|
|
|
|
else
|
|
|
|
box = owner->child;
|
2006-07-01 22:16:05 +04:00
|
|
|
|
|
|
|
for (parent = box; parent; parent = parent->next) {
|
2009-07-06 14:46:15 +04:00
|
|
|
/* permanently delink deleted nodes */
|
2006-07-02 17:18:29 +04:00
|
|
|
if (parent->deleted) {
|
2009-07-06 14:46:15 +04:00
|
|
|
if (prev) {
|
|
|
|
/* not the first valid element: just skip future */
|
|
|
|
prev->next = parent->next;
|
|
|
|
} else {
|
|
|
|
if (owner) {
|
|
|
|
/* first valid element: update child reference */
|
|
|
|
owner->child = parent->next;
|
|
|
|
/* have we deleted all child nodes? */
|
|
|
|
if (!owner->child)
|
|
|
|
owner->deleted = true;
|
|
|
|
} else {
|
|
|
|
/* we are the head of the list */
|
|
|
|
knockout_list = parent->next;
|
|
|
|
}
|
|
|
|
}
|
2006-07-01 22:16:05 +04:00
|
|
|
continue;
|
2006-07-02 17:18:29 +04:00
|
|
|
} else {
|
2009-07-06 14:46:15 +04:00
|
|
|
prev = parent;
|
2006-07-02 17:18:29 +04:00
|
|
|
}
|
|
|
|
|
2006-07-02 05:36:02 +04:00
|
|
|
/* get the parent dimensions */
|
2009-07-06 14:46:15 +04:00
|
|
|
nx0 = parent->bbox.x0;
|
|
|
|
ny0 = parent->bbox.y0;
|
|
|
|
nx1 = parent->bbox.x1;
|
|
|
|
ny1 = parent->bbox.y1;
|
2006-07-02 05:36:02 +04:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/* reject non-overlapping boxes */
|
2006-07-02 05:36:02 +04:00
|
|
|
if ((nx0 >= x1) || (nx1 <= x0) || (ny0 >= y1) || (ny1 <= y0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check for a total knockout */
|
|
|
|
if ((x0 <= nx0) && (x1 >= nx1) && (y0 <= ny0) && (y1 >= ny1)) {
|
|
|
|
parent->deleted = true;
|
2006-07-01 22:16:05 +04:00
|
|
|
continue;
|
2006-07-02 05:36:02 +04:00
|
|
|
}
|
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/* has the box been replaced by children? */
|
|
|
|
if (parent->child) {
|
2006-07-02 17:18:29 +04:00
|
|
|
knockout_calculate(x0, y0, x1, y1, parent);
|
2006-07-01 22:16:05 +04:00
|
|
|
} else {
|
|
|
|
/* we need a maximum of 4 child boxes */
|
2006-07-02 05:36:02 +04:00
|
|
|
if (knockout_box_cur + 4 >= KNOCKOUT_BOXES) {
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clip top */
|
|
|
|
if (y1 < ny1) {
|
2009-07-06 14:46:15 +04:00
|
|
|
knockout_boxes[knockout_box_cur].bbox.x0 = nx0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y0 = y1;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x1 = nx1;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y1 = ny1;
|
|
|
|
knockout_boxes[knockout_box_cur].deleted = false;
|
|
|
|
knockout_boxes[knockout_box_cur].child = NULL;
|
|
|
|
knockout_boxes[knockout_box_cur].next = parent->child;
|
2006-07-01 22:16:05 +04:00
|
|
|
parent->child = &knockout_boxes[knockout_box_cur++];
|
|
|
|
ny1 = y1;
|
|
|
|
}
|
|
|
|
/* clip bottom */
|
|
|
|
if (y0 > ny0) {
|
2009-07-06 14:46:15 +04:00
|
|
|
knockout_boxes[knockout_box_cur].bbox.x0 = nx0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y0 = ny0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x1 = nx1;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y1 = y0;
|
|
|
|
knockout_boxes[knockout_box_cur].deleted = false;
|
|
|
|
knockout_boxes[knockout_box_cur].child = NULL;
|
|
|
|
knockout_boxes[knockout_box_cur].next = parent->child;
|
2006-07-01 22:16:05 +04:00
|
|
|
parent->child = &knockout_boxes[knockout_box_cur++];
|
|
|
|
ny0 = y0;
|
|
|
|
}
|
|
|
|
/* clip right */
|
|
|
|
if (x1 < nx1) {
|
2009-07-06 14:46:15 +04:00
|
|
|
knockout_boxes[knockout_box_cur].bbox.x0 = x1;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y0 = ny0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x1 = nx1;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y1 = ny1;
|
|
|
|
knockout_boxes[knockout_box_cur].deleted = false;
|
|
|
|
knockout_boxes[knockout_box_cur].child = NULL;
|
|
|
|
knockout_boxes[knockout_box_cur].next = parent->child;
|
2006-07-01 22:16:05 +04:00
|
|
|
parent->child = &knockout_boxes[knockout_box_cur++];
|
2009-05-28 19:59:02 +04:00
|
|
|
/* nx1 isn't used again, but if it was it would
|
|
|
|
* need to be updated to x1 here. */
|
2006-07-01 22:16:05 +04:00
|
|
|
}
|
|
|
|
/* clip left */
|
|
|
|
if (x0 > nx0) {
|
2009-07-06 14:46:15 +04:00
|
|
|
knockout_boxes[knockout_box_cur].bbox.x0 = nx0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y0 = ny0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x1 = x0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y1 = ny1;
|
|
|
|
knockout_boxes[knockout_box_cur].deleted = false;
|
|
|
|
knockout_boxes[knockout_box_cur].child = NULL;
|
|
|
|
knockout_boxes[knockout_box_cur].next = parent->child;
|
2006-07-01 22:16:05 +04:00
|
|
|
parent->child = &knockout_boxes[knockout_box_cur++];
|
2009-05-28 19:59:02 +04:00
|
|
|
/* nx0 isn't used again, but if it was it would
|
|
|
|
* need to be updated to x0 here. */
|
2006-07-01 22:16:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-06 00:10:17 +04:00
|
|
|
bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_style)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
struct knockout_box *parent;
|
|
|
|
|
|
|
|
for (parent = box; parent; parent = parent->next) {
|
|
|
|
if (parent->deleted)
|
|
|
|
continue;
|
|
|
|
if (parent->child)
|
2009-07-06 00:10:17 +04:00
|
|
|
knockout_plot_fill_recursive(parent->child, plot_style);
|
2006-07-01 22:16:05 +04:00
|
|
|
else
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.rectangle(parent->bbox.x0,
|
2009-07-09 02:04:40 +04:00
|
|
|
parent->bbox.y0,
|
|
|
|
parent->bbox.x1,
|
|
|
|
parent->bbox.y1,
|
|
|
|
plot_style);
|
2006-07-01 22:16:05 +04:00
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 17:02:23 +04:00
|
|
|
bool knockout_plot_bitmap_recursive(struct knockout_box *box,
|
2006-07-01 22:16:05 +04:00
|
|
|
struct knockout_entry *entry)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
struct knockout_box *parent;
|
|
|
|
|
|
|
|
for (parent = box; parent; parent = parent->next) {
|
|
|
|
if (parent->deleted)
|
|
|
|
continue;
|
|
|
|
if (parent->child)
|
2009-06-30 17:02:23 +04:00
|
|
|
knockout_plot_bitmap_recursive(parent->child, entry);
|
2006-07-01 22:16:05 +04:00
|
|
|
else {
|
2011-06-30 19:48:07 +04:00
|
|
|
success &= real_plot.clip(&parent->bbox);
|
|
|
|
success &= real_plot.bitmap(entry->data.bitmap.x,
|
2009-06-30 17:02:23 +04:00
|
|
|
entry->data.bitmap.y,
|
|
|
|
entry->data.bitmap.width,
|
|
|
|
entry->data.bitmap.height,
|
|
|
|
entry->data.bitmap.bitmap,
|
|
|
|
entry->data.bitmap.bg,
|
|
|
|
entry->data.bitmap.flags);
|
2006-07-01 22:16:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2009-07-09 02:04:40 +04:00
|
|
|
bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *pstyle)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
2009-07-09 02:04:40 +04:00
|
|
|
int kx0, ky0, kx1, ky1;
|
|
|
|
|
|
|
|
if (pstyle->fill_type != PLOT_OP_TYPE_NONE) {
|
|
|
|
/* filled draw */
|
|
|
|
|
|
|
|
/* get our bounds */
|
2011-02-15 01:05:39 +03:00
|
|
|
kx0 = (x0 > clip_cur.x0) ? x0 : clip_cur.x0;
|
|
|
|
ky0 = (y0 > clip_cur.y0) ? y0 : clip_cur.y0;
|
|
|
|
kx1 = (x1 < clip_cur.x1) ? x1 : clip_cur.x1;
|
|
|
|
ky1 = (y1 < clip_cur.y1) ? y1 : clip_cur.y1;
|
|
|
|
if ((kx0 > clip_cur.x1) || (kx1 < clip_cur.x0) ||
|
|
|
|
(ky0 > clip_cur.y1) || (ky1 < clip_cur.y0))
|
2009-07-09 02:04:40 +04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/* fills both knock out and get knocked out */
|
|
|
|
knockout_calculate(kx0, ky0, kx1, ky1, NULL);
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x0 = x0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y0 = y0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x1 = x1;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y1 = y1;
|
|
|
|
knockout_boxes[knockout_box_cur].deleted = false;
|
|
|
|
knockout_boxes[knockout_box_cur].child = NULL;
|
|
|
|
knockout_boxes[knockout_box_cur].next = knockout_list;
|
|
|
|
knockout_list = &knockout_boxes[knockout_box_cur];
|
|
|
|
knockout_entries[knockout_entry_cur].box = &knockout_boxes[knockout_box_cur];
|
|
|
|
knockout_entries[knockout_entry_cur].data.fill.x0 = x0;
|
|
|
|
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.plot_style = *pstyle;
|
2009-07-10 22:36:49 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.fill.plot_style.stroke_type = PLOT_OP_TYPE_NONE; /* ensure we only plot the fill */
|
2009-07-09 02:04:40 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_FILL;
|
|
|
|
if ((++knockout_entry_cur >= KNOCKOUT_ENTRIES) ||
|
|
|
|
(++knockout_box_cur >= KNOCKOUT_BOXES))
|
|
|
|
knockout_plot_flush();
|
2009-07-10 22:36:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pstyle->stroke_type != PLOT_OP_TYPE_NONE) {
|
|
|
|
/* draw outline */
|
2009-07-09 02:04:40 +04:00
|
|
|
|
|
|
|
knockout_entries[knockout_entry_cur].data.rectangle.x0 = x0;
|
|
|
|
knockout_entries[knockout_entry_cur].data.rectangle.y0 = y0;
|
|
|
|
knockout_entries[knockout_entry_cur].data.rectangle.x1 = x1;
|
|
|
|
knockout_entries[knockout_entry_cur].data.rectangle.y1 = y1;
|
|
|
|
knockout_entries[knockout_entry_cur].data.fill.plot_style = *pstyle;
|
2009-07-10 22:36:49 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.fill.plot_style.fill_type = PLOT_OP_TYPE_NONE; /* ensure we only plot the outline */
|
2009-07-09 02:04:40 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_RECTANGLE;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
|
|
|
knockout_plot_flush();
|
|
|
|
}
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-10 22:36:49 +04:00
|
|
|
bool knockout_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
|
|
|
knockout_entries[knockout_entry_cur].data.line.x0 = x0;
|
|
|
|
knockout_entries[knockout_entry_cur].data.line.y0 = y0;
|
|
|
|
knockout_entries[knockout_entry_cur].data.line.x1 = x1;
|
|
|
|
knockout_entries[knockout_entry_cur].data.line.y1 = y1;
|
2009-07-10 22:36:49 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.line.plot_style = *pstyle;
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_LINE;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-14 14:03:58 +04:00
|
|
|
bool knockout_plot_polygon(const int *p, unsigned int n, const plot_style_t *pstyle)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
2009-07-06 14:46:15 +04:00
|
|
|
bool success = true;
|
|
|
|
int *dest;
|
2006-07-01 22:16:05 +04:00
|
|
|
|
|
|
|
/* ensure we have sufficient room even when flushed */
|
|
|
|
if (n * 2 >= KNOCKOUT_POLYGONS) {
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2009-07-14 14:03:58 +04:00
|
|
|
success = real_plot.polygon(p, n, pstyle);
|
2006-07-01 22:16:05 +04:00
|
|
|
return success;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/* ensure we have enough room right now */
|
|
|
|
if (knockout_polygon_cur + n * 2 >= KNOCKOUT_POLYGONS)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/* copy our data */
|
|
|
|
dest = &(knockout_polygons[knockout_polygon_cur]);
|
|
|
|
memcpy(dest, p, n * 2 * sizeof(int));
|
|
|
|
knockout_polygon_cur += n * 2;
|
|
|
|
knockout_entries[knockout_entry_cur].data.polygon.p = dest;
|
|
|
|
knockout_entries[knockout_entry_cur].data.polygon.n = n;
|
2009-07-14 14:03:58 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.polygon.plot_style = *pstyle;
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_POLYGON;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-03 04:27:54 +03:00
|
|
|
bool knockout_plot_path(const float *p, unsigned int n, colour fill,
|
|
|
|
float width, colour c, const float transform[6])
|
2007-11-29 08:50:21 +03:00
|
|
|
{
|
2007-12-11 05:45:38 +03:00
|
|
|
knockout_plot_flush();
|
|
|
|
return real_plot.path(p, n, fill, width, c, transform);
|
2007-11-29 08:50:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-15 01:05:39 +03:00
|
|
|
bool knockout_plot_clip(const struct rect *clip)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
2011-02-15 01:05:39 +03:00
|
|
|
if (clip->x1 < clip->x0 || clip->y0 > clip->y1) {
|
2011-04-04 02:23:14 +04:00
|
|
|
#ifdef KNOCKOUT_DEBUG
|
2006-07-01 22:16:05 +04:00
|
|
|
LOG(("bad clip rectangle %i %i %i %i",
|
2011-02-15 01:05:39 +03:00
|
|
|
clip->x0, clip->y0, clip->x1, clip->y1));
|
2011-04-04 02:23:14 +04:00
|
|
|
#endif
|
2006-07-01 22:16:05 +04:00
|
|
|
return false;
|
|
|
|
}
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/* memorise clip for bitmap tiling */
|
2011-02-15 01:05:39 +03:00
|
|
|
clip_cur = *clip;
|
|
|
|
|
|
|
|
knockout_entries[knockout_entry_cur].data.clip = *clip;
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_CLIP;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-21 14:59:53 +04:00
|
|
|
bool knockout_plot_text(int x, int y, const char *text, size_t length,
|
|
|
|
const plot_font_style_t *fstyle)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
|
|
|
knockout_entries[knockout_entry_cur].data.text.x = x;
|
|
|
|
knockout_entries[knockout_entry_cur].data.text.y = y;
|
|
|
|
knockout_entries[knockout_entry_cur].data.text.text = text;
|
|
|
|
knockout_entries[knockout_entry_cur].data.text.length = length;
|
2009-07-21 14:59:53 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.text.font_style = *fstyle;
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_TEXT;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-14 14:03:58 +04:00
|
|
|
bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
|
|
|
knockout_entries[knockout_entry_cur].data.disc.x = x;
|
|
|
|
knockout_entries[knockout_entry_cur].data.disc.y = y;
|
|
|
|
knockout_entries[knockout_entry_cur].data.disc.radius = radius;
|
2009-07-14 14:03:58 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.disc.plot_style = *pstyle;
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_DISC;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-14 14:03:58 +04:00
|
|
|
bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
|
|
|
knockout_entries[knockout_entry_cur].data.arc.x = x;
|
|
|
|
knockout_entries[knockout_entry_cur].data.arc.y = y;
|
|
|
|
knockout_entries[knockout_entry_cur].data.arc.radius = radius;
|
|
|
|
knockout_entries[knockout_entry_cur].data.arc.angle1 = angle1;
|
|
|
|
knockout_entries[knockout_entry_cur].data.arc.angle2 = angle2;
|
2009-07-14 14:03:58 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.arc.plot_style = *pstyle;
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_ARC;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-30 17:02:23 +04:00
|
|
|
bool knockout_plot_bitmap(int x, int y, int width, int height,
|
2006-07-01 22:16:05 +04:00
|
|
|
struct bitmap *bitmap, colour bg,
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap_flags_t flags)
|
2006-07-01 22:16:05 +04:00
|
|
|
{
|
2006-07-02 17:18:29 +04:00
|
|
|
int kx0, ky0, kx1, ky1;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-02 17:18:29 +04:00
|
|
|
/* get our bounds */
|
2011-02-15 01:05:39 +03:00
|
|
|
kx0 = clip_cur.x0;
|
|
|
|
ky0 = clip_cur.y0;
|
|
|
|
kx1 = clip_cur.x1;
|
|
|
|
ky1 = clip_cur.y1;
|
2009-07-06 14:46:15 +04:00
|
|
|
if (!(flags & BITMAPF_REPEAT_X)) {
|
|
|
|
if (x > kx0)
|
|
|
|
kx0 = x;
|
|
|
|
if (x + width < kx1)
|
|
|
|
kx1 = x + width;
|
2011-02-15 01:05:39 +03:00
|
|
|
if ((kx0 > clip_cur.x1) || (kx1 < clip_cur.x0))
|
2009-07-06 14:46:15 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!(flags & BITMAPF_REPEAT_Y)) {
|
|
|
|
if (y > ky0)
|
|
|
|
ky0 = y;
|
|
|
|
if (y + height < ky1)
|
|
|
|
ky1 = y + height;
|
2011-02-15 01:05:39 +03:00
|
|
|
if ((ky0 > clip_cur.y1) || (ky1 < clip_cur.y0))
|
2009-07-06 14:46:15 +04:00
|
|
|
return true;
|
|
|
|
}
|
2006-07-02 17:18:29 +04:00
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
/* tiled bitmaps both knock out and get knocked out */
|
2006-07-02 17:18:29 +04:00
|
|
|
if (bitmap_get_opaque(bitmap))
|
|
|
|
knockout_calculate(kx0, ky0, kx1, ky1, NULL);
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x0 = kx0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y0 = ky0;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.x1 = kx1;
|
|
|
|
knockout_boxes[knockout_box_cur].bbox.y1 = ky1;
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_boxes[knockout_box_cur].deleted = false;
|
|
|
|
knockout_boxes[knockout_box_cur].child = NULL;
|
|
|
|
knockout_boxes[knockout_box_cur].next = knockout_list;
|
|
|
|
knockout_list = &knockout_boxes[knockout_box_cur];
|
|
|
|
knockout_entries[knockout_entry_cur].box = &knockout_boxes[knockout_box_cur];
|
2009-06-30 17:02:23 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.bitmap.x = x;
|
|
|
|
knockout_entries[knockout_entry_cur].data.bitmap.y = y;
|
|
|
|
knockout_entries[knockout_entry_cur].data.bitmap.width = width;
|
|
|
|
knockout_entries[knockout_entry_cur].data.bitmap.height = height;
|
|
|
|
knockout_entries[knockout_entry_cur].data.bitmap.bitmap = bitmap;
|
|
|
|
knockout_entries[knockout_entry_cur].data.bitmap.bg = bg;
|
|
|
|
knockout_entries[knockout_entry_cur].data.bitmap.flags = flags;
|
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_BITMAP;
|
2006-07-01 22:16:05 +04:00
|
|
|
if ((++knockout_entry_cur >= KNOCKOUT_ENTRIES) ||
|
|
|
|
(++knockout_box_cur >= KNOCKOUT_BOXES))
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2011-02-15 01:05:39 +03:00
|
|
|
return knockout_plot_clip(&clip_cur);
|
2006-07-01 22:16:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool knockout_plot_group_start(const char *name)
|
|
|
|
{
|
2011-06-30 19:48:07 +04:00
|
|
|
if (real_plot.group_start == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].data.group_start.name = name;
|
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_GROUP_START;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool knockout_plot_group_end(void)
|
|
|
|
{
|
2011-06-30 19:48:07 +04:00
|
|
|
if (real_plot.group_end == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-01 22:16:05 +04:00
|
|
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_GROUP_END;
|
|
|
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
2006-07-02 20:17:51 +04:00
|
|
|
knockout_plot_flush();
|
2006-07-01 22:16:05 +04:00
|
|
|
return true;
|
|
|
|
}
|