Added button image data transmission from
[irreco.git] / irreco / src / core / irreco_theme_button.c
blob57b1ff7a02942454d1cb5ec96d8617023bf26e1d
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_theme_button.h"
22 /**
23 * @addtogroup IrrecoThemeButton
24 * @ingroup Irreco
26 * Contains information of button.
28 * @{
31 /**
32 * @file
33 * Source file of @ref IrrecoThemeButton.
36 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 /* Prototypes */
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /* Construction & Destruction */
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /**
45 * @name Construction & Destruction
46 * @{
49 IrrecoThemeButton *irreco_theme_button_new(const char *theme_name)
51 IrrecoThemeButton *self;
52 IRRECO_ENTER
54 self = g_slice_new0(IrrecoThemeButton);
56 self->theme_name = g_string_new(theme_name);
57 self->style_name = g_string_new("");
58 self->name = g_string_new("");
59 self->image_up = g_string_new("");
60 self->image_down = g_string_new("");
61 self->text_format_up = g_string_new("");
62 self->text_format_down = g_string_new("");
63 self->text_padding = 5;
65 /* Default to center alignment. */
66 self->text_h_align = 0.5;
67 self->text_v_align = 0.5;
69 IRRECO_RETURN_PTR(self);
72 void irreco_theme_button_free(IrrecoThemeButton *self)
74 IRRECO_ENTER
76 g_assert(self != NULL);
78 g_string_free(self->theme_name, TRUE);
79 self->theme_name = NULL;
81 g_string_free(self->style_name, TRUE);
82 self->style_name = NULL;
84 g_string_free(self->name, TRUE);
85 self->name = NULL;
87 g_string_free(self->image_up, TRUE);
88 self->image_up = NULL;
90 g_string_free(self->image_down, TRUE);
91 self->image_down = NULL;
93 g_string_free(self->text_format_up, TRUE);
94 self->text_format_up = NULL;
96 g_string_free(self->text_format_down, TRUE);
97 self->text_format_down = NULL;
99 g_slice_free(IrrecoThemeButton, self);
100 self = NULL;
102 IRRECO_RETURN
105 /** @} */
107 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
108 /* Private Functions */
109 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
111 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
112 /* Public Functions */
113 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
116 * @name Public Functions
117 * @{
120 void irreco_theme_button_set(IrrecoThemeButton *self,
121 const char *style_name,
122 const char *name,
123 gboolean allow_text,
124 const char *image_up,
125 const char *image_down,
126 const char *text_format_up,
127 const char *text_format_down,
128 gint text_padding,
129 gfloat text_h_align,
130 gfloat text_v_align)
132 IRRECO_ENTER
134 if (style_name != NULL) {
135 g_string_printf(self->style_name, "%s", style_name);
137 if (name != NULL) {
138 g_string_printf(self->name, "%s", name);
140 self->allow_text = allow_text;
141 if (image_up != NULL) {
142 g_string_printf(self->image_up, "%s", image_up);
144 if (image_down != NULL) {
145 g_string_printf(self->image_down, "%s", image_down);
146 } else {
147 g_string_printf(self->image_down, "%s", image_up);
149 if (text_format_up != NULL) {
150 g_string_printf(self->text_format_up, "%s", text_format_up);
152 if (text_format_down != NULL) {
153 g_string_printf(self->text_format_down, "%s", text_format_down);
156 self->text_padding = text_padding;
158 /* Set Horisontal aligment. */
159 if (self->text_h_align < 0) {
160 self->text_h_align = 0;
161 } else if (self->text_h_align > 1) {
162 self->text_h_align = 1;
163 } else {
164 self->text_h_align = text_h_align;
167 /* Set vertical alignment. */
168 if (self->text_v_align < 0) {
169 self->text_v_align = 0;
170 } else if (self->text_v_align > 1) {
171 self->text_v_align = 1;
172 } else {
173 self->text_v_align = text_v_align;
176 IRRECO_RETURN
179 void irreco_theme_button_print(IrrecoThemeButton *self)
181 IRRECO_ENTER
183 IRRECO_DEBUG("--------------------------------------------\n");
184 IRRECO_DEBUG("theme_name: %s\n", self->theme_name->str);
185 IRRECO_DEBUG("style_name: %s\n", self->style_name->str);
186 IRRECO_DEBUG("button_name: %s\n", self->name->str);
187 IRRECO_DEBUG("allow_text: %d\n", self->allow_text);
188 IRRECO_DEBUG("image_up: %s\n",self->image_up->str);
189 IRRECO_DEBUG("image_down: %s\n", self->image_down->str);
190 IRRECO_DEBUG("text_format_up: %s\n", self->text_format_up->str);
191 IRRECO_DEBUG("text_format_down: %s\n", self->text_format_down->str);
192 IRRECO_DEBUG("text_padding: %d\n", self->text_padding);
193 IRRECO_DEBUG("--------------------------------------------\n");
195 IRRECO_RETURN
199 IrrecoThemeButton *irreco_theme_button_copy(IrrecoThemeButton *self)
201 IrrecoThemeButton *new = NULL;
202 IRRECO_ENTER
204 new = irreco_theme_button_new(self->theme_name->str);
205 irreco_theme_button_set(new, self->style_name->str, self->name->str,
206 self->allow_text, self->image_up->str,
207 self->image_down->str, self->text_format_up->str,
208 self->text_format_down->str, self->text_padding,
209 self->text_h_align, self->text_v_align);
211 IRRECO_RETURN_PTR(new);
216 /** @} */
218 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
219 /* Events and Callbacks */
220 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
222 /** @} */