Adding RrButton to libobrender, ref counted appearances.
Dave Foster daf@minuslab.net
5 files changed,
183 insertions(+),
0 deletions(-)
M
Makefile.am
→
Makefile.am
@@ -87,6 +87,8 @@ $(IMLIB2_LIBS) \
$(XML_LIBS) obrender_libobrender_la_SOURCES = \ gettext.h \ + obrender/button.h \ + obrender/button.c \ obrender/color.h \ obrender/color.c \ obrender/font.h \
M
obrender/render.c
→
obrender/render.c
@@ -204,6 +204,7 @@ RrAppearance *out;
out = g_slice_new0(RrAppearance); out->inst = inst; + out->ref = 1; out->textures = numtex; out->surface.bevel_light_adjust = 128; out->surface.bevel_dark_adjust = 64;@@ -231,12 +232,22 @@ {
memset(a->texture, 0, a->textures * sizeof(RrTexture)); } +/* shallow copy means up the ref count and return it */ +RrAppearance *RrAppearanceCopyShallow(RrAppearance *orig) +{ + orig->ref++; + return orig; +} + +/* deep copy of orig, means reset ref to 1 on copy + * and copy each thing memwise. */ RrAppearance *RrAppearanceCopy(RrAppearance *orig) { RrSurface *spo, *spc; RrAppearance *copy = g_slice_new(RrAppearance); copy->inst = orig->inst; + copy->ref = 1; spo = &(orig->surface); spc = &(copy->surface);@@ -316,6 +327,7 @@ copy->w = copy->h = 0;
return copy; } +/* now decrements ref counter, and frees only if ref <= 0 */ void RrAppearanceFree(RrAppearance *a) { if (a) {
M
obrender/render.h
→
obrender/render.h
@@ -46,6 +46,7 @@ typedef struct _RrColor RrColor;
typedef struct _RrImage RrImage; typedef struct _RrImagePic RrImagePic; typedef struct _RrImageCache RrImageCache; +typedef struct _RrButton RrButton; typedef guint32 RrPixel32; typedef guint16 RrPixel16;@@ -220,6 +221,8 @@ };
struct _RrAppearance { const RrInstance *inst; + + gint ref; RrSurface surface; gint textures;@@ -314,12 +317,16 @@ gulong RrColorPixel (const RrColor *c);
GC RrColorGC (RrColor *c); RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex); +RrAppearance *RrAppearanceCopyShallow (RrAppearance *a); RrAppearance *RrAppearanceCopy (RrAppearance *a); void RrAppearanceFree (RrAppearance *a); void RrAppearanceRemoveTextures(RrAppearance *a); void RrAppearanceAddTextures(RrAppearance *a, gint numtex); /*! Always call this when changing the type of a texture in an appearance */ void RrAppearanceClearTextures(RrAppearance *a); + +RrButton *RrButtonNew (const RrInstance *inst); +void RrButtonFree(RrButton *b); RrFont *RrFontOpen (const RrInstance *inst, const gchar *name, gint size, RrFontWeight weight, RrFontSlant slant);