summaryrefslogtreecommitdiff
path: root/obrender/button.c
blob: 14a454ddda71b49ef89d4e784beec5404abe50e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "render.h"
#include "button.h"
#include "instance.h"
#include "mask.h"

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <string.h>

RrButton *RrButtonNew (const RrInstance *inst)
{
    RrButton *out = NULL;

    out = g_new(RrButton, 1);
    out->inst = inst;

    /* 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)
{
    /* 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 */
    if (b->mask) RrPixmapMaskFree(b->mask);
    if (b->pressed_mask) RrPixmapMaskFree(b->pressed_mask);
    if (b->disabled_mask) RrPixmapMaskFree(b->disabled_mask);
    if (b->hover_mask) RrPixmapMaskFree(b->hover_mask);
    if (b->toggled_mask) RrPixmapMaskFree(b->toggled_mask);
    if (b->toggled_hover_mask) RrPixmapMaskFree(b->toggled_hover_mask);
    if (b->toggled_pressed_mask) RrPixmapMaskFree(b->toggled_pressed_mask);

    /* appearances */
    RrAppearanceFree(b->a_focused_unpressed);
    RrAppearanceFree(b->a_unfocused_unpressed);
    RrAppearanceFree(b->a_focused_pressed);
    RrAppearanceFree(b->a_unfocused_pressed);
    RrAppearanceFree(b->a_disabled_focused);
    RrAppearanceFree(b->a_disabled_unfocused);
    RrAppearanceFree(b->a_hover_focused);
    RrAppearanceFree(b->a_hover_unfocused);
    RrAppearanceFree(b->a_toggled_focused_unpressed);
    RrAppearanceFree(b->a_toggled_unfocused_unpressed);
    RrAppearanceFree(b->a_toggled_focused_pressed);
    RrAppearanceFree(b->a_toggled_unfocused_pressed);
    RrAppearanceFree(b->a_toggled_hover_focused);
    RrAppearanceFree(b->a_toggled_hover_unfocused);
}