Add drawing functions that will be needed later on
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
9a24779425
commit
97f66c57b5
|
@ -133,6 +133,7 @@ pkg_check_modules(AWESOME_COMMON_REQUIRED REQUIRED
|
||||||
pkg_check_modules(AWESOME_REQUIRED REQUIRED
|
pkg_check_modules(AWESOME_REQUIRED REQUIRED
|
||||||
glib-2.0
|
glib-2.0
|
||||||
cairo
|
cairo
|
||||||
|
oocairo
|
||||||
x11
|
x11
|
||||||
pango>=1.19.3
|
pango>=1.19.3
|
||||||
pangocairo>=1.19.3
|
pangocairo>=1.19.3
|
||||||
|
|
58
draw.c
58
draw.c
|
@ -402,4 +402,62 @@ draw_align_tostr(alignment_t a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cairo_user_data_key_t data_key;
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
free_data(void *data)
|
||||||
|
{
|
||||||
|
p_delete(&data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create a surface object on the lua stack from this image data.
|
||||||
|
* \param L The lua stack.
|
||||||
|
* \param width The width of the image.
|
||||||
|
* \param height The height of the image
|
||||||
|
* \param data The image's data in ARGB format, will be copied by this function.
|
||||||
|
* \return Number of items pushed on the lua stack.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
luaA_surface_from_data(lua_State *L, int width, int height, uint32_t *data)
|
||||||
|
{
|
||||||
|
unsigned long int len = width * height;
|
||||||
|
unsigned char *buffer = p_dup(data, len);
|
||||||
|
cairo_surface_t *surface =
|
||||||
|
cairo_image_surface_create_for_data(buffer,
|
||||||
|
CAIRO_FORMAT_ARGB32,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
width*4);
|
||||||
|
/* This makes sure that buffer will be freed */
|
||||||
|
cairo_surface_set_user_data(surface, &data_key, buffer, &free_data);
|
||||||
|
|
||||||
|
/* This will increase the reference count of the surface */
|
||||||
|
int ret = oocairo_surface_push(globalconf.L, surface);
|
||||||
|
/* So we have to drop our own reference */
|
||||||
|
cairo_surface_destroy(surface);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Duplicate the specified image surface.
|
||||||
|
* \param surface The surface to copy
|
||||||
|
* \return A pointer to a new cairo image surface.
|
||||||
|
*/
|
||||||
|
cairo_surface_t *
|
||||||
|
draw_dup_image_surface(cairo_surface_t *surface)
|
||||||
|
{
|
||||||
|
cairo_surface_t *res = cairo_image_surface_create(
|
||||||
|
cairo_image_surface_get_format(surface),
|
||||||
|
cairo_image_surface_get_width(surface),
|
||||||
|
cairo_image_surface_get_height(surface));
|
||||||
|
|
||||||
|
cairo_t *cr = cairo_create(res);
|
||||||
|
cairo_set_source_surface(cr, surface, 0, 0);
|
||||||
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||||
|
cairo_paint(cr);
|
||||||
|
cairo_destroy(cr);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
5
draw.h
5
draw.h
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
|
#include <oocairo.h>
|
||||||
|
|
||||||
#include "objects/image.h"
|
#include "objects/image.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "common/array.h"
|
#include "common/array.h"
|
||||||
|
@ -132,6 +134,9 @@ void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int
|
||||||
area_t draw_text_extents(draw_text_context_t *);
|
area_t draw_text_extents(draw_text_context_t *);
|
||||||
alignment_t draw_align_fromstr(const char *);
|
alignment_t draw_align_fromstr(const char *);
|
||||||
const char *draw_align_tostr(alignment_t);
|
const char *draw_align_tostr(alignment_t);
|
||||||
|
int luaA_surface_from_data(lua_State *L, int width, int height, uint32_t *data);
|
||||||
|
cairo_surface_t *draw_dup_image_surface(cairo_surface_t *surface);
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
draw_text_context_wipe(draw_text_context_t *pdata)
|
draw_text_context_wipe(draw_text_context_t *pdata)
|
||||||
|
|
Loading…
Reference in New Issue