Improved commentary.
[irreco.git] / irreco / src / core / irreco_theme_button.c
blob09224397d8a32ed6d7f76695e9d73bf8eab9003b
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
4 *
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.
9 *
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()
51 IrrecoThemeButton *self;
52 IRRECO_ENTER
54 self = g_slice_new0(IrrecoThemeButton);
56 self->style_name = g_string_new("");
57 self->name = g_string_new("");
58 self->image_up = g_string_new("");
59 self->image_down = g_string_new("");
60 self->text_format_up = g_string_new("");
61 self->text_format_down = g_string_new("");
62 self->text_padding = 5;
64 /* Default to center alignment. */
65 self->text_h_align = 0.5;
66 self->text_v_align = 0.5;
68 IRRECO_RETURN_PTR(self);
71 void irreco_theme_button_free(IrrecoThemeButton *self)
73 IRRECO_ENTER
75 g_assert(self != NULL);
77 g_string_free(self->style_name, TRUE);
78 self->style_name = NULL;
80 g_string_free(self->name, TRUE);
81 self->name = NULL;
83 g_string_free(self->image_up, TRUE);
84 self->image_up = NULL;
86 g_string_free(self->image_down, TRUE);
87 self->image_down = NULL;
89 g_string_free(self->text_format_up, TRUE);
90 self->text_format_up = NULL;
92 g_string_free(self->text_format_down, TRUE);
93 self->text_format_down = NULL;
95 g_slice_free(IrrecoThemeButton, self);
96 self = NULL;
98 IRRECO_RETURN
101 /** @} */
103 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
104 /* Private Functions */
105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
107 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
108 /* Public Functions */
109 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
112 * @name Public Functions
113 * @{
116 void irreco_theme_button_set(IrrecoThemeButton *self,
117 const char *style_name,
118 const char *name,
119 gboolean allow_text,
120 const char *image_up,
121 const char *image_down,
122 const char *text_format_up,
123 const char *text_format_down,
124 gint text_padding,
125 gfloat text_h_align,
126 gfloat text_v_align)
128 IRRECO_ENTER
130 if (style_name != NULL) {
131 g_string_printf(self->style_name, "%s", style_name);
133 if (name != NULL) {
134 g_string_printf(self->name, "%s", name);
136 self->allow_text = allow_text;
137 if (image_up != NULL) {
138 g_string_printf(self->image_up, "%s", image_up);
140 if (image_down != NULL) {
141 g_string_printf(self->image_down, "%s", image_down);
142 } else {
143 g_string_printf(self->image_down, "%s", image_up);
145 if (text_format_up != NULL) {
146 g_string_printf(self->text_format_up, "%s", text_format_up);
148 if (text_format_down != NULL) {
149 g_string_printf(self->text_format_down, "%s", text_format_down);
152 self->text_padding = text_padding;
154 /* Set Horisontal aligment. */
155 if (self->text_h_align < 0) {
156 self->text_h_align = 0;
157 } else if (self->text_h_align > 1) {
158 self->text_h_align = 1;
159 } else {
160 self->text_h_align = text_h_align;
163 /* Set vertical alignment. */
164 if (self->text_v_align < 0) {
165 self->text_v_align = 0;
166 } else if (self->text_v_align > 1) {
167 self->text_v_align = 1;
168 } else {
169 self->text_v_align = text_v_align;
172 IRRECO_RETURN
175 void irreco_theme_button_print(IrrecoThemeButton *self)
177 IRRECO_ENTER
179 IRRECO_DEBUG("--------------------------------------------\n");
180 IRRECO_DEBUG("style_name: %s\n", self->style_name->str);
181 IRRECO_DEBUG("button_name: %s\n", self->name->str);
182 IRRECO_DEBUG("allow_text: %d\n", self->allow_text);
183 IRRECO_DEBUG("image_up: %s\n",self->image_up->str);
184 IRRECO_DEBUG("image_down: %s\n", self->image_down->str);
185 IRRECO_DEBUG("text_format_up: %s\n", self->text_format_up->str);
186 IRRECO_DEBUG("text_format_down: %s\n", self->text_format_down->str);
187 IRRECO_DEBUG("text_padding: %d\n", self->text_padding);
188 IRRECO_DEBUG("--------------------------------------------\n");
190 IRRECO_RETURN
193 /** @} */
195 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
196 /* Events and Callbacks */
197 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
199 /** @} */