Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-04-23 21:16:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-04-23 21:24:49 +0300
commit1287fa3f7c5a0dc4484aa7e94267d21cc8b0b1f0 (patch)
tree20ab632c21b31b5994481978a2e8f1d8d44f0558 /source/blender/python/intern/bpy_app_icons.c
parent20105fc8454a34c342f0f5500497c4452ec2b7ee (diff)
UI: option to load icon from file
Diffstat (limited to 'source/blender/python/intern/bpy_app_icons.c')
-rw-r--r--source/blender/python/intern/bpy_app_icons.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/source/blender/python/intern/bpy_app_icons.c b/source/blender/python/intern/bpy_app_icons.c
index 8aeee1aff9c..6d3b50d5688 100644
--- a/source/blender/python/intern/bpy_app_icons.c
+++ b/source/blender/python/intern/bpy_app_icons.c
@@ -38,22 +38,28 @@
/* We may want to load direct from file. */
PyDoc_STRVAR(bpy_app_icons_new_triangles_doc,
-".. function:: new_triangles(coords, colors)"
+".. function:: new_triangles(range, coords, colors)"
"\n"
" Create a new icon from triangle geometry.\n"
"\n"
+" :arg range: Pair of ints.\n"
+" :type range: tuple.\n"
" :arg coords: Sequence of bytes (6 floats for one triangle) for (X, Y) coordinates.\n"
-" :type coords: byte sequence\n"
+" :type coords: byte sequence.\n"
" :arg colors: Sequence of ints (12 for one triangles) for RGBA.\n"
-" :type colors: byte sequence\n"
+" :type colors: byte sequence.\n"
" :return: Unique icon value (pass to interface ``icon_value`` argument).\n"
" :rtype: int\n"
);
static PyObject *bpy_app_icons_new_triangles(PyObject *UNUSED(self), PyObject *args)
{
/* bytes */
+ uchar coords_range[2];
PyObject *py_coords, *py_colors;
- if (!PyArg_ParseTuple(args, "SS:new_triangles", &py_coords, &py_colors)) {
+ if (!PyArg_ParseTuple(
+ args, "(BB)SS:new_triangles",
+ &coords_range[0], &coords_range[1], &py_coords, &py_colors))
+ {
return NULL;
}
@@ -78,6 +84,8 @@ static PyObject *bpy_app_icons_new_triangles(PyObject *UNUSED(self), PyObject *a
struct Icon_Geom *geom = MEM_mallocN(sizeof(*geom), __func__);
geom->coords_len = tris_len;
+ geom->coords_range[0] = coords_range[0];
+ geom->coords_range[1] = coords_range[1];
geom->coords = coords;
geom->colors = colors;
geom->icon_id = 0;
@@ -85,6 +93,36 @@ static PyObject *bpy_app_icons_new_triangles(PyObject *UNUSED(self), PyObject *a
return PyLong_FromLong(icon_id);
}
+PyDoc_STRVAR(bpy_app_icons_new_triangles_from_file_doc,
+".. function:: new_triangles_from_file(filename)"
+"\n"
+" Create a new icon from triangle geometry.\n"
+"\n"
+" :arg range: File path.\n"
+" :type range: string.\n"
+" :return: Unique icon value (pass to interface ``icon_value`` argument).\n"
+" :rtype: int\n"
+);
+static PyObject *bpy_app_icons_new_triangles_from_file(PyObject *UNUSED(self), PyObject *args)
+{
+ /* bytes */
+ char *filename;
+ if (!PyArg_ParseTuple(
+ args, "s:new_triangles_from_file",
+ &filename))
+ {
+ return NULL;
+ }
+
+ struct Icon_Geom *geom = BKE_icon_geom_from_file(filename);
+ if (geom == NULL) {
+ PyErr_SetString(PyExc_ValueError, "Unable to load from file");
+ return NULL;
+ }
+ int icon_id = BKE_icon_geom_ensure(geom);
+ return PyLong_FromLong(icon_id);
+}
+
PyDoc_STRVAR(bpy_app_icons_release_doc,
".. function:: release(icon_id)"
"\n"
@@ -110,6 +148,7 @@ static PyObject *bpy_app_icons_release(PyObject *UNUSED(self), PyObject *args)
static struct PyMethodDef M_AppIcons_methods[] = {
{"new_triangles", (PyCFunction)bpy_app_icons_new_triangles, METH_VARARGS, bpy_app_icons_new_triangles_doc},
+ {"new_triangles_from_file", (PyCFunction)bpy_app_icons_new_triangles_from_file, METH_VARARGS, bpy_app_icons_new_triangles_from_file_doc},
{"release", (PyCFunction)bpy_app_icons_release, METH_VARARGS, bpy_app_icons_release_doc},
{NULL, NULL, 0, NULL}
};