Adding RrButton to libobrender, ref counted appearances.
This commit is contained in:
parent
b566d3fcfe
commit
6d30d66efb
5 changed files with 183 additions and 0 deletions
|
@ -87,6 +87,8 @@ obrender_libobrender_la_LIBADD = \
|
||||||
$(XML_LIBS)
|
$(XML_LIBS)
|
||||||
obrender_libobrender_la_SOURCES = \
|
obrender_libobrender_la_SOURCES = \
|
||||||
gettext.h \
|
gettext.h \
|
||||||
|
obrender/button.h \
|
||||||
|
obrender/button.c \
|
||||||
obrender/color.h \
|
obrender/color.h \
|
||||||
obrender/color.c \
|
obrender/color.c \
|
||||||
obrender/font.h \
|
obrender/font.h \
|
||||||
|
|
103
obrender/button.c
Normal file
103
obrender/button.c
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
#include "render.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include "instance.h"
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static void RrButtonFreeReal(RrButton* b);
|
||||||
|
|
||||||
|
RrButton *RrButtonNew (const RrInstance *inst)
|
||||||
|
{
|
||||||
|
RrButton *out = NULL;
|
||||||
|
|
||||||
|
out = g_new(RrButton, 1);
|
||||||
|
out->inst = inst;
|
||||||
|
out->ref = 1;
|
||||||
|
|
||||||
|
/* no need to alloc colors, set them null (for freeing later) */
|
||||||
|
out->focused_unpressed_color = NULL;
|
||||||
|
out->unfocused_unpressed_color = NULL;
|
||||||
|
out->focused_pressed_color = NULL;
|
||||||
|
out->unfocused_pressed_color = NULL;
|
||||||
|
out->disabled_focused_color = NULL;
|
||||||
|
out->disabled_unfocused_color = NULL;
|
||||||
|
out->hover_focused_color = NULL;
|
||||||
|
out->hover_unfocused_color = NULL;
|
||||||
|
out->toggled_hover_focused_color = NULL;
|
||||||
|
out->toggled_hover_unfocused_color = NULL;
|
||||||
|
out->toggled_focused_pressed_color = NULL;
|
||||||
|
out->toggled_unfocused_pressed_color = NULL;
|
||||||
|
out->toggled_focused_unpressed_color = NULL;
|
||||||
|
out->toggled_unfocused_unpressed_color = NULL;
|
||||||
|
|
||||||
|
/* same with masks */
|
||||||
|
out->mask = NULL;
|
||||||
|
out->pressed_mask = NULL;
|
||||||
|
out->disabled_mask = NULL;
|
||||||
|
out->hover_mask = NULL;
|
||||||
|
out->toggled_mask = NULL;
|
||||||
|
out->toggled_hover_mask = NULL;
|
||||||
|
out->toggled_pressed_mask = NULL;
|
||||||
|
|
||||||
|
/* allocate appearances */
|
||||||
|
out->a_focused_unpressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_unfocused_unpressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_focused_pressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_unfocused_pressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_disabled_focused = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_disabled_unfocused = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_hover_focused = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_hover_unfocused = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_toggled_focused_unpressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_toggled_unfocused_unpressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_toggled_focused_pressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_toggled_unfocused_pressed = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_toggled_hover_focused = RrAppearanceNew(inst, 1);
|
||||||
|
out->a_toggled_hover_unfocused = RrAppearanceNew(inst, 1);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RrButtonFree(RrButton *b)
|
||||||
|
{
|
||||||
|
b->ref--;
|
||||||
|
if (b->ref <= 0)
|
||||||
|
RrButtonFreeReal(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RrButtonFreeReal(RrButton* b)
|
||||||
|
{
|
||||||
|
/* colors */
|
||||||
|
if (b->focused_unpressed_color)
|
||||||
|
RrColorFree(b->focused_unpressed_color);
|
||||||
|
if (b->unfocused_unpressed_color)
|
||||||
|
RrColorFree(b->unfocused_unpressed_color);
|
||||||
|
if (b->focused_pressed_color)
|
||||||
|
RrColorFree(b->focused_pressed_color);
|
||||||
|
if (b->unfocused_pressed_color)
|
||||||
|
RrColorFree(b->unfocused_pressed_color);
|
||||||
|
if (b->disabled_focused_color)
|
||||||
|
RrColorFree(b->disabled_focused_color);
|
||||||
|
if (b->disabled_unfocused_color)
|
||||||
|
RrColorFree(b->disabled_unfocused_color);
|
||||||
|
if (b->hover_focused_color)
|
||||||
|
RrColorFree(b->hover_focused_color);
|
||||||
|
if (b->hover_unfocused_color)
|
||||||
|
RrColorFree(b->hover_unfocused_color);
|
||||||
|
if (b->toggled_hover_focused_color)
|
||||||
|
RrColorFree(b->toggled_hover_focused_color);
|
||||||
|
if (b->toggled_hover_unfocused_color)
|
||||||
|
RrColorFree(b->toggled_hover_unfocused_color);
|
||||||
|
if (b->toggled_focused_pressed_color)
|
||||||
|
RrColorFree(b->toggled_focused_pressed_color);
|
||||||
|
if (b->toggled_unfocused_pressed_color)
|
||||||
|
RrColorFree(b->toggled_unfocused_pressed_color);
|
||||||
|
if (b->toggled_focused_unpressed_color)
|
||||||
|
RrColorFree(b->toggled_focused_unpressed_color);
|
||||||
|
if (b->toggled_unfocused_unpressed_color)
|
||||||
|
RrColorFree(b->toggled_unfocused_unpressed_color);
|
||||||
|
|
||||||
|
/* masks */
|
||||||
|
}
|
59
obrender/button.h
Normal file
59
obrender/button.h
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#ifndef __button_h
|
||||||
|
#define __button_h
|
||||||
|
|
||||||
|
#include "render.h"
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
struct _RrButton {
|
||||||
|
const RrInstance *inst;
|
||||||
|
|
||||||
|
/* reference count */
|
||||||
|
gint ref;
|
||||||
|
|
||||||
|
/* colors */
|
||||||
|
RrColor *focused_unpressed_color;
|
||||||
|
RrColor *unfocused_unpressed_color;
|
||||||
|
RrColor *focused_pressed_color;
|
||||||
|
RrColor *unfocused_pressed_color;
|
||||||
|
RrColor *disabled_focused_color;
|
||||||
|
RrColor *disabled_unfocused_color;
|
||||||
|
RrColor *hover_focused_color;
|
||||||
|
RrColor *hover_unfocused_color;
|
||||||
|
RrColor *toggled_hover_focused_color;
|
||||||
|
RrColor *toggled_hover_unfocused_color;
|
||||||
|
RrColor *toggled_focused_pressed_color;
|
||||||
|
RrColor *toggled_unfocused_pressed_color;
|
||||||
|
RrColor *toggled_focused_unpressed_color;
|
||||||
|
RrColor *toggled_unfocused_unpressed_color;
|
||||||
|
|
||||||
|
/* masks */
|
||||||
|
RrPixmapMask *mask;
|
||||||
|
RrPixmapMask *pressed_mask;
|
||||||
|
RrPixmapMask *disabled_mask;
|
||||||
|
RrPixmapMask *hover_mask;
|
||||||
|
RrPixmapMask *toggled_mask;
|
||||||
|
RrPixmapMask *toggled_hover_mask;
|
||||||
|
RrPixmapMask *toggled_pressed_mask;
|
||||||
|
|
||||||
|
/* textures */
|
||||||
|
RrAppearance *a_focused_unpressed;
|
||||||
|
RrAppearance *a_unfocused_unpressed;
|
||||||
|
RrAppearance *a_focused_pressed;
|
||||||
|
RrAppearance *a_unfocused_pressed;
|
||||||
|
RrAppearance *a_disabled_focused;
|
||||||
|
RrAppearance *a_disabled_unfocused;
|
||||||
|
RrAppearance *a_hover_focused;
|
||||||
|
RrAppearance *a_hover_unfocused;
|
||||||
|
RrAppearance *a_toggled_focused_unpressed;
|
||||||
|
RrAppearance *a_toggled_unfocused_unpressed;
|
||||||
|
RrAppearance *a_toggled_focused_pressed;
|
||||||
|
RrAppearance *a_toggled_unfocused_pressed;
|
||||||
|
RrAppearance *a_toggled_hover_focused;
|
||||||
|
RrAppearance *a_toggled_hover_unfocused;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __button_h */
|
|
@ -204,6 +204,7 @@ RrAppearance *RrAppearanceNew(const RrInstance *inst, gint numtex)
|
||||||
|
|
||||||
out = g_slice_new0(RrAppearance);
|
out = g_slice_new0(RrAppearance);
|
||||||
out->inst = inst;
|
out->inst = inst;
|
||||||
|
out->ref = 1;
|
||||||
out->textures = numtex;
|
out->textures = numtex;
|
||||||
out->surface.bevel_light_adjust = 128;
|
out->surface.bevel_light_adjust = 128;
|
||||||
out->surface.bevel_dark_adjust = 64;
|
out->surface.bevel_dark_adjust = 64;
|
||||||
|
@ -231,12 +232,22 @@ void RrAppearanceClearTextures(RrAppearance *a)
|
||||||
memset(a->texture, 0, a->textures * sizeof(RrTexture));
|
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)
|
RrAppearance *RrAppearanceCopy(RrAppearance *orig)
|
||||||
{
|
{
|
||||||
RrSurface *spo, *spc;
|
RrSurface *spo, *spc;
|
||||||
RrAppearance *copy = g_slice_new(RrAppearance);
|
RrAppearance *copy = g_slice_new(RrAppearance);
|
||||||
|
|
||||||
copy->inst = orig->inst;
|
copy->inst = orig->inst;
|
||||||
|
copy->ref = 1;
|
||||||
|
|
||||||
spo = &(orig->surface);
|
spo = &(orig->surface);
|
||||||
spc = &(copy->surface);
|
spc = &(copy->surface);
|
||||||
|
@ -316,6 +327,7 @@ RrAppearance *RrAppearanceCopy(RrAppearance *orig)
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* now decrements ref counter, and frees only if ref <= 0 */
|
||||||
void RrAppearanceFree(RrAppearance *a)
|
void RrAppearanceFree(RrAppearance *a)
|
||||||
{
|
{
|
||||||
if (a) {
|
if (a) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ typedef struct _RrColor RrColor;
|
||||||
typedef struct _RrImage RrImage;
|
typedef struct _RrImage RrImage;
|
||||||
typedef struct _RrImagePic RrImagePic;
|
typedef struct _RrImagePic RrImagePic;
|
||||||
typedef struct _RrImageCache RrImageCache;
|
typedef struct _RrImageCache RrImageCache;
|
||||||
|
typedef struct _RrButton RrButton;
|
||||||
|
|
||||||
typedef guint32 RrPixel32;
|
typedef guint32 RrPixel32;
|
||||||
typedef guint16 RrPixel16;
|
typedef guint16 RrPixel16;
|
||||||
|
@ -220,6 +221,8 @@ struct _RrTexture {
|
||||||
|
|
||||||
struct _RrAppearance {
|
struct _RrAppearance {
|
||||||
const RrInstance *inst;
|
const RrInstance *inst;
|
||||||
|
|
||||||
|
gint ref;
|
||||||
|
|
||||||
RrSurface surface;
|
RrSurface surface;
|
||||||
gint textures;
|
gint textures;
|
||||||
|
@ -314,6 +317,7 @@ gulong RrColorPixel (const RrColor *c);
|
||||||
GC RrColorGC (RrColor *c);
|
GC RrColorGC (RrColor *c);
|
||||||
|
|
||||||
RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex);
|
RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex);
|
||||||
|
RrAppearance *RrAppearanceCopyShallow (RrAppearance *a);
|
||||||
RrAppearance *RrAppearanceCopy (RrAppearance *a);
|
RrAppearance *RrAppearanceCopy (RrAppearance *a);
|
||||||
void RrAppearanceFree (RrAppearance *a);
|
void RrAppearanceFree (RrAppearance *a);
|
||||||
void RrAppearanceRemoveTextures(RrAppearance *a);
|
void RrAppearanceRemoveTextures(RrAppearance *a);
|
||||||
|
@ -321,6 +325,9 @@ void RrAppearanceAddTextures(RrAppearance *a, gint numtex);
|
||||||
/*! Always call this when changing the type of a texture in an appearance */
|
/*! Always call this when changing the type of a texture in an appearance */
|
||||||
void RrAppearanceClearTextures(RrAppearance *a);
|
void RrAppearanceClearTextures(RrAppearance *a);
|
||||||
|
|
||||||
|
RrButton *RrButtonNew (const RrInstance *inst);
|
||||||
|
void RrButtonFree(RrButton *b);
|
||||||
|
|
||||||
RrFont *RrFontOpen (const RrInstance *inst, const gchar *name,
|
RrFont *RrFontOpen (const RrInstance *inst, const gchar *name,
|
||||||
gint size, RrFontWeight weight, RrFontSlant slant);
|
gint size, RrFontWeight weight, RrFontSlant slant);
|
||||||
RrFont *RrFontOpenDefault (const RrInstance *inst);
|
RrFont *RrFontOpenDefault (const RrInstance *inst);
|
||||||
|
|
Loading…
Reference in a new issue