Minor syntactical changes for readability.
[xuni.git] / src / xuni.c
blob5396a0472c61d536f8989e5b02d2b57cd6eee9dc
1 /*! \mainpage
3 xuni, a flexible SDL GUI widget toolkit which supports rescaling \n
4 Copyright (C) 2008 DWK
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 The GNU General Public License version 2 is included in the file COPYING.
22 \author DWK
23 dwks@theprogrammingsite.com \n
24 http://dwks.theprogrammingsite.com \n
26 \version 0.3.0
28 At the time of this writing, xuni can be obtained from:
29 http://dwks.theprogrammingsite.com/myprogs/xuni.htm
31 ----
33 xuni stands for "Explore the Universe". It's entirely coincidental that
34 shifting one of the letters in "xuni" spells UNIX, and that reversing the
35 letters and adding another letter spells Linux. "xuni" is pronounced
36 "zoo-nee" in the author's opinion. But "ecks-you-nee" or
37 "ecks-you-en-eye" or other variations work as well.
39 xuni was written from the ground up without incorporating any code from my
40 numerous previous SDL projects. It uses SDL_image, SDL_gfx, and SDL_ttf in
41 addition to the SDL, along with expat.
44 /*! \file xuni.c
48 #include <stdlib.h>
49 #include <string.h>
50 #include <ctype.h>
52 #include "SDL.h"
54 #include "error.h"
55 #include "graphics.h"
56 #include "gui.h"
57 #include "loop.h"
58 #include "memory.h"
59 #include "resource/resource.h"
60 #include "version.h"
61 #include "xuni.h"
63 static void validate_xuni_structure(struct xuni_t *xuni);
65 /*! Dynamically allocates enough memory for a xuni_t structure. The memory is
66 uninitialized. init_xuni() must eventually be called on the returned
67 structure to get a useful xuni_t object.
68 \return The newly allocated xuni_t structure.
70 struct xuni_t *allocate_xuni(void) {
71 struct xuni_t *xuni = xuni_memory_allocate(sizeof(*xuni));
73 xuni->smode = xuni_memory_allocate(sizeof(*xuni->smode));
74 xuni->theme = xuni_memory_allocate(sizeof(*xuni->theme));
75 xuni->gui = xuni_memory_allocate(sizeof(*xuni->gui));
76 xuni->wtype = xuni_memory_allocate(sizeof(*xuni->wtype));
77 xuni->loadso = xuni_memory_allocate(sizeof(*xuni->loadso));
79 return xuni;
82 /*! Makes sure that the xuni_t structure \a xuni can be executed, i.e. has a
83 root widget.
85 Also checks to see if any themes were loaded. If not, this is not a fatal
86 error, but still warrants an informative message, because xuni will not
87 look very good once it is running.
89 \param xuni The xuni structure to check for a root widget etc.
91 static void validate_xuni_structure(struct xuni_t *xuni) {
92 if(!xuni->gui->widget) {
93 log_message(ERROR_TYPE_FATAL, 0, __FILE__, __LINE__,
94 "No root widget");
95 exit(1);
97 else if(!xuni->theme->current) {
98 log_message(ERROR_TYPE_RESOURCE, 0, __FILE__, __LINE__,
99 "No themes loaded");
103 /*! Initializes a xuni_t structure, after a resource_t structure has been
104 created, perhaps by reading data from an XML file. This should be the
105 first function called on a newly allocated xuni_t structure.
106 \param xuni The xuni_t structure to initialize.
107 \param settings The settings to use while initializing \a xuni.
108 \param icon The icon to use for the xuni window.
110 void init_xuni(struct xuni_t *xuni, struct resource_t *settings,
111 const char *icon) {
113 init_smode(xuni->smode, settings);
114 init_gui(xuni);
116 init_sdl_libraries(xuni->smode, icon);
118 init_loadso(xuni->loadso);
119 init_wtype(xuni, xuni->wtype);
121 init_theme_structure(xuni->theme);
122 load_resource_widgets(xuni, &xuni->gui->widget, settings->data);
124 validate_xuni_structure(xuni);
127 /*! Frees the memory allocated for a xuni_t structure (\a xuni). This includes
128 not only the memory allocated in init_xuni() but also the widget tree etc.
130 This function cannot yet be replaced with a call to xuni_memory_free_all()
131 -- it calls other freeing function too, for example
132 xuni_loadso_free_object().
133 \param xuni The xuni_t structure to free all of the allocated memory of.
135 void free_xuni(struct xuni_t *xuni) {
136 free_smode(xuni->smode);
137 free_theme(xuni->theme);
138 free_gui(xuni);
139 free_wtype(xuni->wtype);
140 free_loadso(xuni->loadso);
142 xuni_memory_free(xuni->smode);
143 xuni_memory_free(xuni->theme);
144 xuni_memory_free(xuni->gui);
145 xuni_memory_free(xuni->wtype);
147 xuni_memory_free(xuni);
150 /*! Returns the version of xuni, as defined by VERSION (in version.h).
151 \return The current version of xuni.
153 const char *get_xuni_version_string(void) {
154 return XUNI_VERSION;