Merge pull request #752 from contre/overlayCustomColor
Allow overlays to have custom colors
This commit is contained in:
@@ -168,6 +168,10 @@ class ClearBase(RenderPrimitive):
|
|||||||
class Overlay(RenderPrimitive):
|
class Overlay(RenderPrimitive):
|
||||||
name = "overlay"
|
name = "overlay"
|
||||||
|
|
||||||
|
options = {
|
||||||
|
'overlay_color' : ('a tuple of (r, g, b, a) for coloring the overlay', None),
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def whitecolor(self):
|
def whitecolor(self):
|
||||||
whitecolor = getattr(self, "_whitecolor", None)
|
whitecolor = getattr(self, "_whitecolor", None)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// increment this value if you've made a change to the c extesion
|
// increment this value if you've made a change to the c extesion
|
||||||
// and want to force users to rebuild
|
// and want to force users to rebuild
|
||||||
#define OVERVIEWER_EXTENSION_VERSION 37
|
#define OVERVIEWER_EXTENSION_VERSION 38
|
||||||
|
|
||||||
/* Python PIL, and numpy headers */
|
/* Python PIL, and numpy headers */
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|||||||
@@ -71,16 +71,16 @@ static void get_color(void *data, RenderState *state,
|
|||||||
RenderPrimitiveSlime *self = (RenderPrimitiveSlime *)data;
|
RenderPrimitiveSlime *self = (RenderPrimitiveSlime *)data;
|
||||||
|
|
||||||
/* set a nice, pretty green color */
|
/* set a nice, pretty green color */
|
||||||
*r = 40;
|
*r = self->parent.color->r;
|
||||||
*g = 230;
|
*g = self->parent.color->g;
|
||||||
*b = 40;
|
*b = self->parent.color->b;
|
||||||
|
|
||||||
/* default to no overlay, until told otherwise */
|
/* default to no overlay, until told otherwise */
|
||||||
*a = 0;
|
*a = 0;
|
||||||
|
|
||||||
if (is_slime(self->seed, state->chunkx, state->chunkz)) {
|
if (is_slime(self->seed, state->chunkx, state->chunkz)) {
|
||||||
/* slimes can spawn! */
|
/* slimes can spawn! */
|
||||||
*a = 240;
|
*a = self->parent.color->a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +98,11 @@ overlay_slime_start(void *data, RenderState *state, PyObject *support) {
|
|||||||
self = (RenderPrimitiveSlime *)data;
|
self = (RenderPrimitiveSlime *)data;
|
||||||
self->parent.get_color = get_color;
|
self->parent.get_color = get_color;
|
||||||
|
|
||||||
|
self->parent.default_color.r = 40;
|
||||||
|
self->parent.default_color.g = 230;
|
||||||
|
self->parent.default_color.b = 40;
|
||||||
|
self->parent.default_color.a = 240;
|
||||||
|
|
||||||
pyseed = PyObject_GetAttrString(state->world, "seed");
|
pyseed = PyObject_GetAttrString(state->world, "seed");
|
||||||
if (!pyseed)
|
if (!pyseed)
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ typedef struct {
|
|||||||
|
|
||||||
static void get_color(void *data, RenderState *state,
|
static void get_color(void *data, RenderState *state,
|
||||||
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
|
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 x = state->x, y = state->y, z = state->z;
|
||||||
int y_light = y + 1;
|
int y_light = y + 1;
|
||||||
unsigned char blocklight, skylight;
|
unsigned char blocklight, skylight;
|
||||||
|
|
||||||
/* set a nice, pretty red color */
|
/* set a nice, pretty red color */
|
||||||
*r = 229;
|
*r = self->parent.color->r;
|
||||||
*g = 36;
|
*g = self->parent.color->g;
|
||||||
*b = 38;
|
*b = self->parent.color->b;
|
||||||
|
|
||||||
/* default to no overlay, until told otherwise */
|
/* default to no overlay, until told otherwise */
|
||||||
*a = 0;
|
*a = 0;
|
||||||
@@ -68,6 +68,11 @@ overlay_spawn_start(void *data, RenderState *state, PyObject *support) {
|
|||||||
self = (RenderPrimitiveSpawn *)data;
|
self = (RenderPrimitiveSpawn *)data;
|
||||||
self->parent.get_color = get_color;
|
self->parent.get_color = get_color;
|
||||||
|
|
||||||
|
self->parent.default_color.r = 229;
|
||||||
|
self->parent.default_color.g = 36;
|
||||||
|
self->parent.default_color.b = 38;
|
||||||
|
self->parent.default_color.a = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,20 +19,49 @@
|
|||||||
|
|
||||||
static void get_color(void *data, RenderState *state,
|
static void get_color(void *data, RenderState *state,
|
||||||
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
|
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
|
||||||
*r = 200;
|
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay *)data;
|
||||||
*g = 200;
|
|
||||||
*b = 255;
|
*r = self->color->r;
|
||||||
*a = 155;
|
*g = self->color->g;
|
||||||
|
*b = self->color->b;
|
||||||
|
*a = self->color->a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
overlay_start(void *data, RenderState *state, PyObject *support) {
|
overlay_start(void *data, RenderState *state, PyObject *support) {
|
||||||
|
PyObject *opt = NULL;
|
||||||
|
OverlayColor *color = NULL;
|
||||||
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
|
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
|
||||||
|
|
||||||
self->facemask_top = PyObject_GetAttrString(support, "facemask_top");
|
self->facemask_top = PyObject_GetAttrString(support, "facemask_top");
|
||||||
self->white_color = PyObject_GetAttrString(support, "whitecolor");
|
self->white_color = PyObject_GetAttrString(support, "whitecolor");
|
||||||
self->get_color = get_color;
|
self->get_color = get_color;
|
||||||
|
|
||||||
|
color = self->color = calloc(1, sizeof(OverlayColor));
|
||||||
|
|
||||||
|
if (color == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->default_color.r = 200;
|
||||||
|
self->default_color.g = 200;
|
||||||
|
self->default_color.b = 255;
|
||||||
|
self->default_color.a = 155;
|
||||||
|
|
||||||
|
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 = &self->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +69,10 @@ static void
|
|||||||
overlay_finish(void *data, RenderState *state) {
|
overlay_finish(void *data, RenderState *state) {
|
||||||
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
|
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
|
||||||
|
|
||||||
|
if (self->color && self->color != &self->default_color) {
|
||||||
|
free(self->color);
|
||||||
|
}
|
||||||
|
|
||||||
Py_DECREF(self->facemask_top);
|
Py_DECREF(self->facemask_top);
|
||||||
Py_DECREF(self->white_color);
|
Py_DECREF(self->white_color);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,18 @@
|
|||||||
|
|
||||||
#include "../overviewer.h"
|
#include "../overviewer.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char r, g, b, a;
|
||||||
|
} OverlayColor;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* top facemask and white color image, for drawing overlays */
|
/* top facemask and white color image, for drawing overlays */
|
||||||
PyObject *facemask_top, *white_color;
|
PyObject *facemask_top, *white_color;
|
||||||
|
/* color will be a pointer to either the default_color object below or
|
||||||
|
to a specially allocated color object that is instantiated from the
|
||||||
|
settings file */
|
||||||
|
OverlayColor *color;
|
||||||
|
OverlayColor default_color;
|
||||||
/* can be overridden in derived classes to control
|
/* can be overridden in derived classes to control
|
||||||
overlay alpha and color
|
overlay alpha and color
|
||||||
last four vars are r, g, b, a out */
|
last four vars are r, g, b, a out */
|
||||||
|
|||||||
Reference in New Issue
Block a user