From 28099deaf62be5e2916109e8f0ee4c541d7c2d15 Mon Sep 17 00:00:00 2001 From: Richard Pastrick Date: Fri, 8 Jun 2012 12:07:21 -0700 Subject: [PATCH] Add customizable overlay colors, works for base overlay, spawn, and slime. I left minerals as it is so you have to still define the minerals option to get that to work. --- overviewer_core/rendermodes.py | 4 ++ .../src/primitives/overlay-slime.c | 10 +++-- .../src/primitives/overlay-spawn.c | 10 +++-- overviewer_core/src/primitives/overlay.c | 39 +++++++++++++++++-- overviewer_core/src/primitives/overlay.h | 5 +++ 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/overviewer_core/rendermodes.py b/overviewer_core/rendermodes.py index d854d0f..9359556 100644 --- a/overviewer_core/rendermodes.py +++ b/overviewer_core/rendermodes.py @@ -168,6 +168,10 @@ class ClearBase(RenderPrimitive): class Overlay(RenderPrimitive): name = "overlay" + options = { + 'overlay_color' : ('a tuple of (r, g, b, a) for coloring the overlay', None), + } + @property def whitecolor(self): whitecolor = getattr(self, "_whitecolor", None) diff --git a/overviewer_core/src/primitives/overlay-slime.c b/overviewer_core/src/primitives/overlay-slime.c index f4abfe8..02c497b 100644 --- a/overviewer_core/src/primitives/overlay-slime.c +++ b/overviewer_core/src/primitives/overlay-slime.c @@ -66,21 +66,23 @@ static int is_slime(long map_seed, long chunkx, long chunkz) { return (random_next_int(&seed, 10) == 0); } +static OverlayColor default_color[] = { 40, 230, 40, 240 }; + static void get_color(void *data, RenderState *state, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) { RenderPrimitiveSlime *self = (RenderPrimitiveSlime *)data; /* set a nice, pretty green color */ - *r = 40; - *g = 230; - *b = 40; + *r = self->parent.color->r; + *g = self->parent.color->g; + *b = self->parent.color->b; /* default to no overlay, until told otherwise */ *a = 0; if (is_slime(self->seed, state->chunkx, state->chunkz)) { /* slimes can spawn! */ - *a = 240; + *a = self->parent.color->a; } } diff --git a/overviewer_core/src/primitives/overlay-spawn.c b/overviewer_core/src/primitives/overlay-spawn.c index 137fd48..662eac2 100644 --- a/overviewer_core/src/primitives/overlay-spawn.c +++ b/overviewer_core/src/primitives/overlay-spawn.c @@ -23,17 +23,19 @@ typedef struct { RenderPrimitiveOverlay parent; } RenderPrimitiveSpawn; +static OverlayColor default_color[] = { 229, 36, 38, 0 }; + static void get_color(void *data, RenderState *state, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) { - + RenderPrimitiveSpawn* self = (RenderPrimitiveSpawn *)data; int x = state->x, y = state->y, z = state->z; int y_light = y + 1; unsigned char blocklight, skylight; /* set a nice, pretty red color */ - *r = 229; - *g = 36; - *b = 38; + *r = self->parent.color->r; + *g = self->parent.color->g; + *b = self->parent.color->b; /* default to no overlay, until told otherwise */ *a = 0; diff --git a/overviewer_core/src/primitives/overlay.c b/overviewer_core/src/primitives/overlay.c index 1e02489..1de341d 100644 --- a/overviewer_core/src/primitives/overlay.c +++ b/overviewer_core/src/primitives/overlay.c @@ -17,28 +17,59 @@ #include "overlay.h" +static OverlayColor default_color[] = { 200, 200, 255, 155 }; + static void get_color(void *data, RenderState *state, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) { - *r = 200; - *g = 200; - *b = 255; - *a = 155; + RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay *)data; + + *r = self->color->r; + *g = self->color->g; + *b = self->color->b; + *a = self->color->a; } static int overlay_start(void *data, RenderState *state, PyObject *support) { + PyObject *opt = NULL; + OverlayColor *color = NULL; RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data; self->facemask_top = PyObject_GetAttrString(support, "facemask_top"); self->white_color = PyObject_GetAttrString(support, "whitecolor"); self->get_color = get_color; + color = self->color = calloc(1, sizeof(OverlayColor)); + + if (color == NULL) { + return 1; + } + + if(!render_mode_parse_option(support, "overlay_color", "bbbb", &(color->r), &(color->g), &(color->b), &(color->a))) { + if(PyErr_Occurred()) + PyErr_Clear(); + free(color); + self->color = default_color; + // Check if it is None, if it is, continue and use the default, if it isn't, return an error + if(render_mode_parse_option(support, "overlay_color", "O", &(opt))) { + // If it is an object, check to see if it is None, if it is, use the default. + if(opt && opt != Py_None) { + return 1; + } + } else { + return 1; + } + } return 0; } static void overlay_finish(void *data, RenderState *state) { RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data; + + if (self->color && self->color != default_color) { + free(self->color); + } Py_DECREF(self->facemask_top); Py_DECREF(self->white_color); diff --git a/overviewer_core/src/primitives/overlay.h b/overviewer_core/src/primitives/overlay.h index cc028bb..abc9a7c 100644 --- a/overviewer_core/src/primitives/overlay.h +++ b/overviewer_core/src/primitives/overlay.h @@ -17,9 +17,14 @@ #include "../overviewer.h" +typedef struct { + unsigned char r, g, b, a; +} OverlayColor; + typedef struct { /* top facemask and white color image, for drawing overlays */ PyObject *facemask_top, *white_color; + OverlayColor *color; /* can be overridden in derived classes to control overlay alpha and color last four vars are r, g, b, a out */